IAN@latlog.UUCP (06/10/88)
Re: Ben Abbott's query about special hardware and C.
The easiest way to access memory-mapped device registers in C is
to declare a structure type with appropriate fields:
struct uart_regs {
int control;
int status;
int data_in;
int data_out;
};
Now we can create pointers into memory which is being used by
such devices:
struct uart_regs *first_uart = 0x80200000,
*secnd_uart = 0x80201000;
(For purists, the 0x...s should be cast into the appropriate
type) Finally, you can make use of the device registers as
follows:
while (first_uart->status & NO_CHAR_READY) do_nothing();
in_char = first_uart->data_in;
Less symbolically, you could just use an integer pointer like:
int *first_uart = 0x80200000;
Then, the device registers are just first_uart[0], first_uart[1]
and so on. Hope this helps,
-- Ian Young, 3L Ltd