Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
usb_tunnel.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2009 Martin Mueller
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
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 /* minimum LED blink on time 10Hz = 100ms */
41 #define BLINK_MIN 10
42 
43 int main( void ) {
44  unsigned char inc;
45  unsigned int rx_time=0, tx_time=0;
46 
47  mcu_init();
48  sys_time_init();
49  led_init();
51 
52 #ifdef USE_USB_SERIAL
53  VCOM_init();
54 #endif
55 
57 
58  LED_ON(3);
59 
60 #ifdef USE_UART0
61  while(1) {
62  if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1);
63  if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2);
64  if (Uart0ChAvailable() && VCOM_check_free_space(1)) {
65  LED_ON(1);
66  rx_time = T0TC;
67  inc = Uart0Getch();
68  VCOM_putchar(inc);
69  }
70  if (VCOM_check_available() && Uart0CheckFreeSpace(1)) {
71  LED_ON(2);
72  tx_time = T0TC;
73  inc = VCOM_getchar();
74  Uart0Transmit(inc);
75  }
76  }
77 #else
78  while(1) {
79  if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1);
80  if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2);
81  if (Uart1ChAvailable() && VCOM_check_free_space(1)) {
82  LED_ON(1);
83  rx_time = T0TC;
84  inc = Uart1Getch();
85  VCOM_putchar(inc);
86  }
87  if (VCOM_check_available() && Uart1CheckFreeSpace(1)) {
88  LED_ON(2);
89  tx_time = T0TC;
90  inc = VCOM_getchar();
91  Uart1Transmit(inc);
92  }
93  }
94 #endif
95 
96  return 0;
97 }
98 
bool_t VCOM_check_free_space(uint8_t len)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
int VCOM_check_available(void)
#define PCLK
Definition: booz_1.0.h:18
#define LED_ON(i)
Definition: led_hw.h:28
#define mcu_int_enable()
Definition: mcu_arch.h:32
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:86
void sys_time_init(void)
Definition: sys_time.c:69
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:43
void mcu_init(void)
Definition: mcu.c:57
#define BLINK_MIN
Definition: usb_tunnel.c:41
arch independent USB API