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


> ------------BIT set/clear macros for I/O registers
> /*
>  * A bit of syntactic sugar around setting and resetting bits in
>  * 8 and 16 bit IO registers. A number of registers have reserved
>  * bits that are marked "do not program" which means don't ever
>  * change them if you expect your driver to work. So these macros
>  * automate the process of reading the old value, oring in or anding
>  * out the bits that are set in the pattern 'bits' and then writing
>  * the result back to the register.
>  */
> #define IO_BIT_SET_8(base, offset, bits)                   \
> CYG_MACRO_START                                            \
>         cyg_uint8       datum;                             \
>         HAL_PCI_IO_READ_UINT8((base) + (offset), datum);   \
>         datum |= (cyg_uint8)(bits);                        \
>         HAL_PCI_IO_wRITE_UINT8((base) + (offset), datum);  \
> CYG_MACRO_END

I suggest you keep to the HAL_PCI_IO_ naming convention. eg:

#define HAL_IO_BIT_SET_UINT8(_register_, _bits_)           \
CYG_MACRO_START                                            \
        cyg_uint8 _datum_;                                 \
        HAL_PCI_IO_READ_UINT8((_register_), _datum_);      \
        _datum_ |= (cyg_uint8)(_bits_);                    \
        HAL_PCI_IO_wRITE_UINT8((_register_) _datum_);      \
CYG_MACRO_END

If you write macros for all three types, UINT8, UINT16 and UINT32 i
should be able to find some suitable header file to place them in.

        Andrew

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