1 /******************************************************************************
2 * Filename: aon_ioc.h
3 *
4 * Description: Defines and prototypes for the AON IO Controller
5 *
6 * Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1) Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2) Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36
37 //*****************************************************************************
38 //
39 //! \addtogroup aon_group
40 //! @{
41 //! \addtogroup aonioc_api
42 //! @{
43 //
44 //*****************************************************************************
45
46 #ifndef __AON_IOC_H__
47 #define __AON_IOC_H__
48
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include "../inc/hw_types.h"
63 #include "../inc/hw_memmap.h"
64 #include "../inc/hw_aon_ioc.h"
65 #include "debug.h"
66
67 //*****************************************************************************
68 //
69 // Defines for the drive strength
70 //
71 //*****************************************************************************
72 #define AONIOC_DRV_STR_1 0x00000000 // Lowest drive strength
73 #define AONIOC_DRV_STR_2 0x00000001
74 #define AONIOC_DRV_STR_3 0x00000003
75 #define AONIOC_DRV_STR_4 0x00000002
76 #define AONIOC_DRV_STR_5 0x00000006
77 #define AONIOC_DRV_STR_6 0x00000007
78 #define AONIOC_DRV_STR_7 0x00000005
79 #define AONIOC_DRV_STR_8 0x00000004 // Highest drive strength
80
81 #define AONIOC_DRV_LVL_MIN (AON_IOC_O_IOSTRMIN)
82 #define AONIOC_DRV_LVL_MED (AON_IOC_O_IOSTRMED)
83 #define AONIOC_DRV_LVL_MAX (AON_IOC_O_IOSTRMAX)
84
85 //*****************************************************************************
86 //
87 // API Functions and prototypes
88 //
89 //*****************************************************************************
90
91 //*****************************************************************************
92 //
93 //! \brief Configure drive strength values for the manual drive strength options.
94 //!
95 //! This function defines the general drive strength settings for the non-AUTO
96 //! drive strength options in the MCU IOC. Consequently, if all IOs are using the
97 //! automatic drive strength option this function has no effect.
98 //!
99 //! Changing the drive strength values affects all current modes (Low-Current,
100 //! High-Current, and Extended-Current). Current mode for individual IOs is set in
101 //! MCU IOC by \ref IOCIODrvStrengthSet().
102 //!
103 //! \note Values are Gray encoded. Simply incrementing values to increase drive
104 //! strength will not work.
105 //!
106 //! \param ui32DriveLevel
107 //! - \ref AONIOC_DRV_LVL_MIN : Minimum drive strength option. Default value is selected
108 //! to give minimum 2/4/8 mA @3.3V for Low-Current mode, High-Current mode,
109 //! and Extended-Current mode respectively.
110 //! - \ref AONIOC_DRV_LVL_MED : Medium drive strength option. Default value is selected
111 //! to give minimum 2/4/8 mA @2.5V for Low-Current mode, High-Current mode,
112 //! and Extended-Current mode respectively.
113 //! - \ref AONIOC_DRV_LVL_MAX : Maximum drive strength option. Default value is selected
114 //! to give minimum 2/4/8 mA @1.8V for Low-Current mode, High-Current mode,
115 //! and Extended-Current mode respectively.
116 //! \param ui32DriveStrength sets the value used by IOs configured as non-AUTO drive strength in MCU IOC.
117 //! - \ref AONIOC_DRV_STR_1 : Lowest drive strength
118 //! - \ref AONIOC_DRV_STR_2
119 //! - \ref AONIOC_DRV_STR_3
120 //! - \ref AONIOC_DRV_STR_4
121 //! - \ref AONIOC_DRV_STR_5
122 //! - \ref AONIOC_DRV_STR_6
123 //! - \ref AONIOC_DRV_STR_7
124 //! - \ref AONIOC_DRV_STR_8 : Highest drive strength
125 //!
126 //! \return None
127 //!
128 //! \sa \ref AONIOCDriveStrengthGet(), \ref IOCIODrvStrengthSet()
129 //
130 //*****************************************************************************
131 __STATIC_INLINE void
AONIOCDriveStrengthSet(uint32_t ui32DriveLevel,uint32_t ui32DriveStrength)132 AONIOCDriveStrengthSet(uint32_t ui32DriveLevel, uint32_t ui32DriveStrength)
133 {
134 ASSERT((ui32DriveLevel == AONIOC_DRV_LVL_MIN) ||
135 (ui32DriveLevel == AONIOC_DRV_LVL_MED) ||
136 (ui32DriveLevel == AONIOC_DRV_LVL_MAX));
137 ASSERT((ui32DriveStrength == AONIOC_DRV_STR_1) ||
138 (ui32DriveStrength == AONIOC_DRV_STR_2) ||
139 (ui32DriveStrength == AONIOC_DRV_STR_3) ||
140 (ui32DriveStrength == AONIOC_DRV_STR_4) ||
141 (ui32DriveStrength == AONIOC_DRV_STR_5) ||
142 (ui32DriveStrength == AONIOC_DRV_STR_6) ||
143 (ui32DriveStrength == AONIOC_DRV_STR_7) ||
144 (ui32DriveStrength == AONIOC_DRV_STR_8));
145
146 // Set the drive strength.
147 HWREG(AON_IOC_BASE + ui32DriveLevel) = ui32DriveStrength;
148 }
149
150 //*****************************************************************************
151 //
152 //! \brief Get a specific drive level setting for all IOs.
153 //!
154 //! Use this function to read the drive strength setting for a specific
155 //! IO drive level.
156 //!
157 //! \note Values are Gray encoded.
158 //!
159 //! \param ui32DriveLevel is the specific drive level to get the setting for.
160 //! - \ref AONIOC_DRV_LVL_MIN : Minimum drive strength option.
161 //! - \ref AONIOC_DRV_LVL_MED : Medium drive strength option.
162 //! - \ref AONIOC_DRV_LVL_MAX : Maximum drive strength option.
163 //!
164 //! \return Returns the requested drive strength level setting for all IOs.
165 //! Possible values are:
166 //! - \ref AONIOC_DRV_STR_1 : Lowest drive strength
167 //! - \ref AONIOC_DRV_STR_2
168 //! - \ref AONIOC_DRV_STR_3
169 //! - \ref AONIOC_DRV_STR_4
170 //! - \ref AONIOC_DRV_STR_5
171 //! - \ref AONIOC_DRV_STR_6
172 //! - \ref AONIOC_DRV_STR_7
173 //! - \ref AONIOC_DRV_STR_8 : Highest drive strength
174 //!
175 //! \sa AONIOCDriveStrengthSet()
176 //
177 //*****************************************************************************
178 __STATIC_INLINE uint32_t
AONIOCDriveStrengthGet(uint32_t ui32DriveLevel)179 AONIOCDriveStrengthGet(uint32_t ui32DriveLevel)
180 {
181 // Check the arguments.
182 ASSERT((ui32DriveLevel == AONIOC_DRV_LVL_MIN) ||
183 (ui32DriveLevel == AONIOC_DRV_LVL_MED) ||
184 (ui32DriveLevel == AONIOC_DRV_LVL_MAX));
185
186 // Return the drive strength value.
187 return( HWREG(AON_IOC_BASE + ui32DriveLevel) );
188 }
189
190 //*****************************************************************************
191 //
192 //! \brief Freeze the IOs.
193 //!
194 //! To retain the values of the output IOs during a powerdown/shutdown of the
195 //! device all IO latches in the AON domain should be frozen in their current
196 //! state. This ensures that software can regain control of the IOs after a
197 //! reboot without the IOs first falling back to the default values (i.e. input
198 //! and no pull).
199 //!
200 //! \return None
201 //!
202 //! \sa AONIOCFreezeDisable()
203 //
204 //*****************************************************************************
205 __STATIC_INLINE void
AONIOCFreezeEnable(void)206 AONIOCFreezeEnable(void)
207 {
208 // Set the AON IO latches as static.
209 HWREG(AON_IOC_BASE + AON_IOC_O_IOCLATCH) = 0x0;
210 }
211
212 //*****************************************************************************
213 //
214 //! \brief Un-freeze the IOs.
215 //!
216 //! When rebooting the chip after it has entered powerdown/shutdown mode, the
217 //! software can regain control of the IOs by setting the IO latches as
218 //! transparent. The IOs should not be unfrozen before software has restored
219 //! the functionality of the IO.
220 //!
221 //! \return None
222 //!
223 //! \sa AONIOCFreezeEnable()
224 //
225 //*****************************************************************************
226 __STATIC_INLINE void
AONIOCFreezeDisable(void)227 AONIOCFreezeDisable(void)
228 {
229 // Set the AON IOC latches as transparent.
230 HWREG(AON_IOC_BASE + AON_IOC_O_IOCLATCH) = AON_IOC_IOCLATCH_EN;
231 }
232
233 //*****************************************************************************
234 //
235 //! \brief Disable the 32kHz clock output.
236 //!
237 //! When outputting a 32 kHz clock on an IO, the output enable/disable functionality
238 //! in the IOC is bypassed. Therefore, the programmer needs to call this
239 //! function to disable the clock output.
240 //!
241 //! \return None
242 //!
243 //! \sa AONIOC32kHzOutputEnable()
244 //
245 //*****************************************************************************
246 __STATIC_INLINE void
AONIOC32kHzOutputDisable(void)247 AONIOC32kHzOutputDisable(void)
248 {
249 // Disable the LF clock output.
250 HWREG(AON_IOC_BASE + AON_IOC_O_CLK32KCTL) = AON_IOC_CLK32KCTL_OE_N;
251 }
252
253 //*****************************************************************************
254 //
255 //! \brief Enable the 32kHz clock output.
256 //!
257 //! When outputting a 32 kHz clock on an IO, the output enable/disable functionality
258 //! in the IOC is bypassed. Therefore, the programmer needs to call this
259 //! function to enable the clock output.
260 //!
261 //! \return None
262 //!
263 //! \sa AONIOC32kHzOutputDisable()
264 //
265 //*****************************************************************************
266 __STATIC_INLINE void
AONIOC32kHzOutputEnable(void)267 AONIOC32kHzOutputEnable(void)
268 {
269 // Enable the LF clock output.
270 HWREG(AON_IOC_BASE + AON_IOC_O_CLK32KCTL) = 0x0;
271 }
272
273 //*****************************************************************************
274 //
275 // Mark the end of the C bindings section for C++ compilers.
276 //
277 //*****************************************************************************
278 #ifdef __cplusplus
279 }
280 #endif
281
282 #endif // __AON_IOC_H__
283
284 //*****************************************************************************
285 //
286 //! Close the Doxygen group.
287 //! @}
288 //! @}
289 //
290 //*****************************************************************************
291