tao_z
2022-06-01 73bf3cdb517b55f662ed5fa513cdaaf55c1fd0c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
 /**
  ******************************************************************************
  * @file     xl_wdog.c
  * @author   Kirk ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about WDOG firmware program 
  ******************************************************************************
  * @attention
  *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
 
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_wdog.h"
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup WDOG WDOG Module 
  * @brief WDOG Driver Modules Library
  * @{
  */
    
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
    
    
/** @defgroup WDOG_Private_Functions 
  * @{
  */ 
 
/**
  * @brief  ÉèÖÃWDOGÍâÉè¼Ä´æÆ÷Ϊ³õʼ״̬
  * @param  WDOGx: WDTÍâÉè¡£
  * @retval None
  */
void WDOG_DeInit(WDOG_Type *WDOGx)
{
    /* Deinitializes to default reset values */
    //WDOGx->CS2 = 0x00;
    WDOGx->CS1 = 0x00;
}
 
/**
  * @brief ³õʼ»¯WTDģʽ
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @param  WDOG_InitStruct: WDOG_InitTypeDef ÀàÐ͵ÄÖ¸Õ룬°üº¬Ìض¨µÄWDTÍâÉèµÄÉèÖÃÐÅÏ¢
  * @retval None
  */
void WDOG_Init(WDOG_Type *WDOGx, const WDOG_InitTypeDef *WDOG_InitStruct)
{
    uint8_t tmpreg1;
    uint32_t tmpreg;
 
    /*---------------------------- WDT CS2 Configuration ------------------------*/    
    /* Get the WDT CS1 value */
    tmpreg1 = (uint8_t)WDOGx->CS2 ;
 
    /* Clear RPL, RMOD bits */
    //tmpreg1 &= ~(WDOG_CS2_CLK_MASK | WDOG_CS2_PRES_MASK | WDOG_CS2_STOP_MASK | WDOG_CS2_WAIT_MASK | WDOG_CS2_DEBUG_MASK);
    tmpreg1 &= ~0x7Fu;
 
    /* Set the bit in CS1 Register */
    tmpreg1 |= (uint8_t)(WDOG_InitStruct->WDOG_ClkSource | \
                            ((uint32_t)WDOG_InitStruct->WDOG_DEBUGEn << WDOG_CS2_DEBUG_SHIFT) | \
                            ((uint32_t)WDOG_InitStruct->WDOG_PRESEn << WDOG_CS2_PRES_SHIFT)   | \
                            ((uint32_t)WDOG_InitStruct->WDOG_STOPEn << WDOG_CS2_STOP_SHIFT)   | \
                            ((uint32_t)WDOG_InitStruct->WDOG_WAITEn << WDOG_CS2_WAIT_SHIFT));
    
    /* Write to WDT CS1 */
    WDOGx->CS2 = (uint32_t)tmpreg1;
 
/*---------------------------- WDT CS1 Configuration ------------------------*/    
    /* Get the WDT CS1 value */
    tmpreg = WDOGx->CS1;
 
    /* Clear RPL, RMOD bits */
    tmpreg &= ~(WDOG_CS1_RMOD_MASK | WDOG_CS1_RPL_MASK);
 
    /* Set the bit in CS1 Register */
    tmpreg |= (((uint32_t)WDOG_InitStruct->WDOG_PulseLength << WDOG_CS1_RPL_SHIFT) | \
               ((uint32_t)WDOG_InitStruct->WDOG_ResponseMode << WDOG_CS1_RMOD_SHIFT));
 
    /* Write to WDT CS1 */
    WDOGx->CS1 = tmpreg ;
/*------------------------------------ end --------------------------------*/    
}
 
/**
  * @brief  WDOGʹÄÜ
  * @param  WDOGx: Ñ¡ÔñWODGÍâÉè¡£
  * @param  State: WDOGʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
  *            @arg ENABLE: WDOGʹÄÜ
  *            @arg DISABLE: WDOGʧÄÜ
  * @retval None
  */
void WDOG_EnableCmd(WDOG_Type *WDOGx,FunctionalState State)
{
    if(State !=DISABLE)
    {
        /* Enable the WDT */
        WDOGx->CS1 |= WDOG_CS1_EN_MASK;
    }
    else 
    {
        /* Disable the WDT */
        WDOGx->CS1 &= ~WDOG_CS1_EN_MASK;
    }
}
 
/**
  * @brief  ½¨Á¢¿´ÃŹ·Ê±ÖÓ·ÖÆµ
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @param  TimeoutIndex: ³¬Ê±Ê±¼ä
  * @retval None
  */
void WDOG_SetTimeoutPeriod(WDOG_Type *WDOGx, uint8_t TimeoutIndex)
{
    WDOGx->TORR &= ~WDOG_TORR_TOP_MASK;
    WDOGx->TORR |= TimeoutIndex;
}
 
/**
  * @brief  »ñµÃÄÚ²¿¼ÆÊýÆ÷µÄÖµ
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @retval ¼ÆÊýÆ÷µÄµ±Ç°Öµ
  */
uint32_t WDOG_GetCurrentVal(const WDOG_Type *WDOGx)
{
    return WDOGx->CCVR ;
}
 
/**
  * @brief  ÖØÆô WDT
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @retval None
  */
void WDOG_CountRestart(WDOG_Type *WDOGx)
{    
    /* write the value 0x76 to the register */
    WDOGx->CRR = 0x76;        
}
 
/**
  * @brief  »ñµÃWDOGÖжÏ״̬
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @retval ÖжÏ״̬
  */
FlagStatus WDOG_GetIntStatus(const WDOG_Type *WDOGx)
{
    FlagStatus  ret;
    
    /* get the interrupt status */
    if(WDOGx->STAT != 0u)
    {
        ret = SET;
    }
    else
    {
        ret = RESET;
    }
    
    return ret;
}
 
/**
  * @brief  Çå¿ÕWDOGÖжÏ
  * @param  WDOGx: Ñ¡ÔñWDTÍâÉè¡£
  * @retval None
  */
void WDOG_ClrInt(const WDOG_Type *WDOGx)
{
    /* Dummy read to clear */
    (void)(WDOGx->EOI);
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */
/**
  * @}
  */
 
/**
  * @}
  */