/* Program to copy a ROM pgm from SRAM to ROM */ /* To properly execute this pgm: - make this (fmu) pgm with an srec start @ $80000 - make the rom pgm with an srec start @ $0 - load fmu pgm into cpu32 thru bdm with 0 offset - load rom pgm into cpu32 thru bdm with $a0000 offset - clear the area from $90000 to $90050 (so cam monitor flags) - go $80000 - monitor for finished by checking flag=2 & fcount=0 (no errors) - take care after running this pgm to not reset, else will again download to rom. As soon as finished, download some other program in the space assigned for this program. */ struct variables { unsigned short int *start_addr; unsigned short int data; int rom_addr,addr,flag,no_words,i,j,t, setw,fcount; unsigned short int data_rdbk[50]; }; #define vp (*(struct variables *)0x090000) fmu() { vp.start_addr = (short int *)0x0A0000; /* start addr of data or pgm in sram which is to be copied into rom */ vp.rom_addr = 0x000000; /* rom start addr */ vp.no_words = 1000; /* max no of words to be copied */ vp.flag = 0; vp.fcount = 0; erase(); vp.flag = 1; for (vp.i = 0;vp.i < vp.no_words;vp.i++) { vp.addr = vp.rom_addr + 2*vp.i; vp.data = *(vp.start_addr + vp.i); program_word(); if(vp.setw == 0) /* try 1 more time-need for 1st byte */ program_word(); if(vp.setw == 0) vp.fcount++; /* error count */ } vp.flag = 2; while(1); } erase() { /* chip erase: shift addresses left 1 bit since a0 not connected to rom; send unlock codes to both rom banks (1st 2 bytes go to 1st rom bank via d0-7, 2nd pair to 2nd rom bank via d8-15 */ *(unsigned volatile short int *)(0x5555<<1)=0xaaaa; *(unsigned volatile short int *)(0x2aaa<<1)=0x5555; *(unsigned volatile short int *)(0x5555<<1)=0x8080; *(unsigned volatile short int *)(0x5555<<1)=0xaaaa; *(unsigned volatile short int *)(0x2aaa<<1)=0x5555; *(unsigned volatile short int *)(0x5555<<1)=0x1010; /* Poll til chip erased (d7=1; d15=1) */ while (!((*(unsigned volatile short int *)0x0) & 0x8080)); return; } program_word() { vp.setw = 0; /* Shift addresses left 1 bit since a0 not connected to rom; send unlock codes to both rom banks (1st 2 bytes go to 1st rom bank via d0-7, 2nd pair to 2nd rom bank via d8-15 */ *(unsigned volatile short int *)(0x5555<<1)=0xaaaa; *(unsigned volatile short int *)(0x2aaa<<1)=0x5555; *(unsigned volatile short int *)(0x5555<<1)=0xa0a0; /* don't shift address of data, since cpu won't shift when tries to read rom */ *(unsigned volatile short int *)(vp.addr)=vp.data; /* Poll til word is set in rom */ for (vp.t = 0; vp.t < 100000; vp.t++) { if(vp.t < 47)vp.data_rdbk[vp.t] = *(unsigned volatile short int *)vp.addr; /* next 2 shoul show when toggling stops */ vp.data_rdbk[47] = *(unsigned volatile short int *)vp.addr; vp.data_rdbk[48] = *(unsigned volatile short int *)vp.addr; if(vp.t == 49)vp.data_rdbk[vp.t] = *(unsigned volatile short int *)vp.addr; if((*(unsigned volatile short int *)vp.addr) == vp.data ) { vp.setw = 1; /* successfully set word */ return; } } return; }