lin_mngt_example.c File Reference


Detailed Description

LIN example application for AVR32 USART driver.

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

Definition in file lin_mngt_example.c.

#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "tc.h"
#include "intc.h"
#include "usart.h"
#include "lin.h"

Go to the source code of this file.

Defines

#define FPBA   FOSC0
 PBA Clock Reference.
#define TC_CHANNEL   0
 Timer Counter Channel Used.
#define TC_INSTANCE   &AVR32_TC0
#define TC_INSTANCE_IRQ   AVR32_TC0_IRQ0
#define TC_INSTANCE_IRQ_GROUP   AVR32_TC0_IRQ_GROUP

Functions

void lin_master_task_ID12 (void)
 Lin Master Task linked to the transmission of the message with the ID 0x12.
void lin_master_task_ID15 (void)
 Lin Master Task linked to the transmission of the message with the ID 0x15.
void lin_slave_task_ID12 (U8 *d_buf)
 Lin Slave Task linked to the reception of the message with the ID 0x12.
void lin_slave_task_ID15 (U8 *d_buf)
 Lin Slave Task linked to the reception of the message with the ID 0x15.
int main (void)
 This is an example demonstrating the LIN mode of USART IP functionalities using a dedicated USART LIN driver.
void start_scheduler (void)
 Start Scheduler: Configuration of dedicated timer for periodic LIN transmission.
static void tc_irq (void)
 TC interrupt.

Variables

U8 lin_data_in_node0 [8]
 Local Buffer for emission.
U8 lin_data_out_node0 [8]
 Local Buffer for transmission.
volatile unsigned char task_id = 0
 Current Task Id used for the scheduled table.


Define Documentation

#define FPBA   FOSC0

PBA Clock Reference.

Definition at line 113 of file lin_mngt_example.c.

Referenced by start_scheduler().

#define TC_CHANNEL   0

Timer Counter Channel Used.

Definition at line 116 of file lin_mngt_example.c.

Referenced by start_scheduler(), and tc_irq().

#define TC_INSTANCE   &AVR32_TC0

Definition at line 100 of file lin_mngt_example.c.

Referenced by start_scheduler(), and tc_irq().

#define TC_INSTANCE_IRQ   AVR32_TC0_IRQ0

Definition at line 101 of file lin_mngt_example.c.

Referenced by start_scheduler().

#define TC_INSTANCE_IRQ_GROUP   AVR32_TC0_IRQ_GROUP

Definition at line 102 of file lin_mngt_example.c.


Function Documentation

void lin_master_task_ID12 ( void   ) 

Lin Master Task linked to the transmission of the message with the ID 0x12.

lin_master_task_ID12

Definition at line 296 of file lin_mngt_example.c.

References lin_descript_list_node0, and lin_send_cmd().

Referenced by tc_irq().

00297 {
00298   lin_send_cmd (0,lin_descript_list_node0[0].l_id, lin_descript_list_node0[0].l_dlc );
00299 }

void lin_master_task_ID15 ( void   ) 

Lin Master Task linked to the transmission of the message with the ID 0x15.

lin_master_task_ID15

Definition at line 304 of file lin_mngt_example.c.

References lin_descript_list_node0, and lin_send_cmd().

Referenced by tc_irq().

00305 {
00306   lin_send_cmd (0,lin_descript_list_node0[1].l_id, lin_descript_list_node0[1].l_dlc );
00307 }

void lin_slave_task_ID12 ( U8 *  d_buf  ) 

Lin Slave Task linked to the reception of the message with the ID 0x12.

lin_slave_task_ID12

Definition at line 314 of file lin_mngt_example.c.

Referenced by main().

00315 {
00316   gpio_tgl_gpio_pin(LED0_GPIO);
00317   d_buf[0] = 0x77;
00318   d_buf[1] = 0x88;
00319 }

void lin_slave_task_ID15 ( U8 *  d_buf  ) 

Lin Slave Task linked to the reception of the message with the ID 0x15.

lin_slave_task_ID15

