Yahoo Groups archive

AVR-Chat

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

Thread

ATmega128, flags, semaphores and interrupts

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

Re: [AVR-Chat] ATmega128, flags, semaphores and interrupts

2007-08-02 by John Samperi

At 04:49 PM 2/08/2007, you wrote:
>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...

No REALLY sure what you are trying to do but here we go....

There are no INVISIBLE instructions...that I can see...... :-)

but you can save the status register (SREG), do testing on bits or
whatever, and then restore the status register which SHOULD re enable
interrupts.


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.2/931 - Release Date: 1/08/2007 4:53 PM

Re: [AVR-Chat] ATmega128, flags, semaphores and interrupts

2007-08-02 by David VanHorn

> >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...
>
> No REALLY sure what you are trying to do but here we go....
> There are no INVISIBLE instructions...that I can see...... :-)

And that would be sort of an oxymoron.. :)
He meant "atomic", but he did say "indivisible"

> but you can save the status register (SREG), do testing on bits or
> whatever, and then restore the status register which SHOULD re enable
> interrupts.

something like

in  temp,sreg
cli

(do stuff)

out  sreg,temp ;


This might be a case where doing it a little differently would work better.
Remember too, that if you're IN an isr, that ints are disabled till
you RETI, unless you sei them yourself, which I've never had to do.

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.