Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_can.c
Go to the documentation of this file.
1 /*
2  * $Id:$
3  *
4  * Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 
25 #include "mcu.h"
26 #include "mcu_periph/sys_time.h"
27 #include "led.h"
29 #include "mcu_periph/uart.h"
30 #include "mcu_periph/can.h"
31 
32 static inline void main_init( void );
33 static inline void main_periodic_task( void );
34 static inline void main_event_task( void );
35 void main_on_can_msg(uint32_t id, uint8_t *data, int len);
36 
39 bool new_can_data = false;
40 
41 int main(void) {
42  main_init();
43 
44  tx_data[0] = 0;
45  tx_data[1] = 0;
46  tx_data[2] = 0;
47  tx_data[3] = 0;
48  tx_data[4] = 0;
49  tx_data[5] = 0;
50  tx_data[6] = 0;
51  tx_data[7] = 0;
52 
53  new_can_data = false;
54 
55  while(1) {
59  }
60 
61  return 0;
62 }
63 
64 static inline void main_init( void ) {
65  mcu_init();
68 }
69 
70 static inline void main_periodic_task( void ) {
71 
72  tx_data[0]+=1;
74 
75  LED_PERIODIC();
76  DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
77 }
78 
79 
80 
81 static inline void main_event_task( void ) {
82 
83  if (new_can_data) {
84  if (rx_data[0] & 0x10) {
85  LED_ON(2);
86  } else {
87  LED_OFF(2);
88  }
89  }
90 
91  if (new_can_data) {
92  if (rx_data[0] & 0x20) {
93  LED_ON(3);
94  } else {
95  LED_OFF(3);
96  }
97  }
98 
99  if (new_can_data) {
100  if (rx_data[0] & 0x40) {
101  LED_ON(4);
102  } else {
103  LED_OFF(4);
104  }
105  }
106 
107  if (new_can_data) {
108  if (rx_data[0] & 0x80) {
109  LED_ON(5);
110  } else {
111  LED_OFF(5);
112  }
113  }
114 
115 }
116 
117 void main_on_can_msg(uint32_t id, uint8_t *data, int len)
118 {
119  for (int i = 0; i<8; i++) {
120  rx_data[i] = data[i];
121  }
122 
123  new_can_data = true;
124 }
125 
126 
127 
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static void main_init(void)
Definition: test_can.c:64
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
int main(void)
Definition: test_can.c:41
static void main_event_task(void)
Definition: test_can.c:81
bool new_can_data
Definition: test_can.c:39
#define LED_ON(i)
Definition: led_hw.h:28
void ppz_can_init(can_rx_callback_t callback)
Definition: can.c:32
int ppz_can_transmit(uint32_t id, const uint8_t *buf, uint8_t len)
Definition: can.c:38
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
static void main_periodic_task(void)
Definition: test_can.c:70
#define LED_PERIODIC()
Definition: led_hw.h:8
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
void main_on_can_msg(uint32_t id, uint8_t *data, int len)
Definition: test_can.c:117
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
uint8_t tx_data[8]
Definition: test_can.c:37
uint8_t rx_data[8]
Definition: test_can.c:38