xref: /qemu/include/hw/char/nrf51_uart.h (revision e3a6e0da)
1 /*
2  * nRF51 SoC UART emulation
3  *
4  * Copyright (c) 2018 Julia Suvorova <jusual@mail.ru>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 or
8  * (at your option) any later version.
9  */
10 
11 #ifndef NRF51_UART_H
12 #define NRF51_UART_H
13 
14 #include "hw/sysbus.h"
15 #include "chardev/char-fe.h"
16 #include "hw/registerfields.h"
17 #include "qom/object.h"
18 
19 #define UART_FIFO_LENGTH 6
20 #define UART_SIZE 0x1000
21 
22 #define TYPE_NRF51_UART "nrf51_soc.uart"
23 typedef struct NRF51UARTState NRF51UARTState;
24 DECLARE_INSTANCE_CHECKER(NRF51UARTState, NRF51_UART,
25                          TYPE_NRF51_UART)
26 
27 REG32(UART_STARTRX, 0x000)
28 REG32(UART_STOPRX, 0x004)
29 REG32(UART_STARTTX, 0x008)
30 REG32(UART_STOPTX, 0x00C)
31 REG32(UART_SUSPEND, 0x01C)
32 
33 REG32(UART_CTS, 0x100)
34 REG32(UART_NCTS, 0x104)
35 REG32(UART_RXDRDY, 0x108)
36 REG32(UART_TXDRDY, 0x11C)
37 REG32(UART_ERROR, 0x124)
38 REG32(UART_RXTO, 0x144)
39 
40 REG32(UART_INTEN, 0x300)
41     FIELD(UART_INTEN, CTS, 0, 1)
42     FIELD(UART_INTEN, NCTS, 1, 1)
43     FIELD(UART_INTEN, RXDRDY, 2, 1)
44     FIELD(UART_INTEN, TXDRDY, 7, 1)
45     FIELD(UART_INTEN, ERROR, 9, 1)
46     FIELD(UART_INTEN, RXTO, 17, 1)
47 REG32(UART_INTENSET, 0x304)
48 REG32(UART_INTENCLR, 0x308)
49 REG32(UART_ERRORSRC, 0x480)
50 REG32(UART_ENABLE, 0x500)
51 REG32(UART_PSELRTS, 0x508)
52 REG32(UART_PSELTXD, 0x50C)
53 REG32(UART_PSELCTS, 0x510)
54 REG32(UART_PSELRXD, 0x514)
55 REG32(UART_RXD, 0x518)
56 REG32(UART_TXD, 0x51C)
57 REG32(UART_BAUDRATE, 0x524)
58 REG32(UART_CONFIG, 0x56C)
59 
60 struct NRF51UARTState {
61     SysBusDevice parent_obj;
62 
63     MemoryRegion iomem;
64     CharBackend chr;
65     qemu_irq irq;
66     guint watch_tag;
67 
68     uint8_t rx_fifo[UART_FIFO_LENGTH];
69     unsigned int rx_fifo_pos;
70     unsigned int rx_fifo_len;
71 
72     uint32_t reg[0x56C];
73 
74     bool rx_started;
75     bool tx_started;
76     bool pending_tx_byte;
77     bool enabled;
78 };
79 
80 #endif
81