Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
link_mcu_usart.c File Reference
#include "link_mcu_usart.h"
#include "mcu_periph/uart.h"
#include "led.h"
#include "subsystems/commands.h"
+ Include dependency graph for link_mcu_usart.c:

Go to the source code of this file.

Data Structures

struct  InterMcuData
 

Macros

#define InterMcuBuffer()   uart_char_available(&(INTERMCU_LINK))
 
#define InterMcuUartSend1(c)   uart_put_byte(&(INTERMCU_LINK), 0, c)
 
#define InterMcuUartSetBaudrate(_a)   uart_periph_set_baudrate(&(INTERMCU_LINK), _a)
 
#define InterMcuUartSendMessage()   {}
 
#define InterMcuUartGetch()   uart_getch(&(INTERMCU_LINK))
 
#define INTERMCU_SYNC1   0xB5
 
#define INTERMCU_SYNC2   0x62
 
#define InterMcuInitCheksum()   { intermcu_data.send_ck_a = intermcu_data.send_ck_b = 0; }
 
#define InterMcuUpdateChecksum(c)   { intermcu_data.send_ck_a += c; intermcu_data.send_ck_b += intermcu_data.send_ck_a; }
 
#define InterMcuTrailer()   { InterMcuUartSend1(intermcu_data.send_ck_a); InterMcuUartSend1(intermcu_data.send_ck_b); InterMcuUartSendMessage(); }
 
#define InterMcuSend1(c)   { uint8_t i8=c; InterMcuUartSend1(i8); InterMcuUpdateChecksum(i8); }
 
#define InterMcuSend2(c)   { uint16_t i16=c; InterMcuSend1(i16&0xff); InterMcuSend1(i16 >> 8); }
 
#define InterMcuSend1ByAddr(x)   { InterMcuSend1(*x); }
 
#define InterMcuSend2ByAddr(x)   { InterMcuSend1(*x); InterMcuSend1(*(x+1)); }
 
#define InterMcuSend4ByAddr(x)   { InterMcuSend1(*x); InterMcuSend1(*(x+1)); InterMcuSend1(*(x+2)); InterMcuSend1(*(x+3)); }
 
#define InterMcuHeader(nav_id, msg_id, len)
 
#define MSG_INTERMCU_ID   100
 
#define MSG_INTERMCU_COMMAND_ID   0x05
 
#define MSG_INTERMCU_COMMAND_LENGTH   (2*(COMMANDS_NB))
 
#define MSG_INTERMCU_COMMAND(_intermcu_payload, nr)   (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)
 
#define InterMcuSend_INTERMCU_COMMAND(cmd)
 
#define MSG_INTERMCU_RADIO_ID   0x08
 
#define MSG_INTERMCU_RADIO_LENGTH   (2*(RADIO_CONTROL_NB_CHANNEL))
 
#define MSG_INTERMCU_RADIO(_intermcu_payload, nr)   (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)
 
#define InterMcuSend_INTERMCU_RADIO(cmd)
 
#define MSG_INTERMCU_FBW_ID   0x06
 
#define MSG_INTERMCU_FBW_MOD(_intermcu_payload)   (uint8_t)(*((uint8_t*)_intermcu_payload+0))
 
#define MSG_INTERMCU_FBW_STAT(_intermcu_payload)   (uint8_t)(*((uint8_t*)_intermcu_payload+1))
 
#define MSG_INTERMCU_FBW_ERR(_intermcu_payload)   (uint8_t)(*((uint8_t*)_intermcu_payload+2))
 
#define MSG_INTERMCU_FBW_VOLT(_intermcu_payload)   (uint16_t)(*((uint8_t*)_intermcu_payload+3)|*((uint8_t*)_intermcu_payload+1+3)<<8)
 
#define MSG_INTERMCU_FBW_CURRENT(_intermcu_payload)   (uint16_t)(*((uint8_t*)_intermcu_payload+5)|*((uint8_t*)_intermcu_payload+1+5)<<8)
 
#define InterMcuSend_INTERMCU_FBW(mod, stat, err, volt, current)
 
#define MSG_INTERMCU_TRIM_ID   0x07
 
#define MSG_INTERMCU_TRIM_ROLL(_intermcu_payload)   (uint16_t)(*((uint8_t*)_intermcu_payload+0)|*((uint8_t*)_intermcu_payload+1)<<8)
 
#define MSG_INTERMCU_TRIM_PITCH(_intermcu_payload)   (uint16_t)(*((uint8_t*)_intermcu_payload+2)|*((uint8_t*)_intermcu_payload+3)<<8)
 
#define InterMcuSend_INTERMCU_TRIM(roll, pitch)
 
#define LINK_MCU_UNINIT   0
 
#define LINK_MCU_GOT_SYNC1   1
 
#define LINK_MCU_GOT_SYNC2   2
 
#define LINK_MCU_GOT_CLASS   3
 
