lin.h File Reference


Detailed Description

LIN service for AVR32 UC3.

This file contains basic functions for the AVR32 USART, with support for all modes, settings and clock speeds.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file lin.h.

#include <avr32/io.h>
#include "compiler.h"
#include "usart.h"
#include "conf_lin.h"

Go to the source code of this file.

Data Structures

struct  st_lin_message
 This structure allows to handle a LIN message and, at the end of the received/transmitted message, allows to call a function associated to this message, the update or the capture of "signals". More...

Defines

#define LIN_LAST_ERR_LENGHT   0x04
 Default lenght of the 'lin_last_error[]' array.
#define LIN_OVERLOAD_INT   ((U16)0x00FF)
 Error report definitions.
#define NUMBER_OF_LIN_FRAMES_NODE0   8
LIN Versions
#define LIN_1x   1
 Lin 1.x Version.
#define LIN_2x   0
 Lin 2.x Version.

Enumerations

enum  enum_lin_cmd { PUBLISH, SUBSCRIBE, IGNORE }
 This enumeration is used to select an action for a specific message declared in st_lin_message structure. Note: XXX_STAND_BY keeps the direction (PUBLISH or SUBSCRIBE) for a message that will be IGNORE. When the 'stand_by' will be finished, PUBLISH_STAND_BY would become PUBLISH and SUBSCRIBE_STAND_BY would become SUBSCRIBE. An IGNORE message could become either PUBLISH or SUBSCRIBE. More...

Functions

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.
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.

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
 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
 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 []
 Last error FIFO: lin_handle | status. Default: 4 elements.


Define Documentation

#define LIN_1x   1

Lin 1.x Version.

Definition at line 65 of file lin.h.

#define LIN_2x   0

Lin 2.x Version.

Definition at line 64 of file lin.h.

#define LIN_LAST_ERR_LENGHT   0x04

Default lenght of the 'lin_last_error[]' array.

Definition at line 127 of file lin.h.

Referenced by lin_int_handler_node0().

#define LIN_OVERLOAD_INT   ((U16)0x00FF)

Error report definitions.

More than ONE interrupt in the same time !

Definition at line 125 of file lin.h.

#define NUMBER_OF_LIN_FRAMES_NODE0   8


Enumeration Type Documentation

This enumeration is used to select an action for a specific message declared in st_lin_message structure. Note: XXX_STAND_BY keeps the direction (PUBLISH or SUBSCRIBE) for a message that will be IGNORE. When the 'stand_by' will be finished, PUBLISH_STAND_BY would become PUBLISH and SUBSCRIBE_STAND_BY would become SUBSCRIBE. An IGNORE message could become either PUBLISH or SUBSCRIBE.

Enumerator:
PUBLISH  The node sends the response.
SUBSCRIBE  The node receives the response.
IGNORE  The node is not concerned by the response, it doesn't send or receive.

Definition at line 86 of file lin.h.

00086              {
00087   PUBLISH,            
00088   SUBSCRIBE,          
00089   IGNORE              
00090 } enum_lin_cmd;


Function Documentation

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.

Parameters:
master TRUE for master, FALSE for slave
b_rate Baudrate Value
l_node Node Value
pba_hz PBA Value
Returns:
Status PASS / FAIL
Parameters:
master TRUE for master, FALSE for slave
l_node Node Value
b_rate Baudrate Value
pba_hz PBA Value
Returns:
Status PASS / FAIL

Enable Interrupt for Error flags and end ID Reception

Register Interrupt for LIN

Register Interrupt for PDCA Transfer TX

Register Interrupt for PDCA Transfer 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             #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     // Enable GPIO Alternate Functions
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     // USART options.
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 }

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.

Parameters:
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’.
l_node Node Value
Returns:
Status PASS / FAIL
Parameters:
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’.
Returns:
Status PASS / FAIL

Definition at line 604 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().

