startup.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral :
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @implements startup.c_Artifact
  26. */
  27. /**
  28. * @page misra_violations MISRA-C:2012 violations
  29. *
  30. * @section [global]
  31. * Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block
  32. * scope if its identifier only appears in a single function.
  33. * All variables with this problem are defined in the linker files.
  34. *
  35. * @section [global]
  36. * Violates MISRA 2012 Advisory Rule 8.11, When an array with external linkage
  37. * is declared, its size should be explicitly specified.
  38. * The size of the arrays can not be explicitly determined.
  39. *
  40. * @section [global]
  41. * Violates MISRA 2012 Advisory Rule 11.4, A conversion should not be performed
  42. * between a pointer to object and an integer type.
  43. * The cast is required to initialize a pointer with an unsigned int define,
  44. * representing an address.
  45. *
  46. * @section [global]
  47. * Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed
  48. * between pointer to void and an arithmetic type.
  49. * The cast is required to initialize a pointer with an unsigned int define,
  50. * representing an address.
  51. *
  52. * @section [global]
  53. * Violates MISRA 2012 Required Rule 2.1, A project shall not contain unreachable
  54. * code.
  55. * The condition compares two address defined in linker files that can be different.
  56. *
  57. * @section [global]
  58. * Violates MISRA 2012 Advisory Rule 8.7, External could be made static.
  59. * Function is defined for usage by application code.
  60. *
  61. * @section [global]
  62. * Violates MISRA 2012 Required Rule 1.3, Unusual pointer cast (incompatible
  63. * indirect types).
  64. * The cast is required to cast the address of linker section to initialization layout.
  65. *
  66. * @section [global]
  67. * Violates MISRA 2012 Required Rule 11.3, Cast performed between a pointer
  68. * to object type and a pointer to a different object type.
  69. * The cast is required to cast the address of linker section to initialization layout.
  70. *
  71. * @section [global]
  72. * Violates MISRA 2012 Required Rule 11.8, Attempt to cast away const/volatile from a pointer or reference.
  73. * The cast is required to cast the initialization layout structure.
  74. *
  75. * @section [global]
  76. * Violates MISRA 2012 Advisory Rule 18.4, Pointer arithmetic other than array indexing used.
  77. * This is required to increment the source address.
  78. *
  79. */
  80. #include "Std_Types.h"
  81. /*******************************************************************************
  82. * Definitions
  83. *******************************************************************************/
  84. /*!
  85. * @brief Defines the init table layout
  86. */
  87. typedef struct
  88. {
  89. uint8 * ram_start; /*!< Start address of section in RAM */
  90. uint8 * rom_start; /*!< Start address of section in ROM */
  91. uint8 * rom_end; /*!< End address of section in ROM */
  92. } Sys_CopyLayoutType;
  93. /*!
  94. * @brief Defines the zero table layout
  95. */
  96. typedef struct
  97. {
  98. uint8 * ram_start; /*!< Start address of section in RAM */
  99. uint8 * ram_end; /*!< End address of section in RAM */
  100. } Sys_ZeroLayoutType;
  101. extern uint32 __INIT_TABLE[];
  102. extern uint32 __ZERO_TABLE[];
  103. #if (defined(__ARMCC_VERSION))
  104. extern uint32 __VECTOR_RAM;
  105. #else
  106. extern uint32 __VECTOR_RAM[];
  107. #endif
  108. /*******************************************************************************
  109. * Static Variables
  110. ******************************************************************************/
  111. /*******************************************************************************
  112. * Code
  113. ******************************************************************************/
  114. /*FUNCTION**********************************************************************
  115. *
  116. * Function Name : init_data_bss
  117. * Description : Make necessary initializations for RAM.
  118. * - Copy the vector table from ROM to RAM.
  119. * - Copy initialized data from ROM to RAM.
  120. * - Copy code that should reside in RAM from ROM
  121. * - Clear the zero-initialized data section.
  122. *
  123. * Tool Chains:
  124. * __GNUC__ : GNU Compiler Collection
  125. * __ghs__ : Green Hills ARM Compiler
  126. * __ICCARM__ : IAR ARM Compiler
  127. * __DCC__ : Wind River Diab Compiler
  128. * __ARMCC_VERSION : ARMC Compiler
  129. *
  130. * Implements : init_data_bss_Activity
  131. *END**************************************************************************/
  132. void init_data_bss(void);
  133. void init_data_bss(void)
  134. {
  135. const Sys_CopyLayoutType * copy_layout;
  136. const Sys_ZeroLayoutType * zero_layout;
  137. const uint8 * rom;
  138. uint8 * ram;
  139. uint32 len = 0U;
  140. uint32 size = 0U;
  141. uint32 i = 0U;
  142. uint32 j = 0U;
  143. const uint32 * initTable_Ptr = (uint32 *)__INIT_TABLE;
  144. const uint32 * zeroTable_Ptr = (uint32*)__ZERO_TABLE;
  145. /* Copy initialized table */
  146. len = *initTable_Ptr;
  147. initTable_Ptr++;
  148. copy_layout = (const Sys_CopyLayoutType *)initTable_Ptr;
  149. for(i = 0; i < len; i++)
  150. {
  151. rom = copy_layout[i].rom_start;
  152. ram = copy_layout[i].ram_start;
  153. size = (uint32)copy_layout[i].rom_end - (uint32)copy_layout[i].rom_start;
  154. for(j = 0UL; j < size; j++)
  155. {
  156. ram[j] = rom[j];
  157. }
  158. }
  159. /* Clear zero table */
  160. len = *zeroTable_Ptr;
  161. zeroTable_Ptr++;
  162. zero_layout = (const Sys_ZeroLayoutType *)zeroTable_Ptr;
  163. for(i = 0; i < len; i++)
  164. {
  165. ram = zero_layout[i].ram_start;
  166. size = (uint32)zero_layout[i].ram_end - (uint32)zero_layout[i].ram_start;
  167. for(j = 0UL; j < size; j++)
  168. {
  169. ram[j] = 0U;
  170. }
  171. }
  172. }
  173. /*******************************************************************************
  174. * EOF
  175. ******************************************************************************/