Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: Some C help please !

2007-03-23 by David Kelly

On Thu, Mar 22, 2007 at 08:44:08PM -0000, kernels_nz wrote:
>
> The huge advantage of using the shift and mask method is that it makes
> pre-written code completely portable to any other AVR micro with the
> same names for bits, and generally when two AVR micros have the same
> peripherals, they also use the same bit-names, but not necessarily in
> the same bit position.

If someone was interested enough to do the work there is no reason why
each and every register could not be defined as structs with bitfields.
Codewarrior does exactly that. Makes for some *huge* .h files.

If one were determined to do such a thing I think a script should be
written to make structs out of register definitions. This way new CPUs
and new CPU families could be added relatively painlessly with minimum
opportunities for human error.

But (reaching for an example which might not exactly apply) if one
wanted to know of the TX register had 1) just completed or 2) was empty,
then the masking solution allows one to kill two birds with one stone.

Also if the compiler is smart and the device offers bitwise instructions
then the compiler will use bitwise instructions no matter if masks or
bit structs are used. So for code efficiency there is no difference.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.