/************************************************************************* lbbug.c It is a debugging program of linux version for MC68EZ328 based systems running in bootstrap mode. It is originally provided by Motorla.Because it is a dos programm which operate on serial device,It is very slow in win2k. That is why I ported it to linux. I don't know if there is any license problem.:( Obviously there is no Warranty for lbbug. I do NOT reserve rights. Paul eepaul@cnunint.com ************************************************************************** This program contains 7 major functions: 1.Send File -This is a file sending function, which is to convert s-record to b-record file (if the original copy is in s format), and transmit it through serial port to target board. 2.Memory Display -This function is for reading the code in the Target board memory registers. User can decide which register to read from, and the number of bytes to read. 3.Memory Modify -This function is for editing code into Target board memory registers. User can decide which memory address and what data to write. 4.Program Execution -User can go to specified memory location and execute the program from that register. 5.Baud Rate -Baud rate is preset to 19200. There is a choice of 2 baud rates to be selected. 6.Help -The help menu contains essential information for executing this program. 7.Exit -Exit the program and return to DOS. **************************************************************************/ /*Include Libraries*/ #include #include #include #include #include #include #include #include #include #include /*Definitions - B-record commands for Baud Rates*/ #define div1 "\nFFFFF9020101" #define div0 "\nFFFFF9020100" #define pre26 "\nFFFFF9030126" #define pre38 "\nFFFFF9030138" #define _POSIX_SOURCE 1 #define INIT "init.b" #define MAX_CH 100 #define NotHex 17 #define MAXBUF 255 /* the size of some array */ /*Communication Port Addresses*/ #define TTY0 "/dev/ttyS0" #define TTY1 "/dev/ttyS1" /*Function Prototypes*/ void init_port(void); void menu(void); void scanning(void); void init(void); void sendfile(void); int open_s_file(char *mode, char *filename, char record); int open_b_file(char *mode, char *filename, char record); int open_init_file(void); int ctoi(char); void stob(void); void stobstart(void); void sendbrec(unsigned char *filename); int send(unsigned char *brecord); int address(unsigned char *address); void memdis(void); void memmod(void); void memexe(void); void help(void); void sendb(unsigned char *brecord); /* not used */ int CommTest1(void); void BaudRate1(void); void ChangePCBaud(speed_t newBaud); char *itoa(int num,char *str,int radix); char *ltoa(long num,char *str,int radix); char *strupr(char *str); char *mygets(char *buf,size_t lenOfBuf); void Delay(int timeout); void clean(void); /*Definitions - Global Variables*/ FILE *fp_srec, *fp_brec, *fp_init; char rate1, rate2; char *output,*port_Name=NULL; int LCR,LSR,DATA,BRDL,BRDH,MCR,IER; int n, command1, command2; unsigned char input[MAXBUF], input1[8], input2[MAXBUF], input3[6+1]/* one for '\n' */ , feedback; unsigned char rxbuff[MAXBUF]; int debug_on = 1; int port_fd=-1; struct termios oldtio,newtio; /**************************/ /*This is the main program*/ /**************************/ int main(void) { char c; printf("\n *****************************************************************"); printf("\n * lbbug --- a bootstrap mode debugger in linux for MC68EZ328 *"); printf("\n * *"); printf("\n * Please reset target system to enter Bootstrap mode. For *"); printf("\n * more info regarding bootstrap operation, please refer to *"); printf("\n * M68EZ328 user's manual. *"); printf("\n * *"); printf("\n * Ported by Paul *"); printf("\n * eepaul@cnuninet.com *"); printf("\n *****************************************************************"); printf("\n\n"); do{ port_Name = NULL; printf("\rSelect Serial port(0/1) =>"); fflush(stdout); c=getchar(); if(c!='\n') while(getchar()!='\n'); if(c=='0') port_Name = TTY0; if(c=='1') port_Name = TTY1; }while(!port_Name); init_port(); menu(); debug_on = 0; if(CommTest1()){ printf("\nComm port error.\n"); printf("Please check Comm Port and/or reset target system.\n"); } debug_on = 1; while(1){ printf(" Bootstrap:>"); fflush(stdout); scanning(); strupr(input1); debug_on = 1; /*Set flags for command inputs */ if ((input1[0]=='I')&&(input1[1]=='N')) command1=1; if ((input1[0]=='L')&&(input1[1]=='O')) command1=2; if ((input1[0]=='M')&&(input1[1]=='D')) command1=3; if ((input1[0]=='M')&&(input1[1]=='M')) command1=4; if ((input1[0]=='G')&&(input1[1]=='O')) command1=5; if ((input1[0]=='C')&&(input1[1]=='B')) command1=6; if ((input1[0]=='H')&&(input1[1]=='E')) command1=8; if ((input1[0]=='E')&&(input1[1]=='X')) { printf("bye\n"); clean(); return 0; } debug_on = 0; if(CommTest1()){ printf("Comm port error.\n"); printf("Please check Comm Port and/or reset target system.\n"); } debug_on = 1; switch (command1){ case 1 : init(); break; case 2 : strupr(input3); sendfile(); break; case 3 : memdis(); break; case 4 : memmod(); break; case 5 : memexe(); break; case 6 : debug_on = 0; BaudRate1(); debug_on = 1; break; case 8 : strupr(input2);help(); break; default : if(input1[0] !='\0'){ printf(" Syntax Error\n"); } command1=0; break; } command1=0; } } /*************************************************/ /* This is the function doing some cleaning work */ /************************************************/ void clean(void) { if(port_fd<0) return; /* restore the original configuration of serial port */ tcsetattr(port_fd,TCSANOW,&newtio); tcflush(port_fd,TCIOFLUSH); close(port_fd); } /******************************************/ /*This is the function for initializations*/ /******************************************/ void init_port(void) { port_fd = open(port_Name, O_RDWR | O_NOCTTY ); if (port_fd <0) { perror(port_Name); exit(-1); } rate1='1'; /* set 19200 flag */ tcgetattr(port_fd,&oldtio); bzero(&newtio, sizeof(newtio)); newtio.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD; /*8n1 (8bit,no parity,1 stopbit)*/ newtio.c_iflag = IGNPAR; /* Ignore all frame error and parity error */ newtio.c_oflag = 0; /* set input mode (non-canonical, no echo,...) */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 1; /* timeout 0.1s */ newtio.c_cc[VMIN] = 0; /* */ tcflush(port_fd, TCIOFLUSH); tcsetattr(port_fd,TCSANOW,&newtio); } /*********************************/ /*This is the menu of the program*/ /*********************************/ void menu(void) { printf("********************************************************************\n"); printf("* Welcome to Bootstrap Mode Debugging Program. *\n"); printf("********************************************************************\n"); printf("* Please start up target system in Bootstrap mode. *\n"); printf("* There are 8 options. Please enter the command of your choice: *\n"); printf("* *\n"); printf("* init (file path) -- initialize target system *\n"); printf("* lo (file path) (file type) -- download s- or b-record file *\n"); printf("* md (address) (count) -- memory display *\n"); printf("* mm (address) -- memory modify *\n"); printf("* go (address) -- program execution *\n"); printf("* cb -- change baud rate *\n"); printf("* he (command) -- help *\n"); printf("* exit -- exit the program *\n"); printf("********************************************************************\n\n"); } /* This function is for waiting key-in non-blockingly */ int kbhit(void) { struct pollfd pollstdin; int res; pollstdin.fd=0; /* stdin */ pollstdin.events=POLLIN; res=poll(&pollstdin,1,0); if(res<0 || res>1) { printf("In line %d",__LINE__); perror("poll"); exit(-1); } return res; } /* This Function is for get and change str to Upper Case */ char *strupr(char *str) { int i=0; while(str[i++]) str[i-1]=toupper(str[i-1]); return str; } char *mygets(char *buf,size_t lenOfBuf) { int i; fgets(buf,lenOfBuf,stdin); for(i=0;buf[i]!='\n';i++); buf[i]=0; return buf; } /***************************************************/ /*This function is for manipulating the user inputs*/ /***************************************************/ void scanning(void) { int i=0, shifting=0, lp=1, j=0,res,oldflags; struct pollfd pollfds[2]; input1[0]='\0'; /* Initialize input strings */ input2[0]='\0'; input3[0]='\0'; strcpy(rxbuff,""); rxbuff[MAXBUF]=0; j=0; pollfds[0].fd=0; /* stdin */ pollfds[0].events=POLLIN; pollfds[1].fd=port_fd; /* serial port */ pollfds[1].events=POLLIN; /* change port_fd NON_BLOCK */ oldflags=fcntl(port_fd,F_GETFL); if(oldflags<0) { perror("fcntl"); clean(); exit(-1); } if(fcntl(port_fd,F_SETFL,oldflags | O_NONBLOCK)<0) { perror("fcntl"); clean(); exit(-1); } do { int pollres; #define INFINITE -1 pollres=poll(pollfds,2,INFINITE); if(pollres<0 || pollres>2) { printf("In line %d",__LINE__); perror("poll"); clean(); exit(-1); } if(pollfds[1].revents & POLLIN) /* There is data ready in serial port */ { res=read(port_fd,rxbuff,MAXBUF); if(res<0) { printf("In Line %d ",__LINE__); perror("read"); clean(); exit(-1); } for(j=0;j3){ /*Error message for more than 3 sets of input */ printf(" Syntax Error. Please type your command again.\n"); return; } lp=1; } /**************************************************/ /*This function is for sending init.b to ADS board*/ /**************************************************/ void init(void) { if (input2[0]=='\0'){ if (open_init_file()==0) return; sendbrec(INIT); /*send init.b in the currect directory */ } else sendbrec(input2); /*send the file specified in input2 */ } /********************************************************/ /*This function is for sending s-record or b-record file*/ /********************************************************/ void sendfile(void) { int file_type=-1; if ((input3[0]=='B')&&(input3[1]=='\0')) /* for B-record files */ file_type=1; if ((input3[0]=='S')&&(input3[1]=='\0')) /* for S-record files */ file_type=0; if (((input3[0]!='S')&&(input3[0]!='B'))||(input3[1]!='\0')) { /*invalid record type*/ file_type=2; printf(" Syntax Error. Please type your command again.\n"); return; } if (file_type==1) sendbrec(input2); /*Send B-record specified in input2 */ if (file_type==0){ stobstart(); /*Convert S-record to B-record file */ sendbrec(output); /*Send the converted B-record file */ } } /********************************************/ /*This function is for opening S-record file*/ /********************************************/ int open_s_file(char *mode, char *filename, char record) { if ((fp_srec = fopen(filename, mode))==NULL){ printf("Sorry! Your %c-Record file cannot be open.\n",record); printf("Make sure you type in the correct path.\n"); return 0; } else return 1; } /*********************************************/ /*This function is for opening B-record file */ /*********************************************/ int open_b_file(char *mode, char *filename, char record) { if ((fp_brec = fopen(filename, mode))==NULL){ printf("Sorry! Your %c-Record file cannot be opened.\n",record); printf("Make sure you type in the correct path.\n"); return 0; } else return 1; } /*****************************************************/ /*This function is to open the init.b file in A-drive*/ /*****************************************************/ int open_init_file(void) { if ((fp_init=fopen(INIT,"rb"))==NULL){ printf("\nError. Cannot open init.b in this directory.\n\n"); return 0; } else return 1; } int ctoi(char ch) { switch(ch){ case'0': return 0; case'1': return 1; case'2': return 2; case'3': return 3; case'4': return 4; case'5': return 5; case'6': return 6; case'7': return 7; case'8': return 8; case'9': return 9; case'A': return 10; case'B': return 11; case'C': return 12; case'D': return 13; case'E': return 14; case'F': return 15; } return(NotHex); } char *itoa(int num,char *str,int radix) { char *format=NULL; if(radix==16) format="%x"; sprintf(str,format,num); return str; } char *ltoa(long num,char *str,int radix) { char *format=NULL; if(radix==16) format="%x"; sprintf(str,format,num); return str; } void stob(void) { char srec[256], strcount[10] ; char brec[256]; int count,a=0; while(1){ a++; printf("%i record(s) is/are converted.\r", a); if(!fgets(srec, 256, fp_srec)) /*ch stores the type of S-Rec.*/ break; if(srec[0] == 'S'){ count = ctoi(srec[2])*16 + ctoi(srec[3]); strcpy(brec,""); switch(srec[1]){ case '1': strcpy(brec,"0000"); strncat(brec,&srec[4],4); count = count - 3; itoa(count,strcount,16); if(strlen(strcount) == 1) strcat(brec,"0"); strcat(brec,strupr(strcount)); strncat(brec,&srec[8],count*2); strcat(brec,"\n"); fputs(brec,fp_brec); break; case '2': strcpy(brec,"00"); strncat(brec,&srec[4],6); count = count - 4; itoa(count,strcount,16); if(strlen(strcount) == 1) strcat(brec,"0"); strcat(brec,strupr(strcount)); strncat(brec,&srec[10],count*2); strcat(brec,"\n"); fputs(brec,fp_brec); break; case '3': strncat(brec,&srec[4],8); count = count - 5; itoa(count,strcount,16); if(strlen(strcount) == 1) strcat(brec,"0"); strcat(brec,strupr(strcount)); strncat(brec,&srec[12],count*2); strcat(brec,"\n"); fputs(brec,fp_brec); break; default: break; } } } fclose(fp_srec); fclose(fp_brec); } /******************************************************************/ /*This function is for translating s-record file to b-record file,*/ /*and adding in the init.b file if necessary. */ /******************************************************************/ void stobstart(void) { if (open_s_file("rb", input2, 'S')==0) /*Check and open S-record file */ return; output=strtok(input2,"."); /*Make B-record file */ output=strcat(output,".b"); if (open_b_file("wb", output, 'B')==0) /*Check and open B-record file */ return; stob(); } /*********************************************************/ /*This function is for sending B-record file to ADS board*/ /*********************************************************/ void sendbrec(unsigned char *filename) { unsigned char buffer[MAX_CH]; /*store the string got from the file */ strcpy(&buffer[0],""); if (open_b_file("rb", filename, 'B')==0){ /*Open B-record file */ printf("\n Can't open %s\n",filename); return; } send("\n"); while(fgets(&buffer[0], MAX_CH, fp_brec)) { printf(&buffer[0]); if(send(&buffer[0])) break; } fclose(fp_brec); } /*******************************************/ /*This function is for sending data from PC*/ /*******************************************/ int send(unsigned char *brecord) { int s_length; /* length of the string sent */ int n=0,res; rxbuff[0] = '\0'; if((brecord[8] == '0')&&(brecord[9] == '0')) /* check for execution record */ brecord[10] = 0; /* end execution record */ s_length = strlen(brecord); tcflush(port_fd, TCIOFLUSH); /* clear receive buffer & ouput buffer*/ /* send a line of brecord */ while(s_length>n) { if((res=write(port_fd,brecord+n,s_length-n))<=0) { if(debug_on) printf("In Line %d\n",__LINE__); perror("write "); clean(); exit(-1); } n+=res; } n=0; while(s_length>n) { if((res=read(port_fd,rxbuff+n,s_length-n))<0) { if(debug_on) printf("In Line %d\n",__LINE__); perror("read "); clean(); exit(-1); } if(res==0) { if(debug_on) printf("Receive time out error\n"); return (1); } n+=res; } if(strncmp(rxbuff,brecord,s_length-1)) /* skip the last character */ { if(debug_on) { printf("Feedback Error\n"); rxbuff[s_length]=0; printf("Write: %s\n",brecord); printf("Read : %s\n",rxbuff); return (1); } } rxbuff[s_length] = '\0'; return(0); } /**************************************************************/ /*This function is for adjusting the memory address to 4 bytes*/ /**************************************************************/ int address(unsigned char *address) { int len, shift; strupr(address); len = strlen(address); for(n=0; n 8)|(len == 0)){ printf("\nInvalid address."); return (1); } shift=8-len; if(shift){ for (n=7;n>=shift;n--) address[n]=address[n-shift]; for (n=0;n=0;count1--) /*Convert address str to int*/ n_input2 += ctoi(input2[count1])*pow(16,(7-count1)); if ((n_input2==0)&&(strcmp(input2,"00000000")!=0)){ printf(" Invalid Address : %s \n", input2); return; } input3_len=strlen(input3); if (input3_len==1){ input3[1]=input3[0]; input3[0]='0'; }else if((input3_len == 0)|(input3_len > 2)){ strcpy(input3,"10"); } n_input3 = ctoi(input3[0])*16 + ctoi(input3[1]); if (n_input3==0){ strcpy(input3,"10"); n_input3 = 16; /* display 16 bytes by default */ } printf("\n%s ", input2); offset=ctoi(input2[7]); for(i=offset;i>=1;i--) printf(" "); do { /*send commands for memory displaying*/ if(send("\nFFFFFFAA082C7C")){ printf("Comm error \n"); break; } send(input2); send("4E71"); send("\nFFFFFFAA00"); send("\nFFFFFFAA082A7CFFFFF9074E71"); send("\nFFFFFFAA00"); send("\nFFFFFFAA081A964E714E714E71"); send("\nFFFFFFAA00"); tcounter = 0; while(!(res=read(port_fd,&feedback,1))) { tcounter++; if(tcounter==timeout) break; } if(res<0) { printf("In Line %d",__LINE__); perror("read"); clean(); exit(-1); } printf("%.2X ",feedback); /* displaying feedback */ n_input2++; /* increment address */ ltoa(n_input2,input2,16); address(input2); /* convert address str to int */ NByte++; if(NByte < n_input3){ ByteCnt++; if((line1)&&(ByteCnt+offset==16)){ printf("\n%s ",input2); ByteCnt = 0; line1 = 0; } else if(ByteCnt==16){ printf("\n%s ",input2); ByteCnt = 0; } }else break; }while (1); printf("\n"); } /***************************************/ /*This function is for memory modifying*/ /***************************************/ void memmod(void) { long n_input2; int count1, res; int addr_err; long timeout=10, tcounter=0; if(address(input2)) return; n_input2=0; for (count1=7;count1>=0;count1--) /* Convert address str to int */ n_input2+=ctoi(input2[count1])*pow(16,(7-count1)); if ((n_input2==0)&&(strcmp(input2,"00000000")!=0)){ printf(" Invalid Address : %s \n", input2); return; } while (1){ /* send commands for memory displaying */ if(send("\nFFFFFFAA082C7C")){ printf("Comm error \n"); break; } send(input2); /* movea.l #input2,A6 */ send("4E71"); send("\nFFFFFFAA00"); send("\nFFFFFFAA082A7CFFFFF9074E71"); /* MOVEA.L #0xFFFFF907,A5 */ send("\nFFFFFFAA00"); /* MOVE.B (A6),(A5) */ send("\nFFFFFFAA081A964E714E714E71"); send("\nFFFFFFAA00"); tcounter = 0; while(!(res=read(port_fd,&feedback,1))) { /* wait for port input */ tcounter++; if(tcounter==timeout){ /* printf("\nComm error"); return; */ /* if overrun read data */ break; } } if(res<0) { printf("In Line %d",__LINE__); perror("read"); clean(); exit(-1); } printf(" %.8s >",input2); /* print address */ printf("%.2X ",feedback); /* print feedback */ feedback='\0'; /* reset feedback */ // strupr(gets(input3)); /* get input command */ mygets(input3,6+1); strupr(input3); if((input3[0]=='.')|(input3[0] == 'Q')) break; /* end memmod */ addr_err = 0; switch (strlen(input3)) { case 0 : break; case 1 : input3[1]=input3[0]; input3[0]='0'; case 2 : if((ctoi(input3[0])==NotHex)|(ctoi(input3[1])==NotHex)) addr_err = 1; break; default: addr_err = 1; break; } if(addr_err) printf("??\n"); else if(strlen(input3)) { send(input2); /* send address to be modified */ send("01"); /* number of byte to be modified */ send(input3); /* data to modify */ n_input2++; /* increment address */ ltoa(n_input2,input2,16); /* convert address int to str */ address(input2); } else { n_input2++; /* increment address */ ltoa(n_input2,input2,16); /* convert address int to str */ address(input2); } } } /*************************************************************/ /*This function is for execution at specified memory location*/ /*************************************************************/ void memexe(void) { if(address(input2)) return; send("\n"); /* send commands for memory execution*/ send(input2); send("00"); printf("%.8s\n",input2); } /********************************************************/ /* This function is used to change baud rate */ /********************************************************/ void BaudRate1() { /*Baud Rate Selection Menu*/ printf("\n"); switch(rate1) { case '1' : printf(" Current baud is 19200 bps\n"); break; case '2' : printf(" Current baud is 115200 bps\n"); break; default : break; } printf(" Please select new baud frequency:\n"); printf(" 1 = 19200, 2 = 115200 \n"); do{ printf("\r =>"); rate2 = getchar(); if(rate2!='\n') while(getchar()!='\n'); //printf("%c",rate2); if((rate2=='\n') || (rate1==rate2)) return; }while((rate2!='1')&&(rate2!='2')); if((rate1 == '1') && (rate2 == '2')) { /* 19200 to 115200 */ send("\nFFFFF9020100"); /* set board to 38400 */ ChangePCBaud(B38400); /* Set PC to 38400 */ send("\nFFFFF9030138"); /* set board to 115200 */ ChangePCBaud(B115200); /* Set PC to 115200 */ } if((rate1 == '2') && (rate2 == '1')) { /* 115200 to 19200 */ send("\nFFFFF9030126"); /* set board to 38400 */ ChangePCBaud(B38400); /* Set PC to 38400 */ send("\nFFFFF9020101"); /* set board to 19200 */ ChangePCBaud(B19200); /* Set PC to 19200 */ } rate1=rate2; /* Reset Initial Baud Rate Flag */ } /*****************************************/ /*This function is to run the help option*/ /*****************************************/ void help(void) { int len; command2=10; len=strlen(input2); if (len>4){ printf(" Syntax Error. Please type your command again.\n"); return; } if (input2[0]=='\0') command2=0; if ((input2[0]=='I')&&(input2[1]=='N')) command2=1; if ((input2[0]=='L')&&(input2[1]=='O')) command2=2; if ((input2[0]=='M')&&(input2[1]=='D')) command2=3; if ((input2[0]=='M')&&(input2[1]=='M')) command2=4; if ((input2[0]=='G')&&(input2[1]=='O')) command2=5; if ((input2[0]=='C')&&(input2[1]=='B')) command2=6; if ((input2[0]=='C')&&(input2[1]=='E')) command2=7; if ((input2[0]=='H')&&(input2[1]=='E')) command2=8; if ((input2[0]=='E')&&(input2[1]=='X')) command2=9; switch (command2){ case 0: menu(); printf(" You may type in the following to get help on specified commands. \n"); printf(" The command is not case sensitve\n"); printf(" HELP (COMMAND) [ENTER] \n"); printf(" e.g. HELP LO [ENTER] -- help on SEND FILE function \n"); printf(" HELP GO [ENTER] -- help on MEMORY EXECUTION function \n"); printf(" The functions are : INIT , LO , MD , MM , GO , CB , HELP , EXIT\n");break; case 1: printf(" IN initialize target system\n\n"); printf(" e.g. IN\n"); printf(" IN /bootstrap/file.b \n"); printf(" If the path of the initializing b-record is not typed, the \n"); printf(" the program will automatically search for the b-record init.b \n"); printf(" in the same directory of bbug.exe \n");break; case 2: printf(" LO send s or b record files to target system\n\n"); printf(" e.g. LO /somepath/example.S19 S \n"); printf(" Above is a command sending a s-record file to target system. \n"); printf(" 'LO' is the send command, '/somepath/example.S19' is the file path, \n"); printf(" and 'S' is the file type. \n");break; case 3: printf(" MD display memory content\n\n"); printf(" e.g. MD 1000 10 \n"); printf(" MD 00001000 10 \n"); printf(" The above command is to display memory content from address \n"); printf(" 00001000, and for 16 bytes (byte count is in hex from 1-99) \n");break; case 4: printf(" MM modify memory content\n\n"); printf(" e.g. MM 1000 \n"); printf(" MM 00001000 \n"); printf(" The above command is to display memory content from 00001000. \n"); printf(" If is pressed, memory content of 1001 is displayed. \n"); printf(" If '.' is pressed, the program will jump back to routine.\n"); printf(" If other characters are typed and is pressed, the \n"); printf(" the memory content will be replaced by the new input data. \n"); printf(" (while the new input is valid, or error message is displayed) \n");break; case 5: printf(" GO go to user input memory address and start execution. \n\n"); printf(" e.g. GO 1000 \n"); printf(" The commmand is to execute program from memory address 1000 \n"); printf(" Note: This program and the target system must be reset after \n"); printf(" memory execution.\n");break; case 6: printf(" CB change baud rate by selecting the numbers\n\n"); printf(" The available choices of baud rate are : \n"); printf(" 1. 9600 2. 19200 3. 28800 4. 57600 \n");break; case 7: printf(" CE execute 68000 commands\n\n");break; case 8: printf(" HE\n HELP get help on how to use the functions\n");break; case 9: printf(" EX\n EXIT exit the program and return to DOS\n");break; default: printf(" Syntax Error. Please type your command again.\n");return; } } void ChangePCBaud(speed_t newBaud) { cfsetispeed(&newtio,newBaud); cfsetospeed(&newtio,newBaud); tcflush(port_fd,TCIOFLUSH); tcsetattr(port_fd,TCSANOW,&newtio); } /* Sleep for timeout milliseconds */ void Delay(int timeout) { poll(NULL,0,timeout); } /*****************************************/ /*This function test comm port */ /*****************************************/ int CommTest1(void) { char teststr[] = "\ntest"; /* check for 19200 */ Delay(10); /* sleep for 10 milliseconds */ ChangePCBaud(B19200); /* set pc to 19200 */ send(teststr); if(!strcmp(rxbuff,teststr)) { rate1 = '1'; return(0); } /* check for 115200 */ Delay(10); ChangePCBaud(B115200); send(teststr); if(!strcmp(rxbuff,teststr)){ rate1 = '2'; return(0); } /* check for 9600 */ Delay(10); ChangePCBaud(B9600); Delay(10); send(teststr); if(!strcmp(teststr,rxbuff)) { send("\nFFFFF2010100"); /* change to 19200 */ printf("Target was reset\n"); printf("Baud rate is now set to 19200\n"); ChangePCBaud(B19200); /* Change PC Baud Rate to 19200 */ rate1 = '1'; return(0); } /* None of the above 3 possible baud */ return(1); }