LIN HAL API

Module: HAL (AM13E232X) API

More…

Structures

Name

struct

Lin_Hal_InitParamsType
LIN HW initialization parameters.

struct

Lin_Hal_TransferParamsType
LIN HW transfer parameters.

struct

Lin_Hal_InstanceType
LIN HW instance structure. Should not be modified by application directly.

struct

Lin_Hal_TransactionStatusType
LIN Transfer status.

Types

Name

enum

Lin_Hal_StateType { LIN_HAL_STATE_UNCONFIGURED = 0U, LIN_HAL_STATE_READY, LIN_HAL_STATE_TRANSFER}
LIN instance states.

enum

Lin_Hal_ModeType { LIN_HAL_MODE_TARGET = 0U, LIN_HAL_MODE_CONTROLLER}
LIN operational mode.

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}
Target-mode header detection state.

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}
Software transmit progress, independent of received header state.

Functions

Name

sint32

Lin_Hal_InitParamsSetDefault(Lin_Hal_InitParamsType * paramsPtr)
Initializes the LIN module with Default Parameters.

sint32

Lin_Hal_TransferParamsSetDefault(Lin_Hal_TransferParamsType * paramsPtr)
Initializes the transfer params structure with Default Parameters.

sint32

Lin_Hal_Init(Lin_Hal_InstanceType * instancePtr, const Lin_Hal_InitParamsType * paramsPtr)
Initialize a LIN HW instance.

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.

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.

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.

void

Lin_Hal_InterruptHandler(Lin_Hal_InstanceType * instancePtr)
LIN interrupt handler.

void

Lin_Hal_TxCompleteCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransactionStatusType * statusPtr, void * userArgsPtr)
Transmit complete callback.

void

Lin_Hal_RxCompleteCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransactionStatusType * statusPtr, void * userArgsPtr)
Receive complete callback.

void

Lin_Hal_TargetHeaderReceivedCallback(Lin_Hal_InstanceType * instancePtr, Lin_Hal_TransferParamsType * paramsPtr, void * userArgsPtr)
Target header received callback.

void

Lin_Hal_ErrorCallback(Lin_Hal_InstanceType * instancePtr, uint32 errorCode, void * userArgsPtr)
Error in transmit or receive callback.

sint32

Lin_Hal_TargetSetStop(Lin_Hal_InstanceType * instancePtr)
Stop LIN transfer in target mode.

sint32

Lin_Hal_DeInit(Lin_Hal_InstanceType * instancePtr)
De-initialize a LIN HW instance.

Defines

Name

LIN_HAL_ERROR_NONE
No error.

LIN_HAL_ERROR_INVALID_INSTANCE
Invalid instance pointer.

LIN_HAL_ERROR_INVALID_PARAMS
Invalid parameters.

LIN_HAL_ERROR_UNSUPPORTED_FEATURE
Unsupported operation.

LIN_HAL_ERROR_HW_BUSY
LIN transfer fail since underlying HW was busy.

LIN_HAL_TRANSFER_ERROR_BIT_ERROR
Bit error during transmit or receive.

LIN_HAL_TRANSFER_ERROR_CHECKSUM_ERROR
Error due to invalid checksum.

LIN_HAL_TRANSFER_ERROR_TIMEOUT_ERROR
Error due to timeout at controller or target.

LIN_HAL_TRANSFER_ERROR_PARITY_ERROR
Error due to parity error during transmit or receive (only valid for target mode)

LIN_HAL_TRANSFER_ERROR_INVALID_PARAMS
Error due to invalid transfer params being set by user.

LIN_HAL_TRANSFER_ERROR_INVALID_RECEIVED_LENGTH
Error due to invalid data length.

LIN_HAL_TRANSFER_ERROR_INVALID_BUFFER
Error due to invalid buffer.

LIN_HAL_MODE_TYPE_COUNT
Number of values in Lin_Hal_ModeType.

LIN_HAL_TX_PHASE_TYPE_COUNT
Number of transmit phases.

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

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.