Skip to content

Commit

Permalink
[chibios] uart: Log uart/serial errors
Browse files Browse the repository at this point in the history
- Fixed makefiles of some serial peripherals to be compatible with ChibiOS
- Serial line error logging compatible with Paparazzzi (so far for telemetry/gps ports)
- Minor fixes in uart arch
  • Loading branch information
podhrmic authored and flixr committed Nov 26, 2013
1 parent d8fb50f commit ecd8b7a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 48 deletions.
3 changes: 3 additions & 0 deletions conf/firmwares/subsystems/rotorcraft/gps_ublox.makefile
Expand Up @@ -9,6 +9,9 @@ ap.srcs += $(SRC_SUBSYSTEMS)/gps/gps_ubx.c
ap.CFLAGS += -DUSE_$(GPS_PORT) -D$(GPS_PORT)_BAUD=$(GPS_BAUD)
ap.CFLAGS += -DUSE_GPS -DGPS_LINK=$(GPS_PORT)

GPS_PORT_LOWER=$(shell echo $(GPS_PORT) | tr A-Z a-z)
ap.CFLAGS += -DGPS_PORT=$(GPS_PORT_LOWER)

ifneq ($(GPS_LED),none)
ap.CFLAGS += -DGPS_LED=$(GPS_LED)
endif
Expand Down
Expand Up @@ -10,5 +10,9 @@ ap.CFLAGS += -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)

ap.CFLAGS += -DDOWNLINK -DDOWNLINK_DEVICE=$(MODEM_PORT) -DPPRZ_UART=$(MODEM_PORT)
ap.CFLAGS += -DDOWNLINK_TRANSPORT=PprzTransport -DDATALINK=PPRZ

MODEM_PORT_LOWER=$(shell echo $(MODEM_PORT) | tr A-Z a-z)
ap.CFLAGS += -DDOWNLINK_PORT=$(MODEM_PORT_LOWER)

