X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Flpcload.c;h=7c2db70b1546bfa9124dbf44d65c0dc8fd5e8d79;hb=203e912166256906b85dfe2db43508c2d2a381d1;hp=ff78d967950474371f8fec874cc217770a690891;hpb=06e719791011a2c8eb472943492b7b0b6d445c6f;p=my-code%2Farm.git diff --git a/betty/lpcload.c b/betty/lpcload.c index ff78d96..7c2db70 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -19,7 +19,8 @@ #define TXRX_TYPE_BAUD 0x01 #define TXRX_TYPE_SYNC 0x02 -#define TXRX_TYPE_DATA 0x03 +#define TXRX_TYPE_CMD 0x03 +#define TXRX_TYPE_DATA 0x04 #define CMD_SUCCESS "0\r\n" #define INVALID_COMMAND "1\r\n" @@ -125,7 +126,7 @@ int open_firmware(t_lpc *lpc) { return lpc->fwfd; } -int txrx(t_lpc *lpc,char *buf,int len,u8 type) { +int txrx(t_lpc *lpc,u8 *buf,int len,u8 type) { int ret,cnt; int i; @@ -165,6 +166,11 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) { } } + /* return here if type is data */ + + if(type==TXRX_TYPE_DATA) + return cnt; + /* read */ if(lpc->info&VERBOSE) @@ -190,12 +196,11 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) { } if(lpc->info&VERBOSE) printf(" (%d)\n",cnt); - len=cnt; buf[cnt]='\0'; /* check/strip return code if type is data */ - if(type==TXRX_TYPE_DATA) { + if(type==TXRX_TYPE_CMD) { ret=strlen(CMD_SUCCESS); if(!strncmp(buf,CMD_SUCCESS,ret)) { for(i=ret;ipartid=atoi(buf); return lpc->partid; @@ -258,11 +263,11 @@ int read_part_id(t_lpc *lpc) { int read_bcv(t_lpc *lpc) { - char buf[BUFSIZE]; + u8 buf[BUFSIZE]; char *ptr; memcpy(buf,"K\r\n",3); - txrx(lpc,buf,3,TXRX_TYPE_DATA); + txrx(lpc,buf,3,TXRX_TYPE_CMD); ptr=strtok(buf,"\r\n"); lpc->bcv[0]=strtol(ptr,NULL,16); ptr=strtok(NULL,"\r\n"); @@ -271,6 +276,106 @@ int read_bcv(t_lpc *lpc) { return 0; } +int uuencode(u8 *in,u8 *out) { + + out[0]=0x20+((in[0]>>2)&0x3f); + out[1]=0x20+(((in[0]<<4)|(in[1]>>4))&0x3f); + out[2]=0x20+(((in[1]<<2)|(in[2]>>6))&0x3f); + out[3]=0x20+(in[2]&0x3f); + + return 0; +} + +int write_to_ram(t_lpc *lpc,u8 *buf,int addr,int len) { + + int lcount; + u8 checksum; + u8 txrxbuf[BUFSIZE]; + int count,bcnt; + int nlen,slen; + int i; + + /* check length */ + if(len%4) { + printf("ram write: not a multiple of 4\n"); + return -1; + } + + /* make it a multiple of 3 (reason: uuencode) */ + nlen=(len/3+1)*3; + if(nlen>BUFSIZE) { + printf("ram write: too much data\n"); + return -1; + } + for(i=len;i