#include <stdio.h>
#include "rtkernel.h"
#include "rtkeybrd.h"

#define MAIN_PRIORITY 3

Semaphore  S;

void TaskA(void)
{
   int count=0;
   printf("<Task A> is waiting at semaphore S\n");
   do {
     RTKWait(S);          // wait signal from Semaphore S
     printf("<Task A> call %d\n",++count);
   } while(count<5);
   printf("<Task A> - Finish -\n");
}

void main(void)
{
   char ch;

   RTKernelInit(MAIN_PRIORITY);   // Initialize main task piority
   RTKeybrdInit();               // Initialize RTKernel keyboard module

   S = RTKCreateSema(Counting, 0);      // create counting semaphore
   RTKCreateTask(TaskA, MAIN_PRIORITY+1, 1024, "Task A"); // create Task A

   do {
      printf("\n* main * Please enter a charactera [Exit='A']\n");
      ch = RTGetCh();        // same as getch() but it is not load CPU time
      printf("* main * Key pressed: %c\n", ch);
      RTKSignal(S);          // signal Semaphore S
   } while (ch != 'A');
   printf("* main * - Finish -");
}

