AM263Px MCU+ SDK: LIN LLD

| AM263Px MCU+ SDK 26.00.00 |

LIN LLD

The Local Interconnect Network (LIN) is a serial communication protocol which is a low cost alternative of CAN (Controller Area Network) where bandwidth and fault tolerence is not required. The communication concept is single-commander/multiple-responder with a message identification for multi-cast transmission between any network nodes.

# Features Supported

- Compatible to LIN 1.3, 2.0 and 2.1 protocols
- Multi-buffered receive and transmit units
- DMA capability for minimal CPU intervention
- Identification masks for message filtering
- 2 Interrupt lines with priority encoding
- Automatic Bus Idle Detection

# SysConfig Features

Note
  It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

SysConfig can be used to configure below parameters apart from common configuration like Clock, MPU, RAT and others.

- LIN instances and pin configurations.
- Enable Loopback support with Loopback Mode and Type of Loopback.
- Enable Interrupts with different lines and triggers.
- Different LIN Modes, Communication Modes, Debug Mode, Checksum Type, Message Filter, Enable Parity Check.

# Usage

## DMA Support

To reduce CPU load when receiving a LIN N-byte (with N from 1 to 8) response in interrupt mode or DMA mode the SCI/LIN module has receive buffers to able to store a whole LIN response in receive buffers.

A recieve interrupt (RX Interrupt), a receive ready RXRDY flag in SCIFLR (9th bit) as well as a DMA request could occur after receiving a response.

A transmit interrupt (TX Interrupt), a Transmit ready TXRDY flag as well as a DMA request (TXDMA) could occur after transmitting a response. A DMA request can be generated for each transmitted byte or for the entire response depending if the multibuffer is enabled or not.

For Buffered SCI Mode, the TX DMA request is initiated as the SET_TX_DMA (16th bit) in SCISETINT is set. The RX DMA request is initiated if the SET_RX_DMA (17th bit) is set and the data is received in RDy (LIN Receive buffers).

For LIN Mode, the TX DMA request is initiated if the SET_TX_DMA (16th bit) is already set and ID BYTE in LINID is not written. The RX DMA request is initiated if the if the SET_RX_DMA (17th bit) is set and the data is received in RDy (LIN Receive buffers) only after LINID is recieved on the RX Line.

## Interrupt Management

The LIN module has 2 interrupt lines : level 0 and level 1 to VIM (Vector Interrupt Manager) module.

Each interrupt has a bit to enable/disable the interrupt in the SCISETINT and SCICLRINT registers. This can also be done via SYSCFG.

Each interrupt has to be set via interrupt level 0 or to be set as interrupt level 1. By default interrupts are in line level 0.

Please refer table "SCI/BLIN Interrupts" in technical reference manual for more details.

## Message filtering

Message filtering uses the entire identified to determine which nodes will participate in a response. The participation could be to either recieve or transmit response. All nodes use the RX-ID mask and the TX-ID mask (in LINMASK) to filter the bits of the identifier that should not be compared. The masked bits become don't care for the comparison.

### Filter Example

To build a mask to accept IDs 0x26 and 0x25, compare 5MSBs and filter 3 LSBs the configuration to be done is :

- Configure LINID[7:0]=0x20.
- The TX ID MASK and the RX ID MASK to be configured as 0xFC.

## Low Power Mode

The LIN module may enter low power mode either when there was no activity on LINRX for more than 4s or when a Sleep Command frame was received.

### Global Low Power Mode

Global low-power mode is asserted by the system and is not controlled by the BLIN module. During global low-power mode, all clocks to the SCI/BLIN are turned off so module is completely inactive.

Note
  Global Low power mode can be acheived through CLKSTOP_REQ/CLKSTOP_ACK interface.

### Local Low Power Mode

If the POWERDOWN bit is set and then the module receives a Sleep Command, it will enter local low-power mode.

The Sleep Command consists of a diagnostic commander request fram with identifier 0x3C (60) with first data field as 0x00.

### Wakeup

The wake-up interrupt is used to allow the LIN module to automatically exit low-power mode. A wakeup is triggered when a falling edge is detected on the receive RX pin, and this clears the POWDERDOWN bit.

0.25ms <= T(WUSIG) <= 5ms

Note
  The wakeup signal should be atleast 5 Tbits for LIN bus baudrates. A write of 0xF0 to TD0 will load the transmitter to meet the wakeup signal timing requirement of T(WUSIG).

# Example Usage

Include the below file to access the APIs

#include <drivers/lin.h>

LIN Initialization Default LIN Initialization can be done by selecting default configuration option via SYSCFG. To override the default initialization, use SYSCFG tool. The generated code for initialization is part of System_init() in ti_drivers_config.c

