Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Local Interconnect Network (LIN)

See Quick start guide for the SAM LIN module.

Service driver for the LIN. This driver provides access to the LIN service features of the usart controller.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Local Interconnect Network (LIN).
 

Macros

#define USART_LIN_CLASSIC_CHECKSUM   1
 Classic checksum used in the LIN 1.x. More...
 
#define USART_LIN_DIAGNOSTIC_FRAME_ID   60
 The frame identifier used to carry diagnostic data. More...
 
#define USART_LIN_DLM_DLC   0
 The response data length is defined by the field DLC of DLM. More...
 
#define USART_LIN_DLM_IDCHR   1
 The response data length is defined by the bits 5 and 6 of the identifier. More...
 
#define USART_LIN_ENHANCED_CHECKSUM   0
 Enhanced checksum used in the LIN 2.x. More...
 
#define USART_LIN_ERROR_OFFSET   25
 LIN error offset. More...
 

Functions

static void lin_get_response (uint8_t uc_node, uint8_t *p_data)
 This function reads (empties) the reception data buffer when a LIN response had been received. More...
 
uint8_t lin_init (Usart *usart_node, bool b_master, uint8_t uc_node, uint16_t us_rate, uint32_t ul_mck)
 This function initializes the LIN controller. More...
 
uint8_t lin_register_descriptor (uint8_t uc_node, uint8_t uc_frame_id, st_lin_message *lin_desc)
 This function initializes the LIN message descriptor. More...
 
static uint8_t lin_rx_response (uint8_t uc_node, uint8_t uc_len)
 This function commands the reception of a LIN response, SLAVE task of MASTER or SLAVE node. More...
 
uint8_t lin_send_cmd (uint8_t uc_node, uint8_t uc_id, uint8_t uc_len)
 This function commands the sending of the LIN header, MASTER task of MASTER node. More...
 
static uint8_t lin_tx_header_and_response (uint8_t uc_node, uint8_t uc_handle, uint8_t uc_len)
 This function commands the sending of a LIN header and response, MASTER task only. More...
 
static uint8_t lin_tx_response (uint8_t uc_node, uint8_t *p_data, uint8_t uc_len)
 This function commands the sending of a LIN response, SLAVE task of MASTER or SLAVE node. More...
 
void usart_lin_handler (uint8_t uc_node)
 USART LIN interrupt handler: manage ID reception. More...
 

Variables

Pdc * g_p_pdc [LIN_NODE_NUM]
 Pointer to PDC register base. More...
 
pdc_packet_t g_st_packet [LIN_NODE_NUM]
 PDC data packet. More...
 
st_lin_message lin_descript_list_node [LIN_NODE_NUM][NUMBER_OF_LIN_FRAMES_NODE]
 
uint16_t lin_error_number_node [LIN_NODE_NUM] = {0}
 
uint16_t lin_last_errors_node [LIN_NODE_NUM][LIN_LAST_ERR_LENGHT]
 
uint8_t lin_rx_buffer_node [LIN_NODE_NUM][LIN_BUFF_SIZE]
 
uint8_t lin_tx_buffer_node [LIN_NODE_NUM][LIN_BUFF_SIZE]
 
Usart * usart_lin_node [LIN_NODE_NUM]
 Instance of the USART IP used. More...
 

#define USART_LIN_CLASSIC_CHECKSUM   1

Classic checksum used in the LIN 1.x.

Referenced by lin_send_cmd(), and usart_lin_handler().

#define USART_LIN_DIAGNOSTIC_FRAME_ID   60

The frame identifier used to carry diagnostic data.

Referenced by lin_send_cmd(), and usart_lin_handler().

#define USART_LIN_DLM_DLC   0

The response data length is defined by the field DLC of DLM.

Referenced by lin_send_cmd(), and usart_lin_handler().

#define USART_LIN_DLM_IDCHR   1

The response data length is defined by the bits 5 and 6 of the identifier.

Referenced by lin_send_cmd(), and usart_lin_handler().

#define USART_LIN_ENHANCED_CHECKSUM   0

Enhanced checksum used in the LIN 2.x.

Referenced by lin_send_cmd(), and usart_lin_handler().

#define USART_LIN_ERROR_OFFSET   25

LIN error offset.

Referenced by usart_lin_handler().

static void lin_get_response ( uint8_t  uc_node,
uint8_t *  p_data 
)
static

This function reads (empties) the reception data buffer when a LIN response had been received.

This function is additional of the lin_rx_response() function.

Parameters
uc_nodeNode Value.
p_dataPointer on the data corresponding to the message pointed by the handle in the descriptor list.
Returns
Status PASS / FAIL.

Referenced by usart_lin_handler().

uint8_t lin_init ( Usart *  usart_node,
bool  b_master,
uint8_t  uc_node,
uint16_t  us_rate,
uint32_t  ul_mck 
)

