Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
mag_micromag_fw.c
Go to the documentation of this file.
1
#include "
modules/sensors/mag_micromag_fw.h
"
2
#include "
modules/sensors/mag_micromag_fw_hw.h
"
3
#include "
led.h
"
4
5
#include "
mcu_periph/uart.h
"
6
#include "pprzlink/messages.h"
7
#include "
subsystems/datalink/downlink.h
"
8
9
volatile
uint8_t
micromag_status
;
10
volatile
int16_t
micromag_values
[
MM_NB_AXIS
];
11
12
13
void
micromag_periodic
(
void
)
14
{
15
16
static
uint8_t
cnt = 0;
17
18
if
(
micromag_status
==
MM_IDLE
) {
19
// uint8_t * tab = &cnt;
20
// DOWNLINK_SEND_DEBUG(1,tab);
21
cnt = 0;
22
MmSendReq
();
23
}
else
if
(
micromag_status
==
MM_GOT_EOC
) {
24
MmReadRes
();
25
}
else
if
(
micromag_status
==
MM_WAITING_EOC
) {
26
cnt++;
27
if
(cnt > 50) {cnt = 0;
micromag_status
=
MM_IDLE
;}
28
}
29
}
30
31
void
micromag_event
(
void
)
32
{
33
34
int32_t
mx =
micromag_values
[0];
35
int32_t
my =
micromag_values
[1];
36
int32_t
mz =
micromag_values
[2];
37
38
if
(
micromag_status
==
MM_DATA_AVAILABLE
) {
39
DOWNLINK_SEND_IMU_MAG_RAW(
DefaultChannel
,
DefaultDevice
,
40
&mx,
41
&my,
42
&mz);
43
micromag_status
=
MM_IDLE
;
44
}
45
}
46
47
void
micromag_init
(
void
)
48
{
49
50
micromag_hw_init
();
51
52
uint8_t
i;
53
for
(i = 0; i <
MM_NB_AXIS
; i++) {
54
micromag_values
[i] = 0;
55
}
56
micromag_status
=
MM_IDLE
;
57
}
58
59
void
micromag_reset
()
60
{
61
micromag_status
=
MM_IDLE
;
62
}
63
64
void
micromag_read
()
65
{
66
if
(
micromag_status
==
MM_IDLE
) {
67
MmSendReq
();
68
}
else
if
(
micromag_status
==
MM_GOT_EOC
) {
69
MmReadRes
();
70
}
else
if
(
micromag_status
==
MM_DATA_AVAILABLE
) {
71
micromag_status
=
MM_IDLE
;
72
}
73
}
74
mag_micromag_fw.h
micromag_init
void micromag_init(void)
Definition:
mag_micromag_fw.c:47
MmReadRes
#define MmReadRes()
Definition:
mag_micromag_fw_hw.h:80
MM_WAITING_EOC
#define MM_WAITING_EOC
Definition:
mag_micromag_fw.h:18
micromag_read
void micromag_read()
Definition:
mag_micromag_fw.c:64
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
int16_t
signed short int16_t
Definition:
types.h:17
uint8_t
unsigned char uint8_t
Definition:
types.h:14
micromag_event
void micromag_event(void)
Definition:
mag_micromag_fw.c:31
mag_micromag_fw_hw.h
MmSendReq
#define MmSendReq()
Definition:
mag_micromag_fw_hw.h:68
led.h
arch independent LED (Light Emitting Diodes) API
micromag_values
volatile int16_t micromag_values[MM_NB_AXIS]
Definition:
mag_micromag_fw.c:10
downlink.h
Common code for AP and FBW telemetry.
micromag_reset
void micromag_reset()
Definition:
mag_micromag_fw.c:59
int32_t
signed long int32_t
Definition:
types.h:19
MM_NB_AXIS
#define MM_NB_AXIS
Definition:
mag_micromag_fw.h:6
MM_IDLE
#define MM_IDLE
Definition:
mag_micromag_fw.h:15
micromag_status
volatile uint8_t micromag_status
Definition:
mag_micromag_fw.c:9
micromag_hw_init
void micromag_hw_init(void)
Definition:
mag_micromag_fw_hw.c:48
MM_DATA_AVAILABLE
#define MM_DATA_AVAILABLE
Definition:
mag_micromag_fw.h:21
DefaultChannel
#define DefaultChannel
Definition:
downlink.h:42
DefaultDevice
#define DefaultDevice
Definition:
downlink.h:46
micromag_periodic
void micromag_periodic(void)
Definition:
mag_micromag_fw.c:13
MM_GOT_EOC
#define MM_GOT_EOC
Definition:
mag_micromag_fw.h:19
sw
airborne
modules
sensors
mag_micromag_fw.c
Generated on Tue Feb 1 2022 13:51:16 for Paparazzi UAS by
1.8.17