pmc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /******************************************************************************
  2. *
  3. * @brief header file for PMC.
  4. *
  5. *******************************************************************************
  6. *
  7. * provide APIs for accessing PMC
  8. ******************************************************************************/
  9. #ifndef PMC_H_
  10. #define PMC_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /******************************************************************************
  15. * Includes
  16. ******************************************************************************/
  17. /******************************************************************************
  18. * Macros
  19. ******************************************************************************/
  20. /******************************************************************************
  21. * PMC system mode definition
  22. *
  23. *//*! @addtogroup pmc_sysmode
  24. * @{
  25. *******************************************************************************/
  26. #define PmcModeRun 0 /*!< run mode */
  27. #define PmcModeWait 1 /*!< wait mode */
  28. #define PmcModeStop4 2 /*!< stop4 mode */
  29. #define PmcModeStop3 3 /*!< stop3 mode */
  30. /*! @} End of pmc_sysmode */
  31. /******************************************************************************
  32. * PMC LVD and LVW voltage definition
  33. *
  34. *//*! @addtogroup pmc_voltageselect
  35. * @{
  36. *******************************************************************************/
  37. #define PmcLVDTrip_Low 0 /*!< LVD low trip point */
  38. #define PmcLVDTrip_High 1 /*!< LVD high trip point */
  39. #define PmcLVWTrip_Low 0 /*!< LVW low trip point */
  40. #define PmcLVWTrip_Mid1 1 /*!< LVW mid1 trip point */
  41. #define PmcLVWTrip_Mid2 2 /*!< LVW mid2 trip point */
  42. #define PmcLVWTrip_High 3 /*!< LVW high trip point */
  43. /*! @} End of pmc_voltageselect */
  44. /******************************************************************************
  45. * Types
  46. ******************************************************************************/
  47. /******************************************************************************
  48. * PMC control struct
  49. *
  50. *//*! @addtogroup pmc_ctrlstruct
  51. * @{
  52. *******************************************************************************/
  53. /*!
  54. * @brief PMC Control Structure Type.
  55. *
  56. */
  57. typedef union
  58. {
  59. uint8_t byte; /*!< byte field of union type */
  60. struct
  61. {
  62. uint8_t bBandgapEn :1; /*!< bandgap enable */
  63. uint8_t bBandgapDrv :1; /*!< bandgap drive select */
  64. uint8_t bLvdEn :1; /*!< LVD enable */
  65. uint8_t bLvdStopEn :1; /*!< LVD enable in stop mode */
  66. uint8_t bLvdRstEn :1; /*!< reset enable when VLD evvent */
  67. uint8_t bLvwIrqEn :1; /*!< LVW int enable */
  68. uint8_t bLvwAck :1; /*!< LVW acknowledge */
  69. uint8_t bLvwFlag :1; /*!< LVW flag */
  70. }bits; /*!< bitfield of union type */
  71. }PMC_Ctrl1Type, *PMC_Ctrl1Ptr; /*!< PMC control1 reg structure */
  72. /*! @} End of pmc_ctrlstruct */
  73. /******************************************************************************
  74. * PMC control-- voltage select type.
  75. *
  76. *//*! @addtogroup pmc_voltselectstruct
  77. * @{
  78. *******************************************************************************/
  79. /*!
  80. * @brief PMC control-- voltage select type.
  81. *
  82. */
  83. typedef union
  84. {
  85. uint8_t byte; /*!< byte field of union type */
  86. struct
  87. {
  88. uint8_t :4; /*!< none */
  89. uint8_t bLVWV :2; /*!< LVW voltage select */
  90. uint8_t bLVDV :1; /*!< LVD voltage select */
  91. uint8_t :1; /*!< none */
  92. }bits; /*!< bitfield of union type */
  93. }PMC_Ctrl2Type, *PMC_Ctrl2Ptr; /*!< PMC control2 reg structure */
  94. /*! @} End of pmc_voltselectstruct */
  95. /******************************************************************************
  96. * PMC configrue type.
  97. *
  98. *//*! @addtogroup pmc_configstruct
  99. * @{
  100. *******************************************************************************/
  101. /*!
  102. * @brief PMC configrue type.
  103. *
  104. */
  105. typedef struct
  106. {
  107. PMC_Ctrl1Type sCtrlstatus; /*!< PMC control and status */
  108. PMC_Ctrl2Type sDetectVoltSelect; /*!< LVW and LVW voltage select */
  109. }PMC_ConfigType, *PMC_ConfigPtr; /*!< PMC configuration structure */
  110. /*! @} End of pmc_configstruct */
  111. /******************************************************************************
  112. * Global variables
  113. ******************************************************************************/
  114. /*!
  115. * inline functions
  116. */
  117. /******************************************************************************
  118. * PMC api list.
  119. *
  120. *//*! @addtogroup pmc_api_list
  121. * @{
  122. *******************************************************************************/
  123. /*****************************************************************************//*!
  124. *
  125. * @brief enable LVD events during stop mode.
  126. *
  127. * @param[in] pPMC pointer to the PMC module.
  128. *
  129. * @return none.
  130. *
  131. * @ Pass/ Fail criteria: none.
  132. *
  133. * @see PMC_DisableLVDInStopMode.
  134. *
  135. *****************************************************************************/
  136. __STATIC_INLINE void PMC_EnableLVDInStopMode(PMC_Type *pPMC)
  137. {
  138. pPMC->SPMSC1 |= PMC_SPMSC1_LVDSE_MASK;
  139. }
  140. /*****************************************************************************//*!
  141. *
  142. * @brief disable LVD events during stop mode.
  143. *
  144. * @param[in] pPMC pointer to the PMC module.
  145. *
  146. * @return none.
  147. *
  148. * @ Pass/ Fail criteria: none.
  149. *
  150. * @see PMC_EnableLVDInStopMode.
  151. *
  152. *****************************************************************************/
  153. __STATIC_INLINE void PMC_DisableLVDInStopMode(PMC_Type *pPMC)
  154. {
  155. pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDSE_MASK;
  156. }
  157. /*****************************************************************************//*!
  158. *
  159. * @brief enable LVD events to generate a hardware reset, note: write once.
  160. *
  161. * @param[in] pPMC pointer to the PMC module.
  162. *
  163. * @return none.
  164. *
  165. * @ Pass/ Fail criteria: none.
  166. *
  167. * @see PMC_DisableLVDRst.
  168. *
  169. *****************************************************************************/
  170. __STATIC_INLINE void PMC_EnableLVDRst(PMC_Type *pPMC)
  171. {
  172. pPMC->SPMSC1 |= PMC_SPMSC1_LVDRE_MASK;
  173. }
  174. /*****************************************************************************//*!
  175. *
  176. * @brief disable LVD events to generate a hardware reset, note: write once.
  177. *
  178. * @param[in] pPMC pointer to the PMC module.
  179. *
  180. * @return none.
  181. *
  182. * @ Pass/ Fail criteria: none.
  183. *
  184. * @see PMC_EnableLVDRst.
  185. *
  186. *****************************************************************************/
  187. __STATIC_INLINE void PMC_DisableLVDRst(PMC_Type *pPMC)
  188. {
  189. pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDRE_MASK;
  190. }
  191. /*****************************************************************************//*!
  192. *
  193. * @brief enable low-voltage detect logic, note: write once.
  194. *
  195. * @param[in] pPMC pointer to the PMC module.
  196. *
  197. * @return none.
  198. *
  199. * @ Pass/ Fail criteria: none.
  200. *
  201. * @see PMC_DisableLVD.
  202. *
  203. *****************************************************************************/
  204. __STATIC_INLINE void PMC_EnableLVD(PMC_Type *pPMC)
  205. {
  206. pPMC->SPMSC1 |= PMC_SPMSC1_LVDE_MASK;
  207. }
  208. /*****************************************************************************//*!
  209. *
  210. * @brief disable low-voltage detect logic, note: write once
  211. *
  212. * @param[in] pPMC pointer to the PMC module.
  213. *
  214. * @return none.
  215. *
  216. * @ Pass/ Fail criteria: none
  217. *
  218. * @see PMC_EnableLVD.
  219. *
  220. *****************************************************************************/
  221. __STATIC_INLINE void PMC_DisableLVD(PMC_Type *pPMC)
  222. {
  223. pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDE_MASK;
  224. }
  225. /*****************************************************************************//*!
  226. *
  227. * @brief set the low-voltage detect trip point voltage, note: write once.
  228. *
  229. * @param[in] pPMC pointer to the PMC module.
  230. * @param[in] Trippoint LVD trip point voltage,0~1.
  231. *
  232. * @return none.
  233. *
  234. * @ Pass/ Fail criteria: none.
  235. *
  236. * @see PMC_SetLVWTripVolt.
  237. *
  238. *****************************************************************************/
  239. __STATIC_INLINE void PMC_SetLVDTripVolt(PMC_Type *pPMC, uint8_t Trippoint)
  240. {
  241. if(Trippoint)
  242. pPMC->SPMSC2 |= PMC_SPMSC2_LVDV_MASK;
  243. else
  244. pPMC->SPMSC2 &= ~PMC_SPMSC2_LVDV_MASK;
  245. }
  246. /*****************************************************************************//*!
  247. *
  248. * @brief set the low-voltage warning (LVW) trip point voltage.
  249. *
  250. * @param[in] pPMC pointer to the PMC module.
  251. * @param[in] Trippoint LVW trip point voltage,0~3.
  252. *
  253. * @return none.
  254. *
  255. * @ Pass/ Fail criteria: none.
  256. *
  257. * @see PMC_SetLVDTripVolt.
  258. *
  259. *****************************************************************************/
  260. __STATIC_INLINE void PMC_SetLVWTripVolt(PMC_Type *pPMC, uint8_t Trippoint)
  261. {
  262. pPMC->SPMSC2 &= ~PMC_SPMSC2_LVWV_MASK;
  263. pPMC->SPMSC2 |= PMC_SPMSC2_LVWV(Trippoint);
  264. }
  265. /*****************************************************************************//*!
  266. *
  267. * @brief Enable hardware interrupt requests for LVWF.
  268. *
  269. * @param[in] pPMC pointer to the PMC module.
  270. *
  271. * @return none.
  272. *
  273. * @ Pass/ Fail criteria: none.
  274. *
  275. * @see PMC_DisableLVWInterrupt.
  276. *
  277. *****************************************************************************/
  278. __STATIC_INLINE void PMC_EnableLVWInterrupt(PMC_Type *pPMC)
  279. {
  280. pPMC->SPMSC1 |= PMC_SPMSC1_LVWIE_MASK;
  281. }
  282. /*****************************************************************************//*!
  283. *
  284. * @brief Disable hardware interrupt requests for LVWF.
  285. *
  286. * @param[in] pPMC pointer to the PMC module.
  287. *
  288. * @return none.
  289. *
  290. * @ Pass/ Fail criteria: none.
  291. *
  292. * @see PMC_EnableLVWInterrupt.
  293. *
  294. *****************************************************************************/
  295. __STATIC_INLINE void PMC_DisableLVWInterrupt(PMC_Type *pPMC)
  296. {
  297. pPMC->SPMSC1 &= ~PMC_SPMSC1_LVWIE_MASK;
  298. }
  299. /*****************************************************************************//*!
  300. *
  301. * @brief get the lvw warning flag.
  302. *
  303. * @param[in] pPMC pointer to the PMC module.
  304. *
  305. * @return uint8_t lvw warning flag.
  306. *
  307. * @ Pass/ Fail criteria: none.
  308. *
  309. * @see PMC_ClrLVWFlag.
  310. *
  311. *****************************************************************************/
  312. __STATIC_INLINE uint8_t PMC_GetLVWFlag(PMC_Type *pPMC)
  313. {
  314. return (pPMC->SPMSC1 & PMC_SPMSC1_LVWF_MASK);
  315. }
  316. /*****************************************************************************//*!
  317. *
  318. * @brief clear the lvw warning flag.
  319. *
  320. * @param[in] pPMC pointer to the PMC module.
  321. *
  322. * @return none.
  323. *
  324. * @ Pass/ Fail criteria: none.
  325. *
  326. * @see PMC_GetLVWFlag.
  327. *
  328. *****************************************************************************/
  329. __STATIC_INLINE void PMC_ClrLVWFlag(PMC_Type *pPMC)
  330. {
  331. pPMC->SPMSC1 |= PMC_SPMSC1_LVWACK_MASK;
  332. }
  333. /*! @} End of pmc_api_list */
  334. /******************************************************************************
  335. * Global functions
  336. ******************************************************************************/
  337. void PMC_Init(PMC_Type *pPMC, PMC_ConfigType *pPMC_Config);
  338. void PMC_DeInit(PMC_Type *pPMC);
  339. void PMC_SetMode(PMC_Type *pPMC,uint8_t u8PmcMode);
  340. #ifdef __cplusplus
  341. }
  342. #endif
  343. #endif /* PMC_H_ */