3 #include <avr/pgmspace.h>
9 #include "../monitor.h"
11 static uint8_t get_hex(char c)
24 case 'A': case 'a': return 10;
25 case 'B': case 'b': return 11;
26 case 'C': case 'c': return 12;
27 case 'D': case 'd': return 13;
28 case 'E': case 'e': return 14;
29 case 'F': case 'f': return 15;
38 uint8_t len, count, sum, type = 0;
41 uint8_t echo = uart_echo;
45 printf_P(PSTR("Please send IHEX file now.\n"));
48 /* wait for RECORD START */
50 while(c != ':') c = uart_getc(NULL);
52 /* read RECORD LENGTH */
53 c=uart_getc(NULL); len = get_hex(c) << 4;
54 c=uart_getc(NULL); len |= get_hex(c);
57 /* read LOAD OFFSET */
58 c=uart_getc(NULL); addr = get_hex(c) << 12;
59 c=uart_getc(NULL); addr |= get_hex(c) << 8;
60 c=uart_getc(NULL); addr |= get_hex(c) << 4;
61 c=uart_getc(NULL); addr |= get_hex(c);
65 /* read RECORD TYPE */
66 c=uart_getc(NULL); type = get_hex(c) << 4;
67 c=uart_getc(NULL); type |= get_hex(c);
71 for(uint8_t i = 0; i < len; i++) {
72 c = uart_getc(NULL); byte = get_hex(c) << 4;
73 c = uart_getc(NULL); byte |= get_hex(c);
76 mem_write(addr + i, byte);
80 c = uart_getc(NULL); byte = get_hex(c) << 4;
81 c = uart_getc(NULL); byte |= get_hex(c);
84 if(sum) printf_P(PSTR("\nFAIL:0x%02x"), sum);
85 else printf_P(PSTR("\r0x%04x"), addr);
89 if((char)(uart_getc(NULL)) == '\r') uart_getc(NULL);
91 printf_P(PSTR("\nReading IHEX file finished.\n"));