Yahoo Groups archive

AVR-Chat

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

Message

ATmega128, flags, semaphores and interrupts

2007-08-02 by Mark

Hi Guys,

I am a relative newcomer to the ATmega128 and have a question about 
semaphore (and general flag) management.

I have been looking for an ATmega128 instruction that allows a flag 
to be tested then set in a single instruction while not allowing 
interrupts during it's execution. The Motorola 68000 has the TAS 
(Test And Set) instruction which is indivisible which does what I am 
looking for (?)

All manner of interesting things can happen to a system if an 
interrupt occurs between reading a semaphore, changing it's state and 
writing it back again when the interrupt in question changes the 
state of that same semaphore.

I could disable Global Interrupts, run the process, Enable 
interrupts. This won't work for both cases of interrupts being 
enabled or disabled before my example is run since in one case I will 
have changed final GI state.

If I could Test (save) and Disable Interrupts with an indivisible 
instruction, run the process then return the original Global 
Interrupt state I would feel a bit safer...

Am I working too hard at this problem and there a mechanism in place 
that I haven't appreciated yet ?

Thanks,

Mark

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.