Rev 2848 Rev 2896
Line 7... Line 7...
7   7  
8 Add "uf\n\r" to the first line of .HEX. or use this script: 8 Add "uf\n\r" to the first line of .HEX. or use this script:
9 echo uf > /dev/ttyUSB$1 9 echo uf > /dev/ttyUSB$1
10 ascii-xfr -s -v -l 100 ./bltest.hex > /dev/ttyUSB$1 10 ascii-xfr -s -v -l 100 ./bltest.hex > /dev/ttyUSB$1
11 11
12 Or add "uf\n\r" and add some dummy characters at end or begin of each line (for 100 ms delay) and use: 12 Or add "uf\n\r" and add some dummy characters at the end or begin of each line (for 100 ms delay) and use:
13 cp ./bltest.hex > /dev/ttyUSB0 13 cp ./bltest.hex > /dev/ttyUSB0
14 14
15 For adding characters you can use this: 15 For adding characters you can use this:
16 sed -i 's/^/pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp/' ./bltest.hex 16 sed -i 's/^/pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp/' ./bltest.hex
17 sed -i 1i"uf" ./bltest.hex 17 sed -i 1i"uf" ./bltest.hex
18 18
-   19 Windows script:
-   20 echo uf > com1
-   21 ping 1.1.1.1 -n 1 -w 100 > nul
-   22 FOR /F "tokens=1*" %%i in (bltest.hex) do @echo %%i > com1 & ping 1.1.1.1 -n 1 -w 100 > nul
19 */ 23 */
20   24  
21 #define ID "$Id: bloader.c 2848 2013-03-21 08:16:49Z kakl $" 25 #define ID "$Id: bloader.c 2896 2013-04-09 20:40:51Z kakl $"
22   26  
23 #CASE // Case sensitive compiler 27 #CASE // Case sensitive compiler
24   28  
25 #define ERR_BUFFER_OVERRUN 1 // Error 1 - Buffer Overrun 29 #define ERR_BUFFER_OVERRUN 1 // Error 1 - Buffer Overrun
26 #define ERR_CHECKSUM 2 // Error 2 - Bad CheckSum 30 #define ERR_CHECKSUM 2 // Error 2 - Bad CheckSum
Line 109... Line 113...
109   113  
110 void assert(int1 Condition, int8 ErrorCode) // Send error number to the serial line 114 void assert(int1 Condition, int8 ErrorCode) // Send error number to the serial line
111 { 115 {
112 if(Condition) 116 if(Condition)
113 { 117 {
114 putchar('E'); 118 putchar('e');
115 putchar(ErrorCode+'0'); 119 putchar(ErrorCode+'0');
116 reset_cpu(); 120 reset_cpu();
117 } 121 }
118 } 122 }
119   123  
Line 156... Line 160...
156 int8 i8[16]; 160 int8 i8[16];
157 int16 i16[8]; 161 int16 i16[8];
158 } data; 162 } data;
159   163  
160 disable_interrupts(GLOBAL); 164 disable_interrupts(GLOBAL);
161 /* -  
162 putchar('@'); //Start Erase -  
163   165  
-   166 putchar('@'); //Start Erase
-   167 /*
164 //Erase program memory is not necessary. 168 //Erase program memory is not necessary.
165 { 169 {
166 int8 i; 170 int8 i;
167 for(i=0;i<32;i++)buffer[i]=0xFF; 171 for(i=0;i<32;i++)buffer[i]=0xFF;
168 } 172 }
Line 190... Line 194...
190 { 194 {
191 buffer[buffidx] = getc(); 195 buffer[buffidx] = getc();
192 putc(buffer[buffidx]); 196 putc(buffer[buffidx]);
193 } while ( (buffer[buffidx++] != '\r') && (buffidx < BUFFER_LEN_LOD) ); 197 } while ( (buffer[buffidx++] != '\r') && (buffidx < BUFFER_LEN_LOD) );
194 assert(buffidx == BUFFER_LEN_LOD, ERR_BUFFER_OVERRUN); // Error 1 - Buffer Overrun 198 assert(buffidx == BUFFER_LEN_LOD, ERR_BUFFER_OVERRUN); // Error 1 - Buffer Overrun
195 buffidx--; -  
196 199
197 //---WDT 200 //---WDT
198 restart_wdt(); 201 restart_wdt();
199   202  
200 checksum = 0; // Sum the bytes to find the check sum value 203 checksum = 0; // Sum the bytes to find the check sum value
201 for (i=0; i<(buffidx); i+=2) 204 for (i=0; i<(buffidx-3); i+=2)
202 { 205 {
203 checksum += atoi_b16 (&buffer[i]); 206 checksum += atoi_b16 (&buffer[i]);
-   207 //!!! printf(".%x",checksum);
204 } 208 }
205 assert(checksum != 0, ERR_CHECKSUM); // Error 2 - Bad CheckSum 209 assert(checksum != 0, ERR_CHECKSUM); // Error 2 - Bad CheckSum
206   210  
207 // Get the lower 16 bits of address 211 // Get the lower 16 bits of address
208 l_addr = make16(atoi_b16(&buffer[2]),atoi_b16(&buffer[4])); 212 l_addr = make16(atoi_b16(&buffer[2]),atoi_b16(&buffer[4]));
Line 228... Line 232...
228 { 232 {
229 // Read old program memory content 233 // Read old program memory content
230 for (i=0,next_addr=addr;i<8;i++) 234 for (i=0,next_addr=addr;i<8;i++)
231 data.i16[i]=read_program_eeprom(next_addr++); 235 data.i16[i]=read_program_eeprom(next_addr++);
232 // Loops through all of the data and stores it in data 236 // Loops through all of the data and stores it in data
233 // The last 2 bytes are the check sum, hence buffidx-2 237 // The last 2 bytes are the check sum, hence buffidx-4
234 for (i=8,dataidx=0; i < (buffidx-2); i += 2) 238 for (i=8,dataidx=0; i < (buffidx-5); i += 2)
235 data.i8[dataidx++]=atoi_b16(&buffer[i]); 239 data.i8[dataidx++]=atoi_b16(&buffer[i]);
236   240  
237 if (addr == 0) 241 if (addr == 0)
238 { 242 {
239 // Write 8 words to the Loader location (jump to the main()) 243 // Write 8 words to the Loader location (jump to the main())
240 addr=LOADER_RESERVED; 244 addr=LOADER_RESERVED;
241 write_program_memory(addr, &data.i8[0], 16); // It works only with 16 !!! 245 write_program_memory(addr, &data.i8[0], 16); // It works only with 16 !!!
242 putchar('%'); 246 putchar('%');
243 } 247 }
244 else 248 else
245 if ( (addr > 7) && (addr <= (LOADER_RESERVED-16)) ) // Do not overwrite BootLoader 249 if ( (addr >= FLASH_BLOCK_SIZE) && (addr <= (LOADER_RESERVED-16)) ) // Do not overwrite BootLoader
246 { 250 {
247 // Write program 251 // Write program
248 write_program_memory(addr, &data.i8[0], 16); // It works only with 16 !!! 252 write_program_memory(addr, &data.i8[0], 16); // It works only with 16 !!!
249 putchar('$'); 253 putchar('$');
250 } 254 }