HelenOS sources
This source file includes following definitions.
- omap_uart_txb
- omap_uart_putuchar
- omap_uart_claim
- omap_uart_handler
- omap_uart_init
- omap_uart_input_wire
#include <assert.h>
#include <genarch/drivers/omap/uart.h>
#include <str.h>
#include <mm/km.h>
static void omap_uart_txb(omap_uart_t *uart, uint8_t b)
{
while (uart->regs->ssr & OMAP_UART_SSR_TX_FIFO_FULL_FLAG)
;
uart->regs->thr = b;
}
static void omap_uart_putuchar(outdev_t *dev, char32_t ch)
{
omap_uart_t *uart = dev->data;
if (!ascii_check(ch)) {
omap_uart_txb(uart, U_SPECIAL);
} else {
if (ch == '\n')
omap_uart_txb(uart, '\r');
omap_uart_txb(uart, ch);
}
}
static outdev_operations_t omap_uart_ops = {
.write = omap_uart_putuchar,
.redraw = NULL,
.scroll_up = NULL,
.scroll_down = NULL
};
static irq_ownership_t omap_uart_claim(irq_t *irq)
{
return IRQ_ACCEPT;
}
static void omap_uart_handler(irq_t *irq)
{
omap_uart_t *uart = irq->instance;
while ((uart->regs->rx_fifo_lvl)) {
const uint8_t val = uart->regs->rhr;
if (uart->indev && val) {
indev_push_character(uart->indev, val);
}
}
}
bool omap_uart_init(
omap_uart_t *uart, inr_t interrupt, uintptr_t addr, size_t size)
{
assert(uart);
uart->regs = (void *)km_map(addr, size, KM_NATURAL_ALIGNMENT,
PAGE_NOT_CACHEABLE);
assert(uart->regs);
uart->regs->sysc = OMAP_UART_SYSC_SOFTRESET_FLAG;
while (!(uart->regs->syss & OMAP_UART_SYSS_RESETDONE_FLAG))
;
uart->regs->mdr1 |= OMAP_UART_MDR_MS_DISABLE;
uart->regs->lcr = 0xbf;
const bool enhanced = uart->regs->efr & OMAP_UART_EFR_ENH_FLAG;
uart->regs->efr |= OMAP_UART_EFR_ENH_FLAG;
uart->regs->lcr = 0x80;
const bool tcl_tlr = uart->regs->mcr & OMAP_UART_MCR_TCR_TLR_FLAG;
uart->regs->mcr |= OMAP_UART_MCR_TCR_TLR_FLAG;
uart->regs->fcr = OMAP_UART_FCR_FIFO_EN_FLAG;
uart->regs->lcr = 0xBF;
uart->regs->scr = OMAP_UART_SCR_RX_TRIG_GRANU1_FLAG;
uart->regs->tlr = 1 << OMAP_UART_TLR_RX_FIFO_TRIG_SHIFT;
uart->regs->lcr = 0x80;
if (!tcl_tlr)
uart->regs->mcr &= ~OMAP_UART_MCR_TCR_TLR_FLAG;
uart->regs->lcr = 0xBF;
uart->regs->dll = 0x1A;
uart->regs->dlh = 0x00;
if (!enhanced)
uart->regs->efr &= ~OMAP_UART_EFR_ENH_FLAG;
uart->regs->lcr &= ~OMAP_UART_LCR_DIV_EN_FLAG;
uart->regs->lcr &= ~OMAP_UART_LCR_BREAK_EN_FLAG;
uart->regs->lcr &= ~OMAP_UART_LCR_PARITY_EN_FLAG;
uart->regs->lcr &= ~OMAP_UART_LCR_NB_STOP_FLAG;
uart->regs->lcr |= OMAP_UART_LCR_CHAR_LENGTH_8BITS;
uart->regs->mdr1 &= (OMAP_UART_MDR_MS_UART16 &
~OMAP_UART_MDR_MS_MASK);
uart->regs->ier = 0;
outdev_initialize("omap_uart_dev", &uart->outdev, &omap_uart_ops);
uart->outdev.data = uart;
irq_initialize(&uart->irq);
uart->irq.inr = interrupt;
uart->irq.claim = omap_uart_claim;
uart->irq.handler = omap_uart_handler;
uart->irq.instance = uart;
return true;
}
void omap_uart_input_wire(omap_uart_t *uart, indev_t *indev)
{
assert(uart);
uart->indev = indev;
irq_register(&uart->irq);
uart->regs->ier |= OMAP_UART_IER_RHR_IRQ_FLAG;
}
HelenOS homepage, sources at GitHub