sys_startup.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. /* Startup Routine */
  51. /** @fn void memoryInit(uint32 ram)
  52. * @brief Memory Initialization Driver
  53. *
  54. * This function is called to perform Memory initialization of selected RAM's.
  55. */
  56. void memoryInit(uint32 ram)
  57. {
  58. /* Enable Memory Hardware Initialization */
  59. systemREG1->MINITGCR = 0xAU;
  60. /* Enable Memory Hardware Initialization for selected RAM's */
  61. systemREG1->MSINENA = ram;
  62. /* Wait until Memory Hardware Initialization complete */
  63. while((systemREG1->MSTCGSTAT & 0x00000100U) != 0x00000100U)
  64. {
  65. }/* Wait */
  66. /* Disable Memory Hardware Initialization */
  67. systemREG1->MINITGCR = 0x5U;
  68. }
  69. void _c_int00(void)
  70. {
  71. /* Work Around for Errata DEVICE#140: ( Only on Rev A silicon)
  72. *
  73. * Errata Description:
  74. * The Core Compare Module(CCM-R4) may cause nERROR to be asserted after a cold power-on
  75. * Workaround:
  76. * Clear ESM Group2 Channel 2 error in ESMSR2 and Compare error in CCMSR register */
  77. if (DEVICE_ID_REV == 0x802AAD05U)
  78. {
  79. _esmCcmErrorsClear_();
  80. }
  81. _errata_CORTEXR4_66_();
  82. _errata_CORTEXR4_57_();
  83. /* Reset handler: the following instructions read from the system exception status register
  84. * to identify the cause of the CPU reset. */
  85. /* check for power-on reset condition */
  86. if ((SYS_EXCEPTION & POWERON_RESET) != 0U)
  87. {
  88. /* clear all reset status flags */
  89. SYS_EXCEPTION = 0xFFFFU;
  90. /* continue with normal start-up sequence */
  91. }
  92. else if ((SYS_EXCEPTION & OSC_FAILURE_RESET) != 0U)
  93. {
  94. /* Reset caused due to oscillator failure.
  95. Add user code here to handle oscillator failure */
  96. }
  97. else if ((SYS_EXCEPTION & WATCHDOG_RESET) !=0U)
  98. {
  99. /* Reset caused due
  100. * 1) windowed watchdog violation - Add user code here to handle watchdog violation.
  101. * 2) ICEPICK Reset - After loading code via CCS / System Reset through CCS
  102. */
  103. /* Check the WatchDog Status register */
  104. if(WATCHDOG_STATUS != 0U)
  105. {
  106. /* Add user code here to handle watchdog violation. */
  107. /* Clear the Watchdog reset flag in Exception Status register */
  108. SYS_EXCEPTION = WATCHDOG_RESET;
  109. }
  110. else
  111. {
  112. /* Clear the ICEPICK reset flag in Exception Status register */
  113. SYS_EXCEPTION = ICEPICK_RESET;
  114. }
  115. }
  116. else if ((SYS_EXCEPTION & CPU_RESET) !=0U)
  117. {
  118. /* Reset caused due to CPU reset.
  119. CPU reset can be caused by CPU self-test completion, or
  120. by toggling the "CPU RESET" bit of the CPU Reset Control Register. */
  121. /* clear all reset status flags */
  122. SYS_EXCEPTION = CPU_RESET;
  123. }
  124. else if ((SYS_EXCEPTION & SW_RESET) != 0U)
  125. {
  126. /* Reset caused due to software reset.
  127. Add user code to handle software reset. */
  128. }
  129. else
  130. {
  131. /* Reset caused by nRST being driven low externally.
  132. Add user code to handle external reset. */
  133. }
  134. /* Initialize System - Clock, Flash settings with Efuse self check */
  135. systemInit();
  136. /* Initialize CPU RAM.
  137. * This function uses the system module's hardware for auto-initialization of memories and their
  138. * associated protection schemes. The CPU RAM is initialized by setting bit 0 of the MSIENA register.
  139. * Hence the value 0x1 passed to the function.
  140. * This function will initialize the entire CPU RAM and the corresponding ECC locations.
  141. */
  142. memoryInit(0x1U);
  143. _coreEnableRamEcc_();
  144. /* Release the MibSPI1 modules from local reset.
  145. * This will cause the MibSPI1 RAMs to get initialized along with the parity memory.
  146. */
  147. mibspiREG1->GCR0 = 0x1U;
  148. /* Release the MibSPI3 modules from local reset.
  149. * This will cause the MibSPI3 RAMs to get initialized along with the parity memory.
  150. */
  151. mibspiREG3->GCR0 = 0x1U;
  152. /* Release the MibSPI5 modules from local reset.
  153. * This will cause the MibSPI5 RAMs to get initialized along with the parity memory.
  154. */
  155. mibspiREG5->GCR0 = 0x1U;
  156. /* Initialize all on-chip SRAMs except for MibSPIx RAMs The MibSPIx modules
  157. * have their own auto-initialization mechanism which is triggered as soon
  158. * as the modules are brought out of local reset. */
  159. /* The system module auto-init will hang on the MibSPI RAM if the module is
  160. * still in local reset. */
  161. /* NOTE : Please Refer DEVICE DATASHEET for the list of Supported Memories
  162. * and their channel numbers. Memory Initialization is perfomed only on
  163. * the user selected memories in HALCoGen's GUI SAFETY INIT tab. */
  164. memoryInit((1U << 1U) | (1U << 2U) | (1U << 5U) | (1U << 6U)
  165. | (1U << 10U) | (1U << 8U) | (1U << 14U) | (1U << 3U)
  166. | (1U << 4U) | (1U << 15U) | (1U << 16U) | (0U << 13U) );
  167. while ((mibspiREG1->FLG & 0x01000000U) == 0x01000000U)
  168. {
  169. }/* Wait */
  170. /* wait for MibSPI1 RAM to complete initialization */
  171. while ((mibspiREG3->FLG & 0x01000000U) == 0x01000000U)
  172. {
  173. }/* Wait */
  174. /* wait for MibSPI3 RAM to complete initialization */
  175. while ((mibspiREG5->FLG & 0x01000000U) == 0x01000000U)
  176. {
  177. }/* Wait */
  178. /* wait for MibSPI5 RAM to complete initialization */
  179. /* Initialize VIM table */
  180. vimInit();
  181. #ifdef __GNUC__
  182. data_init();
  183. #elif defined(__TI_COMPILER_VERSION__)
  184. /* initialize copy table */
  185. if ((uint32 *)&__binit__ != (uint32 *)0xFFFFFFFFU)
  186. {
  187. extern void copy_in(void * binit);
  188. copy_in((void *)&__binit__);
  189. }
  190. /* initialize the C global variables */
  191. if (&__TI_Handler_Table_Base < &__TI_Handler_Table_Limit)
  192. {
  193. uint8 **tablePtr = (uint8 **)&__TI_CINIT_Base;
  194. uint8 **tableLimit = (uint8 **)&__TI_CINIT_Limit;
  195. while (tablePtr < tableLimit)
  196. {
  197. uint8 * loadAdr = *tablePtr++;
  198. uint8 * runAdr = *tablePtr++;
  199. uint8 idx = *loadAdr++;
  200. handler_fptr handler = (handler_fptr)(&__TI_Handler_Table_Base)[idx];
  201. (*handler)((const uint8 *)loadAdr, runAdr);
  202. }
  203. }
  204. /* initialize constructors */
  205. if (__TI_PINIT_Base < __TI_PINIT_Limit)
  206. {
  207. void (**p0)(void) = (void *)__TI_PINIT_Base;
  208. while ((uint32)p0 < __TI_PINIT_Limit)
  209. {
  210. void (*p)(void) = *p0++;
  211. p();
  212. }
  213. }
  214. #endif
  215. /* call the application */
  216. main();
  217. }