Definition in file lin_task.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"
#include "dsp.h"
#include "lin_task.h"
#include "conf_demo.h"
#include "can.h"
Go to the source code of this file.
Defines | |
#define | FPBA FOSC0 |
#define | TC_CHANNEL 0 |
#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_cb_task_ID12 (U8 *d_buf) |
Lin Callback when message is transmitted. | |
void | lin_master_task_ID12 (void) |
Lin Command When Id is transmitted. | |
void | lin_slave_task_ID12 (U8 *d_buf) |
Lin Callback when message is received. | |
void | lin_task () |
LIN Task
| |
void | lin_task_init (void) |
LIN Task Init
| |
void | lin_task_restart () |
LIN Task Restart. | |
void | lin_task_stop () |
LIN Task Stop. | |
void | start_scheduler (void) |
Start LIN scheduler for periodic transmission of LIN message. | |
static void | tc_irq (void) |
TC interrupt. | |
Variables | |
volatile U8 | lin_data_in_node1 [8] |
U8 | lin_data_out_node0 [8] |
can_mob_t | pCANMOB_message2 [1] |
A_ALIGNED dsp16_t | signal2_buf [BUFFER_LENGTH] |
volatile unsigned char | task_id = 0 |
volatile avr32_tc_t * | tc = TC_INSTANCE |
volatile avr32_usart_t * | usart_lin_node1 |
#define FPBA FOSC0 |
#define TC_CHANNEL 0 |
#define TC_INSTANCE &AVR32_TC0 |
#define TC_INSTANCE_IRQ AVR32_TC0_IRQ0 |
#define TC_INSTANCE_IRQ_GROUP AVR32_TC0_IRQ_GROUP |
Definition at line 61 of file lin_task.c.
void lin_master_cb_task_ID12 | ( | U8 * | d_buf | ) |
Lin Callback when message is transmitted.
Definition at line 242 of file lin_task.c.
References pCANMOB_message2.
Referenced by lin_task_init().
00242 { 00243 gpio_tgl_gpio_pin(LED1_GPIO); 00244 00245 d_buf[0] = pCANMOB_message2[0].can_msg->data.u8[0]; 00246 d_buf[1] = pCANMOB_message2[0].can_msg->data.u8[1]; 00247 00248 }
void lin_master_task_ID12 | ( | void | ) |
Lin Command When Id is transmitted.
Definition at line 235 of file lin_task.c.
Referenced by tc_irq().
00235 { 00236 lin_send_cmd (0,lin_descript_list_node0[0].l_id, \ 00237 lin_descript_list_node0[0].l_dlc ); 00238 }
void lin_slave_task_ID12 | ( | U8 * | d_buf | ) |
Lin Callback when message is received.
Definition at line 253 of file lin_task.c.
Referenced by lin_task_init().
void lin_task | ( | void | ) |
LIN Task
Definition at line 205 of file lin_task.c.
References BUFFER_LENGTH, and signal2_buf.
Referenced by main().
00206 { 00207 int i; 00208 int value; 00209 for (i=BUFFER_LENGTH-1;i>=1;i--) 00210 { 00211 signal2_buf[i] = signal2_buf[i-1]; 00212 } 00213 value = (lin_descript_list_node1[0].l_pt_data[0]<<8)|(lin_descript_list_node1[1].l_pt_data[1]); 00214 signal2_buf[0] = ( value*0x20) - 0x8000; 00215 }
void lin_task_init | ( | void | ) |
LIN Task Init
Definition at line 169 of file lin_task.c.
References lin_data_in_node1, lin_data_out_node0, lin_master_cb_task_ID12(), lin_slave_task_ID12(), and start_scheduler().
Referenced by main().
00170 { 00171 // USART LIN options. 00172 // Node 0: LIN_MASTER_MODE 00173 lin_init (TRUE,0,9600,FOSC0); 00174 00175 // Node 1: LIN_SLAVE_MODE 00176 lin_init (FALSE,1,9600,FOSC0); 00177 00178 // Configure lin_descriptor 00179 //- Init LIN data Node 0 00180 // Object 0 00181 lin_descript_list_node0[0].l_id = 0x22; 00182 lin_descript_list_node0[0].l_dlc = 8; 00183 lin_descript_list_node0[0].l_cmd = PUBLISH; 00184 lin_descript_list_node0[0].l_status = 0; 00185 lin_descript_list_node0[0].l_pt_data = lin_data_out_node0; 00186 lin_descript_list_node0[0].l_pt_function = lin_master_cb_task_ID12; 00187 00188 // Configure lin_descriptor 00189 //- Init LIN data Node 1 00190 // Object 0 00191 lin_descript_list_node1[0].l_id = 0x22; 00192 lin_descript_list_node1[0].l_dlc = 8; 00193 lin_descript_list_node1[0].l_cmd = SUBSCRIBE; 00194 lin_descript_list_node1[0].l_status = 0; 00195 lin_descript_list_node1[0].l_pt_data = (U8 *)lin_data_in_node1; 00196 lin_descript_list_node1[0].l_pt_function = lin_slave_task_ID12; 00197 00198 // In case of Master Mode, the timing transmission starts... 00199 start_scheduler(); 00200 }
void lin_task_restart | ( | void | ) |
LIN Task Restart.
Definition at line 223 of file lin_task.c.
00224 { 00225 Disable_global_interrupt(); 00226 lin_init (FALSE,1,9600,FOSC0); 00227 Enable_global_interrupt(); 00228 }
void lin_task_stop | ( | void | ) |
void start_scheduler | ( | void | ) |
Start LIN scheduler for periodic transmission of LIN message.
Definition at line 104 of file lin_task.c.
References FPBA, TC_CHANNEL, TC_INSTANCE_IRQ, and tc_irq().
Referenced by lin_task_init().
00105 { 00106 // Options for waveform genration. 00107 static const tc_waveform_opt_t WAVEFORM_OPT = 00108 { 00109 .channel = TC_CHANNEL, // Channel selection. 00110 00111 .bswtrg = TC_EVT_EFFECT_NOOP, // Software trigger effect on TIOB. 00112 .beevt = TC_EVT_EFFECT_NOOP, // External event effect on TIOB. 00113 .bcpc = TC_EVT_EFFECT_NOOP, // RC compare effect on TIOB. 00114 .bcpb = TC_EVT_EFFECT_NOOP, // RB compare effect on TIOB. 00115 00116 .aswtrg = TC_EVT_EFFECT_NOOP, // Software trigger effect on TIOA. 00117 .aeevt = TC_EVT_EFFECT_NOOP, // External event effect on TIOA. 00118 .acpc = TC_EVT_EFFECT_NOOP, // RC compare effect on TIOA: toggle. 00119 .acpa = TC_EVT_EFFECT_NOOP, // RA compare effect on TIOA: toggle (other possibilities are none, set and clear). 00120 00121 .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,// Waveform selection: Up mode with automatic trigger(reset) on RC compare. 00122 .enetrg = FALSE, // External event trigger enable. 00123 .eevt = 0, // External event selection. 00124 .eevtedg = TC_SEL_NO_EDGE, // External event edge selection. 00125 .cpcdis = FALSE, // Counter disable when RC compare. 00126 .cpcstop = FALSE, // Counter clock stopped with RC compare. 00127 00128 .burst = FALSE, // Burst signal selection. 00129 .clki = FALSE, // Clock inversion. 00130 .tcclks = TC_CLOCK_SOURCE_TC5 // Internal source clock 3, connected to fPBA / 128. 00131 }; 00132 00133 static const tc_interrupt_t TC_INTERRUPT = 00134 { 00135 .etrgs = 0, 00136 .ldrbs = 0, 00137 .ldras = 0, 00138 .cpcs = 1, 00139 .cpbs = 0, 00140 .cpas = 0, 00141 .lovrs = 0, 00142 .covfs = 0 00143 }; 00144 // Register the TC interrupt handler to the interrupt controller. 00145 INTC_register_interrupt(&tc_irq, TC_INSTANCE_IRQ, AVR32_INTC_INT0); 00146 00147 // Initialize the timer/counter. 00148 tc_init_waveform(tc, &WAVEFORM_OPT); // Initialize the timer/counter waveform. 00149 00150 // Set the compare triggers. 00151 // Remember TC counter is 16-bits, so counting second is not possible with fPBA = 16 MHz. 00152 // We configure it to count 0.5 s. 00153 // We want: (1/(fPBA/8)) * RC = 0.5 s, hence RC = (fPBA/128)/2 = 62500 to get an interrupt every 0.5 s. 00154 tc_write_rc(tc, TC_CHANNEL, (FPBA / 128)/2); // Set RC value. 00155 00156 tc_configure_interrupts(tc, TC_CHANNEL, &TC_INTERRUPT); 00157 00158 // Start the timer/counter. 00159 tc_start(tc, TC_CHANNEL); 00160 }
static void tc_irq | ( | void | ) | [static] |
TC interrupt.
Definition at line 93 of file lin_task.c.
References lin_master_task_ID12(), TC_CHANNEL, and TC_INSTANCE.
Referenced by start_scheduler().
00094 { 00095 // Clear the interrupt flag. This is a side effect of reading the TC SR. 00096 tc_read_sr(TC_INSTANCE, TC_CHANNEL); 00097 lin_master_task_ID12(); 00098 }
volatile U8 lin_data_in_node1[8] |
U8 lin_data_out_node0[8] |
can_mob_t pCANMOB_message2[1] |
Definition at line 122 of file conf_can_task.h.
Referenced by can_example_prepare_data_to_receive(), can_out_callback_channel0(), can_task(), and lin_master_cb_task_ID12().
A_ALIGNED dsp16_t signal2_buf[BUFFER_LENGTH] |
volatile unsigned char task_id = 0 |
Definition at line 80 of file lin_task.c.
volatile avr32_tc_t* tc = TC_INSTANCE |
Definition at line 100 of file lin_task.c.
volatile avr32_usart_t* usart_lin_node1 |