- /* Output Welcome Message */
- Puts4(" \n\n");
- Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
-
- /* Do BlankCheck on Sector at 0xA0000 */
- Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");
- error = FLASH_SectorBlankCheck(0xA0000, 0x4000);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- Puts4("failed.\n");
- }
-
- /* Show Current Content of 0xA0000 ... 0xA001F */
- i=0;
- Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
- while(i < 0x20)
- {
- Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4(" ");
- i++;
- if( (i % 0x10) == 0 ) Puts4("\n");
- }
- Puts4("\n");
-
- /* SectorErase of FLASH Memory 0xA0000*/
- Puts4("Sector Erase of 0xA0000 ... ");
- error = FLASH_SectorErase(0xA0000);
- error = FLASH_SectorErase(0xA0004);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- global_error = 1;
- Puts4("failed.\n");
+ while(running) {
+ cleardata();
+ increaseled();
+
+ switch(recvbyte()) {
+ case 0x15: //chip erase
+ Putch4(0x45);
+ increaseled();
+ if(FLASH_ChipErase() != 1) {
+ panic();
+ }
+ Putch4(0x23);
+ break;
+
+ case 0x12: //erase
+ Putch4(0x11);
+ address = recvdword();
+ increaseled();
+
+ size = recvword();
+ increaseled();
+
+ PDR14 = 0xff;
+ for(i=0; i<(size+4); i+=4) { /* erase */
+ if(FLASH_SectorErase(address + i) != 1) {
+ panic();
+ }
+ increaseled();
+ }
+ Putch4(0x18); //Erasing done.
+ break;
+
+ case 0x13: //receive
+ Putch4(0x37);
+ increaseled();
+
+ address = recvdword();
+ increaseled();
+
+ size = recvword();
+ increaseled();
+
+ PDR14 = 0xff;
+ for(i=0; i<size; i++) { /* get data */
+ increaseled();
+ data[i] = recvbyte();
+ }
+
+ PDR14 = 0xff;
+ for(i=0; i<size; i+=2) { /* flash the data */
+ increaseled();
+ next = (((unsigned short)data[i])<<8) | (unsigned short)data[i+1];
+ if(FLASH_WriteHalfWord(address + i, next) != 1) {
+ panic();
+ }
+ }
+ break;
+
+ case 0x23: //ack it
+ Putch4(0xaa);
+ break;
+
+ case 0x97: /* exit and restart (let do this by the watchdog)! */
+ while(1) {
+ increaseled();
+ }
+
+ case 0x99: /* exit */
+ running = 0;
+ break;
+ default: break;
+ }