|
The C Kernel application program Examples PC/MSDOS command prompt Life example: Moving lifeforms on your DOS desktop ! Each lifeform is a task, that is created , lives and dies after a certain time. The program runs best in DOS maximized mode (ALT+ENTER). Press <F1> for a short help window and summary of key commands. Life.exe. Get the full project example in the download section.
Simple Main program example: /****************************************************************************/ void main (void) /****************************************************************************/ { /**** Initialize the C Kernel ****/ CK_Init ();
/**** Create the tasks to be used ****/ CK_CreateTask (runLedTask, 20, RunLedTaskStack, 200); CK_CreateTask (outputTask, 100, OutputTaskStack, 200);
/**** Create semaphore which will be signaled by a timer ****/ Output_SM = CK_CreateSema (0, PRIO_Q); Output_TM = CK_CreateTimer (); CK_StartTimer (Output_TM, MS_TO_KERNELCOUNT (1000), Output_SM);
/**** Initialize Resource Reporter Task ****/ ReportInit ();
/**** Start the C Kernel; start scheduler and tasks ****/ CK_Run (); /**** Never to return here ****/ }
Task functions used in Main program example: /****************************************************************************/ static void runLedTask (void) /****************************************************************************/ { bool runLed;
/**** Initialize task data first ****/ runLed = FALSE; /**** Enter task main forever loop ****/ forever { /**** Toggle run led flag ****/ runLed = !runLed; /**** Using flag set the run led output state ****/ if (runLed) RUN_LED = OUTPUT_ON; else RUN_LED = OUTPUT_OFF;
/**** Go to SLEEP state for 0.5 seconds ****/ CK_Sleep (MS_TO_KERNELCOUNT (500)); } } /****************************************************************************/ static void outputTask (void) /****************************************************************************/ { forever { /**** Wait for the output semaphore to be signaled; done by timer ****/
CK_Wait (Output_SM); /**** Perform the required output action ****/ OUTPUT1 = !OUTPUT1; } } Top
|