diff --git a/conf/firmwares/test_progs.makefile b/conf/firmwares/test_progs.makefile index ed4acb49af..c802059e14 100644 --- a/conf/firmwares/test_progs.makefile +++ b/conf/firmwares/test_progs.makefile @@ -82,6 +82,9 @@ COMMON_TELEMETRY_CFLAGS += -DPPRZ_UART=$(MODEM_DEV) COMMON_TELEMETRY_CFLAGS += -DDOWNLINK_DEVICE=$(UDP_MODEM_PORT_LOWER) else # via UART +#ifeq ($(MODEM_PORT),) +#$(error MODEM_PORT not defined) +#endif COMMON_TELEMETRY_MODEM_PORT_LOWER=$(shell echo $(MODEM_PORT) | tr A-Z a-z) COMMON_TELEMETRY_CFLAGS += -DUSE_$(MODEM_PORT) -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD) COMMON_TELEMETRY_CFLAGS += -DPPRZ_UART=$(MODEM_PORT) @@ -138,7 +141,6 @@ test_uart.ARCHDIR = $(ARCH) test_uart.CFLAGS += $(COMMON_TEST_CFLAGS) test_uart.srcs += $(COMMON_TEST_SRCS) -test_uart.CFLAGS += -I$(SRC_LISA) -DUSE_UART #test_uart.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B57600 #test_uart.CFLAGS += -DUSE_UART2 -DUART2_BAUD=B57600 #test_uart.CFLAGS += -DUSE_UART3 -DUART3_BAUD=B57600 @@ -146,6 +148,27 @@ test_uart.CFLAGS += -I$(SRC_LISA) -DUSE_UART test_uart.srcs += mcu_periph/uart.c test_uart.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c test_uart.srcs += test/mcu_periph/test_uart.c +ifeq ($(ARCH), linux) +test_uart.srcs += $(SRC_ARCH)/serial_port.c +endif + + +# +# test uart_echo +# +# required configuration: +# -DUSE_UARTx +# -DUARTx_BAUD=B57600 +# +test_uart_echo.ARCHDIR = $(ARCH) +test_uart_echo.CFLAGS += $(COMMON_TEST_CFLAGS) +test_uart_echo.srcs += $(COMMON_TEST_SRCS) +test_uart_echo.srcs += mcu_periph/uart.c +test_uart_echo.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c +test_uart_echo.srcs += test/mcu_periph/test_uart_echo.c +ifeq ($(ARCH), linux) +test_uart_echo.srcs += $(SRC_ARCH)/serial_port.c +endif # diff --git a/sw/airborne/test/mcu_periph/test_uart.c b/sw/airborne/test/mcu_periph/test_uart.c index be0d49a882..bdc778b123 100644 --- a/sw/airborne/test/mcu_periph/test_uart.c +++ b/sw/airborne/test/mcu_periph/test_uart.c @@ -37,6 +37,7 @@ int main(void) if (sys_time_check_and_ack_timer(0)) { main_periodic(); } + uart_event(); } return 0; @@ -61,8 +62,11 @@ static inline void main_periodic(void) #if USE_UART3 uart_transmit(&uart3, 'c'); #endif +#if USE_UART4 + uart_transmit(&uart4, 'd'); +#endif #if USE_UART5 - uart_transmit(&uart5, 'd'); + uart_transmit(&uart5, 'e'); #endif LED_OFF(1); @@ -101,9 +105,9 @@ static inline void main_periodic(void) } #endif -#if USE_UART5 - if (uart_char_available(&uart5)) { - ch = uart_getch(&uart5); +#if USE_UART4 + if (uart_char_available(&uart4)) { + ch = uart_getch(&uart4); if (ch == 'd') { LED_ON(1); } else { @@ -111,4 +115,15 @@ static inline void main_periodic(void) } } #endif + +#if USE_UART5 + if (uart_char_available(&uart5)) { + ch = uart_getch(&uart5); + if (ch == 'e') { + LED_ON(1); + } else { + LED_ON(2); + } + } +#endif } diff --git a/sw/airborne/test/mcu_periph/test_uart_echo.c b/sw/airborne/test/mcu_periph/test_uart_echo.c new file mode 100644 index 0000000000..0c398b4ef2 --- /dev/null +++ b/sw/airborne/test/mcu_periph/test_uart_echo.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2015 Felix Ruess + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include BOARD_CONFIG +#include "mcu.h" +#include "mcu_periph/uart.h" +#include "mcu_periph/sys_time.h" +#include "std.h" + +#include +#include + +#ifndef TEST_UART +#if USE_UART1 +#define TEST_UART uart1 +#endif +#if USE_UART4 +#define TEST_UART uart4 +#endif +#endif +PRINT_CONFIG_VAR(TEST_UART) + +static inline void main_init(void); +static inline void main_periodic(void); +static inline void main_event(void); + +int main(void) +{ + main_init(); + + while (1) { + if (sys_time_check_and_ack_timer(0)) { + main_periodic(); + } + main_event(); + } + + return 0; +} + +static inline void main_init(void) +{ + mcu_init(); + sys_time_register_timer((1. / PERIODIC_FREQUENCY), NULL); +} + +static inline void main_periodic(void) +{ + const char *foo = "FooBarBaz"; + static int i = 0; + + if (i == strlen(foo)) { + i = 0; + } + + uart_transmit(&TEST_UART, foo[i]); + printf("%f, transmit: '%c'\n", get_sys_time_float(), foo[i]); + + if (uart_char_available(&TEST_UART)) { + char c = uart_getch(&TEST_UART); + printf("%f, received: '%c'\n", get_sys_time_float(), c); + } + + i++; +} + +static inline void main_event(void) +{ + uart_event(); +} diff --git a/sw/airborne/test/subsystems/test_ahrs.c b/sw/airborne/test/subsystems/test_ahrs.c index c86cc63e07..33b5ef2408 100644 --- a/sw/airborne/test/subsystems/test_ahrs.c +++ b/sw/airborne/test/subsystems/test_ahrs.c @@ -82,6 +82,8 @@ static inline void main_event_task(void) { #if USE_UDP udp_event(); +#else + uart_event(); #endif ImuEvent(on_gyro_event, on_accel_event, on_mag_event); } diff --git a/sw/airborne/test/subsystems/test_imu.c b/sw/airborne/test/subsystems/test_imu.c index 959be1da8c..e33557bdb6 100644 --- a/sw/airborne/test/subsystems/test_imu.c +++ b/sw/airborne/test/subsystems/test_imu.c @@ -118,6 +118,8 @@ static inline void main_event_task(void) { #if USE_UDP udp_event(); +#else + uart_event(); #endif ImuEvent(on_gyro_event, on_accel_event, on_mag_event); } diff --git a/sw/airborne/test/subsystems/test_radio_control.c b/sw/airborne/test/subsystems/test_radio_control.c index 90c162fd30..f791947088 100644 --- a/sw/airborne/test/subsystems/test_radio_control.c +++ b/sw/airborne/test/subsystems/test_radio_control.c @@ -88,6 +88,8 @@ static inline void main_event_task(void) { #if USE_UDP udp_event(); +#else + uart_event(); #endif RadioControlEvent(main_on_radio_control_frame); } diff --git a/sw/airborne/test/subsystems/test_settings.c b/sw/airborne/test/subsystems/test_settings.c index 477ce5ba50..b0434c54d1 100644 --- a/sw/airborne/test/subsystems/test_settings.c +++ b/sw/airborne/test/subsystems/test_settings.c @@ -90,6 +90,8 @@ static inline void main_event(void) { #if USE_UDP udp_event(); +#else + uart_event(); #endif DatalinkEvent(); } diff --git a/sw/airborne/test/test_telemetry.c b/sw/airborne/test/test_telemetry.c index e062afc481..282b903e13 100644 --- a/sw/airborne/test/test_telemetry.c +++ b/sw/airborne/test/test_telemetry.c @@ -67,5 +67,7 @@ static inline void main_event(void) { #if USE_UDP udp_event(); +#else + uart_event(); #endif }