-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec_uart.com2
63 lines (54 loc) · 1.1 KB
/
ec_uart.com2
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
54
55
56
57
58
59
60
61
62
63
parameters {
wire tx;
integer baud;
integer bit_period = 1000000/baud;
integer stop_bits = 1;
}
variables {
byte data;
bit resend;
bit parity;
}
states {
IDLE: (tx){
tx --> 1;
}
START: (bit_period us){
tx --> 0;
}
for $s from 0 to 1 {
for $i from 0 to 3 {
BIT_$s_$i: (bit_period us){
tx ==> data[4 * $s + $i];
}
}
(bit_period us) {
parity = data[4 * $s] ^ data[4 * $s + 1] ^ data[4 * $s + 2] ^ data[4 * $s + 3];
tx ==> parity;
}
(bit_period us) {
resend = parity != (data[4 * $s] ^ data[4 * $s + 1] ^ data[4 * $s + 2] ^ data[4 * $s + 3]);
resend <== tx;
}[resend => BIT_$s_0]
}
STOP: (bit_period * stop_bits us){
tx --> 1;
}[=> IDLE]
}
shared {
fn com2_ec_uart_setup() {
...IDLE;
}
}
left {
fn com2_ec_uart_send(output byte x) {
data = x;
START...IDLE;
}
}
right {
fn com2_ec_uart_recv(input byte x) {
IDLE...IDLE;
x = data;
}
}