5 #define cleardata() memset(data,0,BUFSIZE)
7 static void increaseled(void)
9 PDR14 = ~(((~PDR14)+1)%256);
12 static unsigned char recvbyte(void)
17 static unsigned short recvword(void)
19 static unsigned char b1, b2;
20 static unsigned short ret;
23 ret = (unsigned short)(b2 << 8) | b1;
27 static unsigned int recvdword(void)
29 static unsigned char b1, b2, b3, b4;
30 static unsigned int ret;
35 ret = ((unsigned int) (b4 << 24)) | ((unsigned int) (b3 << 16)) | ((unsigned int) (b2 << 8)) |(unsigned int)b1;
39 static void halt(void)
46 static void panic(void)
55 unsigned short i, size, next;
56 unsigned char running = 1, data[BUFSIZE] = {0};
69 case 0x15: //chip erase
72 if(FLASH_ChipErase() != 1) {
80 address = recvdword();
87 for(i=0; i<(size+4); i+=4) { /* erase */
88 if(FLASH_SectorErase(address + i) != 1) {
93 Putch4(0x18); //Erasing done.
100 address = recvdword();
107 for(i=0; i<size; i++) { /* get data */
109 data[i] = recvbyte();
113 for(i=0; i<size; i+=2) { /* flash the data */
115 next = (((unsigned short)data[i])<<8) | (unsigned short)data[i+1];
116 if(FLASH_WriteHalfWord(address + i, next) != 1) {
120 Putch4(0x28); //Flashing done.
123 case 0x97: /* exit and restart (let do this by the watchdog!) */
128 case 0x99: /* exit */
135 PDR14 = 0x55; //signal that we finished now!
141 for (; i <0x10; i+=4) {
142 (void) FLASH_SectorErase(baseaddr + i);
150 (void) FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);