OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F103_Keil/] [STM32F10xFWLib/] [src/] [stm32f10x_pwr.c] - Blame information for rev 582

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 jeremybenn
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
2
* File Name          : stm32f10x_pwr.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 09/29/2006
5
* Description        : This file provides all the PWR firmware functions.
6
********************************************************************************
7
* History:
8
* 04/02/2007: V0.2
9
* 02/05/2007: V0.1
10
* 09/29/2006: V0.01
11
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
15
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
16
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
/* Includes ------------------------------------------------------------------*/
21
#include "stm32f10x_pwr.h"
22
#include "stm32f10x_rcc.h"
23
 
24
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
26
/* --------- PWR registers bit address in the alias region ---------- */
27
#define PWR_OFFSET               (PWR_BASE - PERIPH_BASE)
28
 
29
/* --- CR Register ---*/
30
/* Alias word address of DBP bit */
31
#define CR_OFFSET                (PWR_OFFSET + 0x00)
32
#define DBP_BitNumber            0x08
33
#define CR_DBP_BB                (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
34
 
35
/* Alias word address of PVDE bit */
36
#define PVDE_BitNumber           0x04
37
#define CR_PVDE_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
38
 
39
/* --- CSR Register ---*/
40
/* Alias word address of EWUP bit */
41
#define CSR_OFFSET               (PWR_OFFSET + 0x04)
42
#define EWUP_BitNumber           0x08
43
#define CSR_EWUP_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
44
 
45
/* ------------------ PWR registers bit mask ------------------------ */
46
/* CR register bit mask */
47
#define CR_PDDS_Set              ((u32)0x00000002)
48
#define CR_DS_Mask               ((u32)0xFFFFFFFC)
49
#define CR_CWUF_Set              ((u32)0x00000004)
50
#define CR_PLS_Mask              ((u32)0xFFFFFF1F)
51
 
52
/* --------- Cortex System Control register bit mask ---------------- */
53
/* Cortex System Control register address */
54
#define SCB_SysCtrl              ((u32)0xE000ED10)
55
/* SLEEPDEEP bit mask */
56
#define SysCtrl_SLEEPDEEP_Set    ((u32)0x00000004)
57
 
58
/* Private macro -------------------------------------------------------------*/
59
/* Private variables ---------------------------------------------------------*/
60
/* Private function prototypes -----------------------------------------------*/
61
/* Private functions ---------------------------------------------------------*/
62
 
63
/*******************************************************************************
64
* Function Name  : PWR_DeInit
65
* Description    : Deinitializes the PWR peripheral registers to their default
66
*                  reset values.
67
* Input          : None
68
* Output         : None
69
* Return         : None
70
*******************************************************************************/
71
void PWR_DeInit(void)
72
{
73
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
74
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
75
}
76
 
77
/*******************************************************************************
78
* Function Name  : PWR_BackupAccessCmd
79
* Description    : Enables or disables access to the RTC and backup registers.
80
* Input          : - NewState: new state of the access to the RTC and backup
81
*                    registers. This parameter can be: ENABLE or DISABLE.
82
* Output         : None
83
* Return         : None
84
*******************************************************************************/
85
void PWR_BackupAccessCmd(FunctionalState NewState)
86
{
87
  /* Check the parameters */
88
  assert(IS_FUNCTIONAL_STATE(NewState));
89
 
90
  *(vu32 *) CR_DBP_BB = (u32)NewState;
91
}
92
 
93
/*******************************************************************************
94
* Function Name  : PWR_PVDCmd
95
* Description    : Enables or disables the Power Voltage Detector(PVD).
96
* Input          : - NewState: new state of the PVD.
97
*                    This parameter can be: ENABLE or DISABLE.
98
* Output         : None
99
* Return         : None
100
*******************************************************************************/
101
void PWR_PVDCmd(FunctionalState NewState)
102
{
103
  /* Check the parameters */
104
  assert(IS_FUNCTIONAL_STATE(NewState));
105
 
106
  *(vu32 *) CR_PVDE_BB = (u32)NewState;
107
}
108
 
