5 #define cleardata() memset(data,0,BUFSIZE)
10 static unsigned int t = T_INIT;
11 static unsigned char l = (1<<0);
12 static unsigned char s = 1;
16 } else if (l & (1<<7)) {
19 l = s ? l << 1 : l >> 1;
27 static unsigned char recvbyte(void)
32 static unsigned short recvword(void)
34 static unsigned char b1, b2;
35 static unsigned short ret;
38 ret = (unsigned short)(b2 << 8) | b1;
42 static unsigned int recvdword(void)
44 static unsigned char b1, b2, b3, b4;
45 static unsigned int ret;
50 ret = ((unsigned int) (b4 << 24)) | ((unsigned int) (b3 << 16)) | ((unsigned int) (b2 << 8)) |(unsigned int)b1;
54 static void halt(void)
61 static void panic(void)
70 unsigned short i, size, next;
71 unsigned char running = 1, data[BUFSIZE] = {0};
84 case 0x15: //chip erase
87 if(FLASH_ChipErase() != 1) {
97 address = recvdword();
103 for(i=0; i<size; i++) { /* get data */
105 data[i] = recvbyte();
108 for(i=0; i<size; i+=2) { /* flash the data */
110 next = (((unsigned short)data[i])<<8) | (unsigned short)data[i+1];
111 if(FLASH_WriteHalfWord(address + i, next) != 1) {
115 Putch4(0x28); //Flashing done.
118 case 0x97: /* exit and restart (let do this by the watchdog!) */
120 unsigned long tmp = 1800;
126 case 0x99: /* exit */
133 PDR14 = 0x55; //signal that we finished now!
139 for (; i <0x10; i+=4) {
140 (void) FLASH_SectorErase(baseaddr + i);
148 (void) FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);