/* WRFLASH.C

 This program demonstrates how to write information into the second
 flash EPROM (if equipped) and read the information back. To initialize,
 call sysChk2ndFlash to initialize parameters of the second flash,
 to write information to the flash, use sysRoot2FXmem (much like root2xmem,
 but writes to flash space instead of RAM space). To read information from
 the flash to root space, use xmem2root.
*/

#use eziolp31.lib
#use xmem.lib

main() {
  char strbuf[50];
	struct _flashInfo pInfo;
   unsigned long cur_addr;
   int i;

	_GLOBAL_INIT();

  // check to see that 2nd flash exists
   if ( sysChk2ndFlash ( &pInfo ) != 0 ) {
    printf( "Do not have 2nd Flash - cannot log data!!" );
   }

    hitwd();
    cur_addr = 0x40000;
    sprintf ( strbuf, "Test 2nd flash\r\n" );
    printf ( "Starting logging test\n" );
    for ( i = 0; i < 10; i++ ) {
       sysRoot2FXmem( &pInfo, strbuf, cur_addr, 16 );
       printf ( "\ncur_addr = %ld", cur_addr );
       cur_addr += 16;
       hitwd();
    }
    hitwd();
    printf ( "\nreading from 2nd flash\n");
    hitwd();
    cur_addr = 0x40000;
    for ( i = 0; i < 10; i++ ) {
       xmem2root ( cur_addr, strbuf, 16 );
       printf ( "\n%3d %7ld : %s", i, cur_addr, strbuf );
       cur_addr += 16;
       hitwd();
   }

}
