Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
usb_tunnel.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Martin Mueller
3  * 2014 Felix Ruess <felix.ruess@gmail.com>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  */
23 
33 #include "std.h"
34 #include "mcu.h"
35 #include "mcu_periph/sys_time.h"
36 #include "led.h"
37 #include "mcu_periph/uart.h"
38 #include "mcu_periph/usb_serial.h"
39 
40 #ifndef USB_TUNNEL_UART
41 #error USB_TUNNEL_UART not defined. Add <configure name="TUNNEL_PORT" value="UARTx"/>
42 #endif
43 
44 PRINT_CONFIG_VAR(USB_TUNNEL_UART)
45 
46 PRINT_CONFIG_VAR(TUNNEL_RX_LED)
47 PRINT_CONFIG_VAR(TUNNEL_TX_LED)
48 
50 #define BLINK_MIN 100
51 
52 static inline void tunnel_event(void)
53 {
54  unsigned char inc;
55 
56 #if LED_AVAILABLE(TUNNEL_RX_LED)
57  static uint32_t rx_time = 0;
58  if (get_sys_time_msec() > rx_time + BLINK_MIN) {
59  LED_OFF(TUNNEL_RX_LED);
60  }
61 #endif
62 #if LED_AVAILABLE(TUNNEL_TX_LED)
63  static uint32_t tx_time = 0;
64  if (get_sys_time_msec() > tx_time + BLINK_MIN) {
65  LED_OFF(TUNNEL_TX_LED);
66  }
67 #endif
68 
69  if (uart_char_available(&USB_TUNNEL_UART) && VCOM_check_free_space(1)) {
70 #if LED_AVAILABLE(TUNNEL_RX_LED)
71  LED_ON(TUNNEL_RX_LED);
72  rx_time = get_sys_time_msec();
73 #endif
74  inc = uart_getch(&USB_TUNNEL_UART);
75  VCOM_putchar(inc);
76  }
77  if (VCOM_check_available() && uart_check_free_space(&USB_TUNNEL_UART, 1)) {
78 #if LED_AVAILABLE(TUNNEL_TX_LED)
79  LED_ON(TUNNEL_TX_LED);
80  tx_time = get_sys_time_msec();
81 #endif
82  inc = VCOM_getchar();
83  uart_put_byte(&USB_TUNNEL_UART, inc);
84  }
85 }
86 
87 int main(void)
88 {
89  mcu_init();
90  sys_time_init();
91  led_init();
92 
94 
95  VCOM_init();
96 
98 
99  while (1) {
100  VCOM_event();
101  tunnel_event();
102  }
103 
104  return 0;
105 }
static uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
Definition: sys_time_arch.h:49
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:71
void VCOM_event(void)
Definition: usb_ser_hw.c:563
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:296
Architecture independent timing functions.
int VCOM_getchar(void)
Reads one character from VCOM port.
Definition: usb_ser_hw.c:386
unsigned long uint32_t
Definition: types.h:18
static void led_init(void)
Definition: led.h:36
static void tunnel_event(void)
Definition: usb_tunnel.c:52
void sys_time_init(void)
Definition: sys_time.c:73
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:256
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:287
#define LED_ON(i)
Definition: led_hw.h:42
Arch independent mcu ( Micro Controller Unit ) utilities.
#define mcu_int_enable()
Definition: mcu_arch.h:35
arch independent LED (Light Emitting Diodes) API
int VCOM_putchar(int c)
Writes one character to VCOM port.
Definition: usb_ser_hw.c:376
bool_t VCOM_check_free_space(uint8_t len)
Checks if buffer free in VCOM buffer.
Definition: usb_ser_hw.c:409
#define LED_OFF(i)
Definition: led_hw.h:43
void VCOM_allow_linecoding(uint8_t mode)
int main(void)
Definition: usb_tunnel.c:87
int VCOM_check_available(void)
Checks if data available in VCOM buffer.
Definition: usb_ser_hw.c:420
void uart_put_byte(struct uart_periph *periph, uint8_t data)
Definition: uart_arch.c:243
void VCOM_init(void)
Definition: usb_ser_hw.c:578
#define BLINK_MIN
minimum LED blink on time in ms
Definition: usb_tunnel.c:50
arch independent USB API