Usage with Interrupt Service Routines


Detailed Description

TiROS API calls can be used within ISRs.

Mark the beginning and end of an ISR, so that TiROS can appropriately perform task scheduling if needed. Interrupt service routines are notoriusly hardware and compiler dependent, so use the instructions for your hardware/compiler port.

TiROS supports three ways of servicing interrupts:

  1. Simple Usage: An ISR can be written as you would normally write one for your hardware only if all of the following are true:
  2. Saving context per interrupt response: This is the standard way to service interrupts. Due to the presence of an OS, the sequence of steps to be taken are as follows:
         function ISR( ) {
            stkptr = save_context_of_task();  // See port instructions.
             // stkptr = pointer to stack of saved task.
             
             perform_functions();
            newstkptr = osint_taskswitcher(stkptr);
            load_context_of_newtask(newstkptr);    
         }
    
    The exact implementation depends on the hardware port. See the port documentation for more details.

  3. Using Kernel Traps: TiROS can take advantage of hardware architectures that can support a software initiated interrupt (kernel trap). This is the most preferable option because interrupt service routines have very low overhead and can yet use all of the TiROS calls and interact with tasks. If your port supports this, use this. It also makes writing the ISRs very simple. The way this works is that the context of a task is not saved on entry to the ISR. Instead, at the end of the ISR, OS_ISR_END() determines if the task has to be switched out. If so, it invokes a kernel trap. The kernel trap is entered as soon as the ISR ends. The kernel trap performs the context switch. Thus, the context switch overhead is only invoked when necessary, not at every ISR. Eg.
     void ISR_function(void) 
     {
       int x;
       OS_CRITICAL_ENABLE();   // Only needed if any critical sections
                               // will be used and interrupt nesting is enabled.
    
       OS_ISR_BEGIN();         // Mark the beginning of an ISR. Note
                               // that if OS_CRITICAL_ENABLE() is also
                               // present, then this comes after 
                               // that. 
      
      x = 3;
        Do more stuff ....
      
      OS_ISR_END();
     }
    

TiROS supports nested interrupts. However, for reliability, try not to use nested interrupts unless absolutely necessary. Interrupt service routines use the stack of the task that was running when the interrupt occured. Nested interrupts can cause the stack to grow unpredictably and overflow.

To use nested interrupts, write code as below:

 extern uint8_t os_isr_nesting; // Internal TiROS variable that keeps track
                                // of nesting level.
 void ISR_function(void) 
 {
   int x;
   OS_CRITICAL_ENABLE();   // Only needed if any critical sections
                           // will be used and interrupt nesting is enabled.

   OS_ISR_BEGIN();         // Mark the beginning of an ISR. Note
                           // that if OS_CRITICAL_ENABLE() is also
                           // present, then this comes after 
                           // that. 

  if (os_isr_nesting < TIROS_MAX_ISR_NESTING) {
     // Interrupts should only be reenabled if the current nesting level
     // is less than or equal to the maximum configured nesting level.
     renable_interrupts();
  }
  x = 3;
    Do more stuff ....
  
  OS_ISR_END();
 }


Defines

#define OS_ISR_BEGIN()   OS_PORT_ISR_BEGIN()

Functions

void OS_ISR_END (void)


Define Documentation

 
#define OS_ISR_BEGIN (  )     OS_PORT_ISR_BEGIN()

Enable this within ISRs immediately after any variable declarations, and after any OS_CRITICAL_ENABLE().

Definition at line 379 of file tiros.h.


Function Documentation

void OS_ISR_END ( void   ) 

Mark the end of an ISR.

This should be called at the end of an ISR. There must exist a corresponding OS_ISR_BEGIN() statement.


TiROS User Manual: Last Updated on Fri Jul 20 10:52:24 2007