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