WXK
2024-12-16 78e84fcf264afd731cd66c807d9fcb690fe12126
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
/**************************************************************************
 * @file     pan_efuse.h
 * @version  V1.00
 * $Revision: 0$
 * $Date: 2023/11/08 $ 
 * @brief    Panchip SoC eFuse driver header file
 *
 * @note
 * Copyright (C) 2023 Panchip Technology Corp. All rights reserved.
 *****************************************************************************/
 
#ifndef __PAN_EFUSE_H__
#define __PAN_EFUSE_H__
 
/**
 * @brief Efuse Interface
 * @defgroup efuse_interface Efuse Interface
 * @{
 */
 
#ifdef __cplusplus
extern "C"
{
#endif
 
/**@defgroup EFUSE_OPERATE_FLAG Efuse operate command 
 * @brief       Efuse operate command definitions
 * @{ */
#define EFUSE_CMD_READ      (0X0)   /*!< Command to read efuse momery */
#define EFUSE_CMD_PROGRAM   (0X1)   /*!< Command to program data to efuse memory */
#define EFUSE_CMD_INACTIVE  (0X2)   /*!< Command to disable efuse operate */
/**@} */
 
/**@defgroup EFUSE_STATUS_FLAG Efuse status 
 * @brief       Efuse status definitions
 * @{ */
#define EFUSE_STATUS_OK     (0x0)   /*!< Status of efuse operate,status ok */
#define EFUSE_STATUS_FAIL   (0x1)   /*!< Status of efuse operate,status fail */
/**@} */
 
/**
  * @brief  Init eFuse module.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @return None.
  *
  * @note Unlock register before use this API.
  */
__STATIC_INLINE void EFUSE_Init(EFUSE_T* efuse)
{
    efuse->EF_VDD = EFUSE_VDD_DVDD_REG_Msk;
    efuse->EF_CTL = EFUSE_CTL_EFUSE_EN_Msk;
}
 
/**
  * @brief  Un-Init eFuse module.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @return None.
  *
  * @note Unlock register before use this API.
  */
__STATIC_INLINE void EFUSE_UnInit(EFUSE_T* efuse)
{
    efuse->EF_CTL = 0;
    efuse->EF_VDD = 0;  // Disable eFuse VDD to save power
}
 
/**
  * @brief  Get eFuse error status flag.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @retval EFUSE_STATUS_OK    The previous eFuse operation success.
  * @retval EFUSE_STATUS_FAIL  The previous eFuse operation is illegal.
  */
__STATIC_INLINE uint32_t EFUSE_GetErrorStatus(EFUSE_T* efuse)
{
    return efuse->EF_OP_ERROR;
}
 
/**
  * @brief  Clear eFuse error status flag.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @return None
  */
__STATIC_INLINE void EFUSE_ClrErrorStatus(EFUSE_T* efuse)
{
    // Write 0x1 to clear this register
    efuse->EF_OP_ERROR = 1u;
}
 
/**
  * @brief  Read specified one byte from eFuse.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to read data from.
  * @return Data read from eFuse.
  *
  * @note Unlock register before use this API.
  */
extern uint8_t EFUSE_ReadByte(EFUSE_T* efuse, uint32_t addr);
 
/**
  * @brief  Write one byte data to specified eFuse address.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to write data to.
  * @param[in]  data    Data to write to eFuse.
  * @return None.
  *
  * @note Unlock register before use this API.
  */
extern void EFUSE_WriteByte(EFUSE_T* efuse, uint32_t addr, uint8_t data);
 
/**
  * @brief  Read multiple data from eFuse.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to read data from.
  * @param[in]  data    Buffer to store data read from eFuse.
  * @param[in]  len     Number of bytes to read.
  * @retval true    Read success.
  * @retval false   Error occurs while reading.
  *
  * @note Unlock register before use this API.
  */
extern bool EFUSE_Read(EFUSE_T* efuse, uint32_t addr, uint8_t* data, uint16_t len);
 
/**
  * @brief  Write multiple data to eFuse.
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to write data to.
  * @param[in]  data    Buffer to store data to be write to eFuse.
  * @param[in]  len     Number of bytes to write.
  * @retval true    Write success.
  * @retval false   Error occurs while writing.
  *
  * @note Unlock register before use this API.
  */
extern bool EFUSE_Write(EFUSE_T* efuse, uint32_t addr, uint8_t* data, uint16_t len);
 
/**
  * @brief  Read multiple data from User Area of eFuse (Address 0xE9 ~ 0xFF).
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to read data from, should be in range of 0xE9 ~ 0xFF.
  * @param[in]  data    Buffer to store data read from eFuse.
  * @param[in]  len     Number of bytes to read.
  * @retval true    Read success.
  * @retval false   Error, illegal parameter (addr or len).
  *
  * @note Unlock register before use this API.
  */
extern bool EFUSE_UserRead(EFUSE_T* efuse, uint32_t addr, uint8_t* data, uint16_t len);
 
/**
  * @brief  Write multiple data to User Area of eFuse (Address 0xE9 ~ 0xFF).
  *
  * @param[in]  efuse   Module name of eFuse, typically EFUSE.
  * @param[in]  addr    eFuse address to write data to, should be in range of 0xE9 ~ 0xFF.
  * @param[in]  data    Buffer to store data to be write to eFuse.
  * @param[in]  len     Number of bytes to write.
  * @retval true    Write success.
  * @retval false   Error, illegal parameter (addr or len).
  *
  * @note Unlock register before use this API.
  */
extern bool EFUSE_UserWrite(EFUSE_T* efuse, uint32_t addr, uint8_t* data, uint16_t len);
 
 
/**@} */
 
#ifdef __cplusplus
}
#endif
 
#endif /* __PAN_EFUSE_H__ */