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
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 "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  main_init();
18  while(1) {
22  }
23  return 0;
24 }
25 
26 static inline void main_init( void ) {
27  mcu_init();
29  uart0_init_tx();
31 }
32 
33 static inline void main_periodic_task( void ) {
34  // LED_TOGGLE(1);
35  uint16_t time_sec = sys_time.nb_sec;
36  DOWNLINK_SEND_TAKEOFF(&time_sec);
37 }
38 
39 static inline void main_event_task( void ) {
40  if (PprzBuffer()) {
42  if (pprz_msg_received) {
44  pprz_msg_received = FALSE;
45  }
46  }
47  if (dl_msg_available) {
50  LED_TOGGLE(1);
51  }
52 }
53 
55 
57 
58 #define MSG_SIZE 128
59 uint8_t dl_buffer[MSG_SIZE] __attribute__ ((aligned));
60 
61 #include "generated/settings.h"
62 
63 #define IdOfMsg(x) (x[1])
64 
65 static inline void main_dl_parse_msg(void) {
66  uint8_t msg_id = IdOfMsg(dl_buffer);
67  if (msg_id == DL_SETTING) {
68  uint8_t i = DL_SETTING_index(dl_buffer);
69  float var = DL_SETTING_value(dl_buffer);
70  DlSetting(i, var);
71  DOWNLINK_SEND_DL_VALUE(&i, &var);
72  }
73 }
static void main_event_task(void)
Definition: main_demo5.c:39
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:61
#define ReadPprzBuffer(_dev, _trans)
#define FALSE
Definition: imu_chimu.h:141
static void main_init(void)
Definition: main_demo5.c:26
bool_t dl_msg_available
Definition: main_demo5.c:56
#define mcu_int_enable()
Definition: mcu_arch.h:37
#define MSG_SIZE
Definition: main_demo5.c:58
static void main_dl_parse_msg(void)
Definition: main_demo5.c:65
Architecture independent timing functions.
uint16_t foo
Definition: main_demo5.c:54
#define IdOfMsg(x)
Definition: main_demo5.c:63
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
#define LED_TOGGLE(i)
Definition: led_hw.h:30
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
int main(void)
Definition: main_demo5.c:16
static void main_periodic_task(void)
Definition: main_demo5.c:33
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define PprzBuffer(_dev)
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:59
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
static void pprz_parse_payload(struct pprz_transport *t)