#include <stdio.h>
#include <time.h>

#include <rtkernel.h>		/* RTKernel main header file	*/


#define MAIN_PRIORITY      3        /* priorities of main task  */
#define CLOCK_PRIO     MAIN_PRIORITY + 1    /* priorities of main task  */

#define DEFAULT_STACK	1024	/* some task need lower than this */
				/* but this is safe value */
#define CLOCK_DELAY	18	/* clock delay */
TaskHandle  ClockHandle;	/* These task handles are used   */
				/* to address the various tasks  */


/*---  Clock task  ---*/
void Clock(void)		/* task to display the time-of-day */
{
   time_t dummy;

   printf("Clock task run.\n");
   RTKProtect8087();		/* coprocessor is used by Ticks() */
   while (True)
   {
	time(&dummy);
	printf("<task Clock> : %-10li,\tDOS time-of-day: %s",
		RTKGetTime(), asctime(localtime(&dummy)) );
	RTKDelay(CLOCK_DELAY);	/* delay 1 second */
   }
}

/*---   Main task   ---*/
int main(int argc)
{
   /* Most of RTKernel's modules must be initialized before they  */
   /* can be used.                                                */

   RTKernelInit(MAIN_PRIORITY); /* initial RTKernel and set priority MAIN_PRIORITY to main task */
                                /* This mean switch task interval 10 ms */

   printf("Main task create Clock task\n");
   ClockHandle  = RTKCreateTask(Clock, CLOCK_PRIO, DEFAULT_STACK, "Uhranzeige");

   do {
     printf("Main task wait key stroke\n");
     delay(1000);
   } while(!kbhit());			/* wait key stroke */
   printf("Main task Finish\n");

   return 0;
}

