S32 SDK
lin_lpuart_driver.c File Reference

Go to the source code of this file.

Functions

static status_t LIN_LPUART_DRV_WaitComplete (uint32_t instance, uint32_t timeoutMSec)
 
static void LIN_LPUART_DRV_ProcessBreakDetect (uint32_t instance)
 
static void LIN_LPUART_DRV_CheckWakeupSignal (uint32_t instance)
 
static void LIN_LPUART_DRV_ProcessFrame (uint32_t instance, uint8_t tmpByte)
 
static void LIN_LPUART_DRV_ProcessFrameHeader (uint32_t instance, uint8_t tmpByte)
 
static void LIN_LPUART_DRV_ProcessReceiveFrameData (uint32_t instance, uint8_t tmpByte)
 
static void LIN_LPUART_DRV_ProcessSendFrameData (uint32_t instance, uint8_t tmpByte)
 
static void LIN_LPUART_DRV_AutobaudTimerValEval (uint32_t instance, uint32_t twoBitTimeLength)
 
static void LIN_LPUART_DRV_EvalTwoBitTimeLength (uint32_t instance, uint32_t twoBitTimeLength)
 
status_t LIN_LPUART_DRV_Init (uint32_t instance, lin_user_config_t *linUserConfig, lin_state_t *linCurrentState)
 Initializes an LIN_LPUART instance for LIN Network. More...
 
status_t LIN_LPUART_DRV_Deinit (uint32_t instance)
 Shuts down the LIN_LPUART by disabling interrupts and transmitter/receiver. More...
 
lin_callback_t LIN_LPUART_DRV_InstallCallback (uint32_t instance, lin_callback_t function)
 Installs callback function that is used for LIN_LPUART_DRV_IRQHandler. More...
 
status_t LIN_LPUART_DRV_SendFrameDataBlocking (uint32_t instance, const uint8_t *txBuff, uint8_t txSize, uint32_t timeoutMSec)
 Sends Frame data out through the LIN_LPUART module using blocking method. This function will calculate the checksum byte and send it with the frame data. Blocking means that the function does not return until the transmission is complete. This function checks if txSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY. The function does not return until the transmission is complete. If the transmission is successful, it will return STATUS_SUCCESS. If not, it will return STATUS_TIMEOUT. More...
 
status_t LIN_LPUART_DRV_SendFrameData (uint32_t instance, const uint8_t *txBuff, uint8_t txSize)
 Sends frame data out through the LIN_LPUART module using non-blocking method. This enables an a-sync method for transmitting data. Non-blocking means that the function returns immediately. The application has to get the transmit status to know when the transmit is complete. This function will calculate the checksum byte and send it with the frame data. If txSize is equal to 0 or greater than 8 or node's current state is in SLEEP mode then the function will return STATUS_ERROR. If isBusBusy is currently true then the function will return STATUS_BUSY. More...
 
status_t LIN_LPUART_DRV_GetTransmitStatus (uint32_t instance, uint8_t *bytesRemaining)
 Get status of an on-going non-blocking transmission While sending frame data using non-blocking method, users can use this function to get status of that transmission. This function return STATUS_BUSY while sending, or STATUS_TIMEOUT if timeout has occurred, or return STATUS_SUCCESS when the transmission is complete. The bytesRemaining shows number of bytes that still needed to transmit. More...
 
status_t LIN_LPUART_DRV_RecvFrmDataBlocking (uint32_t instance, uint8_t *rxBuff, uint8_t rxSize, uint32_t timeoutMSec)
 Receives frame data through the LIN_LPUART module using blocking method. The function does not return until the receive is complete. The interrupt handler LIN_LPUART_DRV_IRQHandler will check the checksum byte. If the checksum is correct, it will receive the frame data. If the checksum is incorrect, this function will return STATUS_TIMEOUT and data in rxBuff might be wrong. This function also check if rxSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY. More...
 
status_t LIN_LPUART_DRV_RecvFrmData (uint32_t instance, uint8_t *rxBuff, uint8_t rxSize)
 Receives frame data through the LIN_LPUART module using non-blocking method. This function returns immediately after initiating the receive function. The application has to get the receive status to see when the receive is complete. The interrupt handler LIN_LPUART_DRV_IRQHandler will check the checksum byte. If the checksum is correct, it will receive the frame data. If the checksum is incorrect, this function will return STATUS_TIMEOUT and data in rxBuff might be wrong. This function also check if rxSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY. More...
 
