misc.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file misc.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __MISC_H__
  35. #define __MISC_H__
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "n32g45x.h"
  40. /** @addtogroup N32G45X_StdPeriph_Driver
  41. * @{
  42. */
  43. /** @addtogroup MISC
  44. * @{
  45. */
  46. /** @addtogroup MISC_Exported_Types
  47. * @{
  48. */
  49. /**
  50. * @brief NVIC Init Structure definition
  51. */
  52. typedef struct
  53. {
  54. uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled.
  55. This parameter can be a value of @ref IRQn_Type
  56. (For the complete N32G45X Devices IRQ Channels list, please
  57. refer to n32g45x.h file) */
  58. uint8_t
  59. NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel
  60. specified in NVIC_IRQChannel. This parameter can be a value
  61. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  62. uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified
  63. in NVIC_IRQChannel. This parameter can be a value
  64. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  65. FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
  66. will be enabled or disabled.
  67. This parameter can be set either to ENABLE or DISABLE */
  68. } NVIC_InitType;
  69. /**
  70. * @}
  71. */
  72. /** @addtogroup NVIC_Priority_Table
  73. * @{
  74. */
  75. /**
  76. @code
  77. The table below gives the allowed values of the pre-emption priority and subpriority according
  78. to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
  79. ============================================================================================================================
  80. NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description
  81. ============================================================================================================================
  82. NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption
  83. priority | | | 4 bits for subpriority
  84. ----------------------------------------------------------------------------------------------------------------------------
  85. NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption
  86. priority | | | 3 bits for subpriority
  87. ----------------------------------------------------------------------------------------------------------------------------
  88. NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption
  89. priority | | | 2 bits for subpriority
  90. ----------------------------------------------------------------------------------------------------------------------------
  91. NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption
  92. priority | | | 1 bits for subpriority
  93. ----------------------------------------------------------------------------------------------------------------------------
  94. NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption
  95. priority | | | 0 bits for subpriority
  96. ============================================================================================================================
  97. @endcode
  98. */
  99. /**
  100. * @}
  101. */
  102. /** @addtogroup MISC_Exported_Constants
  103. * @{
  104. */
  105. /** @addtogroup Vector_Table_Base
  106. * @{
  107. */
  108. #define NVIC_VectTab_RAM ((uint32_t)0x20000000)
  109. #define NVIC_VectTab_FLASH ((uint32_t)0x08000000)
  110. #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || ((VECTTAB) == NVIC_VectTab_FLASH))
  111. /**
  112. * @}
  113. */
  114. /** @addtogroup System_Low_Power
  115. * @{
  116. */
  117. #define NVIC_LP_SEVONPEND ((uint8_t)0x10)
  118. #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04)
  119. #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02)
  120. #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || ((LP) == NVIC_LP_SLEEPDEEP) || ((LP) == NVIC_LP_SLEEPONEXIT))
  121. /**
  122. * @}
  123. */
  124. /** @addtogroup Preemption_Priority_Group
  125. * @{
  126. */
  127. #define NVIC_PriorityGroup_0 \
  128. ((uint32_t)0x700) /*!< 0 bits for pre-emption priority \
  129. 4 bits for subpriority */
  130. #define NVIC_PriorityGroup_1 \
  131. ((uint32_t)0x600) /*!< 1 bits for pre-emption priority \
  132. 3 bits for subpriority */
  133. #define NVIC_PriorityGroup_2 \
  134. ((uint32_t)0x500) /*!< 2 bits for pre-emption priority \
  135. 2 bits for subpriority */
  136. #define NVIC_PriorityGroup_3 \
  137. ((uint32_t)0x400) /*!< 3 bits for pre-emption priority \
  138. 1 bits for subpriority */
  139. #define NVIC_PriorityGroup_4 \
  140. ((uint32_t)0x300) /*!< 4 bits for pre-emption priority \
  141. 0 bits for subpriority */
  142. #define IS_NVIC_PRIORITY_GROUP(GROUP) \
  143. (((GROUP) == NVIC_PriorityGroup_0) || ((GROUP) == NVIC_PriorityGroup_1) || ((GROUP) == NVIC_PriorityGroup_2) \
  144. || ((GROUP) == NVIC_PriorityGroup_3) || ((GROUP) == NVIC_PriorityGroup_4))
  145. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  146. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  147. #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF)
  148. /**
  149. * @}
  150. */
  151. /** @addtogroup SysTick_clock_source
  152. * @{
  153. */
  154. //#define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB)
  155. #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004)
  156. #define IS_SYSTICK_CLK_SOURCE(SOURCE) ((SOURCE) == SysTick_CLKSource_HCLK)
  157. /**
  158. * @}
  159. */
  160. /**
  161. * @}
  162. */
  163. /** @addtogroup MISC_Exported_Macros
  164. * @{
  165. */
  166. /**
  167. * @}
  168. */
  169. /** @addtogroup MISC_Exported_Functions
  170. * @{
  171. */
  172. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
  173. void NVIC_Init(NVIC_InitType* NVIC_InitStruct);
  174. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);
  175. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState Cmd);
  176. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource);
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif /* __MISC_H__ */
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. /**
  188. * @}
  189. */