This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Ever learning, setting individual bits
- From: Bart Veer <bartv at ecoscentric dot com>
- To: ecos at mcmanis dot com
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Sun, 19 Feb 2006 17:31:58 +0000 (GMT)
- Subject: Re: [ECOS] Ever learning, setting individual bits
- References: <6.1.2.0.2.20060218162645.04e06550@66.125.189.29>
>>>>> "Chuck" == Chuck McManis <ecos@mcmanis.com> writes:
Chuck> ------------BIT set/clear macros for I/O registers
Chuck> /*
Chuck> * A bit of syntactic sugar around setting and resetting bits in
Chuck> * 8 and 16 bit IO registers. A number of registers have reserved
Chuck> * bits that are marked "do not program" which means don't ever
Chuck> * change them if you expect your driver to work. So these macros
Chuck> * automate the process of reading the old value, oring in or anding
Chuck> * out the bits that are set in the pattern 'bits' and then writing
Chuck> * the result back to the register.
Chuck> */
Chuck> #define IO_BIT_SET_8(base, offset, bits) \
Chuck> CYG_MACRO_START \
Chuck> cyg_uint8 datum; \
Chuck> HAL_PCI_IO_READ_UINT8((base) + (offset), datum); \
Chuck> datum |= (cyg_uint8)(bits); \
Chuck> HAL_PCI_IO_wRITE_UINT8((base) + (offset), datum); \
Chuck> CYG_MACRO_END
<snip>
I think these macros might be a mistake. The existing macros
HAL_READ_UINT8() etc. are atomic. Your read/modify/write macros will
usually be non-atomic, although there may be some architectures where
they can be implemented atomically with bit-set instructions or
equivalent. There is lots of opportunity for confusion, for example
the register might have a different bit that gets cleared
automatically whenever the register is read.
When writing a device driver it is often important to know EXACTLY
how the code will access the hardware. Using HAL_READ_xxx() and
HAL_WRITE_xxx() gives you that. They might require slightly more
verbose code than your bit set and clear macros, but there are no
hidden operations on the device.
Bart
--
Bart Veer eCos Configuration Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss