avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] generic queue library for AVR GCC?


From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] generic queue library for AVR GCC?
Date: Mon, 15 Nov 2004 15:33:11 -0800
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

E. Weddington wrote:

I agree with Bruce's method; it's better in that it preserves the original state of the interrupt flag.

I believe that the "push/pop" method did as well...

The push/pop is not required, and probably wasteful.

Though you don't have to do it in inline assembly. It can be done all in C:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
....
{
   uint8_t sreg = SREG;
   cli();
   sm_qin = sm_qout = 0;  // reset queue pointers.
   SREG = sreg;  }

Yeah.  I like yours better.  The resultant AVR code is identical.

I've got to "get onboard" with the "new" gcc 3.x AVR I/O syntax.
I still have a number of active mixed AVR assembly/avr-gcc
projects, which only work with the gcc 2.95 I/O definitions, so
I guess I gravitate to inline assembly more often than I probably
should. :-)

How about this...

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <inttypes.h>
    #define begin_critical_section()  SREG; cli()
    #define end_critical_section(val) SREG = val
    ....
    {
        unsigned char sreg = begin_critical_section();
        sm_qin = sm_qout = 0;   // reset queue pointers
        end_critical_section(sreg);
    }

This gets you the same, optimally efficient AVR code.

Best regards,

Bruce

--
 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Voice: +1-858-551-4011
 FAX: +1-858-551-0777
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/


reply via email to

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