startup_iar.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*******************************************************************************
  2. *
  3. * Copyright 2013 - 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2019 NXP
  5. *
  6. * This software is owned or controlled by NXP and may only be used
  7. * strictly in accordance with the applicable license terms. By expressly
  8. * accepting such terms or by downloading, installing, activating and/or
  9. * otherwise using the software, you are agreeing that you have read, and
  10. * that you agree to comply with and are bound by, such license terms. If
  11. * you do not agree to be bound by the applicable license terms, then you
  12. * may not retain, install, activate or otherwise use the software.
  13. *
  14. *
  15. *******************************************************************************/
  16. #include "safety_config.h"
  17. #pragma section = ".data"
  18. #pragma section = ".data_init"
  19. #pragma section = ".safety_ram"
  20. #pragma section = ".safety_ram_init"
  21. #pragma section = ".bss"
  22. /*******************************************************************************
  23. * Prototypes
  24. ******************************************************************************/
  25. void common_startup(void);
  26. void write_vtor(int32_t);
  27. /*******************************************************************************
  28. * Code
  29. ******************************************************************************/
  30. /*!
  31. * @brief Initialization of RAM sections.
  32. *
  33. * @param void
  34. *
  35. * @return None
  36. */
  37. void common_startup(void)
  38. {
  39. /* Set the IVT address in SCB */
  40. extern uint32_t __VECTOR_TABLE[];
  41. write_vtor((uint32_t)__VECTOR_TABLE);
  42. #if (__FPU_PRESENT)
  43. SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access */
  44. #endif
  45. /* Declare a counter we'll use in all of the copy loops */
  46. uint32_t SectionLen;
  47. uint32_t *data_ram;
  48. uint32_t *data_rom;
  49. uint32_t *data_rom_end;
  50. /* Get the addresses for the .data section (initialized data section) */
  51. data_ram = __section_begin(".data");
  52. data_rom = __section_begin(".data_init");
  53. data_rom_end = __section_end(".data_init");
  54. /* Copy initialized data from ROM to RAM */
  55. SectionLen = data_rom_end - data_rom; /* This case in number of adress*/
  56. while (SectionLen--)
  57. {
  58. *data_ram++ = *data_rom++;
  59. #ifdef WATCHDOG_ON
  60. Watchdog_refresh;
  61. #endif
  62. }
  63. /* Get the addresses for the .safety_ram section (initialized safety_ram section) */
  64. data_ram = __section_begin(".safety_ram");
  65. data_rom = __section_begin(".safety_ram_init");
  66. data_rom_end = __section_end(".safety_ram_init");
  67. /* Copy initialized data from ROM to RAM */
  68. SectionLen = data_rom_end - data_rom; /* This case in number of adress*/
  69. while (SectionLen--)
  70. {
  71. *data_ram++ = *data_rom++;
  72. #ifdef WATCHDOG_ON
  73. Watchdog_refresh;
  74. #endif
  75. }
  76. /* Get the addresses for the .bss section (zero-initialized data) */
  77. uint32_t *bss_start, *bss_end;
  78. bss_start = __section_begin(".bss");
  79. bss_end = __section_end(".bss");
  80. SectionLen = bss_end - bss_start;
  81. while (SectionLen--)
  82. {
  83. *bss_start++ = 0;
  84. #ifdef WATCHDOG_ON
  85. Watchdog_refresh;
  86. #endif
  87. }
  88. #ifdef WATCHDOG_ON
  89. Watchdog_refresh;
  90. #endif
  91. }
  92. /*!
  93. * @brief write to VTOR register
  94. *
  95. * @param void
  96. *
  97. * @return None
  98. */
  99. void write_vtor(int32_t vtor)
  100. {
  101. unsigned long *pVTOR = (unsigned long *)0xE000ED08;
  102. *pVTOR = vtor;
  103. }