33 #define InterMcuBuffer() uart_char_available(&(INTERMCU_LINK))
34 #define InterMcuUartSend1(c) uart_put_byte(&(INTERMCU_LINK), 0, c)
35 #define InterMcuUartSetBaudrate(_a) uart_periph_set_baudrate(&(INTERMCU_LINK), _a)
36 #define InterMcuUartSendMessage() {}
37 #define InterMcuUartGetch() uart_getch(&(INTERMCU_LINK))
42 #define INTERMCU_SYNC1 0xB5
43 #define INTERMCU_SYNC2 0x62
45 #define InterMcuInitCheksum() { intermcu_data.send_ck_a = intermcu_data.send_ck_b = 0; }
46 #define InterMcuUpdateChecksum(c) { intermcu_data.send_ck_a += c; intermcu_data.send_ck_b += intermcu_data.send_ck_a; }
47 #define InterMcuTrailer() { InterMcuUartSend1(intermcu_data.send_ck_a); InterMcuUartSend1(intermcu_data.send_ck_b); InterMcuUartSendMessage(); }
49 #define InterMcuSend1(c) { uint8_t i8=c; InterMcuUartSend1(i8); InterMcuUpdateChecksum(i8); }
50 #define InterMcuSend2(c) { uint16_t i16=c; InterMcuSend1(i16&0xff); InterMcuSend1(i16 >> 8); }
51 #define InterMcuSend1ByAddr(x) { InterMcuSend1(*x); }
52 #define InterMcuSend2ByAddr(x) { InterMcuSend1(*x); InterMcuSend1(*(x+1)); }
53 #define InterMcuSend4ByAddr(x) { InterMcuSend1(*x); InterMcuSend1(*(x+1)); InterMcuSend1(*(x+2)); InterMcuSend1(*(x+3)); }
55 #define InterMcuHeader(nav_id, msg_id, len) { \
56 InterMcuUartSend1(INTERMCU_SYNC1); \
57 InterMcuUartSend1(INTERMCU_SYNC2); \
58 InterMcuInitCheksum(); \
59 InterMcuSend1(nav_id); \
60 InterMcuSend1(msg_id); \
68 #define MSG_INTERMCU_ID 100
71 #define MSG_INTERMCU_COMMAND_ID 0x05
72 #define MSG_INTERMCU_COMMAND_LENGTH (2*(COMMANDS_NB))
73 #define MSG_INTERMCU_COMMAND(_intermcu_payload, nr) (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)
75 #define InterMcuSend_INTERMCU_COMMAND(cmd) { \
76 InterMcuHeader(MSG_INTERMCU_ID, MSG_INTERMCU_COMMAND_ID, MSG_INTERMCU_COMMAND_LENGTH);\
77 for (int i=0;i<COMMANDS_NB;i++) { \
78 uint16_t _cmd = cmd[i]; \
79 InterMcuSend2ByAddr((uint8_t*)&_cmd);\
84 #define MSG_INTERMCU_RADIO_ID 0x08
85 #define MSG_INTERMCU_RADIO_LENGTH (2*(RADIO_CONTROL_NB_CHANNEL))
86 #define MSG_INTERMCU_RADIO(_intermcu_payload, nr) (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)
88 #define InterMcuSend_INTERMCU_RADIO(cmd) { \
89 InterMcuHeader(MSG_INTERMCU_ID, MSG_INTERMCU_RADIO_ID, MSG_INTERMCU_RADIO_LENGTH);\
90 for (int i=0;i<RADIO_CONTROL_NB_CHANNEL;i++) { \
91 uint16_t _cmd = cmd[i]; \
92 InterMcuSend2ByAddr((uint8_t*)&_cmd);\
97 #define MSG_INTERMCU_FBW_ID 0x06
98 #define MSG_INTERMCU_FBW_MOD(_intermcu_payload) (uint8_t)(*((uint8_t*)_intermcu_payload+0))
99 #define MSG_INTERMCU_FBW_STAT(_intermcu_payload) (uint8_t)(*((uint8_t*)_intermcu_payload+1))
100 #define MSG_INTERMCU_FBW_ERR(_intermcu_payload) (uint8_t)(*((uint8_t*)_intermcu_payload+2))
101 #define MSG_INTERMCU_FBW_VOLT(_intermcu_payload) (uint16_t)(*((uint8_t*)_intermcu_payload+3)|*((uint8_t*)_intermcu_payload+1+3)<<8)
103 #define MSG_INTERMCU_FBW_CURRENT(_intermcu_payload) (uint16_t)(*((uint8_t*)_intermcu_payload+5)|*((uint8_t*)_intermcu_payload+1+5)<<8)
105 #define InterMcuSend_INTERMCU_FBW(mod,stat,err,volt,current) { \
106 InterMcuHeader(MSG_INTERMCU_ID, MSG_INTERMCU_FBW_ID, 7);\
107 uint8_t _mod = mod; InterMcuSend1ByAddr((uint8_t*)&_mod);\
108 uint8_t _stat = stat; InterMcuSend1ByAddr((uint8_t*)&_stat);\
109 uint8_t _err = err; InterMcuSend1ByAddr((uint8_t*)&_err);\
110 uint16_t _volt = volt; InterMcuSend2ByAddr((uint8_t*)&_volt);\
111 uint16_t _current = current; InterMcuSend2ByAddr((uint8_t*)&_current);\
115 #define MSG_INTERMCU_TRIM_ID 0x07
116 #define MSG_INTERMCU_TRIM_ROLL(_intermcu_payload) (uint16_t)(*((uint8_t*)_intermcu_payload+0)|*((uint8_t*)_intermcu_payload+1)<<8)
117 #define MSG_INTERMCU_TRIM_PITCH(_intermcu_payload) (uint16_t)(*((uint8_t*)_intermcu_payload+2)|*((uint8_t*)_intermcu_payload+3)<<8)
119 #define InterMcuSend_INTERMCU_TRIM(roll,pitch) { \
120 InterMcuHeader(MSG_INTERMCU_ID, MSG_INTERMCU_TRIM_ID, 4);\
121 uint16_t _roll = roll; InterMcuSend2ByAddr((uint8_t*)&_roll);\
122 uint16_t _pitch = pitch; InterMcuSend2ByAddr((uint8_t*)&_pitch);\
130 #define LINK_MCU_UNINIT 0
131 #define LINK_MCU_GOT_SYNC1 1
132 #define LINK_MCU_GOT_SYNC2 2
133 #define LINK_MCU_GOT_CLASS 3
134 #define LINK_MCU_GOT_ID 4
135 #define LINK_MCU_GOT_LEN1 5
136 #define LINK_MCU_GOT_LEN2 6
137 #define LINK_MCU_GOT_PAYLOAD 7
138 #define LINK_MCU_GOT_CHECKSUM1 8
141 #define INTERMCU_MAX_PAYLOAD 255
252 #define RC_REALLY_LOST 2
255 static void send_commands(
struct transport_tx *trans,
struct link_device *
dev)
257 pprz_msg_send_COMMANDS(trans, dev, AC_ID, COMMANDS_NB,
ap_state->commands);
265 if (bit_is_set(
fbw_state->status, STATUS_MODE_AUTO)) {
268 if (bit_is_set(
fbw_state->status, STATUS_MODE_FAILSAFE)) {
271 if (bit_is_set(
fbw_state->status, STATUS_RADIO_REALLY_LOST)) {
278 pprz_msg_send_FBW_STATUS(trans, dev, AC_ID,
289 #if PERIODIC_TELEMETRY
302 #error "INTERMCU UART CAN ONLY SEND 8 COMMANDS OR THE UART WILL BE OVERFILLED"
305 for (
int i = 0; i < COMMANDS_NB; i++) {
314 #if RADIO_CONTROL_NB_CHANNEL > 10
315 #error "INTERMCU UART CAN ONLY SEND 10 RADIO CHANNELS OR THE UART WILL BE OVERFILLED"
350 static uint8_t SixtyHzCounter = 0;
355 if (SixtyHzCounter >= 3) {
358 inter_mcu_fill_fbw_state();
366 #if defined RADIO_CONTROL || RADIO_CONTROL_AUTO1
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define InterMcuSend_INTERMCU_COMMAND(cmd)
struct link_mcu_msg link_mcu_from_ap_msg
#define MSG_INTERMCU_RADIO_ID
void parse_mavpilot_msg(void)
static struct fbw_status_t fbw_status
Transport for the communication between FBW and AP via UART.
Periodic telemetry system header (includes downlink utility and generated code).
#define LINK_MCU_GOT_CHECKSUM1
#define MSG_INTERMCU_RADIO(_intermcu_payload, nr)
void intermcu_parse(uint8_t c)
volatile bool inter_mcu_received_ap
struct fbw_state * fbw_state
#define MSG_INTERMCU_FBW_CURRENT(_intermcu_payload)
struct ap_state * ap_state
#define RADIO_CONTROL_NB_CHANNEL
struct InterMcuData intermcu_data
#define MSG_INTERMCU_FBW_VOLT(_intermcu_payload)
#define LINK_MCU_GOT_LEN1
void link_mcu_event_task(void)
#define MSG_INTERMCU_COMMAND_ID
uint8_t msg_buf[INTERMCU_MAX_PAYLOAD]
#define DefaultPeriodic
Set default periodic telemetry.
Hardware independent code for commands handling.
#define MSG_INTERMCU_FBW_ID
#define MSG_INTERMCU_FBW_STAT(_intermcu_payload)
#define MSG_INTERMCU_FBW_MOD(_intermcu_payload)
#define InterMcuSend_INTERMCU_TRIM(roll, pitch)
static const struct usb_device_descriptor dev
#define LINK_MCU_GOT_SYNC1
volatile bool inter_mcu_received_fbw
#define INTERMCU_MAX_PAYLOAD
#define MSG_INTERMCU_FBW_ERR(_intermcu_payload)
#define InterMcuSend_INTERMCU_FBW(mod, stat, err, volt, current)
static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
#define MSG_INTERMCU_TRIM_ID
#define MSG_INTERMCU_TRIM_ROLL(_intermcu_payload)
static void send_commands(struct transport_tx *trans, struct link_device *dev)
#define LINK_MCU_GOT_SYNC2
#define MSG_INTERMCU_COMMAND(_intermcu_payload, nr)
#define MSG_INTERMCU_TRIM_PITCH(_intermcu_payload)
arch independent LED (Light Emitting Diodes) API
#define LINK_MCU_GOT_CLASS
struct link_mcu_msg link_mcu_from_fbw_msg
#define LINK_MCU_GOT_LEN2
#define InterMcuSend_INTERMCU_RADIO(cmd)
#define LINK_MCU_GOT_PAYLOAD
#define InterMcuUartGetch()
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
void link_mcu_periodic_task(void)