Fork us on GitHub Follow us on Facebook Follow us on Twitter

Opened 10 years ago

Closed 9 years ago

#262 closed enhancement (fixed)

The ns8250 driver uses too many magic numbers

Reported by: Jakub Jermář Owned by:
Priority: minor Milestone: 0.5.0
Component: helenos/drv/ns8250 Version:
Keywords: Cc:
Blocker for: Depends on:
See also:


The new ns8250 serial driver uses magic numbers when accessing I/O ports, such as in:

pio_write_8(port + 1, 0x1);     /* Interrupt when data received. */
pio_write_8(port + 4, 0xB);

It would be better to do something similar as e.g. we do in the kernel ns16550 driver. We define a structure which describes the registers of the device:

/** NS16550 registers. */
typedef struct {
        ioport8_t rbr;      /**< Receiver Buffer Register. */
        ioport8_t ier;      /**< Interrupt Enable Register. */
        union {
                ioport8_t iir;  /**< Interrupt Ident Register (read). */
                ioport8_t fcr;  /**< FIFO control register (write). */
        } __attribute__ ((packed));
        ioport8_t lcr;      /**< Line Control register. */
        ioport8_t mcr;      /**< Modem Control Register. */
        ioport8_t lsr;      /**< Line Status Register. */
} __attribute__ ((packed)) ns16550_t;

and then comfortably access it like this:

if (pio_read_8(&dev->lsr) & LSR_DATA_READY) {
        uint8_t data = pio_read_8(&dev->rbr);

Of course, the constants should be replaced with symbolic constants as well.

Change History (3)

comment:1 Changed 10 years ago by Jakub Jermář


comment:2 Changed 9 years ago by Jakub Jermář


comment:3 Changed 9 years ago by Jakub Jermář

Resolution: fixed
Status: newclosed

Fixed in mainline,1452.

Note: See TracTickets for help on using tickets.