/***************************************************************

   FlashLEDS2.c
   Zworld, 2000

   Rabbit 2000 Core Module Demo board example program

   This program flashes the DS2 and DS3 LED's on the Rabbit
   2000 Core Module Prototyping board (PA0 and PA1 ports on
   the Rabbit Core Module).
   It also demonstrates coding with cofunctions and
   costatements.

****************************************************************/

///// predefines for the leds and switches
#define DS2 0
#define DS3 1

///// This cofunction which flashes the led on for ontime then
///// off for offtime
cofunc flashled[4](int led, int ontime, int offtime)
{
	for(;;) {
		waitfor(DelayMs(ontime));									//on delay
		WrPortI(PADR, &PADRShadow, (1<<led)|PADR);			//turn led off
		waitfor(DelayMs(offtime));									//off delay
		WrPortI(PADR, &PADRShadow, ((1<<led)^0xff)&PADR);	//turn led on
	}
}


main()
{
	//initialize ports
	WrPortI(SPCR, &SPCRShadow, 0x84);		//set port a all outputs, leds on
	WrPortI(PEFR, &PEFRShadow, 0x00);		//set port e normal i/o
	WrPortI(PEDDR, &PEDDRShadow, 0x01);		//set port e bits 7..1 inputs, 0 output
	WrPortI(PECR, &PECRShadow, 0x00);		//set transfer clock as pclk/2
	
	for(;;) {										//run forever
		costate {									//start costatement
			wfd {										//use wfd (waitfordone) with cofunctions
				flashled[0](DS2,200,200);		//Flash DS2 on 200ms, off 200ms
				flashled[1](DS3,1000,500);		//Flash DS3 on 1000ms, off 500ms
				}
		}												//end costatment
	}													//end for loop
}