#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"
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;
// input/output baudrate
- cfsetispeed(&term,B9600);
- cfsetospeed(&term,B9600);
+ cfsetispeed(&term,B38400);
+ cfsetospeed(&term,B38400);
// control options -> 8n1
// 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;
int open_firmware(t_lpc *lpc) {
- int ret;
- char buf[BUFSIZE];
-
/* open firmware file */
lpc->fwfd=open(lpc->fwfile,O_RDONLY);
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;
}
}
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) {
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;
}
for(i=len;i<nlen;i++) buf[i]=0;
/* prepare addr */
- addr+=(lpc->roff-lpc->hoff);
+ addr+=lpc->roff;
/* prepare write command */
if(lpc->info&VERBOSE)
// /* 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);
t_lpc lpc;
int i;
- u8 buf[BUFSIZE];
int ret;
/*
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<ret;i++)
- printf("%02x ",buf[i]);
- printf("\n");
- }
-
end:
close(lpc.sfd);
close(lpc.fwfd);