tao_z
2022-06-01 0ff91e66071237834a1501c78648729c8c32f67a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
  ******************************************************************************
  * @file     xl_pmc.c
  * @author   Kirk ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about PMC firmware program 
  ******************************************************************************
  * @attention
  *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
    
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
    
/* Includes ---------------------------------------------------------------*/
#include "xl_pmc.h"
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup PMC PMC Module 
  * @brief PMC Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/** @defgroup PMC_Private_Functions
  * @{
  */ 
 
/**
  * @brief  ½«PMCµÄÄ£¿éÉèÖÃΪ³õʼ״̬¡£
  * @param  None
  * @retval None.
  */
void PMC_Deinit(void)
{
    PMC->SPMSC = 0x001Cu;
}
 
/**
  * @brief  PMC³õʼ»¯
  * @param  PMC_InitStruct: PMC_InitTypeDef ÀàÐÍÖ¸Õ룬°üº¬ÁËPMC³õʼ»¯ÅäÖõIJÎÊýÐÅÏ¢
  * @retval None
  */
void PMC_Init(const PMC_InitTypeDef *PMC_InitStruct)
{
    uint16_t tmpreg;
 
    /*********************** configure the register. ****************************/
    /* Get the PMC SPMSC value */
    tmpreg = (uint16_t)PMC->SPMSC ;
    /* clear the bits in SPMSC register */
    tmpreg &= ~(uint16_t)(PMC_SPMSC_LVDE_MASK | PMC_SPMSC_LVDSE_MASK | PMC_SPMSC_LVDRE_MASK | \
            PMC_SPMSC_LVWIE_MASK | PMC_SPMSC_LVWV_MASK | PMC_SPMSC_LVDV_MASK) ;
    /* set PMC SPMSC: System Power Management Status and Control Register */
    tmpreg |= ( (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_LVWIntEnable  << PMC_SPMSC_LVWIE_SHIFT) & PMC_SPMSC_LVWIE_MASK) | \
                        (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_LVDRstEnable << PMC_SPMSC_LVDRE_SHIFT) & PMC_SPMSC_LVDRE_MASK) | \
                        (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_LVDStopEnable << PMC_SPMSC_LVDSE_SHIFT) & PMC_SPMSC_LVDSE_MASK) | \
                        (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_LVDectEnable  << PMC_SPMSC_LVDE_SHIFT) & PMC_SPMSC_LVDE_MASK) | \
                        (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_lvwvselect << PMC_SPMSC_LVWV_SHIFT) & PMC_SPMSC_LVWV_MASK) | \
                        (uint16_t)( ((uint16_t)PMC_InitStruct->PMC_lvdvselect << PMC_SPMSC_LVDV_SHIFT) & PMC_SPMSC_LVDV_MASK) );
    /* Write to PMC SPMSC */
    PMC->SPMSC = tmpreg ;
}
 
 
/**
  * @brief  ÓÃÔËÐС¢µÈ´ý¡¢Í£Ö¹À´½øÐÐÉèÖÃPMCģʽ
  * @param  u8PmcMode: ÒªÖ¸¶¨µÄPMCµÄģʽ.
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg PMC_ModeRun: ÔËÐÐģʽ
  *            @arg PMC_ModeWait: WAITģʽ
  *            @arg PMC_ModeStop4: STOPģʽʹÄÜLVD
  *            @arg PMC_ModeStop3: STOPģʽÊÇÄÜLVD
  * @retval None
  */
void PMC_SetMode(uint8_t u8PmcMode)
{
    switch(u8PmcMode & 0x3u)
    {
        case PMC_ModeRun:
            break;
        case PMC_ModeWait:
            /* Clear the SLEEPDEEP bit to make sure we go into WAIT (sleep) mode instead
             * of deep sleep.
             */
            SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
            /* using KEIL's uVision, use the CMSIS intrinsic */
            __WFI();
            break;
        case PMC_ModeStop4:
            /* enable LVD in stop mode */
            PMC->SPMSC |= (PMC_SPMSC_LVDE_MASK | PMC_SPMSC_LVDSE_MASK);
            /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
            SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
            /* using KEIL's uVision, use the CMSIS intrinsic */
            __WFI();
            break;
        case PMC_ModeStop3:
        default:
            /* disable LVD in stop mode */
            PMC->SPMSC &= ~(PMC_SPMSC_LVDE_MASK | PMC_SPMSC_LVDRE_MASK | PMC_SPMSC_LVDSE_MASK);
            /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
            SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
            /* using KEIL's uVision, use the CMSIS intrinsic */
            __WFI();
            break;
    }
}
 
/**
  * @brief  »ñµÃlvm¾¯¸æ±ê־λ
  * @param  None.
  * @retval PMC±ê־λ
  */
FlagStatus PMC_GetLVWFlag(void)
{    
    FlagStatus ret;
    if( (PMC->SPMSC & PMC_SPMSC_LVWF_MASK) == PMC_SPMSC_LVWF_MASK)
    {
        ret = SET;
    }
    else
    {
        ret= RESET;
    }
    
    return ret;
}
 
/**
  * @brief  Çå¿Õlvm¾¯¸æ±ê־λ.
  * @param  None.
  * @retval None.
  */
void PMC_ClrLVWFlag(void)
{
    if((PMC->SPMSC & PMC_SPMSC_LVWF_MASK) == PMC_SPMSC_LVWF_MASK)
    {
        /* LVWF must be cleared by writing LVWACK */
        PMC->SPMSC |= PMC_SPMSC_LVWACK_MASK; 
    }
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
 
#ifdef __cplusplus
}
#endif /* __cplusplus */