Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 #ifndef USB_TUNNEL_UART
42 #if USE_UART0
43 #define USB_TUNNEL_UART uart0
44 #else
45 #define USB_TUNNEL_UART uart1
46 #endif
47 #endif
48 
49 int main( void ) {
50  unsigned char inc;
51  unsigned int rx_time=0, tx_time=0;
52 
53  mcu_init();
54  sys_time_init();
55  led_init();
57 
58 #ifdef USE_USB_SERIAL
59  VCOM_init();
60 #endif
61 
63 
64 #if USE_LED_3
65  LED_ON(3);
66 #endif
67 
68  while(1) {
69 
70 #if USE_LED_1
71  if (T0TC > (rx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(1);
72 #endif
73 #if USE_LED_2
74  if (T0TC > (tx_time+((PCLK / T0_PCLK_DIV) / BLINK_MIN))) LED_OFF(2);
75 #endif
76 
78 #if USE_LED_1
79  LED_ON(1);
80 #endif
81  rx_time = T0TC;
83  VCOM_putchar(inc);
84  }
86 #if USE_LED_2
87  LED_ON(2);
88 #endif
89  tx_time = T0TC;
90  inc = VCOM_getchar();
92  }
93  }
94 
95  return 0;
96 }
97 
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:204
static uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart.h:87
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:75
#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:36
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:197
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:49
#define BLINK_MIN
Definition: usb_tunnel.c:39
arch independent USB API
#define USB_TUNNEL_UART
Definition: usb_tunnel.c:45