109
/*******************************************************************************
110
* Function Name  : PWR_PVDLevelConfig
111
* Description    : Configures the value detected by the Power Voltage Detector(PVD).
112
* Input          : - PWR_PVDLevel: specifies the PVD detection level
113
*                    This parameter can be one of the following values:
114
*                       - PWR_PVDLevel_2V2: PVD detection level set to 2.2V
115
*                       - PWR_PVDLevel_2V3: PVD detection level set to 2.3V
116
*                       - PWR_PVDLevel_2V4: PVD detection level set to 2.4V
117
*                       - PWR_PVDLevel_2V5: PVD detection level set to 2.5V
118
*                       - PWR_PVDLevel_2V6: PVD detection level set to 2.6V
119
*                       - PWR_PVDLevel_2V7: PVD detection level set to 2.7V
120
*                       - PWR_PVDLevel_2V8: PVD detection level set to 2.8V
121
*                       - PWR_PVDLevel_2V9: PVD detection level set to 2.9V
122
* Output         : None
123
* Return         : None
124
*******************************************************************************/
125
void PWR_PVDLevelConfig(u32 PWR_PVDLevel)
126
{
127
  u32 tmpreg = 0;
128
 
129
  /* Check the parameters */
130
  assert(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
131
 
132
  tmpreg = PWR->CR;
133
 
134
  /* Clear PLS[7:5] bits */
135
  tmpreg &= CR_PLS_Mask;
136
 
137
  /* Set PLS[7:5] bits according to PWR_PVDLevel value */
138
  tmpreg |= PWR_PVDLevel;
139
 
140
  /* Store the new value */
141
  PWR->CR = tmpreg;
142
}
143
 
144
/*******************************************************************************
145
* Function Name  : PWR_WakeUpPinCmd
146
* Description    : Enables or disables the WakeUp Pin functionality.
147
* Input          : - NewState: new state of the WakeUp Pin functionality.
148
*                    This parameter can be: ENABLE or DISABLE.
149
* Output         : None
150
* Return         : None
151
*******************************************************************************/
152
void PWR_WakeUpPinCmd(FunctionalState NewState)
153
{
154
  /* Check the parameters */
155
  assert(IS_FUNCTIONAL_STATE(NewState));
156
 
157
  *(vu32 *) CSR_EWUP_BB = (u32)NewState;
158
}
159
 
160
/*******************************************************************************
161
* Function Name  : PWR_EnterSTOPMode
162
* Description    : Enters STOP mode.
163
* Input          : - PWR_Regulator: specifies the regulator state in STOP mode.
164
*                    This parameter can be one of the following values:
165
*                       - PWR_Regulator_ON: STOP mode with regulator ON
166
*                       - PWR_Regulator_LowPower: STOP mode with
167
*                         regulator in low power mode
168
*                  - PWR_STOPEntry: specifies if STOP mode in entered with WFI or
169
*                    WFE instruction.
170
*                    This parameter can be one of the following values:
171
*                       - PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
172
*                       - PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
173
* Output         : None
174
* Return         : None
175
*******************************************************************************/
176
void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)
177
{
178
  u32 tmpreg = 0;
179
 
180
  /* Check the parameters */
181
  assert(IS_PWR_REGULATOR(PWR_Regulator));
182
  assert(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
183
 
184
  /* Select the regulator state in STOP mode ---------------------------------*/
185
  tmpreg = PWR->CR;
186
 
187
  /* Clear PDDS and LPDS bits */
188
  tmpreg &= CR_DS_Mask;
189
 
190
  /* Set LPDS bit according to PWR_Regulator value */
191
  tmpreg |= PWR_Regulator;
192
 
193
  /* Store the new value */
194
  PWR->CR = tmpreg;
195
 
196
  /* Set SLEEPDEEP bit of Cortex System Control Register */
197
  *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
198
 
199
  /* Select STOP mode entry --------------------------------------------------*/
200
  if(PWR_STOPEntry == PWR_STOPEntry_WFI)
201
  {
202
    /* Request Wait For Interrupt */
203
    __WFI();
204
  }
205
  else
206
  {
207
    /* Request Wait For Event */
208
    __WFE();
209
  }
210
}
211
 
212
/*******************************************************************************
213
* Function Name  : PWR_EnterSTANDBYMode
214
* Description    : Enters STANDBY mode.
215
* Input          : None
216
* Output         : None
217
* Return         : None
218
*******************************************************************************/
219
void PWR_EnterSTANDBYMode(void)
220
{
221
  /* Clear Wake-up flag */
222
  PWR->CR |= CR_CWUF_Set;
223
 
224
  /* Select STANDBY mode */
225
  PWR->CR |= CR_PDDS_Set;
226
 
227
  /* Set SLEEPDEEP bit of Cortex System Control Register */
228
  *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
229
 
230
  /* Request Wait For Interrupt */
231
  __WFI();
232
}
233
 
234
/*******************************************************************************
235
* Function Name  : PWR_GetFlagStatus
236
* Description    : Checks whether the specified PWR flag is set or not.
237
* Input          : - PWR_FLAG: specifies the flag to check.
238
*                    This parameter can be one of the following values:
239
*                       - PWR_FLAG_WU: Wake Up flag
240
*                       - PWR_FLAG_SB: StandBy flag
241
*                       - PWR_FLAG_PVDO: PVD Output
242
* Output         : None
243
* Return         : The new state of PWR_FLAG (SET or RESET).
244
*******************************************************************************/
245
FlagStatus PWR_GetFlagStatus(u32 PWR_FLAG)
246
{
247
  FlagStatus bitstatus = RESET;
248
 
249
  /* Check the parameters */
250
  assert(IS_PWR_GET_FLAG(PWR_FLAG));
251
 
252
  if ((PWR->CSR & PWR_FLAG) != (u32)RESET)
253
  {
254
    bitstatus = SET;
255
  }
256
  else
257
  {
258
    bitstatus = RESET;
259
  }
260
 
261
  /* Return the flag status */
262
  return bitstatus;
263
}
264
 
265
/*******************************************************************************
266
* Function Name  : PWR_ClearFlag
267
* Description    : Clears the PWR's pending flags.
268
* Input          : - PWR_FLAG: specifies the flag to clear.
269
*                    This parameter can be one of the following values:
270
*                       - PWR_FLAG_WU: Wake Up flag
271
*                       - PWR_FLAG_SB: StandBy flag
272
* Output         : None
273
* Return         : None
274
*******************************************************************************/
275
void PWR_ClearFlag(u32 PWR_FLAG)
276
{
277
  /* Check the parameters */
278
  assert(IS_PWR_CLEAR_FLAG(PWR_FLAG));
279
 
280
  PWR->CR |=  PWR_FLAG << 2;
281
}
282
 
283
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.