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: Bjarne Laursen
Subject: Re: [avr-gcc-list] generic queue library for AVR GCC?
Date: Tue, 16 Nov 2004 09:55:36 +0100
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Bruce D. Lightner wrote:


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.

but be careful
this will not work:

       unsigned char cr;
       if (bSomeFlag) cr = begin_critical_section();
       sm_qin = sm_qout = 0;   // reset queue pointers
       if (bSomeFlag) end_critical_section(cr);

cli() will get executed even if bSomeFlag is 0.
maybe an inline function will do the job.

-Bjarne



reply via email to

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