/
uart_tunnel.c
53 lines (45 loc) · 969 Bytes
/
uart_tunnel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "LPC21xx.h"
#include "std.h"
#include "mcu.h"
#include "led.h"
#define TXD0_PIN 0
#define RXD0_PIN 1
#define TXD1_PIN 8
#define RXD1_PIN 9
int main (int argc, char** argv) {
int tx=0, rx=0;
int tx_shadow=1, rx_shadow=1;
mcu_init();
led_init();
LED_ON(1);
/* TXD0 and TXD1 output */
SetBit(IO0DIR, TXD0_PIN);
SetBit(IO0DIR, TXD1_PIN);
/* RXD0 and RXD1 input */
ClearBit(IO0DIR,RXD0_PIN);
ClearBit(IO0DIR,RXD1_PIN);
/* use shadow bits to reduce jitter */
while(1) {
tx = bit_is_set(IO0PIN, RXD0_PIN);
if (tx != tx_shadow) {
if (tx) {
SetBit(IO0SET, TXD1_PIN);
} else {
SetBit(IO0CLR, TXD1_PIN);
}
tx_shadow = tx;
LED_TOGGLE(2);
}
rx = bit_is_set(IO0PIN, RXD1_PIN);
if (rx != rx_shadow) {
if (rx) {
SetBit(IO0SET, TXD0_PIN);
} else {
SetBit(IO0CLR, TXD0_PIN);
}
rx_shadow = rx;
LED_TOGGLE(3);
}
}
return 0;
}