From: hackbard Date: Thu, 30 Aug 2007 14:32:29 +0000 (+0200) Subject: baudrate 384000, no return check for go ccmd, parse 04 record X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0063836254cf1caf26cb35af0486fab97b2d1407;p=my-code%2Farm.git baudrate 384000, no return check for go ccmd, parse 04 record --- diff --git a/betty/lpcload.c b/betty/lpcload.c index 80af804..bd69fbe 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -19,11 +19,12 @@ #define VERBOSE (1<<0) #define FIRMWARE (1<<1) +#define TXRX_TYPE_SYNC 0x00 +#define TXRX_TYPE_CKSM 0x00 #define TXRX_TYPE_BAUD 0x01 -#define TXRX_TYPE_SYNC 0x02 -#define TXRX_TYPE_CMD 0x03 -#define TXRX_TYPE_DATA 0x04 -#define TXRX_TYPE_CKSM 0x05 +#define TXRX_TYPE_CMD 0x02 +#define TXRX_TYPE_DATA 0x03 +#define TXRX_TYPE_GO 0x04 #define CMD_SUCCESS "0\r\n" #define INVALID_COMMAND "1\r\n" @@ -58,7 +59,6 @@ typedef struct s_lpc { char fwfile[128]; /* firmware file */ u8 info; /* info/mode */ char freq[8]; /* frequency */ - u32 hoff; /* start addr of ihex file */ u32 roff; /* ram offset of uc */ } t_lpc; @@ -93,8 +93,8 @@ int open_serial_device(t_lpc *lpc) { // input/output baudrate - cfsetispeed(&term,B9600); - cfsetospeed(&term,B9600); + cfsetispeed(&term,B38400); + cfsetospeed(&term,B38400); // control options -> 8n1 @@ -120,7 +120,7 @@ int open_serial_device(t_lpc *lpc) { // more control options -> timeout / flow control term.c_cc[VMIN]=0; - term.c_cc[VTIME]=40; // 4 second timeout + term.c_cc[VTIME]=10; // 1 second timeout term.c_cc[VSTART]=0x11; term.c_cc[VSTOP]=0x13; @@ -131,9 +131,6 @@ int open_serial_device(t_lpc *lpc) { int open_firmware(t_lpc *lpc) { - int ret; - char buf[BUFSIZE]; - /* open firmware file */ lpc->fwfd=open(lpc->fwfile,O_RDONLY); @@ -141,16 +138,6 @@ int open_firmware(t_lpc *lpc) { if(lpc->fwfd<0) perror("fw open"); - /* read hex file offset */ - - ret=read(lpc->fwfd,buf,7); - if(buf[0]!=':') { - printf("fw open: not an intel hex file?\n"); - return -1; - } - sscanf(buf+3,"%04x",&(lpc->hoff)); - lseek(lpc->fwfd,0,SEEK_SET); - return lpc->fwfd; } @@ -251,6 +238,11 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) { } buf[cnt+1]='\0'; + /* return if type is go */ + + if(type==TXRX_TYPE_GO) + return 0; + /* check/strip return code if type is cmd */ if(type==TXRX_TYPE_CMD) { @@ -321,7 +313,7 @@ int go(t_lpc *lpc) { snprintf(buf,BUFSIZE,"G %d A\r\n",lpc->roff); len=strlen(buf); - ret=txrx(lpc,buf,len,TXRX_TYPE_CMD); + ret=txrx(lpc,buf,len,TXRX_TYPE_GO); return ret; } @@ -361,7 +353,7 @@ int write_to_ram(t_lpc *lpc,char *buf,u32 addr,int len) { for(i=len;iroff-lpc->hoff); + addr+=lpc->roff; /* prepare write command */ if(lpc->info&VERBOSE) @@ -479,10 +471,15 @@ int firmware_to_ram(t_lpc *lpc) { // /* get cs and ip */ // break; case 0x00: + if(len%4) { + printf("fw to ram: invalid len\n"); + return -1; + } write_to_ram(lpc,buf,addr,len); break; - case 0x01: - write_to_ram(lpc,buf,addr,len); + case 0x04: + lpc->roff=((buf[0]<<28)|(buf[1]<<24)); + lpc->roff|=((buf[2]<<20)|(buf[3]<<16)); break; default: printf("fw to ram: unknown type %02x\n",type); @@ -497,7 +494,6 @@ int main(int argc,char **argv) { t_lpc lpc; int i; - u8 buf[BUFSIZE]; int ret; /* @@ -569,29 +565,6 @@ int main(int argc,char **argv) { printf("go ...\n"); ret=go(&lpc); - /* tell the user that the error might be due to the jump */ - printf("\n\n"); - if(ret<0) - printf("the above error might be due to the jump!\n\n"); - - /* query user for serial port listening */ - printf("continue listening on serial port? (ctrl+c to quit) [y|n]: "); - buf[0]=getchar(); - printf("\n"); - - if(buf[0]!='y') - goto end; - - /* continue lsitening on serial port */ - ret=1; - while(ret) { - ret=read(lpc.sfd,buf,BUFSIZE); - printf("\rread %d bytes: ",ret); - for(i=0;i