1 /******************************************************************************
2 * Filename: vims.h
3 *
4 * Description: Defines and prototypes for the VIMS.
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 system_control_group
40 //! @{
41 //! \addtogroup vims_api
42 //! @{
43 //
44 //*****************************************************************************
45
46 #ifndef __VIMS_H__
47 #define __VIMS_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 #define DOXYGEN
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include "../inc/hw_types.h"
63 #include "../inc/hw_memmap.h"
64 #include "../inc/hw_vims.h"
65 #include "debug.h"
66
67 //*****************************************************************************
68 //
69 // Support for DriverLib in ROM:
70 // This section renames all functions that are not "static inline", so that
71 // calling these functions will default to implementation in flash. At the end
72 // of this file a second renaming will change the defaults to implementation in
73 // ROM for available functions.
74 //
75 // To force use of the implementation in flash, e.g. for debugging:
76 // - Globally: Define DRIVERLIB_NOROM at project level
77 // - Per function: Use prefix "NOROM_" when calling the function
78 //
79 //*****************************************************************************
80 #if !defined(DOXYGEN)
81 #define VIMSConfigure NOROM_VIMSConfigure
82 #define VIMSModeSet NOROM_VIMSModeSet
83 #define VIMSModeGet NOROM_VIMSModeGet
84 #define VIMSModeSafeSet NOROM_VIMSModeSafeSet
85 #endif
86
87 //*****************************************************************************
88 //
89 // Values that can be passed to VIMSModeSet() as the ui32IntFlags parameter,
90 // and returned from VIMSModeGet().
91 //
92 //*****************************************************************************
93 #define VIMS_MODE_CHANGING 0x4 // VIMS mode is changing now and VIMS_MODE
94 // can not be changed at moment.
95 #define VIMS_MODE_DISABLED (VIMS_CTL_MODE_GPRAM) // Disabled mode (GPRAM enabled).
96 #define VIMS_MODE_ENABLED (VIMS_CTL_MODE_CACHE) // Enabled mode, only USERCODE is cached.
97 #define VIMS_MODE_OFF (VIMS_CTL_MODE_OFF) // VIMS Cache RAM is off
98
99 //*****************************************************************************
100 //
101 // API Functions and prototypes
102 //
103 //*****************************************************************************
104
105 #ifdef DRIVERLIB_DEBUG
106 //*****************************************************************************
107 //
108 //! \brief Checks a VIMS base address.
109 //!
110 //! This function determines if the VIMS base address is valid.
111 //!
112 //! \param ui32Base is the base address of the VIMS.
113 //!
114 //! \return Returns \c true if the base address is valid and \c false
115 //! otherwise.
116 //
117 //*****************************************************************************
118 static bool
VIMSBaseValid(uint32_t ui32Base)119 VIMSBaseValid(uint32_t ui32Base)
120 {
121 return(ui32Base == VIMS_BASE);
122 }
123 #endif
124
125 //*****************************************************************************
126 //
127 //! \brief Configures the VIMS.
128 //!
129 //! This function sets general control settings of the VIMS system.
130 //!
131 //! \note The VIMS mode must be set using the \ref VIMSModeSet() call.
132 //!
133 //! \param ui32Base is the base address of the VIMS.
134 //! \param bRoundRobin specifies the arbitration method.
135 //! - \c true : Round Robin arbitration between the two available read/write interfaces
136 //! (i.e. Icode/Dcode and Sysbus) is to be used.
137 //! - \c false : Strict arbitration will be used, where Icode/Dcode
138 //! is preferred over the Sysbus.
139 //! \param bPrefetch specifies if prefetching is to be used.
140 //! - \c true : Cache is to prefetch tag data for the following address.
141 //! - \c false : No prefetch.
142 //!
143 //! \return None
144 //!
145 //! \sa \ref VIMSModeSet()
146 //
147 //*****************************************************************************
148 extern void VIMSConfigure(uint32_t ui32Base, bool bRoundRobin,
149 bool bPrefetch);
150
151 //*****************************************************************************
152 //
153 //! \brief Set the operational mode of the VIMS.
154 //!
155 //! This function sets the operational mode of the VIMS.
156 //!
157 //! Upon reset the VIMS will be in \ref VIMS_MODE_CHANGING mode.
158 //! In this mode the VIMS will initialize the cache (GP) RAM (to all zeros).
159 //! The GP RAM will not be operational (read/write will result in bus fault).
160 //! The Cache will not be operational.
161 //! Reads and writes to flash will be uncached.
162 //! After a short delay (approx. 1029 clock cycles) the VIMS will
163 //! automatically switch mode to \ref VIMS_MODE_DISABLED (GPRAM enabled).
164 //!
165 //! In \ref VIMS_MODE_DISABLED mode, the cache is disabled but the GP RAM is
166 //! accessible:
167 //! The GP RAM will be accessible.
168 //! The Cache will not be operational.
169 //! Reads from flash will be uncached.
170 //! From this mode, the VIMS may be put in \ref VIMS_MODE_ENABLED (CACHE mode).
171 //!
172 //! In \ref VIMS_MODE_ENABLED mode, the cache is enabled for \b USERCODE space.
173 //! The GP RAM will not be operational (read/write will result in bus fault).
174 //! The Cache will be operational for SYSCODE space.
175 //! Reads from flash in USERCODE space will be uncached.
176 //!
177 //! In \ref VIMS_MODE_OFF the cache RAM is off to conserve power.
178 //!
179 //! \note The VIMS must be invalidated when switching mode.
180 //! This is done by setting VIMS_MODE_OFF before setting any new mode.
181 //! This is automatically handled in \ref VIMSModeSafeSet()
182 //!
183 //! \note It is highly recommended that the VIMS is put in disabled mode before
184 //! \b writing to flash, since the cache will not be updated nor invalidated
185 //! by flash writes. The line buffers should also be disabled when updating the
186 //! flash. Once \ref VIMSModeSet() is used to set the VIMS in
187 //! \ref VIMS_MODE_CHANGING mode, the user should check using
188 //! \ref VIMSModeGet() when the mode switches to \ref VIMS_MODE_DISABLED. Only when
189 //! the mode has changed the cache has been completely invalidated.
190 //!
191 //! \note Access from System Bus is never cached. Only access through ICODE
192 //! DCODE bus from the System CPU is cached.
193 //!
194 //! \param ui32Base is the base address of the VIMS.
195 //! \param ui32Mode is the operational mode.
196 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
197 //! - \ref VIMS_MODE_ENABLED (CACHE mode)
198 //! - \ref VIMS_MODE_OFF
199 //!
200 //! \return None
201 //!
202 //! \sa \ref VIMSModeGet() and \ref VIMSModeSafeSet()
203 //
204 //*****************************************************************************
205 extern void VIMSModeSet(uint32_t ui32Base, uint32_t ui32Mode);
206
207 //*****************************************************************************
208 //
209 //! \brief Get the current operational mode of the VIMS.
210 //!
211 //! This function returns the operational mode of the VIMS.
212 //!
213 //! \param ui32Base is the base address of the VIMS.
214 //!
215 //! \return Returns one of:
216 //! - \ref VIMS_MODE_CHANGING
217 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
218 //! - \ref VIMS_MODE_ENABLED (CACHE mode)
219 //! - \ref VIMS_MODE_OFF
220 //!
221 //! \sa \ref VIMSModeSet()
222 //
223 //*****************************************************************************
224 extern uint32_t VIMSModeGet(uint32_t ui32Base);
225
226 //*****************************************************************************
227 //
228 //! \brief Set the operational mode of the VIMS in a safe sequence.
229 //!
230 //! This function sets the operational mode of the VIMS in a safe sequence
231 //!
232 //! Upon reset the VIMS will be in \ref VIMS_MODE_CHANGING mode.
233 //! In this mode the VIMS will initialize the cache (GP) RAM (to all zeros).
234 //! The GP RAM will not be operational (read/write will result in bus fault).
235 //! The Cache will not be operational (read/write to flash will be uncached).
236 //! After a short delay (approx. 1029 clock cycles) the VIMS will
237 //! automatically switch mode to \ref VIMS_MODE_DISABLED (GPRAM enabled).
238 //!
239 //! In \ref VIMS_MODE_DISABLED mode, the cache is disabled but the GP RAM is
240 //! accessible:
241 //! The GP RAM will be accessible.
242 //! The Cache will not be operational.
243 //! Reads from flash will be uncached.
244 //! From this mode, the VIMS may be put in \ref VIMS_MODE_ENABLED (CACHE mode).
245 //!
246 //! In \ref VIMS_MODE_ENABLED mode, the cache is enabled for \b USERCODE space.
247 //! The GP RAM will not be operational (read/write will result in bus fault).
248 //! The Cache will be operational for SYSCODE space.
249 //! Reads from flash in USERCODE space will be uncached.
250 //!
251 //! In \ref VIMS_MODE_OFF the cache RAM is off to conserve power.
252 //!
253 //! \note The VIMS must be invalidated when switching mode.
254 //! This is done by setting VIMS_MODE_OFF before setting any new mode.
255 //! This is automatically handled in this function.
256 //!
257 //! \note It is highly recommended that the VIMS is put in disabled mode before
258 //! \b writing to flash, since the cache will not be updated nor invalidated
259 //! by flash writes. The line buffers should also be disabled when updating the
260 //! flash.
261 //!
262 //! \note Access from System Bus is never cached. Only access through ICODE
263 //! DCODE bus from the System CPU is cached.
264 //!
265 //! \param ui32Base is the base address of the VIMS.
266 //! \param ui32NewMode is the new operational mode:
267 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
268 //! - \ref VIMS_MODE_ENABLED (CACHE mode)
269 //! - \ref VIMS_MODE_OFF
270 //! \param blocking shall be set to TRUE if further code execution shall be
271 //! blocked (delayed) until mode change is completed.
272 //!
273 //! \return None
274 //!
275 //! \sa \ref VIMSModeSet() and \ref VIMSModeGet()
276 //
277 //*****************************************************************************
278 extern void VIMSModeSafeSet( uint32_t ui32Base ,
279 uint32_t ui32NewMode ,
280 bool blocking );
281
282 //*****************************************************************************
283 //
284 //! \brief Disable VIMS linebuffers.
285 //!
286 //! Linebuffers should only be disabled when attempting to update the flash, to
287 //! ensure that the content of the buffers is not stale. As soon as flash is
288 //! updated the linebuffers should be reenabled. Failing to enable
289 //! will have a performance impact.
290 //!
291 //! \param ui32Base is the base address of the VIMS.
292 //!
293 //! \return None.
294 //
295 //*****************************************************************************
296 __STATIC_INLINE void
VIMSLineBufDisable(uint32_t ui32Base)297 VIMSLineBufDisable(uint32_t ui32Base)
298 {
299 // Disable line buffers
300 HWREG(ui32Base + VIMS_O_CTL) |= VIMS_CTL_IDCODE_LB_DIS_M |
301 VIMS_CTL_SYSBUS_LB_DIS_M;
302 }
303
304 //*****************************************************************************
305 //
306 //! \brief Enable VIMS linebuffers.
307 //!
308 //! Linebuffers should only be disabled when attempting to update the flash, to
309 //! ensure that the content of the buffers is not stale. As soon as flash is
310 //! updated the linebuffers should be reenabled. Failing to enable
311 //! will have a performance impact.
312 //!
313 //! \param ui32Base is the base address of the VIMS.
314 //!
315 //! \return None.
316 //
317 //*****************************************************************************
318 __STATIC_INLINE void
VIMSLineBufEnable(uint32_t ui32Base)319 VIMSLineBufEnable(uint32_t ui32Base)
320 {
321 // Enable linebuffers
322 HWREG(ui32Base + VIMS_O_CTL) &= ~(VIMS_CTL_IDCODE_LB_DIS_M |
323 VIMS_CTL_SYSBUS_LB_DIS_M);
324 }
325
326 //*****************************************************************************
327 //
328 // Support for DriverLib in ROM:
329 // Redirect to implementation in ROM when available.
330 //
331 //*****************************************************************************
332 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
333 // #include "../driverlib/rom.h"
334 #ifdef ROM_VIMSConfigure
335 #undef VIMSConfigure
336 #define VIMSConfigure ROM_VIMSConfigure
337 #endif
338 #ifdef ROM_VIMSModeSet
339 #undef VIMSModeSet
340 #define VIMSModeSet ROM_VIMSModeSet
341 #endif
342 #ifdef ROM_VIMSModeGet
343 #undef VIMSModeGet
344 #define VIMSModeGet ROM_VIMSModeGet
345 #endif
346 #ifdef ROM_VIMSModeSafeSet
347 #undef VIMSModeSafeSet
348 #define VIMSModeSafeSet ROM_VIMSModeSafeSet
349 #endif
350 #endif
351
352 //*****************************************************************************
353 //
354 // Mark the end of the C bindings section for C++ compilers.
355 //
356 //*****************************************************************************
357 #ifdef __cplusplus
358 }
359 #endif
360
361 #endif // __VIMS_H__
362
363 //*****************************************************************************
364 //
365 //! Close the Doxygen group.
366 //! @}
367 //! @}
368 //
369 //*****************************************************************************
370