Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
main_demo5.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 "pprzlink/messages.h"
9 
10 static inline void main_init(void);
11 static inline void main_periodic_task(void);
12 static inline void main_event_task(void);
13 
14 static inline void main_dl_parse_msg(void);
15 
16 int main(void)
17 {
18  main_init();
19  while (1) {
22  }
24  }
25  return 0;
26 }
27 
28 static inline void main_init(void)
29 {
30  mcu_init();
31  sys_time_register_timer((1. / PERIODIC_FREQUENCY), NULL);
32  uart0_init_tx();
34 }
35 
36 static inline void main_periodic_task(void)
37 {
38  // LED_TOGGLE(1);
39  uint16_t time_sec = sys_time.nb_sec;
40  DOWNLINK_SEND_TAKEOFF(&time_sec);
41 }
42 
43 static inline void main_event_task(void)
44 {
45  if (PprzBuffer()) {
46  ReadPprzBuffer();
47  if (pprz_msg_received) {
48  pprz_parse_payload();
49  pprz_msg_received = false;
50  }
51  }
52  if (dl_msg_available) {
54  dl_msg_available = false;
55  LED_TOGGLE(1);
56  }
57 }
58 
60 
62 
63 #define MSG_SIZE 256
64 uint8_t dl_buffer[MSG_SIZE] __attribute__((aligned));
65 
66 #include "generated/settings.h"
67 
68 #define IdOfMsg(x) (x[1])
69 
70 static inline void main_dl_parse_msg(void)
71 {
72  uint8_t msg_id = IdOfMsg(dl_buffer);
73  if (msg_id == DL_SETTING) {
74  uint8_t i = DL_SETTING_index(dl_buffer);
75  float var = DL_SETTING_value(dl_buffer);
76  DlSetting(i, var);
77  DOWNLINK_SEND_DL_VALUE(&i, &var);
78  }
79 }
static void main_event_task(void)
Definition: main_demo5.c:43
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:76
#define mcu_int_enable()
Definition: mcu_arch.h:36
bool dl_msg_available
Definition: main_demo5.c:61
static void main_init(void)
Definition: main_demo5.c:28
#define MSG_SIZE
Definition: main_demo5.c:63
static void main_dl_parse_msg(void)
Definition: main_demo5.c:70
Architecture independent timing functions.
uint16_t foo
Definition: main_demo5.c:59
#define IdOfMsg(x)
Definition: main_demo5.c:68
#define LED_TOGGLE(i)
Definition: led_hw.h:52
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:114
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
int main(void)
Definition: main_demo5.c:16
static void main_periodic_task(void)
Definition: main_demo5.c:36
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
arch independent LED (Light Emitting Diodes) API
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43