Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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, char** argv) {
15  int tx=0, rx=0;
16  int tx_shadow=1, rx_shadow=1;
17  mcu_init();
18  led_init();
19 #if USE_LED_1
20  LED_ON(1);
21 #endif
22 
23  /* TXD0 and TXD1 output */
24  SetBit(IO0DIR, TXD0_PIN);
25  SetBit(IO0DIR, TXD1_PIN);
26 
27  /* RXD0 and RXD1 input */
28  ClearBit(IO0DIR,RXD0_PIN);
29  ClearBit(IO0DIR,RXD1_PIN);
30 
31  /* use shadow bits to reduce jitter */
32  while(1) {
33  tx = bit_is_set(IO0PIN, RXD0_PIN);
34  if (tx != tx_shadow) {
35  if (tx) {
36  SetBit(IO0SET, TXD1_PIN);
37  } else {
38  SetBit(IO0CLR, TXD1_PIN);
39  }
40  tx_shadow = tx;
41 #if USE_LED_2
42  LED_TOGGLE(2);
43 #endif
44  }
45  rx = bit_is_set(IO0PIN, RXD1_PIN);
46  if (rx != rx_shadow) {
47  if (rx) {
48  SetBit(IO0SET, TXD0_PIN);
49  } else {
50  SetBit(IO0CLR, TXD0_PIN);
51  }
52  rx_shadow = rx;
53 #if USE_LED_3
54  LED_TOGGLE(3);
55 #endif
56  }
57  }
58  return 0;
59 }
#define LED_ON(i)
Definition: led_hw.h:28
#define RXD1_PIN
Definition: uart_tunnel.c:12
#define TXD0_PIN
Definition: uart_tunnel.c:9
int main(int argc, char **argv)
Definition: uart_tunnel.c:14
static void led_init(void)
Definition: led.h:86
#define IO0CLR
Definition: LPC21xx.h:304
#define LED_TOGGLE(i)
Definition: led_hw.h:30
#define IO0SET
Definition: LPC21xx.h:302
#define IO0DIR
Definition: LPC21xx.h:303
#define TXD1_PIN
Definition: uart_tunnel.c:11
arch independent mcu ( Micro Controller Unit ) utilities
arch independent LED (Light Emitting Diodes) API
#define RXD0_PIN
Definition: uart_tunnel.c:10
void mcu_init(void)
Definition: mcu.c:57
#define IO0PIN
Definition: LPC21xx.h:301