🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.transputer
Article #2084

Re: C Query

#2084
From: 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
Technical Details
Message-ID: <1043.8806092145@latlog.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!latlog.UUCP!IAN

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!latlog.UUCP!IAN
From: IAN@latlog.UUCP
Newsgroups: comp.sys.transputer
Subject: Re: C Query
Message-ID: <1043.8806092145@latlog.co.uk>
Date: 9 Jun 88 23:45:34 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The Internet
Lines: 32