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
usb_tunnel.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Martin Mueller
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
31 #include "std.h"
32 #include "mcu.h"
33 #include "mcu_periph/sys_time.h"
34 #include "led.h"
35 #include "mcu_periph/uart.h"
36 #include "mcu_periph/usb_serial.h"
37 
38 /* minimum LED blink on time 10Hz = 100ms */
39 #define BLINK_MIN 10
40 
41 int main( void ) {
42  unsigned char inc;
43  unsigned int rx_time=0, tx_time=0;
44 
45  mcu_init();
46  sys_time_init();
47  led_init();
49 
50 #ifdef USE_USB_SERIAL
51  VCOM_init();
52 #endif
53 
55 
56  LED_ON(3);
57 
58 #ifdef USE_UART0
59  while(1) {
60  if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1);
61  if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2);
62  if (uart_char_available(&uart0) && VCOM_check_free_space(1)) {
63  LED_ON(1);
64  rx_time = T0TC;
65  inc = uart_getch(&uart0);
66  VCOM_putchar(inc);
67  }
68  if (VCOM_check_available() && uart_check_free_space(&uart0, 1)) {
69  LED_ON(2);
70  tx_time = T0TC;
71  inc = VCOM_getchar();
72  uart_transmit(&uart0, inc);
73  }
74  }
75 #else
76  while(1) {
77  if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1);
78  if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2);
79  if (uart_char_available(&uart1) && VCOM_check_free_space(1)) {
80  LED_ON(1);
81  rx_time = T0TC;
82  inc = uart_getch(&uart1);
83  VCOM_putchar(inc);
84  }
85  if (VCOM_check_available() && uart_check_free_space(&uart1, 1)) {
86  LED_ON(2);
87  tx_time = T0TC;
88  inc = VCOM_getchar();
89  uart_transmit(&uart1, inc);
90  }
91  }
92 #endif
93 
94  return 0;
95 }
96 
bool_t VCOM_check_free_space(uint8_t len)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
uint8_t uart_getch(struct uart_periph *p)
Definition: uart.c:71
static bool_t uart_char_available(struct uart_periph *p)
Definition: uart.h:83
int VCOM_check_available(void)
#define PCLK
Definition: booz_1.0.h:18
#define LED_ON(i)
Definition: led_hw.h:28
void uart_transmit(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:71
#define mcu_int_enable()
Definition: mcu_arch.h:37
Architecture independent timing functions.
int VCOM_putchar(int c)
void VCOM_init(void)
#define T0TC
Definition: LPC21xx.h:52
static void led_init(void)
Definition: led.h:89
void sys_time_init(void)
Definition: sys_time.c:70
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:64
Arch independent mcu ( Micro Controller Unit ) utilities.
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
int VCOM_getchar(void)
void VCOM_allow_linecoding(uint8_t mode)
int main(void)
Definition: usb_tunnel.c:41
#define BLINK_MIN
Definition: usb_tunnel.c:39
arch independent USB API