ald_wdt.c 3.8 KB
Newer Older
W
wangyq2018 已提交
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
/**
 *********************************************************************************
 *
 * @file    ald_wdt.c
 * @brief   WDT module driver.
 *
 * @version V1.0
 * @date    18 Dec 2017
 * @author  AE Team
 * @note
 *
 * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
 *
 *********************************************************************************
 */
#include "ald_conf.h"
#include "ald_wdt.h"


/** @addtogroup ES32FXXX_ALD
 * @{
 */

/** @defgroup WDT WDT
 * @brief WDT module driver
 * @{
 */
#ifdef ALD_WDT


/** @defgroup WWDT_Public_Functions WWDT Public Functions
 * @brief Init and configure WWDT function
 * @{
 */
/**
 * @brief Initializes the WWDT according to the specified parameters.
 * @param load: Specifies the free-running downcounter value.
 * @param win: specifics the no dog windows,
 *        the parameter can be one of the following values:
 *        @arg @ref WWDT_WIN_25 No dog window size: 25%
 *        @arg @ref WWDT_WIN_50 No dog window size: 50%
 *        @arg @ref WWDT_WIN_75 No dog window size: 75%
 *        @arg @ref WWDT_WIN_00 No dog window size: 0%
 * @param interrupt: Enable or disable interrupt.
 * @retval None
 */
W
wangyq2018 已提交
47
void ald_wwdt_init(uint32_t load, wwdt_win_t win, type_func_t interrupt)
W
wangyq2018 已提交
48
{
W
wangyq2018 已提交
49 50 51 52 53 54 55 56 57 58 59 60
	assert_param(IS_WWDT_WIN_TYPE(win));
	assert_param(IS_FUNC_STATE(interrupt));

	WWDT_UNLOCK();
	WRITE_REG(WWDT->LOAD, load);
	MODIFY_REG(WWDT->CON, WWDT_CON_WWDTWIN_MSK, win << WWDT_CON_WWDTWIN_POSS);
	SET_BIT(WWDT->CON, WWDT_CON_CLKS_MSK);
	SET_BIT(WWDT->CON, WWDT_CON_RSTEN_MSK);
	MODIFY_REG(WWDT->CON, WWDT_CON_IE_MSK, interrupt << WWDT_CON_IE_POS);
	WWDT_LOCK();

	return;
W
wangyq2018 已提交
61 62 63 64 65 66
}

/**
 * @brief Start the WWDT
 * @retval None
 */
W
wangyq2018 已提交
67
void ald_wwdt_start(void)
W
wangyq2018 已提交
68
{
W
wangyq2018 已提交
69 70 71
	WWDT_UNLOCK();
	SET_BIT(WWDT->CON, WWDT_CON_EN_MSK);
	WWDT_LOCK();
W
wangyq2018 已提交
72

W
wangyq2018 已提交
73
	return;
W
wangyq2018 已提交
74 75 76 77 78 79
}

/**
 * @brief Get the free-running downcounter value
 * @retval Value
 */
W
wangyq2018 已提交
80
uint32_t ald_wwdt_get_value(void)
W
wangyq2018 已提交
81
{
W
wangyq2018 已提交
82
	return WWDT->VALUE;
W
wangyq2018 已提交
83 84 85 86 87 88
}

/**
 * @brief Get interrupt state
 * @retval Value
 */
W
wangyq2018 已提交
89
it_status_t ald_wwdt_get_flag_status(void)
W
wangyq2018 已提交
90
{
W
wangyq2018 已提交
91 92
	if (READ_BIT(WWDT->RIS, WWDT_RIS_WWDTIF_MSK))
		return SET;
W
wangyq2018 已提交
93

W
wangyq2018 已提交
94
	return RESET;
W
wangyq2018 已提交
95 96 97 98 99 100
}

/**
 * @brief Clear interrupt state
 * @retval None
 */
W
wangyq2018 已提交
101
void ald_wwdt_clear_flag_status(void)
W
wangyq2018 已提交
102
{
W
wangyq2018 已提交
103 104
	WRITE_REG(WWDT->INTCLR, 1);
	return;
W
wangyq2018 已提交
105 106 107 108 109 110
}

