fsl_common.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016 NXP
  5. * All rights reserved.
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted (subject to the limitations in the disclaimer below) provided
  10. * that the following conditions are met:
  11. *
  12. * o Redistributions of source code must retain the above copyright notice, this list
  13. * of conditions and the following disclaimer.
  14. *
  15. * o Redistributions in binary form must reproduce the above copyright notice, this
  16. * list of conditions and the following disclaimer in the documentation and/or
  17. * other materials provided with the distribution.
  18. *
  19. * o Neither the name of the copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include "fsl_common.h"
  36. #ifndef __GIC_PRIO_BITS
  37. #if defined(ENABLE_RAM_VECTOR_TABLE)
  38. uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
  39. {
  40. /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
  41. #if defined(__CC_ARM)
  42. extern uint32_t Image$$VECTOR_ROM$$Base[];
  43. extern uint32_t Image$$VECTOR_RAM$$Base[];
  44. extern uint32_t Image$$RW_m_data$$Base[];
  45. #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
  46. #define __VECTOR_RAM Image$$VECTOR_RAM$$Base
  47. #define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
  48. #elif defined(__ICCARM__)
  49. extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
  50. extern uint32_t __VECTOR_TABLE[];
  51. extern uint32_t __VECTOR_RAM[];
  52. #elif defined(__GNUC__)
  53. extern uint32_t __VECTOR_TABLE[];
  54. extern uint32_t __VECTOR_RAM[];
  55. extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
  56. uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
  57. #endif /* defined(__CC_ARM) */
  58. uint32_t n;
  59. uint32_t ret;
  60. uint32_t irqMaskValue;
  61. irqMaskValue = DisableGlobalIRQ();
  62. if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
  63. {
  64. /* Copy the vector table from ROM to RAM */
  65. for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
  66. {
  67. __VECTOR_RAM[n] = __VECTOR_TABLE[n];
  68. }
  69. /* Point the VTOR to the position of vector table */
  70. SCB->VTOR = (uint32_t)__VECTOR_RAM;
  71. }
  72. ret = __VECTOR_RAM[irq + 16];
  73. /* make sure the __VECTOR_RAM is noncachable */
  74. __VECTOR_RAM[irq + 16] = irqHandler;
  75. EnableGlobalIRQ(irqMaskValue);
  76. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  77. exception return operation might vector to incorrect interrupt */
  78. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  79. __DSB();
  80. #endif
  81. return ret;
  82. }
  83. #endif /* ENABLE_RAM_VECTOR_TABLE. */
  84. #endif /* __GIC_PRIO_BITS. */
  85. #ifndef QN908XC_SERIES
  86. #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
  87. void EnableDeepSleepIRQ(IRQn_Type interrupt)
  88. {
  89. uint32_t index = 0;
  90. uint32_t intNumber = (uint32_t)interrupt;
  91. while (intNumber >= 32u)
  92. {
  93. index++;
  94. intNumber -= 32u;
  95. }
  96. SYSCON->STARTERSET[index] = 1u << intNumber;
  97. EnableIRQ(interrupt); /* also enable interrupt at NVIC */
  98. }
  99. void DisableDeepSleepIRQ(IRQn_Type interrupt)
  100. {
  101. uint32_t index = 0;
  102. uint32_t intNumber = (uint32_t)interrupt;
  103. while (intNumber >= 32u)
  104. {
  105. index++;
  106. intNumber -= 32u;
  107. }
  108. DisableIRQ(interrupt); /* also disable interrupt at NVIC */
  109. SYSCON->STARTERCLR[index] = 1u << intNumber;
  110. }
  111. #endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
  112. #endif /* QN908XC_SERIES */