Parallel ARM hardware interrupts with one carrying memset() or memcpy()

275 Views Asked by At

This is a rather an 'expert' question but we have a similar issue and I have trouble understanding the concept of interrupt-priority with respect to the execution of ISR in and embedded DSP system.

Let's say we have two - ISR1 and ISR2 - interrupts occuring after each other like shown below:

enter image description here

I'd like to compare two scenarios with respect to the interrupt priority and thread-safety of the system. Assume, we have no semaphore, mutex, etc. and gcc as a compiler

So, what happens if:

a)

  • NVIC priority of IRQ1 is higher than IRQ2
  • ISR1 contains a critical memset function, ISR2 contains uncritical sections only

b)

  • NVIC priority of IRQ1 is lower than IRQ2
  • ISR1 contains a critical memset function, ISR2 contains uncritical sections only

My expectation would be:

a) Nothing happens, ISR2 is exectuted once ISR1 is finished

b) Memset is interrupted (uo-oh), system throws an exception.

Am I correct with that?

1

There are 1 best solutions below

0
On

If see NVIC then I understand that we talk about Cortex-M core uCs.

The first question is what you mea by critical section. There are two posibilities:

  1. Yuo modify the shared object.
  2. The timing of the code executed is critical and it should not be interrupted by antyhing (for example it is a bitbanding communication driver)

If the pririty of the interrupt 1 is higher than the interrupt 2 then the interrupt 1 cannot be preempted by the interrupt 2. The uC will remember that the interrupt 2 is pending and it will invoke its handler when interrupt has finished.

In the opposite situation interrupt 2 will preempt the execution and return to the interrupt 1 handler when finished.

b) Memset is interrupted (uo-oh), system throws an exception.

I do not understand what you mean. memset is just a normal function. If interrupt arrives in the middle of its execution then when interrupt handler returns control to it will continue from the point where it was interrupted. No exceptions. Interrupts always happens in the middle of some function.

If both handlers modify the same area of memory you need to provide the synchronisation mechanisms to prevent unpredicted results of this operation. Example: interrupt 1 executes memset and sets the value 5 to the memory location starting at address 100 and ending at address 100. You expect to have 5 in all 100 bytes. But in the meantime (lets say memset was at address 160) the interrupt 2 arrives and sets the same memory locations to 10. When this interrupts finishes execution that memory area is set to 10. But the interrupt 1 continues execution and sets the remaining 40 bytes to 5. So after it you have memory area from address 100 to 159 set to 10 and from 160 to 200 to 5 which probably is not what you would expect.