blob: 391193e3827e7cfb15b33072ab6fc934bba9b436 (
plain)
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
|
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file hc32f460_swdt.c
**
** A detailed description is available at
** @link SwdtGroup Special Watchdog Counter description @endlink
**
** - 2018-10-16 CDT First version for Device Driver Library of SWDT.
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32f460_swdt.h"
#include "hc32f460_utility.h"
/**
*******************************************************************************
** \addtogroup SwdtGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*!< Parameter valid check for flag type */
#define IS_VALID_FLAG_TYPE(x) \
( (SwdtFlagCountUnderflow == (x)) || \
(SwdtFlagRefreshError == (x)))
/*!< SWDT_RR register refresh key */
#define SWDT_REFRESH_START_KEY ((uint16_t)0x0123)
#define SWDT_REFRESH_END_KEY_ ((uint16_t)0x3210)
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief SWDT refresh counter
**
** \param [in] None
**
** \retval Ok Process successfully done
**
******************************************************************************/
en_result_t SWDT_RefreshCounter(void)
{
en_result_t enRet = Ok;
M4_SWDT->RR = SWDT_REFRESH_START_KEY;
M4_SWDT->RR = SWDT_REFRESH_END_KEY_;
return enRet;
}
/**
*******************************************************************************
** \brief Get SWDT counter current count value
**
** \param [in] None
**
** \retval uint16_t SWDT counter current count value
**
******************************************************************************/
uint16_t SWDT_GetCountValue(void)
{
return ((uint16_t)M4_SWDT->SR_f.CNT);
}
/**
*******************************************************************************
** \brief Get SWDT flag status
**
** \param [in] enFlag SWDT flag type
** \arg SwdtFlagCountUnderflow Count underflow flag
** \arg SwdtFlagRefreshError Refresh error flag
**
** \retval Set Flag is set
** \retval Reset Flag is reset
**
******************************************************************************/
en_flag_status_t SWDT_GetFlag(en_swdt_flag_type_t enFlag)
{
en_flag_status_t enFlagSta = Reset;
/* Check parameters */
DDL_ASSERT(IS_VALID_FLAG_TYPE(enFlag));
switch (enFlag)
{
case SwdtFlagCountUnderflow:
enFlagSta = (en_flag_status_t)M4_SWDT->SR_f.UDF;
break;
case SwdtFlagRefreshError:
enFlagSta = (en_flag_status_t)M4_SWDT->SR_f.REF;
break;
default:
break;
}
return enFlagSta;
}
/**
*******************************************************************************
** \brief Clear SWDT flag status
**
** \param [in] enFlag SWDT flag type
** \arg SwdtFlagCountUnderflow Count underflow flag
** \arg SwdtFlagRefreshError Refresh error flag
**
** \retval Ok Process successfully done
**
******************************************************************************/
en_result_t SWDT_ClearFlag(en_swdt_flag_type_t enFlag)
{
en_result_t enRet = Ok;
/* Check parameters */
DDL_ASSERT(IS_VALID_FLAG_TYPE(enFlag));
switch (enFlag)
{
case SwdtFlagCountUnderflow:
M4_SWDT->SR_f.UDF = 0u;
break;
case SwdtFlagRefreshError:
M4_SWDT->SR_f.REF = 0u;
break;
default:
break;
}
return enRet;
}
//@} // SwdtGroup
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
|