sys_startup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /** @file sys_startup.c
  2. * @brief Startup Source File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. * This file contains:
  7. * - Include Files
  8. * - Type Definitions
  9. * - External Functions
  10. * - VIM RAM Setup
  11. * - Startup Routine
  12. * .
  13. * which are relevant for the Startup.
  14. */
  15. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  16. /* Include Files */
  17. #include "sys_common.h"
  18. #include "system.h"
  19. #include "sys_vim.h"
  20. #include "sys_core.h"
  21. #include "sys_selftest.h"
  22. #include "esm.h"
  23. #include "mibspi.h"
  24. /* Type Definitions */
  25. typedef void (*handler_fptr)(const uint8 * in, uint8 * out);
  26. /* External Functions */
  27. /*SAFETYMCUSW 94 S MR:11.1 <REVIEWED> "Startup code(handler pointers)" */
  28. /*SAFETYMCUSW 296 S MR:8.6 <REVIEWED> "Startup code(library functions at block scope)" */
  29. /*SAFETYMCUSW 298 S MR: <REVIEWED> "Startup code(handler pointers)" */
  30. /*SAFETYMCUSW 299 S MR: <REVIEWED> "Startup code(typedef for handler pointers in library )" */
  31. /*SAFETYMCUSW 326 S MR:8.2 <REVIEWED> "Startup code(Declaration for main in library)" */
  32. /*SAFETYMCUSW 60 D MR:8.8 <REVIEWED> "Startup code(Declaration for main in library;Only doing an extern for the same)" */
  33. /*SAFETYMCUSW 94 S MR:11.1 <REVIEWED> "Startup code(handler pointers)" */
  34. /*SAFETYMCUSW 354 S MR:1.4 <REVIEWED> " Startup code(Extern declaration present in the library)" */
  35. /*SAFETYMCUSW 218 S MR:20.2 <REVIEWED> "Functions from library" */
  36. #ifdef __TI_COMPILER_VERSION__
  37. #pragma WEAK(__TI_Handler_Table_Base)
  38. #pragma WEAK(__TI_Handler_Table_Limit)
  39. #pragma WEAK(__TI_CINIT_Base)
  40. #pragma WEAK(__TI_CINIT_Limit)
  41. extern uint32 __TI_Handler_Table_Base;
  42. extern uint32 __TI_Handler_Table_Limit;
  43. extern uint32 __TI_CINIT_Base;
  44. extern uint32 __TI_CINIT_Limit;
  45. extern uint32 __TI_PINIT_Base;
  46. extern uint32 __TI_PINIT_Limit;
  47. extern uint32 * __binit__;
  48. #endif
  49. extern void main(void);
  50. /* USER CODE BEGIN (3) */
  51. /* USER CODE END */
  52. /* Startup Routine */
  53. /** @fn void memoryInit(uint32 ram)
  54. * @brief Memory Initialization Driver
  55. *
  56. * This function is called to perform Memory initialization of selected RAM's.
  57. */
  58. void memoryInit(uint32 ram)
  59. {
  60. /* USER CODE BEGIN (11) */
  61. /* USER CODE END */
  62. /* Enable Memory Hardware Initialization */
  63. systemREG1->MINITGCR = 0xAU;
  64. /* Enable Memory Hardware Initialization for selected RAM's */
  65. systemREG1->MSINENA = ram;
  66. /* Wait until Memory Hardware Initialization complete */
  67. while((systemREG1->MSTCGSTAT & 0x00000100U) != 0x00000100U)
  68. {
  69. }/* Wait */
  70. /* Disable Memory Hardware Initialization */
  71. systemREG1->MINITGCR = 0x5U;
  72. /* USER CODE BEGIN (12) */
  73. /* USER CODE END */
  74. }
  75. /* USER CODE BEGIN (4) */
  76. /* USER CODE END */
  77. void _c_int00(void)
  78. {
  79. /* Work Around for Errata DEVICE#140: ( Only on Rev A silicon)
  80. *
  81. * Errata Description:
  82. * The Core Compare Module(CCM-R4) may cause nERROR to be asserted after a cold power-on
  83. * Workaround:
  84. * Clear ESM Group2 Channel 2 error in ESMSR2 and Compare error in CCMSR register */
  85. if (DEVICE_ID_REV == 0x802AAD05U)
  86. {
  87. _esmCcmErrorsClear_();
  88. }
  89. /* USER CODE BEGIN (8) */
  90. /* USER CODE END */
  91. /* USER CODE BEGIN (11) */
  92. /* USER CODE END */
  93. /* Reset handler: the following instructions read from the system exception status register
  94. * to identify the cause of the CPU reset. */
  95. /* check for power-on reset condition */
  96. if ((SYS_EXCEPTION & POWERON_RESET) != 0U)
  97. {
  98. /* USER CODE BEGIN (12) */
  99. /* USER CODE END */
  100. /* clear all reset status flags */
  101. SYS_EXCEPTION = 0xFFFFU;
  102. /* USER CODE BEGIN (13) */
  103. /* USER CODE END */
  104. _errata_CORTEXR4_66_();
  105. /* USER CODE BEGIN (14) */
  106. /* USER CODE END */
  107. _errata_CORTEXR4_57_();
  108. /* USER CODE BEGIN (15) */
  109. /* USER CODE END */
  110. /* continue with normal start-up sequence */
  111. }
  112. else if ((SYS_EXCEPTION & OSC_FAILURE_RESET) != 0U)
  113. {
  114. /* Reset caused due to oscillator failure.
  115. Add user code here to handle oscillator failure */
  116. /* USER CODE BEGIN (16) */
  117. /* USER CODE END */
  118. }
  119. else if ((SYS_EXCEPTION & WATCHDOG_RESET) !=0U)
  120. {
  121. /* Reset caused due
  122. * 1) windowed watchdog violation - Add user code here to handle watchdog violation.
  123. * 2) ICEPICK Reset - After loading code via CCS / System Reset through CCS
  124. */
  125. /* Check the WatchDog Status register */
  126. if(WATCHDOG_STATUS != 0U)
  127. {
  128. /* Add user code here to handle watchdog violation. */
  129. /* USER CODE BEGIN (17) */
  130. /* USER CODE END */
  131. /* Clear the Watchdog reset flag in Exception Status register */
  132. SYS_EXCEPTION = WATCHDOG_RESET;
  133. /* USER CODE BEGIN (18) */
  134. /* USER CODE END */
  135. }
  136. else
  137. {
  138. /* Clear the ICEPICK reset flag in Exception Status register */
  139. SYS_EXCEPTION = ICEPICK_RESET;
  140. /* USER CODE BEGIN (19) */
  141. /* USER CODE END */
  142. }
  143. }
  144. else if ((SYS_EXCEPTION & CPU_RESET) !=0U)
  145. {
  146. /* Reset caused due to CPU reset.
  147. CPU reset can be caused by CPU self-test completion, or
  148. by toggling the "CPU RESET" bit of the CPU Reset Control Register. */
  149. /* USER CODE BEGIN (20) */
  150. /* USER CODE END */
  151. /* clear all reset status flags */
  152. SYS_EXCEPTION = CPU_RESET;
  153. /* USER CODE BEGIN (21) */
  154. /* USER CODE END */
  155. }
  156. else if ((SYS_EXCEPTION & SW_RESET) != 0U)
  157. {
  158. /* Reset caused due to software reset.
  159. Add user code to handle software reset. */
  160. /* USER CODE BEGIN (22) */
  161. /* USER CODE END */
  162. }
  163. else
  164. {
  165. /* Reset caused by nRST being driven low externally.
  166. Add user code to handle external reset. */
  167. /* USER CODE BEGIN (23) */
  168. /* USER CODE END */
  169. }
  170. /* USER CODE BEGIN (26) */
  171. /* USER CODE END */
  172. /* Initialize System - Clock, Flash settings with Efuse self check */
  173. systemInit();
  174. /* USER CODE BEGIN (29) */
  175. /* USER CODE END */
  176. /* USER CODE BEGIN (31) */
  177. /* USER CODE END */
  178. /* USER CODE BEGIN (33) */
  179. /* USER CODE END */
  180. /* USER CODE BEGIN (36) */
  181. /* USER CODE END */
  182. /* USER CODE BEGIN (37) */
  183. /* USER CODE END */
  184. /* Initialize CPU RAM.
  185. * This function uses the system module's hardware for auto-initialization of memories and their
  186. * associated protection schemes. The CPU RAM is initialized by setting bit 0 of the MSIENA register.
  187. * Hence the value 0x1 passed to the function.
  188. * This function will initialize the entire CPU RAM and the corresponding ECC locations.
  189. */
  190. memoryInit(0x1U);
  191. /* USER CODE BEGIN (38) */
  192. /* USER CODE END */
  193. _coreEnableRamEcc_();
  194. /* USER CODE BEGIN (39) */
  195. /* USER CODE END */
  196. /* USER CODE BEGIN (40) */
  197. /* USER CODE END */
  198. tcram1REG->RAMCTRL &= ~(0x00000100U); /* disable writes to ECC RAM */
  199. tcram2REG->RAMCTRL &= ~(0x00000100U);
  200. tcram1REG->RAMCTRL &= ~(0x00000100U); /* disable writes to ECC RAM */
  201. tcram2REG->RAMCTRL &= ~(0x00000100U);
  202. /* USER CODE BEGIN (41) */
  203. /* USER CODE END */
  204. /* USER CODE BEGIN (43) */
  205. /* USER CODE END */
  206. /* USER CODE BEGIN (44) */
  207. /* USER CODE END */
  208. /* USER CODE BEGIN (48) */
  209. /* USER CODE END */
  210. /* USER CODE BEGIN (56) */
  211. /* USER CODE END */
  212. /* Release the MibSPI1 modules from local reset.
  213. * This will cause the MibSPI1 RAMs to get initialized along with the parity memory.
  214. */
  215. mibspiREG1->GCR0 = 0x1U;
  216. /* Release the MibSPI3 modules from local reset.
  217. * This will cause the MibSPI3 RAMs to get initialized along with the parity memory.
  218. */
  219. mibspiREG3->GCR0 = 0x1U;
  220. /* Release the MibSPI5 modules from local reset.
  221. * This will cause the MibSPI5 RAMs to get initialized along with the parity memory.
  222. */
  223. mibspiREG5->GCR0 = 0x1U;
  224. /* USER CODE BEGIN (57) */
  225. /* USER CODE END */
  226. /* Initialize all on-chip SRAMs except for MibSPIx RAMs
  227. * The MibSPIx modules have their own auto-initialization mechanism which is triggered
  228. * as soon as the modules are brought out of local reset.
  229. */
  230. /* The system module auto-init will hang on the MibSPI RAM if the module is still in local reset.
  231. */
  232. /* NOTE : Please Refer DEVICE DATASHEET for the list of Supported Memories and their channel numbers.
  233. Memory Initialization is perfomed only on the user selected memories in HALCoGen's GUI SAFETY INIT tab.
  234. */
  235. memoryInit( (1U << 1U)
  236. | (1U << 2U)
  237. | (1U << 5U)
  238. | (1U << 6U)
  239. | (1U << 10U)
  240. | (1U << 8U)
  241. | (1U << 14U)
  242. | (1U << 3U)
  243. | (1U << 4U)
  244. | (1U << 15U)
  245. | (1U << 16U)
  246. | (0U << 13U) );
  247. /* USER CODE BEGIN (58) */
  248. /* USER CODE END */
  249. /* USER CODE BEGIN (59) */
  250. /* USER CODE END */
  251. /* USER CODE BEGIN (60) */
  252. /* USER CODE END */
  253. /* USER CODE BEGIN (61) */
  254. /* USER CODE END */
  255. /* USER CODE BEGIN (62) */
  256. /* USER CODE END */
  257. /* USER CODE BEGIN (63) */
  258. /* USER CODE END */
  259. /* USER CODE BEGIN (64) */
  260. /* USER CODE END */
  261. /* USER CODE BEGIN (65) */
  262. /* USER CODE END */
  263. /* USER CODE BEGIN (66) */
  264. /* USER CODE END */
  265. /* USER CODE BEGIN (67) */
  266. /* USER CODE END */
  267. /* USER CODE BEGIN (68) */
  268. /* USER CODE END */
  269. /* USER CODE BEGIN (69) */
  270. /* USER CODE END */
  271. while ((mibspiREG1->FLG & 0x01000000U) == 0x01000000U)
  272. {
  273. }/* Wait */
  274. /* wait for MibSPI1 RAM to complete initialization */
  275. while ((mibspiREG3->FLG & 0x01000000U) == 0x01000000U)
  276. {
  277. }/* Wait */
  278. /* wait for MibSPI3 RAM to complete initialization */
  279. while ((mibspiREG5->FLG & 0x01000000U) == 0x01000000U)
  280. {
  281. }/* Wait */
  282. /* wait for MibSPI5 RAM to complete initialization */
  283. /* USER CODE BEGIN (70) */
  284. /* USER CODE END */
  285. /* USER CODE BEGIN (71) */
  286. /* USER CODE END */
  287. /* USER CODE BEGIN (72) */
  288. /* USER CODE END */
  289. /* USER CODE BEGIN (73) */
  290. /* USER CODE END */
  291. /* USER CODE BEGIN (74) */
  292. /* USER CODE END */
  293. /* Initialize VIM table */
  294. vimInit();
  295. /* USER CODE BEGIN (75) */
  296. /* USER CODE END */
  297. #ifdef __GNUC__
  298. data_init();
  299. #elif defined(__TI_COMPILER_VERSION__)
  300. /* initialize copy table */
  301. if ((uint32 *)&__binit__ != (uint32 *)0xFFFFFFFFU)
  302. {
  303. extern void copy_in(void * binit);
  304. copy_in((void *)&__binit__);
  305. }
  306. /* initialize the C global variables */
  307. if (&__TI_Handler_Table_Base < &__TI_Handler_Table_Limit)
  308. {
  309. uint8 **tablePtr = (uint8 **)&__TI_CINIT_Base;
  310. uint8 **tableLimit = (uint8 **)&__TI_CINIT_Limit;
  311. while (tablePtr < tableLimit)
  312. {
  313. uint8 * loadAdr = *tablePtr++;
  314. uint8 * runAdr = *tablePtr++;
  315. uint8 idx = *loadAdr++;
  316. handler_fptr handler = (handler_fptr)(&__TI_Handler_Table_Base)[idx];
  317. (*handler)((const uint8 *)loadAdr, runAdr);
  318. }
  319. }
  320. /* initialize constructors */
  321. if (__TI_PINIT_Base < __TI_PINIT_Limit)
  322. {
  323. void (**p0)(void) = (void *)__TI_PINIT_Base;
  324. while ((uint32)p0 < __TI_PINIT_Limit)
  325. {
  326. void (*p)(void) = *p0++;
  327. p();
  328. }
  329. }
  330. #endif
  331. /* USER CODE BEGIN (76) */
  332. /* USER CODE END */
  333. /* call the application */
  334. main();
  335. /* USER CODE BEGIN (77) */
  336. /* USER CODE END */
  337. /* USER CODE BEGIN (78) */
  338. /* USER CODE END */
  339. }
  340. /* USER CODE BEGIN (79) */
  341. /* USER CODE END */