Rev 1300 Rev 1705
Line 1... Line 1...
1 /**** BootLoader ****/ 1 /**** BootLoader ****/
2 #define VERSION "1.0" 2 #define VERSION "1.1"
3 #define ID "$Id: bloader.c 1300 2009-01-17 08:41:49Z kakl $" 3 #define ID "$Id: bloader.c 1705 2010-12-05 19:24:34Z kakl $"
4   4  
5 #CASE // Case sensitive compiler 5 #CASE // Case sensitive compiler
6   6  
-   7 #define FLASH_BLOCK_SIZE 32
-   8 #define BLOADER_MAIN_LENGTH 139 // Rezervovane misto pro main BootLoaderu
-   9 #define RESERVED_BLOCKS 24 // Pocet rezervovanych bloku Flash pro BootLoader
-   10 #define LOADER_RESERVED getenv("PROGRAM_MEMORY")-RESERVED_BLOCKS*FLASH_BLOCK_SIZE
-   11 #define BUFFER_LEN_LOD 46
-   12 #if FLASH_BLOCK_SIZE != getenv("FLASH_ERASE_SIZE")/2
-   13 #error Wrong length of the Flash Block Size. getenv("FLASH_ERASE_SIZE")/getenv("FLASH_WRITE_SIZE")
-   14 #endif
-   15  
7 #include "bloader.h" 16 #include "bloader.h"
8 #include <string.h> 17 #include <string.h>
9   18  
10 #bit CREN = 0x18.4 // USART registers 19 #bit CREN = 0x18.4 // USART registers
11 #bit SPEN = 0x18.7 20 #bit SPEN = 0x18.7
12 #bit OERR = 0x18.1 21 #bit OERR = 0x18.1
13 #bit FERR = 0x18.2 22 #bit FERR = 0x18.2
14   23  
15   24  
16 #INT_RDA 25 #INT_RDA
17 rs232_handler() 26 void rs232_handler()
18 { 27 {
19 putchar(getc()); 28 putchar(getc());
20 } 29 }
21   30  
22 void welcome(void) // Welcome message 31 void welcome(void) // Welcome message
23 { 32 {
24 char REV[50]=ID; // Buffer for concatenate of a version string 33 char REV[50]=ID; // Buffer for concatenate of a version string
25 char VER[4]=VERSION; // Buffer for concatenate of a version string 34 char VER[4]=VERSION; // Buffer for concatenate of a version string
26   35  
27 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; 36 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 37 printf("\r\n\r\n# BLoader %s (C) 2007 KAKL\r\n",VER); // Welcome message
29 printf("#%s\n\r",&REV[4]); 38 printf("#%s\r\n",&REV[4]);
30 } 39 }
31   40  
32   41  
33 /*-------------------------------- MAIN --------------------------------------*/ 42 /*-------------------------------- MAIN --------------------------------------*/
34 #SEPARATE 43 #SEPARATE
Line 36... Line 45...
36 { 45 {
37 int8 i=0; 46 int8 i=0;
38   47  
39 welcome(); 48 welcome();
40   49  
-   50 printf("# Reserved: %Lu\r\n", RESERVED_BLOCKS*FLASH_BLOCK_SIZE);
-   51
41 printf("# Boot Loader Test >>>\n\r# "); 52 printf("# Boot Loader Test >>>\r\n# ");
42 enable_interrupts(INT_RDA); 53 enable_interrupts(INT_RDA);
43 enable_interrupts(GLOBAL); 54 enable_interrupts(GLOBAL);
44 while(TRUE) 55 while(TRUE)
45 { 56 {
46 printf("%u|",i++); 57 printf("%u|",i++);
Line 48... Line 59...
48 } 59 }
49 } 60 }
50   61  
51   62  
52 /*------------------- BOOT LOADER --------------------------------------------*/ 63 /*------------------- BOOT LOADER --------------------------------------------*/
53 #define FLASH_BLOCK_SIZE 32 -  
54 #define LOADER_RESERVED getenv("PROGRAM_MEMORY")-26*FLASH_BLOCK_SIZE -  
55 #define BUFFER_LEN_LOD 46 -  
56 #if FLASH_BLOCK_SIZE != getenv("FLASH_ERASE_SIZE")/2 -  
57 #error Wrong length of the Flash Block Size. getenv("FLASH_ERASE_SIZE")/getenv("FLASH_WRITE_SIZE") -  
58 #endif -  
59   -  
60   64  
61 #BUILD(INTERRUPT=FLASH_BLOCK_SIZE) // Redirect Interrupt routine above first flash block 65 #BUILD(INTERRUPT=FLASH_BLOCK_SIZE) // Redirect Interrupt routine above first flash block
62 #ORG 4,5 66 #ORG 4,5
63 void JumpToTheInterrupt() // Jump to the Interrupt Handler 67 void JumpToTheInterrupt() // Jump to the Interrupt Handler
64 { #asm GOTO FLASH_BLOCK_SIZE #endasm } 68 { #asm GOTO FLASH_BLOCK_SIZE #endasm }
Line 70... Line 74...
70 void dummy_main() // Main on the fix position 74 void dummy_main() // Main on the fix position
71 { 75 {
72 real_main(); 76 real_main();
73 } 77 }
74   78  
75 #ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-130 auto=0 default 79 #ORG LOADER_RESERVED+FLASH_BLOCK_SIZE,getenv("PROGRAM_MEMORY")-BLOADER_MAIN_LENGTH auto=0 default
76   80  
77 unsigned int atoi_b16(char *s) // Convert two hex characters to an int8 81 unsigned int atoi_b16(char *s) // Convert two hex characters to an int8
78 { 82 {
79 unsigned int result = 0; 83 unsigned int result = 0;
80 int i; 84 int i;
Line 105... Line 109...
105   109  
106 for(timeout=0; timeout<65535; timeout++); // Delay cca 300ms 110 for(timeout=0; timeout<65535; timeout++); // Delay cca 300ms
107 } 111 }
108   112  
109 #SEPARATE 113 #SEPARATE
110 boot_loader() 114 void boot_loader()
111 { 115 {
112 int buffidx; 116 int buffidx;
113 char buffer[BUFFER_LEN_LOD]; 117 char buffer[BUFFER_LEN_LOD];
114   118  
115 int8 checksum, line_type; 119 int8 checksum, line_type;
116 int16 l_addr,h_addr=0; 120 int16 l_addr,h_addr=0;
117 int16 addr; 121 int16 addr;
118 int32 next_addr; 122 int32 next_addr;
119   123  
120 int8 dataidx, i, count; 124 int8 dataidx, i;
121 union program_data { 125 union program_data {
122 int8 i8[16]; 126 int8 i8[16];
123 int16 i16[8]; 127 int16 i16[8];
124 } data; 128 } data;
125   129  
Line 215... Line 219...
215 } 219 }
216 } 220 }
217   221  
218 #ORG default 222 #ORG default
219   223  
220 #ORG getenv("PROGRAM_MEMORY")-129,getenv("PROGRAM_MEMORY")-1 auto=0 224 #ORG getenv("PROGRAM_MEMORY")-BLOADER_MAIN_LENGTH+1,getenv("PROGRAM_MEMORY")-1 auto=0
221 void main() 225 void main()
222 { 226 {
223 int8 timeout; 227 int8 timeout;
224   228  
225 disable_interrupts(GLOBAL); 229 disable_interrupts(GLOBAL);