• AVR Freaks

Hot!Clarification of Interrupt Control with p33FJ128MC706A

New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2019/08/15 10:07:13
  • Location: 0
  • Status: offline
2019/08/19 08:30:22 (permalink)

Clarification of Interrupt Control with p33FJ128MC706A

I noticed some code with interrupt disable and enable inside code which would be called in the main context and in the interrupt context.  (It kinda wigged me out to see this...  I usually separate out interrupt/main context functions.)
Is this safe to do?
This is a snippet, interrupt nesting is disabled.
 asm("#disi #0x3ff");
 b->dataSize -= size;
 asm("#disi #0");
Thanks for any help..

1 Reply Related Threads

    Aussie Susan
    Super Member
    • Total Posts : 3663
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: Clarification of Interrupt Control with p33FJ128MC706A 2019/08/19 19:42:32 (permalink)
    It is not interrupt nesting that is disabled, but any interrupts are disabled altogether. 'disi' is an assembler instruction that disables the recognition of interrupts for the specified number of instruction cycles. Using the parameter of 0 enables the interrupts to be recognised again.
    If you are using the XC16 compiler, then you can also use the '__builtin_disi()' macro.
    The reason this is done is often when you must make sure that an operation is (in effect) atomic. In this case you want to make sure that the pointer dereferencing and value updating all occur without being interrupted by some code that might (for example) update 'size' or the 'dataSize' values. Also, depending on the size of the values, it might take several CPU instructions to retrieve/store the value and you don't want and ISR changing (say) the top part of a value after you have read it.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5