This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ever learning, setting individual bits


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]