00001
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include <stdio.h>
00049 #include <string.h>
00050 #include "compiler.h"
00051 #include "intc.h"
00052 #include "pdca.h"
00053 #include "gpio.h"
00054 #include "lin.h"
00055
00056
00057
00058
00059 volatile st_lin_message lin_descript_list_node0[NUMBER_OF_LIN_FRAMES_NODE0];
00060 #ifdef USART_LIN_NODE1_INSTANCE
00061 volatile st_lin_message lin_descript_list_node1[NUMBER_OF_LIN_FRAMES_NODE1];
00062 #endif
00063
00064
00065 volatile U8 lin_handle_node0 = 0xFF;
00066 #ifdef USART_LIN_NODE1_INSTANCE
00067 volatile U8 lin_handle_node1 = 0xFF;
00068 #endif
00069
00070
00071 volatile U16 lin_error_number_node0 = 0;
00072 #ifdef USART_LIN_NODE1_INSTANCE
00073 volatile U16 lin_error_number_node1 = 0;
00074 #endif
00075
00076
00077 volatile U16 lin_last_errors_node0[LIN_LAST_ERR_LENGHT];
00078 #ifdef USART_LIN_NODE1_INSTANCE
00079 volatile U16 lin_last_errors_node1[LIN_LAST_ERR_LENGHT];
00080 #endif
00081
00082
00083 U8 lin_tx_buffer_node0[256];
00084 #ifdef USART_LIN_NODE1_INSTANCE
00085 U8 lin_tx_buffer_node1[256];
00086 #endif
00087
00088
00089 volatile U8 lin_rx_buffer_node0[256];
00090 #ifdef USART_LIN_NODE1_INSTANCE
00091 volatile U8 lin_rx_buffer_node1[256];
00092 #endif
00093
00095 static const gpio_map_t USART_LIN_NODE0_GPIO_MAP =
00096 {
00097 {USART_LIN_NODE0_RX_PIN, USART_LIN_NODE0_RX_FUNCTION},
00098 {USART_LIN_NODE0_TX_PIN, USART_LIN_NODE0_TX_FUNCTION}
00099 };
00100
00101 #ifdef USART_LIN_NODE1_INSTANCE
00102 static const gpio_map_t USART_LIN_NODE1_GPIO_MAP =
00103 {
00104 {USART_LIN_NODE1_RX_PIN, USART_LIN_NODE1_RX_FUNCTION},
00105 {USART_LIN_NODE1_TX_PIN, USART_LIN_NODE1_TX_FUNCTION}
00106 };
00107 #endif
00108
00110 volatile avr32_usart_t* usart_lin_node0 = &USART_LIN_NODE0_INSTANCE;
00111 #ifdef USART_LIN_NODE1_INSTANCE
00112 volatile avr32_usart_t* usart_lin_node1 = &USART_LIN_NODE1_INSTANCE;
00113 #endif
00114
00115
00116
00117 static U8 lin_rx_response( U8 l_node, U8 l_handle, U8 l_len);
00118 static U8 lin_tx_response( U8 l_node, U8 l_handle, U8 *l_data, U8 l_len) ;
00119 static void lin_get_response(U8 l_node, U8 *l_data);
00120 static U8 lin_tx_header_and_response(U8 l_node, U8 l_handle, U8 l_len);
00121
00124 #if defined (__GNUC__) && defined (__AVR32__)
00125 __attribute__((__interrupt__))
00126 #elif defined (__ICCAVR32__)
00127 #pragma handler = USART_LIN_NODE0_TX_PDCA_IRQ_GROUP, USART_LIN_NODE0_TX_PDCA_CHANNEL
00128 __interrupt
00129 #endif
00130 static void lin_pdca_int_tx_handler_node0(void)
00131 {
00132 U8 index = 0;
00133 U8 l_handle = 0xFF;
00134
00135
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
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
00149 lin_descript_list_node0[l_handle].l_pt_function(lin_descript_list_node0[l_handle].l_pt_data);
00150 lin_handle_node0 = 0xFF;
00151 }
00152 }
00153 }
00154
00157 #if defined (__GNUC__) && defined (__AVR32__)
00158 __attribute__((__interrupt__))
00159 #elif defined (__ICCAVR32__)
00160 #pragma handler = USART_LIN_NODE0_RX_PDCA_IRQ_GROUP, USART_LIN_NODE0_RX_PDCA_CHANNEL
00161 __interrupt
00162 #endif
00163 static void lin_pdca_int_rx_handler_node0(void)
00164 {
00165 U8 index = 0;
00166 U8 l_handle = 0xFF;
00167
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
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
00182 lin_descript_list_node0[l_handle].l_pt_function(lin_descript_list_node0[l_handle].l_pt_data);
00183 lin_handle_node0 = 0xFF;
00184 }
00185 }
00186 }
00189 #if defined (__GNUC__) && defined (__AVR32__)
00190 __attribute__((__interrupt__))
00191 #elif defined (__ICCAVR32__)
00192 __interrupt
00193 #endif
00194 static void lin_int_handler_node0(void)
00195 {
00196 U32 l_error;
00197 U8 index;
00198 U8 l_handle = 0xFF;
00199
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
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;
00221 }
00222
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
00231 usart_lin_enable_parity(usart_lin_node0,TRUE);
00232
00233 usart_lin_enable_checksum(usart_lin_node0,TRUE);
00234
00235 usart_lin_set_checksum(usart_lin_node0,USART_LIN_ENHANCED_CHECKSUM);
00236
00237 usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00238
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
00242 usart_lin_enable_parity(usart_lin_node0,TRUE);
00243
00244 usart_lin_enable_checksum(usart_lin_node0,TRUE);
00245
00246 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM);
00247
00248 usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00249
00250 usart_lin_set_data_length_lin1x(usart_lin_node0);
00251 #endif
00252
00253
00254 if((usart_lin_get_id_char(usart_lin_node0)>=60)) {
00255 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM);
00256
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;
00279 break;
00280 }
00281 }
00282 }
00283 }
00284
00285 #ifdef USART_LIN_NODE1_INSTANCE
00286
00288 #if defined (__GNUC__) && defined (__AVR32__)
00289 __attribute__((__interrupt__))
00290 #elif defined (__ICCAVR32__)
00291 #pragma handler = USART_LIN_NODE1_TX_PDCA_IRQ_GROUP, USART_LIN_NODE1_TX_PDCA_CHANNEL
00292 __interrupt
00293 #endif
00294 static void lin_pdca_int_tx_handler_node1(void)
00295 {
00296 U8 index = 0;
00297 U8 l_handle = 0xFF;
00298
00299 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE1; index ++)
00300 {
00301 if(lin_descript_list_node1[index].l_id == usart_lin_get_id_char(usart_lin_node1))
00302 {
00303 l_handle = index;
00304 break;
00305 }
00306 }
00307
00308
00309 if (l_handle!=0xFF)
00310 {
00311 if (pdca_get_transfer_status(USART_LIN_NODE1_TX_PDCA_CHANNEL)&PDCA_TRANSFER_COMPLETE)
00312 {
00313 pdca_disable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00314
00315 lin_descript_list_node1[l_handle].l_pt_function(lin_descript_list_node1[l_handle].l_pt_data);
00316 lin_handle_node1 = 0xFF;
00317 }
00318 }
00319 }
00320
00323 #if defined (__GNUC__) && defined (__AVR32__)
00324 __attribute__((__interrupt__))
00325 #elif defined (__ICCAVR32__)
00326 #pragma handler = USART_LIN_NODE1_RX_PDCA_IRQ_GROUP, USART_LIN_NODE1_RX_PDCA_CHANNEL
00327 __interrupt
00328 #endif
00329 static void lin_pdca_int_rx_handler_node1(void)
00330 {
00331 U8 index = 0;
00332 U8 l_handle = 0xFF;
00333
00334 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE1; index ++)
00335 {
00336 if(lin_descript_list_node1[index].l_id == usart_lin_get_id_char(usart_lin_node1))
00337 {
00338 l_handle = index;
00339 break;
00340 }
00341 }
00342
00343
00344 if (l_handle!=0xFF)
00345 {
00346 if (pdca_get_transfer_status(USART_LIN_NODE1_RX_PDCA_CHANNEL)&PDCA_TRANSFER_COMPLETE)
00347 {
00348 pdca_disable_interrupt_transfer_complete(USART_LIN_NODE1_RX_PDCA_CHANNEL);
00349 lin_get_response (1,lin_descript_list_node1[l_handle].l_pt_data);
00350
00351 lin_descript_list_node1[l_handle].l_pt_function(lin_descript_list_node1[l_handle].l_pt_data);
00352 lin_handle_node1 = 0xFF;
00353 }
00354 }
00355 }
00358 #if defined (__GNUC__) && defined (__AVR32__)
00359 __attribute__((__interrupt__))
00360 #elif defined (__ICCAVR32__)
00361 __interrupt
00362 #endif
00363 static void lin_int_handler_node1(void)
00364 {
00365 U32 l_error;
00366 U8 index;
00367 U8 l_handle = 0xFF;
00368
00369 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE1; index ++)
00370 {
00371 if(lin_descript_list_node1[index].l_id == usart_lin_get_id_char(usart_lin_node1))
00372 {
00373 l_handle = index;
00374 break;
00375 }
00376 }
00377
00378
00379 l_error = usart_lin_get_error(usart_lin_node1);
00380 usart_reset_status(usart_lin_node1);
00381 if (l_error!=0)
00382 {
00383 if(l_handle != 0xFF)
00384 {
00385 lin_descript_list_node1[l_handle].l_status = l_error;
00386 }
00387 lin_last_errors_node1[(((U8)lin_error_number_node1) & (LIN_LAST_ERR_LENGHT-1))] \
00388 = ((((U16)l_handle)<<8) | ((U16)l_error)) ;
00389 lin_error_number_node1++;
00390 lin_handle_node1 = 0xFF;
00391 }
00392
00393 else
00394 {
00395 usart_lin_set_node_action(usart_lin_node1,lin_descript_list_node1[l_handle].l_cmd);
00396
00397 if(l_handle != 0xFF) {
00398 #if USART_LIN_VERSION == LIN_2x
00399
00400 usart_lin_enable_parity(usart_lin_node1,TRUE);
00401
00402 usart_lin_enable_checksum(usart_lin_node1,TRUE);
00403
00404 usart_lin_set_checksum(usart_lin_node1,USART_LIN_ENHANCED_CHECKSUM);
00405
00406 usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00407
00408 usart_lin_set_data_length_lin2x(usart_lin_node1,lin_descript_list_node1[l_handle].l_dlc);
00409 #elif USART_LIN_VERSION == LIN_1x
00410
00411 usart_lin_enable_parity(usart_lin_node1,TRUE);
00412
00413 usart_lin_enable_checksum(usart_lin_node1,TRUE);
00414
00415 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM);
00416
00417 usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00418
00419 usart_lin_set_data_length_lin1x(usart_lin_node1);
00420 #endif
00421
00422
00423 if((usart_lin_get_id_char(usart_lin_node1)>=60))
00424 {
00425 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM);
00426
00427 usart_lin_set_data_length_lin1x(usart_lin_node1);
00428 }
00429
00430 switch (lin_descript_list_node1[l_handle].l_cmd)
00431 {
00432
00433 case PUBLISH:
00434 lin_tx_response ( 1,
00435 l_handle,
00436 lin_descript_list_node1[l_handle].l_pt_data,
00437 lin_descript_list_node1[l_handle].l_dlc) ;
00438 break;
00439
00440 case SUBSCRIBE:
00441 lin_rx_response ( 1,
00442 l_handle,
00443 lin_descript_list_node1[l_handle].l_dlc) ;
00444 break;
00445
00446 case IGNORE:
00447 default:
00448 lin_handle_node1 = 0xFF;
00449 break;
00450 }
00451 }
00452 }
00453 }
00454 #endif
00455
00458
00459
00470 U8 lin_init (Bool master,
00471 U8 l_node,
00472 U16 b_rate,
00473 long pba_hz) {
00474 if (l_node == 0)
00475 {
00476
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
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 #if ( defined (AVR32_USART_400_H_INCLUDED) || \
00494 defined (AVR32_USART_410_H_INCLUDED) || \
00495 defined (AVR32_USART_420_H_INCLUDED) )
00496 usart_lin_node0->ier = AVR32_USART_IER_LINIR_MASK |
00497 AVR32_USART_IER_LINBE_MASK |
00498 AVR32_USART_IER_LINISFE_MASK |
00499 AVR32_USART_IER_LINIPE_MASK |
00500 AVR32_USART_IER_LINCE_MASK |
00501 AVR32_USART_IER_LINSNRE_MASK;
00503 INTC_register_interrupt(&lin_int_handler_node0,
00504 USART_LIN_NODE0_USART_IRQ,
00505 USART_LIN_NODE0_USART_IRQ_LEVEL);
00506 #else
00507
00508 usart_lin_node0->ier = AVR32_USART_IER_LINID_MASK |
00509 AVR32_USART_IER_LINBE_MASK |
00510 AVR32_USART_IER_LINISFE_MASK |
00511 AVR32_USART_IER_LINIPE_MASK |
00512 AVR32_USART_IER_LINCE_MASK |
00513 AVR32_USART_IER_LINSNRE_MASK;
00515 INTC_register_interrupt(&lin_int_handler_node0,
00516 USART_LIN_NODE0_USART_IRQ,
00517 USART_LIN_NODE0_USART_IRQ_LEVEL);
00518 #endif
00519 }
00520
00522 INTC_register_interrupt(&lin_pdca_int_tx_handler_node0,
00523 USART_LIN_NODE0_PDCA_TX_IRQ,
00524 USART_LIN_NODE0_PDCA_TX_IRQ_LEVEL);
00525
00527 INTC_register_interrupt(&lin_pdca_int_rx_handler_node0,
00528 USART_LIN_NODE0_PDCA_RX_IRQ,
00529 USART_LIN_NODE0_PDCA_RX_IRQ_LEVEL);
00530
00531 }
00532 #ifdef USART_LIN_NODE1_INSTANCE
00533 else
00534 {
00535
00536 gpio_enable_module(USART_LIN_NODE1_GPIO_MAP,
00537 sizeof(USART_LIN_NODE1_GPIO_MAP) / sizeof(USART_LIN_NODE1_GPIO_MAP[0]));
00538
00539
00540 gpio_enable_pin_pull_up(USART_LIN_NODE1_RX_PIN);
00541
00542
00543 if (master)
00544 usart_init_lin_master(usart_lin_node1,b_rate,pba_hz);
00545 else
00546 usart_init_lin_slave(usart_lin_node1,b_rate,pba_hz);
00547
00548 Disable_global_interrupt();
00549
00550 if (master==FALSE)
00551 {
00553 #if ( defined (AVR32_USART_400_H_INCLUDED) || \
00554 defined (AVR32_USART_410_H_INCLUDED) || \
00555 defined (AVR32_USART_420_H_INCLUDED) )
00556 usart_lin_node1->ier = AVR32_USART_IER_LINIR_MASK |
00557 AVR32_USART_IER_LINBE_MASK |
00558 AVR32_USART_IER_LINISFE_MASK |
00559 AVR32_USART_IER_LINIPE_MASK |
00560 AVR32_USART_IER_LINCE_MASK |
00561 AVR32_USART_IER_LINSNRE_MASK;
00563 INTC_register_interrupt(&lin_int_handler_node1,
00564 USART_LIN_NODE1_USART_IRQ,
00565 USART_LIN_NODE1_USART_IRQ_LEVEL);
00566 #else
00567 usart_lin_node1->ier = AVR32_USART_IER_LINID_MASK |
00568 AVR32_USART_IER_LINBE_MASK |
00569 AVR32_USART_IER_LINISFE_MASK |
00570 AVR32_USART_IER_LINIPE_MASK |
00571 AVR32_USART_IER_LINCE_MASK |
00572 AVR32_USART_IER_LINSNRE_MASK;
00574 INTC_register_interrupt(&lin_int_handler_node1,
00575 USART_LIN_NODE1_USART_IRQ,
00576 USART_LIN_NODE1_USART_IRQ_LEVEL);
00577 #endif
00578 }
00579
00581 INTC_register_interrupt(&lin_pdca_int_tx_handler_node1,
00582 USART_LIN_NODE1_PDCA_TX_IRQ,
00583 USART_LIN_NODE1_PDCA_TX_IRQ_LEVEL);
00584
00586 INTC_register_interrupt(&lin_pdca_int_rx_handler_node1,
00587 USART_LIN_NODE1_PDCA_RX_IRQ,
00588 USART_LIN_NODE1_PDCA_RX_IRQ_LEVEL);
00589 }
00590 #endif
00591 return PASS;
00592 }
00593
00604 U8 lin_send_cmd ( U8 l_node,
00605 U8 l_id,
00606 U8 l_len
00607 ){
00608 U8 index = 0;
00609 U8 l_handle = 0;
00610 if (l_node == 0)
00611 {
00612
00613 usart_reset_status(usart_lin_node0);
00614
00615 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE0; index ++)
00616 {
00617 if(lin_descript_list_node0[index].l_id == l_id)
00618 {
00619 l_handle = index;
00620 break;
00621 }
00622 }
00623
00624 if(l_handle != 0xFF)
00625 {
00626 usart_lin_set_node_action(usart_lin_node0,lin_descript_list_node0[l_handle].l_cmd);
00627 #if USART_LIN_VERSION == LIN_2x
00628
00629 usart_lin_enable_parity(usart_lin_node0,TRUE);
00630
00631 usart_lin_enable_checksum(usart_lin_node0,TRUE);
00632
00633 usart_lin_set_checksum(usart_lin_node0,USART_LIN_ENHANCED_CHECKSUM);
00634
00635 usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00636
00637 usart_lin_set_data_length_lin2x(usart_lin_node0,l_len);
00638 #elif USART_LIN_VERSION == LIN_1x
00639
00640 usart_lin_enable_parity(usart_lin_node0,TRUE);
00641
00642 usart_lin_enable_checksum(usart_lin_node0,TRUE);
00643
00644 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM);
00645
00646 usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00647
00648 usart_lin_set_data_length_lin1x(usart_lin_node0);
00649 #endif
00650
00651 if (lin_descript_list_node0[l_handle].l_id>=60)
00652 {
00653 usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM);
00654
00655 usart_lin_set_data_length_lin1x(usart_lin_node0);
00656 }
00657
00658 switch (lin_descript_list_node0[l_handle].l_cmd)
00659 {
00660
00661 case PUBLISH:
00662 lin_tx_header_and_response(0,l_handle,l_len);
00663 break;
00664
00665 case SUBSCRIBE:
00666 usart_lin_set_id_char(usart_lin_node0,l_id);
00667 lin_rx_response(0,l_handle,l_len);
00668 break;
00669 default:
00670 break;
00671 }
00672 return PASS;
00673 }
00674 else
00675 {
00676 return FAIL;
00677 }
00678 }
00679 #ifdef USART_LIN_NODE1_INSTANCE
00680 else
00681 {
00682
00683 usart_reset_status(usart_lin_node1);
00684
00685 for(index = 0; index < NUMBER_OF_LIN_FRAMES_NODE1; index ++) {
00686 if(lin_descript_list_node1[index].l_id == l_id) {
00687 l_handle = index;
00688 break;
00689 }
00690 }
00691
00692 if(l_handle != 0xFF) {
00693
00694 usart_lin_set_node_action(usart_lin_node1,lin_descript_list_node1[l_handle].l_cmd);
00695
00696 #if USART_LIN_VERSION == LIN_2x
00697
00698 usart_lin_enable_parity(usart_lin_node1,TRUE);
00699
00700 usart_lin_enable_checksum(usart_lin_node1,TRUE);
00701
00702 usart_lin_set_checksum(usart_lin_node1,USART_LIN_ENHANCED_CHECKSUM);
00703
00704 usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00705
00706 usart_lin_set_data_length_lin2x(usart_lin_node1,l_len);
00707 #elif USART_LIN_VERSION == LIN_1x
00708
00709 usart_lin_enable_parity(usart_lin_node1,TRUE);
00710
00711 usart_lin_enable_checksum(usart_lin_node1,TRUE);
00712
00713 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM);
00714
00715 usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00716
00717 usart_lin_set_data_length_lin1x(usart_lin_node1);
00718 #endif
00719
00720 if (lin_descript_list_node1[l_handle].l_id>=60)
00721 {
00722 usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM);
00723
00724 usart_lin_set_data_length_lin1x(usart_lin_node1);
00725 }
00726
00727 switch (lin_descript_list_node0[l_handle].l_cmd)
00728 {
00729
00730 case PUBLISH:
00731 lin_tx_header_and_response(1,l_handle,l_len);
00732 break;
00733
00734 case SUBSCRIBE:
00735 usart_lin_set_id_char(usart_lin_node1,l_id);
00736 lin_rx_response(1,l_handle,l_len);
00737 break;
00738 default:
00739 break;
00740 }
00741 return PASS;
00742 }
00743 else
00744 {
00745 return FAIL;
00746 }
00747 }
00748 #endif
00749 }
00750
00760 static U8 lin_tx_header_and_response( U8 l_node,
00761 U8 l_handle,
00762 U8 l_len
00763 )
00764 {
00765 if (l_node == 0)
00766 {
00768 #if ( defined (AVR32_USART_400_H_INCLUDED) || \
00769 defined (AVR32_USART_410_H_INCLUDED) || \
00770 defined (AVR32_USART_420_H_INCLUDED) )
00771
00772 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00773 {
00774 .addr = (void *)lin_tx_buffer_node0,
00775 .pid = USART_LIN_NODE0_PDCA_PID_TX,
00776 .size = (l_len+1),
00777 .r_addr = NULL,
00778 .r_size = 0,
00779 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00780 };
00781
00782 pdca_init_channel(USART_LIN_NODE0_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00783
00784
00785 memcpy(&lin_tx_buffer_node0[1],lin_descript_list_node0[l_handle].l_pt_data,l_len);
00786
00787 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00788
00789
00790 lin_tx_buffer_node0[0] = lin_descript_list_node0[l_handle].l_id;
00791
00792
00793 pdca_enable(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00794
00795 usart_lin_set_id_char(usart_lin_node0,lin_descript_list_node0[l_handle].l_id);
00796 #else
00797
00798 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00799 {
00800 .addr = (void *)lin_tx_buffer_node0,
00801 .pid = USART_LIN_NODE0_PDCA_PID_TX,
00802 .size = (l_len+1),
00803 .r_addr = NULL,
00804 .r_size = 0,
00805 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00806 };
00807
00808 pdca_init_channel(USART_LIN_NODE0_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00809
00810
00811 memcpy(&lin_tx_buffer_node0[1],lin_descript_list_node0[l_handle].l_pt_data,l_len);
00812
00813 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00814
00815
00816 lin_tx_buffer_node0[0] = lin_descript_list_node0[l_handle].l_id;
00817
00818
00819 pdca_enable(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00820 #endif
00821 return PASS;
00822 }
00823 #ifdef USART_LIN_NODE1_INSTANCE
00824 else
00825 {
00827 #if ( defined (AVR32_USART_400_H_INCLUDED) || \
00828 defined (AVR32_USART_410_H_INCLUDED) || \
00829 defined (AVR32_USART_420_H_INCLUDED) )
00830
00831 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00832 {
00833 .addr = (void *)lin_tx_buffer_node1,
00834 .pid = USART_LIN_NODE1_PDCA_PID_TX,
00835 .size = (l_len+1),
00836 .r_addr = NULL,
00837 .r_size = 0,
00838 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00839 };
00840
00841 pdca_init_channel(USART_LIN_NODE1_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00842
00843
00844 memcpy(&lin_tx_buffer_node1[1],lin_descript_list_node1[l_handle].l_pt_data,l_len);
00845
00846 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00847
00848
00849 lin_tx_buffer_node1[0] = lin_descript_list_node1[l_handle].l_id;
00850
00851
00852 pdca_enable(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00853
00854 usart_lin_set_id_char(usart_lin_node1,lin_descript_list_node1[l_handle].l_id);
00855 #else
00856
00857 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00858 {
00859 .addr = (void *)lin_tx_buffer_node1,
00860 .pid = USART_LIN_NODE1_PDCA_PID_TX,
00861 .size = (l_len+1),
00862 .r_addr = NULL,
00863 .r_size = 0,
00864 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00865 };
00866
00867 pdca_init_channel(USART_LIN_NODE1_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00868
00869
00870 memcpy(&lin_tx_buffer_node1[1],lin_descript_list_node1[l_handle].l_pt_data,l_len);
00871
00872 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00873
00874
00875 lin_tx_buffer_node1[0] = lin_descript_list_node1[l_handle].l_id;
00876
00877
00878 pdca_enable(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00879 #endif
00880 return PASS;
00881 }
00882 #endif
00883 }
00884
00895 static U8 lin_tx_response ( U8 l_node,
00896 U8 l_handle,
00897 U8 *l_data,
00898 U8 l_len
00899 ) {
00900
00901 if (l_node == 0)
00902 {
00903
00904 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00905 {
00906 .addr = (void *)lin_tx_buffer_node0,
00907 .pid = USART_LIN_NODE0_PDCA_PID_TX,
00908 .size = (l_len),
00909 .r_addr = NULL,
00910 .r_size = 0,
00911 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00912 };
00913
00914 pdca_init_channel(USART_LIN_NODE0_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00915
00916
00917 memcpy(&lin_tx_buffer_node0[0],lin_descript_list_node0[l_handle].l_pt_data,l_len+1);
00918
00919 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00920
00921 pdca_enable(USART_LIN_NODE0_TX_PDCA_CHANNEL);
00922 return 1;
00923 }
00924 #ifdef USART_LIN_NODE1_INSTANCE
00925 else
00926 {
00927
00928 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00929 {
00930 .addr = (void *)lin_tx_buffer_node1,
00931 .pid = USART_LIN_NODE1_PDCA_PID_TX,
00932 .size = (l_len),
00933 .r_addr = NULL,
00934 .r_size = 0,
00935 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00936 };
00937
00938 pdca_init_channel(USART_LIN_NODE1_TX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00939
00940
00941 memcpy(&lin_tx_buffer_node1[0],lin_descript_list_node1[l_handle].l_pt_data,l_len+1);
00942
00943 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00944
00945 pdca_enable(USART_LIN_NODE1_TX_PDCA_CHANNEL);
00946 return 1;
00947 }
00948 #endif
00949 }
00950
00960 static U8 lin_rx_response ( U8 l_node,
00961 U8 l_handle,
00962 U8 l_len
00963 ) {
00964
00965 if (l_node == 0)
00966 {
00967
00968 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00969 {
00970 .addr = (void *)lin_rx_buffer_node0,
00971 .pid = USART_LIN_NODE0_PDCA_PID_RX,
00972 .size = (l_len),
00973 .r_addr = NULL,
00974 .r_size = 0,
00975 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00976 };
00977
00978 pdca_init_channel(USART_LIN_NODE0_RX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
00979
00980 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE0_RX_PDCA_CHANNEL);
00981
00982 pdca_enable(USART_LIN_NODE0_RX_PDCA_CHANNEL);
00983 return 1;
00984 }
00985 #ifdef USART_LIN_NODE1_INSTANCE
00986 else
00987 {
00988
00989 pdca_channel_options_t USART_LIN_PDCA_OPTIONS =
00990 {
00991 .addr = (void *)lin_rx_buffer_node1,
00992 .pid = USART_LIN_NODE1_PDCA_PID_RX,
00993 .size = (l_len),
00994 .r_addr = NULL,
00995 .r_size = 0,
00996 .transfer_size = PDCA_TRANSFER_SIZE_BYTE
00997 };
00998
00999 pdca_init_channel(USART_LIN_NODE1_RX_PDCA_CHANNEL, &USART_LIN_PDCA_OPTIONS);
01000
01001 pdca_enable_interrupt_transfer_complete(USART_LIN_NODE1_RX_PDCA_CHANNEL);
01002
01003 pdca_enable(USART_LIN_NODE1_RX_PDCA_CHANNEL);
01004 return 1;
01005 }
01006 #endif
01007 }
01008
01009
01020 static void lin_get_response (U8 l_node, U8 *l_data) {
01021
01022 U8 i, l_len;
01023 if (l_node == 0)
01024 {
01025 l_len = usart_lin_get_data_length(usart_lin_node0);
01026 for (i = 0; i < l_len; i++) {
01027 (*l_data++) = lin_rx_buffer_node0[i];
01028 }
01029 }
01030 #ifdef USART_LIN_NODE1_INSTANCE
01031 else
01032 {
01033 l_len = usart_lin_get_data_length(usart_lin_node1);
01034 for (i = 0; i < l_len; i++) {
01035 (*l_data++) = lin_rx_buffer_node1[i];
01036 }
01037 }
01038 #endif
01039
01040 }