summaryrefslogtreecommitdiff
path: root/bsp/apm32/libraries/APM32F10x_Library/APM32F10x_StdPeriphDriver/src/apm32f10x_bakpr.c
blob: 627eb3752524f587d7a67a9e1ea6fa61c5412719 (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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*!
 * @file        apm32f10x_bakpr.c
 *
 * @brief       This file provides all the BAKPR firmware functions.
 *
 * @version     V1.0.4
 *
 * @date        2022-12-01
 *
 * @attention
 *
 *  Copyright (C) 2020-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

#include "apm32f10x_bakpr.h"
#include "apm32f10x_rcm.h"

/** @addtogroup APM32F10x_StdPeriphDriver
  @{
*/

/** @addtogroup BAKPR_Driver BAKPR Driver
  * @brief BAKPR driver modules
  @{
*/

/** @defgroup BAKPR_Functions Functions
  @{
*/

/*!
 * @brief      Reset the BAKPR peripheral registers to their default reset values.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_Reset(void)
{
    RCM_EnableBackupReset();
    RCM_DisableBackupReset();
}

/*!
 * @brief      Deinitializes the BAKPR peripheral registers to their default reset values.
 *
 * @param      value: specifies the RTC output source.
 *                    This parameter can be one of the following values:
 *                    @arg BAKPR_TAMPER_PIN_LEVEL_HIGH: Tamper pin active on high level
 *                    @arg BAKPR_TAMPER_PIN_LEVEL_LOW: Tamper pin active on low level
 *
 * @retval     None
 */
void BAKPR_ConfigTamperPinLevel(BAKPR_TAMPER_PIN_LEVEL_T value)
{
    BAKPR->CTRL_B.TPALCFG = value;
}

/*!
 * @brief      Enables the Tamper Pin activation.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_EnableTamperPin(void)
{
    BAKPR->CTRL_B.TPFCFG = ENABLE ;
}

/*!
 * @brief      Disables the Tamper Pin activation.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_DisableTamperPin(void)
{
    BAKPR->CTRL_B.TPFCFG = DISABLE ;
}

/*!
 * @brief      Enables the Tamper Pin Interrupt.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_EnableInterrupt(void)
{
    BAKPR->CSTS_B.TPIEN = ENABLE ;
}

/*!
 * @brief      Disables the Tamper Pin Interrupt.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_DisableInterrupt(void)
{
    BAKPR->CSTS_B.TPIEN = DISABLE ;
}

/*!
 * @brief   Select the RTC output source to output on the Tamper pin.
 *
 * @param   soure: specifies the RTC output source.
 *            This parameter can be one of the following values:
 *            @arg BAKPR_RTC_OUTPUT_SOURCE_NONE             : no RTC output on the Tamper pin.
 *            @arg BAKPR_RTC_OUTPUT_SOURCE_CALIBRATION_CLOCK: output the RTC clock with frequency divided by 64 on the Tamper pin.
 *            @arg BAKPR_RTC_OUTPUT_SOURCE_ALARM            : output the RTC Alarm pulse signal on the Tamper pin.
 *            @arg BAKPR_RTC_OUTPUT_SOURCE_SECOND           : output the RTC Second pulse signal on the Tamper pin.
 *
 * @retval  None
 */
void BAKPR_ConfigRTCOutput(BAKPR_RTC_OUTPUT_SOURCE_T soure)
{
    if (soure == BAKPR_RTC_OUTPUT_SOURCE_NONE)
    {
        BAKPR->CLKCAL = RESET;
    }
    else if (soure == BAKPR_RTC_OUTPUT_SOURCE_CALIBRATION_CLOCK)
    {
        BAKPR->CLKCAL_B.CALCOEN = BIT_SET;
    }
    else if (soure == BAKPR_RTC_OUTPUT_SOURCE_ALARM)
    {
        BAKPR->CLKCAL_B.ASPOEN = BIT_SET;
    }
    else if (soure == BAKPR_RTC_OUTPUT_SOURCE_SECOND)
    {
        BAKPR->CLKCAL_B.ASPOSEL = BIT_SET;
    }
}

/*!
 * @brief      Sets RTC Clock Calibration value.
 *
 * @param      calibrationValue: Specifies the calibration value.
 *                               This parameter must be a number between 0 and 0x7F.
 *
 * @retval     None
 */
void BAKPR_ConfigRTCCalibrationValue(uint8_t calibrationValue)
{
    BAKPR->CLKCAL_B.CALVALUE = calibrationValue;
}

/*!
 * @brief      Set user data to the specified Data Backup Register.
 *
 * @param      bakrData : specifies the Data Backup Register.
 *                        This parameter can be BAKPR_DATAx where x is between 1 and 42.
 *
 * @param      data : data to set
 *                    This parameter can be a 16bit value.
 *
 * @retval     None
 */
void BAKPR_ConfigBackupRegister(BAKPR_DATA_T bakrData, uint16_t data)
{
    __IOM uint32_t tmp = 0;

    tmp = (uint32_t)BAKPR_BASE;
    tmp += bakrData;

    *(__IOM uint32_t*) tmp = data;
}

/*!
 * @brief      Reads user data from the specified Data Backup Register.
 *
 * @param      bakrData : specifies the Data Backup Register.
 *                        This parameter can be BAKPR_DATAx where x is between 1 and 42.
 *
 * @retval     The content of the specified Data Backup Register
 */
uint16_t BAKPR_ReadBackupRegister(BAKPR_DATA_T bakrData)
{
    __IOM uint32_t tmp = 0;

    tmp = (uint32_t)BAKPR_BASE;
    tmp += bakrData;

    return (*(__IOM uint32_t*) tmp);
}

/*!
 * @brief      Read whether the Tamper Pin Event flag is set or not.
 *
 * @param      None
 *
 * @retval     Tamper Pin Event flag state
 */
uint8_t BAKPR_ReadStatusFlag(void)
{
    return BAKPR->CSTS_B.TEFLG;
}

/*!
 * @brief      Clears Tamper Pin Event pending flag.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_ClearStatusFlag(void)
{
    BAKPR->CSTS_B.TECLR = BIT_SET;
}

/*!
 * @brief      Get whether the Tamper Pin Interrupt has occurred or not.
 *
 * @param      None
 *
 * @retval     Tamper Pin Interrupt State
 */
uint8_t BAKPR_ReadIntFlag(void)
{
    return BAKPR->CSTS_B.TIFLG;
}

/*!
 * @brief      Clears Tamper Pin Interrupt pending bit.
 *
 * @param      None
 *
 * @retval     None
 */
void BAKPR_ClearIntFlag(void)
{
    BAKPR->CSTS_B.TICLR = BIT_SET;
}

/**@} end of group BAKPR_Functions*/
/**@} end of group BAKPR_Driver*/
/**@} end of group APM32F10x_StdPeriphDriver */