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

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

Re: [avr-gcc-list] race condition in sleep_mode()


From: Dmitry K.
Subject: Re: [avr-gcc-list] race condition in sleep_mode()
Date: Mon, 19 Dec 2005 09:07:10 +1000
User-agent: KMail/1.5

On Sunday 18 December 2005 19:39, Andreas Kaiser wrote:
> When power-down sleep mode is to be used and only part of an interrupt
> driven state machine causes a wakeup (e.g. in a I2C slave implemented
> by USI, the start condition causes a wakeup, the bit counter however
> does not), the avr-libc implementation seems unfit.
>
> In the case described above, a test has to be made to find out whether
> the state is suitable for power-down. To avoid a race condition, the
> test has to be done with interrupts disabled and the sleep mode has to
> be entered without giving the machine a chance to interrupt before.
>
> Proposal: In sleep_mode(), the SLEEP instruction should be augmented
> by a SEI instruction: "sei \n\t sleep". This sequence is safe, since
> the instruction right after SEI is always executed before any
> interrupt. Also, it should not do harm to reasonable existing code,
> since sleep does not make much sense when executed with interrupts
> disabled. Unless the machine is to be securely halted.

Another common method is to set SE bit *after* 'sleep' instruction.
(The important interrupt must clean SE). 'cli' is not needed in this case.

Dmitry.





reply via email to

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