This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: EINT and Nesting

Part Number: TMS320F28388D


Tool/software:

Hi,

  I am still a little confused about Interrupt priorities and Nesting.

  1. Can a higher priority ISR, interrupt a lower priority if you are currently in the lower priority ISR handler?
    1. Can this happen if they are in the same PIE group?
    2. Can this happen if they are NOT in the same PIE group?
    3. Can this only happen if you do an EINT at the beginning of the lower priority ISR?
    4. With EINT done at the beginning of the ISR handler can a lower ISR interrupt the higher priority?
  2. How can a higher priority ISR interrupt a lower priority ISR in the same PIE group?
    1. What masking do we use or does it just happen automatically.
  3. Regarding nesting:
    1. If you have 2 ISRs not in the same PIE Group but you do an EINT at the beginning of the ISR handler can a lower priority ISR interrupt the higher priority? And vice-versa?
      1. I don't want this to happen but I just want to understand.

  I have these 2 links that I have read but still a little confused.
https://software-dl.ti.com/C2000/docs/c28x_interrupt_nesting/html/index.html
https://software-dl.ti.com/C2000/docs/c28x_interrupt_faq/html/index.html

  • Hi Dorion,

    By default, the CPU will service each interrupt to completion without breaking out of an ISR even if a higher priority interrupt gets flagged during its execution. Once the CPU finishes executing an ISR, it will then service the highest priority interrupt that is both flagged and enabled. The links you have mentioned give a solution for two different scenarios:

    • Simple Nesting (Highest priority interrupts will be branched to no matter if the CPU is already servicing another interrupt)
      • Case 1: All interrupts are in different groups & priority from ePIE is good
        • In highest priority ISR
          • no additional code needed
        • In lowest priority ISR
          • EINT
          • ISR application execution
          • DINT
        • In medium priority ISRs (not highest or lowest priority)
          • clear all IERs in all lower priority groups
          • EINT
          • ISR application execution
          • DINT
      • Case 2: Two (or more) interrupts are from same group
        • In highest priority ISR
          • No additional code needed 
        • In lower priority ISRs of two interrupts within same group
          • Re-enable IER for group
          • Clear ACK for the group
          • wait 1 cycle (NOP)
          • EINT
          • ISR application execution
          • DINT
        • For extra protection (not always needed):
          • Clear the PIEIER each time to avoid spurious interrupting from the same group (ex. second interrupt of same ISR comes in during execution, and you want to avoid nesting and going into the second one before completing the first one)
    • Changing Priority (Nesting to change priority in ePIE) - use the masks from the sw_prioritization_isr_levels.h
      • All interrupts being used are in different groups
        • In highest priority ISR
          • No additional code needed 
        • In all lower priority ISRs:
          • Enable IER of all higher priority interrupts
          • Clear ACK of current group
          • wait 1 cycle (NOP)
          • EINT
          • ISR application execution
          • DINT
      • 2 (or more) interrupts are from the same group
        • In highest priority ISR
          • No additional code needed  
        • In lower priority ISRs from a unique group
          • Enable IER of all higher priority interrupts
          • Clear ACK of current group
          • wait 1 cycle (NOP)
          • EINT
          • ISR application execution
          • DINT
        • In lower priority ISRs of two interrupts within same group
          • Save PIEIER of current ISR
          • Enable IER of all higher priority interrupts <- use masks from the header file for this
          • Enable PIEIER of all higher priority interrupts in same group <- use masks from the header file for this
          • Clear ACK of current group
          • wait 1 cycle (NOP)
          • EINT
          • ISR application execution
          • DINT
          • Restore PIEIER for current group

    I am planning on updating the link you have mentioned with the information above and examples of each case. Please let me know if anything about it is unclear.

    Best Regards,

    Delaney

  • To answer your questions specifically:

    Can a higher priority ISR, interrupt a lower priority if you are currently in the lower priority ISR handler?
    1. Can this happen if they are in the same PIE group?

    No, in normal operation this would never happen. It is possible to enable this for any combination of interrupts though (see Simple Nesting above)

    Can this happen if they are NOT in the same PIE group?

    Not in normal operation, however it is also possible. This would require just an EINT in the lower priority ISR.

    Can this only happen if you do an EINT at the beginning of the lower priority ISR?

    The EINT would be required, yes. If trying to nest an interrupt in the same group, modifications to the IER (and PIEIER optionally) and ack would also be needed. You would want to do these in the same order shown as in the example code.

    With EINT done at the beginning of the ISR handler can a lower ISR interrupt the higher priority?

    Yes, if the interrupt of a higher priority is in a different ePIE group.

    How can a higher priority ISR interrupt a lower priority ISR in the same PIE group?
    1. What masking do we use or does it just happen automatically.

    You would need to do all of the following:

    • Re-enable IER for group
    • Clear ACK for the group
    • wait 1 cycle (NOP)
    • EINT

    No need to use the masks. Modifying the PIEIER would be optional. Technically, the PIEIER for the higher priority interrupt would already be enabled when inside the lower priority ISR. You could just disable the PIEIER of the current group if you wanted to avoid spurious interrupts.

    Regarding nesting:
    1. If you have 2 ISRs not in the same PIE Group but you do an EINT at the beginning of the ISR handler can a lower priority ISR interrupt the higher priority? And vice-versa?

    This case is why you would not want to add EINT to the higher priority ISR, just the lower (or all lower ISRs). That way only the higher priority ISR can nest the lower priority ISR and not vice versa. Theoretically if you added EINT to the higher priority ISR and a lower priority interrupt came in during execution, it would nest it yes.

    Please upvote any responses that were helpful for you Slight smile

    Best Regards,

    Delaney

  • Delaney,

    Fantastic, It answered all my questions and a few more I had. A suggestion maybe add my questions to the FAQ?

    One thing in case 1 of the simple nesting you say to enable EINT in all ISRs except the lower ISR But in my questions below in Regarding Nesting you say "This case is why you would not want to add EINT to the higher priority ISR, just the lower (or all lower ISRs)"

    I assumed that case 1 of the simple nesting that is the same case to only do an EINT on the lower ISRs?

    Dorion

  • Hi Dorion,

    My mistake, the simple nesting case should have said highest priority. I just updated the reply to fix it.

    Best Regards,

    Delaney

  • Delaney,

      Do not apologize, that is why I clarified. I appreciate all the clarifications this helps a lot

      So I have one more scenario:

      If I do an EINT at the beginning of the ISR Handler and do not change IER for ISRS that can come in, this would allow any higher or lower priority ISR to "interrupt" the current ISR handler, correct? Except anything in the same PIE group I would need to clear the PIE register also.

      If I only want to allow higher ISRs to "interrupt" the current ISR handler (not lower ones) then I need to change the IER mask BEFORE enabling EINT. Example I get Interrupt PIE group 3.8 (PWM) and only want Interrupt PIE Group 1.x, I would set the IER to enable just PIE group 1.

     this would then allow me to prevent any lower ISRs from interrupting this ISR.

     Do I have that correct?

    Dorion
     

  • Hi Dorion,

    That is a good question. I know it will choose whichever of the other interrupts (flagged and enabled) has the highest priority when nesting, but I'm not sure if it includes itself in that check (as in, I don't know if interrupts of a lower priority can nest inside). Let me look into this and get back to you.

    Best Regards,

    Delaney

  • Hi Dorion,

    I apologize for the delay. You are correct, adding just EINT could cause lower priority interrupts to nest inside. You need to modify the IER in the ISRs as well for all but the lowest priority ISR. So, for example, you can do the following in this case:

    INT 1.3 (highest priority) - regular ISR

    INT 2.1 - Clear IER for group 4 and group 7, then EINT

    INT 4.2 - Clear IER for group 7, then EINT

    INT 7.5 (lowest priority) - just add EINT

    Best Regards,

    Delaney