Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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"
8
#include "
subsystems/datalink/downlink.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) {
20
if
(
sys_time_check_and_ack_timer
(0)) {
21
main_periodic_task
();
22
}
23
main_event_task
();
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();
33
mcu_int_enable
();
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
) {
53
main_dl_parse_msg
();
54
dl_msg_available
=
false
;
55
LED_TOGGLE
(1);
56
}
57
}
58
59
uint16_t
foo
;
60
61
bool
dl_msg_available
;
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
}
main_event_task
static void main_event_task(void)
Definition:
main_demo5.c:43
dl_buffer
uint8_t dl_buffer[MSG_SIZE]
Definition:
main_demo5.c:64
uint16_t
unsigned short uint16_t
Definition:
types.h:16
mcu_int_enable
#define mcu_int_enable()
Definition:
mcu_arch.h:36
main_init
static void main_init(void)
Definition:
main_demo5.c:28
LED_TOGGLE
#define LED_TOGGLE(i)
Definition:
led_hw.h:53
foo
uint16_t foo
Definition:
main_demo5.c:59
MSG_SIZE
#define MSG_SIZE
Definition:
main_demo5.c:63
std.h
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition:
types.h:14
led.h
arch independent LED (Light Emitting Diodes) API
IdOfMsg
#define IdOfMsg(x)
Definition:
main_demo5.c:68
downlink.h
Common code for AP and FBW telemetry.
dl_msg_available
bool dl_msg_available
Definition:
main_demo5.c:61
sys_time
Definition:
sys_time.h:71
main
int main(void)
Definition:
main_demo5.c:16
main_periodic_task
static void main_periodic_task(void)
Definition:
main_demo5.c:36
sys_time_register_timer
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition:
sys_time.c:43
main_dl_parse_msg
static void main_dl_parse_msg(void)
Definition:
main_demo5.c:70
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition:
sys_time.h:72
mcu_init
void mcu_init(void)
Microcontroller peripherals initialization.
Definition:
mcu.c:87
sys_time_check_and_ack_timer
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition:
sys_time.h:114
sw
airborne
firmwares
tutorial
main_demo5.c
Generated on Tue Feb 1 2022 13:51:14 for Paparazzi UAS by
1.8.17