/******************************************************************************
* LIN Configurations
*****************************************************************************/
LIN_initModule(CONFIG_LIN1_BASE_ADDR);
/*
* Enable LIN test mode
*/
/*
* Enable Internal Loopback mode
*/
LIN_enableIntLoopback(CONFIG_LIN1_BASE_ADDR);
/*
* Enable LIN Interrupts
*/
LIN_enableInterrupt(CONFIG_LIN1_BASE_ADDR, LIN_INT_ID);
/*
* Set the interrupt priority line
*/
LIN_setInterruptLevel0(CONFIG_LIN1_BASE_ADDR, LIN_INT_ALL);
LIN_enableGlobalInterrupt(CONFIG_LIN1_BASE_ADDR, LIN_INTERRUPT_LINE0);
LIN_clearGlobalInterruptStatus(CONFIG_LIN1_BASE_ADDR, LIN_INTERRUPT_LINE0);
/*
* Set the interrupt priority line
*/
LIN_setInterruptLevel1(CONFIG_LIN1_BASE_ADDR, LIN_INT_ALL);
LIN_enableGlobalInterrupt(CONFIG_LIN1_BASE_ADDR, LIN_INTERRUPT_LINE1);
LIN_clearGlobalInterruptStatus(CONFIG_LIN1_BASE_ADDR, LIN_INTERRUPT_LINE1);

LIN Interrupt Registration

int32_t status = SystemP_SUCCESS;
HwiP_Params hwiPrms;
/* Register interrupt */
HwiP_Params_init(&hwiPrms);
hwiPrms.intNum = APP_LIN_INTR_NUM_0;
hwiPrms.callback = &App_linIntrISR;
status = HwiP_construct(&gLinHwiObject, &hwiPrms);
DebugP_assert(status == SystemP_SUCCESS);

LIN Send Data Command Data is placed on LIN Tx Registers via this function but the transmit is not initiated till the LIN ID is sent.

/*
* This places data into the transmit buffer.
* No ID or data is placed on the bus and transmitted yet.
*/
LIN_sendData(APP_LIN_BASE_ADDR, txData);
/*
* Set the message ID to initiate a header transmission.
* This causes the ID to be written to the bus followed by the
* data in the transmit buffers.
*/
LIN_setIDByte(APP_LIN_BASE_ADDR, txID);
/* Wait until Transmit buffer is empty and has completed transmission */
while(!LIN_isTxBufferEmpty(APP_LIN_BASE_ADDR));

LIN Get Data Command Data placed on LIN Rx Registers can be further processed by the CPU.

/* Read the received data in the receive buffers */
LIN_getData(APP_LIN_BASE_ADDR, rxData);

LIN Configuration in SCI Mode LIN can be configured in SCI Mode. This can be done directly via using a function example as mentioned below.

/* Enter LIN reset state to perform configurations */
LIN_enterSoftwareReset(APP_LIN_BASE_ADDR);
/* Switch LIN into SCI mode */
LIN_enableSCIMode(APP_LIN_BASE_ADDR);
/* Set the SCI communication mode to idle line */
LIN_setSCICommMode(APP_LIN_BASE_ADDR, LIN_COMM_SCI_IDLELINE);
/* Set SCI to transmit one stop bit */
LIN_setSCIStopBits(APP_LIN_BASE_ADDR, LIN_SCI_STOP_ONE);
/* Disable parity check */
LIN_disableSCIParity(APP_LIN_BASE_ADDR);
/* Disable multi-buffer mode */
LIN_disableMultibufferMode(APP_LIN_BASE_ADDR);
/* Module set to complete operations when halted by debugger */
LIN_setDebugSuspendMode(APP_LIN_BASE_ADDR, LIN_DEBUG_COMPLETE);
/* Set character length as 8-bits */
LIN_setSCICharLength(APP_LIN_BASE_ADDR, CHAR_LENGTH);
/* Set to 1 character in response field */
LIN_setSCIFrameLength(APP_LIN_BASE_ADDR, FRAME_LENGTH);
/* Enable Internal Loopback mode */
LIN_enableIntLoopback(APP_LIN_BASE_ADDR);
/* Enable interrupt for when a frame has been completely received */
LIN_enableSCIInterrupt(APP_LIN_BASE_ADDR, LIN_SCI_INT_RX);
/* Set the interrupt priority to line 0 (high) */
LIN_setSCIInterruptLevel0(APP_LIN_BASE_ADDR, LIN_SCI_INT_RX);
/* Exit LIN reset state */
LIN_exitSoftwareReset(APP_LIN_BASE_ADDR);

# API

APIs for LIN LLD

