There are 2 messages in this thread.
You are currently looking at messages 0 to 2.
On 05 Mar 2004 18:50:42 GMT, c...@aol.com (CBarn24050) wrote: >that should not happen anyway. Are you being obtuse, or do you really not know? Consider routines to insert and remove data from queues. In a particular application, these routines might be used to communicate between an ISR and main-line code. Ignoring for the moment niceties like error checking, you might write the code something like: void queue_insert(QUEUE *q, ITEM d) { mDisable(); /* Disable interrupts */ /* insert d in *q */ mEnable(); /* Enable interrupts */ } ITEM queue_remove(QUEUE *q) { ITEM d; mDisable(); /* copy head of *q to d and remove from *q */ mEnable(); return d; } But what happens in the ISR? The call to queue_insert or queue_remove causes interrupts (which had been disabled before the function was called) to be enabled. Which might result in nested interrupts. Which might break the application. How do you solve this? Well, there are generally two ways. One is to require the caller to disable interrupts before making the call. But that's a huge bug just waiting to happen. The other is to save the stte of the interrupt flag before disabling interrupts, and then restoring the old state rather than blindly enabling interrupts when done. The name of the macros (in my other post) should provide a hint: mSave_Disable() saves the interrupt state and disables interrupts, mRestore() restores the saved state. Regards, -=Dave -- Change is inevitable, progress is not.