-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathuart_echo.si
More file actions
55 lines (45 loc) · 1.22 KB
/
uart_echo.si
File metadata and controls
55 lines (45 loc) · 1.22 KB
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
// @sylefeb, 2020-10-08, UART example
// MIT license, see LICENSE_MIT in Silice repo root
// https://github.com/sylefeb/Silice
$include('../common/uart.si')
// UART echo
algorithm main(
output uint$NUM_LEDS$ leds,
output uint1 uart_tx,
input uint1 uart_rx,
$$if BROT then
output uint1 sd_csn(0), /// NOTE: special for musbx
output uint1 sd_clk(0),
output uint1 sd_mosi(0),
input uint1 sd_miso,
$$end
) {
uint1 send_asap = 0;
uart_out uo;
uart_sender usend(
io <:> uo,
uart_tx :> uart_tx
);
uart_in ui;
uart_receiver urecv(
io <:> ui,
uart_rx <: uart_rx
);
uo.data_in_ready := 0; // maintain low
leds := 1; // light one LED
// NOTE: We only have to be carefull to wait for a previous
// transmission to be done before starting a new one.
// There is no real need for buffering since receive/transmit have
// the same overall speed.
while (1) {
if (send_asap) {
// send echo
uo.data_in = ui.data_out; // uart_sender copies the data on start
uo.data_in_ready = ~uo.busy; // so we can change it at any time
send_asap = uo.busy;
} else {
// wait for data
send_asap = ui.data_out_ready;
}
}
}