119790847SJulia Suvorova /* 219790847SJulia Suvorova * nRF51 SoC UART emulation 319790847SJulia Suvorova * 419790847SJulia Suvorova * Copyright (c) 2018 Julia Suvorova <jusual@mail.ru> 519790847SJulia Suvorova * 619790847SJulia Suvorova * This program is free software; you can redistribute it and/or modify 719790847SJulia Suvorova * it under the terms of the GNU General Public License version 2 or 819790847SJulia Suvorova * (at your option) any later version. 919790847SJulia Suvorova */ 1019790847SJulia Suvorova 1119790847SJulia Suvorova #ifndef NRF51_UART_H 1219790847SJulia Suvorova #define NRF51_UART_H 1319790847SJulia Suvorova 1419790847SJulia Suvorova #include "hw/sysbus.h" 1519790847SJulia Suvorova #include "chardev/char-fe.h" 1619790847SJulia Suvorova #include "hw/registerfields.h" 17db1015e9SEduardo Habkost #include "qom/object.h" 1819790847SJulia Suvorova 1919790847SJulia Suvorova #define UART_FIFO_LENGTH 6 2019790847SJulia Suvorova #define UART_SIZE 0x1000 2119790847SJulia Suvorova 2219790847SJulia Suvorova #define TYPE_NRF51_UART "nrf51_soc.uart" 23*8063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(NRF51UARTState, NRF51_UART) 2419790847SJulia Suvorova 2519790847SJulia Suvorova REG32(UART_STARTRX, 0x000) 2619790847SJulia Suvorova REG32(UART_STOPRX, 0x004) 2719790847SJulia Suvorova REG32(UART_STARTTX, 0x008) 2819790847SJulia Suvorova REG32(UART_STOPTX, 0x00C) 2919790847SJulia Suvorova REG32(UART_SUSPEND, 0x01C) 3019790847SJulia Suvorova 3119790847SJulia Suvorova REG32(UART_CTS, 0x100) 3219790847SJulia Suvorova REG32(UART_NCTS, 0x104) 3319790847SJulia Suvorova REG32(UART_RXDRDY, 0x108) 3419790847SJulia Suvorova REG32(UART_TXDRDY, 0x11C) 3519790847SJulia Suvorova REG32(UART_ERROR, 0x124) 3619790847SJulia Suvorova REG32(UART_RXTO, 0x144) 3719790847SJulia Suvorova 3819790847SJulia Suvorova REG32(UART_INTEN, 0x300) 3919790847SJulia Suvorova FIELD(UART_INTEN, CTS, 0, 1) 4019790847SJulia Suvorova FIELD(UART_INTEN, NCTS, 1, 1) 4119790847SJulia Suvorova FIELD(UART_INTEN, RXDRDY, 2, 1) 4219790847SJulia Suvorova FIELD(UART_INTEN, TXDRDY, 7, 1) 4319790847SJulia Suvorova FIELD(UART_INTEN, ERROR, 9, 1) 4419790847SJulia Suvorova FIELD(UART_INTEN, RXTO, 17, 1) 4519790847SJulia Suvorova REG32(UART_INTENSET, 0x304) 4619790847SJulia Suvorova REG32(UART_INTENCLR, 0x308) 4719790847SJulia Suvorova REG32(UART_ERRORSRC, 0x480) 4819790847SJulia Suvorova REG32(UART_ENABLE, 0x500) 4919790847SJulia Suvorova REG32(UART_PSELRTS, 0x508) 5019790847SJulia Suvorova REG32(UART_PSELTXD, 0x50C) 5119790847SJulia Suvorova REG32(UART_PSELCTS, 0x510) 5219790847SJulia Suvorova REG32(UART_PSELRXD, 0x514) 5319790847SJulia Suvorova REG32(UART_RXD, 0x518) 5419790847SJulia Suvorova REG32(UART_TXD, 0x51C) 5519790847SJulia Suvorova REG32(UART_BAUDRATE, 0x524) 5619790847SJulia Suvorova REG32(UART_CONFIG, 0x56C) 5719790847SJulia Suvorova 58db1015e9SEduardo Habkost struct NRF51UARTState { 5919790847SJulia Suvorova SysBusDevice parent_obj; 6019790847SJulia Suvorova 6119790847SJulia Suvorova MemoryRegion iomem; 6219790847SJulia Suvorova CharBackend chr; 6319790847SJulia Suvorova qemu_irq irq; 6419790847SJulia Suvorova guint watch_tag; 6519790847SJulia Suvorova 6619790847SJulia Suvorova uint8_t rx_fifo[UART_FIFO_LENGTH]; 6719790847SJulia Suvorova unsigned int rx_fifo_pos; 6819790847SJulia Suvorova unsigned int rx_fifo_len; 6919790847SJulia Suvorova 7019790847SJulia Suvorova uint32_t reg[0x56C]; 7119790847SJulia Suvorova 7219790847SJulia Suvorova bool rx_started; 7319790847SJulia Suvorova bool tx_started; 7419790847SJulia Suvorova bool pending_tx_byte; 7519790847SJulia Suvorova bool enabled; 76db1015e9SEduardo Habkost }; 7719790847SJulia Suvorova 7819790847SJulia Suvorova #endif 79