STM32 RTOS
0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Toggle main menu visibility
Loading...
Searching...
No Matches
wwdg.c
Go to the documentation of this file.
1
5
#include "
wwdg.h
"
6
11
18
static
DriverStatus_e
wwdgValidateCount
(uint32_t value)
19
{
20
DriverStatus_e
status =
DRIVER_STATUS_OK
;
21
22
if
((value <
WWDG_COUNTER_MIN
) || (value >
WWDG_COUNTER_MAX
))
23
{
24
status =
DRIVER_STATUS_ERR_INVALID_PARAM
;
25
}
26
27
return
status;
28
}
29
30
DriverStatus_e
wwdgStart
(
WwdgRegisters_t
*wwdg, uint32_t prescaler, uint32_t window,
31
uint32_t counter)
32
{
33
DriverStatus_e
status =
wwdgValidateCount
(window);
34
35
if
(status ==
DRIVER_STATUS_OK
)
36
{
37
status =
wwdgValidateCount
(counter);
38
}
39
40
if
((status ==
DRIVER_STATUS_OK
) && (prescaler >
WWDG_CFR_WDGTB_DIV8
))
41
{
42
status =
DRIVER_STATUS_ERR_INVALID_PARAM
;
43
}
44
45
if
(status ==
DRIVER_STATUS_OK
)
46
{
47
wwdg->
CFR
= (wwdg->
CFR
&
WWDG_CFR_EWI
) | (window <<
WWDG_CFR_W_Pos
)
48
| (prescaler <<
WWDG_CFR_WDGTB_Pos
);
49
wwdg->
CR
=
WWDG_CR_WDGA
| (counter <<
WWDG_CR_T_Pos
);
50
51
/* The counter free-runs from the moment the clock is enabled, even
52
* with WDGA clear, and sets EWIF each time it passes 0x40 whether or
53
* not EWI is enabled. That stale flag would raise the early wakeup at
54
* once, and a refresh from it would come above the window. Cleared
55
* after the start, the counter is back at @p counter and cannot set
56
* it again for a full period. */
57
wwdg->
SR
= 0U;
58
}
59
60
return
status;
61
}
62
63
DriverStatus_e
wwdgRefresh
(
WwdgRegisters_t
*wwdg, uint32_t counter)
64
{
65
DriverStatus_e
status =
wwdgValidateCount
(counter);
66
67
if
(status ==
DRIVER_STATUS_OK
)
68
{
69
wwdg->
CR
=
WWDG_CR_WDGA
| (counter <<
WWDG_CR_T_Pos
);
70
}
71
72
return
status;
73
}
74
75
void
wwdgEnableEarlyWakeup
(
WwdgRegisters_t
*wwdg)
76
{
77
wwdg->
CFR
|=
WWDG_CFR_EWI
;
78
}
79
80
void
wwdgClearEarlyWakeup
(
WwdgRegisters_t
*wwdg)
81
{
82
/* EWIF is the only SR bit, and it clears on a written 0. */
83
wwdg->
SR
= 0U;
84
}
85
86
void
wwdgFreezeInDebug
(
DbgmcuRegisters_t
*dbgmcu)
87
{
88
dbgmcu->
APB1_FZ
|=
DBGMCU_APB1_FZ_DBG_WWDG_STOP
;
89
}
90
DBGMCU_APB1_FZ_DBG_WWDG_STOP
#define DBGMCU_APB1_FZ_DBG_WWDG_STOP
<span class="regaccess">rw</span> Stop the WWDG counter while the core is halted.
Definition
dbgmcu_reg.h:37
DriverStatus_e
DriverStatus_e
Outcome of a driver call: a category for control flow, not a diagnosis.
Definition
driver_status.h:32
DRIVER_STATUS_OK
@ DRIVER_STATUS_OK
Succeeded.
Definition
driver_status.h:36
DRIVER_STATUS_ERR_INVALID_PARAM
@ DRIVER_STATUS_ERR_INVALID_PARAM
A parameter is outside its valid domain.
Definition
driver_status.h:38
wwdgRefresh
DRIVER_MUST_CHECK DriverStatus_e wwdgRefresh(WwdgRegisters_t *wwdg, uint32_t counter)
Reload the counter with counter (CR = WDGA | counter).
Definition
wwdg.c:63
wwdgFreezeInDebug
void wwdgFreezeInDebug(DbgmcuRegisters_t *dbgmcu)
Stop the WWDG counter whenever the core is halted by a debugger.
Definition
wwdg.c:86
wwdgEnableEarlyWakeup
void wwdgEnableEarlyWakeup(WwdgRegisters_t *wwdg)
Raise WWDG_IRQn when the counter reaches 0x40, one count before reset.
Definition
wwdg.c:75
wwdgStart
DRIVER_MUST_CHECK DriverStatus_e wwdgStart(WwdgRegisters_t *wwdg, uint32_t prescaler, uint32_t window, uint32_t counter)
Set the window and timer base, then start the watchdog counting from counter.
Definition
wwdg.c:30
wwdgClearEarlyWakeup
void wwdgClearEarlyWakeup(WwdgRegisters_t *wwdg)
Clear the early-wakeup flag (SR.EWIF, write 0 to clear).
Definition
wwdg.c:80
wwdgValidateCount
static DriverStatus_e wwdgValidateCount(uint32_t value)
Accept a counter or window value: 0x40 to 0x7F.
Definition
wwdg.c:18
WWDG_COUNTER_MAX
#define WWDG_COUNTER_MAX
Highest counter or window value (7 bits).
Definition
wwdg.h:38
WWDG_COUNTER_MIN
#define WWDG_COUNTER_MIN
Lowest counter or window value: 0x3F is the reset point.
Definition
wwdg.h:37
WWDG_CR_T_Pos
#define WWDG_CR_T_Pos
Bits 6:0.
Definition
wwdg_reg.h:33
WWDG_CFR_WDGTB_Pos
#define WWDG_CFR_WDGTB_Pos
Bits 8:7.
Definition
wwdg_reg.h:46
WWDG_CFR_EWI
#define WWDG_CFR_EWI
<span class="regaccess">rs</span> Enable the early-wakeup interrupt; only a reset clears it.
Definition
wwdg_reg.h:55
WWDG_CR_WDGA
#define WWDG_CR_WDGA
<span class="regaccess">rs</span> Activate the watchdog; only a reset clears it.
Definition
wwdg_reg.h:38
WWDG_CFR_WDGTB_DIV8
#define WWDG_CFR_WDGTB_DIV8
WDGTB value: PCLK1 / 4096 / 8.
Definition
wwdg_reg.h:52
WWDG_CFR_W_Pos
#define WWDG_CFR_W_Pos
Bits 6:0.
Definition
wwdg_reg.h:43
DbgmcuRegisters_t
DBGMCU register block.
Definition
dbgmcu_reg.h:24
DbgmcuRegisters_t::APB1_FZ
volatile uint32_t APB1_FZ
0x08: APB1 peripheral freeze while the core is halted
Definition
dbgmcu_reg.h:27
WwdgRegisters_t
WWDG register block.
Definition
wwdg_reg.h:23
WwdgRegisters_t::CR
volatile uint32_t CR
0x00: control
Definition
wwdg_reg.h:24
WwdgRegisters_t::CFR
volatile uint32_t CFR
0x04: configuration
Definition
wwdg_reg.h:25
WwdgRegisters_t::SR
volatile uint32_t SR
0x08: status
Definition
wwdg_reg.h:26
wwdg.h
WWDG driver: start, refresh and debug-freeze the window watchdog.
drivers
src
wwdg.c
Generated by
1.18.0