CC26xx Driver Library
vims.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: vims.c
3 * Revised: 2015-05-08 15:31:06 +0200 (Fri, 08 May 2015)
4 * Revision: 43457
5 *
6 * Description: Driver 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 #include <driverlib/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 VIMSModeSetBlocking
55  #define VIMSModeSetBlocking NOROM_VIMSModeSetBlocking
56 #endif
57 
58 //*****************************************************************************
59 //
61 //
62 //*****************************************************************************
63 void
64 VIMSConfigure(uint32_t ui32Base, bool bRoundRobin, bool bPrefetch)
65 {
66  uint32_t ui32Reg;
67 
68  //
69  // Check the arguments.
70  //
71  ASSERT(VIMSBaseValid(ui32Base));
72 
73  ui32Reg = HWREG(ui32Base + VIMS_O_CTL);
74  ui32Reg &= ~(VIMS_CTL_PREF_EN | VIMS_CTL_ARB_CFG);
75  if(bRoundRobin)
76  {
77  ui32Reg |= VIMS_CTL_ARB_CFG;
78  }
79  if(bPrefetch)
80  {
81  ui32Reg |= VIMS_CTL_PREF_EN;
82  }
83 
84  //
85  // Set the Arbitration and prefetch mode.
86  //
87  HWREG(ui32Base + VIMS_O_CTL) = ui32Reg;
88 }
89 
90 //*****************************************************************************
91 //
93 //
94 //*****************************************************************************
95 void
96 VIMSModeSet(uint32_t ui32Base, uint32_t ui32Mode)
97 {
98  uint32_t ui32Reg;
99 
100  //
101  // Check the arguments.
102  //
103  ASSERT(VIMSBaseValid(ui32Base));
104 
105  ASSERT((ui32Mode == VIMS_MODE_DISABLED) ||
106  (ui32Mode == VIMS_MODE_ENABLED) ||
107  (ui32Mode == VIMS_MODE_OFF) ||
108  (ui32Mode == VIMS_MODE_SPLIT));
109 
110  //
111  // Set the mode.
112  //
113  ui32Reg = HWREG(ui32Base + VIMS_O_CTL);
114  ui32Reg &= ~VIMS_CTL_MODE_M;
115  ui32Reg |= (ui32Mode & VIMS_CTL_MODE_M);
116 
117  HWREG(ui32Base + VIMS_O_CTL) = ui32Reg;
118 }
119 
120 //*****************************************************************************
121 //
123 //
124 //*****************************************************************************
125 uint32_t
126 VIMSModeGet(uint32_t ui32Base)
127 {
128  uint32_t ui32Reg;
129 
130  //
131  // Check the arguments.
132  //
133  ASSERT(VIMSBaseValid(ui32Base));
134 
135  ui32Reg = HWREG(ui32Base + VIMS_O_STAT);
136  if(ui32Reg & VIMS_STAT_MODE_CHANGING)
137  {
138  return (VIMS_MODE_CHANGING);
139  }
140  else
141  {
142  return (ui32Reg & VIMS_STAT_MODE_M);
143  }
144 }
145 
146 //*****************************************************************************
147 //
148 // Safe setting of new VIMS mode
149 // - Function is blocking
150 // - Can be called for any mode change (also if actually not changing mode)
151 // Note: The shift operators (VIMS_CTL_MODE_S and VIMS_STAT_MODE_S) is not
152 // used because we know that they both are = 0.
153 //
154 //*****************************************************************************
155 void
156 VIMSModeSetBlocking( uint32_t ui32Mode )
157 {
158  //
159  // Make sure that only the mode bits are set (just for security)
160  //
161  ui32Mode &= VIMS_CTL_MODE_M;
162 
163  //
164  // Wait for any pending change to complete
165  //
166  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
167  // Do nothing - wait for change to complete.
168  }
169 
170  //
171  // Request mode change
172  //
173  HWREG( VIMS_BASE + VIMS_O_CTL ) =
174  ( HWREG( VIMS_BASE + VIMS_O_CTL ) & ~VIMS_CTL_MODE_M ) | ui32Mode;
175 
176  //
177  // Wait for mode change to complete
178  //
179  while (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != ui32Mode ) {
180  // Do nothing - wait for new mode to be entered
181  }
182 }
void VIMSModeSet(uint32_t ui32Base, uint32_t ui32Mode)
Set the operational mode of the VIMS.
Definition: vims.c:96
#define VIMS_MODE_ENABLED
Definition: vims.h:98
uint32_t VIMSModeGet(uint32_t ui32Base)
Get the current operational mode of the VIMS.
Definition: vims.c:126
#define VIMS_MODE_SPLIT
Definition: vims.h:99
#define ASSERT(expr)
Definition: debug.h:74
#define VIMS_MODE_DISABLED
Definition: vims.h:97
#define VIMS_MODE_CHANGING
Definition: vims.h:95
#define VIMS_MODE_OFF
Definition: vims.h:101
void VIMSModeSetBlocking(uint32_t ui32Mode)
Set the operational mode of the VIMS in a safe sequence (blocking).
Definition: vims.c:156
void VIMSConfigure(uint32_t ui32Base, bool bRoundRobin, bool bPrefetch)
Configures the VIMS.
Definition: vims.c:64