Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

Discussion Groups | Comp.Arch.Embedded | Re: How to save HC08's interrupt state to the stack without using register?

There are 2 messages in this thread.

You are currently looking at messages 0 to 2.

Re: How to save HC08's interrupt state to the stack without using register? - CBarn24050 - 13:50 05-03-04

that should not happen anyway.



Re: How to save HC08's interrupt state to the stack without using register? - Dave Hansen - 16:32 05-03-04

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.