/**
 * @brief Refreshes the WWDT
 * @retval None
 */
W
wangyq2018 已提交
111
void ald_wwdt_feed_dog(void)
W
wangyq2018 已提交
112
{
W
wangyq2018 已提交
113 114 115
	WWDT_UNLOCK();
	WRITE_REG(WWDT->INTCLR, 0x1);
	WWDT_LOCK();
W
wangyq2018 已提交
116

W
wangyq2018 已提交
117
	return;
W
wangyq2018 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
}
/**
 * @}
 */

/** @defgroup IWDT_Public_Functions IWDT Public Functions
 * @brief Init and configure IWDT function
 * @{
 */
/**
 * @brief Initializes the IWDG according to the specified parameters.
 * @param load: Specifies the free-running downcounter value.
 * @param interrupt: Enable or disable interrupt.
 * @retval None
 */
W
wangyq2018 已提交
133
void ald_iwdt_init(uint32_t load, type_func_t interrupt)
W
wangyq2018 已提交
134
{
W
wangyq2018 已提交
135
	assert_param(IS_FUNC_STATE(interrupt));
W
wangyq2018 已提交
136

W
wangyq2018 已提交
137 138 139 140 141 142
	IWDT_UNLOCK();
	WRITE_REG(IWDT->LOAD, load);
	SET_BIT(IWDT->CON, IWDT_CON_CLKS_MSK);
	SET_BIT(IWDT->CON, IWDT_CON_RSTEN_MSK);
	MODIFY_REG(IWDT->CON, IWDT_CON_IE_MSK, interrupt << IWDT_CON_IE_POS);
	IWDT_LOCK();
W
wangyq2018 已提交
143

W
wangyq2018 已提交
144
	return;
W
wangyq2018 已提交
145 146 147 148 149 150
}

/**
 * @brief Start the IWDT
 * @retval None
 */
W
wangyq2018 已提交
151
void ald_iwdt_start(void)
W
wangyq2018 已提交
152
{
W
wangyq2018 已提交
153 154 155
	IWDT_UNLOCK();
	SET_BIT(IWDT->CON, IWDT_CON_EN_MSK);
	IWDT_LOCK();
W
wangyq2018 已提交
156

W
wangyq2018 已提交
157
	return;
W
wangyq2018 已提交
158 159 160 161 162 163
}

/**
 * @brief Get the free-running downcounter value
 * @retval Value
 */
W
wangyq2018 已提交
164
uint32_t ald_iwdt_get_value(void)
W
wangyq2018 已提交
165
{
W
wangyq2018 已提交
166
	return IWDT->VALUE;
W
wangyq2018 已提交
167 168 169 170 171 172
}

/**
 * @brief Get interrupt state
 * @retval Value
 */
W
wangyq2018 已提交
173
it_status_t ald_iwdt_get_flag_status(void)
W
wangyq2018 已提交
174
{
W
wangyq2018 已提交
175 176
	if (READ_BIT(IWDT->RIS, IWDT_RIS_WDTIF_MSK))
		return SET;
W
wangyq2018 已提交
177

W
wangyq2018 已提交
178
	return RESET;
W
wangyq2018 已提交
179 180 181 182 183 184
}

/**
 * @brief Clear interrupt state
 * @retval None
 */
W
wangyq2018 已提交
185
void ald_iwdt_clear_flag_status(void)
W
wangyq2018 已提交
186
{
W
wangyq2018 已提交
187 188
	WRITE_REG(IWDT->INTCLR, 1);
	return;
W
wangyq2018 已提交
189 190 191 192 193 194
}

/**
 * @brief Refreshes the WWDT
 * @retval None
 */
W
wangyq2018 已提交
195
void ald_iwdt_feed_dog(void)
W
wangyq2018 已提交
196
{
W
wangyq2018 已提交
197 198 199
	IWDT_UNLOCK();
	WRITE_REG(IWDT->INTCLR, 1);
	IWDT_LOCK();
W
wangyq2018 已提交
200

W
wangyq2018 已提交
201
	return;
W
wangyq2018 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214
}
/**
 * @}
 */

#endif /* ALD_WDT */
/**
 * @}
 */

/**
 * @}
 */