status_t LIN_LPUART_DRV_AbortTransferData (uint32_t instance)
 Aborts an on-going non-blocking transmission/reception. While performing a non-blocking transferring data, users can call this function to terminate immediately the transferring. More...
 
status_t LIN_LPUART_DRV_GetReceiveStatus (uint32_t instance, uint8_t *bytesRemaining)
 Get status of an on-going non-blocking reception While receiving frame data using non-blocking method, users can use this function to get status of that receiving. This function return the current event ID, STATUS_BUSY while receiving and return STATUS_SUCCESS, or timeout (STATUS_TIMEOUT) when the reception is complete. The bytesRemaining shows number of bytes that still needed to receive. More...
 
status_t LIN_LPUART_DRV_GoToSleepMode (uint32_t instance)
 This function puts current node to sleep mode This function changes current node state to LIN_NODE_STATE_SLEEP_MODE. More...
 
status_t LIN_LPUART_DRV_SendWakeupSignal (uint32_t instance)
 Sends a wakeup signal through the LIN_LPUART interface. More...
 
lin_node_state_t LIN_LPUART_DRV_GetCurrentNodeState (uint32_t instance)
 Get the current LIN node state. More...
 
void LIN_LPUART_DRV_TimeoutService (uint32_t instance)
 Callback function for Timer Interrupt Handler Users shall initialize a timer (for example FTM) in Output compare mode with period of 500 micro seconds. In timer IRQ handler, call this function. More...
 
void LIN_LPUART_DRV_SetTimeoutCounter (uint32_t instance, uint32_t timeoutValue)
 Set Value for Timeout Counter that is used in LIN_LPUART_DRV_TimeoutService. More...
 
status_t LIN_LPUART_DRV_MasterSendHeader (uint32_t instance, uint8_t id)
 Sends frame header out through the LIN_LPUART module using a non-blocking method. This function sends LIN Break field, sync field then the ID with correct parity. This function checks if the interface is Master, if not, it will return STATUS_ERROR.This function checks if id is in range from 0 to 0x3F, if not it will return STATUS_ERROR. More...
 
status_t LIN_LPUART_DRV_EnableIRQ (uint32_t instance)
 Enables LIN_LPUART hardware interrupts. More...
 
status_t LIN_LPUART_DRV_DisableIRQ (uint32_t instance)
 Disables LIN_LPUART hardware interrupts. More...
 
status_t LIN_LPUART_DRV_GotoIdleState (uint32_t instance)
 Puts current LIN node to Idle state This function changes current node state to LIN_NODE_STATE_IDLE. More...
 
void LIN_LPUART_DRV_IRQHandler (uint32_t instance)
 LIN_LPUART interrupt handler for RX_TX and Error interrupts. More...
 
status_t LIN_LPUART_DRV_AutoBaudCapture (uint32_t instance)
 LIN_LPUART capture time interval to set baudrate automatically when enable autobaud feature. This function should only be used in Slave. The timer should be in input capture mode of both rising and falling edges. The timer input capture pin should be externally connected to RXD pin. More...
 

Variables

LPUART_Type *const g_linLpuartBase [LPUART_INSTANCE_COUNT] = LPUART_BASE_PTRS
 Table of base addresses for LPUART instances. More...
 
const IRQn_Type g_linLpuartRxTxIrqId [LPUART_INSTANCE_COUNT] = LPUART_RX_TX_IRQS
 Table to save LPUART IRQ enumeration numbers defined in the device header file. More...
 
lin_state_tg_linStatePtr [LPUART_INSTANCE_COUNT] = {NULL}
 Table to save LPUART state structure pointers. More...
 
lin_user_config_tg_linUserconfigPtr [LPUART_INSTANCE_COUNT] = {NULL}
 Table to save LIN user config structure pointers. More...
 
isr_t g_linLpuartIsrs [LPUART_INSTANCE_COUNT]
 
static uint32_t s_previousTwoBitTimeLength [LPUART_INSTANCE_COUNT] = {0U}
 
