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

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

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


From: Andreas Kaiser
Subject: [avr-gcc-list] race condition in sleep_mode()
Date: Sun, 18 Dec 2005 10:39:59 +0100

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.

Gruss,
Andreas




reply via email to

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