diff --git a/conf/boards/tiny_1.1.makefile b/conf/boards/tiny_1.1.makefile index 2f49f838b7..31ac33fb95 100644 --- a/conf/boards/tiny_1.1.makefile +++ b/conf/boards/tiny_1.1.makefile @@ -27,6 +27,9 @@ AHRS_ALIGNER_LED ?= none GPS_LED ?= none SYS_TIME_LED ?= none +TUNNEL_RX_LED ?= 1 +TUNNEL_TX_LED ?= 2 + # # default uart settings diff --git a/conf/firmwares/setup.makefile b/conf/firmwares/setup.makefile index 027bc77855..cfe5d2669b 100644 --- a/conf/firmwares/setup.makefile +++ b/conf/firmwares/setup.makefile @@ -73,7 +73,16 @@ TUNNEL_BAUD ?= B115200 usb_tunnel.CFLAGS += -DUSE_$(TUNNEL_PORT_UPPER) -D$(TUNNEL_PORT_UPPER)_BAUD=$(TUNNEL_BAUD) usb_tunnel.CFLAGS += -DUSB_TUNNEL_UART=$(TUNNEL_PORT_LOWER) usb_tunnel.CFLAGS += -DUSE_USB_LINE_CODING -DUSE_USB_SERIAL -usb_tunnel.srcs += $(SRC_ARCH)/usb_tunnel.c $(SRC_ARCH)/usb_ser_hw.c +usb_tunnel.srcs += $(SRC_FIRMWARE)/usb_tunnel.c $(SRC_ARCH)/usb_ser_hw.c + +TUNNEL_RX_LED ?= 2 +TUNNEL_TX_LED ?= 3 +ifneq ($(TUNNEL_TX_LED),none) + usb_tunnel.CFLAGS += -DTUNNEL_TX_LED=$(TUNNEL_TX_LED) +endif +ifneq ($(TUNNEL_RX_LED),none) + usb_tunnel.CFLAGS += -DTUNNEL_RX_LED=$(TUNNEL_RX_LED) +endif ifeq ($(ARCH), lpc21) # for the usb_tunnel we need to set PCLK higher with the flag USE_USB_HIGH_PCLK diff --git a/sw/airborne/arch/lpc21/usb_tunnel.c b/sw/airborne/arch/lpc21/usb_tunnel.c deleted file mode 100644 index beb35901fe..0000000000 --- a/sw/airborne/arch/lpc21/usb_tunnel.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2009 Martin Mueller - * - * 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. - * - */ - -/** \file usb_tunnel.c - * \brief USB tunnel application - * - * This creates a USB serial port that connects to UART0 or UART1 - * port of the LPC processor. This enables you to configure the gps - * receiver or the modem without removing it. - */ - -#include "std.h" -#include "mcu.h" -#include "mcu_periph/sys_time.h" -#include "led.h" -#include "mcu_periph/uart.h" -#include "mcu_periph/usb_serial.h" - -/* minimum LED blink on time 10Hz = 100ms */ -#define BLINK_MIN 10 - -#ifndef USB_TUNNEL_UART -#if USE_UART0 -#define USB_TUNNEL_UART uart0 -#else -#define USB_TUNNEL_UART uart1 -#endif -#endif - -INFO_VAR(USB_TUNNEL_UART) - -int main( void ) { - unsigned char inc; - unsigned int rx_time=0, tx_time=0; - - mcu_init(); - sys_time_init(); - led_init(); - VCOM_allow_linecoding(1); - - VCOM_init(); - - mcu_int_enable(); - -#if USE_LED_3 - LED_ON(3); -#endif - - while(1) { - -#if USE_LED_1 - if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1); -#endif -#if USE_LED_2 - if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2); -#endif - - if (uart_char_available(&USB_TUNNEL_UART) && VCOM_check_free_space(1)) { -#if USE_LED_1 - LED_ON(1); -#endif - rx_time = T0TC; - inc = uart_getch(&USB_TUNNEL_UART); - VCOM_putchar(inc); - } - if (VCOM_check_available() && uart_check_free_space(&USB_TUNNEL_UART, 1)) { -#if USE_LED_2 - LED_ON(2); -#endif - tx_time = T0TC; - inc = VCOM_getchar(); - uart_transmit(&USB_TUNNEL_UART, inc); - } - } - - return 0; -} - diff --git a/sw/airborne/arch/stm32/usb_tunnel.c b/sw/airborne/firmwares/setup/usb_tunnel.c similarity index 71% rename from sw/airborne/arch/stm32/usb_tunnel.c rename to sw/airborne/firmwares/setup/usb_tunnel.c index 391932b1ad..cab7d8daeb 100644 --- a/sw/airborne/arch/stm32/usb_tunnel.c +++ b/sw/airborne/firmwares/setup/usb_tunnel.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2009 Martin Mueller - * 2014 Felix Ruess * * This file is part of paparazzi. * @@ -41,23 +41,43 @@ #error USB_TUNNEL_UART not defined. Add #endif -INFO_VAR(USB_TUNNEL_UART) +PRINT_CONFIG_VAR(USB_TUNNEL_UART) +PRINT_CONFIG_VAR(TUNNEL_RX_LED) +PRINT_CONFIG_VAR(TUNNEL_TX_LED) -static void tunnel_event(void) +/** minimum LED blink on time in ms */ +#define BLINK_MIN 100 + +static inline void tunnel_event(void) { - static unsigned char inc; + unsigned char inc; + +#ifdef TUNNEL_RX_LED + static uint32_t rx_time=0; + if (get_sys_time_msec() > rx_time + BLINK_MIN) { + LED_OFF(TUNNEL_RX_LED); + } +#endif +#ifdef TUNNEL_TX_LED + static uint32_t tx_time=0; + if (get_sys_time_msec() > tx_time + BLINK_MIN) { + LED_OFF(TUNNEL_TX_LED); + } +#endif if (uart_char_available(&USB_TUNNEL_UART) && VCOM_check_free_space(1)) { -#if USE_LED_2 - LED_TOGGLE(2); +#ifdef TUNNEL_RX_LED + LED_ON(TUNNEL_RX_LED); + rx_time = get_sys_time_msec(); #endif inc = uart_getch(&USB_TUNNEL_UART); VCOM_putchar(inc); } if (VCOM_check_available() && uart_check_free_space(&USB_TUNNEL_UART, 1)) { -#if USE_LED_3 - LED_TOGGLE(3); +#ifdef TUNNEL_TX_LED + LED_ON(TUNNEL_TX_LED); + tx_time = get_sys_time_msec(); #endif inc = VCOM_getchar(); uart_transmit(&USB_TUNNEL_UART, inc);