Microchip® Advanced Software Framework

lin.c File Reference
#include <stdio.h>
#include <string.h>
#include "compiler.h"
#include "intc.h"
#include "pdca.h"
#include "gpio.h"
#include "lin.h"

Functions

static void lin_int_handler_node0 (void)
 USART LIN interrupt handler: manage ID reception and ERROR. More...
 
static void lin_pdca_int_rx_handler_node0 (void)
 USART LIN RX PDCA interrupt handler. More...
 
static void lin_pdca_int_tx_handler_node0 (void)
 LIN TX PDCA interrupt handler. More...
 
Initialization Functions
static U8 lin_rx_response (U8 l_node, U8 l_handle, U8 l_len)
 This function commands the reception of a LIN response, SLAVE task of MASTER or SLAVE node. More...
 
static U8 lin_tx_response (U8 l_node, U8 l_handle, U8 *l_data, U8 l_len)
 This function commands the sending of a LIN response, SLAVE task of MASTER or SLAVE node. More...
 
static void lin_get_response (U8 l_node, U8 *l_data)
 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. More...
 
static U8 lin_tx_header_and_response (U8 l_node, U8 l_handle, U8 l_len)
 This function commands the sending of a LIN header and response, MASTER task only. More...
 
U8 lin_init (bool master, U8 l_node, U16 b_rate, long pba_hz)
 This function initializes the LIN controller and, if needed, the LIN interrupts. More...
 
U8 lin_send_cmd (U8 l_node, U8 l_id, U8 l_len)
 This function commands the sending of the LIN header, MASTER task of MASTER node. More...
 

Variables

volatile st_lin_message lin_descript_list_node0 [NUMBER_OF_LIN_FRAMES_NODE0]
 Array of structure of type:'st_lin_message'. Default: 8 elements. More...
 
volatile U16 lin_error_number_node0 = 0
 Counter of LIN error. If an error clearly linked to a message (i.e. time-out) the status of this message is written with the error (LINERR). More...
 
volatile U8 lin_handle_node0 = 0xFF
 Index in lin_descript_list[], 'lin_handle' is set after processing IDOK and verified once RXOK or TXOK rises. More...
 
volatile U16 lin_last_errors_node0 [LIN_LAST_ERR_LENGHT]
 Last error FIFO: lin_handle | status. Default: 4 elements. More...
 
volatile U8 lin_rx_buffer_node0 [256]
 
U8 lin_tx_buffer_node0 [256]
 
volatile avr32_usart_t * usart_lin_node0 = &USART_LIN_NODE0_INSTANCE
 Instance of the USART IP used. More...
 
static const gpio_map_t USART_LIN_NODE0_GPIO_MAP
 Map of the LIN pins used. More...
 

static void lin_get_response ( U8  l_node,
U8 l_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
l_nodeNode Value
l_dataPointer on the data corresponding to the message pointed by the handle in the descriptor list
Returns
Status PASS / FAIL

References i, lin_rx_buffer_node0, and usart_lin_node0.

Referenced by lin_pdca_int_rx_handler_node0().

static void lin_int_handler_node0 ( void  )
static
static void lin_pdca_int_rx_handler_node0 ( void  )
static
static void lin_pdca_int_tx_handler_node0 ( void  )
static
static U8 lin_rx_response ( U8  l_node,
U8  l_handle,
U8  l_len 
)
static

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

Parameters
l_nodeNode Value
l_handleHandle on the descriptor list
l_lenMessage length corresponding to the message pointed by the handle in the descriptor list
Returns
Status PASS / FAIL

References pdca_channel_options_t::addr, lin_rx_buffer_node0, NULL, pdca_enable(), pdca_enable_interrupt_transfer_complete(), pdca_init_channel(), and PDCA_TRANSFER_SIZE_BYTE.

Referenced by lin_int_handler_node0(), and lin_send_cmd().

static U8 lin_tx_header_and_response ( U8  l_node,
U8  l_handle,
U8  l_len 
)
static

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

Parameters
l_nodeNode Value
l_handleHandle on the descriptor list
l_lenMessage length corresponding to the message pointed by the handle in the descriptor list
Returns
Status PASS / FAIL

Enable Interrupt for Error flags and end ID Reception

References pdca_channel_options_t::addr, st_lin_message::l_id, lin_tx_buffer_node0, NULL, PASS, pdca_enable(), pdca_enable_interrupt_transfer_complete(), pdca_init_channel(), PDCA_TRANSFER_SIZE_BYTE, and usart_lin_node0.

Referenced by lin_send_cmd().

static U8 lin_tx_response ( U8  l_node,
U8  l_handle,
U8 l_data,
U8  l_len 
)
static

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

Parameters
l_nodeNode Value
l_handleHandle on the descriptor list
l_dataPointer on the data corresponding to the message pointed by the handle in the descriptor list
l_lenMessage length corresponding to the message pointed by the handle in the descriptor list
Returns
Status PASS / FAIL

References pdca_channel_options_t::addr, lin_tx_buffer_node0, NULL, pdca_enable(), pdca_enable_interrupt_transfer_complete(), pdca_init_channel(), and PDCA_TRANSFER_SIZE_BYTE.

Referenced by lin_int_handler_node0().

volatile U8 lin_rx_buffer_node0[256]
U8 lin_tx_buffer_node0[256]
volatile avr32_usart_t* usart_lin_node0 = &USART_LIN_NODE0_INSTANCE
const gpio_map_t USART_LIN_NODE0_GPIO_MAP
static
Initial value:
=
{
{USART_LIN_NODE0_RX_PIN, USART_LIN_NODE0_RX_FUNCTION},
{USART_LIN_NODE0_TX_PIN, USART_LIN_NODE0_TX_FUNCTION}
}

Map of the LIN pins used.