01. IWDG概述1 s8 Y: S8 i4 l* D. t# U
stm32f4xx_iwdg.h和stm32f4xx_iwdg.c文件中+ Q4 q7 `5 r# r1 s8 u& a
( |9 W' ^ |7 a6 E+ D
02. 相关类型7 k1 v/ m6 o+ O/ z a( s
IWDG_WriteAccess- /** @defgroup IWDG_WriteAccess6 V! U; | R* C9 b: T6 F
- * @{
$ O7 e% D/ E4 K7 l6 v - */1 a. p8 R h7 _5 f$ Q# }9 Z
- #define IWDG_WriteAccess_Enable ((uint16_t)0x5555)
4 q* Z! n# l3 K - #define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
3 b+ A+ m+ s/ g0 p7 w; B. R5 x3 t - #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \, l' X$ o3 i2 z v1 F! E( A
- ((ACCESS) == IWDG_WriteAccess_Disable))
复制代码
" u* g/ q) u8 w5 c, Z- tIWDG_prescaler6 f. A0 B, o& N$ D) m) q
8 S; j C+ w( D( t# h- /** @defgroup IWDG_prescaler
! W7 `# V2 M: t' B - * @{% Z4 L% L6 N# U3 o7 p
- */
2 d; R0 i, y2 M" U0 L; J - #define IWDG_Prescaler_4 ((uint8_t)0x00)3 t& i" h% }7 X9 \ G8 c
- #define IWDG_Prescaler_8 ((uint8_t)0x01)
3 z# ?# h3 z. x+ o9 b - #define IWDG_Prescaler_16 ((uint8_t)0x02)* C( \* X2 w# H3 `* x7 U5 V
- #define IWDG_Prescaler_32 ((uint8_t)0x03)
+ Z. F" j5 z$ B- Y% L- S5 y$ I - #define IWDG_Prescaler_64 ((uint8_t)0x04)1 E, U% H4 a% ~# c8 i; J4 |5 F
- #define IWDG_Prescaler_128 ((uint8_t)0x05); [9 H4 [/ i8 i( r. u6 }2 x6 q
- #define IWDG_Prescaler_256 ((uint8_t)0x06)
. z7 ^3 F6 |8 y( s - #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \5 R- r& J! F" m* W( s% l! _3 U
- ((PRESCALER) == IWDG_Prescaler_8) || \
- L, {, P2 |% X& O: @6 \/ Z$ r - ((PRESCALER) == IWDG_Prescaler_16) || \
8 J. c/ ~* F) o& T. x) c) F - ((PRESCALER) == IWDG_Prescaler_32) || \
" F$ l. X7 S' k - ((PRESCALER) == IWDG_Prescaler_64) || \1 U( ^4 O- ^. u& e+ v
- ((PRESCALER) == IWDG_Prescaler_128)|| \
& S6 V; r& R; [' g: q# v - ((PRESCALER) == IWDG_Prescaler_256))
复制代码 . N7 E6 S; @2 f! }6 N" k. g1 `% B
IWDG_Flag
& F O& T. Y4 \4 b
! \8 o3 G9 K& Y c3 d7 y2 S& T! l- /** @defgroup IWDG_Flag
" p" x/ A5 H- G+ ]/ q( d A+ ~# C - * @{
. ]& s' \, z" |# X; o' `% t - */8 M) H3 H7 B! ~. g( @2 [+ h
- #define IWDG_FLAG_PVU ((uint16_t)0x0001)
0 {- [4 ?. }* u; |' w6 h" M# D - #define IWDG_FLAG_RVU ((uint16_t)0x0002); _2 F; T1 r7 m; F5 i) a2 h
- #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU))
- w" v! e# Y3 K" y0 x. F - #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
复制代码 9 i; M6 Q& `9 i5 x" @) k" L) S: }
03. 相关函数8 v6 D- b9 }, u, |
- /* Exported macro ------------------------------------------------------------*/
; Z* h8 r! a7 j/ O$ h. M3 y8 J8 ~ - /* Exported functions --------------------------------------------------------*/
- o+ C8 U4 `- q7 [- C7 x: x - : a! F& Z' n+ k
- /* Prescaler and Counter configuration functions ******************************/# N- C: m, _ {: }3 X# I: K
- void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);& U" u, O# K' F
- void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);
4 H* }% y. t/ q; F" A7 N5 c - void IWDG_SetReload(uint16_t Reload);+ m$ X; i2 _( m5 c" U1 |
- void IWDG_ReloadCounter(void);
* f2 j; w/ M) I: R* ~; v
: ~6 [5 P; p. E2 e: x6 ]- /* IWDG activation function ***************************************************/
! ~ y# G% g' ^2 G& o - void IWDG_Enable(void);
; a; X# ?0 |5 W: t+ E, t
2 Y) o& c2 Z7 R6 m7 h ~, A- /* Flag management function ***************************************************/, ]' T! x1 ~+ I8 z0 e
- FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
复制代码 : P- \+ S" _8 x' V1 l( |. w/ l4 ~' ]
04. 结构体封装
# O% x& I3 N4 i1 A& U- /** : b) p/ ~5 P% T0 k7 }' U
- * @brief Independent WATCHDOG
2 h: h; o5 ~' `& _6 A+ r% t9 o - */
s/ e, C& h* Y% P$ a) f
; [6 I4 a q! G- typedef struct5 Y# T; }9 d( f* R
- {' l( x i9 r( m# x( ]
- __IO uint32_t KR; /*!< IWDG Key register, Address offset: 0x00 */& r4 \0 v0 h5 a
- __IO uint32_t PR; /*!< IWDG Prescaler register, Address offset: 0x04 */
+ K" K) A, K' w+ r - __IO uint32_t RLR; /*!< IWDG Reload register, Address offset: 0x08 */
- k" c8 G4 n1 s6 ^% R( Q - __IO uint32_t SR; /*!< IWDG Status register, Address offset: 0x0C */; ^0 {1 c9 {. {# U. [
- } IWDG_TypeDef;
复制代码 3 C9 x: \$ \% |+ ^ u
|