1 /******************************************************************************
2 *  Filename:       setup_rom.h
3 *  Revised:        2020-09-17 15:26:49 +0200 (Thu, 17 Sep 2020)
4 *  Revision:       58682
5 *
6 *  Description:    Prototypes and defines for the setup API.
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 //*****************************************************************************
40 //
41 //! \addtogroup system_control_group
42 //! @{
43 //! \addtogroup setup_rom_api
44 //! @{
45 //
46 //*****************************************************************************
47 
48 #ifndef __SETUP_ROM_H__
49 #define __SETUP_ROM_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 // Hardware headers
63 #include "../inc/hw_types.h"
64 // Driverlib headers
65 // - None needed
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 SetupAfterColdResetWakeupFromShutDownCfg1 NOROM_SetupAfterColdResetWakeupFromShutDownCfg1
82     #define SetupAfterColdResetWakeupFromShutDownCfg2 NOROM_SetupAfterColdResetWakeupFromShutDownCfg2
83     #define SetupAfterColdResetWakeupFromShutDownCfg3 NOROM_SetupAfterColdResetWakeupFromShutDownCfg3
84     #define SetupGetTrimForAdcShModeEn      NOROM_SetupGetTrimForAdcShModeEn
85     #define SetupGetTrimForAdcShVbufEn      NOROM_SetupGetTrimForAdcShVbufEn
86     #define SetupGetTrimForAmpcompCtrl      NOROM_SetupGetTrimForAmpcompCtrl
87     #define SetupGetTrimForAmpcompTh1       NOROM_SetupGetTrimForAmpcompTh1
88     #define SetupGetTrimForAmpcompTh2       NOROM_SetupGetTrimForAmpcompTh2
89     #define SetupGetTrimForAnabypassValue1  NOROM_SetupGetTrimForAnabypassValue1
90     #define SetupGetTrimForDblrLoopFilterResetVoltage NOROM_SetupGetTrimForDblrLoopFilterResetVoltage
91     #define SetupGetTrimForRadcExtCfg       NOROM_SetupGetTrimForRadcExtCfg
92     #define SetupGetTrimForRcOscLfIBiasTrim NOROM_SetupGetTrimForRcOscLfIBiasTrim
93     #define SetupGetTrimForRcOscLfRtuneCtuneTrim NOROM_SetupGetTrimForRcOscLfRtuneCtuneTrim
94     #define SetupGetTrimForXoscHfCtl        NOROM_SetupGetTrimForXoscHfCtl
95     #define SetupGetTrimForXoscHfFastStart  NOROM_SetupGetTrimForXoscHfFastStart
96     #define SetupGetTrimForXoscHfIbiastherm NOROM_SetupGetTrimForXoscHfIbiastherm
97     #define SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio NOROM_SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
98     #define SetupSetCacheModeAccordingToCcfgSetting NOROM_SetupSetCacheModeAccordingToCcfgSetting
99     #define SetupSetAonRtcSubSecInc         NOROM_SetupSetAonRtcSubSecInc
100     #define SetupStepVddrTrimTo             NOROM_SetupStepVddrTrimTo
101 #endif
102 
103 //*****************************************************************************
104 //
105 //! \brief First part of configuration required after cold reset and when waking up from shutdown.
106 //!
107 //! Configures the following based on settings in CCFG (Customer Configuration area:
108 //! - Boost mode for CC13xx devices
109 //! - Minimal VDDR voltage threshold used during sleep mode
110 //! - DCDC functionality:
111 //!   - Selects if DCDC or GLDO regulator will be used for VDDR in active mode
112 //!   - Selects if DCDC or GLDO regulator will be used for VDDR in sleep mode
113 //!
114 //! In addition the battery monitor low limit for internal regulator mode is set
115 //! to a hard coded value.
116 //!
117 //! \param ccfg_ModeConfReg is the value of the CCFG_O_MODE_CONF_1 register
118 //!
119 //! \return None
120 //
121 //*****************************************************************************
122 extern void SetupAfterColdResetWakeupFromShutDownCfg1( uint32_t ccfg_ModeConfReg );
123 
124 //*****************************************************************************
125 //
126 //! \brief Second part of configuration required after cold reset and when waking up from shutdown.
127 //!
128 //! Configures and trims functionalites required for use of XOSC_HF.
129 //! The configurations and trimmings are based on settings in FCFG1 (Factory
130 //! Configuration area) and partly on \c ccfg_ModeConfReg.
131 //!
132 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
133 //! \param ccfg_ModeConfReg is the value of the CCFG_O_MODE_CONF_1 register
134 //!
135 //! \return None
136 //
137 //*****************************************************************************
138 extern void SetupAfterColdResetWakeupFromShutDownCfg2( uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg );
139 
140 //*****************************************************************************
141 //
142 //! \brief Third part of configuration required after cold reset and when waking up from shutdown.
143 //!
144 //! Configures the following:
145 //! - XOSC source selection based on \c ccfg_ModeConfReg. If HPOSC is selected on a
146 //!   HPOSC device the oscillator is configured based on settings in FCFG1 (Factory
147 //!   Configuration area).
148 //! - Clock loss detection is disabled. Will be re-enabled by TIRTOS power driver.
149 //! - Duration of the XOSC_HF fast startup mode based on FCFG1 setting.
150 //! - SCLK_LF based on \c ccfg_ModeConfReg.
151 //! - Output voltage of ADC fixed reference based on FCFG1 setting.
152 //!
153 //! \param ccfg_ModeConfReg is the value of the CCFG_O_MODE_CONF_1 register
154 //!
155 //! \return None
156 //
157 //*****************************************************************************
158 extern void SetupAfterColdResetWakeupFromShutDownCfg3( uint32_t ccfg_ModeConfReg );
159 
160 //*****************************************************************************
161 //
162 //! \brief Returns the trim value from FCFG1 to be used as ADC_SH_MODE_EN setting.
163 //!
164 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
165 //!
166 //! \return Returns the trim value from FCFG1.
167 //
168 //*****************************************************************************
169 extern uint32_t SetupGetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision );
170 
171 //*****************************************************************************
172 //
173 //! \brief Returns the trim value from FCFG1 to be used as ADC_SH_VBUF_EN setting.
174 //!
175 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
176 //!
177 //! \return Returns the trim value from FCFG1.
178 //
179 //*****************************************************************************
180 extern uint32_t SetupGetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision );
181 
182 //*****************************************************************************
183 //
184 //! \brief Returns the trim value to be used for the AMPCOMP_CTRL register in OSC_DIG.
185 //!
186 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
187 //!
188 //! \return Returns the trim value.
189 //
190 //*****************************************************************************
191 extern uint32_t SetupGetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision );
192 
193 //*****************************************************************************
194 //
195 //! \brief Returns the trim value to be used for the AMPCOMP_TH1 register in OSC_DIG.
196 //!
197 //! \return Returns the trim value.
198 //
199 //*****************************************************************************
200 extern uint32_t SetupGetTrimForAmpcompTh1( void );
201 
202 //*****************************************************************************
203 //
204 //! \brief Returns the trim value to be used for the AMPCOMP_TH2 register in OSC_DIG.
205 //!
206 //! \return Returns the trim value.
207 //
208 //*****************************************************************************
209 extern uint32_t SetupGetTrimForAmpcompTh2( void );
210 
211 //*****************************************************************************
212 //
213 //! \brief Returns the trim value to be used for the ANABYPASS_VALUE1 register in OSC_DIG.
214 //!
215 //! \param ccfg_ModeConfReg is the value of the CCFG_O_MODE_CONF_1 register
216 //!
217 //! \return Returns the trim value.
218 //
219 //*****************************************************************************
220 extern uint32_t SetupGetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg );
221 
222 //*****************************************************************************
223 //
224 //! \brief Returns the trim value from FCFG1 to be used as DBLR_LOOP_FILTER_RESET_VOLTAGE setting.
225 //!
226 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
227 //!
228 //! \return Returns the trim value from FCFG1.
229 //
230 //*****************************************************************************
231 extern uint32_t SetupGetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision );
232 
233 //*****************************************************************************
234 //
235 //! \brief Returns the trim value to be used for the RADCEXTCFG register in OSC_DIG.
236 //!
237 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
238 //!
239 //! \return Returns the trim value.
240 //
241 //*****************************************************************************
242 extern uint32_t SetupGetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision );
243 
244 //*****************************************************************************
245 //
246 //! \brief Returns the FCFG1 OSC_CONF_ATESTLF_RCOSCLF_IBIAS_TRIM.
247 //!
248 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
249 //!
250 //! \return Returns the trim value from FCFG1.
251 //
252 //*****************************************************************************
253 extern uint32_t SetupGetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision );
254 
255 //*****************************************************************************
256 //
257 //! \brief Returns the trim value to be used for the RCOSCLF_RTUNE_TRIM and the
258 //! RCOSCLF_CTUNE_TRIM bit fields in the XOSCLF_RCOSCLF_CTRL register in OSC_DIG.
259 //!
260 //! \return Returns the trim value.
261 //
262 //*****************************************************************************
263 extern uint32_t SetupGetTrimForRcOscLfRtuneCtuneTrim( void );
264 
265 //*****************************************************************************
266 //
267 //! \brief Returns the trim value to be used for the XOSCHFCTL register in OSC_DIG.
268 //!
269 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
270 //!
271 //! \return Returns the trim value.
272 //
273 //*****************************************************************************
274 extern uint32_t SetupGetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision );
275 
276 //*****************************************************************************
277 //
278 //! \brief Returns the trim value to be used as OSC_DIG:CTL1.XOSC_HF_FAST_START.
279 //!
280 //! \return Returns the trim value.
281 //
282 //*****************************************************************************
283 extern uint32_t SetupGetTrimForXoscHfFastStart( void );
284 
285 //*****************************************************************************
286 //
287 //! \brief Returns the trim value to be used for the XOSC_HF_IBIASTHERM bit field in
288 //! the ANABYPASS_VALUE2 register in OSC_DIG.
289 //!
290 //! \return Returns the trim value.
291 //
292 //*****************************************************************************
293 extern uint32_t SetupGetTrimForXoscHfIbiastherm( void );
294 
295 //*****************************************************************************
296 //
297 //! \brief Returns XOSCLF_REGULATOR_TRIM and XOSCLF_CMIRRWR_RATIO as one packet
298 //! spanning bits [5:0] in the returned value.
299 //!
300 //! \param ui32Fcfg1Revision is the value of the FCFG1_O_FCFG1_REVISION register
301 //!
302 //! \return Returns XOSCLF_REGULATOR_TRIM and XOSCLF_CMIRRWR_RATIO as one packet.
303 //
304 //*****************************************************************************
305 extern uint32_t SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio( uint32_t ui32Fcfg1Revision );
306 
307 //*****************************************************************************
308 //
309 //! \brief Sign extend the VDDR_TRIM setting (special format ranging from -10 to +21)
310 //!
311 //! \param ui32VddrTrimVal
312 //!
313 //! \return Returns Sign extended VDDR_TRIM setting.
314 //
315 //*****************************************************************************
316 __STATIC_INLINE int32_t
SetupSignExtendVddrTrimValue(uint32_t ui32VddrTrimVal)317 SetupSignExtendVddrTrimValue( uint32_t ui32VddrTrimVal )
318 {
319     // The VDDR trim value is 5 bits representing the range from -10 to +21
320     // (where -10=0x16, -1=0x1F, 0=0x00, 1=0x01 and +21=0x15)
321     int32_t i32SignedVddrVal = ui32VddrTrimVal;
322     if ( i32SignedVddrVal > 0x15 ) {
323         i32SignedVddrVal -= 0x20;
324     }
325     return ( i32SignedVddrVal );
326 }
327 
328 //*****************************************************************************
329 //
330 //! \brief Set correct VIMS_MODE according to CCFG setting (CACHE or GPRAM)
331 //!
332 //! \return None
333 //
334 //*****************************************************************************
335 extern void SetupSetCacheModeAccordingToCcfgSetting( void );
336 
337 //*****************************************************************************
338 //
339 //! \brief Doing the tricky stuff needed to enter new RTCSUBSECINC value
340 //!
341 //! \param subSecInc
342 //!
343 //! \return None
344 //
345 //*****************************************************************************
346 extern void SetupSetAonRtcSubSecInc( uint32_t subSecInc );
347 
348 //*****************************************************************************
349 //
350 //! \brief Set VDDR boost mode (by setting VDDR_TRIM to FCFG1..VDDR_TRIM_HH and
351 //! setting VDDS_BOD to max)
352 //!
353 //! \param toCode specifies the target VDDR trim value.
354 //!        The input parameter \c toCode can be either the signed extended
355 //!        trim value or holding the trim code bits only.
356 //!
357 //! \return None
358 //
359 //*****************************************************************************
360 extern void SetupStepVddrTrimTo( uint32_t toCode );
361 
362 //*****************************************************************************
363 //
364 // Support for DriverLib in ROM:
365 // Redirect to implementation in ROM when available.
366 //
367 //*****************************************************************************
368 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
369     #include "../driverlib/rom.h"
370     #ifdef ROM_SetupAfterColdResetWakeupFromShutDownCfg1
371         #undef  SetupAfterColdResetWakeupFromShutDownCfg1
372         #define SetupAfterColdResetWakeupFromShutDownCfg1 ROM_SetupAfterColdResetWakeupFromShutDownCfg1
373     #endif
374     #ifdef ROM_SetupAfterColdResetWakeupFromShutDownCfg2
375         #undef  SetupAfterColdResetWakeupFromShutDownCfg2
376         #define SetupAfterColdResetWakeupFromShutDownCfg2 ROM_SetupAfterColdResetWakeupFromShutDownCfg2
377     #endif
378     #ifdef ROM_SetupAfterColdResetWakeupFromShutDownCfg3
379         #undef  SetupAfterColdResetWakeupFromShutDownCfg3
380         #define SetupAfterColdResetWakeupFromShutDownCfg3 ROM_SetupAfterColdResetWakeupFromShutDownCfg3
381     #endif
382     #ifdef ROM_SetupGetTrimForAdcShModeEn
383         #undef  SetupGetTrimForAdcShModeEn
384         #define SetupGetTrimForAdcShModeEn      ROM_SetupGetTrimForAdcShModeEn
385     #endif
386     #ifdef ROM_SetupGetTrimForAdcShVbufEn
387         #undef  SetupGetTrimForAdcShVbufEn
388         #define SetupGetTrimForAdcShVbufEn      ROM_SetupGetTrimForAdcShVbufEn
389     #endif
390     #ifdef ROM_SetupGetTrimForAmpcompCtrl
391         #undef  SetupGetTrimForAmpcompCtrl
392         #define SetupGetTrimForAmpcompCtrl      ROM_SetupGetTrimForAmpcompCtrl
393     #endif
394     #ifdef ROM_SetupGetTrimForAmpcompTh1
395         #undef  SetupGetTrimForAmpcompTh1
396         #define SetupGetTrimForAmpcompTh1       ROM_SetupGetTrimForAmpcompTh1
397     #endif
398     #ifdef ROM_SetupGetTrimForAmpcompTh2
399         #undef  SetupGetTrimForAmpcompTh2
400         #define SetupGetTrimForAmpcompTh2       ROM_SetupGetTrimForAmpcompTh2
401     #endif
402     #ifdef ROM_SetupGetTrimForAnabypassValue1
403         #undef  SetupGetTrimForAnabypassValue1
404         #define SetupGetTrimForAnabypassValue1  ROM_SetupGetTrimForAnabypassValue1
405     #endif
406     #ifdef ROM_SetupGetTrimForDblrLoopFilterResetVoltage
407         #undef  SetupGetTrimForDblrLoopFilterResetVoltage
408         #define SetupGetTrimForDblrLoopFilterResetVoltage ROM_SetupGetTrimForDblrLoopFilterResetVoltage
409     #endif
410     #ifdef ROM_SetupGetTrimForRadcExtCfg
411         #undef  SetupGetTrimForRadcExtCfg
412         #define SetupGetTrimForRadcExtCfg       ROM_SetupGetTrimForRadcExtCfg
413     #endif
414     #ifdef ROM_SetupGetTrimForRcOscLfIBiasTrim
415         #undef  SetupGetTrimForRcOscLfIBiasTrim
416         #define SetupGetTrimForRcOscLfIBiasTrim ROM_SetupGetTrimForRcOscLfIBiasTrim
417     #endif
418     #ifdef ROM_SetupGetTrimForRcOscLfRtuneCtuneTrim
419         #undef  SetupGetTrimForRcOscLfRtuneCtuneTrim
420         #define SetupGetTrimForRcOscLfRtuneCtuneTrim ROM_SetupGetTrimForRcOscLfRtuneCtuneTrim
421     #endif
422     #ifdef ROM_SetupGetTrimForXoscHfCtl
423         #undef  SetupGetTrimForXoscHfCtl
424         #define SetupGetTrimForXoscHfCtl        ROM_SetupGetTrimForXoscHfCtl
425     #endif
426     #ifdef ROM_SetupGetTrimForXoscHfFastStart
427         #undef  SetupGetTrimForXoscHfFastStart
428         #define SetupGetTrimForXoscHfFastStart  ROM_SetupGetTrimForXoscHfFastStart
429     #endif
430     #ifdef ROM_SetupGetTrimForXoscHfIbiastherm
431         #undef  SetupGetTrimForXoscHfIbiastherm
432         #define SetupGetTrimForXoscHfIbiastherm ROM_SetupGetTrimForXoscHfIbiastherm
433     #endif
434     #ifdef ROM_SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
435         #undef  SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
436         #define SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio ROM_SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
437     #endif
438     #ifdef ROM_SetupSetCacheModeAccordingToCcfgSetting
439         #undef  SetupSetCacheModeAccordingToCcfgSetting
440         #define SetupSetCacheModeAccordingToCcfgSetting ROM_SetupSetCacheModeAccordingToCcfgSetting
441     #endif
442     #ifdef ROM_SetupSetAonRtcSubSecInc
443         #undef  SetupSetAonRtcSubSecInc
444         #define SetupSetAonRtcSubSecInc         ROM_SetupSetAonRtcSubSecInc
445     #endif
446     #ifdef ROM_SetupStepVddrTrimTo
447         #undef  SetupStepVddrTrimTo
448         #define SetupStepVddrTrimTo             ROM_SetupStepVddrTrimTo
449     #endif
450 #endif
451 
452 //*****************************************************************************
453 //
454 // Mark the end of the C bindings section for C++ compilers.
455 //
456 //*****************************************************************************
457 #ifdef __cplusplus
458 }
459 #endif
460 
461 #endif //  __SETUP_ROM_H__
462 
463 //*****************************************************************************
464 //
465 //! Close the Doxygen group.
466 //! @}
467 //! @}
468 //
469 //*****************************************************************************
470