28 #include "pprzlink/intermcu_msg.h"
39 #include "libopencm3/cm3/scb.h"
42 static uint8_t px4RebootSequence[] = {0x41, 0xd7, 0x32, 0x0a, 0x46, 0x39};
43 static uint8_t px4RebootSequenceCount = 0;
47 #if RADIO_CONTROL_NB_CHANNEL > 8
48 #undef RADIO_CONTROL_NB_CHANNEL
49 #define RADIO_CONTROL_NB_CHANNEL 8
50 INFO(
"InterMCU UART will only send 8 radio channels!")
66 static void checkPx4RebootCommand(
unsigned char b);
99 #ifdef RADIO_KILL_SWITCH
103 #if defined (RADIO_AUX1) && defined (RADIO_KILL_SWITCH)
104 #warning "RC AUX1 and KILL_SWITCH are on the same channel."
117 pprz_msg_send_IMCU_RADIO_COMMANDS(&(intermcu.
transport.trans_tx), intermcu.
device,
129 #pragma GCC diagnostic ignored "-Wcast-align"
135 case DL_IMCU_COMMANDS: {
145 for (i = 0; i < size; i++) {
146 intermcu_commands[i] = new_commands[i];
151 commands_frame_handler();
154 #if defined(TELEMETRY_INTERMCU_DEV)
155 case DL_IMCU_TELEMETRY: {
163 #if defined(SPEKTRUM_HAS_SOFT_BIND_PIN) //TODO: make subscribable module parser
164 case DL_IMCU_SPEKTRUM_SOFT_BIND:
173 #pragma GCC diagnostic pop
180 if (intermcu.
device->char_available(intermcu.
device->periph)) {
181 while (intermcu.
device->char_available(intermcu.
device->periph) && !intermcu.
transport.trans_rx.msg_received) {
187 checkPx4RebootCommand(c);
192 if (intermcu.
transport.trans_rx.msg_received) {
193 for (i = 0; i < intermcu.
transport.trans_rx.payload_len; i++) {
198 intermcu.
transport.trans_rx.msg_received =
false;
211 static void checkPx4RebootCommand(
uint8_t b)
217 }
else if (intermcu.stable_px4_baud ==
PX4_BAUD) {
236 if (b == px4RebootSequence[px4RebootSequenceCount]) {
237 px4RebootSequenceCount++;
239 px4RebootSequenceCount = 0;
242 if (px4RebootSequenceCount >= 6) {
243 px4RebootSequenceCount = 0;
247 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x00);
248 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0xe5);
249 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x32);
250 intermcu.
device->put_byte(intermcu.
device->periph, 0, 0x0a);
struct intermcu_t intermcu
int32_t current
current in milliamps
void intermcu_send_status(uint8_t mode)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Set baudrate.
#define INTERMCU_LOST_CNT
uint8_t imcu_msg_buf[128]
The InterMCU message buffer.
void InterMcuEvent(void(*frame_handler)(void))
static void intermcu_parse_msg(void(*commands_frame_handler)(void))
struct link_device * device
Device used for communication.
#define INTERMCU_RADIO_AUX3
pprz_t intermcu_commands[COMMANDS_NB]
uint8_t cmd_status
Command status information that is transfered (intermcu_cmd_status)
void telemetry_intermcu_on_msg(uint8_t msg_id, uint8_t *msg, uint8_t size)
Telemetry through InterMCU.
void sys_time_cancel_timer(tid_t id)
Cancel a system timer by id.
enum intermcu_status status
Status of the INTERMCU.
InterMCU communication is OK.
#define INTERMCU_RADIO_PITCH
#define INTERMCU_RADIO_MODE
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
bool msg_available
If we have an InterMCU message.
Rotorcraft Inter-MCU on FlyByWire.
bool enabled
If the InterMCU communication is enabled.
#define INTERMCU_RADIO_ROLL
No interMCU communication anymore.
#define INTERMCU_RADIO_AUX1
Interface for electrical status: supply voltage, current, battery status, etc.
Architecture independent timing functions.
The status of autopilot_motors_on.
#define INTERMCU_RADIO_YAW
#define INTERMCU_GET_CMD_STATUS(_bit)
int8_t tid_t
sys_time timer id type
struct RadioControl radio_control
struct pprz_transport transport
Transport over communication line (PPRZ)
void intermcu_on_rc_frame(uint8_t fbw_mode)
#define INTERMCU_RADIO_KILL_SWITCH
#define RADIO_CONTROL_NB_CHANNEL
#define INTERMCU_RADIO_THROTTLE
#define INTERMCU_CLR_CMD_STATUS(_bit)
#define INTERMCU_RADIO_AUX2
void received_spektrum_soft_bind(void)
uint8_t time_since_last_frame
Time since last frame.
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
uint16_t vsupply
supply voltage in decivolts
arch independent LED (Light Emitting Diodes) API
struct Electrical electrical
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
void intermcu_periodic(void)
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.