/********************************************************************** rtos_ex1 An introductory Salvo example. There are two tasks, of equal priority. One counts, the other displays the count. Salvo Lite RTOS with sfc18sfm.lib library used. Mainly for simulation but can run on Derbot. TJW 21.12.05, rev. 10.6.09 Tested 23.12.05 **********************************************************************/ #include #undef OSC //necessary for this version of Salvo, as it also defines this name #include #pragma config OSC = HS //HS oscillator #pragma config PWRT = ON, BOREN = OFF //power-up timer on, brown-out detect off #pragma config WDT = OFF //watchdog timer off #pragma config LVP = OFF //low voltage programming off //function prototypes. These functions are tasks. void Count_Task( void ); void Display_Task( void ); //Define labels for context switches _OSLabel(Count_Task1) _OSLabel(Display_Task1) //Define and initialise variable unsigned char counter = 0; /************************************************************* Task Definitions (configured as functions) **************************************************************/ void Count_Task( void ) { for (;;) { //infinite loop counter++; OS_Yield(Count_Task1); //context switch } } // void Display_Task( void ) { for (;;) { PORTC = counter<<5; //Shift Counter left, and move to PORT C OS_Yield(Display_Task1); } } /******************************************************************* Main ********************************************************************/ void main( void ) { //Initialise TRISC = 0b10000000; //Set all Port C bits to output, except bit 7. PORTC = 0; //Set all Port C outputs low //Initialise the RTOS OSInit(); //Create Tasks OSCreateTask(Count_Task, OSTCBP(1), 10); OSCreateTask(Display_Task, OSTCBP(2), 10); //Set up continuous loop, within which scheduling will take place. for (;;) OSSched(); }