cmem7_misc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. *****************************************************************************
  3. * @file cmem7_misc.h
  4. *
  5. * @brief CMEM7 miscellaneous header file
  6. *
  7. *
  8. * @version V1.0
  9. * @date 3. September 2013
  10. *
  11. * @note
  12. *
  13. *****************************************************************************
  14. * @attention
  15. *
  16. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  17. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  18. * TIME. AS A RESULT, CAPITAL-MICRO SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  19. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  20. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  21. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22. *
  23. * <h2><center>&copy; COPYRIGHT 2013 Capital-micro </center></h2>
  24. *****************************************************************************
  25. */
  26. #ifndef __CMEM7_MISC_H
  27. #define __CMEM7_MISC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "cmem7.h"
  32. #include "cmem7_conf.h"
  33. /**
  34. * @brief NVIC initialization structure
  35. */
  36. /**
  37. @code
  38. The table below gives the allowed values of the pre-emption priority and subpriority according
  39. to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
  40. ============================================================================================================================
  41. NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description
  42. ============================================================================================================================
  43. NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority
  44. | | | 4 bits for subpriority
  45. ----------------------------------------------------------------------------------------------------------------------------
  46. NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority
  47. | | | 3 bits for subpriority
  48. ----------------------------------------------------------------------------------------------------------------------------
  49. NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority
  50. | | | 2 bits for subpriority
  51. ----------------------------------------------------------------------------------------------------------------------------
  52. NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority
  53. | | | 1 bits for subpriority
  54. ----------------------------------------------------------------------------------------------------------------------------
  55. NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority
  56. | | | 0 bits for subpriority
  57. ============================================================================================================================
  58. @endcode
  59. */
  60. typedef struct
  61. {
  62. uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled.
  63. This parameter can be a value of @ref IRQn_Type
  64. (For the complete Capital-micro Devices IRQ Channels list, please
  65. refer to cmem7.h file) */
  66. uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel
  67. specified in NVIC_IRQChannel. This parameter can be a value
  68. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  69. uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified
  70. in NVIC_IRQChannel. This parameter can be a value
  71. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  72. BOOL NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
  73. will be enabled or disabled.
  74. This parameter can be set either to ENABLE or DISABLE */
  75. } NVIC_InitTypeDef;
  76. /** @defgroup NVIC_VectTab
  77. * @{
  78. */
  79. #define NVIC_VectTab_RAM ((uint32_t)0x20000000)
  80. #define NVIC_VectTab_FLASH ((uint32_t)0x08000000)
  81. #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \
  82. ((VECTTAB) == NVIC_VectTab_FLASH))
  83. /**
  84. * @}
  85. */
  86. /** @defgroup NVIC_LP
  87. * @{
  88. */
  89. #define NVIC_LP_SEVONPEND ((uint8_t)0x10)
  90. #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04)
  91. #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02)
  92. #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \
  93. ((LP) == NVIC_LP_SLEEPDEEP) || \
  94. ((LP) == NVIC_LP_SLEEPONEXIT))
  95. /**
  96. * @}
  97. */
  98. /** @defgroup NVIC_PriorityGroup
  99. * @{
  100. */
  101. #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
  102. 4 bits for subpriority */
  103. #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority
  104. 3 bits for subpriority */
  105. #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority
  106. 2 bits for subpriority */
  107. #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority
  108. 1 bits for subpriority */
  109. #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority
  110. 0 bits for subpriority */
  111. #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \
  112. ((GROUP) == NVIC_PriorityGroup_1) || \
  113. ((GROUP) == NVIC_PriorityGroup_2) || \
  114. ((GROUP) == NVIC_PriorityGroup_3) || \
  115. ((GROUP) == NVIC_PriorityGroup_4))
  116. /**
  117. * @}
  118. */
  119. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  120. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  121. #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF)
  122. /**
  123. * @brief Configures the priority grouping: pre-emption priority and subpriority.
  124. * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
  125. * This parameter can be one of the following values, ref as @ref NVIC_PriorityGroup:
  126. * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  127. * 4 bits for subpriority
  128. * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  129. * 3 bits for subpriority
  130. * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  131. * 2 bits for subpriority
  132. * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  133. * 1 bits for subpriority
  134. * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  135. * 0 bits for subpriority
  136. * @retval None
  137. */
  138. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
  139. /**
  140. * @brief Initializes the NVIC peripheral according to the specified
  141. * parameters in the NVIC_InitStruct.
  142. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  143. * the configuration information for the specified NVIC peripheral.
  144. * @retval None
  145. */
  146. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
  147. /**
  148. * @brief Sets the vector table location and Offset.
  149. * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
  150. * This parameter can be one of the following values, ref as @ref NVIC_VectTab:
  151. * @arg NVIC_VectTab_RAM
  152. * @arg NVIC_VectTab_FLASH
  153. * @param Offset: Vector Table base offset field. This value must be a multiple
  154. * of 0x200.
  155. * @retval None
  156. */
  157. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);
  158. /**
  159. * @brief Selects the condition for the system to enter low power mode.
  160. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  161. * This parameter can be one of the following values, ref as @ref NVIC_LP:
  162. * @arg NVIC_LP_SEVONPEND
  163. * @arg NVIC_LP_SLEEPDEEP
  164. * @arg NVIC_LP_SLEEPONEXIT
  165. * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
  166. * @retval None
  167. */
  168. void NVIC_SystemLPConfig(uint8_t LowPowerMode, BOOL NewState);
  169. /**
  170. * @brief Memory map from address 'from' to 'address 'to' and open icache or not
  171. * @param[in] from address to be mapped from
  172. * @param[in] to address to be mapped to
  173. * @param[in] isIcacheOn icache is on or off
  174. * @retval None
  175. */
  176. void GLB_MMAP(uint32_t from, uint32_t to, BOOL isIcacheOn);
  177. /**
  178. * @brief Set NMI irq number, it should be one of @ref IRQn_Type.
  179. * @Note You can assign any valid IRQn_Type to NMI. After that, you will enter NMI
  180. * interrupt routine if the specific 'irq' occurs. By default, NMI irq number
  181. * is 0, same as ETH_INT_IRQn
  182. * @param[in] irq irq number
  183. * @retval None
  184. */
  185. void GLB_SetNmiIrqNum(uint32_t irq);
  186. /** @defgroup SYS_CLK_SEL
  187. * @{
  188. */
  189. #define SYS_CLK_SEL_OSC 0x0
  190. #define SYS_CLK_SEL_DLL 0x1
  191. #define SYS_CLK_SEL_CRYSTAL 0x2
  192. #define SYS_CLK_SEL_EXTERNAL 0x3
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @brief Select system clock source, it should be one of @ref SYS_CLK_SEL.
  198. * @Note You MUST make sure externel clock has been stabled if clock
  199. * source is external before call this function.
  200. * Default value is SYS_CLK_SEL_OSC
  201. * @param[in] irq irq number
  202. * @retval None
  203. */
  204. void GLB_SelectSysClkSource(uint8_t source);
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #endif /* __CMEM7_MISC_H */