/* 
   Test of round-robin scheduler.
   Last updated 29.10.00.
 */

#include "RCX_String.h"
#include "RCX_Control.h"
#include "H8.h" 
#include "Time.h"
#include "LCD.h"
#include "Battery.h"
#include "Buttons.h"

#include "RoundRobinScheduler.h"

#define  forever  while (1)

static semaphore  LCDAccess;

/******* Reset Process ***************************************************/  

void ResetProcess( void )
{
  while ( ! Prgm ) ;

  SchedulerClose();
  RCX_Reset();
}


/******* Process  1   ***************************************************/  

void Process1( void )
{
  forever {
    Wait(& LCDAccess);
      lcd_show_int16(MSCount); lcd_show_digit(Current);
    Signal(& LCDAccess);
  }
}

/******* Process  2   ***************************************************/  

void Process2( void )
{
  forever {
    Wait(& LCDAccess);
      lcd_show_int16(MSCount); lcd_show_digit(Current);
    Signal(& LCDAccess);
  }
}

void _start(void) 
{  

  lcd_show_int16(BatteryLevel());
  lcd_show_icon(LCD_STANDING);
  while ( ! Run );
  while (   Run );
  lcd_show_icon(LCD_WALKING);

  LCDAccess = 1;

  SchedulerInit();
  StartProcess( ResetProcess);
  StartProcess( Process1);
  StartProcess( Process2);

  forever {
    Wait(& LCDAccess);
      lcd_show_int16(MSCount); lcd_show_digit(Current);
    Signal(& LCDAccess);
  }
}	
