pmc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /******************************************************************************
  2. * @brief providing APIs for configuring PMC.
  3. *
  4. *******************************************************************************
  5. *
  6. * provide APIs for configuring PMC
  7. ******************************************************************************/
  8. #include "common.h"
  9. #include "pmc.h"
  10. /******************************************************************************
  11. * Constants
  12. ******************************************************************************/
  13. /******************************************************************************
  14. * Macros
  15. ******************************************************************************/
  16. /******************************************************************************
  17. * Types
  18. ******************************************************************************/
  19. /******************************************************************************
  20. * Global variables
  21. ******************************************************************************/
  22. /******************************************************************************
  23. * Global functions
  24. ******************************************************************************/
  25. /******************************************************************************
  26. * PMC api list.
  27. *
  28. *//*! @addtogroup pmc_api_list
  29. * @{
  30. *******************************************************************************/
  31. /*****************************************************************************//*!
  32. *
  33. * @brief configure PMC with given parameters.
  34. *
  35. * @param[in] pPMC_Config PMC configuration structure.
  36. * @param[in] pPMC pointer to the PMC module.
  37. *
  38. * @return none.
  39. *
  40. * @ Pass/ Fail criteria: none.
  41. *
  42. * @see PMC_DeInit.
  43. *
  44. *****************************************************************************/
  45. void PMC_Init(PMC_Type *pPMC, PMC_ConfigType *pPMC_Config)
  46. {
  47. pPMC->SPMSC1 = pPMC_Config->sCtrlstatus.byte;
  48. pPMC->SPMSC2 = pPMC_Config->sDetectVoltSelect.byte;
  49. }
  50. /*****************************************************************************//*!
  51. *
  52. * @brief config the pmc register to the default mode.
  53. *
  54. * @param[in] pPMC pointer to the PMC module.
  55. *
  56. * @return none.
  57. *
  58. * @ Pass/ Fail criteria: none.
  59. *
  60. * @see PMC_Init.
  61. *
  62. *****************************************************************************/
  63. void PMC_DeInit(PMC_Type *pPMC)
  64. {
  65. pPMC->SPMSC1 = 0x1C;
  66. pPMC->SPMSC2 = 0;
  67. }
  68. /*****************************************************************************//*!
  69. *
  70. * @brief config the pmc mode among run, wait and stop modes.
  71. *
  72. * @param[in] u8PmcMode PMC mode select.
  73. * @param[in] pPMC pointer to the PMC module.
  74. *
  75. * @return none.
  76. *
  77. * @ Pass/ Fail criteria: none.
  78. *
  79. *****************************************************************************/
  80. void PMC_SetMode(PMC_Type *pPMC,uint8_t u8PmcMode)
  81. {
  82. switch(u8PmcMode & 0x3)
  83. {
  84. case PmcModeRun:
  85. break;
  86. case PmcModeWait:
  87. wait();
  88. break;
  89. case PmcModeStop4:
  90. /* enable LVD in stop mode */
  91. pPMC->SPMSC1 |= (PMC_SPMSC1_LVDE_MASK | PMC_SPMSC1_LVDSE_MASK);
  92. stop();
  93. break;
  94. case PmcModeStop3:
  95. /* disable LVD in stop mode */
  96. pPMC->SPMSC1 &= ~(PMC_SPMSC1_LVDE_MASK | PMC_SPMSC1_LVDRE_MASK | PMC_SPMSC1_LVDSE_MASK);
  97. stop();
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. /*! @} End of pmc_api_list */