Detailed Description

This section describes the programming interface of the Peripheral driver for LIN.

LIN Driver Overview

The LIN (Local Interconnect Network) Driver is an use-case driven High Level Peripheral Driver. The driver is built on HAL drivers and provides users important key features. NXP provides LIN Stack as a middleware software package that is developed on LIN driver. Users also can create their own LIN applications and LIN stack that are compatible with LIN Specification.
In this release package, LIN Driver is built on LPUART interface.

LIN Driver Device structures

The driver uses instantiations of the lin_state_t to maintain the current state of a particular LIN Hardware instance module driver.
The user is required to provide memory for the driver state structures during the initialization. The driver itself does not statically allocate memory.

LIN Driver Initialization

  1. To initialize the LIN driver, call the LIN_DRV_Init() function and pass the instance number of the relevant LIN hardware interface instance which is LPUART instance in this release.
    For example: to use LPUART0 pass value 0 to the initialization function.
  2. Pass a user configuration structure lin_user_config_t as shown here:
    /* LIN Driver configuration structure */
    typedef struct {
    uint32_t baudRate;
    bool nodeFunction;
    bool autobaudEnable;
    lin_timer_get_time_interval_t timerGetTimeIntervalCallback;
  3. For LIN, typically the user configures the lin_user_config_t instantiation with a baudrate from 1000bps to 20000bps.
    -E.g. 19200 bps linUserConfig.baudRate = 19200U.
  4. Node function can be MASTER or SLAVE.
    -E.g. linUserConfig.nodeFunction = MASTER
  5. If users do not want to use Autobaud feature, then just configure linUserConfig.autobaudEnable = FALSE.
  6. Users shall assign measurement callback function pointer that is timerGetTimeIntervalCallback. This function must return time period between two consecutive calls in nano seconds with accuracy at least 0.1 microsecond and if this function is called for the first time, it will start the timer to measure time. When an event (such as detecting a falling edge of a dominant signal while node is in sleep mode) occurs, LIN driver will call timerGetTimeIntervalCallback to start time measurement. Then on rising edge of that signal, LIN driver will call timerGetTimeIntervalCallback function to get time interval of that dominant signal in nano seconds. If Autobaud feature is enabled, LIN driver uses timerGetTimeIntervalCallback to measure two bit time length between two consecutive falling edges of the sync byte in order to evaluate Master's baudrate. Users can implement this function in their applications. -E.g. linUserConfig.timerGetTimeIntervalCallback = timerGetTimeIntervalCallback0; This is a code example to set up a FTM0 for LIN Driver:
    /* Global variables */
    uint16_t timerCounterValue[2] = {0u};
    uint16_t timerOverflowInterruptCount = 0u;
    /* Callback function to get time interval in nano seconds */
    uint32_t timerGetTimeIntervalCallback0(uint32_t *ns)
    {
    timerCounterValue[1] = (uint16_t)(ftmBase->CNT);
    *ns = ((uint32_t)(timerCounterValue[1] + timerOverflowInterruptCount*65536u - timerCounterValue[0]))*1000 / TIMER_1US;
    timerOverflowInterruptCount = 0U;
    timerCounterValue[0] = timerCounterValue[1];
    return 0U;
    }
  7. This is a code example to set up a user LIN Driver configuration instantiation:
    /* Device instance number as LPUART instance*/
    #define LI0 (0U)
    lin_state_t linState;
    lin_user_config_t linUserConfig;
    /* Set baudrate 19200 bps */
    linUserConfig.baudRate = 19200U;
    /* Node is MASTER */
    linUserConfig.nodeFunction = MASTER;
    /* Disable autobaud feature */
    linUserConfig.autobaudEnable = FALSE;
    /* Callback function to get time interval in nano seconds */
    linUserConfig.timerGetTimeIntervalCallback = (lin_timer_get_time_t) timerGetTimeIntervalCallback0;
    /* Initialize LIN Hardware interface */
    LIN_DRV_Init(LI0, (lin_user_config_t *) &linUserConfig, (lin_state_t *) &linState);
  8. The users are required to initialize a timer for LIN.
    E.g. a Flex Timer (FTM). FTM instance should be initialized in Output Compare mode with an interrupt(E.g. FTM0_Ch0_Ch1_IRQHandler) period of about 500 us. Users can choose a different interrupt period that is appropriate to their applications. In timer interrupt handler, users shall call LIN_DRV_TimeoutService to handle linCurrentState->timeoutCounter while sending or receiving data.

LIN Data Transfers

The driver implements transmit and receive functions to transfer buffers of data by blocking and non-blocking modes.

The blocking transmit and receive functions include LIN_DRV_SendFrameDataBlocking() and the LIN_DRV_ReceiveFrameDataBlocking() functions.

The non-blocking (async) transmit and receive functions include the LIN_DRV_SendFrameData() and the LIN_DRV_ReceiveFrameData() functions.

The LIN_DRV_ReceiveFrameData() function is recommended to be called in an interrupt event of receiving PID as implemented in LIN Stack middleware.

The LIN_DRV_ReceiveFrameData() function should be called before data is transferring on the LIN bus. The LIN_DRV_ReceiveFrameDataBlocking() function should be called before frame is transferring on the LIN bus. Otherwise, some data may be lost.

Master nodes can transmit frame headers in non-blocking mode using LIN_DRV_MasterSendHeader().

In all these cases, the functions are interrupt-driven.

Autobaud feature

AUTOBAUD is an extensive feature in LIN Driver which allows a slave node to automatically detect baudrate of LIN bus and adapt its original baudrate to bus value. Auto Baud is applied when the baudrate of the incoming data is unknown. Currently autobaud feature is supported to detect LIN bus baudrates 2400, 4800, 9600, 14400, 19200 bps.

  1. If autobaud feature is enabled, at LIN driver initialization slave's baudrate is set to 19200bps. The application should use a timer interrupt in input capture mode of both rising and falling edges(E.g FTM), call LIN_DRV_AutoBaudCapture(uint32_t instance) function to calculate and set Slave's baudrate like Master's baudrate. When receiving a frame header, the slave detect LIN bus's baudrate based on the synchronization byte and adapts its baudrate accordingly. On changing baudrate, the slave set current event ID to LIN_BAUDRATE_ADJUSTED and call the callback function. In that callback function users might change the frame data count timeout. Users can look at CallbackHandler() in lin.c of lin middleware for a reference.

    Note: Lin driver should be initiated before initiating a timer interrupt( E.g FTM).

  2. Baudrate evaluation process is executed until autobaud successfully. During run-time if LIN bus's baudrate is changed suddenly to a value other than the slave's current baudrate, users shall reset MCU to execute baudrate evaluation process.

Data Structures

struct  lin_user_config_t
 LIN hardware configuration structure Implements : lin_user_config_t_Class. More...
 
struct  lin_state_t
 Runtime state of the LIN driver. More...
 

Macros

#define SLAVE   0U
 
#define MASTER   1U
 
#define MAKE_PARITY   0U
 
#define CHECK_PARITY   1U
 

Typedefs

typedef uint32_t(* lin_timer_get_time_interval_t) (uint32_t *nanoSeconds)
 Callback function to get time interval in nanoseconds Implements : lin_timer_get_time_interval_t_Class. More...
 
typedef void(* lin_callback_t) (uint32_t instance, void *linState)
 LIN Driver callback function type Implements : lin_callback_t_Class. More...
 

Enumerations

enum  lin_event_id_t {
  LIN_NO_EVENT = 0x00U, LIN_WAKEUP_SIGNAL = 0x01U, LIN_BAUDRATE_ADJUSTED = 0x02U, LIN_RECV_BREAK_FIELD_OK = 0x03U,
  LIN_SYNC_OK = 0x04U, LIN_SYNC_ERROR = 0x05U, LIN_PID_OK = 0x06U, LIN_PID_ERROR = 0x07U,
  LIN_FRAME_ERROR = 0x08U, LIN_READBACK_ERROR = 0x09U, LIN_CHECKSUM_ERROR = 0x0AU, LIN_TX_COMPLETED = 0x0BU,
  LIN_RX_COMPLETED = 0x0CU, LIN_RX_OVERRUN = 0x0DU
}
 Defines types for an enumerating event related to an Identifier. Implements : lin_event_id_t_Class. More...
 
enum  lin_node_state_t {
  LIN_NODE_STATE_UNINIT = 0x00U, LIN_NODE_STATE_SLEEP_MODE = 0x01U, LIN_NODE_STATE_IDLE = 0x02U, LIN_NODE_STATE_SEND_BREAK_FIELD = 0x03U,
  LIN_NODE_STATE_RECV_SYNC = 0x04U, LIN_NODE_STATE_SEND_PID = 0x05U, LIN_NODE_STATE_RECV_PID = 0x06U, LIN_NODE_STATE_RECV_DATA = 0x07U,
  LIN_NODE_STATE_RECV_DATA_COMPLETED = 0x08U, LIN_NODE_STATE_SEND_DATA = 0x09U, LIN_NODE_STATE_SEND_DATA_COMPLETED = 0x0AU
}
 Define type for an enumerating LIN Node state. Implements : lin_node_state_t_Class. More...
 

LIN DRIVER

status_t LIN_DRV_Init (uint32_t instance, lin_user_config_t *linUserConfig, lin_state_t *linCurrentState)
 Initializes an instance LIN Hardware Interface for LIN Network. More...
 
status_t LIN_DRV_Deinit (uint32_t instance)
 Shuts down the LIN Hardware Interface by disabling interrupts and transmitter/receiver. More...
 
lin_callback_t LIN_DRV_InstallCallback (uint32_t instance, lin_callback_t function)
 Installs callback function that is used for LIN_DRV_IRQHandler. More...
 
status_t LIN_DRV_SendFrameDataBlocking (uint32_t instance, const uint8_t *txBuff, uint8_t txSize, uint32_t timeoutMSec)
 Sends Frame data out through the LIN Hardware Interface 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 LIN_BUS_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_DRV_SendFrameData (uint32_t instance, const uint8_t *txBuff, uint8_t txSize)
 Sends frame data out through the LIN Hardware Interface 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. The function will return immediately after calling this function. 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 LIN_BUS_BUSY. More...
 
status_t LIN_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. The bytesRemaining shows number of bytes that still needed to transmit. More...
 
status_t LIN_DRV_ReceiveFrameDataBlocking (uint32_t instance, uint8_t *rxBuff, uint8_t rxSize, uint32_t timeoutMSec)
 Receives frame data through the LIN Hardware Interface using blocking method. This function receives data from 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 LIN_BUS_BUSY. More...
 
status_t LIN_DRV_ReceiveFrameData (uint32_t instance, uint8_t *rxBuff, uint8_t rxSize)
 Receives frame data through the LIN Hardware Interface using non-blocking method. This function will check the checksum byte. If the checksum is correct, it will receive it with the frame data. Non-blocking means that the function returns immediately. The application has to get the receive status to know when the reception 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 LIN_BUS_BUSY. More...
 
status_t LIN_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_DRV_GetReceiveStatus (uint32_t instance, uint8_t *bytesRemaining)
 Get status of an on-going non-blocking reception. This function returns whether the data reception is complete. When performing non-blocking transmit, the user can call this function to ascertain the state of the current receive progress: in progress (STATUS_BUSY) or timeout (STATUS_TIMEOUT) or complete (STATUS_SUCCESS). In addition, if the reception is still in progress, the user can obtain the number of bytes that still needed to receive. More...
 
status_t LIN_DRV_GoToSleepMode (uint32_t instance)
 Puts current LIN node to sleep mode This function changes current node state to LIN_NODE_STATE_SLEEP_MODE. More...
 
status_t LIN_DRV_GotoIdleState (uint32_t instance)
 Puts current LIN node to Idle state This function changes current node state to LIN_NODE_STATE_IDLE. More...
 
status_t LIN_DRV_SendWakeupSignal (uint32_t instance)
 Sends a wakeup signal through the LIN Hardware Interface. More...
 
lin_node_state_t LIN_DRV_GetCurrentNodeState (uint32_t instance)
 Get the current LIN node state. More...
 
void LIN_DRV_TimeoutService (uint32_t instance)
 Callback function for Timer Interrupt Handler Users may use (optional, not required) LIN_DRV_TimeoutService to check if timeout has occurred during non-blocking frame data transmission and reception. User may initialize a timer (for example FTM) in Output Compare Mode with period of 500 micro seconds (recommended). In timer IRQ handler, call this function. More...
 
void LIN_DRV_SetTimeoutCounter (uint32_t instance, uint32_t timeoutValue)
 Set Value for Timeout Counter that is used in LIN_DRV_TimeoutService. More...
 
status_t LIN_DRV_MasterSendHeader (uint32_t instance, uint8_t id)
 Sends frame header out through the LIN Hardware Interface 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_DRV_EnableIRQ (uint32_t instance)
 Enables LIN hardware interrupts. More...
 
status_t LIN_DRV_DisableIRQ (uint32_t instance)
 Disables LIN hardware interrupts. More...
 
void LIN_DRV_IRQHandler (uint32_t instance)
 Interrupt handler for LIN Hardware Interface. More...
 
uint8_t LIN_DRV_ProcessParity (uint8_t PID, uint8_t typeAction)
 Makes or checks parity bits. If action is checking parity, the function returns ID value if parity bits are correct or 0xFF if parity bits are incorrect. If action is making parity bits, then from input value of ID, the function returns PID. This is not a public API as it is called by other API functions. More...
 
uint8_t LIN_DRV_MakeChecksumByte (const uint8_t *buffer, uint8_t sizeBuffer, uint8_t PID)
 Makes the checksum byte for a frame. More...
 
status_t LIN_DRV_AutoBaudCapture (uint32_t instance)
 Captures time interval to capture 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...
 

Macro Definition Documentation

#define CHECK_PARITY   1U

Definition at line 53 of file lin_driver.h.

#define MAKE_PARITY   0U

Definition at line 52 of file lin_driver.h.

#define MASTER   1U

Definition at line 51 of file lin_driver.h.

#define SLAVE   0U

Definition at line 50 of file lin_driver.h.

Typedef Documentation

typedef void(* lin_callback_t) (uint32_t instance, void *linState)

LIN Driver callback function type Implements : lin_callback_t_Class.

Definition at line 116 of file lin_driver.h.

typedef uint32_t(* lin_timer_get_time_interval_t) (uint32_t *nanoSeconds)

Callback function to get time interval in nanoseconds Implements : lin_timer_get_time_interval_t_Class.

Definition at line 60 of file lin_driver.h.

Enumeration Type Documentation

Defines types for an enumerating event related to an Identifier. Implements : lin_event_id_t_Class.

Enumerator
LIN_NO_EVENT 

No event yet

LIN_WAKEUP_SIGNAL 

Received a wakeup signal

LIN_BAUDRATE_ADJUSTED 

Indicate that baudrate was adjusted to Master's baudrate

LIN_RECV_BREAK_FIELD_OK 

Indicate that correct Break Field was received

LIN_SYNC_OK 

Sync byte is correct

LIN_SYNC_ERROR 

Sync byte is incorrect

LIN_PID_OK 

PID correct

LIN_PID_ERROR 

PID incorrect

LIN_FRAME_ERROR 

Framing Error

LIN_READBACK_ERROR 

Readback data is incorrect

LIN_CHECKSUM_ERROR 

Checksum byte is incorrect

LIN_TX_COMPLETED 

Sending data completed

LIN_RX_COMPLETED 

Receiving data completed

LIN_RX_OVERRUN 

RX overrun flag

Definition at line 77 of file lin_driver.h.

Define type for an enumerating LIN Node state. Implements : lin_node_state_t_Class.

Enumerator
LIN_NODE_STATE_UNINIT 

Uninitialized state

LIN_NODE_STATE_SLEEP_MODE 

Sleep mode state

LIN_NODE_STATE_IDLE 

Idle state

LIN_NODE_STATE_SEND_BREAK_FIELD 

Send break field state

LIN_NODE_STATE_RECV_SYNC 

Receive the synchronization byte state

LIN_NODE_STATE_SEND_PID 

Send PID state

LIN_NODE_STATE_RECV_PID 

Receive PID state

LIN_NODE_STATE_RECV_DATA 

Receive data state

LIN_NODE_STATE_RECV_DATA_COMPLETED 

Receive data completed state

LIN_NODE_STATE_SEND_DATA 

Send data state

LIN_NODE_STATE_SEND_DATA_COMPLETED 

Send data completed state

Definition at line 98 of file lin_driver.h.

Function Documentation

status_t LIN_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 Hardware Interface instance number
Returns
function always return STATUS_SUCCESS

Definition at line 257 of file lin_driver.c.

status_t LIN_DRV_AutoBaudCapture ( uint32_t  instance)

Captures time interval to capture 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 Hardware Interface 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 484 of file lin_driver.c.

status_t LIN_DRV_Deinit ( uint32_t  instance)

Shuts down the LIN Hardware Interface by disabling interrupts and transmitter/receiver.

Parameters
instanceLIN Hardware Interface instance number
Returns
operation status:
  • STATUS_SUCCESS : Operation was successful.
  • STATUS_ERROR : Operation failed due to destroy TX and RX semaphores.

Definition at line 83 of file lin_driver.c.

status_t LIN_DRV_DisableIRQ ( uint32_t  instance)

Disables LIN hardware interrupts.

Parameters
instanceLIN Hardware Interface instance number
Returns
function always return STATUS_SUCCESS.

Definition at line 446 of file lin_driver.c.

status_t LIN_DRV_EnableIRQ ( uint32_t  instance)

Enables LIN hardware interrupts.

Parameters
instanceLIN Hardware Interface instance number.
Returns
function always return STATUS_SUCCESS.

Definition at line 428 of file lin_driver.c.

lin_node_state_t LIN_DRV_GetCurrentNodeState ( uint32_t  instance)

Get the current LIN node state.

Parameters
instanceLIN Hardware Interface instance number
Returns
current LIN node state

Definition at line 354 of file lin_driver.c.

status_t LIN_DRV_GetReceiveStatus ( uint32_t  instance,
uint8_t *  bytesRemaining 
)

Get status of an on-going non-blocking reception. This function returns whether the data reception is complete. When performing non-blocking transmit, the user can call this function to ascertain the state of the current receive progress: in progress (STATUS_BUSY) or timeout (STATUS_TIMEOUT) or complete (STATUS_SUCCESS). In addition, if the reception is still in progress, the user can obtain the number of bytes that still needed to receive.

Parameters
instanceLIN Hardware Interface instance number
bytesRemainingNumber of bytes still needed to receive
Returns
operation status:
  • STATUS_SUCCESS : The reception is complete.
  • STATUS_TIMEOUT : The reception isn't complete.
  • STATUS_BUSY : The reception is on going

Definition at line 280 of file lin_driver.c.

status_t LIN_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. The bytesRemaining shows number of bytes that still needed to transmit.

Parameters
instanceLIN Hardware Interface instance number
bytesRemainingNumber of bytes still needed to transmit
Returns
operation status:
  • STATUS_SUCCESS : The transmission is successful.
  • STATUS_BUSY : The transmission is sending
  • STATUS_TIMEOUT : Operation failed due to timeout has occurred.

Definition at line 178 of file lin_driver.c.

status_t LIN_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 Hardware Interface instance number
Returns
function always return STATUS_SUCCESS

Definition at line 318 of file lin_driver.c.

status_t LIN_DRV_GoToSleepMode ( uint32_t  instance)

Puts current LIN node to sleep mode This function changes current node state to LIN_NODE_STATE_SLEEP_MODE.

Parameters
instanceLIN Hardware Interface instance number
Returns
function always return STATUS_SUCCESS

Definition at line 300 of file lin_driver.c.

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

Initializes an instance LIN Hardware Interface for LIN Network.

The caller provides memory for the driver state structures during initialization. The user must select the LIN Hardware Interface clock source in the application to initialize the LIN Hardware Interface.

Parameters
instanceLIN Hardware Interface instance number
linUserConfiguser configuration structure of type lin_user_config_t
linCurrentStatepointer to the LIN Hardware Interface driver state structure
Returns
operation status:
  • STATUS_SUCCESS : Operation was successful.
  • STATUS_ERROR : Operation failed due to semaphores initialize error.

Definition at line 62 of file lin_driver.c.

lin_callback_t LIN_DRV_InstallCallback ( uint32_t  instance,
lin_callback_t  function 
)

Installs callback function that is used for LIN_DRV_IRQHandler.

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

Definition at line 102 of file lin_driver.c.

void LIN_DRV_IRQHandler ( uint32_t  instance)

Interrupt handler for LIN Hardware Interface.

Parameters
instanceLIN Hardware Interface instance number
Returns
void

Definition at line 466 of file lin_driver.c.

uint8_t LIN_DRV_MakeChecksumByte ( const uint8_t *  buffer,
uint8_t  sizeBuffer,
uint8_t  PID 
)

Makes the checksum byte for a frame.

Parameters
bufferPointer to Tx buffer
sizeBufferNumber of bytes that are contained in the buffer.
PIDProtected Identifier byte.
Returns
the checksum byte.

Definition at line 102 of file lin_common.c.

status_t LIN_DRV_MasterSendHeader ( uint32_t  instance,
uint8_t  id 
)

Sends frame header out through the LIN Hardware Interface 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 Hardware Interface instance number
idFrame Identifier
Returns
operation status:
  • STATUS_SUCCESS : The transmission is successful.
  • STATUS_BUSY : Bus busy flag is true.
  • STATUS_ERROR : The interface isn't Master or id isn't in range from 0 to 0x3F or node's current state is in SLEEP mode.

Definition at line 409 of file lin_driver.c.

uint8_t LIN_DRV_ProcessParity ( uint8_t  PID,
uint8_t  typeAction 
)

Makes or checks parity bits. If action is checking parity, the function returns ID value if parity bits are correct or 0xFF if parity bits are incorrect. If action is making parity bits, then from input value of ID, the function returns PID. This is not a public API as it is called by other API functions.

Parameters
PIDPID byte in case of checking parity bits or ID byte in case of making parity bits.
typeAction1 for Checking parity bits, 0 for making parity bits
Returns
Value has 8 bit:
  • 0xFF : Parity bits are incorrect,
  • ID : Checking parity bits are correct.
  • PID : typeAction is making parity bits.

Definition at line 58 of file lin_common.c.

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

Receives frame data through the LIN Hardware Interface using non-blocking method. This function will check the checksum byte. If the checksum is correct, it will receive it with the frame data. Non-blocking means that the function returns immediately. The application has to get the receive status to know when the reception 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 LIN_BUS_BUSY.

Note
If users use LIN_DRV_TimeoutService in a timer interrupt handler, then before using this function, users have to set timeout counter to an appropriate value by using LIN_DRV_SetTimeoutCounter(instance, timeoutValue). The timeout value should be big enough to complete the reception. Timeout in real time is (timeoutValue) * (time period that LIN_DRV_TimeoutService is called). For example, if LIN_DRV_TimeoutService is called in an timer interrupt with period of 500 micro seconds, then timeout in real time is timeoutValue * 500 micro seconds.
Parameters
instanceLIN Hardware Interface instance number
rxBuffbuffer containing 8-bit received data
rxSizethe number of bytes to receive
Returns
operation status:
  • STATUS_SUCCESS : The receives frame data is successful.
  • STATUS_TIMEOUT : The checksum is incorrect.
  • STATUS_BUSY : Bus busy flag is true.
  • STATUS_ERROR : Operation failed due is equal to 0 or greater than 8 or node's current state is in SLEEP mode

Definition at line 235 of file lin_driver.c.

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

Receives frame data through the LIN Hardware Interface using blocking method. This function receives data from 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 LIN_BUS_BUSY.

Parameters
instanceLIN Hardware Interface instance number
rxBuffbuffer containing 8-bit received data
rxSizethe number of bytes to receive
timeoutMSectimeout value in milliseconds
Returns
operation status:
  • STATUS_SUCCESS : The receives frame data is successful.
  • STATUS_TIMEOUT : The checksum is incorrect.
  • STATUS_BUSY : Bus busy flag is true.
  • STATUS_ERROR : Operation failed due is equal to 0 or greater than 8 or node's current state is in SLEEP mode

Definition at line 205 of file lin_driver.c.

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

Sends frame data out through the LIN Hardware Interface 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. The function will return immediately after calling this function. 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 LIN_BUS_BUSY.

Note
If users use LIN_DRV_TimeoutService in a timer interrupt handler, then before using this function, users have to set timeout counter to an appropriate value by using LIN_DRV_SetTimeoutCounter(instance, timeoutValue). The timeout value should be big enough to complete the transmission. Timeout in real time is (timeoutValue) * (time period that LIN_DRV_TimeoutService is called). For example, if LIN_DRV_TimeoutService is called in an timer interrupt with period of 500 micro seconds, then timeout in real time is timeoutValue * 500 micro seconds.
Parameters
instanceLIN Hardware Interface instance number
txBuffsource buffer containing 8-bit data chars to send
txSizethe number of bytes to send
Returns
operation status:
  • STATUS_SUCCESS : The transmission is successful.
  • STATUS_BUSY : Operation failed due to isBusBusy is currently true.
  • STATUS_ERROR : Operation failed due to txSize is equal to 0 or greater than 8 or node's current state is in SLEEP mode

Definition at line 153 of file lin_driver.c.

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

Sends Frame data out through the LIN Hardware Interface 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 LIN_BUS_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 Hardware Interface instance number
txBuffsource buffer containing 8-bit data chars to send
txSizethe number of bytes to send
timeoutMSectimeout value in milliseconds
Returns
operation status:
  • STATUS_SUCCESS : The transmission is successful.
  • STATUS_TIMEOUT : The transmission isn't successful.

Definition at line 128 of file lin_driver.c.

status_t LIN_DRV_SendWakeupSignal ( uint32_t  instance)

Sends a wakeup signal through the LIN Hardware Interface.

Parameters
instanceLIN Hardware Interface instance number
Returns
operation status:
  • STATUS_SUCCESS : Bus busy flag is false.
  • STATUS_BUSY : Bus busy flag is true.

Definition at line 336 of file lin_driver.c.

void LIN_DRV_SetTimeoutCounter ( uint32_t  instance,
uint32_t  timeoutValue 
)

Set Value for Timeout Counter that is used in LIN_DRV_TimeoutService.

Parameters
instanceLIN Hardware Interface instance number
timeoutValueTimeout Value to be set
Returns
void

Definition at line 389 of file lin_driver.c.

void LIN_DRV_TimeoutService ( uint32_t  instance)

Callback function for Timer Interrupt Handler Users may use (optional, not required) LIN_DRV_TimeoutService to check if timeout has occurred during non-blocking frame data transmission and reception. User may initialize a timer (for example FTM) in Output Compare Mode with period of 500 micro seconds (recommended). In timer IRQ handler, call this function.

Parameters
instanceLIN Hardware Interface instance number
Returns
void

Definition at line 374 of file lin_driver.c.