Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
uart_tunnel.c
Go to the documentation of this file.
1 
2 #include "LPC21xx.h"
3 
4 #include "std.h"
5 
6 #include "mcu.h"
7 #include "led.h"
8 
9 #define TXD0_PIN 0
10 #define RXD0_PIN 1
11 #define TXD1_PIN 8
12 #define RXD1_PIN 9
13 
14 int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
15 {
16  int tx = 0, rx = 0;
17  int tx_shadow = 1, rx_shadow = 1;
18  mcu_init();
19  led_init();
20 #if USE_LED_1
21  LED_ON(1);
22 #endif
23 
24  /* TXD0 and TXD1 output */
25  SetBit(IO0DIR, TXD0_PIN);
26  SetBit(IO0DIR, TXD1_PIN);
27 
28  /* RXD0 and RXD1 input */
29  ClearBit(IO0DIR, RXD0_PIN);
30  ClearBit(IO0DIR, RXD1_PIN);
31 
32  /* use shadow bits to reduce jitter */
33  while (1) {
34  tx = bit_is_set(IO0PIN, RXD0_PIN);
35  if (tx != tx_shadow) {
36  if (tx) {
37  SetBit(IO0SET, TXD1_PIN);
38  } else {
39  SetBit(IO0CLR, TXD1_PIN);
40  }
41  tx_shadow = tx;
42 #if USE_LED_2
43  LED_TOGGLE(2);
44 #endif
45  }
46  rx = bit_is_set(IO0PIN, RXD1_PIN);
47  if (rx != rx_shadow) {
48  if (rx) {
49  SetBit(IO0SET, TXD0_PIN);
50  } else {
51  SetBit(IO0CLR, TXD0_PIN);
52  }
53  rx_shadow = rx;
54 #if USE_LED_3
55  LED_TOGGLE(3);
56 #endif
57  }
58  }
59  return 0;
60 }
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:76
#define TXD0_PIN
Definition: uart_tunnel.c:9
int main(int argc, char **argv)
Definition: uart_tunnel.c:14
#define TXD1_PIN
Definition: uart_tunnel.c:11
static void led_init(void)
Definition: led.h:36
#define RXD1_PIN
Definition: uart_tunnel.c:12
#define IO0CLR
Definition: LPC21xx.h:336
#define LED_TOGGLE(i)
Definition: led_hw.h:51
#define IO0SET
Definition: LPC21xx.h:334
#define IO0DIR
Definition: LPC21xx.h:335
Arch independent mcu ( Micro Controller Unit ) utilities.
#define RXD0_PIN
Definition: uart_tunnel.c:10
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:49
#define IO0PIN
Definition: LPC21xx.h:333