#define LINK_MCU_GOT_ID   4
 
#define LINK_MCU_GOT_LEN1   5
 
#define LINK_MCU_GOT_LEN2   6
 
#define LINK_MCU_GOT_PAYLOAD   7
 
#define LINK_MCU_GOT_CHECKSUM1   8
 
#define INTERMCU_MAX_PAYLOAD   255
 

Functions

void intermcu_parse (uint8_t c)
 
void parse_mavpilot_msg (void)
 
void link_mcu_init (void)
 
void link_mcu_event_task (void)
 

Variables

struct InterMcuData intermcu_data
 
struct link_mcu_msg link_mcu_from_ap_msg
 
struct link_mcu_msg link_mcu_from_fbw_msg
 

Data Structure Documentation

struct InterMcuData

Definition at line 142 of file link_mcu_usart.c.

Data Fields
uint8_t ck_a
uint8_t ck_b
uint8_t error_cnt
uint16_t len
bool msg_available
uint8_t msg_buf[INTERMCU_MAX_PAYLOAD]
uint8_t msg_class
uint8_t msg_id
uint8_t msg_idx
uint8_t send_ck_a
uint8_t send_ck_b
uint8_t status

Macro Definition Documentation

#define INTERMCU_MAX_PAYLOAD   255

Definition at line 141 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define INTERMCU_SYNC1   0xB5

Definition at line 42 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define INTERMCU_SYNC2   0x62

Definition at line 43 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define InterMcuBuffer ( )    uart_char_available(&(INTERMCU_LINK))

Definition at line 33 of file link_mcu_usart.c.

Referenced by link_mcu_event_task().

#define InterMcuHeader (   nav_id,
  msg_id,
  len 
)
Value:
{ \
InterMcuSend1(nav_id); \
InterMcuSend1(msg_id); \
}

Definition at line 55 of file link_mcu_usart.c.

#define InterMcuInitCheksum ( )    { intermcu_data.send_ck_a = intermcu_data.send_ck_b = 0; }

Definition at line 45 of file link_mcu_usart.c.

#define InterMcuSend1 (   c)    { uint8_t i8=c; InterMcuUartSend1(i8); InterMcuUpdateChecksum(i8); }

Definition at line 49 of file link_mcu_usart.c.

#define InterMcuSend1ByAddr (   x)    { InterMcuSend1(*x); }

Definition at line 51 of file link_mcu_usart.c.

#define InterMcuSend2 (   c)    { uint16_t i16=c; InterMcuSend1(i16&0xff); InterMcuSend1(i16 >> 8); }

Definition at line 50 of file link_mcu_usart.c.

#define InterMcuSend2ByAddr (   x)    { InterMcuSend1(*x); InterMcuSend1(*(x+1)); }

Definition at line 52 of file link_mcu_usart.c.

#define InterMcuSend4ByAddr (   x)    { InterMcuSend1(*x); InterMcuSend1(*(x+1)); InterMcuSend1(*(x+2)); InterMcuSend1(*(x+3)); }

Definition at line 53 of file link_mcu_usart.c.

#define InterMcuSend_INTERMCU_COMMAND (   cmd)
Value:
{ \
for (int i=0;i<COMMANDS_NB;i++) { \
uint16_t _cmd = cmd[i]; \
} \
}
unsigned short uint16_t
Definition: types.h:16
unsigned char uint8_t
Definition: types.h:14

Definition at line 75 of file link_mcu_usart.c.

#define InterMcuSend_INTERMCU_FBW (   mod,
  stat,
  err,
  volt,
  current 
)
Value:
{ \
uint8_t _mod = mod; InterMcuSend1ByAddr((uint8_t*)&_mod);\
uint8_t _stat = stat; InterMcuSend1ByAddr((uint8_t*)&_stat);\
uint8_t _err = err; InterMcuSend1ByAddr((uint8_t*)&_err);\
uint16_t _volt = volt; InterMcuSend2ByAddr((uint8_t*)&_volt);\
uint16_t _current = current; InterMcuSend2ByAddr((uint8_t*)&_current);\
}
unsigned short uint16_t
Definition: types.h:16
int32_t current
Supply current in milliAmpere.
unsigned char uint8_t
Definition: types.h:14

Definition at line 105 of file link_mcu_usart.c.

#define InterMcuSend_INTERMCU_RADIO (   cmd)
Value:
{ \
for (int i=0;i<RADIO_CONTROL_NB_CHANNEL;i++) { \
uint16_t _cmd = cmd[i]; \
} \
}
unsigned short uint16_t
Definition: types.h:16
#define RADIO_CONTROL_NB_CHANNEL
Definition: intermcu_ap.h:48
unsigned char uint8_t
Definition: types.h:14

Definition at line 88 of file link_mcu_usart.c.

