[ECOS] Ever learning, setting individual bits

Chuck McManis ecos@mcmanis.com
Mon Feb 20 00:06:00 GMT 2006


At 09:31 AM 2/19/2006, Bart Veer wrote:
>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.

This is a valid concern, a number of bits in the registers are "latch high" 
or "latch low" and they reset to their default when the register has been 
read. That being said, when I wrote them i wasn't too concerned about 
atomicity because it wasn't a requirement, I only use them on registers 
where it is safe to read and write non-atomically.

Another wrinkle in these is that they encapsulate the HAL_READ_UINT* in a 
HAL_PCI_READ_UINT*, now I assume the original creator of the HAL_PCI_xxx 
equivalents created them so that different endian machines would use PCI 
based peripherals and do the byte swapping or not as necessary. On the PC 
architecture of course that is not necessary but on other architectures it 
would be.

>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.

True, that is why good documentation of all the macros are important. I 
have found that this has, so far, not been an issue.

--Chuck


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list