LIN_sendData
void LIN_sendData(uint32_t base, uint16_t *data)
This function sends the data.
LIN_enableInterrupt
static void LIN_enableInterrupt(uint32_t base, uint32_t intFlags)
Enable interrupts.
Definition: lin/v0/lin.h:966
LIN_INT_ID
#define LIN_INT_ID
Definition: lin/v0/lin.h:112
LIN_enableIntLoopback
static void LIN_enableIntLoopback(uint32_t base)
Enable Internal Loopback mode for self test.
Definition: lin/v0/lin.h:2475
HwiP_Params
Parameters passed during HwiP_construct.
Definition: HwiP.h:127
LIN_setSCIStopBits
static void LIN_setSCIStopBits(uint32_t base, LIN_SCIStopBits number)
Set the number of stop bits for SCI.
Definition: lin/v0/lin.h:1466
LIN_COMM_SCI_IDLELINE
@ LIN_COMM_SCI_IDLELINE
Definition: lin/v0/lin.h:270
LIN_setInterruptLevel0
static void LIN_setInterruptLevel0(uint32_t base, uint32_t intFlags)
Set interrupt level to 0.
Definition: lin/v0/lin.h:1094
LIN_disableMultibufferMode
static void LIN_disableMultibufferMode(uint32_t base)
Disable Multi-buffer Mode.
Definition: lin/v0/lin.h:2684
LIN_setSCICharLength
static void LIN_setSCICharLength(uint32_t base, uint16_t numBits)
Set SCI character length.
Definition: lin/v0/lin.h:1579
HwiP_construct
int32_t HwiP_construct(HwiP_Object *obj, HwiP_Params *params)
Create a Hwi object.
LIN_setSCIInterruptLevel0
static void LIN_setSCIInterruptLevel0(uint32_t base, uint32_t intFlags)
Set interrupt level to 0.
Definition: lin/v0/lin.h:2000
LIN_INTERRUPT_LINE1
@ LIN_INTERRUPT_LINE1
Definition: lin/v0/lin.h:289
HwiP_Params_init
void HwiP_Params_init(HwiP_Params *params)
Set default values to HwiP_Params.
LIN_disableSCIParity
static void LIN_disableSCIParity(uint32_t base)
Disable SCI Parity mode.
Definition: lin/v0/lin.h:1442
LIN_getData
void LIN_getData(uint32_t base, uint16_t *const data)
This function reads the received data.
LIN_setSCICommMode
static void LIN_setSCICommMode(uint32_t base, LIN_SCICommMode mode)
Set SCI communication mode.
Definition: lin/v0/lin.h:1395
LIN_clearGlobalInterruptStatus
static void LIN_clearGlobalInterruptStatus(uint32_t base, LIN_InterruptLine line)
Clears a LIN global interrupt flag.
Definition: lin/v0/lin.h:2841
LIN_setSCIFrameLength
static void LIN_setSCIFrameLength(uint32_t base, uint16_t length)
Set SCI Frame Length.
Definition: lin/v0/lin.h:1604
LIN_INTERRUPT_LINE0
@ LIN_INTERRUPT_LINE0
Definition: lin/v0/lin.h:288
SystemP_SUCCESS
#define SystemP_SUCCESS
Return status when the API execution was successful.
Definition: SystemP.h:56
LIN_INT_ALL
#define LIN_INT_ALL
Definition: lin/v0/lin.h:121
LIN_isTxBufferEmpty
static Bool LIN_isTxBufferEmpty(uint32_t base)
Check if the Transmit Buffer is Empty.
Definition: lin/v0/lin.h:2395
LIN_enableSCIMode
static void LIN_enableSCIMode(uint32_t base)
Enable SCI Mode.
Definition: lin/v0/lin.h:1341
LIN_enterSoftwareReset
static void LIN_enterSoftwareReset(uint32_t base)
Put LIN into its reset state.
Definition: lin/v0/lin.h:2334
LIN_enableGlobalInterrupt
static void LIN_enableGlobalInterrupt(uint32_t base, LIN_InterruptLine line)
Enables a LIN global interrupt.
Definition: lin/v0/lin.h:2795
LIN_enableSCIInterrupt
static void LIN_enableSCIInterrupt(uint32_t base, uint32_t intFlags)
Enable SCI interrupts.
Definition: lin/v0/lin.h:1884
HwiP_Params::callback
HwiP_FxnCallback callback
Definition: HwiP.h:130
LIN_setIDByte
static void LIN_setIDByte(uint32_t base, uint16_t identifier)
Set ID Byte.
Definition: lin/v0/lin.h:580
LIN_SCI_STOP_ONE
@ LIN_SCI_STOP_ONE
Definition: lin/v0/lin.h:338
LIN_exitSoftwareReset
static void LIN_exitSoftwareReset(uint32_t base)
Put LIN into its ready state.
Definition: lin/v0/lin.h:2355
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:187
HwiP_Params::intNum
uint32_t intNum
Definition: HwiP.h:129
LIN_setDebugSuspendMode
static void LIN_setDebugSuspendMode(uint32_t base, LIN_DebugMode mode)
Set the Debug Suspended Mode.
Definition: lin/v0/lin.h:2771
lin.h
LIN_setInterruptLevel1
static void LIN_setInterruptLevel1(uint32_t base, uint32_t intFlags)
Set interrupt level to 1.
Definition: lin/v0/lin.h:1137
LIN_SCI_INT_RX
#define LIN_SCI_INT_RX
Definition: lin/v0/lin.h:228
LIN_initModule
void LIN_initModule(uint32_t base)
This function initializes the LIN module.
LIN_DEBUG_COMPLETE
@ LIN_DEBUG_COMPLETE
Complete Tx/Rx before Freezing.
Definition: lin/v0/lin.h:313