#define InterMcuSend_INTERMCU_TRIM (   roll,
  pitch 
)
Value:
{ \
uint16_t _roll = roll; InterMcuSend2ByAddr((uint8_t*)&_roll);\
uint16_t _pitch = pitch; InterMcuSend2ByAddr((uint8_t*)&_pitch);\
}
unsigned short uint16_t
Definition: types.h:16
unsigned char uint8_t
Definition: types.h:14

Definition at line 119 of file link_mcu_usart.c.

#define InterMcuTrailer ( )    { InterMcuUartSend1(intermcu_data.send_ck_a); InterMcuUartSend1(intermcu_data.send_ck_b); InterMcuUartSendMessage(); }

Definition at line 47 of file link_mcu_usart.c.

#define InterMcuUartGetch ( )    uart_getch(&(INTERMCU_LINK))

Definition at line 37 of file link_mcu_usart.c.

Referenced by link_mcu_event_task().

#define InterMcuUartSend1 (   c)    uart_put_byte(&(INTERMCU_LINK), 0, c)

Definition at line 34 of file link_mcu_usart.c.

#define InterMcuUartSendMessage ( )    {}

Definition at line 36 of file link_mcu_usart.c.

#define InterMcuUartSetBaudrate (   _a)    uart_periph_set_baudrate(&(INTERMCU_LINK), _a)

Definition at line 35 of file link_mcu_usart.c.

#define InterMcuUpdateChecksum (   c)    { intermcu_data.send_ck_a += c; intermcu_data.send_ck_b += intermcu_data.send_ck_a; }

Definition at line 46 of file link_mcu_usart.c.

#define LINK_MCU_GOT_CHECKSUM1   8

Definition at line 138 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_CLASS   3

Definition at line 133 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_ID   4

Definition at line 134 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_LEN1   5

Definition at line 135 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_LEN2   6

Definition at line 136 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_PAYLOAD   7

Definition at line 137 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_SYNC1   1

Definition at line 131 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_GOT_SYNC2   2

Definition at line 132 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define LINK_MCU_UNINIT   0

Definition at line 130 of file link_mcu_usart.c.

Referenced by intermcu_parse(), and link_mcu_init().

#define MSG_INTERMCU_COMMAND (   _intermcu_payload,
  nr 
)    (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)

Definition at line 73 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_COMMAND_ID   0x05

Definition at line 71 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_COMMAND_LENGTH   (2*(COMMANDS_NB))

Definition at line 72 of file link_mcu_usart.c.

#define MSG_INTERMCU_FBW_CURRENT (   _intermcu_payload)    (uint16_t)(*((uint8_t*)_intermcu_payload+5)|*((uint8_t*)_intermcu_payload+1+5)<<8)

Definition at line 103 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_ERR (   _intermcu_payload)    (uint8_t)(*((uint8_t*)_intermcu_payload+2))

Definition at line 100 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_ID   0x06

Definition at line 97 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_MOD (   _intermcu_payload)    (uint8_t)(*((uint8_t*)_intermcu_payload+0))

Definition at line 98 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_STAT (   _intermcu_payload)    (uint8_t)(*((uint8_t*)_intermcu_payload+1))

Definition at line 99 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_VOLT (   _intermcu_payload)    (uint16_t)(*((uint8_t*)_intermcu_payload+3)|*((uint8_t*)_intermcu_payload+1+3)<<8)

Definition at line 101 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_ID   100

Definition at line 68 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_RADIO (   _intermcu_payload,
  nr 
)    (uint16_t)(*((uint8_t*)_intermcu_payload+0+(2*(nr)))|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)

Definition at line 86 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_RADIO_ID   0x08

Definition at line 84 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_RADIO_LENGTH   (2*(RADIO_CONTROL_NB_CHANNEL))

Definition at line 85 of file link_mcu_usart.c.

#define MSG_INTERMCU_TRIM_ID   0x07

Definition at line 115 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_TRIM_PITCH (   _intermcu_payload)    (uint16_t)(*((uint8_t*)_intermcu_payload+2)|*((uint8_t*)_intermcu_payload+3)<<8)

Definition at line 117 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_TRIM_ROLL (   _intermcu_payload)    (uint16_t)(*((uint8_t*)_intermcu_payload+0)|*((uint8_t*)_intermcu_payload+1)<<8)

Definition at line 116 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

Function Documentation

void link_mcu_event_task ( void  )

Definition at line 374 of file link_mcu_usart.c.

References intermcu_data, intermcu_parse(), InterMcuBuffer, InterMcuUartGetch, InterMcuData::msg_available, and parse_mavpilot_msg().

+ Here is the call graph for this function:

Variable Documentation

struct InterMcuData intermcu_data
struct link_mcu_msg link_mcu_from_ap_msg

Definition at line 241 of file link_mcu_usart.c.

struct link_mcu_msg link_mcu_from_fbw_msg

Definition at line 242 of file link_mcu_usart.c.