#include #include #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include "RS_download.h" #define INFO_LEN 10 #define GERDAT_LEN 131 #define KONFIG_LEN 86 void Cominit(void); void ReadconvHexload(void); void loadnsendMON(void); void load_application(void); void get_box_info(char *info_buf); void check_info(char *info_buf,char *cpu_file,char *dsp_file,char *info_ok); void boot_cpu(unsigned int filesize); void getPMbytes(unsigned int filesize); void getDMbytes(unsigned int filesize); void PMwrite(void); void DMwrite(void); void boot_dsp(void); void reset_mbx(void); void close_all(void); static int panelHandle,mbarHandle; unsigned char COMNUM=1,comstate=0; unsigned char fname[260],charbuf[3000000],PMbytebuf[49152],DMbytebuf[32768],Bytebuf[0x20000]; int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "RS_download.uir", main_pan)) < 0) return -1; mbarHandle = LoadMenuBar (panelHandle, "RS_download.uir", menu); SetCtrlAttribute (panelHandle, main_pan_boot_msg, ATTR_VISIBLE, 0); //SetCtrlAttribute (panelHandle, main_pan_boot_msg, ATTR_WRAP_MODE,VAL_LINE_WRAP); SetCtrlAttribute (panelHandle, main_pan_boot_msg, ATTR_VISIBLE_LINES, 10); ResetTextBox (panelHandle, main_pan_boot_msg, ""); DisplayPanel (panelHandle); MessagePopup ("important information", "Dies ist ein download-tool für Memobox 30x/40x.\n Bitte folgen Sie genau den Anweisungen! "); MessagePopup ("instruction", "Verbinden Sie die Memobox mit COM1 oder COM2 Ihres PC.\n Stellen Sie die entsprechende COM mit 'COM-Einstellung'im Menü ein! "); RunUserInterface (); return 0; } void CVICALLBACK ex (int menuBar, int menuItem, void *callbackData, //close application int panel) { QuitUserInterface (0); if(comstate!=0){ComSetEscape (COMNUM, 6); CloseCom(COMNUM); } } void CVICALLBACK comp2 (int menuBar, int menuItem, void *callbackData,//set com int panel) {int state2,state1; GetMenuBarAttribute (mbarHandle, menuItem, ATTR_CHECKED, &state2); GetMenuBarAttribute (mbarHandle, menu_comp_comp1, ATTR_CHECKED, &state1); if(state2 == 1) return; SetMenuBarAttribute (mbarHandle, menuItem, ATTR_CHECKED, 1); SetMenuBarAttribute (mbarHandle,menu_comp_comp1 , ATTR_CHECKED, 0); COMNUM=2; Cominit(); return; } void CVICALLBACK comp1 (int menuBar, int menuItem, void *callbackData, //set com int panel) {int state2,state1; GetMenuBarAttribute (mbarHandle, menuItem, ATTR_CHECKED, &state1); GetMenuBarAttribute (mbarHandle, menu_comp_comp2, ATTR_CHECKED, &state2); if(state1 == 1) return; SetMenuBarAttribute (mbarHandle, menuItem, ATTR_CHECKED, 1); SetMenuBarAttribute (mbarHandle, menu_comp_comp2, ATTR_CHECKED, 0); COMNUM=1; Cominit(); return; } //Fast-Boot Routine (main programm) void CVICALLBACK FB (int menuBar, int menuItem, void *callbackData, int panel) { unsigned char initout1[32]={0xE6,0x03,0x03,0x0,0xE6,0xF0,0x60,0xFA,0x9A,0xB7,0xFE,0x70,0x7E,0xB7,0xA4,0x0,0xB2,0xFE,0x86,0xF0,0x5F,0xFC,0x3D,0xF8,0xFA,0x0,0x60,0xFA,0xCC,0x00,0xCC,0}; char resp; int n; if(comstate==0){MessagePopup ("instruction", " Sie haben keine Verbindung (COM) ausgewählt !\n Setzen Sie erst die Verbindung mit der Com-Einstellung im Menü! "); return; } SetCtrlAttribute (panelHandle, main_pan_boot_msg, ATTR_VISIBLE, 1); FlushInQ (COMNUM); ComWrtByte(COMNUM,0x00); /*0-Byte zu C161*/ InsertTextBoxLine (panelHandle, main_pan_boot_msg, 0, "Versuche Verbindung aufzubauen..."); ReadconvHexload(); /*Hexloader-Assembling in Bytebuf*/ ProcessDrawEvents(); Delay(0.5); if(GetInQLen (COMNUM)!=0){resp = ComRdByte (COMNUM); /*Identifikations-Byte*/ ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 0, "Versuche Verbindung aufzubauen...ok!"); for (n=0;n<32;n++)ComWrtByte(COMNUM,initout1[n]); /*Preloader downloaden*/ Delay(0.5); for (n=0;n<512;n++)ComWrtByte(COMNUM,Bytebuf[n]); /*Hexloader downloaden*/ InsertTextBoxLine (panelHandle, main_pan_boot_msg, 1, "Hexloader downloaded!"); InsertTextBoxLine (panelHandle, main_pan_boot_msg, 2, "loading monitor..."); ProcessDrawEvents(); loadnsendMON(); /*ladet Monitor ins externe RAM*/ load_application(); } else {ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 0, "Versuche Verbindung aufzubauen...fehlgeschlagen!"); // MessagePopup ("information"," Some of the first seria of memoboxes can cause troubles with communication.\n Disconnect the box from mains,\n wait for aprox. 1 minute and reconnect the box.\n Then try again with 'Boot mbx300'. "); SetCtrlAttribute (panelHandle, main_pan_boot_msg, ATTR_VISIBLE, 0); ResetTextBox (panelHandle, main_pan_boot_msg, ""); return; } } void Cominit(void) {int status; status=OpenComConfig (COMNUM, "", 115200, 0, 8, 1, 1500, 1500); if(status <0){ MessagePopup ("error", " COM error!\n Möglicherweise benutzen andere Programme diese COM!\n Schließen Sie diese und versuchen Sie es erneut!"); close_all(); return; } ComSetEscape (COMNUM, 4); comstate=1; MessagePopup ("instruction", " 1.)Memobox vom Netz trennen \n 2.)Nach ca. 5s wieder ans Netz!\n 3.)Drücken Sie dann 'Download memobox'! "); } void ReadconvHexload(void) /*Konvertiert das Hex-File in Bytebuffer*/ { char fname[27]="hexload.h86"; char tempbuf[5]; int indno[20],i,j,startind=0,tempvar,NumofRec,NoofBytes,Startadr,Rectype,tempval,n; unsigned int filesize,filehandle; filehandle = OpenFile (fname, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); GetFileInfo (fname, &filesize); ReadFile (filehandle, charbuf, filesize); CloseFile (filehandle); n=0; while(FindPattern (charbuf,startind, filesize-startind, ":", 0, 0)>=0){ indno[n] = FindPattern (charbuf,startind, filesize, ":", 0, 0); startind=indno[n]+1; n++;} NumofRec=n; /*Anzahl der Records bzw. Doppelpunkte*/ j=0; for (n=0;n=0){ indno[n] = FindPattern (charbuf,startind, filesize, ":", 0, 0); startind=indno[n]+1; n++;} NumofRec=n; /*Anzahl der Records bzw. Doppelpunkte*/ for (n=0;n>8; ADR23_16=Adroffset; ADR15_8=Startadr>>8; ADR7_0=Startadr; D7_0=tempval; Checksum +=D7_0; ComWrtByte(COMNUM,0x70); ComWrtByte(COMNUM,ADR31_24); ComWrtByte(COMNUM,ADR23_16); ComWrtByte(COMNUM,ADR15_8); ComWrtByte(COMNUM,ADR7_0); ComWrtByte(COMNUM,D7_0); Startadr ++; } break; case 04: CopyString (tempbuf, 0, charbuf, (indno[n]+9), 4); sscanf (tempbuf, "%x", &Adroffset); break; case 01: ComWrtByte(COMNUM,'e'); FlushInQ (COMNUM); Delay(0.5); n=NumofRec; /*sicherer Abbruch*/ if(GetInQLen (COMNUM)!=0){tempval=ComRdByte(COMNUM); if((Checksum&0x00FF)==(tempval&0x00FF)) { ComWrtByte(COMNUM,0x1B); Delay(0.5); if(GetInQLen (COMNUM)==0){ MessagePopup ("error", " No response from box!\n Sorry, there is no download possible!"); close_all(); return; } FlushInQ (COMNUM); DeleteTextBoxLine (panelHandle, main_pan_boot_msg, 2); InsertTextBoxLine (panelHandle, main_pan_boot_msg, 2, "lade Monitor...ok!"); ProcessDrawEvents(); return; } else DeleteTextBoxLine (panelHandle, main_pan_boot_msg, 2); InsertTextBoxLine (panelHandle, main_pan_boot_msg, 2,"loading monitor...failed!"); MessagePopup ("error", " Checksum error!\n Check if other programs are using the same COM!\n Close this programs and try again!"); close_all(); return; } else {DeleteTextBoxLine (panelHandle, main_pan_boot_msg, 2); InsertTextBoxLine (panelHandle, main_pan_boot_msg, 2,"loading monitor...failed!"); MessagePopup ("error", " No response from box!\n Check if other programs are using the same COM!\n Close this programs and try again!"); close_all(); } break; } } } void load_application(void) {char info_buf[INFO_LEN],info_ok=0; char cpu_file[260],dsp_file[13],string_msg[70]="lese CPU file: ",dsp_msg[50]="reading DSP file: "; unsigned int filehandle,filesize,fileend; //get_box_info(info_buf); //check_info(info_buf,cpu_file,dsp_file,&info_ok); //dsp_file[12]=0; //cpu_file[12]=0; if(info_ok ==0) {FileSelectPopup ("", "*.H86", "*.*", "", VAL_LOAD_BUTTON, 0, 0, 1, 1, cpu_file); if(*cpu_file == *"")return; filehandle = OpenFile (cpu_file, VAL_READ_ONLY, VAL_OPEN_AS_IS,VAL_ASCII); if(filehandle == -1){ MessagePopup ("error", " CPU file not found in current directory!\n Sorry, there is no download possible!"); close_all(); return; } GetFileInfo (cpu_file, &filesize); ReadFile (filehandle, charbuf, filesize); CloseFile (filehandle); sprintf (&string_msg[15], "%s", cpu_file); InsertTextBoxLine (panelHandle, main_pan_boot_msg,3,string_msg); InsertTextBoxLine (panelHandle, main_pan_boot_msg,4,"Lösche Flash-Speicher..."); ProcessDrawEvents(); boot_cpu(filesize); /* filehandle = OpenFile (dsp_file, VAL_READ_ONLY, VAL_OPEN_AS_IS,VAL_ASCII); if(filehandle ==-1){ MessagePopup ("error", " DSP file not found in current directory!\n Sorry, there is no download possible!"); close_all(); return; } GetFileInfo (dsp_file, &filesize); ReadFile (filehandle, charbuf, filesize); CloseFile (filehandle); fileend=FindPattern (charbuf,0, filesize, "o", 0, 0); filesize=fileend; sprintf (&dsp_msg[18], "%s", dsp_file); InsertTextBoxLine (panelHandle, main_pan_boot_msg, 8,dsp_msg); ProcessDrawEvents(); getPMbytes(filesize); getDMbytes(filesize); boot_dsp();*/ // InsertTextBoxLine (panelHandle, main_pan_boot_msg, 7,"download fertig!"); reset_mbx(); } else{ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 3, "trying to get info about box...failed"); ProcessDrawEvents(); MessagePopup ("error", " The connected mbx30x/40x contains no proper device data!\n Sorry, there is no download possible!"); close_all(); } } void get_box_info(char *info_buf) { char gerdat_buf[GERDAT_LEN],konfig_buf[KONFIG_LEN]; char type_buf[15]="box type: "; char func_buf[25]="meas. function: "; InsertTextBoxLine (panelHandle, main_pan_boot_msg, 3, "trying to get info about box..."); ProcessDrawEvents(); FlushInQ (COMNUM); ComWrtByte(COMNUM,'y'); while(GetInQLen (COMNUM) '4')*info_ok=0; if(info_buf[5] < '5' || info_buf[5] > '6')*info_ok=0; } void boot_cpu(unsigned int filesize) { unsigned long MAXADR=0x20000; char tempbuf[5],Adressstring[6],resp; unsigned int indno[10000],i,startind=0,NumofRec,NoofBytes,Rectype,n,Adroffset,Startadr,tempval,Checksum=0; char c,Command,Blocknum[3],blocknr,string_msg[40]="CPU-file download..."; unsigned int progress; ComWrtByte(COMNUM,'B'); FlushInQ (COMNUM); n=0; while(FindPattern (charbuf,startind, filesize-startind, ":", 0, 0)>=0){ indno[n] = FindPattern (charbuf,startind, filesize, ":", 0, 0); startind=indno[n]+1; n++;} NumofRec=n; /*Anzahl der Records bzw. Doppelpunkte*/ for (n=0;n0xEFFF && n<0x10000)n=0x10000; ComWrtByte(COMNUM,'W'); ComWrtByte(COMNUM,'R'); ComWrtByte(COMNUM,'8'); ComWrtByte(COMNUM,'0'); sprintf (Adressstring,"%05x", n); ComWrtByte(COMNUM,Adressstring[0]); ComWrtByte(COMNUM,Adressstring[1]); ComWrtByte(COMNUM,Adressstring[2]); ComWrtByte(COMNUM,Adressstring[3]); ComWrtByte(COMNUM,Adressstring[4]); for(i=0;i<0x80;i++)ComWrtByte(COMNUM,Bytebuf[n+i]); resp=ComRdByte (COMNUM); if(resp != 'o'){printf("\n Error occured!! %u",resp); n=MAXADR; } else{n+=0x80; if((n%0x200)==0){progress= (n*100)/MAXADR; sprintf (&string_msg[20], "%2u%%", progress); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg,5, string_msg); ProcessDrawEvents(); } } } ComWrtByte(COMNUM,'c'); sprintf (&string_msg[20], "%s", "fertig!"); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 5, string_msg); ProcessDrawEvents(); end:; } void getPMbytes(unsigned int filesize) { int n,i,paind[100],startind,segadr[100][2]; unsigned long tempvar,j; unsigned char tempbuf[7]; int vis=1; n=0; startind=0; while(FindPattern (charbuf,startind, filesize-startind, "@PA", 0, 0)>=0){ paind[n] = FindPattern (charbuf,startind, filesize, "@PA", 0, 0); startind=paind[n]+3; segadr[n][1]=paind[n]+9; /*ab hier PM-Daten*/ n++;} for (i=0;i>16); j++; PMbytebuf[segadr[i][0]*3+j]= (tempvar>>8); j++; PMbytebuf[segadr[i][0]*3+j]= (tempvar) & 0x0000FF; j++; startind +=7; } } } void getDMbytes(unsigned int filesize) {int n,i,paind[200],startind,segadr[200][2]; unsigned long tempvar,j; unsigned char tempbuf[7]; n=0; startind=0; while(FindPattern (charbuf,startind, (filesize-startind), "@DA", 0, 0)>=0){ paind[n] = FindPattern (charbuf,startind, filesize, "@DA", 0, 0); startind=paind[n]+3; segadr[n][1]=paind[n]+9; /*ab hier DM-Daten*/ n++;} for (i=0;i>8); j++; DMbytebuf[segadr[i][0]*2+j]= tempvar; j++; startind +=5; } } } void PMwrite(void) {int i,n; unsigned char csum,chekvar,string_msg[40]="downloading DSP program memory..."; ComWrtByte(COMNUM,0x03); while((csum=ComRdByte(COMNUM))!=0x02); InsertTextBoxLine (panelHandle, main_pan_boot_msg,9,string_msg); for(i=0;i<16;i++){ do{ csum=0; for(n=0;n<3072;n++){ComWrtByte(COMNUM,PMbytebuf[3072*i+n]); csum+=PMbytebuf[3072*i+n];} ComWrtByte(COMNUM,csum); while(GetInQLen (COMNUM)==0); chekvar=ComRdByte(COMNUM); }while(chekvar!=0x09); sprintf (&string_msg[33], "%2u%%", ((i*100)/16)); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 9, string_msg); ProcessDrawEvents(); } /*Prüfsumme falsch,3072 Bytes nochmal senden*/ sprintf (&string_msg[33], "%s", "done!"); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 9, string_msg); ProcessDrawEvents(); } void DMwrite(void) {int i,n; unsigned char csum,chekvar,string_msg[40]="downloading DSP data memory..."; ComWrtByte(COMNUM,0x03); while(ComRdByte(COMNUM)!=0x02); InsertTextBoxLine (panelHandle, main_pan_boot_msg,10,string_msg); for(i=0;i<16;i++){ do{ csum=0; for(n=0;n<2048;n++){ComWrtByte(COMNUM,DMbytebuf[2048*i+n]); csum+=DMbytebuf[2048*i+n]; } ComWrtByte(COMNUM,csum); while(GetInQLen (COMNUM)==0); chekvar=ComRdByte(COMNUM); }while(chekvar!=0x09); sprintf (&string_msg[30], "%2u%%", ((i*100)/16)); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 10, string_msg); ProcessDrawEvents (); } /*Prüfsumme falsch,1024 Bytes nochmal senden*/ sprintf (&string_msg[30], "%s", "done!"); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 10, string_msg); ProcessDrawEvents(); } void boot_dsp(void) {char resp; FlushInQ (COMNUM); ComWrtByte(COMNUM,'D'); Delay(0.5); while(ComRdByte (COMNUM)!=0x06); ComWrtByte(COMNUM,0x03); if((resp=ComRdByte(COMNUM))== 0x02){PMwrite(); DMwrite(); ComWrtByte(COMNUM,0x03); } } void reset_mbx(void) {char resp; InsertTextBoxLine (panelHandle, main_pan_boot_msg, 6,"Führe Reset durch..."); ProcessDrawEvents(); ComWrtByte(COMNUM,'R'); Delay(3); ComWrtByte(COMNUM,0x1B); while(GetInQLen (COMNUM)==0){Delay(0.3); ComWrtByte(COMNUM,0x1B); } while((resp=ComRdByte(COMNUM))!= '+'); ComWrtByte(COMNUM,'R'); while((resp=ComRdByte(COMNUM))!= '+'); ReplaceTextBoxLine (panelHandle, main_pan_boot_msg, 6,"Führe Reset durch...ok!"); ProcessDrawEvents(); MessagePopup ("information", "Download erfolgreich beendet!"); close_all(); } void close_all(void) { QuitUserInterface (0); if(comstate!=0){ComSetEscape (COMNUM, 6); CloseCom(COMNUM); } }