ls2: add support for the Nexys Video board
[ls2.git] / verilator / uart-verilator.h
1 // Copyright (C) IBM 2019, see LICENSE.CC4
2 // based on code from microwatt https://github.com/antonblanchard/microwatt
3
4 /*
5 * Our UART uses 16x oversampling, so at 50 MHz and 115200 baud
6 * each sample is: 50000000/(115200*16) = 27 clock cycles. This
7 * means each bit is off by 0.47% so for 8 bits plus a start and
8 * stop bit the errors add to be 4.7%.
9 */
10
11 enum state {
12 IDLE, START_BIT, BITS, STOP_BIT, ERROR
13 };
14
15 struct uart_tx_state {
16 double error = 0.05;
17
18 enum state tx_state = IDLE;
19 unsigned long tx_countbits;
20 unsigned char tx_bits;
21 unsigned char tx_byte;
22 unsigned char tx_prev;
23
24 enum state rx_state = IDLE;
25 unsigned char rx_char;
26 unsigned long rx_countbits;
27 unsigned char rx_bit;
28 unsigned char rx = 1;
29 };
30
31 void uart_tx(unsigned char tx);
32 unsigned char uart_rx(void);
33 struct uart_tx_state * uart_get_state(void);
34 void uart_restore(struct uart_tx_state *);
35