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_csc_servo.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 
23 #include "mcu.h"
24 #include "mcu_periph/sys_time.h"
25 #include "csc_msg_def.h"
26 #include "csc_protocol.h"
27 #include "stm32/can.h"
29 
30 static inline void main_init( void );
31 static inline void main_periodic_task( void );
32 static inline void main_event_task( void );
33 
35 
36 FlagStatus can_error_warning = RESET;
37 FlagStatus can_error_passive = RESET;
38 FlagStatus can_bus_off = RESET;
39 
40 struct CscVaneMsg csc_vane_msg;
41 
42 void main_on_vane_msg(void *data);
43 
44 int main(void) {
45  main_init();
46 
47  servos[0] = 1;
48  servos[1] = 2;
49  servos[2] = 3;
50  servos[3] = 4;
51 
52  while(1) {
56  }
57 
58  return 0;
59 }
60 
61 static inline void main_init( void ) {
62  hw_init();
64  cscp_init();
65  cscp_register_callback(CSC_VANE_MSG_ID, main_on_vane_msg, (void *)&csc_vane_msg);
66 }
67 
68 static inline void main_periodic_task( void ) {
69  servos[0]+=10;
70  servos[1]+=10;
71  servos[2]+=10;
72  servos[3]+=10;
73 
74  if ((can_error_warning = CAN_GetFlagStatus(CAN1, CAN_FLAG_EWG)) == SET) {
75  LED_ON(2);
76  } else {
77  LED_OFF(2);
78  }
79  if ((can_error_passive = CAN_GetFlagStatus(CAN1, CAN_FLAG_EPV)) == SET) {
80  LED_ON(3);
81  } else {
82  LED_OFF(3);
83  }
84  if ((can_bus_off = CAN_GetFlagStatus(CAN1, CAN_FLAG_BOF)) == SET) {
85  LED_ON(0);
86  } else {
87  LED_OFF(0);
88  }
89 
90  cscp_transmit(0, 0, (uint8_t *)servos, 8);
91 
92  LED_PERIODIC();
93  DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
94 }
95 
96 
97 
98 static inline void main_event_task( void ) {
99  cscp_event();
100 
101  LED_OFF(0);
102  LED_OFF(1);
103  LED_OFF(2);
104  LED_OFF(3);
105 
106 // DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
107 }
108 
109 void main_on_vane_msg(void *data)
110 {
111  int zero = 0;
112 
113 // DOWNLINK_SEND_PONG(DefaultChannel, DefaultDevice);
114 
115 // RunOnceEvery(10, {
116  DOWNLINK_SEND_VANE_SENSOR(DefaultChannel, DefaultDevice,
117  &(csc_vane_msg.vane_angle1),
118  &zero,
119  &zero,
120  &zero,
121  &zero,
122  &csc_vane_msg.vane_angle2,
123  &zero,
124  &zero,
125  &zero,
126  &zero);
127 // });
128 }
129 
130 
131 
unsigned short uint16_t
Definition: types.h:16
static void main_periodic_task(void)
FlagStatus can_bus_off
struct CscVaneMsg csc_vane_msg
FlagStatus can_error_warning
#define CAN1
Definition: LPC21xx.h:484
#define LED_ON(i)
Definition: led_hw.h:28
FlagStatus can_error_passive
Architecture independent timing functions.
static void main_init(void)
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_event_task(void)
#define LED_PERIODIC()
Definition: led_hw.h:8
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define LED_OFF(i)
Definition: led_hw.h:29
uint16_t servos[4]
void main_on_vane_msg(void *data)
int main(void)
#define RESET
Definition: humid_sht.h:40
void hw_init(void)