1 /******************************************************************************
2 *  Filename:       vims.h
3 *  Revised:        2015-09-01 10:40:32 +0200 (Tue, 01 Sep 2015)
4 *  Revision:       44488
5 *
6 *  Description:    Defines and prototypes for the VIMS.
7 *
8 *  Copyright (c) 2015, Texas Instruments Incorporated
9 *  All rights reserved.
10 *
11 *  Redistribution and use in source and binary forms, with or without
12 *  modification, are permitted provided that the following conditions are met:
13 *
14 *  1) Redistributions of source code must retain the above copyright notice,
15 *     this list of conditions and the following disclaimer.
16 *
17 *  2) Redistributions in binary form must reproduce the above copyright notice,
18 *     this list of conditions and the following disclaimer in the documentation
19 *     and/or other materials provided with the distribution.
20 *
21 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 *     be used to endorse or promote products derived from this software without
23 *     specific prior written permission.
24 *
25 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 *  POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
41 //! \addtogroup system_control_group
42 //! @{
43 //! \addtogroup vims_api
44 //! @{
45 //
46 //*****************************************************************************
47 
48 #ifndef __VIMS_H__
49 #define __VIMS_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_vims.h>
67 #include <driverlib/debug.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 //*****************************************************************************
82 #if !defined(DOXYGEN)
83     #define VIMSConfigure                   NOROM_VIMSConfigure
84     #define VIMSModeSet                     NOROM_VIMSModeSet
85     #define VIMSModeGet                     NOROM_VIMSModeGet
86     #define VIMSModeSafeSet                 NOROM_VIMSModeSafeSet
87 #endif
88 
89 //*****************************************************************************
90 //
91 // Values that can be passed to VIMSModeSet() as the ui32IntFlags parameter,
92 // and returned from VIMSModeGet().
93 //
94 //*****************************************************************************
95 #define VIMS_MODE_CHANGING 0x4                   // VIMS mode is changing now and VIMS_MODE
96                                                  // can not be changed at moment.
97 #define VIMS_MODE_DISABLED (VIMS_CTL_MODE_GPRAM) // Disabled mode (GPRAM enabled).
98 #define VIMS_MODE_ENABLED  (VIMS_CTL_MODE_CACHE) // Enabled mode, only USERCODE is cached.
99 #define VIMS_MODE_OFF      (VIMS_CTL_MODE_OFF)   // VIMS Cache RAM is off
100 
101 //*****************************************************************************
102 //
103 // API Functions and prototypes
104 //
105 //*****************************************************************************
106 
107 #ifdef DRIVERLIB_DEBUG
108 //*****************************************************************************
109 //
110 //! \brief Checks a VIMS base address.
111 //!
112 //! This function determines if the VIMS base address is valid.
113 //!
114 //! \param ui32Base is the base address of the VIMS.
115 //!
116 //! \return Returns \c true if the base address is valid and \c false
117 //! otherwise.
118 //
119 //*****************************************************************************
120 static bool
VIMSBaseValid(uint32_t ui32Base)121 VIMSBaseValid(uint32_t ui32Base)
122 {
123     return(ui32Base == VIMS_BASE);
124 }
125 #endif
126 
127 //*****************************************************************************
128 //
129 //! \brief Configures the VIMS.
130 //!
131 //! This function sets general control settings of the VIMS system.
132 //!
133 //! \note The VIMS mode must be set using the \ref VIMSModeSet() call.
134 //!
135 //! \param ui32Base is the base address of the VIMS.
136 //! \param bRoundRobin specifies the arbitration method.
137 //! - \c true  : Round Robin arbitration between the two available read/write interfaces
138 //! (i.e. Icode/Dcode and Sysbus) is to be used.
139 //! - \c false : Strict arbitration will be used, where Icode/Dcode
140 //! is preferred over the Sysbus.
141 //! \param bPrefetch specifies if prefetching is to be used.
142 //! - \c true  : Cache is to prefetch tag data for the following address.
143 //! - \c false : No prefetch.
144 //!
145 //! \return None
146 //!
147 //! \sa \ref VIMSModeSet()
148 //
149 //*****************************************************************************
150 extern void VIMSConfigure(uint32_t ui32Base, bool bRoundRobin,
151                           bool bPrefetch);
152 
153 //*****************************************************************************
154 //
155 //! \brief Set the operational mode of the VIMS.
156 //!
157 //! This function sets the operational mode of the VIMS.
158 //!
159 //! Upon reset the VIMS will be in \ref VIMS_MODE_CHANGING mode.
160 //!   In this mode the VIMS will initialize the cache (GP) RAM (to all zeros).
161 //!   The GP RAM will not be operational (read/write will result in bus fault).
162 //!   The Cache will not be operational.
163 //!   Reads and writes to flash will be uncached.
164 //!   After a short delay (approx. 1029 clock cycles) the VIMS will
165 //!   automatically switch mode to \ref VIMS_MODE_DISABLED (GPRAM enabled).
166 //!
167 //! In \ref VIMS_MODE_DISABLED mode, the cache is disabled but the GP RAM is
168 //! accessible:
169 //!   The GP RAM will be accessible.
170 //!   The Cache will not be operational.
171 //!   Reads from flash will be uncached.
172 //!   From this mode, the VIMS may be put in \ref VIMS_MODE_ENABLED (CACHE mode).
173 //!
174 //! In \ref VIMS_MODE_ENABLED mode, the cache is enabled for \b USERCODE space.
175 //!   The GP RAM will not be operational (read/write will result in bus fault).
176 //!   The Cache will be operational for SYSCODE space.
177 //!   Reads from flash in USERCODE space will be uncached.
178 //!
179 //! In \ref VIMS_MODE_OFF the cache RAM is off to conserve power.
180 //!
181 //! \note The VIMS must be invalidated when switching mode.
182 //! This is done by setting VIMS_MODE_OFF before setting any new mode.
183 //! This is automatically handled in \ref VIMSModeSafeSet()
184 //!
185 //! \note It is highly recommended that the VIMS is put in disabled mode before
186 //! \b writing to flash, since the cache will not be updated nor invalidated
187 //! by flash writes. The line buffers should also be disabled when updating the
188 //! flash. Once \ref VIMSModeSet() is used to set the VIMS in
189 //! \ref VIMS_MODE_CHANGING mode, the user should check using
190 //! \ref VIMSModeGet() when the mode switches to \ref VIMS_MODE_DISABLED. Only when
191 //! the mode has changed the cache has been completely invalidated.
192 //!
193 //! \note Access from System Bus is never cached. Only access through ICODE
194 //! DCODE bus from the System CPU is cached.
195 //!
196 //! \param ui32Base is the base address of the VIMS.
197 //! \param ui32Mode is the operational mode.
198 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
199 //! - \ref VIMS_MODE_ENABLED  (CACHE mode)
200 //! - \ref VIMS_MODE_OFF
201 //!
202 //! \return None
203 //!
204 //! \sa \ref VIMSModeGet() and \ref VIMSModeSafeSet()
205 //
206 //*****************************************************************************
207 extern void VIMSModeSet(uint32_t ui32Base, uint32_t ui32Mode);
208 
209 //*****************************************************************************
210 //
211 //! \brief Get the current operational mode of the VIMS.
212 //!
213 //! This function returns the operational mode of the VIMS.
214 //!
215 //! \param ui32Base is the base address of the VIMS.
216 //!
217 //! \return Returns one of:
218 //! - \ref VIMS_MODE_CHANGING
219 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
220 //! - \ref VIMS_MODE_ENABLED  (CACHE mode)
221 //! - \ref VIMS_MODE_OFF
222 //!
223 //! \sa \ref VIMSModeSet()
224 //
225 //*****************************************************************************
226 extern uint32_t VIMSModeGet(uint32_t ui32Base);
227 
228 //*****************************************************************************
229 //
230 //! \brief Set the operational mode of the VIMS in a safe sequence.
231 //!
232 //! This function sets the operational mode of the VIMS in a safe sequence
233 //!
234 //! Upon reset the VIMS will be in \ref VIMS_MODE_CHANGING mode.
235 //!   In this mode the VIMS will initialize the cache (GP) RAM (to all zeros).
236 //!   The GP RAM will not be operational (read/write will result in bus fault).
237 //!   The Cache will not be operational (read/write to flash will be uncached).
238 //!   After a short delay (approx. 1029 clock cycles) the VIMS will
239 //!   automatically switch mode to \ref VIMS_MODE_DISABLED (GPRAM enabled).
240 //!
241 //! In \ref VIMS_MODE_DISABLED mode, the cache is disabled but the GP RAM is
242 //! accessible:
243 //!   The GP RAM will be accessible.
244 //!   The Cache will not be operational.
245 //!   Reads from flash will be uncached.
246 //!   From this mode, the VIMS may be put in \ref VIMS_MODE_ENABLED (CACHE mode).
247 //!
248 //! In \ref VIMS_MODE_ENABLED mode, the cache is enabled for \b USERCODE space.
249 //!   The GP RAM will not be operational (read/write will result in bus fault).
250 //!   The Cache will be operational for SYSCODE space.
251 //!   Reads from flash in USERCODE space will be uncached.
252 //!
253 //! In \ref VIMS_MODE_OFF the cache RAM is off to conserve power.
254 //!
255 //! \note The VIMS must be invalidated when switching mode.
256 //! This is done by setting VIMS_MODE_OFF before setting any new mode.
257 //! This is automatically handled in this function.
258 //!
259 //! \note It is highly recommended that the VIMS is put in disabled mode before
260 //! \b writing to flash, since the cache will not be updated nor invalidated
261 //! by flash writes. The line buffers should also be disabled when updating the
262 //! flash.
263 //!
264 //! \note Access from System Bus is never cached. Only access through ICODE
265 //! DCODE bus from the System CPU is cached.
266 //!
267 //! \param ui32Base is the base address of the VIMS.
268 //! \param ui32NewMode is the new operational mode:
269 //! - \ref VIMS_MODE_DISABLED (GPRAM enabled)
270 //! - \ref VIMS_MODE_ENABLED  (CACHE mode)
271 //! - \ref VIMS_MODE_OFF
272 //! \param blocking shall be set to TRUE if further code execution shall be
273 //! blocked (delayed) until mode change is completed.
274 //!
275 //! \return None
276 //!
277 //! \sa \ref VIMSModeSet() and \ref VIMSModeGet()
278 //
279 //*****************************************************************************
280 extern void VIMSModeSafeSet( uint32_t ui32Base    ,
281                              uint32_t ui32NewMode ,
282                              bool     blocking    );
283 
284 //*****************************************************************************
285 //
286 //! \brief Disable VIMS linebuffers.
287 //!
288 //! Linebuffers should only be disabled when attempting to update the flash, to
289 //! ensure that the content of the buffers is not stale. As soon as flash is
290 //! updated the linebuffers should be reenabled. Failing to enable
291 //! will have a performance impact.
292 //!
293 //! \param ui32Base is the base address of the VIMS.
294 //!
295 //! \return None.
296 //
297 //*****************************************************************************
298 __STATIC_INLINE void
VIMSLineBufDisable(uint32_t ui32Base)299 VIMSLineBufDisable(uint32_t ui32Base)
300 {
301     //
302     // Disable line buffers
303     //
304     HWREG(ui32Base + VIMS_O_CTL) |= VIMS_CTL_IDCODE_LB_DIS_M |
305                                         VIMS_CTL_SYSBUS_LB_DIS_M;
306 }
307 
308 //*****************************************************************************
309 //
310 //! \brief Enable VIMS linebuffers.
311 //!
312 //! Linebuffers should only be disabled when attempting to update the flash, to
313 //! ensure that the content of the buffers is not stale. As soon as flash is
314 //! updated the linebuffers should be reenabled. Failing to enable
315 //! will have a performance impact.
316 //!
317 //! \param ui32Base is the base address of the VIMS.
318 //!
319 //! \return None.
320 //
321 //*****************************************************************************
322 __STATIC_INLINE void
VIMSLineBufEnable(uint32_t ui32Base)323 VIMSLineBufEnable(uint32_t ui32Base)
324 {
325     //
326     // Enable linebuffers
327     //
328     HWREG(ui32Base + VIMS_O_CTL) &= ~(VIMS_CTL_IDCODE_LB_DIS_M |
329                                           VIMS_CTL_SYSBUS_LB_DIS_M);
330 }
331 
332 //*****************************************************************************
333 //
334 // Support for DriverLib in ROM:
335 // Redirect to implementation in ROM when available.
336 //
337 //*****************************************************************************
338 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
339     #include <driverlib/rom.h>
340     #ifdef ROM_VIMSConfigure
341         #undef  VIMSConfigure
342         #define VIMSConfigure                   ROM_VIMSConfigure
343     #endif
344     #ifdef ROM_VIMSModeSet
345         #undef  VIMSModeSet
346         #define VIMSModeSet                     ROM_VIMSModeSet
347     #endif
348     #ifdef ROM_VIMSModeGet
349         #undef  VIMSModeGet
350         #define VIMSModeGet                     ROM_VIMSModeGet
351     #endif
352     #ifdef ROM_VIMSModeSafeSet
353         #undef  VIMSModeSafeSet
354         #define VIMSModeSafeSet                 ROM_VIMSModeSafeSet
355     #endif
356 #endif
357 
358 //*****************************************************************************
359 //
360 // Mark the end of the C bindings section for C++ compilers.
361 //
362 //*****************************************************************************
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif //  __VIMS_H__
368 
369 //*****************************************************************************
370 //
371 //! Close the Doxygen group.
372 //! @}
373 //! @}
374 //
375 //*****************************************************************************
376