STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
wwdg.c
Go to the documentation of this file.
1
5#include "wwdg.h"
6
11
18static DriverStatus_e wwdgValidateCount(uint32_t value)
19{
21
22 if ((value < WWDG_COUNTER_MIN) || (value > WWDG_COUNTER_MAX))
23 {
25 }
26
27 return status;
28}
29
30DriverStatus_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 {
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
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
76{
77 wwdg->CFR |= WWDG_CFR_EWI;
78}
79
81{
82 /* EWIF is the only SR bit, and it clears on a written 0. */
83 wwdg->SR = 0U;
84}
85
90
#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
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_MUST_CHECK DriverStatus_e wwdgRefresh(WwdgRegisters_t *wwdg, uint32_t counter)
Reload the counter with counter (CR = WDGA | counter).
Definition wwdg.c:63
void wwdgFreezeInDebug(DbgmcuRegisters_t *dbgmcu)
Stop the WWDG counter whenever the core is halted by a debugger.
Definition wwdg.c:86
void wwdgEnableEarlyWakeup(WwdgRegisters_t *wwdg)
Raise WWDG_IRQn when the counter reaches 0x40, one count before reset.
Definition wwdg.c:75
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
void wwdgClearEarlyWakeup(WwdgRegisters_t *wwdg)
Clear the early-wakeup flag (SR.EWIF, write 0 to clear).
Definition wwdg.c:80
static DriverStatus_e wwdgValidateCount(uint32_t value)
Accept a counter or window value: 0x40 to 0x7F.
Definition wwdg.c:18
#define WWDG_COUNTER_MAX
Highest counter or window value (7 bits).
Definition wwdg.h:38
#define WWDG_COUNTER_MIN
Lowest counter or window value: 0x3F is the reset point.
Definition wwdg.h:37
#define WWDG_CR_T_Pos
Bits 6:0.
Definition wwdg_reg.h:33
#define WWDG_CFR_WDGTB_Pos
Bits 8:7.
Definition wwdg_reg.h:46
#define WWDG_CFR_EWI
<span class="regaccess">rs</span> Enable the early-wakeup interrupt; only a reset clears it.
Definition wwdg_reg.h:55
#define WWDG_CR_WDGA
<span class="regaccess">rs</span> Activate the watchdog; only a reset clears it.
Definition wwdg_reg.h:38
#define WWDG_CFR_WDGTB_DIV8
WDGTB value: PCLK1 / 4096 / 8.
Definition wwdg_reg.h:52
#define WWDG_CFR_W_Pos
Bits 6:0.
Definition wwdg_reg.h:43
DBGMCU register block.
Definition dbgmcu_reg.h:24
volatile uint32_t APB1_FZ
0x08: APB1 peripheral freeze while the core is halted
Definition dbgmcu_reg.h:27
WWDG register block.
Definition wwdg_reg.h:23
volatile uint32_t CR
0x00: control
Definition wwdg_reg.h:24
volatile uint32_t CFR
0x04: configuration
Definition wwdg_reg.h:25
volatile uint32_t SR
0x08: status
Definition wwdg_reg.h:26
WWDG driver: start, refresh and debug-freeze the window watchdog.