PeterBLITZ / m2tklib

Automatically exported from code.google.com/p/m2tklib
0 stars 0 forks source link

Add ATOMIC_BLOCK for GetFromQueue #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
http://www.nongnu.org/avr-libc/user-manual/group__util__atomic.html#ga362c18b15a
09703e42e1c246c47420ef

#include <util/atomic.h>

ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
  // ...
}

to be protected from interrupts. This will ensure, that setKey can be called 
within interrupts.

Maybe, add this also to PutIntoQueue()

Original issue reported on code.google.com by olikr...@gmail.com on 10 Jul 2011 at 11:03

GoogleCodeExporter commented 8 years ago
PutIntoQueue definitely needs the protection as well (as it may be interrupted 
while it's running and it's not re-entrant.

Original comment by DrZip...@gmail.com on 11 Jul 2011 at 2:58

GoogleCodeExporter commented 8 years ago

Original comment by olikr...@gmail.com on 11 Jul 2011 at 2:52

GoogleCodeExporter commented 8 years ago
done:
m2_GetKeyFromQueue:
/* prologue: function */
/* frame size = 0 */
    movw r26,r24
    adiw r26,41
    ld r24,X
    sbiw r26,41
    tst r24
    brne .L2
    ldi r18,lo8(0)
    rjmp .L3
.L2:
    in r25,__SREG__
/* #APP */
 ;  50 "/usr/lib/gcc/avr/4.3.4/../../../avr/include/util/atomic.h" 1
    cli
 ;  0 "" 2
/* #NOAPP */
    adiw r26,40
    ld r24,X
    sbiw r26,40
    movw r30,r26
    add r30,r24
    adc r31,__zero_reg__
    ldd r18,Z+36
    subi r24,lo8(-(1))
    andi r24,lo8(3)
    adiw r26,40
    st X,r24
    sbiw r26,40
    adiw r26,41
    ld r24,X
    sbiw r26,41
    subi r24,lo8(-(-1))
    adiw r26,41
    st X,r24
    out __SREG__,r25
.L3:
    mov r24,r18
/* epilogue start */
    ret

similar for PutKeyIntoQueue

Original comment by olikr...@gmail.com on 12 Jul 2011 at 4:58