* [ECOS] Memory mapped IO
@ 2005-07-20 17:02 Enrico Piria
0 siblings, 0 replies; only message in thread
From: Enrico Piria @ 2005-07-20 17:02 UTC (permalink / raw)
To: ecos-discuss
Hello.
I'm rewriting the port of eCos to ColdFire.
This processor has a large number of IO registers mapped to memory.
I have two alternatives in writing code to manage the
IO registers.
The first one is to use a data structure that maps all the
registers, like the following:
typedef volatile struct {
cyg_uint32 reg1;
cyg_uint16 reg2;
cyg_uint16 pad;
} __attribute__ ((aligned (4), packed)) regs_t;
Then I can assign the base address of the registers to
a pointer of type regs_t:
regs_t *regs = (regs_t *)BASE_ADDRESS;
and start using the structure:
regs->reg2 = regs->reg2 + VALUE;
However, although the GCC produces the correct code,
nothing guarantees that read/write accesses to the registers
will be done in a single instruction (ColdFire permits
8, 16, or 32 bit read or write accesses to memory).
The alternative is to use the
HAL_READ_UINTx/HAL_WRITE_UINTx macros.
However, the code this way becomes much less readable:
cyg_uint16 tmpvariable;
HAL_READ_UINT16(®s->reg2, tmpvariable);
HAL_WRITE_UINT16(®s->reg2, tmpvariable + VALUE);
Moreover, this code is error prone, because I need to specify
the size of the access.
What is the better thing to do?
Thank you
Enrico
____________________________________________________________
Libero Flat, sempre a 4 Mega a 19,95 euro al mese!
Abbonati subito su http://www.libero.it
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-07-20 17:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-20 17:02 [ECOS] Memory mapped IO Enrico Piria
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).