🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.transputer
1 messages
1 total messages Started by IAN Thu, 09 Jun 1988 23:45
Re: C Query
#2084
Author: IAN
Date: Thu, 09 Jun 1988 23:45
33 lines
1187 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads