Rev 1299 Rev 1300
Line 1... Line 1...
1 /**** Bootloader ****/ 1 /**** BootLoader ****/
2 #define VERSION "1.0" 2 #define VERSION "1.0"
3 #define ID "$Id: bloader.c 1299 2009-01-16 23:42:46Z kakl $" 3 #define ID "$Id: bloader.c 1300 2009-01-17 08:41:49Z kakl $"
4   4  
5 #CASE // Case sensitive compiler 5 #CASE // Case sensitive compiler
6   6  
7 #include "bloader.h" 7 #include "bloader.h"
-   8 #include <string.h>
8   9  
9 #bit CREN = 0x18.4 // USART registers 10 #bit CREN = 0x18.4 // USART registers
10 #bit SPEN = 0x18.7 11 #bit SPEN = 0x18.7
11 #bit OERR = 0x18.1 12 #bit OERR = 0x18.1
12 #bit FERR = 0x18.2 13 #bit FERR = 0x18.2
Line 16... Line 17...
16 rs232_handler() 17 rs232_handler()
17 { 18 {
18 putchar(getc()); 19 putchar(getc());
19 } 20 }
20   21  
-   22 void welcome(void) // Welcome message
-   23 {
-   24 char REV[50]=ID; // Buffer for concatenate of a version string
-   25 char VER[4]=VERSION; // Buffer for concatenate of a version string
-   26  
-   27 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0;
-   28 printf("\n\r\n\r# BLoader %s (C) 2007 KAKL\n\r",VER); // Welcome message
-   29 printf("#%s\n\r",&REV[4]);
-   30 }
-   31  
21   32  
22 /*-------------------------------- MAIN --------------------------------------*/ 33 /*-------------------------------- MAIN --------------------------------------*/
23 #SEPARATE 34 #SEPARATE
24 void real_main() 35 void real_main()
25 { 36 {
26 int8 i=0; 37 int8 i=0;
27   38  
-   39 welcome();
-   40  
28 printf("/n/rBootloader/n/r"); 41 printf("# Boot Loader Test >>>\n\r# ");
29 enable_interrupts(INT_RDA); 42 enable_interrupts(INT_RDA);
30 enable_interrupts(GLOBAL); 43 enable_interrupts(GLOBAL);
31 while(TRUE) 44 while(TRUE)
32 { 45 {
33 printf("|%u",i++); 46 printf("%u|",i++);
34 delay_ms(100); 47 delay_ms(100);
35 } 48 }
36 } 49 }
37   50  
38   51  
Line 57... Line 70...
57 void dummy_main() // Main on the fix position 70 void dummy_main() // Main on the fix position
58 { 71 {
59 real_main(); 72 real_main();
60 } 73 }
61   74  
62 #ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-125 auto=0 default 75 #ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-130 auto=0 default
63   76  
64 unsigned int atoi_b16(char *s) // Convert two hex characters to an int8 77 unsigned int atoi_b16(char *s) // Convert two hex characters to an int8
65 { 78 {
66 unsigned int result = 0; 79 unsigned int result = 0;
67 int i; 80 int i;
Line 126... Line 139...
126 while(TRUE) 139 while(TRUE)
127 { 140 {
128 //---WDT 141 //---WDT
129 while (getc()!=':') restart_wdt(); // Only process data blocks that starts with ':' 142 while (getc()!=':') restart_wdt(); // Only process data blocks that starts with ':'
130   143  
131 buffidx = 0; // Read into the buffer until 'x' is received or buffer is full 144 buffidx = 0; // Read into the buffer until fill is received or buffer is full
132 do 145 do
133 { 146 {
134 buffer[buffidx] = getc(); 147 buffer[buffidx] = getc();
135 } while ( (buffer[buffidx++] != 'x') && (buffidx < BUFFER_LEN_LOD) ); 148 } while ( (buffer[buffidx++] < 'g') && (buffidx < BUFFER_LEN_LOD) );
136 assert(buffidx == BUFFER_LEN_LOD,1); // Error 1 - Buffer Overrun 149 assert(buffidx == BUFFER_LEN_LOD,1); // Error 1 - Buffer Overrun
137   150  
138 //---WDT 151 //---WDT
139 restart_wdt(); 152 restart_wdt();
140   153  
Line 193... Line 206...
193 write_program_eeprom(addr++, data.i16[i]); 206 write_program_eeprom(addr++, data.i16[i]);
194 putchar('*'); 207 putchar('*');
195 } 208 }
196 else putchar('.'); 209 else putchar('.');
197 //---WDT 210 //---WDT
198 restart_wdt(); 211 restart_wdt();
199 CREN=0; CREN=1; 212 CREN=0; CREN=1; // Reinitialise USART
200 } 213 }
201 } 214 }
202 } 215 }
203 } 216 }
204   217  
205 #ORG default 218 #ORG default
206   219  
207 #ORG getenv("PROGRAM_MEMORY")-124,getenv("PROGRAM_MEMORY")-1 auto=0 220 #ORG getenv("PROGRAM_MEMORY")-129,getenv("PROGRAM_MEMORY")-1 auto=0
208 void main() 221 void main()
209 { 222 {
210 int8 timeout; 223 int8 timeout;
211   224  
212 disable_interrupts(GLOBAL); 225 disable_interrupts(GLOBAL);
Line 218... Line 231...
218 setup_timer_2(T2_DISABLED,0,1); 231 setup_timer_2(T2_DISABLED,0,1);
219 setup_comparator(NC_NC_NC_NC); 232 setup_comparator(NC_NC_NC_NC);
220 setup_vref(FALSE); 233 setup_vref(FALSE);
221 setup_oscillator(OSC_8MHZ|OSC_INTRC); 234 setup_oscillator(OSC_8MHZ|OSC_INTRC);
222   235  
223 putchar('?'); -  
224 for(timeout=0; timeout<255; timeout++) //cca 50s 236 for(timeout=0; timeout<255; timeout++) //cca 50s
225 { 237 {
226 if (kbhit()) 238 if (kbhit())
227 if (getc()=='u') // "uf" as Update Firmware 239 if (getc()=='u') // "uf" as Update Firmware
228 { 240 {
Line 231... Line 243...
231 restart_wdt(); 243 restart_wdt();
232 boot_loader(); // Update Firmware starter 244 boot_loader(); // Update Firmware starter
233 } 245 }
234 } 246 }
235 else break; 247 else break;
-   248 putchar('u'); putchar('f'); putchar('?');
236 pause(); 249 pause();
237 CREN=0; CREN=1; // Reinitialise USART 250 CREN=0; CREN=1; // Reinitialise USART
238 restart_wdt(); 251 restart_wdt();
239 }; 252 };
240   253