summaryrefslogtreecommitdiff
path: root/bsp/nuvoton/libraries/m2354/StdDriver/inc/nu_dpm.h
blob: 879b23ab4e83d00267092e8ca5c2f5b0ced1a939 (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
/**************************************************************************//**
 * @file     nu_dpm.h
 * @version  V3.00
 * @brief    Debug Protection Mechanism (DPM) driver header file
 *
 * @copyright SPDX-License-Identifier: Apache-2.0
 * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
 *****************************************************************************/
#ifndef __NU_DPM_H__
#define __NU_DPM_H__

#ifdef __cplusplus
extern "C"
{
#endif


/** @addtogroup Standard_Driver Standard Driver
  @{
*/

/** @addtogroup DPM_Driver DPM Driver
  @{
*/

/** @addtogroup DPM_EXPORTED_CONSTANTS DPM Exported Constants
  @{
*/


/*---------------------------------------------------------------------------------------------------------*/
/* DPM Control Register Constant Definitions                                                               */
/*---------------------------------------------------------------------------------------------------------*/
#define SECURE_DPM          0   /*!< Secure DPM module */
#define NONSECURE_DPM       1   /*!< Non-secure DPM module */


#define DPM_CTL_WVCODE      (0x5AUL<<DPM_CTL_WVCODE_Pos)    /*!< Secure DPM control register write verify code */
#define DPM_CTL_RVCODE      (0xA5UL<<DPM_CTL_RVCODE_Pos)    /*!< Secure DPM control register read verify code */
#define DPM_NSCTL_WVCODE    (0x5AUL<<DPM_CTL_WVCODE_Pos)    /*!< Non-secure DPM control register write verify code */
#define DPM_NSCTL_RVCODE    (0xA5UL<<DPM_CTL_RVCODE_Pos)    /*!< Non-secure DPM control register read verify code */



/**@}*/ /* end of group WDT_EXPORTED_CONSTANTS */


/** @addtogroup DPM_EXPORTED_FUNCTIONS DPM Exported Functions
  @{
*/


/**
  * @brief      Enable DPM Interrupt
  * @param      None
  * @return     None
  * @details    This macro enables DPM interrupt.
  *             This macro is for Secure DPM and Secure region only.
  */
#define DPM_ENABLE_INT() \
    do{ \
        while(DPM->STS & DPM_STS_BUSY_Msk); \
        DPM->CTL = (DPM->CTL & (~DPM_CTL_WVCODE_Msk)) | (DPM_CTL_WVCODE|DPM_CTL_INTEN_Msk); \
    }while(0)

/**
  * @brief      Disable DPM Interrupt
  * @param      None
  * @return     None
  * @details    This macro disables DPM interrupt.
  *             This macro is for Secure DPM and Secure region only.
  */
#define DPM_DISABLE_INT() \
    do{ \
        while(DPM->STS & DPM_STS_BUSY_Msk); \
        DPM->CTL = (DPM->CTL & (~(DPM_CTL_WVCODE_Msk|DPM_CTL_INTEN_Msk))) | (DPM_CTL_WVCODE); \
    }while(0)

/**
  * @brief      Enable Debugger to Access DPM Registers
  * @param      None
  * @return     None
  * @details    This macro enables debugger to access Secure and Non-secure DPM registers.
  *             This macro is for Secure DPM and Secure region only.
  */
#define DPM_ENABLE_DBG_ACCESS() \
    do{ \
        while(DPM->STS & DPM_STS_BUSY_Msk); \
        DPM->CTL = (DPM->CTL & (~(DPM_CTL_WVCODE_Msk|DPM_CTL_DACCDIS_Msk))) | (DPM_CTL_WVCODE); \
    }while(0)

/**
  * @brief      Disable Debugger to Access DPM Registers
  * @param      None
  * @return     None
  * @details    This macro disables debugger to access Secure and Non-secure DPM registers.
  *             This macro is for Secure DPM and Secure region only.
  */
#define DPM_DISABLE_DBG_ACCESS() \
    do{ \
        while(DPM->STS & DPM_STS_BUSY_Msk); \
        DPM->CTL = (DPM->CTL & (~DPM_CTL_WVCODE_Msk)) | (DPM_CTL_WVCODE|DPM_CTL_DACCDIS_Msk); \
    }while(0)


void DPM_SetDebugDisable(uint32_t u32dpm);
void DPM_SetDebugLock(uint32_t u32dpm);
uint32_t DPM_GetDebugDisable(uint32_t u32dpm);
uint32_t DPM_GetDebugLock(uint32_t u32dpm);
uint32_t DPM_SetPasswordUpdate(uint32_t u32dpm, uint32_t au32Pwd[]);
uint32_t DPM_SetPasswordCompare(uint32_t u32dpm, uint32_t au32Pwd[]);
uint32_t DPM_GetPasswordErrorFlag(uint32_t u32dpm);
uint32_t DPM_GetIntFlag(void);
void DPM_ClearPasswordErrorFlag(uint32_t u32dpm);
void DPM_EnableDebuggerWriteAccess(uint32_t u32dpm);
void DPM_DisableDebuggerWriteAccess(uint32_t u32dpm);



/**@}*/ /* end of group DPM_EXPORTED_FUNCTIONS */

/**@}*/ /* end of group DPM_Driver */

/**@}*/ /* end of group Standard_Driver */

#ifdef __cplusplus
}
#endif

#endif /* __NU_DPM_H__ */