Rev 1298 Rev 1300
Line 1... Line 1...
1 /**** IR Mrakomer 4 ****/ 1 /**** IR Mrakomer 4 ****/
2 #define VERSION "4.0" 2 #define VERSION "4.0"
3 #define ID "$Id: irmrak4.c 1298 2009-01-16 23:40:59Z kakl $" 3 #define ID "$Id: irmrak4.c 1300 2009-01-17 08:41:49Z kakl $"
4   4  
5 #include "irmrak4.h" 5 #include "irmrak4.h"
6   6  
7 #bit CREN = 0x18.4 // USART registers 7 #bit CREN = 0x18.4 // USART registers
8 #bit SPEN = 0x18.7 8 #bit SPEN = 0x18.7
9 #bit OERR = 0x18.1 9 #bit OERR = 0x18.1
10 #bit FERR = 0x18.2 10 #bit FERR = 0x18.2
11   11  
12 #include <string.h> 12 #include <string.h>
13 //!!! #include "bloader.c" // Boot Loader driver -  
14   13  
15 #CASE // Case sensitive compiler 14 #CASE // Case sensitive compiler
16   15  
17 #define MAXHEAT 20 // Number of cycles for heating 16 #define MAXHEAT 20 // Number of cycles for heating
18 #define MAXOPEN 20 // Number of cycles for dome open 17 #define MAXOPEN 20 // Number of cycles for dome open
Line 91... Line 90...
91 return temp; 90 return temp;
92 } 91 }
93   92  
94   93  
95 /*-------------------------------- MAIN --------------------------------------*/ 94 /*-------------------------------- MAIN --------------------------------------*/
96 void real_main() 95 void main()
97 { 96 {
98 unsigned int16 seq, temp, tempa; 97 unsigned int16 seq, temp, tempa;
99 signed int16 ta, to; 98 signed int16 ta, to;
100 int8 safety_counter; 99 int8 safety_counter;
101 int1 repeat; 100 int1 repeat;
Line 183... Line 182...
183 case 's': 182 case 's':
184 repeat=FALSE; // Single measure mode 183 repeat=FALSE; // Single measure mode
185 break; 184 break;
186   185  
187 case 'u': 186 case 'u':
188 // load_program(); // Update firmware 187 reset_cpu(); // Update firmware
189 } 188 }
190 } 189 }
191 // while(kbhit()) getc(); // Flush USART buffer 190 // while(kbhit()) getc(); // Flush USART buffer
192 CREN=0; CREN=1; // Reinitialise USART 191 CREN=0; CREN=1; // Reinitialise USART
193   192  
Line 229... Line 228...
229 restart_wdt(); 228 restart_wdt();
230 } 229 }
231 } 230 }
232   231  
233   232  
234 /*------------------- BOOT LOADER --------------------------------------------*/ -  
235 #define LOADER_RESERVED getenv("PROGRAM_MEMORY")-getenv("FLASH_ERASE_SIZE")-800 -  
236 #define BUFFER_LEN_LOD 46 -  
237   -  
238 #ORG LOADER_RESERVED,getenv("PROGRAM_MEMORY")-201 auto=0 default -  
239   -  
240 unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8 -  
241 unsigned int result = 0; -  
242 int i; -  
243   -  
244 for (i=0; i<2; i++,s++) { -  
245 if (*s >= 'A') -  
246 result = 16*result + (*s) - 'A' + 10; -  
247 else -  
248 result = 16*result + (*s) - '0'; -  
249 } -  
250   -  
251 return(result); -  
252 } -  
253   -  
254 void assert(int1 Condition, int8 ErrorCode) -  
255 { -  
256 if(Condition) -  
257 { -  
258 putchar('E'); -  
259 putchar(ErrorCode+'1'); -  
260 reset_cpu(); -  
261 } -  
262 } -  
263   -  
264 void pause() -  
265 { -  
266 int16 timeout; -  
267   -  
268 for(timeout=0; timeout<65535; timeout++); // Delay cca 300ms -  
269 } -  
270   -  
271 boot_loader() -  
272 { -  
273 int buffidx; -  
274 char buffer[BUFFER_LEN_LOD]; -  
275   -  
276 int8 checksum, line_type; -  
277 int16 l_addr,h_addr=0; -  
278 int32 addr; -  
279 #if getenv("FLASH_ERASE_SIZE")>2 -  
280 int32 next_addr; -  
281 #endif -  
282   -  
283 //!!! #error ble getenv("FLASH_ERASE_SIZE") getenv("FLASH_WRITE_SIZE") -  
284   -  
285 int8 dataidx, i, count; -  
286 union program_data { -  
287 int8 i8[16]; -  
288 int16 i16[8]; -  
289 } data; -  
290   -  
291 putchar('@'); -  
292   -  
293 //!!!nesmaze obsluhu preruseni -  
294 for(i=getenv("FLASH_ERASE_SIZE")+1;i<LOADER_RESERVED;i+=getenv("FLASH_ERASE_SIZE")) -  
295 erase_program_eeprom(i); -  
296   -  
297 putchar('@'); -  
298   -  
299 while(TRUE) -  
300 { -  
301 //---WDT -  
302 //!!! musi fungovat watchdog -  
303 while (getc()!=':') restart_wdt(); // Only process data blocks that starts with ':' -  
304   -  
305 buffidx = 0; // Read into the buffer until 'x' is received or buffer is full -  
306 do -  
307 { -  
308 buffer[buffidx] = getc(); -  
309 } while ( (buffer[buffidx++] != 'x') && (buffidx < BUFFER_LEN_LOD) ); -  
310 assert(buffidx == BUFFER_LEN_LOD,1); // Overrun buffer? -  
311   -  
312 //---WDT -  
313 restart_wdt(); -  
314   -  
315 checksum = 0; // Sum the bytes to find the check sum value 233 #include "dbloader.c" // Space reservation for the BootLoader
316 for (i=0; i<(buffidx-3); i+=2) -  
317 checksum += atoi_b16 (&buffer[i]); -  
318 checksum = 0xFF - checksum + 1; -  
319 assert(checksum != atoi_b16 (&buffer[buffidx-3]),2); // Bad CheckSum? -  
320   -  
321 count = atoi_b16 (&buffer[0]); // Get the number of bytes from the buffer -  
322   -  
323 // Get the lower 16 bits of address -  
324 l_addr = make16(atoi_b16(&buffer[2]),atoi_b16(&buffer[4])); -  
325   -  
326 line_type = atoi_b16 (&buffer[6]); -  
327   -  
328 addr = make32(h_addr,l_addr); -  
329   -  
330 addr /= 2; // PIC16 uses word addresses -  
331   -  
332 // If the line type is 1, then data is done being sent -  
333 if (line_type == 1) -  
334 { -  
335 putchar('#'); -  
336 reset_cpu(); -  
337 } -  
338   -  
339 assert (line_type == 4,4); -  
340   -  
341   -  
342 //!!! pozor, nevypalilo by to obsluhu preruseni -  
343 if (addr > 3 || addr < LOADER_RESERVED) -  
344 { -  
345   -  
346 if (line_type == 0) -  
347 { -  
348 for (i=0,next_addr=addr;i<8;i++) -  
349 data.i16[i]=read_program_eeprom(next_addr++); -  
350 // Loops through all of the data and stores it in data -  
351 // The last 2 bytes are the check sum, hence buffidx-3 -  
352 for (i=8,dataidx=0; i < buffidx-3; i += 2) -  
353 data.i8[dataidx++]=atoi_b16(&buffer[i]); -  
354   -  
355 write_program_memory(addr, data.i8, count); -  
356 } -  
357 putchar('*'); -  
358 } -  
359 } -  
360 } -  
361   -  
362 #ORG default -  
363   -  
364 #ORG getenv("PROGRAM_MEMORY")-200,getenv("PROGRAM_MEMORY")-1 -  
365 void main() -  
366 { -  
367 int8 timeout; -  
368   -  
369 disable_interrupts(GLOBAL); -  
370 setup_wdt(WDT_2304MS); // Setup Watch Dog -  
371 setup_adc_ports(NO_ANALOGS); -  
372 setup_adc(ADC_OFF); -  
373 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); -  
374 setup_timer_1(T1_DISABLED); -  
375 setup_timer_2(T2_DISABLED,0,1); -  
376 setup_comparator(NC_NC_NC_NC); -  
377 setup_vref(FALSE); -  
378 setup_oscillator(OSC_8MHZ|OSC_INTRC); -  
379   -  
380 /* -  
381 for(timeout=0; timeout<(3*20); timeout++) //cca 20s -  
382 if (kbhit()) -  
383 { -  
384 if (getc()=='u') if (getc()=='f') boot_loader(); // Update Firmware starter -  
385 pause(); -  
386 CREN=0; CREN=1; -  
387 restart_wdt(); -  
388 }; -  
389 */ -  
390 real_main(); -  
391 } -  
392   -  
393 #include "dbloader.c" -