static uint8_t s_wakeupSignal [LPUART_INSTANCE_COUNT] = {0U}
 
static uint8_t s_countMeasure [LPUART_INSTANCE_COUNT] = {0U}
 
static uint32_t s_timeMeasure [LPUART_INSTANCE_COUNT] = {0U}
 

Function Documentation

status_t LIN_LPUART_DRV_AbortTransferData ( uint32_t  instance)

Aborts an on-going non-blocking transmission/reception. While performing a non-blocking transferring data, users can call this function to terminate immediately the transferring.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 756 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_AutoBaudCapture ( uint32_t  instance)

LIN_LPUART capture time interval to set baudrate automatically when enable autobaud feature. This function should only be used in Slave. The timer should be in input capture mode of both rising and falling edges. The timer input capture pin should be externally connected to RXD pin.

Parameters
instanceLIN_LPUART instance number
Returns
operation status
  • STATUS_SUCCESS: Operation was successful.
  • STATUS_BUSY: Operation is running.
  • STATUS_ERROR: Operation failed due to break char incorrect, wakeup signal incorrect or calculate baudrate failed.

Definition at line 2058 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_AutobaudTimerValEval ( uint32_t  instance,
uint32_t  twoBitTimeLength 
)
static

Definition at line 1915 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_CheckWakeupSignal ( uint32_t  instance)
static

Definition at line 1446 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_Deinit ( uint32_t  instance)

Shuts down the LIN_LPUART by disabling interrupts and transmitter/receiver.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 307 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_DisableIRQ ( uint32_t  instance)

Disables LIN_LPUART hardware interrupts.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 1152 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_EnableIRQ ( uint32_t  instance)

Enables LIN_LPUART hardware interrupts.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 1106 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_EvalTwoBitTimeLength ( uint32_t  instance,
uint32_t  twoBitTimeLength 
)
static

Definition at line 2007 of file lin_lpuart_driver.c.

lin_node_state_t LIN_LPUART_DRV_GetCurrentNodeState ( uint32_t  instance)

Get the current LIN node state.

Parameters
instanceLIN_LPUART instance number
Returns
current LIN node state

Definition at line 897 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_GetReceiveStatus ( uint32_t  instance,
uint8_t *  bytesRemaining 
)

Get status of an on-going non-blocking reception While receiving frame data using non-blocking method, users can use this function to get status of that receiving. This function return the current event ID, STATUS_BUSY while receiving and return STATUS_SUCCESS, or timeout (STATUS_TIMEOUT) when the reception is complete. The bytesRemaining shows number of bytes that still needed to receive.

Parameters
instanceLIN_LPUART instance number
bytesRemainingNumber of bytes still needed to receive
Returns
status_t STATUS_BUSY, STATUS_TIMEOUT or STATUS_SUCCESS

Definition at line 788 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_GetTransmitStatus ( uint32_t  instance,
uint8_t *  bytesRemaining 
)

Get status of an on-going non-blocking transmission While sending frame data using non-blocking method, users can use this function to get status of that transmission. This function return STATUS_BUSY while sending, or STATUS_TIMEOUT if timeout has occurred, or return STATUS_SUCCESS when the transmission is complete. The bytesRemaining shows number of bytes that still needed to transmit.

Parameters
instanceLIN_LPUART instance number
bytesRemainingNumber of bytes still needed to transmit
Returns
status_t STATUS_BUSY, STATUS_SUCCESS or STATUS_TIMEOUT

Definition at line 556 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_GotoIdleState ( uint32_t  instance)

Puts current LIN node to Idle state This function changes current node state to LIN_NODE_STATE_IDLE.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 1198 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_GoToSleepMode ( uint32_t  instance)

This function puts current node to sleep mode This function changes current node state to LIN_NODE_STATE_SLEEP_MODE.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 826 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_Init ( uint32_t  instance,
lin_user_config_t linUserConfig,
lin_state_t linCurrentState 
)

Initializes an LIN_LPUART instance for LIN Network.

The caller provides memory for the driver state structures during initialization. The user must select the LIN_LPUART clock source in the application to initialize the LIN_LPUART. This function initializes a LPUART instance for operation. This function will initialize the run-time state structure to keep track of the on-going transfers, initialize the module to user defined settings and default settings, set break field length to be 13 bit times minimum, enable the break detect interrupt, Rx complete interrupt, frame error detect interrupt, and enable the LPUART module transmitter and receiver

