]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_Kinetis_K60_Tower_IAR/Freescale_Code/common/startup.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_Kinetis_K60_Tower_IAR / Freescale_Code / common / startup.c
1 /*\r
2  * File:    startup.c\r
3  * Purpose: Generic Kinetis startup code\r
4  *\r
5  * Notes:\r
6  */\r
7 \r
8 #include "common.h"\r
9 \r
10 #if (defined(IAR))\r
11         #pragma section = ".data"\r
12         #pragma section = ".data_init"\r
13         #pragma section = ".bss"\r
14         #pragma section = "CodeRelocate"\r
15         #pragma section = "CodeRelocateRam"\r
16 #endif\r
17 \r
18 /********************************************************************/\r
19 void\r
20 common_startup(void)\r
21 {\r
22 \r
23 #if (defined(CW))       \r
24     extern char __START_BSS[];\r
25     extern char __END_BSS[];\r
26     extern uint32 __DATA_ROM[];\r
27     extern uint32 __DATA_RAM[];\r
28     extern char __DATA_END[];\r
29 #endif\r
30 \r
31     /* Declare a counter we'll use in all of the copy loops */\r
32     uint32 n;\r
33 \r
34     /* Declare pointers for various data sections. These pointers\r
35      * are initialized using values pulled in from the linker file\r
36      */\r
37     uint8 * data_ram, * data_rom, * data_rom_end;\r
38     uint8 * bss_start, * bss_end;\r
39 \r
40 \r
41     /* Get the addresses for the .data section (initialized data section) */\r
42         #if (defined(CW))\r
43         data_ram = (uint8 *)__DATA_RAM;\r
44             data_rom = (uint8 *)__DATA_ROM;\r
45             data_rom_end  = (uint8 *)__DATA_END; /* This is actually a RAM address in CodeWarrior */\r
46             n = data_rom_end - data_ram;\r
47     #elif (defined(IAR))\r
48                 data_ram = __section_begin(".data");\r
49                 data_rom = __section_begin(".data_init");\r
50                 data_rom_end = __section_end(".data_init");\r
51                 n = data_rom_end - data_rom;\r
52         #endif          \r
53                 \r
54         /* Copy initialized data from ROM to RAM */\r
55         while (n--)\r
56                 *data_ram++ = *data_rom++;\r
57         \r
58         \r
59     /* Get the addresses for the .bss section (zero-initialized data) */\r
60         #if (defined(CW))\r
61                 bss_start = (uint8 *)__START_BSS;\r
62                 bss_end = (uint8 *)__END_BSS;\r
63         #elif (defined(IAR))\r
64                 bss_start = __section_begin(".bss");\r
65                 bss_end = __section_end(".bss");\r
66         #endif\r
67                 \r
68                 \r
69         \r
70 \r
71     /* Clear the zero-initialized data section */\r
72     n = bss_end - bss_start;\r
73     while(n--)\r
74       *bss_start++ = 0;\r
75 \r
76         /* Get addresses for any code sections that need to be copied from ROM to RAM.\r
77          * The IAR tools have a predefined keyword that can be used to mark individual\r
78          * functions for execution from RAM. Add "__ramfunc" before the return type in\r
79          * the function prototype for any routines you need to execute from RAM instead\r
80          * of ROM. ex: __ramfunc void foo(void);\r
81          */\r
82         #if (defined(IAR))\r
83                 uint8* code_relocate_ram = __section_begin("CodeRelocateRam");\r
84                 uint8* code_relocate = __section_begin("CodeRelocate");\r
85                 uint8* code_relocate_end = __section_end("CodeRelocate");\r
86 \r
87                 /* Copy functions from ROM to RAM */\r
88                 n = code_relocate_end - code_relocate;\r
89                 while (n--)\r
90                         *code_relocate_ram++ = *code_relocate++;\r
91         #endif\r
92 }\r
93 /********************************************************************/\r