1 /*
2 * Copyright 2021 MindMotion Microelectronics Co., Ltd.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "hal_iwdg.h"
9
IWDG_Init(IWDG_Type * IWDGx,IWDG_Init_Type * init)10 void IWDG_Init(IWDG_Type * IWDGx, IWDG_Init_Type * init)
11 {
12 if ( NULL != init )
13 {
14 IWDGx->KR = IWDG_KEY_UNLOCK;
15 IWDGx->PR = init->Prescaler;
16
17 IWDGx->KR = IWDG_KEY_UNLOCK;
18 IWDGx->RLR = init->Relaod;
19
20 IWDG_DoReload(IWDGx);
21 }
22 }
23
IWDG_Start(IWDG_Type * IWDGx)24 void IWDG_Start(IWDG_Type * IWDGx)
25 {
26 IWDGx->KR = IWDG_KEY_ENABLE;
27 }
28
IWDG_GetStatus(IWDG_Type * IWDGx)29 uint32_t IWDG_GetStatus(IWDG_Type * IWDGx)
30 {
31 return IWDGx->SR;
32 }
33
IWDG_DoReload(IWDG_Type * IWDGx)34 void IWDG_DoReload(IWDG_Type * IWDGx)
35 {
36 IWDGx->KR = IWDG_KEY_RELOAD;
37 }
38
IWDG_EnableInterrupts(IWDG_Type * IWDGx,uint32_t interrupts,bool enable)39 void IWDG_EnableInterrupts(IWDG_Type * IWDGx, uint32_t interrupts, bool enable)
40 {
41 if( (true == enable ) && (IWDG_INT_ALMOST_TIMEOUT == interrupts) )
42 {
43 IWDGx->CR |= IWDG_CR_IRQSEL_MASK;
44 }
45 else
46 {
47 /* if IWDG_EnableInterrupts interrupt was enabled, only MCU reset can close it. */
48 }
49 }
50
IWDG_ClearStatus(IWDG_Type * IWDGx,uint32_t status)51 void IWDG_ClearStatus(IWDG_Type * IWDGx, uint32_t status)
52 {
53 if( 0u != ( status & IWDG_CR_IRQCLR_MASK ) )
54 {
55 IWDGx->CR |= IWDG_CR_IRQCLR_MASK;
56 }
57 }
58
59 /* EOF. */
60