Definition in file can_task.c.
#include <stddef.h>
#include <stdio.h>
#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "pm_uc3c.h"
#include "scif_uc3c.h"
#include "print_funcs.h"
#include "can_task.h"
#include "conf_can_task.h"
#include "dsp.h"
#include "conf_demo.h"
Go to the source code of this file.
Functions | |
void | can_example_prepare_data_to_receive () |
CAN Prepare Data to Receive
| |
void | can_example_prepare_data_to_send () |
Local function to prepare RX and TX buffers. | |
void | can_out_callback_channel0 (U8 handle, U8 event) |
CAN Call Back when message is received. | |
void | can_out_callback_channel1 (U8 handle, U8 event) |
CAN Call Back when message is transmitted. | |
void | can_task (void) |
CAN Task:
| |
void | can_task_init (void) |
Variables | |
volatile U16 | adc_current_conversion |
volatile bool | message_received_on_channel0 = false |
volatile bool | message_transmitted_on_channel1 = false |
can_msg_t | mob_ram_ch0 [NB_MOB_CHANNEL] |
can_msg_t | mob_ram_ch1 [NB_MOB_CHANNEL] |
A_ALIGNED dsp16_t | signal3_buf [BUFFER_LENGTH] |
void can_example_prepare_data_to_receive | ( | ) |
CAN Prepare Data to Receive
Definition at line 189 of file can_task.c.
References can_out_callback_channel0(), mob_ram_ch0, and pCANMOB_message2.
Referenced by can_task(), and can_task_init().
00190 { 00191 // Initialize channel 0 00192 can_init(0, 00193 ((U32)&mob_ram_ch0[0]), 00194 CANIF_CHANNEL_MODE_NORMAL, 00195 can_out_callback_channel0); 00196 00197 // Allocate one mob for RX 00198 pCANMOB_message2[0].handle = can_mob_alloc(0); 00199 00200 can_rx(0, 00201 pCANMOB_message2[0].handle, 00202 pCANMOB_message2[0].req_type, 00203 pCANMOB_message2[0].can_msg); 00204 }
void can_example_prepare_data_to_send | ( | ) |
Local function to prepare RX and TX buffers.
CAN Prepare Data to Send
Definition at line 161 of file can_task.c.
References adc_current_conversion, can_out_callback_channel1(), mob_ram_ch1, and pCANMOB_message0.
Referenced by can_task(), and can_task_init().
00162 { 00163 // Initialize channel 1 00164 can_init(1, 00165 ((U32)&mob_ram_ch1[0]), 00166 CANIF_CHANNEL_MODE_NORMAL, 00167 can_out_callback_channel1); 00168 // Allocate one mob for TX 00169 pCANMOB_message0[0].handle = can_mob_alloc(1); 00170 00171 // Check return if no mob are available 00172 if (pCANMOB_message0[0].handle==CAN_CMD_REFUSED) 00173 { 00174 while(1); 00175 } 00176 pCANMOB_message0[0].can_msg->data.u8[0] = ((adc_current_conversion&0xFF00)>>8); 00177 pCANMOB_message0[0].can_msg->data.u8[1] = (adc_current_conversion&0xFF); 00178 can_tx(1, 00179 pCANMOB_message0[0].handle, 00180 pCANMOB_message0[0].dlc, 00181 pCANMOB_message0[0].req_type, 00182 pCANMOB_message0[0].can_msg); 00183 }
void can_out_callback_channel0 | ( | U8 | handle, | |
U8 | event | |||
) |
CAN Call Back when message is received.
Definition at line 93 of file can_task.c.
References message_received_on_channel0, and pCANMOB_message2.
Referenced by can_example_prepare_data_to_receive().
00094 { 00095 gpio_tgl_gpio_pin(LED3_GPIO); 00096 // Reception Only 00097 pCANMOB_message2[0].can_msg->data.u64 = can_get_mob_data(0,handle).u64; 00098 pCANMOB_message2[0].can_msg->id = can_get_mob_id(0,handle); 00099 pCANMOB_message2[0].dlc = can_get_mob_dlc(0,handle); 00100 pCANMOB_message2[0].status = event; 00101 can_mob_free(0,handle); 00102 message_received_on_channel0 = true; 00103 }
void can_out_callback_channel1 | ( | U8 | handle, | |
U8 | event | |||
) |
CAN Call Back when message is transmitted.
Definition at line 79 of file can_task.c.
References message_transmitted_on_channel1.
Referenced by can_example_prepare_data_to_send().
00080 { 00081 gpio_tgl_gpio_pin(LED2_GPIO); 00082 // Transmission Only 00083 can_mob_free(1,handle); 00084 message_transmitted_on_channel1 = true; 00085 }
void can_task | ( | void | ) |
CAN Task:
Definition at line 134 of file can_task.c.
References BUFFER_LENGTH, can_example_prepare_data_to_receive(), can_example_prepare_data_to_send(), message_received_on_channel0, message_transmitted_on_channel1, pCANMOB_message2, and signal3_buf.
Referenced by main().
00135 { 00136 int i; 00137 int value; 00138 if (message_transmitted_on_channel1 == true) 00139 { 00140 message_transmitted_on_channel1 = false; 00141 if (message_received_on_channel0 == true) 00142 { 00143 message_received_on_channel0 = false; 00144 for (i=BUFFER_LENGTH-1;i>=1;i--) 00145 { 00146 signal3_buf[i] = signal3_buf[i-1]; 00147 } 00148 value = (pCANMOB_message2[0].can_msg->data.u8[0]<<8)|(pCANMOB_message2[0].can_msg->data.u8[1]); 00149 signal3_buf[0] = ( value*0x20) - 0x8000; 00150 can_example_prepare_data_to_receive(); 00151 can_example_prepare_data_to_send(); 00152 } 00153 } 00154 }
void can_task_init | ( | void | ) |
Definition at line 105 of file can_task.c.
References can_example_prepare_data_to_receive(), and can_example_prepare_data_to_send().
Referenced by main().
00106 { 00107 // Setup the generic clock for CAN 00108 scif_gc_setup(AVR32_SCIF_GCLK_CANIF, 00109 SCIF_GCCTRL_OSC0, 00110 AVR32_SCIF_GC_NO_DIV_CLOCK, 00111 0); 00112 // Now enable the generic clock 00113 scif_gc_enable(AVR32_SCIF_GCLK_CANIF); 00114 00115 static const gpio_map_t CAN_GPIO_MAP = 00116 { 00117 {AVR32_CANIF_RXLINE_0_0_PIN, AVR32_CANIF_RXLINE_0_0_FUNCTION}, 00118 {AVR32_CANIF_TXLINE_0_0_PIN, AVR32_CANIF_TXLINE_0_0_FUNCTION}, 00119 {AVR32_CANIF_RXLINE_1_2_PIN, AVR32_CANIF_RXLINE_1_2_FUNCTION}, 00120 {AVR32_CANIF_TXLINE_1_2_PIN, AVR32_CANIF_TXLINE_1_2_FUNCTION} 00121 }; 00122 // Assign GPIO to CAN. 00123 gpio_enable_module(CAN_GPIO_MAP, 00124 sizeof(CAN_GPIO_MAP) / sizeof(CAN_GPIO_MAP[0])); 00125 00126 can_example_prepare_data_to_receive(); 00127 can_example_prepare_data_to_send(); 00128 }
volatile U16 adc_current_conversion |
Definition at line 117 of file main.c.
Referenced by adc_process_task(), and can_example_prepare_data_to_send().
volatile bool message_received_on_channel0 = false |
Definition at line 87 of file can_task.c.
Referenced by can_out_callback_channel0(), and can_task().
volatile bool message_transmitted_on_channel1 = false |
Definition at line 72 of file can_task.c.
Referenced by can_out_callback_channel1(), and can_task().
can_msg_t mob_ram_ch0[NB_MOB_CHANNEL] |
can_msg_t mob_ram_ch1[NB_MOB_CHANNEL] |
A_ALIGNED dsp16_t signal3_buf[BUFFER_LENGTH] |