Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 __InterMcuLink(dev, _x)   dev##_x
 
#define _InterMcuLink(dev, _x)   __InterMcuLink(dev, _x)
 
#define InterMcuLink(_x)   _InterMcuLink(INTERMCU_LINK, _x)
 
#define InterMcuBuffer()   InterMcuLink(ChAvailable())
 
#define InterMcuUartSend1(c)   InterMcuLink(Transmit(c))
 
#define InterMcuUartSetBaudrate(_a)   InterMcuLink(SetBaudrate(_a))
 
#define InterMcuUartRunning   InterMcuLink(TxRunning)
 
#define InterMcuUartSendMessage   InterMcuLink(SendMessage)
 
#define INTERMCU_SYNC1   0xB5
 
#define INTERMCU_SYNC2   0x62
 
#define InterMcuInitCheksum()   { intermcu_data.send_ck_a = intermcu_data.send_ck_b = 0; }
 
#define UpdateChecksum(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); UpdateChecksum(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)|*((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)|*((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 UNINIT   0
 
#define GOT_SYNC1   1
 
#define GOT_SYNC2   2
 
#define GOT_CLASS   3
 
#define GOT_ID   4
 
#define GOT_LEN1   5
 
#define GOT_LEN2   6
 
#define GOT_PAYLOAD   7
 
#define 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
 

Macro Definition Documentation

#define __InterMcuLink (   dev,
  _x 
)    dev##_x

Definition at line 32 of file link_mcu_usart.c.

#define _InterMcuLink (   dev,
  _x 
)    __InterMcuLink(dev, _x)

Definition at line 33 of file link_mcu_usart.c.

#define GOT_CHECKSUM1   8

Definition at line 141 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_CLASS   3

Definition at line 136 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_ID   4

Definition at line 137 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_LEN1   5

Definition at line 138 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_LEN2   6

Definition at line 139 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_PAYLOAD   7

Definition at line 140 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_SYNC1   1

Definition at line 134 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define GOT_SYNC2   2

Definition at line 135 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define INTERMCU_MAX_PAYLOAD   255

Definition at line 144 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define INTERMCU_SYNC1   0xB5

Definition at line 46 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define INTERMCU_SYNC2   0x62

Definition at line 47 of file link_mcu_usart.c.

Referenced by intermcu_parse().

#define InterMcuBuffer ( )    InterMcuLink(ChAvailable())

Definition at line 36 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 59 of file link_mcu_usart.c.

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

Definition at line 49 of file link_mcu_usart.c.

#define InterMcuLink (   _x)    _InterMcuLink(INTERMCU_LINK, _x)

Definition at line 34 of file link_mcu_usart.c.

Referenced by link_mcu_event_task().

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

Definition at line 53 of file link_mcu_usart.c.

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

Definition at line 55 of file link_mcu_usart.c.

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

Definition at line 54 of file link_mcu_usart.c.

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

Definition at line 56 of file link_mcu_usart.c.

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

Definition at line 57 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 79 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
static int32_t current
Supply current in milliAmpere.
Definition: main_ap.c:155
unsigned char uint8_t
Definition: types.h:14

Definition at line 108 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: spektrum_arch.h:34
unsigned char uint8_t
Definition: types.h:14

Definition at line 92 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 122 of file link_mcu_usart.c.

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

Definition at line 51 of file link_mcu_usart.c.

#define InterMcuUartRunning   InterMcuLink(TxRunning)

Definition at line 40 of file link_mcu_usart.c.

#define InterMcuUartSend1 (   c)    InterMcuLink(Transmit(c))

Definition at line 38 of file link_mcu_usart.c.

#define InterMcuUartSendMessage   InterMcuLink(SendMessage)

Definition at line 41 of file link_mcu_usart.c.

#define InterMcuUartSetBaudrate (   _a)    InterMcuLink(SetBaudrate(_a))

Definition at line 39 of file link_mcu_usart.c.

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

Definition at line 77 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_COMMAND_ID   0x05

Definition at line 75 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_COMMAND_LENGTH   (2*(COMMANDS_NB))

Definition at line 76 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 106 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 104 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_FBW_ID   0x06

Definition at line 101 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 102 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 103 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 105 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_ID   100

Definition at line 72 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)|*((uint8_t*)_intermcu_payload+1+(2*(nr)))<<8)

Definition at line 90 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_RADIO_ID   0x08

Definition at line 88 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define MSG_INTERMCU_RADIO_LENGTH   (2*(RADIO_CONTROL_NB_CHANNEL))

Definition at line 89 of file link_mcu_usart.c.

#define MSG_INTERMCU_TRIM_ID   0x07

Definition at line 118 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 120 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 119 of file link_mcu_usart.c.

Referenced by parse_mavpilot_msg().

#define UNINIT   0

Definition at line 133 of file link_mcu_usart.c.

Referenced by intermcu_parse(), link_mcu_init(), and sirf_parse_char().

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

Definition at line 50 of file link_mcu_usart.c.

Function Documentation

void link_mcu_event_task ( void  )

Definition at line 342 of file link_mcu_usart.c.

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

Referenced by event_task_ap(), and event_task_fbw().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void link_mcu_init ( void  )

Definition at line 247 of file link_mcu_usart.c.

References InterMcuData::error_cnt, FALSE, intermcu_data, InterMcuData::msg_available, InterMcuData::status, and UNINIT.

Referenced by init_ap(), and init_fbw().

+ Here is the caller graph for this function:

Variable Documentation

struct InterMcuData intermcu_data
struct link_mcu_msg link_mcu_from_ap_msg

Definition at line 242 of file link_mcu_usart.c.

struct link_mcu_msg link_mcu_from_fbw_msg

Definition at line 243 of file link_mcu_usart.c.