avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] New device support


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] New device support
Date: Sun, 15 Jul 2007 22:07:05 +0200
User-agent: Mutt/1.5.11

As Dmitry K. wrote:

> >     TCCR0B = _BV(CS00) | _BV(CS02);
> >
> > would be rewritten as
> >
> >     TCCR0B_.byte = _BV(CS00) | _BV(CS02);

> A small note: the above expressions are *different*.

No, they aren't.  The .byte union member simply access the entire
8-bit IO register the same way as the current definitions would do, so
there's no read/modify/write behaviour.

Just as a simple example, look at the following:

#include <avr/io.h>

union __tccr0b {
        uint8_t byte;
        struct {
                unsigned int cs0: 3;
                unsigned int wgm02: 1;
                unsigned int : 2;
                unsigned int foc0b: 1;
                unsigned int foc0a: 1;
        } bits;
};

enum __cs0_val {
        CS0_NOCLK,
        CS0_1,
        CS0_8,
        CS0_64,
        CS0_256,
        CS0_1024,
        CS0_EXT_FALLING_EDGE,
        CS0_EXT_RISING_EDGE,
};

#define TCCR0B_ (*(volatile union __tccr0b *)0x45)

void
setup(void)
{
        TCCR0B = _BV(CS00) | _BV(CS02);
        asm volatile("nop");
        TCCR0B_.byte = _BV(CS00) | _BV(CS02);
}

(The NOP is just to distinguish both statements.)  Run it through

avr-gcc -Os -mmcu=atmega1281 -S foo.c

here's the result:

        .file   "foo.c"
        .arch atmega1281
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
        .global __do_copy_data
        .global __do_clear_bss
        .text
.global setup
        .type   setup, @function
setup:
/* prologue: frame size=0 */
/* prologue end (size=0) */
        ldi r24,lo8(5)
        out 69-0x20,r24
/* #APP */
        nop
/* #NOAPP */
        out 69-0x20,r24
/* epilogue: frame size=0 */
        ret
/* epilogue end (size=1) */
/* function setup size 6 (5) */
        .size   setup, .-setup
/* File "foo.c": code    6 = 0x0006 (   5), prologues   0, epilogues   1 */

Of course, what *is* different is to write

        TCCR0B_.bits.cs0 = CS0_1024;

This yields:

        in r24,69-0x20
        andi r24,lo8(-8)
        ori r24,lo8(5)
        out 69-0x20,r24

i.e. read/modify/write behaviour.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]