Opened 14 years ago
Closed 13 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: |
Description
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 by , 14 years ago
Milestone: | 0.5.0 → 0.5.1 |
---|
comment:2 by , 13 years ago
Milestone: | 0.5.0 → 0.5.1 |
---|
comment:3 by , 13 years ago
Milestone: | 0.5.1 → 0.5.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Fixed in mainline,1452.