Back

/* Sched1 in COMATOS C
 The goal of this lab is to run lab 1 exercise in 476 using COMATOS
 */ 
#include "comatos8515.c" 
   #include <stdio.h>
   #define begin {
   #define end } 
//task repetition times
   #define t0 50
   #define t1 125

  
//initial task state variables
   #define Task0State 0
   #define Task1State 8 //4*125 is 1/2 second
#define NoTime 0 
   #define Task0Message 0x01
//Comatos constants
   //Turn off debugger
   #define NODebug 0
   //Any task longer than 10 mS is an error 
   #define OSTimeOut 10
   //mask to define that a task does not listen to messages 
   #define NoMessage 0xff
   //mask to define that a task is not time-scheduled 
   #define NoTime 0
char Task0(void); 
   char Task1(void); 
   unsigned char led; 
   unsigned char flag, i;
   
   void main(void)
   begin
   DDRB = 0xff;
   PORTB = 0xff;
   DDRD = 0x00; 
   led = 0xff;
   
   //Set up OS constants
   OSInit(OSTimeOut, NODebug);
   
   //Define the tasks to the OS
   OSCreateTask(Task0, t0, NoMessage, 0); 
   OSCreateTask(Task1, t1, NoMessage, Task1State);
 //Start the system
   OSStart(); //never returns
   end 
//blink LED 0
   char Task0(void) 
   begin 
 if(~PIND==0x01) 
   OSSendMess(1, 1); //signal blinking LEDs 
 
 else OSSendMess(1,0); //signal stop blinking when button is not pressed
   
   
   
   return 0;
   end 
char Task1(void)
   begin
   char T2State; 
   
   T2State = OSGetState(); 
   
   if(T2State==0 && OSGetMess(0)==1)
   begin
   //OSSetState(4);
   led++;
   PORTB=~led; 
   end 
   
   else OSSetState(T2State-1); 
   
   if(T2State==0) OSSetState(8);
   
   return 0;
   
   end

Back