LIN HAL API
Module: HAL (AM13E232X) API
Structures
Name |
|
|---|---|
struct |
Lin_Hal_InitParamsType |
struct |
Lin_Hal_TransferParamsType |
struct |
Lin_Hal_InstanceType |
struct |
Lin_Hal_TransactionStatusType |
Types
Name |
|
|---|---|
enum |
Lin_Hal_StateType { LIN_HAL_STATE_UNCONFIGURED = 0U, LIN_HAL_STATE_READY, LIN_HAL_STATE_TRANSFER} |
enum |
Lin_Hal_ModeType { LIN_HAL_MODE_TARGET = 0U, LIN_HAL_MODE_CONTROLLER} |
enum |
Lin_Hal_HeaderStateType { LIN_HAL_HEADER_STATE_WAIT_FOR_BREAK = 0U, LIN_HAL_HEADER_STATE_BREAK_FIELD, LIN_HAL_HEADER_STATE_SYNC_FIELD_NEG_EDGE, LIN_HAL_HEADER_STATE_SYNC_FIELD_POS_EDGE, LIN_HAL_HEADER_STATE_PID_FIELD, LIN_HAL_HEADER_STATE_DATA_FIELD} |
enum |
Lin_Hal_TxPhaseType { LIN_HAL_TX_PHASE_SYNC = 0U, LIN_HAL_TX_PHASE_PID, LIN_HAL_TX_PHASE_DATA, LIN_HAL_TX_PHASE_CHECKSUM, LIN_HAL_TX_PHASE_DONE} |
Functions
Name |
|
|---|---|
Lin_Hal_InitParamsSetDefault(Lin_Hal_InitParamsType * paramsPtr) |
|
Lin_Hal_TransferParamsSetDefault(Lin_Hal_TransferParamsType * paramsPtr) |
|
Lin_Hal_Init(Lin_Hal_InstanceType * instancePtr, const Lin_Hal_InitParamsType * paramsPtr) |
|
Lin_Hal_ControllerTransferPolling(Lin_Hal_InstanceType * instancePtr, const Lin_Hal_TransferParamsType * paramsPtr) |
|
Lin_Hal_ControllerContinuePolling(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransactionStatusType * statusPtr) |
|
Lin_Hal_ControllerTransferInterrupt(Lin_Hal_InstanceType * instancePtr, const Lin_Hal_TransferParamsType * paramsPtr) |
|
void |
Lin_Hal_InterruptHandler(Lin_Hal_InstanceType * instancePtr) |
void |
Lin_Hal_TxCompleteCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransactionStatusType * statusPtr, void * userArgsPtr) |
void |
Lin_Hal_RxCompleteCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransactionStatusType * statusPtr, void * userArgsPtr) |
void |
Lin_Hal_TargetHeaderReceivedCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransferParamsType * paramsPtr, void * userArgsPtr) |
void |
Lin_Hal_ErrorCallback(Lin_Hal_InstanceType * instancePtr, uint32 errorCode, void * userArgsPtr) |
Lin_Hal_TargetSetStop(Lin_Hal_InstanceType * instancePtr) |
|
Lin_Hal_DeInit(Lin_Hal_InstanceType * instancePtr) |
Defines
Name |
|
|---|---|
LIN_HAL_ERROR_NONE |
|
LIN_HAL_ERROR_INVALID_INSTANCE |
|
LIN_HAL_ERROR_INVALID_PARAMS |
|
LIN_HAL_ERROR_UNSUPPORTED_FEATURE |
|
LIN_HAL_ERROR_HW_BUSY |
|
LIN_HAL_TRANSFER_ERROR_BIT_ERROR |
|
LIN_HAL_TRANSFER_ERROR_CHECKSUM_ERROR |
|
LIN_HAL_TRANSFER_ERROR_TIMEOUT_ERROR |
|
LIN_HAL_TRANSFER_ERROR_PARITY_ERROR |
|
LIN_HAL_TRANSFER_ERROR_INVALID_PARAMS |
|
LIN_HAL_TRANSFER_ERROR_INVALID_RECEIVED_LENGTH |
|
LIN_HAL_TRANSFER_ERROR_INVALID_BUFFER |
|
LIN_HAL_MODE_TYPE_COUNT |
|
LIN_HAL_TX_PHASE_TYPE_COUNT |
Detailed Description
Note:
All transfer APIs are non-blocking unless specified otherwise, i.e they dont wait for the RX/TX operation to complete.
On this device, LIN runs over the UART/UNICOMM peripheral; timing is configured via BaudRateBps and InputClockHz.
For a given LIN instance, the APIs to use depends on the operation mode - controller or target that is needed. Only APIs valid in a operation mode should be used by the application, else behavior is undefined.
Target is only supported in interrupt mode, transfer from target side is invoked within Lin_Hal_InterruptHandler after a header frame is received from Controller. Lin_Hal_TargetHeaderReceivedCallback is used to fill the transfer parameter that is used during transfer.
For Controller the below two modes are used for transfer using LIN transfer APIs
Polling mode
APIs to use for data transfer Lin_Hal_ControllerTransferPolling
APIs to use to continue transfer of remaining data in polling mode and check transfer status
Lin_Hal_ControllerContinuePolling is called in polling mode to wait for completion of the transaction
Lin_Hal_InterruptHandler MUST not be registered to CPU interrupt line
Lin_Hal_TxCompleteCallback, is not called in this mode
Interrupt mode
APIs to use for data transfer Lin_Hal_ControllerTransferInterrupt
APIs to use to check for transfer completion,
Lin_Hal_TxCompleteCallback is called when the transmit completes
Lin_Hal_RxCompleteCallback is called when the receive completes
Lin_Hal_ErrorCallback is called in case of any error during transfer
Additional callbacks that can get called are Lin_Hal_TargetHeaderReceivedCallback
Lin_Hal_InterruptHandler MUST be called as part of the ISR registered to CPU interrupt line
Lin_Hal_ControllerContinuePolling should NOT be used
Types Documentation
enum Lin_Hal_StateType
Enumerator |
Value |
Description |
|---|---|---|
LIN_HAL_STATE_UNCONFIGURED |
0U |
|
LIN_HAL_STATE_READY |
||
LIN_HAL_STATE_TRANSFER |
LIN instance states.
enum Lin_Hal_ModeType
Enumerator |
Value |
Description |
|---|---|---|
LIN_HAL_MODE_TARGET |
0U |
|
LIN_HAL_MODE_CONTROLLER |
LIN operational mode.
enum Lin_Hal_HeaderStateType
Enumerator |
Value |
Description |
|---|---|---|
LIN_HAL_HEADER_STATE_WAIT_FOR_BREAK |
0U |
|
LIN_HAL_HEADER_STATE_BREAK_FIELD |
||
LIN_HAL_HEADER_STATE_SYNC_FIELD_NEG_EDGE |
||
LIN_HAL_HEADER_STATE_SYNC_FIELD_POS_EDGE |
||
LIN_HAL_HEADER_STATE_PID_FIELD |
||
LIN_HAL_HEADER_STATE_DATA_FIELD |
Target-mode header detection state.
LIN header detection is implemented in software by monitoring RXD transitions. A valid LIN header consists of: BREAK field (RXD low for >= 9.5 Tbit), SYNC byte (validates bit timing), and PID.
enum Lin_Hal_TxPhaseType
Enumerator |
Value |
Description |
|---|---|---|
LIN_HAL_TX_PHASE_SYNC |
0U |
|
LIN_HAL_TX_PHASE_PID |
||
LIN_HAL_TX_PHASE_DATA |
||
LIN_HAL_TX_PHASE_CHECKSUM |
||
LIN_HAL_TX_PHASE_DONE |
Software transmit progress, independent of received header state.
Functions Documentation
function Lin_Hal_InitParamsSetDefault
sint32 Lin_Hal_InitParamsSetDefault(
Lin_Hal_InitParamsType * paramsPtr
)
Initializes the LIN module with Default Parameters.
Parameters:
paramsPtr Pointer to LIN HW initialization parameters
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
function Lin_Hal_TransferParamsSetDefault
sint32 Lin_Hal_TransferParamsSetDefault(
Lin_Hal_TransferParamsType * paramsPtr
)
Initializes the transfer params structure with Default Parameters.
Parameters:
paramsPtr Pointer to LIN transfer parameters
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
function Lin_Hal_Init
sint32 Lin_Hal_Init(
Lin_Hal_InstanceType * instancePtr,
const Lin_Hal_InitParamsType * paramsPtr
)
Initialize a LIN HW instance.
Parameters:
instancePtr Pointer to LIN HW instance
paramsPtr Pointer to LIN HW initialization parameters
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
Initializes the LIN hardware instance with the provided configuration parameters. The function configures timing parameters, operating parameters and prepares hardware for transmission.
For target mode, make sure to register interrupt handler Lin_Hal_InterruptHandler after Lin_Hal_Init
function Lin_Hal_ControllerTransferPolling
sint32 Lin_Hal_ControllerTransferPolling(
Lin_Hal_InstanceType * instancePtr,
const Lin_Hal_TransferParamsType * paramsPtr
)
In controller mode, transfer a frame of LIN data in Polling mode.
Parameters:
instancePtr Pointer to LIN HW instance
paramsPtr Pointer to transfer parameters
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
This function executes a transfer operation to a LIN target device in controller mode. Depending on the transfer options, it can perform:
Writing data to the target
Reading data from the target
The function:
Sets identifier field needed for LIN target
Transmits header field consisting of ID, Break, Sync.
Performs data transfer (TX and/or RX)
function Lin_Hal_ControllerContinuePolling
sint32 Lin_Hal_ControllerContinuePolling(
Lin_Hal_InstanceType * instancePtr,
Lin_Hal_TransactionStatusType * statusPtr
)
Continues the transfer of remaining bytes and gets controller transfer status in polling mode. Can be called only when interrupt mode is disabled.
Parameters:
instancePtr Pointer to LIN HW instance
statusPtr Pointer that stores the status of current transfer
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
In case of receive, application should copy data from the buffer pointed by Lin_Hal_TransactionStatusType::BufferPtr into its local buffer. In case of transmit, Lin_Hal_TransactionStatusType::BufferPtr is ignored.
In case of receive mode, the size of data to be copied is the amount of data recived into LIN data buffers. This value is deduced from the Data Length bits of the register TYPE and stored in Lin_Hal_TransactionStatusType::SizeInBytes
function Lin_Hal_ControllerTransferInterrupt
sint32 Lin_Hal_ControllerTransferInterrupt(
Lin_Hal_InstanceType * instancePtr,
const Lin_Hal_TransferParamsType * paramsPtr
)
In controller mode, transfer a frame of LIN data in Interrupt mode.
Parameters:
instancePtr Pointer to LIN HW instance
paramsPtr Pointer to transfer parameters
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
This function executes a transfer operation to a LIN target device in controller mode. Depending on the transfer options, it can perform:
Writing data to the target
Reading data from the target
The function:
Sets identifier field needed for LIN target
Transmits header field consisting of ID, Break, Sync.
Performs data transfer (TX and/or RX)
The function returns immediately, and the transfer is handled asynchronously through interrupts. When the transfer is complete, the configured callback function will be invoked.
See also Lin_Hal_TxCompleteCallback
function Lin_Hal_InterruptHandler
void Lin_Hal_InterruptHandler(
Lin_Hal_InstanceType * instancePtr
)
LIN interrupt handler.
Parameters:
instancePtr Pointer to LIN HW instance
The interrupt handler MUST be registered by the application against the appropiate CPU interrupt number.
In controller mode, if controller is initialized in polling mode, then interrupt handler should not be registered.
In target mode, interrupt handler MUST always be registered. Target in polling mode is not supported.
The interrupt handler will call one of below callbacks, depending on the conditions detected within the interrupt handler. The interrupt handler will also clear status and interrupt bits as needed for correct operation.
In each of the callbacks, user arguments passed during initialization are passed back to the user.
The callbacks need to be implemented by the application else there will be a linker error.
The supported callbacks are,
function Lin_Hal_TxCompleteCallback
void Lin_Hal_TxCompleteCallback(
Lin_Hal_InstanceType * instancePtr,
Lin_Hal_TransactionStatusType * statusPtr,
void * userArgsPtr
)
Transmit complete callback.
Parameters:
instancePtr Pointer to LIN HW instance
statusPtr Pointer to store status of current transfer
userArgsPtr Pointer to user arguments passed during initialization
function Lin_Hal_RxCompleteCallback
void Lin_Hal_RxCompleteCallback(
Lin_Hal_InstanceType * instancePtr,
Lin_Hal_TransactionStatusType * statusPtr,
void * userArgsPtr
)
Receive complete callback.
Parameters:
instancePtr Pointer to LIN HW instance
statusPtr Pointer to store status of current transfer
userArgsPtr Pointer to user arguments passed during initialization
function Lin_Hal_TargetHeaderReceivedCallback
void Lin_Hal_TargetHeaderReceivedCallback(
Lin_Hal_InstanceType * instancePtr,
Lin_Hal_TransferParamsType * paramsPtr,
void * userArgsPtr
)
Target header received callback.
Parameters:
instancePtr Pointer to LIN HW instance
paramsPtr Pointer to transfer parameters
userArgsPtr Pointer to user arguments passed during initialization
User should process paramsPtr.FrameId and update and fill paramsPtr to respond (either transmit or receive) to the received header.
Once the callback exits, the interrupt handler will initiate the transfer based on values updated in paramsPtr.
function Lin_Hal_ErrorCallback
void Lin_Hal_ErrorCallback(
Lin_Hal_InstanceType * instancePtr,
uint32 errorCode,
void * userArgsPtr
)
Error in transmit or receive callback.
Parameters:
instancePtr Pointer to LIN HW instance
errorCode See [Lin_Hal_TransferErrorType]
userArgsPtr Pointer to user arguments passed during initialization
function Lin_Hal_TargetSetStop
sint32 Lin_Hal_TargetSetStop(
Lin_Hal_InstanceType * instancePtr
)
Stop LIN transfer in target mode.
Parameters:
instancePtr Pointer to LIN HW instance
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
Note: Resets the header state machine and re-arms detection for the next BREAK field.
Typically after header is received at target, target can decide to stop further transfer by calling this API
function Lin_Hal_DeInit
sint32 Lin_Hal_DeInit(
Lin_Hal_InstanceType * instancePtr
)
De-initialize a LIN HW instance.
Parameters:
instancePtr Pointer to LIN HW instance
Return: LIN_HAL_ERROR_NONE on success, otherwise error code [Lin_Hal_ErrorType]
Disable the HW and any enabled interrupts at the LIN HW. Interrupts at CPU should be disabled by the application before calling this API.
Macros Documentation
define LIN_HAL_ERROR_NONE
#define LIN_HAL_ERROR_NONE (0)
No error.
define LIN_HAL_ERROR_INVALID_INSTANCE
#define LIN_HAL_ERROR_INVALID_INSTANCE (1)
Invalid instance pointer.
define LIN_HAL_ERROR_INVALID_PARAMS
#define LIN_HAL_ERROR_INVALID_PARAMS (2)
Invalid parameters.
define LIN_HAL_ERROR_UNSUPPORTED_FEATURE
#define LIN_HAL_ERROR_UNSUPPORTED_FEATURE (3)
Unsupported operation.
e.g. Target mode API called in controller mode or vice versa
define LIN_HAL_ERROR_HW_BUSY
#define LIN_HAL_ERROR_HW_BUSY (4)
LIN transfer fail since underlying HW was busy.
define LIN_HAL_TRANSFER_ERROR_BIT_ERROR
#define LIN_HAL_TRANSFER_ERROR_BIT_ERROR (0x01U)
Bit error during transmit or receive.
define LIN_HAL_TRANSFER_ERROR_CHECKSUM_ERROR
#define LIN_HAL_TRANSFER_ERROR_CHECKSUM_ERROR (0x02U)
Error due to invalid checksum.
define LIN_HAL_TRANSFER_ERROR_TIMEOUT_ERROR
#define LIN_HAL_TRANSFER_ERROR_TIMEOUT_ERROR (0x04U)
Error due to timeout at controller or target.
define LIN_HAL_TRANSFER_ERROR_PARITY_ERROR
#define LIN_HAL_TRANSFER_ERROR_PARITY_ERROR (0x08U)
Error due to parity error during transmit or receive (only valid for target mode)
define LIN_HAL_TRANSFER_ERROR_INVALID_PARAMS
#define LIN_HAL_TRANSFER_ERROR_INVALID_PARAMS (0x10U)
Error due to invalid transfer params being set by user.
define LIN_HAL_TRANSFER_ERROR_INVALID_RECEIVED_LENGTH
#define LIN_HAL_TRANSFER_ERROR_INVALID_RECEIVED_LENGTH (0x20U)
Error due to invalid data length.
define LIN_HAL_TRANSFER_ERROR_INVALID_BUFFER
#define LIN_HAL_TRANSFER_ERROR_INVALID_BUFFER (0x40U)
Error due to invalid buffer.
define LIN_HAL_MODE_TYPE_COUNT
#define LIN_HAL_MODE_TYPE_COUNT ((uint32)LIN_HAL_MODE_CONTROLLER + 1U)
Number of values in Lin_Hal_ModeType.
define LIN_HAL_TX_PHASE_TYPE_COUNT
#define LIN_HAL_TX_PHASE_TYPE_COUNT ((uint32)LIN_HAL_TX_PHASE_DONE + 1U)
Number of transmit phases.