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