//bw_meter_fw.c

//simple firmware to measure the bandwidth of the USB interface

//             (C) Marko Cebokli S57UUU  Aug 2006 
//             GNU/GPL licence:  www.gnu.org/licences/licences.html#GPL

//Compile with SDCC:     sdcc -mmcs51 bw_meter_fw.c

#define ALLOCATE_EXTERN
#include "fx2regs2.h"

//#define NOP   _asm \ nop; \ nop; \ _endasm;		//for IFCLK=48,  CPUCLK=12
#define NOP   _asm \ nop; \ nop; \ nop; \ _endasm;	//for IFCLK=48,  CPUCLK=48
#undef NOP
#define NOP

void main(void)
{
unsigned char i;

REVCTL=0x03;NOP;
CPUCS=0x12;NOP;			//crank up CPU to 48MHz

while (1)
	{
	while (EP8CS & bmBIT3){}		//wait for available buffer
	EP8FIFOBUF[0]=i;
	i++;
	EP8BCH=0x02;
	EP8BCL=0x00;NOP;		//arm endpoint
	}

}