Definition at line 324 of file lin_mngt_example.c.

Referenced by main().

00325 {
00326   gpio_tgl_gpio_pin(LED1_GPIO);
00327 }

int main ( void   ) 

This is an example demonstrating the LIN mode of USART IP functionalities using a dedicated USART LIN driver.

Definition at line 239 of file lin_mngt_example.c.

References st_lin_message::l_cmd, st_lin_message::l_dlc, st_lin_message::l_id, st_lin_message::l_pt_data, st_lin_message::l_pt_function, st_lin_message::l_status, lin_data_in_node0, lin_data_out_node0, lin_descript_list_node0, lin_init(), lin_slave_task_ID12(), lin_slave_task_ID15(), PUBLISH, start_scheduler(), and SUBSCRIBE.

00240 {
00241    // Switch main clock to external oscillator 0 (crystal).
00242   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00243 
00244   AVR32_HMATRIX.mcfg[AVR32_HMATRIX_MASTER_CPU_INSN] = 0x1;
00245 
00246   // The INTC driver has to be used only for GNU GCC for AVR32.
00247   // Initialize interrupt vectors.
00248   INTC_init_interrupts();
00249 
00250   // USART LIN options.
00251 #ifdef MASTER_MODE
00252   // Node 0:  LIN_MASTER_MODE
00253   lin_init( TRUE, 0, 9600, FOSC0);
00254 #else
00255   // Node 0:  LIN_SLAVE_MODE
00256   lin_init( FALSE, 0, 9600, FOSC0);
00257 #endif
00258 
00259   // Configure lin_descriptor
00260   //- Init LIN data Node 0
00261   // Object 0
00262   lin_descript_list_node0[0].l_id = 0x12;
00263   lin_descript_list_node0[0].l_dlc = 2;
00264   lin_descript_list_node0[0].l_cmd = PUBLISH;
00265   lin_descript_list_node0[0].l_status = 0;
00266   lin_descript_list_node0[0].l_pt_data = lin_data_out_node0;
00267   lin_descript_list_node0[0].l_pt_function = lin_slave_task_ID12;
00268 
00269   // Configure lin_descriptor
00270   //- Init LIN data Node 0
00271   // Object 1
00272   lin_descript_list_node0[1].l_id = 0x15;
00273   lin_descript_list_node0[1].l_dlc = 2;
00274   lin_descript_list_node0[1].l_cmd = SUBSCRIBE;
00275   lin_descript_list_node0[1].l_status = 0;
00276   lin_descript_list_node0[1].l_pt_data = lin_data_in_node0;
00277   lin_descript_list_node0[1].l_pt_function = lin_slave_task_ID15;
00278 
00279 #ifdef MASTER_MODE
00280   // In case of Master Mode, the timing transmission starts...
00281   start_scheduler();
00282 #else
00283   // In case of Slave Mode, only wait until ID reception...
00284 #endif
00285 
00286   Enable_global_interrupt();
00287 
00288   while (TRUE);
00289 }

void start_scheduler ( void   ) 

Start Scheduler: Configuration of dedicated timer for periodic LIN transmission.

Definition at line 174 of file lin_mngt_example.c.

References FPBA, TC_CHANNEL, TC_INSTANCE, TC_INSTANCE_IRQ, and tc_irq().

Referenced by main().

