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
|
/**************************************************************************//**
* @file sspcc.c
* @brief SSPCC driver source file
*
* SPDX-License-Identifier: Apache-2.0
* @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/
#include "NuMicro.h"
/** @addtogroup Standard_Driver Standard Driver
@{
*/
/** @addtogroup SSPCC_Driver SSPCC Driver
@{
*/
/** @addtogroup SSPCC_EXPORTED_FUNCTIONS SSPCC Exported Functions
@{
*/
/**
* @brief Set Peripheral Realm
*
* @param[in] u32Perip SSPCC Peripheral ID.
* @param[in] u32Realm Security set(Realm). It could be \n
* SSPCC_SSET_TZS, SSPCC_SSET_TZNS, SSPCC_SSET_SUBM.
*
* @return None
*
* @details This function is used to set specified realm.
*/
void SSPCC_SetRealm(uint32_t u32Perip, uint32_t u32Realm)
{
vu32 *pu32SSet = (vu32 *)(SSPCC_BASE + (u32Perip >> SSPCC_REG_Pos));
uint32_t u32Pos = u32Perip & SSPCC_PS_Msk;
*pu32SSet = (*pu32SSet & ~(SSPCC_SSET_Msk << u32Pos)) | (u32Realm << u32Pos);
}
/**
* @brief Get Peripheral Realm
*
* @param[in] u32Perip SSPCC Peripheral ID.
* @param[out] u32Realm Security set(Realm). It could be \n
* SSPCC_SSET_TZS, SSPCC_SSET_TZNS, SSPCC_SSET_SUBM.
*
* @return None
*
* @details This function is used to get specified realm.
*/
uint32_t SSPCC_GetRealm(uint32_t u32Perip)
{
vu32 *pu32SSet = (vu32 *)(SSPCC_BASE + (u32Perip >> SSPCC_REG_Pos));
uint32_t u32Pos = u32Perip & SSPCC_PS_Msk;
return (*pu32SSet & (SSPCC_SSET_Msk << u32Pos)) >> u32Pos;
}
/**
* @brief Set Pin Realm
*
* @param[in] u32PortBA GPIO port. It could be GPIOA_BASE, GPIOB_BASE, ..., GPIOM_BASE and GPION_BASE.
* @param[in] u32Pin It could be 0 ~ 15 for PA, PB, ..., PM and PN GPIO ports.
* @param[in] u32Realm realm. It could be \n
* SSPCC_SSET_TZS, SSPCC_SSET_TZNS, SSPCC_SSET_SUBM.
*
* @return None
*
* @details This function is used to set specified IO realm.
*/
void SSPCC_SetRealm_GPIO(uint32_t u32PortBA, uint32_t u32Pin, uint32_t u32Realm)
{
uint32_t u32PortIdx = (u32PortBA - GPIO_BASE) / 0x40;
vu32 *avu32IOSecuritySet = (vu32 *)&SSPCC->IOASSET;
avu32IOSecuritySet[u32PortIdx] = (avu32IOSecuritySet[u32PortIdx] & ~(SSPCC_SSET_Msk << (u32Pin << 1))) | (u32Realm << (u32Pin << 1));
}
/**
* @brief Get Pin Realm
*
* @param[in] u32PortBA GPIO port. It could be GPIOA_BASE, GPIOB_BASE, ..., GPIOM_BASE and GPION_BASE.
* @param[in] u32Pin It could be 0 ~ 15 for PA, PB, ..., PM and PN GPIO ports.
*
* @return It could be \n
* SSPCC_SSET_TZS, SSPCC_SSET_TZNS, SSPCC_SSET_SUBM.
*
* @details This function is used to set specified IO realm.
*/
uint32_t SSPCC_GetRealm_GPIO(uint32_t u32PortBA, uint32_t u32Pin)
{
uint32_t u32PortIdx = (u32PortBA - GPIO_BASE) / 0x40;
vu32 *avu32IOSecuritySet = (vu32 *)&SSPCC->IOASSET;
uint32_t u32Ret = avu32IOSecuritySet[u32PortIdx] & (SSPCC_SSET_Msk << (u32Pin << 1));
return u32Ret >> (u32Pin << 1);
}
/*@}*/ /* end of group SSPCC_EXPORTED_FUNCTIONS */
/*@}*/ /* end of group SSPCC_Driver */
/*@}*/ /* end of group Standard_Driver */
|