STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
pwr.c
Go to the documentation of this file.
1
5#include "pwr.h"
6
11
14#define PWR_READY_TIMEOUT_ITERATIONS (100000U)
15
23static DriverStatus_e pwrWaitCsrFlag(const PwrRegisters_t *pwr, uint32_t flag)
24{
26 uint32_t timeout = PWR_READY_TIMEOUT_ITERATIONS;
27
28 while (((pwr->CSR & flag) == 0U) && (timeout > 0U))
29 {
30 timeout--;
31 }
32
33 /* Re-read the flag: one that sets on the last poll still counts. */
34 if ((pwr->CSR & flag) == 0U)
35 {
37 }
38
39 return status;
40}
41
43{
45
46 if ((vos != PWR_CR_VOS_SCALE1) && (vos != PWR_CR_VOS_SCALE2) && (vos != PWR_CR_VOS_SCALE3))
47 {
49 }
50 else
51 {
52 pwr->CR = (pwr->CR & ~PWR_CR_VOS_Msk) | (vos << PWR_CR_VOS_Pos);
53 }
54
55 return status;
56}
57
62
64{
65 DriverStatus_e status;
66
67 /* Read-modify-writes keep CR.VOS. ODSWEN only after ODRDY confirms ODEN. */
68 pwr->CR |= PWR_CR_ODEN;
69 status = pwrWaitCsrFlag(pwr, PWR_CSR_ODRDY);
70
71 if (status == DRIVER_STATUS_OK)
72 {
73 pwr->CR |= PWR_CR_ODSWEN;
74 status = pwrWaitCsrFlag(pwr, PWR_CSR_ODSWRDY);
75 }
76
77 return status;
78}
79
DriverStatus_e
Outcome of a driver call: a category for control flow, not a diagnosis.
@ DRIVER_STATUS_OK
Succeeded.
@ DRIVER_STATUS_ERR_INVALID_PARAM
A parameter is outside its valid domain.
@ DRIVER_STATUS_ERR_TIMEOUT
A bounded wait for a hardware flag ran out.
DRIVER_MUST_CHECK DriverStatus_e pwrEnableOverdrive(PwrRegisters_t *pwr)
Enable over-drive, to run above the scale's normal maximum.
Definition pwr.c:63
DRIVER_MUST_CHECK DriverStatus_e pwrWaitVoltageScaleReady(const PwrRegisters_t *pwr)
Wait until the regulator reaches the selected scale (CSR.VOSRDY).
Definition pwr.c:58
#define PWR_READY_TIMEOUT_ITERATIONS
Polls allowed for each CSR ready-flag wait (see Poll-count timeouts).
Definition pwr.c:14
DRIVER_MUST_CHECK DriverStatus_e pwrSetVoltageScale(PwrRegisters_t *pwr, uint32_t vos)
Select the regulator voltage scale for the coming PLL frequency.
Definition pwr.c:42
static DriverStatus_e pwrWaitCsrFlag(const PwrRegisters_t *pwr, uint32_t flag)
Poll a CSR flag until it sets or PWR_READY_TIMEOUT_ITERATIONS polls pass.
Definition pwr.c:23
#define PWR_CR_VOS_Pos
Bits 15:14.
Definition pwr_reg.h:53
#define PWR_CR_VOS_Msk
<span class="regaccess">rw</span> Regulator voltage scale; values below.
Definition pwr_reg.h:55
#define PWR_CSR_VOSRDY
<span class="regaccess">ro</span> Voltage scaling is ready.
Definition pwr_reg.h:85
#define PWR_CR_VOS_SCALE2
Scale 2.
Definition pwr_reg.h:68
#define PWR_CR_VOS_SCALE1
Scale 1: highest maximum frequency (reset value).
Definition pwr_reg.h:69
#define PWR_CR_VOS_SCALE3
Scale 3: lowest power, lowest maximum frequency.
Definition pwr_reg.h:67
#define PWR_CSR_ODSWRDY
<span class="regaccess">ro</span> The over-drive switch is complete.
Definition pwr_reg.h:91
#define PWR_CR_ODEN
<span class="regaccess">rw</span> Enable over-drive.
Definition pwr_reg.h:58
#define PWR_CSR_ODRDY
<span class="regaccess">ro</span> Over-drive is ready.
Definition pwr_reg.h:88
#define PWR_CR_ODSWEN
<span class="regaccess">rw</span> Switch the regulator to over-drive.
Definition pwr_reg.h:61
PWR driver: regulator voltage scale and over-drive.
PWR register block.
Definition pwr_reg.h:23
volatile uint32_t CSR
0x04: power control/status
Definition pwr_reg.h:25
volatile uint32_t CR
0x00: power control
Definition pwr_reg.h:24