Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 }
led_init
static void led_init(void)
Automatic initialization of actived LED Set to OFF at startup.
Definition: led.h:39
LPC21xx.h
TXD0_PIN
#define TXD0_PIN
Definition: uart_tunnel.c:9
main
int main(int argc, char **argv)
Definition: uart_tunnel.c:14
LED_ON
#define LED_ON(i)
Definition: led_hw.h:51
LED_TOGGLE
#define LED_TOGGLE(i)
Definition: led_hw.h:53
TXD1_PIN
#define TXD1_PIN
Definition: uart_tunnel.c:11
std.h
RXD1_PIN
#define RXD1_PIN
Definition: uart_tunnel.c:12
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
led.h
arch independent LED (Light Emitting Diodes) API
IO0DIR
#define IO0DIR
Definition: LPC21xx.h:335
RXD0_PIN
#define RXD0_PIN
Definition: uart_tunnel.c:10
IO0CLR
#define IO0CLR
Definition: LPC21xx.h:336
IO0SET
#define IO0SET
Definition: LPC21xx.h:334
IO0PIN
#define IO0PIN
Definition: LPC21xx.h:333
mcu_init
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:87