Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
main.c
Go to the documentation of this file.
1 #include "std.h"
2 #include "mcu.h"
3 #include "mcu_periph/sys_time.h"
4 #include "led.h"
5 #include "mcu_periph/uart.h"
6 
7 #include "messages.h"
9 
11 #include "generated/settings.h"
12 #include "dl_protocol.h"
13 
14 #include "mcu_periph/spi.h"
15 #include "sd_card.h"
16 
17 static inline void main_init( void );
18 static inline void main_periodic_task( void );
19 static inline void main_event_task( void );
20 
21 
22 uint8_t dl_buffer[MSG_SIZE] __attribute__ ((aligned));
25 
26 int main( void ) {
27  main_init();
28  while(1) {
31  main_event_task( );
32  }
33  return 0;
34 }
35 
36 static inline void main_init( void ) {
37  mcu_init();
39  led_init();
40  Uart0Init();
41 
42  spi_init();
43  sd_card_init();
44 
46 }
47 
48 static inline void main_periodic_task( void ) {
49  LED_TOGGLE(1);
50  //DOWNLINK_SEND_DEBUG(3,buf_input);
51 }
52 
53 static inline void main_event_task( void ) {
54  DatalinkEvent();
55 
56  // spi event
58  /* Got a message on SPI. */
60  sd_card_event();
61  }
62 
63 }
64 
65 
66 #define IdOfMsg(x) (x[1])
67 
68 void dl_parse_msg(void) {
69 
70  LED_TOGGLE(1);
71 
72  uint8_t msg_id = IdOfMsg(dl_buffer);
73  switch (msg_id) {
74 
75  case DL_PING: {
76  DOWNLINK_SEND_PONG();
77  break;
78  }
79 
80  case DL_SETTING : {
81  uint8_t i = DL_SETTING_index(dl_buffer);
82  float var = DL_SETTING_value(dl_buffer);
83  DlSetting(i, var);
84  DOWNLINK_SEND_DL_VALUE(&i, &var);
85  break;
86  }
87 
88  }
89 }
90 
91 
void dl_parse_msg(void)
Definition: main.c:68
unsigned short uint16_t
Definition: types.h:16
STATIC_INLINE void main_init(void)
Definition: main.c:97
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
bool_t spi_message_received
Definition: sim_baro.c:8
uint16_t datalink_time
Definition: main.c:24
void sd_card_init(void)
Definition: sd_card.c:60
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define FALSE
Definition: imu_chimu.h:141
uint8_t dl_buffer[MSG_SIZE] __attribute__((aligned))
bool_t dl_msg_available
Definition: main.c:23
static void main_event_task(void)
Definition: main.c:53
arch independent SPI (Serial Peripheral Interface) API
#define mcu_int_enable()
Definition: mcu_arch.h:32
#define MSG_SIZE
Definition: main_demo5.c:58
void spi_init(void)
Definition: spi_arch.c:3
Architecture independent timing functions.
#define IdOfMsg(x)
Definition: main.c:66
static void led_init(void)
Definition: led.h:86
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
#define LED_TOGGLE(i)
Definition: led_hw.h:30
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
void sd_card_event(void)
Definition: sd_card.c:99
arch independent mcu ( Micro Controller Unit ) utilities
unsigned char uint8_t
Definition: types.h:14
arch independent LED (Light Emitting Diodes) API
int main(void)
Definition: main.c:45
static void main_periodic_task(void)
Definition: main.c:48
void mcu_init(void)
Definition: mcu.c:57