00175 {
00176   volatile avr32_tc_t *tc = TC_INSTANCE;
00177 
00178   // Options for waveform genration.
00179   static const tc_waveform_opt_t WAVEFORM_OPT =
00180   {
00181     .channel  = TC_CHANNEL,                        // Channel selection.
00182 
00183     .bswtrg   = TC_EVT_EFFECT_NOOP,                // Software trigger effect on TIOB.
00184     .beevt    = TC_EVT_EFFECT_NOOP,                // External event effect on TIOB.
00185     .bcpc     = TC_EVT_EFFECT_NOOP,                // RC compare effect on TIOB.
00186     .bcpb     = TC_EVT_EFFECT_NOOP,                // RB compare effect on TIOB.
00187 
00188     .aswtrg   = TC_EVT_EFFECT_NOOP,                // Software trigger effect on TIOA.
00189     .aeevt    = TC_EVT_EFFECT_NOOP,                // External event effect on TIOA.
00190     .acpc     = TC_EVT_EFFECT_NOOP,                // RC compare effect on TIOA: toggle.
00191     .acpa     = TC_EVT_EFFECT_NOOP,                // RA compare effect on TIOA: toggle (other possibilities are none, set and clear).
00192 
00193     .wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,// Waveform selection: Up mode with automatic trigger(reset) on RC compare.
00194     .enetrg   = FALSE,                             // External event trigger enable.
00195     .eevt     = 0,                                 // External event selection.
00196     .eevtedg  = TC_SEL_NO_EDGE,                    // External event edge selection.
00197     .cpcdis   = FALSE,                             // Counter disable when RC compare.
00198     .cpcstop  = FALSE,                             // Counter clock stopped with RC compare.
00199 
00200     .burst    = FALSE,                             // Burst signal selection.
00201     .clki     = FALSE,                             // Clock inversion.
00202     .tcclks   = TC_CLOCK_SOURCE_TC5                // Internal source clock 3, connected to fPBA / 128.
00203   };
00204 
00205   static const tc_interrupt_t TC_INTERRUPT =
00206   {
00207     .etrgs = 0,
00208     .ldrbs = 0,
00209     .ldras = 0,
00210     .cpcs  = 1,
00211     .cpbs  = 0,
00212     .cpas  = 0,
00213     .lovrs = 0,
00214     .covfs = 0
00215   };
00216 
00217   // Register the RTC interrupt handler to the interrupt controller.
00218   INTC_register_interrupt(&tc_irq, TC_INSTANCE_IRQ, AVR32_INTC_INT0);
00219 
00220   // Initialize the timer/counter.
00221   tc_init_waveform(tc, &WAVEFORM_OPT);         // Initialize the timer/counter waveform.
00222 
00223   // Set the compare triggers.
00224   // Remember TC counter is 16-bits, so counting second is not possible with fPBA = 16 MHz.
00225   // We configure it to count 0.5 s.
00226   // We want: (1/(fPBA/8)) * RC = 0.5 s, hence RC = (fPBA/128)/2 = 62500 to get an interrupt every 0.5 s.
00227   tc_write_rc(tc, TC_CHANNEL, (FPBA / 128)/2); // Set RC value.
00228 
00229   tc_configure_interrupts(tc, TC_CHANNEL, &TC_INTERRUPT);
00230 
00231   // Start the timer/counter.
00232   tc_start(tc, TC_CHANNEL);                    // And start the timer/counter.
00233 
00234 }

static void tc_irq ( void   )  [static]

TC interrupt.

Definition at line 147 of file lin_mngt_example.c.

References lin_master_task_ID12(), lin_master_task_ID15(), task_id, TC_CHANNEL, and TC_INSTANCE.

Referenced by start_scheduler().

00148 {
00149   // Clear the interrupt flag. This is a side effect of reading the TC SR.
00150   tc_read_sr(TC_INSTANCE, TC_CHANNEL);
00151 
00152   // Send message on LIN ...
00153   switch(task_id)
00154   {
00155     case 0 :
00156       lin_master_task_ID12();
00157       task_id=1;
00158       break;
00159 
00160      case 1 :
00161       lin_master_task_ID15();
00162       task_id=0;
00163       break;
00164 
00165     default :
00166       break;
00167   }
00168 }


Variable Documentation

Local Buffer for emission.

Definition at line 134 of file lin_mngt_example.c.

Referenced by main().

Local Buffer for transmission.

Definition at line 131 of file lin_mngt_example.c.

Referenced by main().

volatile unsigned char task_id = 0

Current Task Id used for the scheduled table.

Definition at line 137 of file lin_mngt_example.c.

Referenced by tc_irq().


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