Advertisement
abdullahkahraman

RTOS implementation with in-line assembly - EE.StackExchange

Jun 21st, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: abdullah
  4.  *
  5.  * Created on 10 Haziran 2012 Pazar, 14:43
  6.  */
  7. #include <xc.h> // Include the header file needed by the compiler
  8. #include "RTOS.h" // Include the header for co-operative RTOS.
  9. __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & IOSCFS_4MHZ & BOREN_ON);
  10.  
  11. unsigned char OS_currentTask; // This register holds the current task's place in the array OS_tasks
  12. unsigned char OS_tasks[4]; // This array holds PCL and PCLATH for tasks. This array will have..
  13. //                            .. (number of tasks)*2 elements, since every task occupies 2 places.
  14.  
  15. void fTask1(void); // Prototype the function for task1.
  16. void fTask2(void); // Prototype the function for task2.
  17.  
  18. void main(void) @ 0x0001
  19. {
  20.     TRISA = 0; // Set all of the PORTA pins as outputs.
  21.     TRISC = 0; // Set all of the PORTC pins as outputs.
  22.     ANSEL = 0; // Set all of the analog input pins as digital i/o.
  23.     PORTA = 0; // Clear PORTA bits.
  24.     PORTC = 0; // Clear PORTC bits.
  25.  
  26.     OS_currentTask = 0; // Current task is first task.
  27.     fTask1(); // Call task to initialize it.
  28.     OS_currentTask += 2; // Increment task pointer by two since every task occupies 2 places in the array.
  29.     fTask2(); // Call task to initialize it.
  30.     OS_runTasks(4); // Run the tasks in order. The argument of this macro takes is: (Number of tasks) * 2
  31. }
  32.  
  33. void fTask1(void)
  34. {
  35.     OS_initializeTask(); // Initialize the task so that task runner can get its ingredients.
  36.     while (1)
  37.     {
  38.         PORTC = 0xAA;
  39.         OS_yield(); // Yield CPU to other tasks.
  40.         PORTC = 0x55;
  41.         OS_yield(); // Yield CPU to other tasks.
  42.     }
  43. }
  44.  
  45. void fTask2(void)
  46. {
  47.     OS_initializeTask(); // Initialize the task so that task runner can get its ingredients.
  48.     while (1)
  49.     {
  50.         PORTC = 0xFF;
  51.         OS_yield(); // Yield CPU to other tasks.
  52.         PORTC = 0x00;
  53.         OS_yield(); // Yield CPU to other tasks.
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement