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
|
/**
**************************************************************************
* @file at32f413_bpr.c
* @version v2.0.5
* @date 2022-05-20
* @brief contains all the functions for the bpr firmware library
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "at32f413_conf.h"
/** @addtogroup AT32F413_periph_driver
* @{
*/
/** @defgroup BPR
* @brief BPR driver modules
* @{
*/
#ifdef BPR_MODULE_ENABLED
/** @defgroup BPR_private_functions
* @{
*/
/**
* @brief bpr reset by crm reset register
* @param none
* @retval none
*/
void bpr_reset(void)
{
crm_battery_powered_domain_reset(TRUE);
crm_battery_powered_domain_reset(FALSE);
}
/**
* @brief bpr event flag get, for tamper event flag
* @param flag: specifies the flag to check.
* this parameter can be one of the following values:
* - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
* - BPR_TAMPER_EVENT_FLAG: tamper event flag
* @retval state of tamper event flag
*/
flag_status bpr_flag_get(uint32_t flag)
{
if(flag == BPR_TAMPER_INTERRUPT_FLAG)
{
return (flag_status)(BPR->ctrlsts_bit.tpif);
}
else
{
return (flag_status)(BPR->ctrlsts_bit.tpef);
}
}
/**
* @brief clear bpr tamper flag
* @param flag: specifies the flag to clear.
* this parameter can be one of the following values:
* - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
* - BPR_TAMPER_EVENT_FLAG: tamper event flag
* @retval none
*/
void bpr_flag_clear(uint32_t flag)
{
if(flag == BPR_TAMPER_INTERRUPT_FLAG)
{
BPR->ctrlsts_bit.tpifclr = TRUE;
}
else
{
BPR->ctrlsts_bit.tpefclr = TRUE;
}
}
/**
* @brief enable or disable bpr tamper interrupt
* @param new_state (TRUE or FALSE)
* @retval none
*/
void bpr_interrupt_enable(confirm_state new_state)
{
BPR->ctrlsts_bit.tpien = new_state;
}
/**
* @brief read bpr bpr data
* @param bpr_data
* this parameter can be one of the following values:
* - BPR_DATA1
* - BPR_DATA2
* ...
* - BPR_DATA41
* - BPR_DATA42
* @retval none
*/
uint16_t bpr_data_read(bpr_data_type bpr_data)
{
return (*(__IO uint16_t *)(BPR_BASE + bpr_data));
}
/**
* @brief write bpr data
* @param bpr_data
* this parameter can be one of the following values:
* - BPR_DATA1
* - BPR_DATA2
* ...
* - BPR_DATA41
* - BPR_DATA42
* @param data_value (0x0000~0xFFFF)
* @retval none
*/
void bpr_data_write(bpr_data_type bpr_data, uint16_t data_value)
{
(*(__IO uint32_t *)(BPR_BASE + bpr_data)) = data_value;
}
/**
* @brief select bpr rtc output
* @param output_source
* this parameter can be one of the following values:
* - BPR_RTC_OUTPUT_NONE: output disable.
* - BPR_RTC_OUTPUT_CLOCK_CAL_BEFORE: output clock before calibration.
* - BPR_RTC_OUTPUT_ALARM: output alarm event with pluse mode.
* - BPR_RTC_OUTPUT_SECOND: output second event with pluse mode.
* - BPR_RTC_OUTPUT_CLOCK_CAL_AFTER: output clock after calibration.
* - BPR_RTC_OUTPUT_ALARM_TOGGLE: output alarm event with toggle mode.
* - BPR_RTC_OUTPUT_SECOND_TOGGLE: output second event with toggle mode.
* @retval none
*/
void bpr_rtc_output_select(bpr_rtc_output_type output_source)
{
/* clear cco,asoe,asos,ccos,togen bits */
BPR->rtccal &= (uint32_t)~0x0F80;
/* set output_source value */
BPR->rtccal |= output_source;
}
/**
* @brief set rtc clock calibration value
* @param calibration_value (0x00~0x7f)
* @retval none
*/
void bpr_rtc_clock_calibration_value_set(uint8_t calibration_value)
{
/* set rtc clock calibration value */
BPR->rtccal_bit.calval= calibration_value;
}
/**
* @brief enable or disable bpr tamper pin
* @param new_state (TRUE or FALSE)
* @retval none
*/
void bpr_tamper_pin_enable(confirm_state new_state)
{
BPR->ctrl_bit.tpen = new_state;
}
/**
* @brief set bpr tamper pin active level
* @param active_level
* this parameter can be one of the following values:
* - BPR_TAMPER_PIN_ACTIVE_HIGH: tamper pin input active level is high.
* - BPR_TAMPER_PIN_ACTIVE_LOW: tamper pin input active level is low.
* @retval none
*/
void bpr_tamper_pin_active_level_set(bpr_tamper_pin_active_level_type active_level)
{
BPR->ctrl_bit.tpp = active_level;
}
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/
|