Simple cooperative operating system

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
akouz
Date:
Tue Sep 17 13:20:02 2013 +0000
Parent:
3:85a9253b7559
Commit message:
LED flashes same way as in rtos_basic; typedef removed.

Changed in this revision

coos.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
typedef.h Show diff for this revision Revisions of this file
--- a/coos.h	Mon Sep 16 11:57:29 2013 +0000
+++ b/coos.h	Tue Sep 17 13:20:02 2013 +0000
@@ -23,13 +23,13 @@
 
 extern jmp_buf  COOS_main_context;
 extern jmp_buf  COOS_task_context[MAX_TASKS];    /* store environment for all tasks */
-extern volatile uchar COOS_task_no;
+extern volatile int COOS_task_no;
 
 //##########################################################
 // func
 //##########################################################
 
-void shutdown_task(uchar task_No);
-void wake_up_task(uchar task_No);
+void shutdown_task(int task_No);
+void wake_up_task(int task_No);
 
 #endif /* __COOS_H */
--- a/main.cpp	Mon Sep 16 11:57:29 2013 +0000
+++ b/main.cpp	Tue Sep 17 13:20:02 2013 +0000
@@ -1,24 +1,16 @@
 #include "mbed.h"
-#include "typedef.h"
 #include "coos.h"
 
 //##########################################################
-// def & enum
-//##########################################################
-
-
-//##########################################################
-// class
-//##########################################################
-Ticker flipper;
-DigitalOut myled(LED1);
-
-//##########################################################
 // var
 //##########################################################
+Ticker flipper;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
 jmp_buf         COOS_main_context;
 jmp_buf         COOS_task_context[MAX_TASKS];     /* store environment for tasks */
-volatile uchar  COOS_task_no;
+volatile int    COOS_task_no;
 volatile int    COOS_task_delay[MAX_TASKS];       /* task delay in 1 ms ticks, task stopped if value is negative */
 
 //##########################################################
@@ -29,20 +21,18 @@
 // Task 0
 // ======================================================
 void COOS_task0(void){
-    DELAY(1);
     while(1) {
-        myled = 1;
-        DELAY(250);
+        led2 = !led2;
+        DELAY(1000);
     }
 };
 // ======================================================
 // Task 1
 // ======================================================
 void COOS_task1(void){
-    DELAY(100);
     while(1){
-        myled = 0;
-        DELAY(255);
+        led1 = !led1;
+        DELAY(500);
     }
 };
 // ======================================================
@@ -85,14 +75,14 @@
 // ======================================================
 // Shutdown task No
 // ======================================================
- void shutdown_task(uchar task_No) {
+ void shutdown_task(int task_No) {
     COOS_task_delay[task_No] = STOP;        // sleep forever
 }
 
 // ======================================================
 // Wake-up task No
 // ======================================================
-void wake_up_task(uchar task_No) {
+void wake_up_task(int task_No) {
     if (COOS_task_delay[task_No] < 0){
         COOS_task_delay[task_No] = 0;       // run
     }           
--- a/typedef.h	Mon Sep 16 11:57:29 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#ifndef __TYPEDEF_H
-#define __TYPEDEF_H
-
-//##########################################################
-// def & enum
-//##########################################################
-enum {
-    OK      =   0,
-    ERR     =   0xEE,
-
-    INVALID =   0,
-    VALID   =   1,
-
-    OFF     =   0,
-    ON      =   1
-};
-
-//##########################################################
-// typedef
-//##########################################################
-typedef unsigned char uchar;
-typedef signed   char schar;
-typedef unsigned int  uint;
-typedef signed   long slong;
-typedef unsigned long ulong;
-
-
-#endif /* __TYPEDEF_H */