Ignore:
Timestamp:
2013-12-27T18:18:13Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f6f22cdb
Parents:
96b9724
Message:

code review
coding style changes, removal of debugging prints
simplify directory structure

File:
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/drivers/grlib/uart.c

    r96b9724 re47ed05  
    3737 */
    3838
    39 #include <genarch/drivers/grlib_uart/grlib_uart.h>
     39#include <genarch/drivers/grlib/uart.h>
    4040#include <console/chardev.h>
    4141#include <console/console.h>
     
    5050static void grlib_uart_sendb(outdev_t *dev, uint8_t byte)
    5151{
    52         uint32_t reg;
    5352        grlib_uart_status_t *status;
    54         grlib_uart_t *uart =
    55             (grlib_uart_t *) dev->data;
    56 
     53        grlib_uart_t *uart = (grlib_uart_t *) dev->data;
     54       
    5755        /* Wait for space becoming available in Tx FIFO. */
    5856        do {
    59                 reg = pio_read_32(&uart->io->status);
    60                 status = (grlib_uart_status_t *)&reg;
     57                uint32_t reg = pio_read_32(&uart->io->status);
     58                status = (grlib_uart_status_t *) &reg;
    6159        } while (status->tf != 0);
    62 
     60       
    6361        pio_write_32(&uart->io->data, byte);
    6462}
     
    6664static void grlib_uart_putchar(outdev_t *dev, wchar_t ch)
    6765{
    68         grlib_uart_t *uart =
    69             (grlib_uart_t *) dev->data;
     66        grlib_uart_t *uart = (grlib_uart_t *) dev->data;
    7067       
    7168        if ((!uart->parea.mapped) || (console_override)) {
     
    7572                        if (ch == '\n')
    7673                                grlib_uart_sendb(dev, (uint8_t) '\r');
     74                       
    7775                        grlib_uart_sendb(dev, (uint8_t) ch);
    7876                }
     
    8785static void grlib_uart_irq_handler(irq_t *irq)
    8886{
    89         uint32_t reg;
    9087        grlib_uart_t *uart = irq->instance;
    91         grlib_uart_status_t *status;
    92 
    93         reg = pio_read_32(&uart->io->status);
    94         status = (grlib_uart_status_t *)&reg;
    95 
     88       
     89        uint32_t reg = pio_read_32(&uart->io->status);
     90        grlib_uart_status_t *status = (grlib_uart_status_t *) &reg;
     91       
    9692        while (status->dr != 0) {
    9793                uint32_t data = pio_read_32(&uart->io->data);
    9894                reg = pio_read_32(&uart->io->status);
    99                 status = (grlib_uart_status_t *)&reg;
     95                status = (grlib_uart_status_t *) &reg;
    10096                indev_push_character(uart->indev, data & 0xff);
    10197        }
     
    109105outdev_t *grlib_uart_init(uintptr_t paddr, inr_t inr)
    110106{
    111         printf("grlib_uart_init: paddr=0x%08x\n", paddr);
    112 
    113107        outdev_t *uart_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
    114108        if (!uart_dev)
    115109                return NULL;
    116 
    117         grlib_uart_t *uart =
    118             malloc(sizeof(grlib_uart_t), FRAME_ATOMIC);
     110       
     111        grlib_uart_t *uart = malloc(sizeof(grlib_uart_t), FRAME_ATOMIC);
    119112        if (!uart) {
    120113                free(uart_dev);
    121114                return NULL;
    122115        }
    123 
     116       
    124117        outdev_initialize("grlib_uart_dev", uart_dev, &grlib_uart_ops);
    125118        uart_dev->data = uart;
    126 
     119       
    127120        uart->io = (grlib_uart_io_t *) km_map(paddr, PAGE_SIZE,
    128121            PAGE_WRITE | PAGE_NOT_CACHEABLE);
    129122        uart->indev = NULL;
    130 
     123       
    131124        /* Initialize IRQ structure. */
    132125        irq_initialize(&uart->irq);
     
    136129        uart->irq.handler = grlib_uart_irq_handler;
    137130        uart->irq.instance = uart;
    138 
     131       
    139132        /* Enable FIFO, Tx trigger level: empty, Rx trigger level: 1 byte. */
    140         grlib_uart_control_t control =
    141                 { .fa = 1, .rf = 1, .tf = 1, .ri = 1,
    142                   .te = 1, .re = 1};
    143 
    144         uint32_t *reg = (uint32_t *)&control;
     133        grlib_uart_control_t control = {
     134                .fa = 1,
     135                .rf = 1,
     136                .tf = 1,
     137                .ri = 1,
     138                .te = 1,
     139                .re = 1
     140        };
     141       
     142        uint32_t *reg = (uint32_t *) &control;
    145143        pio_write_32(&uart->io->control, *reg);
    146 
     144       
    147145        link_initialize(&uart->parea.link);
    148146        uart->parea.pbase = paddr;
     
    159157        ASSERT(uart);
    160158        ASSERT(indev);
    161 
     159       
    162160        uart->indev = indev;
    163161        irq_register(&uart->irq);
Note: See TracChangeset for help on using the changeset viewer.