1 /**
2   *********************************************************************************
3   *
4   * @file    ald_rmu.c
5   * @brief   RMU module driver.
6   *
7   * @version V1.0
8   * @date    04 Dec 2019
9   * @author  AE Team
10   * @note
11   *          Change Logs:
12   *          Date            Author          Notes
13   *          04 Dec 2019     AE Team         The first version
14   *
15   * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
16   *
17   * SPDX-License-Identifier: Apache-2.0
18   *
19   * Licensed under the Apache License, Version 2.0 (the License); you may
20   * not use this file except in compliance with the License.
21   * You may obtain a copy of the License at
22   *
23   * www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing, software
26   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
27   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   * See the License for the specific language governing permissions and
29   * limitations under the License.
30   **********************************************************************************
31   */
32 
33 #include "ald_conf.h"
34 
35 /** @addtogroup ES32FXXX_ALD
36   * @{
37   */
38 
39 /** @defgroup RMU RMU
40   * @brief RMU module driver
41   * @{
42   */
43 #ifdef ALD_RMU
44 
45 /** @defgroup RMU_Public_Functions RMU Public Functions
46   * @{
47   */
48 
49 /**
50   * @brief  Configure BOR parameters.
51   * @param  flt: filter time.
52   * @param  vol: The voltage.
53   * @param  state: The new status: ENABLE/DISABLE.
54   * @retval None
55   */
ald_rmu_bor_config(rmu_bor_filter_t flt,rmu_bor_vol_t vol,type_func_t state)56 void ald_rmu_bor_config(rmu_bor_filter_t flt, rmu_bor_vol_t vol, type_func_t state)
57 {
58 	assert_param(IS_FUNC_STATE(state));
59 
60 	SYSCFG_UNLOCK();
61 
62 	if (state) {
63 		assert_param(IS_RMU_BORFLT(flt));
64 		assert_param(IS_RMU_BORVOL(vol));
65 
66 		MODIFY_REG(RMU->CR, RMU_CR_BORFLT_MSK, flt << RMU_CR_BORFLT_POSS);
67 		MODIFY_REG(RMU->CR, RMU_CR_BORVS_MSK, vol << RMU_CR_BORVS_POSS);
68 		SET_BIT(RMU->CR, RMU_CR_BOREN_MSK);
69 	}
70 	else {
71 		CLEAR_BIT(RMU->CR, RMU_CR_BOREN_MSK);
72 	}
73 
74 	SYSCFG_LOCK();
75 	return;
76 }
77 
78 /**
79   * @brief  Get specified reset status
80   * @param  state: Speicifies the type of the reset,
81   * @retval The status.
82   */
ald_rmu_get_reset_status(rmu_state_t state)83 uint32_t ald_rmu_get_reset_status(rmu_state_t state)
84 {
85 	assert_param(IS_RMU_STATE(state));
86 
87 	if (state == RMU_RST_ALL)
88 		return RMU->RSTSR;
89 
90 	if (READ_BIT(RMU->RSTSR, state))
91 		return SET;
92 
93 	return RESET;
94 }
95 
96 /**
97   * @brief  Clear the specified reset status
98   * @param  state: Specifies the type of the reset,
99   * @retval None
100   */
ald_rmu_clear_reset_status(rmu_state_t state)101 void ald_rmu_clear_reset_status(rmu_state_t state)
102 {
103 	assert_param(IS_RMU_STATE_CLEAR(state));
104 
105 	SYSCFG_UNLOCK();
106 	WRITE_REG(RMU->CRSTSR, state);
107 	SYSCFG_LOCK();
108 
109 	return;
110 }
111 /**
112   * @brief  Reset peripheral device
113   * @param  perh: The peripheral device,
114   * @retval None
115   */
ald_rmu_reset_periperal(rmu_peripheral_t perh)116 void ald_rmu_reset_periperal(rmu_peripheral_t perh)
117 {
118 	uint32_t idx, pos;
119 
120 	assert_param(IS_RMU_PERH(perh));
121 
122 	idx = ((uint32_t)perh >> 27) & 0x7;
123 	pos = perh & ~(0x7 << 27);
124 	SYSCFG_UNLOCK();
125 
126 	switch (idx) {
127 	case 0:
128 		WRITE_REG(RMU->AHB1RSTR, pos);
129 		break;
130 
131 	case 1:
132 		WRITE_REG(RMU->AHB2RSTR, pos);
133 		break;
134 
135 	case 2:
136 		WRITE_REG(RMU->APB1RSTR, pos);
137 		break;
138 
139 	case 4:
140 		WRITE_REG(RMU->APB2RSTR, pos);
141 		break;
142 
143 	default:
144 		break;
145 	}
146 
147 	SYSCFG_LOCK();
148 	return;
149 }
150 
151 /**
152   * @}
153   */
154 #endif /* ALD_RMU */
155 /**
156   * @}
157   */
158 
159 /**
160   * @}
161   */
162