1 /**************************************************************************//**
2 * @file tamper.c
3 * @version V3.00
4 * @brief TAMPER driver source file
5 *
6 * @copyright SPDX-License-Identifier: Apache-2.0
7 * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #include "NuMicro.h"
10
11 /** @addtogroup Standard_Driver Standard Driver
12 @{
13 */
14
15 /** @addtogroup TAMPER_Driver Tamper Driver
16 @{
17 */
18
19 /** @addtogroup TAMPER_EXPORTED_FUNCTIONS Tamper Exported Functions
20 @{
21 */
22
23 /**
24 * @brief Enable Tamper Interrupt
25 *
26 * @param[in] u32IntFlagMask Specify the interrupt source. It consists of:
27 * - \ref TAMPER_INTEN_TAMP0IEN_Msk
28 * - \ref TAMPER_INTEN_TAMP1IEN_Msk
29 * - \ref TAMPER_INTEN_TAMP2IEN_Msk
30 * - \ref TAMPER_INTEN_TAMP3IEN_Msk
31 * - \ref TAMPER_INTEN_TAMP4IEN_Msk
32 * - \ref TAMPER_INTEN_TAMP5IEN_Msk
33 * - \ref TAMPER_INTEN_CLKFIEN_Msk
34 * - \ref TAMPER_INTEN_CLKSTOPIEN_Msk
35 * - \ref TAMPER_INTEN_OVPIEN_Msk
36 * - \ref TAMPER_INTEN_VGPIEN_Msk
37 * - \ref TAMPER_INTEN_VGNIEN_Msk
38 * - \ref TAMPER_INTEN_ACTSIEN_Msk
39 * - \ref TAMPER_INTEN_RTCLVRIEN_Msk
40 * - \ref TAMPER_INTEN_RTCIOIEN_Msk
41 * - \ref TAMPER_INTEN_RTCLKIEN_Msk
42 * - \ref TAMPER_INTEN_BODIEN_Msk
43 *
44 * @return None
45 *
46 * @details This API is used to enable the specify tamper interrupt function.
47 */
TAMPER_EnableInt(uint32_t u32IntFlagMask)48 void TAMPER_EnableInt(uint32_t u32IntFlagMask)
49 {
50 TAMPER->INTEN |= u32IntFlagMask;
51 }
52
53 /**
54 * @brief Disable Tamper Interrupt
55 *
56 * @param[in] u32IntFlagMask Specify the interrupt source. It consists of:
57 * - \ref TAMPER_INTEN_TAMP0IEN_Msk
58 * - \ref TAMPER_INTEN_TAMP1IEN_Msk
59 * - \ref TAMPER_INTEN_TAMP2IEN_Msk
60 * - \ref TAMPER_INTEN_TAMP3IEN_Msk
61 * - \ref TAMPER_INTEN_TAMP4IEN_Msk
62 * - \ref TAMPER_INTEN_TAMP5IEN_Msk
63 * - \ref TAMPER_INTEN_CLKFIEN_Msk
64 * - \ref TAMPER_INTEN_CLKSTOPIEN_Msk
65 * - \ref TAMPER_INTEN_OVPIEN_Msk
66 * - \ref TAMPER_INTEN_VGPIEN_Msk
67 * - \ref TAMPER_INTEN_VGNIEN_Msk
68 * - \ref TAMPER_INTEN_ACTSIEN_Msk
69 * - \ref TAMPER_INTEN_RTCLVRIEN_Msk
70 * - \ref TAMPER_INTEN_RTCIOIEN_Msk
71 * - \ref TAMPER_INTEN_RTCLKIEN_Msk
72 * - \ref TAMPER_INTEN_BODIEN_Msk
73 *
74 * @return None
75 *
76 * @details This API is used to disable the specify tamper interrupt function.
77 */
TAMPER_DisableInt(uint32_t u32IntFlagMask)78 void TAMPER_DisableInt(uint32_t u32IntFlagMask)
79 {
80 TAMPER->INTEN &= ~u32IntFlagMask;
81 }
82
83 /**
84 * @brief Static Tamper Detect
85 *
86 * @param[in] u32TamperSelect Tamper pin select. Possible options are
87 * - \ref TAMPER_TAMPER0_SELECT
88 * - \ref TAMPER_TAMPER1_SELECT
89 * - \ref TAMPER_TAMPER2_SELECT
90 * - \ref TAMPER_TAMPER3_SELECT
91 * - \ref TAMPER_TAMPER4_SELECT
92 * - \ref TAMPER_TAMPER5_SELECT
93 *
94 * @param[in] u32DetecLevel Tamper pin detection level select. Possible options are
95 * - \ref TAMPER_TAMPER_HIGH_LEVEL_DETECT
96 * - \ref TAMPER_TAMPER_LOW_LEVEL_DETECT
97 *
98 * @param[in] u32DebounceEn Tamper pin de-bounce enable
99 * - \ref TAMPER_TAMPER_DEBOUNCE_ENABLE
100 * - \ref TAMPER_TAMPER_DEBOUNCE_DISABLE
101 *
102 * @return None
103 *
104 * @details This API is used to enable the tamper pin detect function with specify trigger condition.
105 * User needs to disable dynamic tamper function before use this API.
106 */
TAMPER_StaticTamperEnable(uint32_t u32TamperSelect,uint32_t u32DetecLevel,uint32_t u32DebounceEn)107 void TAMPER_StaticTamperEnable(uint32_t u32TamperSelect, uint32_t u32DetecLevel, uint32_t u32DebounceEn)
108 {
109 uint32_t i;
110 uint32_t u32Reg;
111 uint32_t u32TmpReg;
112
113 u32Reg = TAMPER->TIOCTL;
114
115 u32TmpReg = (TAMPER_TIOCTL_TAMP0EN_Msk | (u32DetecLevel << TAMPER_TIOCTL_TAMP0LV_Pos) |
116 (u32DebounceEn << TAMPER_TIOCTL_TAMP0DBEN_Pos));
117
118 for(i = 0UL; i < (uint32_t)TAMPER_MAX_TAMPER_PIN_NUM; i++)
119 {
120 if(u32TamperSelect & (0x1UL << i))
121 {
122 u32Reg &= ~((TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP0LV_Msk | TAMPER_TIOCTL_TAMP0DBEN_Msk) << (i * 4UL));
123 u32Reg |= (u32TmpReg << (i * 4UL));
124 }
125 }
126
127 TAMPER->TIOCTL = u32Reg;
128 }
129
130 /**
131 * @brief Static Tamper Disable
132 *
133 * @param[in] u32TamperSelect Tamper pin select. Possible options are
134 * - \ref TAMPER_TAMPER0_SELECT
135 * - \ref TAMPER_TAMPER1_SELECT
136 * - \ref TAMPER_TAMPER2_SELECT
137 * - \ref TAMPER_TAMPER3_SELECT
138 * - \ref TAMPER_TAMPER4_SELECT
139 * - \ref TAMPER_TAMPER5_SELECT
140 *
141 * @return None
142 *
143 * @details This API is used to disable the static tamper pin detect.
144 */
TAMPER_StaticTamperDisable(uint32_t u32TamperSelect)145 void TAMPER_StaticTamperDisable(uint32_t u32TamperSelect)
146 {
147 uint32_t i;
148 uint32_t u32Reg;
149 uint32_t u32TmpReg;
150
151 u32Reg = TAMPER->TIOCTL;
152
153 u32TmpReg = TAMPER_TIOCTL_TAMP0EN_Msk;
154
155 for(i = 0UL; i < (uint32_t)TAMPER_MAX_TAMPER_PIN_NUM; i++)
156 {
157 if(u32TamperSelect & (0x1UL << i))
158 {
159 u32Reg &= ~(u32TmpReg << (i * 4UL));
160 }
161 }
162
163 TAMPER->TIOCTL = u32Reg;
164 }
165
166 /**
167 * @brief Dynamic Tamper Detect
168 *
169 * @param[in] u32PairSel Tamper pin detection enable. Possible options are
170 * - \ref TAMPER_PAIR0_SELECT
171 * - \ref TAMPER_PAIR1_SELECT
172 * - \ref TAMPER_PAIR2_SELECT
173 *
174 * @param[in] u32DebounceEn Tamper pin de-bounce enable
175 * - \ref TAMPER_TAMPER_DEBOUNCE_ENABLE
176 * - \ref TAMPER_TAMPER_DEBOUNCE_DISABLE
177 *
178 * @param[in] u32Pair1Source Dynamic pair 1 input source select
179 * 0: Pair 1 source select tamper 2
180 * 1: Pair 1 source select tamper 0
181 *
182 * @param[in] u32Pair2Source Dynamic pair 2 input source select
183 * 0: Pair 2 source select tamper 4
184 * 1: Pair 2 source select tamper 0
185 *
186 * @return None
187 *
188 * @details This API is used to enable the dynamic tamper.
189 */
TAMPER_DynamicTamperEnable(uint32_t u32PairSel,uint32_t u32DebounceEn,uint32_t u32Pair1Source,uint32_t u32Pair2Source)190 void TAMPER_DynamicTamperEnable(uint32_t u32PairSel, uint32_t u32DebounceEn, uint32_t u32Pair1Source, uint32_t u32Pair2Source)
191 {
192 uint32_t i;
193 uint32_t u32Reg;
194 uint32_t u32TmpReg;
195 uint32_t u32Tamper2Debounce, u32Tamper4Debounce;
196
197 u32Reg = TAMPER->TIOCTL;
198 u32Reg &= ~(TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP1EN_Msk | TAMPER_TIOCTL_TAMP2EN_Msk |
199 TAMPER_TIOCTL_TAMP3EN_Msk | TAMPER_TIOCTL_TAMP4EN_Msk | TAMPER_TIOCTL_TAMP5EN_Msk);
200
201 u32Tamper2Debounce = u32Reg & TAMPER_TIOCTL_TAMP2DBEN_Msk;
202 u32Tamper4Debounce = u32Reg & TAMPER_TIOCTL_TAMP4DBEN_Msk;
203
204 u32Reg &= ~(TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP1EN_Msk | TAMPER_TIOCTL_TAMP2EN_Msk |
205 TAMPER_TIOCTL_TAMP3EN_Msk | TAMPER_TIOCTL_TAMP4EN_Msk | TAMPER_TIOCTL_TAMP5EN_Msk);
206 u32Reg &= ~(TAMPER_TIOCTL_DYN1ISS_Msk | TAMPER_TIOCTL_DYN2ISS_Msk);
207 u32Reg |= ((u32Pair1Source & 0x1UL) << TAMPER_TIOCTL_DYN1ISS_Pos) | ((u32Pair2Source & 0x1UL) << TAMPER_TIOCTL_DYN2ISS_Pos);
208
209 if(u32DebounceEn)
210 {
211 u32TmpReg = (TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP1EN_Msk |
212 TAMPER_TIOCTL_TAMP0DBEN_Msk | TAMPER_TIOCTL_TAMP1DBEN_Msk | TAMPER_TIOCTL_DYNPR0EN_Msk);
213 }
214 else
215 {
216 u32TmpReg = (TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP1EN_Msk | TAMPER_TIOCTL_DYNPR0EN_Msk);
217 }
218
219 for(i = 0UL; i < (uint32_t)TAMPER_MAX_PAIR_NUM; i++)
220 {
221 if(u32PairSel & (0x1UL << i))
222 {
223 u32Reg &= ~((TAMPER_TIOCTL_TAMP0DBEN_Msk | TAMPER_TIOCTL_TAMP1DBEN_Msk) << (i * 8UL));
224 u32Reg |= (u32TmpReg << (i * 8UL));
225 }
226 }
227
228 if((u32Pair1Source) && (u32PairSel & (uint32_t)TAMPER_PAIR1_SELECT))
229 {
230 u32Reg &= ~TAMPER_TIOCTL_TAMP2EN_Msk;
231 u32Reg |= u32Tamper2Debounce;
232 }
233
234 if((u32Pair2Source) && (u32PairSel & (uint32_t)TAMPER_PAIR2_SELECT))
235 {
236 u32Reg &= ~TAMPER_TIOCTL_TAMP4EN_Msk;
237 u32Reg |= u32Tamper4Debounce;
238 }
239
240 TAMPER->TIOCTL = u32Reg;
241 }
242
243 /**
244 * @brief Dynamic Tamper Disable
245 *
246 * @param[in] u32PairSel Tamper pin detection disable. Possible options are
247 * - \ref TAMPER_PAIR0_SELECT
248 * - \ref TAMPER_PAIR1_SELECT
249 * - \ref TAMPER_PAIR2_SELECT
250 *
251 * @return None
252 *
253 * @details This API is used to disable the dynamic tamper.
254 */
TAMPER_DynamicTamperDisable(uint32_t u32PairSel)255 void TAMPER_DynamicTamperDisable(uint32_t u32PairSel)
256 {
257 uint32_t i;
258 uint32_t u32Reg;
259 uint32_t u32TmpReg;
260 uint32_t u32Tamper2En = 0UL, u32Tamper4En = 0UL;
261
262 u32Reg = TAMPER->TIOCTL;
263
264 if((u32Reg & (uint32_t)TAMPER_TIOCTL_DYN1ISS_Msk) && (u32PairSel & (uint32_t)TAMPER_PAIR1_SELECT))
265 {
266 u32Tamper2En = u32Reg & TAMPER_TIOCTL_TAMP2EN_Msk;
267 }
268
269 if((u32Reg & (uint32_t)TAMPER_TIOCTL_DYN2ISS_Msk) && (u32PairSel & (uint32_t)TAMPER_PAIR2_SELECT))
270 {
271 u32Tamper4En = u32Reg & TAMPER_TIOCTL_TAMP4EN_Msk;
272 }
273
274 u32TmpReg = (TAMPER_TIOCTL_TAMP0EN_Msk | TAMPER_TIOCTL_TAMP1EN_Msk | TAMPER_TIOCTL_DYNPR0EN_Msk);
275
276 for(i = 0UL; i < (uint32_t)TAMPER_MAX_PAIR_NUM; i++)
277 {
278 if(u32PairSel & (0x1UL << i))
279 {
280 u32Reg &= ~(u32TmpReg << ((i * 8UL)));
281 }
282 }
283
284 u32Reg |= (u32Tamper2En | u32Tamper4En);
285
286 TAMPER->TIOCTL = u32Reg;
287 }
288
289 /**
290 * @brief Config Dynamic Tamper
291 *
292 * @param[in] u32ChangeRate The dynamic tamper output change rate
293 * - \ref TAMPER_2POW6_CLK
294 * - \ref TAMPER_2POW7_CLK
295 * - \ref TAMPER_2POW8_CLK
296 * - \ref TAMPER_2POW9_CLK
297 * - \ref TAMPER_2POW10_CLK
298 * - \ref TAMPER_2POW11_CLK
299 * - \ref TAMPER_2POW12_CLK
300 * - \ref TAMPER_2POW13_CLK
301 *
302 * @param[in] u32SeedReload Reload new seed or not
303 * 0: not reload new seed
304 * 1: reload new seed
305 *
306 * @param[in] u32RefPattern Reference pattern
307 * - \ref TAMPER_REF_RANDOM_PATTERN
308 * - \ref TAMPER_REF_SEED
309 *
310 * @param[in] u32Seed Seed Value (0x0 ~ 0xFFFFFFFF)
311 *
312 * @return None
313 *
314 * @details This API is used to config dynamic tamper setting.
315 */
TAMPER_DynamicTamperConfig(uint32_t u32ChangeRate,uint32_t u32SeedReload,uint32_t u32RefPattern,uint32_t u32Seed)316 void TAMPER_DynamicTamperConfig(uint32_t u32ChangeRate, uint32_t u32SeedReload, uint32_t u32RefPattern, uint32_t u32Seed)
317 {
318 uint32_t u32Reg;
319
320 u32Reg = TAMPER->TIOCTL;
321
322 u32Reg &= ~(TAMPER_TIOCTL_DYNSRC_Msk | TAMPER_TIOCTL_SEEDRLD_Msk | TAMPER_TIOCTL_DYNRATE_Msk);
323
324 u32Reg |= (u32ChangeRate) | ((u32SeedReload & 0x1UL) << TAMPER_TIOCTL_SEEDRLD_Pos) |
325 ((u32RefPattern & 0x1UL) << TAMPER_TIOCTL_DYNSRC_Pos);
326
327 TAMPER->SEED = u32Seed; /* Need to set seed value before reloaded seed */
328 TAMPER->TIOCTL = u32Reg;
329 }
330
331 /**
332 * @brief Active Shield Dynamic Tamper Detect
333 *
334 * @param[in] u32PairSel1/2 Active shield 1/2 tamper pin detection enable. Possible options are
335 * - \ref TAMPER_PAIR0_SELECT
336 * - \ref TAMPER_PAIR1_SELECT
337 * - \ref TAMPER_PAIR2_SELECT
338 *
339 * @param[in] u32Pair1Source1/2 Active shield 1/2 dynamic pair 1 input source select
340 * 0: Pair 1 source select tamper 2
341 * 1: Pair 1 source select tamper 0
342 *
343 * @return None
344 *
345 * @details This API is used to enable the active shield dynamic tamper.
346 */
TAMPER_ActiveShieldDynamicTamperEnable(uint32_t u32PairSel1,uint32_t u32Pair1Source1,uint32_t u32PairSel2,uint32_t u32Pair1Source2)347 void TAMPER_ActiveShieldDynamicTamperEnable(uint32_t u32PairSel1, uint32_t u32Pair1Source1, uint32_t u32PairSel2, uint32_t u32Pair1Source2)
348 {
349 uint32_t i;
350 uint32_t u32Reg1, u32Reg2;
351 uint32_t u32TmpReg1, u32TmpReg2;
352
353 u32Reg1 = TAMPER->ACTSTIOCTL1;
354 u32Reg1 &= ~(TAMPER_ACTSTIOCTL1_ATAMP0EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP1EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP2EN_Msk |
355 TAMPER_ACTSTIOCTL1_ATAMP3EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP4EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP5EN_Msk);
356 u32Reg2 = TAMPER->ACTSTIOCTL2;
357 u32Reg2 &= ~(TAMPER_ACTSTIOCTL2_ATAMP0EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP1EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP2EN2_Msk |
358 TAMPER_ACTSTIOCTL2_ATAMP3EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP4EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP5EN2_Msk);
359
360 u32Reg1 &= ~(TAMPER_ACTSTIOCTL1_ADYN1ISS_Msk);
361 u32Reg1 |= ((u32Pair1Source1 & 0x1UL) << TAMPER_ACTSTIOCTL1_ADYN1ISS_Pos);
362 u32Reg2 &= ~(TAMPER_ACTSTIOCTL2_ADYN1ISS2_Msk);
363 u32Reg2 |= ((u32Pair1Source2 & 0x1UL) << TAMPER_ACTSTIOCTL2_ADYN1ISS2_Pos);
364
365 u32TmpReg1 = (TAMPER_ACTSTIOCTL1_ATAMP0EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP1EN_Msk | TAMPER_ACTSTIOCTL1_ADYNPR0EN_Msk);
366 u32TmpReg2 = (TAMPER_ACTSTIOCTL2_ATAMP0EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP1EN2_Msk | TAMPER_ACTSTIOCTL2_ADYNPR0EN2_Msk);
367
368 for(i = 0UL; i < (uint32_t)TAMPER_MAX_PAIR_NUM; i++)
369 {
370 if(u32PairSel1 & (0x1UL << i))
371 {
372 u32Reg1 |= (u32TmpReg1 << (i * 8UL));
373 }
374
375 if(u32PairSel2 & (0x1UL << i))
376 {
377 u32Reg2 |= (u32TmpReg2 << (i * 8UL));
378 }
379 }
380
381 if((u32Pair1Source1) && (u32PairSel1 & (uint32_t)TAMPER_PAIR1_SELECT))
382 {
383 u32Reg1 &= ~TAMPER_ACTSTIOCTL1_ATAMP2EN_Msk;
384 }
385
386 if((u32Pair1Source2) && (u32PairSel2 & (uint32_t)TAMPER_PAIR1_SELECT))
387 {
388 u32Reg2 &= ~TAMPER_ACTSTIOCTL2_ATAMP2EN2_Msk;
389 }
390
391 TAMPER->ACTSTIOCTL1 = u32Reg1;
392 TAMPER->ACTSTIOCTL2 = u32Reg2;
393 }
394
395 /**
396 * @brief Active Shield Dynamic Tamper Disable
397 *
398 * @param[in] u32PairSel1/2 Active shield 1/2 tamper pin detection disable. Possible options are
399 * - \ref TAMPER_PAIR0_SELECT
400 * - \ref TAMPER_PAIR1_SELECT
401 * - \ref TAMPER_PAIR2_SELECT
402 *
403 * @return None
404 *
405 * @details This API is used to disable the active shield dynamic tamper.
406 */
TAMPER_ActiveShieldDynamicTamperDisable(uint32_t u32PairSel1,uint32_t u32PairSel2)407 void TAMPER_ActiveShieldDynamicTamperDisable(uint32_t u32PairSel1, uint32_t u32PairSel2)
408 {
409 uint32_t i;
410 uint32_t u32Reg1, u32Reg2;
411 uint32_t u32TmpReg1, u32TmpReg2;
412 uint32_t u32Tamper2En1 = 0UL, u32Tamper2En2 = 0UL;
413
414 u32Reg1 = TAMPER->ACTSTIOCTL1;
415 u32Reg2 = TAMPER->ACTSTIOCTL2;
416
417 if((u32Reg1 & (uint32_t)TAMPER_ACTSTIOCTL1_ADYN1ISS_Msk) && (u32PairSel1 & (uint32_t)TAMPER_PAIR1_SELECT))
418 {
419 u32Tamper2En1 = u32Reg1 & TAMPER_ACTSTIOCTL1_ATAMP2EN_Msk;
420 }
421
422 if((u32Reg2 & (uint32_t)TAMPER_ACTSTIOCTL2_ADYN1ISS2_Msk) && (u32PairSel2 & (uint32_t)TAMPER_PAIR1_SELECT))
423 {
424 u32Tamper2En2 = u32Reg2 & TAMPER_ACTSTIOCTL2_ATAMP2EN2_Msk;
425 }
426
427 u32TmpReg1 = (TAMPER_ACTSTIOCTL1_ATAMP0EN_Msk | TAMPER_ACTSTIOCTL1_ATAMP1EN_Msk | TAMPER_ACTSTIOCTL1_ADYNPR0EN_Msk);
428 u32TmpReg2 = (TAMPER_ACTSTIOCTL2_ATAMP0EN2_Msk | TAMPER_ACTSTIOCTL2_ATAMP1EN2_Msk | TAMPER_ACTSTIOCTL2_ADYNPR0EN2_Msk);
429
430 for(i = 0UL; i < (uint32_t)TAMPER_MAX_PAIR_NUM; i++)
431 {
432 if(u32PairSel1 & (0x1UL << i))
433 {
434 u32Reg1 &= ~(u32TmpReg1 << ((i * 8UL)));
435 }
436
437 if(u32PairSel2 & (0x1UL << i))
438 {
439 u32Reg2 &= ~(u32TmpReg2 << ((i * 8UL)));
440 }
441 }
442
443 u32Reg1 |= u32Tamper2En1;
444 u32Reg2 |= u32Tamper2En2;
445
446 TAMPER->ACTSTIOCTL1 = u32Reg1;
447 TAMPER->ACTSTIOCTL2 = u32Reg2;
448 }
449
450 /**
451 * @brief Config Active Shield Dynamic Tamper
452 *
453 * @param[in] u32ChangeRate1/2 The dynamic tamper output change rate
454 * - \ref TAMPER_ACTS_2POW10_CLK
455 * - \ref TAMPER_ACTS_2POW11_CLK
456 * - \ref TAMPER_ACTS_2POW12_CLK
457 * - \ref TAMPER_ACTS_2POW13_CLK
458 * - \ref TAMPER_ACTS_2POW14_CLK
459 * - \ref TAMPER_ACTS_2POW15_CLK
460 * - \ref TAMPER_ACTS_2POW16_CLK
461 * - \ref TAMPER_ACTS_2POW17_CLK
462 *
463 * @param[in] u32SeedReload1/2 Reload new seed or not
464 * 0: not reload new seed
465 * 1: reload new seed
466 *
467 * @param[in] u32RefPattern1/2 Reference pattern
468 * - \ref TAMPER_REF_RANDOM_PATTERN
469 * - \ref TAMPER_REF_SEED
470 *
471 * @param[in] u32Seed/2 Seed Value (0x0 ~ 0xFFFFFFFF)
472 *
473 * @return None
474 *
475 * @details This API is used to config active shield dynamic tamper setting.
476 */
TAMPER_ActiveShieldDynamicTamperConfig(uint32_t u32ChangeRate1,uint32_t u32SeedReload1,uint32_t u32RefPattern1,uint32_t u32Seed,uint32_t u32ChangeRate2,uint32_t u32SeedReload2,uint32_t u32RefPattern2,uint32_t u32Seed2)477 void TAMPER_ActiveShieldDynamicTamperConfig(uint32_t u32ChangeRate1, uint32_t u32SeedReload1, uint32_t u32RefPattern1, uint32_t u32Seed,
478 uint32_t u32ChangeRate2, uint32_t u32SeedReload2, uint32_t u32RefPattern2, uint32_t u32Seed2)
479 {
480 uint32_t u32Reg1, u32Reg2;
481
482 u32Reg1 = TAMPER->ACTSTIOCTL1;
483 u32Reg2 = TAMPER->ACTSTIOCTL2;
484
485 u32Reg1 &= ~(TAMPER_ACTSTIOCTL1_ADYNSRC_Msk | TAMPER_ACTSTIOCTL1_ADYNRATE_Msk);
486 u32Reg2 &= ~(TAMPER_ACTSTIOCTL2_ADYNSRC2_Msk | TAMPER_ACTSTIOCTL2_SEEDRLD2_Msk | TAMPER_ACTSTIOCTL2_ADYNRATE2_Msk);
487
488 u32Reg1 |= (u32ChangeRate1) | ((u32RefPattern1 & 0x1UL) << TAMPER_ACTSTIOCTL1_ADYNSRC_Pos);
489 u32Reg2 |= (u32ChangeRate2) | ((u32SeedReload2 & 0x1UL) << TAMPER_ACTSTIOCTL2_SEEDRLD2_Pos) |
490 ((u32RefPattern2 & 0x1UL) << TAMPER_ACTSTIOCTL2_ADYNSRC2_Pos);
491
492 TAMPER->SEED = u32Seed; /* Need to set seed value before reloaded seed */
493 TAMPER->SEED2 = u32Seed2; /* Need to set seed value before reloaded seed */
494
495 TAMPER->ACTSTIOCTL1 = u32Reg1;
496 TAMPER->TIOCTL |= ((u32SeedReload1 & 0x1UL) << TAMPER_TIOCTL_SEEDRLD_Pos);
497 TAMPER->ACTSTIOCTL2 = u32Reg2;
498 }
499
500 /**@}*/ /* end of group TAMPER_EXPORTED_FUNCTIONS */
501
502 /**@}*/ /* end of group TAMPER_Driver */
503
504 /**@}*/ /* end of group Standard_Driver */
505