1 /******************************************************************************
2 * Filename: vims.c
3 *
4 * Description: Driver 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 #include "vims.h"
38
39 //*****************************************************************************
40 //
41 // Handle support for DriverLib in ROM:
42 // This section will undo prototype renaming made in the header file
43 //
44 //*****************************************************************************
45 #if !defined(DOXYGEN)
46 #undef VIMSConfigure
47 #define VIMSConfigure NOROM_VIMSConfigure
48 #undef VIMSModeSet
49 #define VIMSModeSet NOROM_VIMSModeSet
50 #undef VIMSModeGet
51 #define VIMSModeGet NOROM_VIMSModeGet
52 #undef VIMSModeSafeSet
53 #define VIMSModeSafeSet NOROM_VIMSModeSafeSet
54 #endif
55
56 //*****************************************************************************
57 //
58 // Configures the VIMS.
59 //
60 //*****************************************************************************
61 void
VIMSConfigure(uint32_t ui32Base,bool bRoundRobin,bool bPrefetch)62 VIMSConfigure(uint32_t ui32Base, bool bRoundRobin, bool bPrefetch)
63 {
64 uint32_t ui32Reg;
65
66 // Check the arguments.
67 ASSERT(VIMSBaseValid(ui32Base));
68
69 ui32Reg = HWREG(ui32Base + VIMS_O_CTL);
70 ui32Reg &= ~(VIMS_CTL_PREF_EN | VIMS_CTL_ARB_CFG);
71 if(bRoundRobin)
72 {
73 ui32Reg |= VIMS_CTL_ARB_CFG;
74 }
75 if(bPrefetch)
76 {
77 ui32Reg |= VIMS_CTL_PREF_EN;
78 }
79
80 // Set the Arbitration and prefetch mode.
81 HWREG(ui32Base + VIMS_O_CTL) = ui32Reg;
82 }
83
84 //*****************************************************************************
85 //
86 // Set the operational mode of the VIMS
87 //
88 //*****************************************************************************
89 void
VIMSModeSet(uint32_t ui32Base,uint32_t ui32Mode)90 VIMSModeSet(uint32_t ui32Base, uint32_t ui32Mode)
91 {
92 uint32_t ui32Reg;
93
94 // Check the arguments.
95 ASSERT(VIMSBaseValid(ui32Base));
96
97 ASSERT((ui32Mode == VIMS_MODE_DISABLED) ||
98 (ui32Mode == VIMS_MODE_ENABLED) ||
99 (ui32Mode == VIMS_MODE_OFF));
100
101 // Set the mode.
102 ui32Reg = HWREG(ui32Base + VIMS_O_CTL);
103 ui32Reg &= ~VIMS_CTL_MODE_M;
104 ui32Reg |= (ui32Mode & VIMS_CTL_MODE_M);
105
106 HWREG(ui32Base + VIMS_O_CTL) = ui32Reg;
107 }
108
109 //*****************************************************************************
110 //
111 // Get the current operational mode of the VIMS.
112 //
113 //*****************************************************************************
114 uint32_t
VIMSModeGet(uint32_t ui32Base)115 VIMSModeGet(uint32_t ui32Base)
116 {
117 uint32_t ui32Reg;
118
119 // Check the arguments.
120 ASSERT(VIMSBaseValid(ui32Base));
121
122 ui32Reg = HWREG(ui32Base + VIMS_O_STAT);
123 if(ui32Reg & VIMS_STAT_MODE_CHANGING)
124 {
125 return (VIMS_MODE_CHANGING);
126 }
127 else
128 {
129 return (ui32Reg & VIMS_STAT_MODE_M);
130 }
131 }
132
133 //*****************************************************************************
134 //
135 // Safe setting of new VIMS mode
136 // - Function might be blocking
137 // - Can be called for any mode change (also if actually not changing mode)
138 //
139 //*****************************************************************************
140 void
VIMSModeSafeSet(uint32_t ui32Base,uint32_t ui32NewMode,bool blocking)141 VIMSModeSafeSet( uint32_t ui32Base, uint32_t ui32NewMode, bool blocking )
142 {
143 uint32_t currentMode;
144
145 // Check the arguments.
146 ASSERT(VIMSBaseValid(ui32Base));
147 ASSERT((ui32NewMode == VIMS_MODE_DISABLED) ||
148 (ui32NewMode == VIMS_MODE_ENABLED) ||
149 (ui32NewMode == VIMS_MODE_OFF));
150
151 // Make sure that only the mode bits are set in the input parameter
152 // (done just for security since it is critical to the code flow)
153 ui32NewMode &= VIMS_CTL_MODE_M;
154
155 // Wait for any pending change to complete and get current VIMS mode
156 // (This is a blocking point but will typically only be a blocking point
157 // only if mode is changed multiple times with blocking=0)
158 do {
159 currentMode = VIMSModeGet( ui32Base );
160 } while ( currentMode == VIMS_MODE_CHANGING );
161
162 // First check that it actually is a mode change request
163 if ( ui32NewMode != currentMode ) {
164 // Set new mode
165 VIMSModeSet( ui32Base, ui32NewMode );
166
167 // Wait for final mode change to complete - if blocking is requested
168 if ( blocking ) {
169 while ( HWREG( VIMS_BASE + VIMS_O_STAT) & VIMS_STAT_MODE_CHANGING_BITN ) {
170 // Do nothing - wait for change to complete.
171 }
172 }
173 }
174 }
175