Parameters
instanceLIN_LPUART instance number
linUserConfiguser configuration structure of type lin_user_config_t
linCurrentStatepointer to the LIN_LPUART driver state structure
Returns
An error code or status_t

Definition at line 134 of file lin_lpuart_driver.c.

lin_callback_t LIN_LPUART_DRV_InstallCallback ( uint32_t  instance,
lin_callback_t  function 
)

Installs callback function that is used for LIN_LPUART_DRV_IRQHandler.

Note
After a callback is installed, it bypasses part of the LIN_LPUART IRQHandler logic. Therefore, the callback needs to handle the indexes of txBuff and txSize.
Parameters
instanceThe LIN_LPUART instance number.
functionThe LIN_LPUART receive callback function.
Returns
Former LIN callback function pointer.

Definition at line 369 of file lin_lpuart_driver.c.

void LIN_LPUART_DRV_IRQHandler ( uint32_t  instance)

LIN_LPUART interrupt handler for RX_TX and Error interrupts.

Parameters
instanceLIN_LPUART instance number
Returns
void

Definition at line 1276 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_MasterSendHeader ( uint32_t  instance,
uint8_t  id 
)

Sends frame header out through the LIN_LPUART module using a non-blocking method. This function sends LIN Break field, sync field then the ID with correct parity. This function checks if the interface is Master, if not, it will return STATUS_ERROR.This function checks if id is in range from 0 to 0x3F, if not it will return STATUS_ERROR.

Parameters
instanceLIN_LPUART instance number
idFrame Identifier
Returns
An error code or status_t

Definition at line 1042 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_ProcessBreakDetect ( uint32_t  instance)
static

Definition at line 1378 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_ProcessFrame ( uint32_t  instance,
uint8_t  tmpByte 
)
static

Definition at line 1501 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_ProcessFrameHeader ( uint32_t  instance,
uint8_t  tmpByte 
)
static

Definition at line 1543 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_ProcessReceiveFrameData ( uint32_t  instance,
uint8_t  tmpByte 
)
static

Definition at line 1710 of file lin_lpuart_driver.c.

static void LIN_LPUART_DRV_ProcessSendFrameData ( uint32_t  instance,
uint8_t  tmpByte 
)
static

Definition at line 1790 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_RecvFrmData ( uint32_t  instance,
uint8_t *  rxBuff,
uint8_t  rxSize 
)

Receives frame data through the LIN_LPUART module using non-blocking method. This function returns immediately after initiating the receive function. The application has to get the receive status to see when the receive is complete. The interrupt handler LIN_LPUART_DRV_IRQHandler will check the checksum byte. If the checksum is correct, it will receive the frame data. If the checksum is incorrect, this function will return STATUS_TIMEOUT and data in rxBuff might be wrong. This function also check if rxSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY.

Parameters
instanceLIN_LPUART instance number
rxBuffbuffer containing 8-bit received data
rxSizethe number of bytes to receive
Returns
An error code or status_t

Definition at line 692 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_RecvFrmDataBlocking ( uint32_t  instance,
uint8_t *  rxBuff,
uint8_t  rxSize,
uint32_t  timeoutMSec 
)

Receives frame data through the LIN_LPUART module using blocking method. The function does not return until the receive is complete. The interrupt handler LIN_LPUART_DRV_IRQHandler will check the checksum byte. If the checksum is correct, it will receive the frame data. If the checksum is incorrect, this function will return STATUS_TIMEOUT and data in rxBuff might be wrong. This function also check if rxSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY.

Parameters
instanceLIN_LPUART instance number
rxBuffbuffer containing 8-bit received data
rxSizethe number of bytes to receive
timeoutMSectimeout value in milliseconds
Returns
An error code or status_t

Definition at line 601 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_SendFrameData ( uint32_t  instance,
const uint8_t *  txBuff,
uint8_t  txSize 
)

Sends frame data out through the LIN_LPUART module using non-blocking method. This enables an a-sync method for transmitting data. Non-blocking means that the function returns immediately. The application has to get the transmit status to know when the transmit is complete. This function will calculate the checksum byte and send it with the frame data. If txSize is equal to 0 or greater than 8 or node's current state is in SLEEP mode then the function will return STATUS_ERROR. If isBusBusy is currently true then the function will return STATUS_BUSY.

