dsPIC33E/os_dsPIC33E_APIsB.c
// Interrupt Service Routine 
// Author		: Fabian Kung
// Last modified	: 12 Dec 2011
// Purpose		: This routine performs the following important tasks pertaining to the 
//                RTOS:
//                1. Updates the 32-bits global clock tick gulClockTick of the OS when Timer 1 overflows.
//                2. Increments the timer property of each tasks.
//                3. Check for task overflow condition (i.e. the time used to run the tasks is
//                greater the the clock tick.  When this happen the main scheduler will be
//                stalled, with the indicator LED turned on all the time. This option can be
//                disabled by remarking the relevant codes in the routine.
//
// Arguments		: None
// Return		: None

Interrupt Service Routine
Author         : Fabian Kung
Last modified  : 12 Dec 2011
Purpose                : This routine performs the following important tasks pertaining to the
RTOS:
1. Updates the 32-bits global clock tick gulClockTick of the OS when Timer 1 overflows.
2. Increments the timer property of each tasks.
3. Check for task overflow condition (i.e. the time used to run the tasks is
greater the the clock tick.  When this happen the main scheduler will be
stalled, with the indicator LED turned on all the time. This option can be
disabled by remarking the relevant codes in the routine.

Arguments              : None
Return         : None
Interrupt Service Routine Author : Fabian Kung Last modified : 12 Dec 2011 Purpose : This routine performs the following important tasks pertaining to the RTOS : 1 . Updates the 32 - bits global clock tick gulClockTick of the OS when Timer 1 overflows . 2 . Increments the timer property of each tasks . 3 . Check for task overflow condition ( i . e . the time used to run the tasks is greater the the clock tick . When this happen the main scheduler will be stalled with the indicator LED turned on all the time . This option can be disabled by remarking the relevant codes in the routine . Arguments : None Return : None
void __attribute__((__interrupt__)) _T1Interrupt( void )
{
    if (IFS0bits.T1IF)                                                          
    { 
		OSEnterCritical();
		if ((gnRunTask > 0) || (gunOSError > 0) || (gunTaskExecutedCount != 0)) 
		{                                        
			while (1)
			{
				ClearWatchDog();				
				PIN_OSPROCE1 = 1; 				
				PIN_ILED2 = 1;					
			}
		}
		gnRunTask = 1;							
		gulClockTick++; 						
		PR1 = __TIMER1COUNT;					
 		IFS0bits.T1IF = 0;					
		OSExitCritical(); 	
    }
}
void __attribute__ ( ( __interrupt__ ) ) _T1Interrupt ( void ) { if ( IFS0bits . T1IF ) { OSEnterCritical ( ) ; if ( ( gnRunTask > 0 ) || ( gunOSError > 0 ) || ( gunTaskExecutedCount != 0 ) ) { while ( 1 ) { ClearWatchDog ( ) ; PIN_OSPROCE1 = 1 ; PIN_ILED2 = 1 ; } } gnRunTask = 1 ; gulClockTick ++ ; PR1 = __TIMER1COUNT ; IFS0bits . T1IF = 0 ; OSExitCritical ( ) ; } }
Interrupt Service Routine
Author         : Fabian Kung
Last modified  : 12 Dec 2011
Purpose                : This routine performs the following important tasks pertaining to the
RTOS:
1.
Interrupt Service Routine Author : Fabian Kung Last modified : 12 Dec 2011 Purpose : This routine performs the following important tasks pertaining to the RTOS : 1 .
// If it is Timer 1 overflow interrupt
 //	If task overflow occurs or OS error detected,
 // trap the controller 
 // indefinitely and turn on indicator LED1.
 // Clear the Watch Dog Timer.
 // Turn on indicator LED1.
 // Turn on indicator LED2.
 // Assert gnRunTask.
 // Increment RTOS clock tick counter. 	
 // The codes below should be implemented in the Main() function for this version.
 // This will produce more efficient codes.
 //for (ni = 0;ni < gnTaskCount;ni++)		// Using for-loop produce more efficient 
 //										// assembly codes.
 //{	
 //	if (gstrcTaskContext[ni].nTimer > 0) // Only decrement timer if it is greater than zero.
 //	{
 //		--(gstrcTaskContext[ni].nTimer); // Decrement timer for each process.
 //	}
 //}
 // Load Period Register.
 // reset Timer 1 interrupt flag.