ap.srcs += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c
ap.srcs += $(SRC_FIRMWARE)/datalink.c $(SRC_FIRMWARE)/telemetry.c
10 changes: 5 additions & 5 deletions sw/airborne/arch/chibios/mcu_periph/uart_arch.c
Expand Up @@ -41,7 +41,7 @@ static const SerialConfig usart1_config =
{
UART1_BAUD, /* BITRATE */
0, /* USART CR1 */
USART_CR2_STOP1_BITS | USART_CR2_LINEN, /* USART CR2 */
USART_CR2_STOP1_BITS, /* USART CR2 */
0 /* USART CR3 */
};
void uart1_init(void) {
Expand All @@ -56,7 +56,7 @@ static const SerialConfig usart2_config =
{
UART2_BAUD, /* BITRATE */
0, /* USART CR1 */
USART_CR2_STOP1_BITS | USART_CR2_LINEN, /* USART CR2 */
USART_CR2_STOP1_BITS, /* USART CR2 */
0 /* USART CR3 */
};
void uart2_init(void) {
Expand All @@ -70,7 +70,7 @@ static const SerialConfig usart3_config =
{
UART3_BAUD, /* BITRATE */
0, /* USART CR1 */
USART_CR2_STOP1_BITS | USART_CR2_LINEN, /* USART CR2 */
USART_CR2_STOP1_BITS, /* USART CR2 */
0 /* USART CR3 */
};
void uart3_init(void) {
Expand All @@ -84,7 +84,7 @@ static const SerialConfig usart4_config =
{
UART4_BAUD, /* BITRATE */
0, /* USART CR1 */
USART_CR2_STOP1_BITS | USART_CR2_LINEN, /* USART CR2 */
USART_CR2_STOP1_BITS, /* USART CR2 */
0 /* USART CR3 */
};
void uart4_init(void) {
Expand All @@ -98,7 +98,7 @@ static const SerialConfig usart5_config =
{
UART5_BAUD, /* BITRATE */
0, /* USART CR1 */
USART_CR2_STOP1_BITS | USART_CR2_LINEN, /* USART CR2 */
USART_CR2_STOP1_BITS, /* USART CR2 */
0 /* USART CR3 */
};
void uart5_init(void) {
Expand Down
20 changes: 15 additions & 5 deletions sw/airborne/firmwares/rotorcraft/main_chibios.c
Expand Up @@ -233,21 +233,31 @@ static __attribute__((noreturn)) msg_t thd_telemetry_rx(void *arg)
(void) arg;
EventListener elTelemetryRx;
flagsmask_t flags;
chEvtRegisterMask((EventSource *)chnGetEventSource(&SD2), &elTelemetryRx, EVENT_MASK(1));

chEvtRegisterMask((EventSource *)chnGetEventSource((SerialDriver*)DOWNLINK_PORT.reg_addr), &elTelemetryRx, EVENT_MASK(1));
while (TRUE)
{
chEvtWaitOneTimeout(EVENT_MASK(1), TIME_INFINITE);
chEvtWaitOneTimeout(EVENT_MASK(1), S2ST(1));
chSysLock();
flags = chEvtGetAndClearFlags(&elTelemetryRx);
chSysUnlock();

if ((flags & (SD_FRAMING_ERROR | SD_OVERRUN_ERROR |
SD_NOISE_ERROR)) != 0) {
if (flags & SD_OVERRUN_ERROR) {
DOWNLINK_PORT.ore++;
}
if (flags & SD_NOISE_ERROR) {
DOWNLINK_PORT.ne_err++;
}
if (flags & SD_FRAMING_ERROR) {
DOWNLINK_PORT.fe_err++;
}
}
if (flags & CHN_INPUT_AVAILABLE)
{
msg_t charbuf;
do
{
charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
charbuf = chnGetTimeout((SerialDriver*)DOWNLINK_PORT.reg_addr, TIME_IMMEDIATE);
if ( charbuf != Q_TIMEOUT )
{
parse_pprz(&pprz_tp, charbuf);
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/mcu_periph/uart.h
Expand Up @@ -80,6 +80,10 @@ extern void uart_transmit(struct uart_periph* p, uint8_t data);
extern bool_t uart_check_free_space(struct uart_periph* p, uint8_t len);
extern uint8_t uart_getch(struct uart_periph* p);

#ifdef USE_CHIBIOS_RTOS
extern void uart_transmit_buffer(struct uart_periph* p, uint8_t* data_buffer, size_t length);
#endif

static inline bool_t uart_char_available(struct uart_periph* p) {
return (p->rx_insert_idx != p->rx_extract_idx);
}
Expand Down
84 changes: 46 additions & 38 deletions sw/airborne/subsystems/gps/gps_ubx.h
Expand Up @@ -106,44 +106,52 @@ extern struct GpsUbx gps_ubx;
gps_ubx_parse(GpsLink(Getch())); \
}
#else
#define GpsThread() { \
EventListener elGPSdata; \
flagsmask_t flags; \
chEvtRegisterMask((EventSource *)chnGetEventSource(&SD5), &elGPSdata, EVENT_MASK(1)); \
while (TRUE) \
{ \
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(100));\
chSysLock();\
flags = chEvtGetAndClearFlags(&elGPSdata);\
chSysUnlock();\
if (flags & CHN_INPUT_AVAILABLE)\
{\
msg_t charbuf;\
do \
{\
charbuf = chnGetTimeout(&SD5, TIME_IMMEDIATE);\
if ( charbuf != Q_TIMEOUT )\
{\
gps_ubx_parse(charbuf);\
}\
}\
while (charbuf != Q_TIMEOUT);\
}\
if (gps_ubx.msg_available) { \
gps_ubx_read_message(); \
gps_ubx_ucenter_event(); \
if (gps_ubx.msg_class == UBX_NAV_ID && \
(gps_ubx.msg_id == UBX_NAV_VELNED_ID || \
(gps_ubx.msg_id == UBX_NAV_SOL_ID && \
gps_ubx.have_velned == 0))) { \
if (gps.fix == GPS_FIX_3D) { \
gps.last_fix_ticks = sys_time.nb_sec_rem; \
gps.last_fix_time = sys_time.nb_sec; \
} \
}\
gps_ubx.msg_available = FALSE;\
}\
}\
#define GpsThread() { \
EventListener elGPSdata; \
flagsmask_t flags; \
chEvtRegisterMask((EventSource *)chnGetEventSource((SerialDriver*)GPS_PORT.reg_addr), &elGPSdata, EVENT_MASK(1));\
while (TRUE) { \
chEvtWaitOneTimeout(EVENT_MASK(1), S2ST(1)); \
chSysLock(); \
flags = chEvtGetAndClearFlags(&elGPSdata); \
chSysUnlock(); \
if ((flags & (SD_FRAMING_ERROR | SD_OVERRUN_ERROR | \
SD_NOISE_ERROR)) != 0) { \
if (flags & SD_OVERRUN_ERROR) { \
GPS_PORT.ore++; \
} \
if (flags & SD_NOISE_ERROR) { \
GPS_PORT.ne_err++; \
} \
if (flags & SD_FRAMING_ERROR) { \
GPS_PORT.fe_err++; \
} \
} \
if (flags & CHN_INPUT_AVAILABLE) { \
msg_t charbuf; \
do { \
charbuf = chnGetTimeout((SerialDriver*)GPS_PORT.reg_addr, TIME_IMMEDIATE);\
if ( charbuf != Q_TIMEOUT ) { \
gps_ubx_parse(charbuf); \
} \
} \
while (charbuf != Q_TIMEOUT); \
} \
if (gps_ubx.msg_available) { \
gps_ubx_read_message(); \
gps_ubx_ucenter_event(); \
if (gps_ubx.msg_class == UBX_NAV_ID && \
(gps_ubx.msg_id == UBX_NAV_VELNED_ID || \
(gps_ubx.msg_id == UBX_NAV_SOL_ID && \
gps_ubx.have_velned == 0))) { \
if (gps.fix == GPS_FIX_3D) { \
gps.last_fix_ticks = sys_time.nb_sec_rem; \
gps.last_fix_time = sys_time.nb_sec; \
} \
} \
gps_ubx.msg_available = FALSE; \
} \
} \
}
#endif

Expand Down

0 comments on commit ecd8b7a

Please sign in to comment.