00607                        {
00608       U8 index = 0;
00609       U8 l_handle = 0;
00610 if (l_node == 0)
00611 {
00612     // Clear error in case of previous communication
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         // Configure Parity
00629         usart_lin_enable_parity(usart_lin_node0,TRUE);
00630         // Configure Checksum
00631         usart_lin_enable_checksum(usart_lin_node0,TRUE);
00632         // Configure Checksum Type
00633         usart_lin_set_checksum(usart_lin_node0,USART_LIN_ENHANCED_CHECKSUM);
00634         // Configure Frameslot
00635         usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00636         // Configure Frame Length
00637         usart_lin_set_data_length_lin2x(usart_lin_node0,l_len);
00638 #elif USART_LIN_VERSION == LIN_1x
00639         // Configure Parity
00640         usart_lin_enable_parity(usart_lin_node0,TRUE);
00641         // Configure Checksum
00642         usart_lin_enable_checksum(usart_lin_node0,TRUE);
00643         // Configure Checksum Type
00644         usart_lin_set_checksum(usart_lin_node0,USART_LIN_CLASSIC_CHECKSUM);
00645         // Configure Frameslot
00646         usart_lin_enable_frameslot(usart_lin_node0,FALSE);
00647         // Configure Frame Length
00648         usart_lin_set_data_length_lin1x(usart_lin_node0);
00649 #endif
00650         // Switch to Classic Checksum if diagnostic ID request
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                 // Configure Frame Length
00655                 usart_lin_set_data_length_lin1x(usart_lin_node0);
00656         }
00657 
00658         switch (lin_descript_list_node0[l_handle].l_cmd)
00659         {
00660             // In Publish, the USART Send the Header and the response
00661             case PUBLISH:
00662                   lin_tx_header_and_response(0,l_handle,l_len);
00663               break;
00664             // In Subscribe, the USART Receive the response
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     // Clear error in case of previous communication
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         // Configure Parity
00698         usart_lin_enable_parity(usart_lin_node1,TRUE);
00699         // Configure Checksum
00700         usart_lin_enable_checksum(usart_lin_node1,TRUE);
00701         // Configure Checksum Type
00702         usart_lin_set_checksum(usart_lin_node1,USART_LIN_ENHANCED_CHECKSUM);
00703         // Configure Frameslot
00704         usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00705         // Configure Frame Length
00706         usart_lin_set_data_length_lin2x(usart_lin_node1,l_len);
00707 #elif USART_LIN_VERSION == LIN_1x
00708         // Configure Parity
00709         usart_lin_enable_parity(usart_lin_node1,TRUE);
00710         // Configure Checksum
00711         usart_lin_enable_checksum(usart_lin_node1,TRUE);
00712         // Configure Checksum Type
00713         usart_lin_set_checksum(usart_lin_node1,USART_LIN_CLASSIC_CHECKSUM);
00714         // Configure Frameslot
00715         usart_lin_enable_frameslot(usart_lin_node1,FALSE);
00716         // Configure Frame Length
00717         usart_lin_set_data_length_lin1x(usart_lin_node1);
00718 #endif
00719         // Switch to Classic Checksum if diagnostic ID request
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                 // Configure Frame Length
00724                 usart_lin_set_data_length_lin1x(usart_lin_node1);
00725         }
00726 
00727         switch (lin_descript_list_node0[l_handle].l_cmd)
00728         {
00729             // In Publish, the USART Send the Header and the response
00730             case PUBLISH:
00731                   lin_tx_header_and_response(1,l_handle,l_len);
00732               break;
00733             // In Subscribe, the USART Receive the response
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 }


Variable Documentation

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

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

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[]

Last error FIFO: lin_handle | status. Default: 4 elements.

Definition at line 77 of file lin.c.

Referenced by lin_int_handler_node0().


Generated on Fri Feb 19 02:30:31 2010 for AVR32 - Service for LIN Management - Example by  doxygen 1.5.5