/*
WFLASH2.C

This program illustrates how to write to the second flash on the LP31xx.
With a second flash installed, the program should print "test XXXXXXXX"
when the string at address XXXXXXXX is retrieved.

*/
#use eziolp31.lib

main() {
	auto char strbuf[50];
	auto unsigned count;
	struct _flashInfo pInfo;
   unsigned long cur_addr;
   int i;

	_GLOBAL_INIT();

  // check to see that 2nd flash exists
   if ( sysChk2ndFlash ( &pInfo ) != 0 ) {	//	check if the second flash exists
		printf( "Do not have 2nd Flash - cannot continue!!" );
		exit(0);							//	no second flash, exit program now
   }

	hitwd();
	cur_addr = 0x40000;									//	start at 0x40000
	printf ( "Start test:\n" );
	for ( i = 0; i < 10; i++ ) {
		sprintf ( strbuf, "Test %08lx", cur_addr );	//	location dependent info
		sysRoot2FXmem( &pInfo, strbuf, cur_addr, 16 );	//	write to flash
		printf ( "\nwriting to 0x%08lx", cur_addr );		//	feedback on STDIO
		cur_addr += 16;										//	increment location
		hitwd();
	}
	hitwd();
	printf ( "\n\nreading from 2nd flash\n");
	hitwd();
	cur_addr = 0x40000;									//	start reading back
	for ( i = 0; i < 10; i++ ) {
		xmem2root ( cur_addr, strbuf, 16 );
		printf ( "\n0x%08lx reads \"%s\"", cur_addr, strbuf );
		cur_addr += 16;
		hitwd();
	}

}
