X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Flpcload.c;h=80af804153dc5697da32ba6ae3f30a598cfcd45d;hb=9fe785e6bc1cf36626f4a3db7877b5f7df76ed61;hp=6ec118628d38eb537e43662cc408256159427bce;hpb=14acad803dec0c6e18b1825f2b84e9bbcd409554;p=my-code%2Farm.git diff --git a/betty/lpcload.c b/betty/lpcload.c index 6ec1186..80af804 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -112,11 +112,15 @@ int open_serial_device(t_lpc *lpc) { //term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL); term.c_iflag&=~(INLCR|ICRNL|IXANY); term.c_iflag|=(IXON|IXOFF); + + // output options + + term.c_oflag=0; // more control options -> timeout / flow control term.c_cc[VMIN]=0; - term.c_cc[VTIME]=10; // 1 second timeout + term.c_cc[VTIME]=40; // 4 second timeout term.c_cc[VSTART]=0x11; term.c_cc[VSTOP]=0x13; @@ -317,7 +321,7 @@ int go(t_lpc *lpc) { snprintf(buf,BUFSIZE,"G %d A\r\n",lpc->roff); len=strlen(buf); - ret=txrx(lpc,buf,ret,TXRX_TYPE_CMD); + ret=txrx(lpc,buf,len,TXRX_TYPE_CMD); return ret; } @@ -349,7 +353,7 @@ int write_to_ram(t_lpc *lpc,char *buf,u32 addr,int len) { } /* make it a multiple of 3 (reason: uuencode) */ - nlen=(len/3+1)*3; + nlen=(!(len%3))?len:((len/3+1)*3); if(nlen>BUFSIZE) { printf("ram write: too much data\n"); return -1; @@ -376,7 +380,8 @@ int write_to_ram(t_lpc *lpc,char *buf,u32 addr,int len) { while(bcnt aborting\n"); + goto end; + } + + /* open firmware file */ + if(open_firmware(&lpc)<0) + goto end; + /* parse intel hex file and write to ram */ printf("write firmware to ram ...\n"); firmware_to_ram(&lpc); /* unlock go cmd */ + printf("unlock go command ...\n"); unlock_go(&lpc); /* go! */ - go(&lpc); + 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