Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test_csc_servo.c
Go to the documentation of this file.
1 /*
2  * $Id:$
3  *
4  * Copyright (C) 2010 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 "csc_msg_def.h"
28 #include "csc_protocol.h"
29 #include "stm32/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 
37 
38 FlagStatus can_error_warning = RESET;
39 FlagStatus can_error_passive = RESET;
40 FlagStatus can_bus_off = RESET;
41 
42 struct CscVaneMsg csc_vane_msg;
43 
44 void main_on_vane_msg(void *data);
45 
46 int main(void) {
47  main_init();
48 
49  servos[0] = 1;
50  servos[1] = 2;
51  servos[2] = 3;
52  servos[3] = 4;
53 
54  while(1) {
58  }
59 
60  return 0;
61 }
62 
63 static inline void main_init( void ) {
64  hw_init();
66  cscp_init();
67  cscp_register_callback(CSC_VANE_MSG_ID, main_on_vane_msg, (void *)&csc_vane_msg);
68 }
69 
70 static inline void main_periodic_task( void ) {
71  servos[0]+=10;
72  servos[1]+=10;
73  servos[2]+=10;
74  servos[3]+=10;
75 
76  if ((can_error_warning = CAN_GetFlagStatus(CAN1, CAN_FLAG_EWG)) == SET) {
77  LED_ON(2);
78  } else {
79  LED_OFF(2);
80  }
81  if ((can_error_passive = CAN_GetFlagStatus(CAN1, CAN_FLAG_EPV)) == SET) {
82  LED_ON(3);
83  } else {
84  LED_OFF(3);
85  }
86  if ((can_bus_off = CAN_GetFlagStatus(CAN1, CAN_FLAG_BOF)) == SET) {
87  LED_ON(0);
88  } else {
89  LED_OFF(0);
90  }
91 
92  cscp_transmit(0, 0, (uint8_t *)servos, 8);
93 
94  LED_PERIODIC();
95  DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
96 }
97 
98 
99 
100 static inline void main_event_task( void ) {
101  cscp_event();
102 
103  LED_OFF(0);
104  LED_OFF(1);
105  LED_OFF(2);
106  LED_OFF(3);
107 
108 // DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM);
109 }
110 
111 void main_on_vane_msg(void *data)
112 {
113  int zero = 0;
114 
115 // DOWNLINK_SEND_PONG(DefaultChannel, DefaultDevice);
116 
117 // RunOnceEvery(10, {
118  DOWNLINK_SEND_VANE_SENSOR(DefaultChannel, DefaultDevice,
119  &(csc_vane_msg.vane_angle1),
120  &zero,
121  &zero,
122  &zero,
123  &zero,
124  &csc_vane_msg.vane_angle2,
125  &zero,
126  &zero,
127  &zero,
128  &zero);
129 // });
130 }
131 
132 
133 
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:452
#define LED_ON(i)
Definition: led_hw.h:28
FlagStatus can_error_passive
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
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:35
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
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 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