fsl_common.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "fsl_common.h"
  31. #include <rtthread.h>
  32. //#include "fsl_debug_console.h"
  33. #define PRINTF rt_kprintf
  34. #ifndef NDEBUG
  35. #if (defined(__CC_ARM)) || (defined(__ICCARM__))
  36. void __aeabi_assert(const char *failedExpr, const char *file, int line)
  37. {
  38. PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
  39. for (;;)
  40. {
  41. __BKPT(0);
  42. }
  43. }
  44. #elif(defined(__REDLIB__))
  45. #if SDK_DEBUGCONSOLE
  46. void __assertion_failed(char *_Expr)
  47. {
  48. PRINTF("%s\n", _Expr);
  49. for (;;)
  50. {
  51. __asm("bkpt #0");
  52. }
  53. }
  54. #endif
  55. #elif(defined(__GNUC__))
  56. void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
  57. {
  58. PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func);
  59. for (;;)
  60. {
  61. __BKPT(0);
  62. }
  63. }
  64. #endif /* (defined(__CC_ARM)) || (defined (__ICCARM__)) */
  65. #endif /* NDEBUG */
  66. #ifndef __GIC_PRIO_BITS
  67. //uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
  68. //{
  69. ///* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
  70. //#if defined(__CC_ARM)
  71. // extern uint32_t Image$$VECTOR_ROM$$Base[];
  72. // extern uint32_t Image$$VECTOR_RAM$$Base[];
  73. // extern uint32_t Image$$RW_m_data$$Base[];
  74. //#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
  75. //#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
  76. //#define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
  77. //#elif defined(__ICCARM__)
  78. // extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
  79. // extern uint32_t __VECTOR_TABLE[];
  80. // extern uint32_t __VECTOR_RAM[];
  81. //#elif defined(__GNUC__)
  82. // extern uint32_t __VECTOR_TABLE[];
  83. // extern uint32_t __VECTOR_RAM[];
  84. // extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
  85. // uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
  86. //#endif /* defined(__CC_ARM) */
  87. // uint32_t n;
  88. // uint32_t ret;
  89. // uint32_t irqMaskValue;
  90. // irqMaskValue = DisableGlobalIRQ();
  91. // if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
  92. // {
  93. // /* Copy the vector table from ROM to RAM */
  94. // for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
  95. // {
  96. // __VECTOR_RAM[n] = __VECTOR_TABLE[n];
  97. // }
  98. // /* Point the VTOR to the position of vector table */
  99. // SCB->VTOR = (uint32_t)__VECTOR_RAM;
  100. // }
  101. // ret = __VECTOR_RAM[irq + 16];
  102. // /* make sure the __VECTOR_RAM is noncachable */
  103. // __VECTOR_RAM[irq + 16] = irqHandler;
  104. // EnableGlobalIRQ(irqMaskValue);
  105. // return ret;
  106. //}
  107. #endif
  108. #ifndef CPU_QN908X
  109. #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
  110. void EnableDeepSleepIRQ(IRQn_Type interrupt)
  111. {
  112. uint32_t index = 0;
  113. uint32_t intNumber = (uint32_t)interrupt;
  114. while (intNumber >= 32u)
  115. {
  116. index++;
  117. intNumber -= 32u;
  118. }
  119. SYSCON->STARTERSET[index] = 1u << intNumber;
  120. EnableIRQ(interrupt); /* also enable interrupt at NVIC */
  121. }
  122. void DisableDeepSleepIRQ(IRQn_Type interrupt)
  123. {
  124. uint32_t index = 0;
  125. uint32_t intNumber = (uint32_t)interrupt;
  126. while (intNumber >= 32u)
  127. {
  128. index++;
  129. intNumber -= 32u;
  130. }
  131. DisableIRQ(interrupt); /* also disable interrupt at NVIC */
  132. SYSCON->STARTERCLR[index] = 1u << intNumber;
  133. }
  134. #endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
  135. #else
  136. void EnableDeepSleepIRQ(IRQn_Type interrupt)
  137. {
  138. uint32_t index = 0;
  139. uint32_t intNumber = (uint32_t)interrupt;
  140. while (intNumber >= 32u)
  141. {
  142. index++;
  143. intNumber -= 32u;
  144. }
  145. /* SYSCON->STARTERSET[index] = 1u << intNumber; */
  146. EnableIRQ(interrupt); /* also enable interrupt at NVIC */
  147. }
  148. void DisableDeepSleepIRQ(IRQn_Type interrupt)
  149. {
  150. uint32_t index = 0;
  151. uint32_t intNumber = (uint32_t)interrupt;
  152. while (intNumber >= 32u)
  153. {
  154. index++;
  155. intNumber -= 32u;
  156. }
  157. DisableIRQ(interrupt); /* also disable interrupt at NVIC */
  158. /* SYSCON->STARTERCLR[index] = 1u << intNumber; */
  159. }
  160. #endif /*CPU_QN908X */