This file contains basic functions for the AVR32 USART, with support for all modes, settings and clock speeds.
Definition in file lin.c.
#include <stdio.h>
#include <string.h>
#include "compiler.h"
#include "intc.h"
#include "pdca.h"
#include "gpio.h"
#include "lin.h"
Go to the source code of this file.
Functions | |
static void | lin_int_handler_node0 (void) |
USART LIN interrupt handler: manage ID reception and ERROR. | |
static void | lin_pdca_int_rx_handler_node0 (void) |
USART LIN RX PDCA interrupt handler. | |
static void | lin_pdca_int_tx_handler_node0 (void) |
LIN TX PDCA interrupt handler. | |
Initialization Functions | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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). | |
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. | |
volatile U16 | lin_last_errors_node0 [LIN_LAST_ERR_LENGHT] |
Last error FIFO: lin_handle | status. Default: 4 elements. | |
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. | |
static const gpio_map_t | USART_LIN_NODE0_GPIO_MAP |
Map of the LIN pins used. |
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.
l_node | Node Value | |
l_data | Pointer on the data corresponding to the message pointed by the handle in the descriptor list |
Definition at line 956 of file lin.c.
References lin_rx_buffer_node0, and usart_lin_node0.
Referenced by lin_pdca_int_rx_handler_node0().
00956 { 00957 00958 U8 i, l_len; 00959 if (l_node == 0) 00960 { 00961 l_len = usart_lin_get_data_length(usart_lin_node0); 00962 for (i = 0; i < l_len; i++) { 00963 (*l_data++) = lin_rx_buffer_node0[i]; 00964 } 00965 } 00966 #ifdef USART_LIN_NODE1_INSTANCE 00967 else 00968 { 00969 l_len = usart_lin_get_data_length(usart_lin_node1); 00970 for (i = 0; i < l_len; i++) { 00971 (*l_data++) = lin_rx_buffer_node1[i]; 00972 } 00973 } 00974 #endif 00975 00976 }
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.
master | TRUE for master, FALSE for slave | |
l_node | Node Value | |
b_rate | Baudrate Value | |
pba_hz | PBA Value |
Enable Interrupt for Error flags and end ID Reception
Register Interrupt for LIN
Register Interrupt for PDCA Transfert TX
Register Interrupt for PDCA Transfert RX
Definition at line 470 of file lin.c.
References lin_int_handler_node0(), lin_pdca_int_rx_handler_node0(), lin_pdca_int_tx_handler_node0(), usart_lin_node0, USART_LIN_NODE0_GPIO_MAP, USART_LIN_NODE0_PDCA_RX_IRQ, USART_LIN_NODE0_PDCA_RX_IRQ_LEVEL, USART_LIN_NODE0_PDCA_TX_IRQ, USART_LIN_NODE0_PDCA_TX_IRQ_LEVEL, USART_LIN_NODE0_RX_PIN, USART_LIN_NODE0_USART_IRQ, USART_LIN_NODE0_USART_IRQ_LEVEL, USART_LIN_NODE1_PDCA_RX_IRQ, USART_LIN_NODE1_PDCA_RX_IRQ_LEVEL, USART_LIN_NODE1_PDCA_TX_IRQ, USART_LIN_NODE1_PDCA_TX_IRQ_LEVEL, USART_LIN_NODE1_RX_PIN, USART_LIN_NODE1_USART_IRQ, and USART_LIN_NODE1_USART_IRQ_LEVEL.
Referenced by main().
00473 { 00474 if (l_node == 0) 00475 { 00476 // Enable GPIO Alternate Functions 00477 gpio_enable_module(USART_LIN_NODE0_GPIO_MAP, 00478 sizeof(USART_LIN_NODE0_GPIO_MAP) / sizeof(USART_LIN_NODE0_GPIO_MAP[0])); 00479 00480 gpio_enable_pin_pull_up(USART_LIN_NODE0_RX_PIN); 00481 00482 // USART options. 00483 if (master) 00484 usart_init_lin_master(usart_lin_node0,b_rate,pba_hz); 00485 else 00486 usart_init_lin_slave(usart_lin_node0,b_rate,pba_hz); 00487 00488 Disable_global_interrupt(); 00489 00490 if (master==FALSE) 00491 { 00493 #ifdef AVR32_USART_420_H_INCLUDED 00494 usart_lin_node0->ier = AVR32_USART_IER_LINIR_MASK | 00495 AVR32_USART_IER_LINBE_MASK | 00496 AVR32_USART_IER_LINISFE_MASK | 00497 AVR32_USART_IER_LINIPE_MASK | 00498 AVR32_USART_IER_LINCE_MASK | 00499 AVR32_USART_IER_LINSNRE_MASK; 00501 INTC_register_interrupt(&lin_int_handler_node0, 00502 USART_LIN_NODE0_USART_IRQ, 00503 USART_LIN_NODE0_USART_IRQ_LEVEL); 00504 #else 00505 00506 usart_lin_node0->ier = AVR32_USART_IER_LINID_MASK | 00507 AVR32_USART_IER_LINBE_MASK | 00508 AVR32_USART_IER_LINISFE_MASK | 00509 AVR32_USART_IER_LINIPE_MASK | 00510 AVR32_USART_IER_LINCE_MASK | 00511 AVR32_USART_IER_LINSNRE_MASK; 00513 INTC_register_interrupt(&lin_int_handler_node0, 00514 USART_LIN_NODE0_USART_IRQ, 00515 USART_LIN_NODE0_USART_IRQ_LEVEL); 00516 #endif 00517 } 00518 00520 INTC_register_interrupt(&lin_pdca_int_tx_handler_node0, 00521 USART_LIN_NODE0_PDCA_TX_IRQ, 00522 USART_LIN_NODE0_PDCA_TX_IRQ_LEVEL); 00523 00525 INTC_register_interrupt(&lin_pdca_int_rx_handler_node0, 00526 USART_LIN_NODE0_PDCA_RX_IRQ, 00527 USART_LIN_NODE0_PDCA_RX_IRQ_LEVEL); 00528 00529 } 00530 #ifdef USART_LIN_NODE1_INSTANCE 00531 else 00532 { 00533 // Enable GPIO Alternate Functions 00534 gpio_enable_module(USART_LIN_NODE1_GPIO_MAP, 00535 sizeof(USART_LIN_NODE1_GPIO_MAP) / sizeof(USART_LIN_NODE1_GPIO_MAP[0])); 00536 00537 00538 gpio_enable_pin_pull_up(USART_LIN_NODE1_RX_PIN); 00539 00540 // USART options. 00541 if (master) 00542 usart_init_lin_master(usart_lin_node1,b_rate,pba_hz); 00543 else 00544 usart_init_lin_slave(usart_lin_node1,b_rate,pba_hz); 00545 00546 Disable_global_interrupt(); 00547 00548 if (master==FALSE) 00549 { 00551 #ifdef AVR32_USART_420_H_INCLUDED 00552 usart_lin_node1->ier = AVR32_USART_IER_LINIR_MASK | 00553 AVR32_USART_IER_LINBE_MASK | 00554 AVR32_USART_IER_LINISFE_MASK | 00555 AVR32_USART_IER_LINIPE_MASK | 00556 AVR32_USART_IER_LINCE_MASK | 00557 AVR32_USART_IER_LINSNRE_MASK; 00559 INTC_register_interrupt(&lin_int_handler_node1, 00560 USART_LIN_NODE1_USART_IRQ, 00561 USART_LIN_NODE1_USART_IRQ_LEVEL); 00562 #else 00563 usart_lin_node1->ier = AVR32_USART_IER_LINID_MASK | 00564 AVR32_USART_IER_LINBE_MASK | 00565 AVR32_USART_IER_LINISFE_MASK | 00566 AVR32_USART_IER_LINIPE_MASK | 00567 AVR32_USART_IER_LINCE_MASK | 00568 AVR32_USART_IER_LINSNRE_MASK; 00570 INTC_register_interrupt(&lin_int_handler_node1, 00571 USART_LIN_NODE1_USART_IRQ, 00572 USART_LIN_NODE1_USART_IRQ_LEVEL); 00573 #endif 00574 } 00575 00577 INTC_register_interrupt(&lin_pdca_int_tx_handler_node1, 00578 USART_LIN_NODE1_PDCA_TX_IRQ, 00579 USART_LIN_NODE1_PDCA_TX_IRQ_LEVEL); 00580 00582 INTC_register_interrupt(&lin_pdca_int_rx_handler_node1, 00583 USART_LIN_NODE1_PDCA_RX_IRQ, 00584 USART_LIN_NODE1_PDCA_RX_IRQ_LEVEL); 00585 } 00586 #endif 00587 return PASS; 00588 }
static void lin_int_handler_node0 | ( | void | ) | [static] |
USART LIN interrupt handler: manage ID reception and ERROR.
Definition at line 194 of file lin.c.
References IGNORE, st_lin_message::l_status, lin_error_number_node0, lin_handle_node0, LIN_LAST_ERR_LENGHT, lin_last_errors_node0, lin_rx_response(), lin_tx_response(), NUMBER_OF_LIN_FRAMES_NODE0, PUBLISH, SUBSCRIBE, usart_lin_node0, and usart_reset_status().
Referenced by lin_init().
00195 { 00196 U32 l_error; 00197 U8 index; 00198 U8 l_handle = 0xFF; 00199 // Check ID Value for the current message 00200 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE0; index ++) 00201 { 00202 if(lin_descript_list_node0[index].l_id == usart_lin_get_id_char(usart_lin_node0)) 00203 { 00204 l_handle = index; 00205 break; 00206 } 00207 } 00208 // Check Error Status 00209 l_error = usart_lin_get_error(usart_lin_node0); 00210 usart_reset_status(usart_lin_node0); 00211 if (l_error!=0) 00212 { 00213 if(l_handle != 0xFF) 00214 { 00215 lin_descript_list_node0[l_handle].l_status = l_error; 00216 } 00217 lin_last_errors_node0[(((U8)lin_error_number_node0) & (LIN_LAST_ERR_LENGHT-1))] \ 00218 = ((((U16)l_handle)<<8) | ((U16)l_error)) ; 00219 lin_error_number_node0++; 00220 lin_handle_node0 = 0xFF; // End of communication 00221 } 00222 // Here the communication go on only in case no error is detected!!! 00223 else 00224 { 00225 usart_lin_set_node_action(usart_lin_node0,lin_descript_list_node0[l_handle].l_cmd); 00226 00227 if(l_handle != 0xFF) 00228 { 00229 #if USART_LIN_VERSION == LIN_2x 00230 // Configure Parity 00231 usart_lin_enable_parity(usart_lin_node0,TRUE); 00232 // Configure Checksum 00233 usart_lin_enable_checksum(usart_lin_node0,TRUE); 00234 // Configure Checksum Type 00235 usart_lin_set_checksum(usart_lin_node0,USART_LIN_ENHANCED_CHECKSUM); 00236 // Configure Frameslot 00237 usart_lin_enable_frameslot(usart_lin_node0,FALSE); 00238 // Configure Frame Length 00239 usart_lin_set_data_length_lin2x(usart_lin_node0,lin_descript_list_node0[l_handle].l_dlc); 00240 #elif USART_LIN_VERSION == LIN_1x 00241 // Configure Parity 00242 usart_lin_enable_parity(usart_lin_node0,TRUE); 00243 // Configure Checksum 00244 usart_lin_enable_checksum(usart_lin_node0,TRUE); 00245 // Configure Checksum Type 00246 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM); 00247 // Configure Frameslot 00248 usart_lin_enable_frameslot(usart_lin_node0,FALSE); 00249 // Configure Frame Length 00250 usart_lin_set_data_length_lin1x(usart_lin_node0); 00251 #endif 00252 00253 // Diagnostic frames in LIN 2.0/2.1 00254 if((usart_lin_get_id_char(usart_lin_node0)>=60)) { 00255 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM); 00256 // Configure Frame Length 00257 usart_lin_set_data_length_lin1x(usart_lin_node0); 00258 } 00259 00260 switch (lin_descript_list_node0[l_handle].l_cmd) 00261 { 00262 //------------ 00263 case PUBLISH: 00264 lin_tx_response ( 0, 00265 l_handle, 00266 lin_descript_list_node0[l_handle].l_pt_data, 00267 lin_descript_list_node0[l_handle].l_dlc) ; 00268 break; 00269 //------------ 00270 case SUBSCRIBE: 00271 lin_rx_response ( 0, 00272 l_handle, 00273 lin_descript_list_node0[l_handle].l_dlc) ; 00274 break; 00275 //------------ 00276 case IGNORE: 00277 default: 00278 lin_handle_node0 = 0xFF; // End of communication 00279 break; 00280 } 00281 } 00282 } 00283 }
static void lin_pdca_int_rx_handler_node0 | ( | void | ) | [static] |
USART LIN RX PDCA interrupt handler.
Definition at line 163 of file lin.c.
References st_lin_message::l_pt_function, lin_get_response(), lin_handle_node0, NUMBER_OF_LIN_FRAMES_NODE0, usart_lin_node0, and USART_LIN_NODE0_RX_PDCA_CHANNEL.
Referenced by lin_init().
00164 { 00165 U8 index = 0; 00166 U8 l_handle = 0xFF; 00167 // Check ID Value for the current message 00168 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE0; index ++) { 00169 if(lin_descript_list_node0[index].l_id == usart_lin_get_id_char(usart_lin_node0)) { 00170 l_handle = index; 00171 break; 00172 } 00173 } 00174 // Check if the ID received is registered into the lin description list 00175 if (l_handle!=0xFF) 00176 { 00177 if (pdca_get_transfer_status(USART_LIN_NODE0_RX_PDCA_CHANNEL)&PDCA_TRANSFER_COMPLETE) 00178 { 00179 pdca_disable_interrupt_transfer_complete(USART_LIN_NODE0_RX_PDCA_CHANNEL); 00180 lin_get_response (0,lin_descript_list_node0[l_handle].l_pt_data); 00181 // Start of the associated task 00182 lin_descript_list_node0[l_handle].l_pt_function(lin_descript_list_node0[l_handle].l_pt_data); 00183 lin_handle_node0 = 0xFF; // End of communication 00184 } 00185 } 00186 }
static void lin_pdca_int_tx_handler_node0 | ( | void | ) | [static] |
LIN TX PDCA interrupt handler.
Definition at line 130 of file lin.c.
References st_lin_message::l_pt_function, lin_handle_node0, NUMBER_OF_LIN_FRAMES_NODE0, usart_lin_node0, and USART_LIN_NODE0_TX_PDCA_CHANNEL.
Referenced by lin_init().
00131 { 00132 U8 index = 0; 00133 U8 l_handle = 0xFF; 00134 00135 // Check ID Value for the current message 00136 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE0; index ++) { 00137 if(lin_descript_list_node0[index].l_id == usart_lin_get_id_char(usart_lin_node0)) { 00138 l_handle = index; 00139 break; 00140 } 00141 } 00142 // Check if the ID received is registered into the lin description list 00143 if (l_handle!=0xFF) 00144 { 00145 if (pdca_get_transfer_status(USART_LIN_NODE0_TX_PDCA_CHANNEL)&PDCA_TRANSFER_COMPLETE) 00146 { 00147 pdca_disable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL); 00148 // Start of the associated task 00149 lin_descript_list_node0[l_handle].l_pt_function(lin_descript_list_node0[l_handle].l_pt_data); 00150 lin_handle_node0 = 0xFF; // End of communication 00151 } 00152 } 00153 }
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.
l_node | Node Value | |
l_handle | Handle on the descriptor list | |
l_len | Message length corresponding to the message pointed by the handle in the descriptor list |
Definition at line 896 of file lin.c.
References lin_rx_buffer_node0, USART_LIN_NODE0_PDCA_PID_RX, USART_LIN_NODE0_RX_PDCA_CHANNEL, USART_LIN_NODE1_PDCA_PID_RX, and USART_LIN_NODE1_RX_PDCA_CHANNEL.
Referenced by lin_int_handler_node0(), and lin_send_cmd().
00899 { 00900 00901 if (l_node == 0) 00902 { 00903 // PDCA channel options 00904 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00905 { 00906 .addr = (void *)lin_rx_buffer_node0, // memory address 00907 .pid = USART_LIN_NODE0_PDCA_PID_RX, // select peripheral - data are transmit on USART TX line. 00908 .size = (l_len), // transfer counter 00909 .r_addr = NULL, // next memory address 00910 .r_size = 0, // next transfer counter 00911 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00912 }; 00913 00914 pdca_init_channel(USART_LIN_NODE0_RX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00915 00916 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_RX_PDCA_CHANNEL); 00917 // Start PDCA transfert Data 00918 pdca_enable(USART_LIN_NODE0_RX_PDCA_CHANNEL); 00919 return 1; 00920 } 00921 #ifdef USART_LIN_NODE1_INSTANCE 00922 else 00923 { 00924 // PDCA channel options 00925 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00926 { 00927 .addr = (void *)lin_rx_buffer_node1, // memory address 00928 .pid = USART_LIN_NODE1_PDCA_PID_RX, // select peripheral - data are transmit on USART TX line. 00929 .size = (l_len), // transfer counter 00930 .r_addr = NULL, // next memory address 00931 .r_size = 0, // next transfer counter 00932 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00933 }; 00934 00935 pdca_init_channel(USART_LIN_NODE1_RX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00936 00937 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_RX_PDCA_CHANNEL); 00938 // Start PDCA transfert Data 00939 pdca_enable(USART_LIN_NODE1_RX_PDCA_CHANNEL); 00940 return 1; 00941 } 00942 #endif 00943 }
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.
l_node | Node Value | |
l_id | LIN identifier value. In case of ‘LIN_1X’, the coded length is transported into the LIN identifier. | |
l_len | True length (not coded), number of data bytes transported in the response. This information is not used in ‘LIN_1X’ because it is coded in ‘l_id’. |
Definition at line 600 of file lin.c.
References lin_rx_response(), lin_tx_header_and_response(), NUMBER_OF_LIN_FRAMES_NODE0, PUBLISH, SUBSCRIBE, usart_lin_node0, and usart_reset_status().
Referenced by lin_master_task_ID12(), and lin_master_task_ID15().
00603 { 00604 U8 index = 0; 00605 U8 l_handle = 0; 00606 if (l_node == 0) 00607 { 00608 // Clear error in case of previous communication 00609 usart_reset_status(usart_lin_node0); 00610 00611 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE0; index ++) 00612 { 00613 if(lin_descript_list_node0[index].l_id == l_id) 00614 { 00615 l_handle = index; 00616 break; 00617 } 00618 } 00619 00620 if(l_handle != 0xFF) 00621 { 00622 usart_lin_set_node_action(usart_lin_node0,lin_descript_list_node0[l_handle].l_cmd); 00623 #if USART_LIN_VERSION == LIN_2x 00624 // Configure Parity 00625 usart_lin_enable_parity(usart_lin_node0,TRUE); 00626 // Configure Checksum 00627 usart_lin_enable_checksum(usart_lin_node0,TRUE); 00628 // Configure Checksum Type 00629 usart_lin_set_checksum(usart_lin_node0,USART_LIN_ENHANCED_CHECKSUM); 00630 // Configure Frameslot 00631 usart_lin_enable_frameslot(usart_lin_node0,FALSE); 00632 // Configure Frame Length 00633 usart_lin_set_data_length_lin2x(usart_lin_node0,l_len); 00634 #elif USART_LIN_VERSION == LIN_1x 00635 // Configure Parity 00636 usart_lin_enable_parity(usart_lin_node0,TRUE); 00637 // Configure Checksum 00638 usart_lin_enable_checksum(usart_lin_node0,TRUE); 00639 // Configure Checksum Type 00640 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM); 00641 // Configure Frameslot 00642 usart_lin_enable_frameslot(usart_lin_node0,FALSE); 00643 // Configure Frame Length 00644 usart_lin_set_data_length_lin1x(usart_lin_node0); 00645 #endif 00646 // Switch to Classic Checksum if diagnostic ID request 00647 if (lin_descript_list_node0[l_handle].l_id>=60) 00648 { 00649 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM); 00650 // Configure Frame Length 00651 usart_lin_set_data_length_lin1x(usart_lin_node0); 00652 } 00653 00654 switch (lin_descript_list_node0[l_handle].l_cmd) 00655 { 00656 // In Publish, the USART Send the Header and the response 00657 case PUBLISH: 00658 lin_tx_header_and_response(0,l_handle,l_len); 00659 break; 00660 // In Subscribe, the USART Receive the response 00661 case SUBSCRIBE: 00662 usart_lin_set_id_char(usart_lin_node0,l_id); 00663 lin_rx_response(0,l_handle,l_len); 00664 break; 00665 default: 00666 break; 00667 } 00668 return PASS; 00669 } 00670 else 00671 { 00672 return FAIL; 00673 } 00674 } 00675 #ifdef USART_LIN_NODE1_INSTANCE 00676 else 00677 { 00678 // Clear error in case of previous communication 00679 usart_reset_status(usart_lin_node1); 00680 00681 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE1; index ++) { 00682 if(lin_descript_list_node1[index].l_id == l_id) { 00683 l_handle = index; 00684 break; 00685 } 00686 } 00687 00688 if(l_handle != 0xFF) { 00689 00690 usart_lin_set_node_action(usart_lin_node1,lin_descript_list_node1[l_handle].l_cmd); 00691 00692 #if USART_LIN_VERSION == LIN_2x 00693 // Configure Parity 00694 usart_lin_enable_parity(usart_lin_node1,TRUE); 00695 // Configure Checksum 00696 usart_lin_enable_checksum(usart_lin_node1,TRUE); 00697 // Configure Checksum Type 00698 usart_lin_set_checksum(usart_lin_node1,USART_LIN_ENHANCED_CHECKSUM); 00699 // Configure Frameslot 00700 usart_lin_enable_frameslot(usart_lin_node1,FALSE); 00701 // Configure Frame Length 00702 usart_lin_set_data_length_lin2x(usart_lin_node1,l_len); 00703 #elif USART_LIN_VERSION == LIN_1x 00704 // Configure Parity 00705 usart_lin_enable_parity(usart_lin_node1,TRUE); 00706 // Configure Checksum 00707 usart_lin_enable_checksum(usart_lin_node1,TRUE); 00708 // Configure Checksum Type 00709 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM); 00710 // Configure Frameslot 00711 usart_lin_enable_frameslot(usart_lin_node1,FALSE); 00712 // Configure Frame Length 00713 usart_lin_set_data_length_lin1x(usart_lin_node1); 00714 #endif 00715 // Switch to Classic Checksum if diagnostic ID request 00716 if (lin_descript_list_node1[l_handle].l_id>=60) 00717 { 00718 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM); 00719 // Configure Frame Length 00720 usart_lin_set_data_length_lin1x(usart_lin_node1); 00721 } 00722 00723 switch (lin_descript_list_node0[l_handle].l_cmd) 00724 { 00725 // In Publish, the USART Send the Header and the response 00726 case PUBLISH: 00727 lin_tx_header_and_response(1,l_handle,l_len); 00728 break; 00729 // In Subscribe, the USART Receive the response 00730 case SUBSCRIBE: 00731 usart_lin_set_id_char(usart_lin_node1,l_id); 00732 lin_rx_response(1,l_handle,l_len); 00733 break; 00734 default: 00735 break; 00736 } 00737 return PASS; 00738 } 00739 else 00740 { 00741 return FAIL; 00742 } 00743 } 00744 #endif 00745 }
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.
l_node | Node Value | |
l_handle | Handle on the descriptor list | |
l_len | Message length corresponding to the message pointed by the handle in the descriptor list |
Definition at line 756 of file lin.c.
References st_lin_message::l_id, lin_tx_buffer_node0, USART_LIN_NODE0_PDCA_PID_TX, USART_LIN_NODE0_TX_PDCA_CHANNEL, USART_LIN_NODE1_PDCA_PID_TX, and USART_LIN_NODE1_TX_PDCA_CHANNEL.
Referenced by lin_send_cmd().
00760 { 00761 if (l_node == 0) 00762 { 00763 // PDCA channel options 00764 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00765 { 00766 .addr = (void *)lin_tx_buffer_node0, // memory address 00767 .pid = USART_LIN_NODE0_PDCA_PID_TX, // select peripheral - data are transmit on USART TX line. 00768 .size = (l_len+1), // transfer counter 00769 .r_addr = NULL, // next memory address 00770 .r_size = 0, // next transfer counter 00771 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00772 }; 00773 00774 pdca_init_channel(USART_LIN_NODE0_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00775 00776 // Copy data of the data contained in the descriptor list into the tx buffer of the PDCA 00777 memcpy(&lin_tx_buffer_node0[1],lin_descript_list_node0[l_handle].l_pt_data,l_len); 00778 00779 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL); 00780 00781 // Set the ID First 00782 lin_tx_buffer_node0[0] = lin_descript_list_node0[l_handle].l_id; 00783 00784 // Start PDCA transfert ID + Data 00785 pdca_enable(USART_LIN_NODE0_TX_PDCA_CHANNEL); 00786 return PASS; 00787 } 00788 #ifdef USART_LIN_NODE1_INSTANCE 00789 else 00790 { 00791 00792 // PDCA channel options 00793 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00794 { 00795 .addr = (void *)lin_tx_buffer_node1, // memory address 00796 .pid = USART_LIN_NODE1_PDCA_PID_TX, // select peripheral - data are transmit on USART TX line. 00797 .size = (l_len+1), // transfer counter 00798 .r_addr = NULL, // next memory address 00799 .r_size = 0, // next transfer counter 00800 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00801 }; 00802 00803 pdca_init_channel(USART_LIN_NODE1_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00804 00805 // Copy data of the data contained in the descriptor list into the tx buffer of the PDCA 00806 memcpy(&lin_tx_buffer_node1[1],lin_descript_list_node1[l_handle].l_pt_data,l_len); 00807 00808 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL); 00809 00810 // Set the ID First 00811 lin_tx_buffer_node1[0] = lin_descript_list_node1[l_handle].l_id; 00812 00813 // Start PDCA transfert ID + Data 00814 pdca_enable(USART_LIN_NODE1_TX_PDCA_CHANNEL); 00815 return PASS; 00816 } 00817 #endif 00818 }
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.
l_node | Node Value | |
l_handle | Handle on the descriptor list | |
l_data | Pointer on the data corresponding to the message pointed by the handle in the descriptor list | |
l_len | Message length corresponding to the message pointed by the handle in the descriptor list |
Definition at line 830 of file lin.c.
References lin_tx_buffer_node0, USART_LIN_NODE0_PDCA_PID_TX, USART_LIN_NODE0_TX_PDCA_CHANNEL, USART_LIN_NODE1_PDCA_PID_TX, and USART_LIN_NODE1_TX_PDCA_CHANNEL.
Referenced by lin_int_handler_node0().
00834 { 00835 00836 if (l_node == 0) 00837 { 00838 00839 // PDCA channel options 00840 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00841 { 00842 .addr = (void *)lin_tx_buffer_node0, // memory address 00843 .pid = USART_LIN_NODE0_PDCA_PID_TX, // select peripheral - data are transmit on USART TX line. 00844 .size = (l_len), // transfer counter 00845 .r_addr = NULL, // next memory address 00846 .r_size = 0, // next transfer counter 00847 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00848 }; 00849 00850 pdca_init_channel(USART_LIN_NODE0_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00851 00852 // Copy data of the data contained in the descriptor list into the tx buffer of the PDCA 00853 memcpy(&lin_tx_buffer_node0[0],lin_descript_list_node0[l_handle].l_pt_data,l_len+1); 00854 00855 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL); 00856 // Start PDCA transfert Data 00857 pdca_enable(USART_LIN_NODE0_TX_PDCA_CHANNEL); 00858 return 1; 00859 } 00860 #ifdef USART_LIN_NODE1_INSTANCE 00861 else 00862 { 00863 // PDCA channel options 00864 pdca_channel_options_t USART_LIN_PDCA_OPTIONS = 00865 { 00866 .addr = (void *)lin_tx_buffer_node1, // memory address 00867 .pid = USART_LIN_NODE1_PDCA_PID_TX, // select peripheral - data are transmit on USART TX line. 00868 .size = (l_len), // transfer counter 00869 .r_addr = NULL, // next memory address 00870 .r_size = 0, // next transfer counter 00871 .transfer_size = PDCA_TRANSFER_SIZE_BYTE // select size of the transfer 00872 }; 00873 00874 pdca_init_channel(USART_LIN_NODE1_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS); 00875 00876 // Copy data of the data contained in the descriptor list into the tx buffer of the PDCA 00877 memcpy(&lin_tx_buffer_node1[0],lin_descript_list_node1[l_handle].l_pt_data,l_len+1); 00878 00879 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL); 00880 // Start PDCA transfert Data 00881 pdca_enable(USART_LIN_NODE1_TX_PDCA_CHANNEL); 00882 return 1; 00883 } 00884 #endif 00885 }
volatile st_lin_message lin_descript_list_node0[NUMBER_OF_LIN_FRAMES_NODE0] |
Array of structure of type:'st_lin_message'. Default: 8 elements.
Definition at line 59 of file lin.c.
Referenced by lin_master_task_ID12(), lin_master_task_ID15(), and main().
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).
Definition at line 71 of file lin.c.
Referenced by lin_int_handler_node0().
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.
Definition at line 65 of file lin.c.
Referenced by lin_int_handler_node0(), lin_pdca_int_rx_handler_node0(), and lin_pdca_int_tx_handler_node0().
volatile U16 lin_last_errors_node0[LIN_LAST_ERR_LENGHT] |
Last error FIFO: lin_handle | status. Default: 4 elements.
Definition at line 77 of file lin.c.
Referenced by lin_int_handler_node0().
volatile U8 lin_rx_buffer_node0[256] |
U8 lin_tx_buffer_node0[256] |
Definition at line 83 of file lin.c.
Referenced by lin_tx_header_and_response(), and lin_tx_response().
volatile avr32_usart_t* usart_lin_node0 = &USART_LIN_NODE0_INSTANCE |
Instance of the USART IP used.
Definition at line 110 of file lin.c.
Referenced by lin_get_response(), lin_init(), lin_int_handler_node0(), lin_pdca_int_rx_handler_node0(), lin_pdca_int_tx_handler_node0(), and lin_send_cmd().
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} }
Definition at line 95 of file lin.c.
Referenced by lin_init().