High frequency ISRs in FreeRTOS

peter_balazovic wrote on Tuesday, February 02, 2010:

Hello all,

I am a new to RTOS and starting to be familiarized with FreeRTOS.
My intention is to investigate how to integrate motor control into FreeRTOS.
Usually motor control system (without RTOS) runs Motor_control_ISR at 100 periodic rate and code is executed within this Motor_control_ISR which takes about 40.
It is hard real time system where motor control must complete within a given time limit otherwise results in failure of the system.

Are there any handling techniques of such high frequency ISR to comply with FreeRTOS?
Do you have any suggestions how to handle high frequency ISRs within FreeRTOS?
Should it be such a ISR executed outside of FreeRTOS?
Thank you very much.

regards,
pepe

davedoors wrote on Tuesday, February 02, 2010:

Look at configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY at the bottom of this page. These parameters are only on new ports though.

The Cortex M3 demo apps run a 20KHz timer test that shows an interrupt entry jitter of about 100ns which is apparently equal to the effect of tail chaining in the core itself.

peter_balazovic wrote on Tuesday, February 02, 2010:

Is your suggestion to execute  such ISRs outside FreRTOS? (Interrupts running at these priorities will never be delayed from executing because of anything FreeRTOS.org is doing. )
If so, how to interact with FreeRTOS it means between high frequency ISR and FreeRTOS?

davedoors wrote on Tuesday, February 02, 2010:

Yes, if you want the interrupt to have a priority higher than any used by the kernel (including critical sections) then the handler cannot use any FreeRTOS functions.

peter_balazovic wrote on Tuesday, February 02, 2010:

Any idea how to interact between ISR (priority higher than any used by the kernel) and FreeRTOS kernel?

petermeier wrote on Tuesday, February 02, 2010:

You can use anything you like. If you need a buffer just use it and make it globally available. Make sure you have a lock mechanism.

UINT8 bufferLock = 0x00;
UINT8 buffer;

_ISR_(…)
{
  if (!bufferLock)
  {
    … check buffer data
    …update data
  }
  …
}

void pvTask(…) // Has a lower priority than the ISR, so pvTask can not interrupt the ISR
{
   // Try to access buffer, Method 1
  …disable interrupts
  if (bufferLock)
  {
     // Buffer is in use…
  } else
  {
    // Update buffer here
  }
  …enable interrupts

  #Method 2
  …disable interrupts
  if (!bufferLock)
    bufferLock = 0x01;
  …enable interrupts
  if (bufferLock)
  {
    // Update your buffer…
   …
   // Unlock buffer
   bufferLock = 0x00;
  }

This is quick and dirty, but it works…

peter_balazovic wrote on Tuesday, February 02, 2010:

Guys,
Thank you a lot!