1 /**
2  * @file    pt.h
3  * @brief   Pulse Train data types, definitions and function prototypes.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32572_OTP_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32572_OTP_H_
29 
30 /* **** Includes **** */
31 
32 #include "otp_regs.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @defgroup otp One-Time Programmable Memory Controller
40  * @ingroup periphlibs
41  * @brief This is the high level API for the OTP Controller.
42  * @{
43  */
44 
45 /**
46  * @brief      OTP Controller Clock Divider values.
47  *
48  * @note       There is no divide by 1 -> defaults to divide by 16.
49  *             Default reset value of CLKDIV.pclkdiv is 0 -> divide by 16.
50  */
51 typedef enum {
52     MXC_OTP_CLK_DIV2 = MXC_V_OTP_CLKDIV_PCLKDIV_DIV2, ///< Divide input clock by 2
53     MXC_OTP_CLK_DIV4 = MXC_V_OTP_CLKDIV_PCLKDIV_DIV4, ///< Divide input clock by 4
54     MXC_OTP_CLK_DIV8 = MXC_V_OTP_CLKDIV_PCLKDIV_DIV8, ///< Divide input clock by 8
55     MXC_OTP_CLK_DIV16 = MXC_V_OTP_CLKDIV_PCLKDIV_DIV16, ///< Divide input clock by 16
56     MXC_OTP_CLK_DIV32 = MXC_V_OTP_CLKDIV_PCLKDIV_DIV32, ///< Divide input clock by 32
57 } mxc_otp_clkdiv_t;
58 
59 /**
60  * @brief      Enumeration type for the OTP R/W Operations.
61  */
62 typedef enum { MXC_OTP_READ_OP, MXC_OTP_WRITE_OP } mxc_otp_op_t;
63 
64 /* **** Function Prototypes **** */
65 
66 /**
67  * @brief      Initializes the OTP Controller.
68  *
69  * @param      pclkdiv   Desired peripheral clock divider.
70  *
71  * @return     #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
72  */
73 int MXC_OTP_Init(mxc_otp_clkdiv_t pclkdiv);
74 
75 /**
76  * @brief      Checks whether the OTP user block is locked/unlocked.
77  *
78  * @return     (0) for Unlocked, (1) for Locked.
79  */
80 int MXC_OTP_IsLocked(void);
81 
82 /**
83  * @brief      Unlocks the OTP user blocks (1-2k). Enables user block OTP program ability.
84  */
85 void MXC_OTP_Unlock(void);
86 
87 /**
88  * @brief      Locks the OTP user blocks (1-2k). Disables user block OTP program ability.
89  */
90 void MXC_OTP_Lock(void);
91 
92 /**
93  * @brief      Consecutively write multiple 32-bit values starting at specified address
94  *             in OTP memory.
95  * @note       This function unlocks the OTP block before writing and locks once finished.
96  *
97  * @param      addr    Starting location to write values in OTP memory.
98  * @param      data    Pointer to buffer of data values to write.
99  * @param      size    Size of buffer, number of values to write.
100  *
101  * @return     #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
102  */
103 int MXC_OTP_Write(uint16_t addr, uint32_t *data, uint16_t size);
104 
105 /**
106  * @brief      Write data at specified address in OTP memory.
107  * @note       The OTP block where address is located should be unlocked before running
108  *             this write function. This function doesn't lock the block after a write.
109  *
110  * @param      addr    Location to write data in OTP memory.
111  * @param      data    32-bit Data value to write in memory.
112  *
113  * @return     #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
114  */
115 int MXC_OTP_Write32(uint16_t addr, uint32_t data);
116 
117 /**
118  * @brief      Consecutively read multiple 32-bit values starting at specified address
119  *             in OTP memory.
120  * @note       This function unlocks the OTP block before reading and locks once finished.
121  *
122  * @param      addr    Starting location to read values in OTP memory.
123  * @param      data    Pointer to buffer to store read values.
124  * @param      size    Size of buffer, number of values to read.
125  *
126  * @return     #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
127  */
128 int MXC_OTP_Read(uint16_t addr, uint32_t *data, uint16_t size);
129 
130 /**
131  * @brief      Read data at specified address in OTP memory.
132  * @note       The OTP block where address is located should be unlocked before running
133  *             this read function. This function doesn't lock the block after reading.
134  *             User block (1k-2k) is readable in normal mode.
135  *
136  * @param      addr    Location to read data in OTP memory.
137  * @param      data    Pointer to store 32-bit value from OTP block.
138  *
139  * @return     #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
140  */
141 int MXC_OTP_Read32(uint16_t addr, uint32_t *data);
142 
143 /**@} end of group otp*/
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32572_OTP_H_
150