This function initializes the LIN controller.

Parameters
usart_nodePointer to the usart instance.
b_mastertrue for master, false for slave.
uc_nodeNode Value.
us_rateBaudrate Value.
ul_mckBoard MCK.
Returns
Status PASS / FAIL.

References PASS, pdc_enable_transfer(), and usart_get_pdc_base().

Referenced by main(), and run_lin_test().

uint8_t lin_register_descriptor ( uint8_t  uc_node,
uint8_t  uc_frame_id,
st_lin_message lin_desc 
)

This function initializes the LIN message descriptor.

Parameters
uc_nodeLIN node id.
uc_frame_idFrame node id.
lin_descSpecific LIN descriptor.
Returns
Status PASS / FAIL.

References st_lin_message::lin_cmd, PASS, st_lin_message::pt_function, st_lin_message::uc_dlc, st_lin_message::uc_id, st_lin_message::uc_pt_data, and st_lin_message::uc_status.

Referenced by main(), and run_lin_test().

static uint8_t lin_rx_response ( uint8_t  uc_node,
uint8_t  uc_len 
)
static

This function commands the reception of a LIN response, SLAVE task of MASTER or SLAVE node.

Parameters
uc_nodeNode Value.
uc_handleHandle on the descriptor list.
uc_lenMessage length corresponding to the message pointed by the handle in the descriptor list.
Returns
Status PASS / FAIL.

References NULL, PASS, pdc_rx_init(), pdc_packet::ul_addr, pdc_packet::ul_size, and usart_enable_interrupt().

Referenced by lin_send_cmd(), and usart_lin_handler().

uint8_t lin_send_cmd ( uint8_t  uc_node,
uint8_t  uc_id,
uint8_t  uc_len 
)

This function commands the sending of the LIN header, MASTER task of MASTER node.

Parameters
uc_nodeNode Value.
uc_idLIN identifier value. In case of `LIN_1X', the coded length is transported into the LIN identifier.
uc_lenTrue length (not coded), number of data bytes transported in the response. This information is not used in `LIN_1X' because it is coded in `uc_id'.
Returns
Status PASS / FAIL.

References FAIL, lin_rx_response(), lin_tx_header_and_response(), PASS, PUBLISH, SUBSCRIBE, USART_LIN_CLASSIC_CHECKSUM, USART_LIN_DIAGNOSTIC_FRAME_ID, USART_LIN_DLM_DLC, USART_LIN_DLM_IDCHR, USART_LIN_ENHANCED_CHECKSUM, and usart_reset_status().

Referenced by lin_master_task_ID12().

static uint8_t lin_tx_header_and_response ( uint8_t  uc_node,
uint8_t  uc_handle,
uint8_t  uc_len 
)
static

This function commands the sending of a LIN header and response, MASTER task only.

Parameters
uc_nodeNode Value.
uc_handleHandle on the descriptor list.
uc_lenMessage length corresponding to the message pointed by the handle in the descriptor list.
Returns
Status PASS / FAIL.

References NULL, PASS, pdc_enable_transfer(), pdc_tx_init(), st_lin_message::uc_id, pdc_packet::ul_addr, pdc_packet::ul_size, and usart_enable_interrupt().

Referenced by lin_send_cmd().

static uint8_t lin_tx_response ( uint8_t  uc_node,
uint8_t *  p_data,
uint8_t  uc_len 
)
static

This function commands the sending of a LIN response, SLAVE task of MASTER or SLAVE node.

Parameters
uc_nodeNode Value.
p_dataPointer on the data corresponding to the message pointed by the handle in the descriptor list.
uc_lenMessage length corresponding to the message pointed by the handle in the descriptor list.
Returns
Status PASS / FAIL.

References NULL, PASS, pdc_enable_transfer(), pdc_tx_init(), pdc_packet::ul_addr, and pdc_packet::ul_size.

Referenced by usart_lin_handler().

Pdc* g_p_pdc[LIN_NODE_NUM]

Pointer to PDC register base.

pdc_packet_t g_st_packet[LIN_NODE_NUM]

PDC data packet.

st_lin_message lin_descript_list_node[LIN_NODE_NUM][NUMBER_OF_LIN_FRAMES_NODE]
uint16_t lin_error_number_node[LIN_NODE_NUM] = {0}
uint16_t lin_last_errors_node[LIN_NODE_NUM][LIN_LAST_ERR_LENGHT]
uint8_t lin_rx_buffer_node[LIN_NODE_NUM][LIN_BUFF_SIZE]
uint8_t lin_tx_buffer_node[LIN_NODE_NUM][LIN_BUFF_SIZE]
Usart* usart_lin_node[LIN_NODE_NUM]

Instance of the USART IP used.