Parameters
instanceLIN_LPUART instance number
txBuffsource buffer containing 8-bit data chars to send
txSizethe number of bytes to send
Returns
An error code or status_t

Definition at line 485 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_SendFrameDataBlocking ( uint32_t  instance,
const uint8_t *  txBuff,
uint8_t  txSize,
uint32_t  timeoutMSec 
)

Sends Frame data out through the LIN_LPUART module using blocking method. This function will calculate the checksum byte and send it with the frame data. Blocking means that the function does not return until the transmission is complete. This function checks if txSize is in range from 1 to 8. If not, it will return STATUS_ERROR. This function also returns STATUS_ERROR if node's current state is in SLEEP mode. This function checks if the isBusBusy is false, if not it will return STATUS_BUSY. The function does not return until the transmission is complete. If the transmission is successful, it will return STATUS_SUCCESS. If not, it will return STATUS_TIMEOUT.

Parameters
instanceLIN_LPUART instance number
txBuffsource buffer containing 8-bit data chars to send
txSizethe number of bytes to send
timeoutMSectimeout value in milliseconds
Returns
An error code or status_t

Definition at line 400 of file lin_lpuart_driver.c.

status_t LIN_LPUART_DRV_SendWakeupSignal ( uint32_t  instance)

Sends a wakeup signal through the LIN_LPUART interface.

Parameters
instanceLIN_LPUART instance number
Returns
An error code or status_t

Definition at line 865 of file lin_lpuart_driver.c.

void LIN_LPUART_DRV_SetTimeoutCounter ( uint32_t  instance,
uint32_t  timeoutValue 
)

Set Value for Timeout Counter that is used in LIN_LPUART_DRV_TimeoutService.

Parameters
instanceLPUART instance number
timeoutValueTimeout Value to be set
Returns
void

Definition at line 1012 of file lin_lpuart_driver.c.

void LIN_LPUART_DRV_TimeoutService ( uint32_t  instance)

Callback function for Timer Interrupt Handler Users shall initialize a timer (for example FTM) in Output compare mode with period of 500 micro seconds. In timer IRQ handler, call this function.

Parameters
instanceLIN_LPUART instance number
Returns
void

Definition at line 924 of file lin_lpuart_driver.c.

static status_t LIN_LPUART_DRV_WaitComplete ( uint32_t  instance,
uint32_t  timeoutMSec 
)
static

Definition at line 1240 of file lin_lpuart_driver.c.

Variable Documentation

Table of base addresses for LPUART instances.

Definition at line 58 of file lin_lpuart_driver.c.

isr_t g_linLpuartIsrs[LPUART_INSTANCE_COUNT]

Definition at line 86 of file lin_irq.c.

const IRQn_Type g_linLpuartRxTxIrqId[LPUART_INSTANCE_COUNT] = LPUART_RX_TX_IRQS

Table to save LPUART IRQ enumeration numbers defined in the device header file.

Definition at line 61 of file lin_lpuart_driver.c.

lin_state_t* g_linStatePtr[LPUART_INSTANCE_COUNT] = {NULL}

Table to save LPUART state structure pointers.

Definition at line 69 of file lin_lpuart_driver.c.

lin_user_config_t* g_linUserconfigPtr[LPUART_INSTANCE_COUNT] = {NULL}

Table to save LIN user config structure pointers.

Definition at line 72 of file lin_lpuart_driver.c.

uint8_t s_countMeasure[LPUART_INSTANCE_COUNT] = {0U}
static

Definition at line 87 of file lin_lpuart_driver.c.

uint32_t s_previousTwoBitTimeLength[LPUART_INSTANCE_COUNT] = {0U}
static

Definition at line 85 of file lin_lpuart_driver.c.

uint32_t s_timeMeasure[LPUART_INSTANCE_COUNT] = {0U}
static

Definition at line 88 of file lin_lpuart_driver.c.

uint8_t s_wakeupSignal[LPUART_INSTANCE_COUNT] = {0U}
static

Definition at line 86 of file lin_lpuart_driver.c.