cmem7_misc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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_CME_CODE ((uint32_t)0x00000000)
  80. #define NVIC_VectTab_RAM ((uint32_t)0x20000000)
  81. #define NVIC_VectTab_FLASH ((uint32_t)0x08000000)
  82. #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_CME_CODE) || \
  83. ((VECTTAB) == NVIC_VectTab_RAM) || \
  84. ((VECTTAB) == NVIC_VectTab_FLASH))
  85. /**
  86. * @}
  87. */
  88. /** @defgroup NVIC_LP
  89. * @{
  90. */
  91. #define NVIC_LP_SEVONPEND ((uint8_t)0x10)
  92. #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04)
  93. #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02)
  94. #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \
  95. ((LP) == NVIC_LP_SLEEPDEEP) || \
  96. ((LP) == NVIC_LP_SLEEPONEXIT))
  97. /**
  98. * @}
  99. */
  100. /** @defgroup NVIC_PriorityGroup
  101. * @{
  102. */
  103. #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
  104. 4 bits for subpriority */
  105. #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority
  106. 3 bits for subpriority */
  107. #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority
  108. 2 bits for subpriority */
  109. #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority
  110. 1 bits for subpriority */
  111. #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority
  112. 0 bits for subpriority */
  113. #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \
  114. ((GROUP) == NVIC_PriorityGroup_1) || \
  115. ((GROUP) == NVIC_PriorityGroup_2) || \
  116. ((GROUP) == NVIC_PriorityGroup_3) || \
  117. ((GROUP) == NVIC_PriorityGroup_4))
  118. /**
  119. * @}
  120. */
  121. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  122. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  123. #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF)
  124. /**
  125. * @brief Configures the priority grouping: pre-emption priority and subpriority.
  126. * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
  127. * This parameter can be one of the following values, ref as @ref NVIC_PriorityGroup:
  128. * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  129. * 4 bits for subpriority
  130. * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  131. * 3 bits for subpriority
  132. * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  133. * 2 bits for subpriority
  134. * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  135. * 1 bits for subpriority
  136. * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  137. * 0 bits for subpriority
  138. * @retval None
  139. */
  140. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
  141. /**
  142. * @brief Initializes the NVIC peripheral according to the specified
  143. * parameters in the NVIC_InitStruct.
  144. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  145. * the configuration information for the specified NVIC peripheral.
  146. * @retval None
  147. */
  148. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
  149. /**
  150. * @brief Sets the vector table location and Offset.
  151. * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
  152. * This parameter can be one of the following values, ref as @ref NVIC_VectTab:
  153. * @arg NVIC_VectTab_RAM
  154. * @arg NVIC_VectTab_FLASH
  155. * @param Offset: Vector Table base offset field. This value must be a multiple
  156. * of 0x200.
  157. * @retval None
  158. */
  159. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);
  160. /**
  161. * @brief Selects the condition for the system to enter low power mode.
  162. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  163. * This parameter can be one of the following values, ref as @ref NVIC_LP:
  164. * @arg NVIC_LP_SEVONPEND
  165. * @arg NVIC_LP_SLEEPDEEP
  166. * @arg NVIC_LP_SLEEPONEXIT
  167. * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
  168. * @retval None
  169. */
  170. void NVIC_SystemLPConfig(uint8_t LowPowerMode, BOOL NewState);
  171. /**
  172. * @brief Memory map from address 'from' to 'address 'to' and open icache or not
  173. * @param[in] from address to be mapped from
  174. * @param[in] to address to be mapped to
  175. * @param[in] isIcacheOn icache is on or off
  176. * @retval None
  177. */
  178. void GLB_MMAP(uint32_t from, uint32_t to, BOOL isIcacheOn);
  179. /**
  180. * @brief Convert the mapping destination address to source address
  181. * @param[in] to address to be mapped to
  182. * @retval uint32_t address to be mapped from
  183. */
  184. uint32_t GLB_ConvertToMappingFromAddr(uint32_t to);
  185. /**
  186. * @brief Convert the mapping source address to destination address
  187. * @param[in] from address to be mapped from
  188. * @retval uint32_t address to be mapped to
  189. */
  190. uint32_t GLB_ConvertToMappingToAddr(uint32_t from);
  191. /**
  192. * @brief Set NMI irq number, it should be one of @ref IRQn_Type.
  193. * @Note You can assign any valid IRQn_Type to NMI. After that, you will enter NMI
  194. * interrupt routine if the specific 'irq' occurs. By default, NMI irq number
  195. * is 0, same as ETH_INT_IRQn
  196. * @param[in] irq irq number
  197. * @retval None
  198. */
  199. void GLB_SetNmiIrqNum(uint32_t irq);
  200. /** @defgroup SYS_CLK_SEL
  201. * @{
  202. */
  203. #define SYS_CLK_SEL_OSC 0x0
  204. #define SYS_CLK_SEL_DLL 0x1
  205. #define SYS_CLK_SEL_CRYSTAL 0x2
  206. #define SYS_CLK_SEL_EXTERNAL 0x3
  207. /**
  208. * @}
  209. */
  210. /**
  211. * @brief Select system clock source, it should be one of @ref SYS_CLK_SEL.
  212. * @Note You MUST make sure externel clock has been stabled if clock
  213. * source is external before call this function.
  214. * Default value is SYS_CLK_SEL_OSC
  215. * @param[in] irq irq number
  216. * @retval None
  217. */
  218. void GLB_SelectSysClkSource(uint8_t source);
  219. /**
  220. * @brief Simulate instruction 'STRB' or 'STRH' with 'BFI'
  221. * @Note In M7, you have to write a register in 32-bit alignment,
  222. * not in 8-bit or 16-bit.
  223. * @param[in] addr register address to be written
  224. * @param[in] value value to be written
  225. * @param[in] lsb LSB in register to be written
  226. * @param[in] len bit length to be written
  227. * @retval None
  228. */
  229. //#define aaaa(len) __asm("LDR len, 11")
  230. #define CMEM7_BFI(addr, value, lsb, len) \
  231. do { \
  232. unsigned long tmp; \
  233. unsigned long tmp1 = (unsigned long)addr; \
  234. \
  235. __asm("LDR tmp, [tmp1]\n" \
  236. "BFI tmp, "#value", "#lsb", "#len" \n" \
  237. "STR tmp, [tmp1]\n"); \
  238. } while (0)
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif /* __CMEM7_MISC_H */