CC13xx Driver Library
setup.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: setup.c
3 * Revised: 2016-06-03 14:23:26 +0200 (Fri, 03 Jun 2016)
4 * Revision: 46593
5 *
6 * Description: Setup file for CC13xx/CC26xx devices.
7 *
8 * Copyright (c) 2015 - 2016, 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 // Hardware headers
40 #include <inc/hw_types.h>
41 #include <driverlib/setup.h>
42 // ##### INCLUDE IN ROM BEGIN #####
43 // We need intrinsic functions for IAR (if used in source code)
44 #ifdef __IAR_SYSTEMS_ICC__
45 #include <intrinsics.h>
46 #endif
47 // ##### INCLUDE IN ROM END #####
48 
49 //*****************************************************************************
50 //
51 // Handle support for DriverLib in ROM:
52 // This section will undo prototype renaming made in the header file
53 //
54 //*****************************************************************************
55 #if !defined(DOXYGEN)
56  #undef SetupTrimDevice
57  #define SetupTrimDevice NOROM_SetupTrimDevice
58  #undef SetupAfterColdResetWakeupFromShutDownCfg1
59  #define SetupAfterColdResetWakeupFromShutDownCfg1 NOROM_SetupAfterColdResetWakeupFromShutDownCfg1
60  #undef SetupAfterColdResetWakeupFromShutDownCfg2
61  #define SetupAfterColdResetWakeupFromShutDownCfg2 NOROM_SetupAfterColdResetWakeupFromShutDownCfg2
62  #undef SetupAfterColdResetWakeupFromShutDownCfg3
63  #define SetupAfterColdResetWakeupFromShutDownCfg3 NOROM_SetupAfterColdResetWakeupFromShutDownCfg3
64  #undef SetupGetTrimForAdcShModeEn
65  #define SetupGetTrimForAdcShModeEn NOROM_SetupGetTrimForAdcShModeEn
66  #undef SetupGetTrimForAdcShVbufEn
67  #define SetupGetTrimForAdcShVbufEn NOROM_SetupGetTrimForAdcShVbufEn
68  #undef SetupGetTrimForAmpcompCtrl
69  #define SetupGetTrimForAmpcompCtrl NOROM_SetupGetTrimForAmpcompCtrl
70  #undef SetupGetTrimForAmpcompTh1
71  #define SetupGetTrimForAmpcompTh1 NOROM_SetupGetTrimForAmpcompTh1
72  #undef SetupGetTrimForAmpcompTh2
73  #define SetupGetTrimForAmpcompTh2 NOROM_SetupGetTrimForAmpcompTh2
74  #undef SetupGetTrimForAnabypassValue1
75  #define SetupGetTrimForAnabypassValue1 NOROM_SetupGetTrimForAnabypassValue1
76  #undef SetupGetTrimForDblrLoopFilterResetVoltage
77  #define SetupGetTrimForDblrLoopFilterResetVoltage NOROM_SetupGetTrimForDblrLoopFilterResetVoltage
78  #undef SetupGetTrimForRadcExtCfg
79  #define SetupGetTrimForRadcExtCfg NOROM_SetupGetTrimForRadcExtCfg
80  #undef SetupGetTrimForRcOscLfIBiasTrim
81  #define SetupGetTrimForRcOscLfIBiasTrim NOROM_SetupGetTrimForRcOscLfIBiasTrim
82  #undef SetupGetTrimForRcOscLfRtuneCtuneTrim
83  #define SetupGetTrimForRcOscLfRtuneCtuneTrim NOROM_SetupGetTrimForRcOscLfRtuneCtuneTrim
84  #undef SetupGetTrimForXoscHfCtl
85  #define SetupGetTrimForXoscHfCtl NOROM_SetupGetTrimForXoscHfCtl
86  #undef SetupGetTrimForXoscHfFastStart
87  #define SetupGetTrimForXoscHfFastStart NOROM_SetupGetTrimForXoscHfFastStart
88  #undef SetupGetTrimForXoscHfIbiastherm
89  #define SetupGetTrimForXoscHfIbiastherm NOROM_SetupGetTrimForXoscHfIbiastherm
90  #undef SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
91  #define SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio NOROM_SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
92  #undef SetupSignExtendVddrTrimValue
93  #define SetupSignExtendVddrTrimValue NOROM_SetupSignExtendVddrTrimValue
94  #undef SetupSetCacheModeAccordingToCcfgSetting
95  #define SetupSetCacheModeAccordingToCcfgSetting NOROM_SetupSetCacheModeAccordingToCcfgSetting
96  #undef SetupSetAonRtcSubSecInc
97  #define SetupSetAonRtcSubSecInc NOROM_SetupSetAonRtcSubSecInc
98  #undef SetupSetVddrLevel
99  #define SetupSetVddrLevel NOROM_SetupSetVddrLevel
100 #endif
101 
102 
103 
104 //*****************************************************************************
105 //
107 //
108 //*****************************************************************************
109 #define DELAY_20_USEC 0x140
110 
111 
112 //*****************************************************************************
113 //
114 // Defined CPU delay macro with microseconds as input
115 // Quick check shows: (To be further investigated)
116 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 5 cycles
117 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 1, there is 4 cycles
118 // At 24 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 3 cycles
119 //
120 //*****************************************************************************
121 #define CPU_DELAY_MICRO_SECONDS( x ) \
122  CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )
123 
124 
125 //*****************************************************************************
126 //
127 // Function declarations
128 //
129 //*****************************************************************************
130 static void TrimAfterColdReset( void );
131 static void TrimAfterColdResetWakeupFromShutDown( uint32_t ui32Fcfg1Revision );
133 
134 //*****************************************************************************
135 //
136 // Perform the necessary trim of the device which is not done in boot code
137 //
138 // This function should only execute coming from ROM boot. The current
139 // implementation does not take soft reset into account. However, it does no
140 // damage to execute it again. It only consumes time.
141 //
142 //*****************************************************************************
143 void
145 {
146  uint32_t ui32Fcfg1Revision;
147  uint32_t ui32AonSysResetctl;
148 
149  //
150  // Get layout revision of the factory configuration area
151  // (Handle undefined revision as revision = 0)
152  //
153  ui32Fcfg1Revision = HWREG(FCFG1_BASE + FCFG1_O_FCFG1_REVISION);
154  if ( ui32Fcfg1Revision == 0xFFFFFFFF ) {
155  ui32Fcfg1Revision = 0;
156  }
157 
158  //
159  // This driverlib version and setup file is for CC13xx PG2.0 and later.
160  // Halt if violated
161  //
163 
164  //
165  // Enable standby in flash bank
166  //
168 
169  //
170  // Clock must always be enabled for the semaphore module (due to ADI/DDI HW workaround)
171  //
173 
174  //
175  // Warm resets on CC26XX complicates software design as much of our software
176  // expect that initialization is done from a full system reset.
177  // This includes RTC setup, oscillator configuration and AUX setup.
178  // To ensure a full reset of the device is done when customers get e.g. a Watchdog
179  // reset, the following is set here:
180  //
182 
183  //
184  // Select correct CACHE mode and set correct CACHE configuration
185  //
187 
188  // 1. Check for powerdown
189  // 2. Check for shutdown
190  // 3. Assume cold reset if none of the above.
191  //
192  // It is always assumed that the application will freeze the latches in
193  // AON_IOC when going to powerdown in order to retain the values on the IOs.
194  //
195  // NB. If this bit is not cleared before proceeding to powerdown, the IOs
196  // will all default to the reset configuration when restarting.
198  {
199  //
200  // NB. This should be calling a ROM implementation of required trim and
201  // compensation
202  // e.g. TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
204  }
205  // Check for shutdown
206  //
207  // When device is going to shutdown the hardware will automatically clear
208  // the SLEEPDIS bit in the SLEEP register in the AON_SYSCTRL12 module.
209  // It is left for the application to assert this bit when waking back up,
210  // but not before the desired IO configuration has been re-established.
212  {
213  //
214  // NB. This should be calling a ROM implementation of required trim and
215  // compensation
216  // e.g. TrimAfterColdResetWakeupFromShutDown() -->
217  // TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
218  TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
220  }
221  else
222  {
223  // Consider adding a check for soft reset to allow debugging to skip
224  // this section!!!
225  //
226  // NB. This should be calling a ROM implementation of required trim and
227  // compensation
228  // e.g. TrimAfterColdReset() -->
229  // TrimAfterColdResetWakeupFromShutDown() -->
230  // TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
232  TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
234 
235  }
236 
237  //
238  // Set VIMS power domain control.
239  // PDCTL1VIMS = 0 ==> VIMS power domain is only powered when CPU power domain is powered
240  //
241  HWREG( PRCM_BASE + PRCM_O_PDCTL1VIMS ) = 0;
242 
243  //
244  // Configure optimal wait time for flash FSM in cases where flash pump
245  // wakes up from sleep
246  //
247  HWREG(FLASH_BASE + FLASH_O_FPAC1) = (HWREG(FLASH_BASE + FLASH_O_FPAC1) &
249  (0x139<<FLASH_FPAC1_PSLEEPTDIS_S);
250 
251  //
252  // And finally at the end of the flash boot process:
253  // SET BOOT_DET bits in AON_SYSCTL to 3 if already found to be 1
254  // Note: The BOOT_DET_x_CLR/SET bits must be manually cleared
255  //
256  if ((( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
259  {
260  ui32AonSysResetctl = ( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
264  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl;
265  }
266 
267  //
268  // Make sure there are no ongoing VIMS mode change when leaving SetupTrimDevice()
269  // (There should typically be no wait time here, but need to be sure)
270  //
271  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
272  // Do nothing - wait for an eventual ongoing mode change to complete.
273  }
274 }
275 
276 //*****************************************************************************
277 //
282 //
283 //*****************************************************************************
284 static void
286 {
287  //
288  // Currently no specific trim for Powerdown
289  //
290 }
291 
292 //*****************************************************************************
293 //
298 //
299 //*****************************************************************************
300 static void
301 TrimAfterColdResetWakeupFromShutDown(uint32_t ui32Fcfg1Revision)
302 {
303  uint32_t ccfg_ModeConfReg ;
304  uint32_t mp1rev ;
305 
306  //
307  // Force AUX on and enable clocks
308  //
309  // No need to save the current status of the power/clock registers.
310  // At this point both AUX and AON should have been reset to 0x0.
311  //
313 
314  //
315  // Wait for power on on the AUX domain
316  //
318 
319  //
320  // Enable the clocks for AUX_DDI0_OSC and AUX_ADI4
321  //
324 
325  //
326  // Check in CCFG for alternative DCDC setting
327  //
329  //
330  // ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
331  // ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
332  // Using a single 4-bit masked write since layout is equal for both source and destination
333  //
334  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
336 
337  }
338 
339  //
340  // Enable for JTAG to be powered down (will still be powered on if debugger is connected)
341  //
343 
344  //
345  // read the MODE_CONF register in CCFG
346  //
347  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
348 
349  //
350  // First part of trim done after cold reset and wakeup from shutdown:
351  // -Configure cc13xx boost mode.
352  // -Adjust the VDDR_TRIM_SLEEP value.
353  // -Configure DCDC.
354  //
355  SetupAfterColdResetWakeupFromShutDownCfg1( ccfg_ModeConfReg );
356 
357  //
358  // Second part of trim done after cold reset and wakeup from shutdown:
359  // -Configure XOSC.
360  //
361  SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
362 
363  //
364  // Increased margin between digital supply voltage and VDD BOD during standby.
365  // VTRIM_UDIG: signed 4 bits value to be incremented by 2 (max = 7)
366  // VTRIM_BOD: unsigned 4 bits value to be decremented by 1 (min = 0)
367  // This applies to chips with mp1rev < 542 for cc13xx and for mp1rev < 527 for cc26xx
368  //
369  mp1rev = ( HWREG( FCFG1_BASE + 0x00000314 ) & 0x0000FFFF );
370  if ( mp1rev < 542 ) {
371  uint32_t vtrim_bod = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 24 ) & 0xF ); // bit[27:24] unsigned
372  uint32_t vtrim_udig = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 16 ) & 0xF ); // bit[19:16] signed
373  if ( vtrim_bod > 0 ) {
374  vtrim_bod -= 1;
375  }
376  if ( vtrim_udig != 7 ) {
377  if ( vtrim_udig == 6 ) {
378  vtrim_udig = 7;
379  } else {
380  vtrim_udig = (( vtrim_udig + 2 ) & 0xF );
381  }
382  }
384  ( vtrim_udig << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_UDIG_S ) |
385  ( vtrim_bod << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_BOD_S ) ;
386  }
387 
388  //
389  // Third part of trim done after cold reset and wakeup from shutdown:
390  // -Configure HPOSC.
391  // -Setup the LF clock.
392  //
393  SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
394 
395  //
396  // Allow AUX to power down
397  //
399 
400  //
401  // Leaving on AUX and clock for AUX_DDI0_OSC on but turn off clock for AUX_ADI4
402  //
404 
405  // Disable EFUSE clock
407 }
408 
409 
410 //*****************************************************************************
411 //
415 //
416 //*****************************************************************************
417 static void
419 {
420  //
421  // Currently no specific trim for Cold Reset
422  //
423 }
424 
425 //*****************************************************************************
426 //
428 //
429 //*****************************************************************************
430 void
431 SetupAfterColdResetWakeupFromShutDownCfg1( uint32_t ccfg_ModeConfReg )
432 {
433  int32_t i32VddrSleepTrim;
434  int32_t i32VddrSleepDelta;
435 
436  //
437  // Check for CC13xx boost mode
438  // The combination VDDR_EXT_LOAD=0 and VDDS_BOD_LEVEL=1 is defined to selct boost mode
439  //
440  if ((( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_EXT_LOAD ) == 0 ) &&
441  (( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) != 0 ) ) {
442  //
443  // Set VDDS_BOD trim - using masked write {MASK8:DATA8}
444  // - TRIM_VDDS_BOD is bits[7:3] of ADI3..REFSYSCTL1
445  // - Needs a positive transition on BOD_BG_TRIM_EN (bit[7] of REFSYSCTL3) to
446  // latch new VDDS BOD. Set to 0 first to guarantee a positive transition.
447  //
449 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
450  //
451  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
452  // - Max out the VDDS_BOD trim (=VDDS_BOD_POS_31)
453  //
454  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
457 // } else {
458 // //
459 // // VDDS_BOD_LEVEL = 0
460 // // - Set VDDS_BOD to FCFG1..TRIMBOD_H
461 // //
462 // HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
464 // ((( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
467 // }
469 
470  SetupSetVddrLevel( ccfg_ModeConfReg );
471 
472  i32VddrSleepTrim = SetupSignExtendVddrTrimValue((
473  HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
476  } else
477  {
478  i32VddrSleepTrim = SetupSignExtendVddrTrimValue((
479  HWREG( FCFG1_BASE + FCFG1_O_LDO_TRIM ) &
482  }
483 
484  //
485  // Adjust the VDDR_TRIM_SLEEP value with value adjustable by customer (CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA)
486  // Read and sign extend VddrSleepDelta (in range -8 to +7)
487  //
488  i32VddrSleepDelta = ((((int32_t)ccfg_ModeConfReg )
489  << ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_S ))
490  >> ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W ));
491  // Calculate new VDDR sleep trim
492  i32VddrSleepTrim = ( i32VddrSleepTrim + i32VddrSleepDelta + 1 );
493  if ( i32VddrSleepTrim > 21 ) i32VddrSleepTrim = 21;
494  if ( i32VddrSleepTrim < -10 ) i32VddrSleepTrim = -10;
495  // Write adjusted value using MASKED write (MASK8)
496  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL1 * 2 )) = (( ADI_3_REFSYS_DCDCCTL1_VDDR_TRIM_SLEEP_M << 8 ) |
498 
499  //
500  // 1.
501  // Do not allow DCDC to be enabled if in external regulator mode.
502  // Preventing this by setting both the RECHARGE and the ACTIVE bits bit in the CCFG_MODE_CONF copy register (ccfg_ModeConfReg).
503  //
504  // 2.
505  // Adjusted battery monitor low limit in internal regulator mode.
506  // This is done by setting AON_BATMON_FLASHPUMPP0_LOWLIM=0 in internal regulator mode.
507  //
510  } else {
512  }
513 
514  //
515  // set the RECHARGE source based upon CCFG:MODE_CONF:DCDC_RECHARGE
516  // Note: Inverse polarity
517  //
519  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_RECHARGE_S ) & 1 ) ^ 1 );
520 
521  //
522  // set the ACTIVE source based upon CCFG:MODE_CONF:DCDC_ACTIVE
523  // Note: Inverse polarity
524  //
526  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_ACTIVE_S ) & 1 ) ^ 1 );
527 }
528 
529 //*****************************************************************************
530 //
532 //
533 //*****************************************************************************
534 void
535 SetupAfterColdResetWakeupFromShutDownCfg2( uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg )
536 {
537  uint32_t ui32Trim;
538 
539  //
540  // Following sequence is required for using XOSCHF, if not included
541  // devices crashes when trying to switch to XOSCHF.
542  //
543  // Trim CAP settings. Get and set trim value for the ANABYPASS_VALUE1
544  // register
545  ui32Trim = SetupGetTrimForAnabypassValue1( ccfg_ModeConfReg );
547 
548  // Trim RCOSC_LF. Get and set trim values for the RCOSCLF_RTUNE_TRIM and
549  // RCOSCLF_CTUNE_TRIM fields in the XOSCLF_RCOSCLF_CTRL register.
555  ui32Trim);
556 
557  // Trim XOSCHF IBIAS THERM. Get and set trim value for the
558  // XOSCHF IBIAS THERM bit field in the ANABYPASS_VALUE2 register. Other
559  // register bit fields are set to 0.
560  ui32Trim = SetupGetTrimForXoscHfIbiastherm();
563 
564  // Trim AMPCOMP settings required before switch to XOSCHF
565  ui32Trim = SetupGetTrimForAmpcompTh2();
567  ui32Trim = SetupGetTrimForAmpcompTh1();
569  ui32Trim = SetupGetTrimForAmpcompCtrl( ui32Fcfg1Revision );
571 
572  //
573  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_MODE_EN in accordance to FCFG1 setting
574  // This is bit[5] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
575  // Using MASK4 write + 1 => writing to bits[7:4]
576  //
577  ui32Trim = SetupGetTrimForAdcShModeEn( ui32Fcfg1Revision );
578  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
579  ( 0x20 | ( ui32Trim << 1 ));
580 
581  //
582  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_VBUF_EN in accordance to FCFG1 setting
583  // This is bit[4] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
584  // Using MASK4 write + 1 => writing to bits[7:4]
585  //
586  ui32Trim = SetupGetTrimForAdcShVbufEn( ui32Fcfg1Revision );
587  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
588  ( 0x10 | ( ui32Trim ));
589 
590  //
591  // Set trim for the PEAK_DET_ITRIM, HP_BUF_ITRIM and LP_BUF_ITRIM bit fields
592  // in the DDI0_OSC_O_XOSCHFCTL register in accordance to FCFG1 setting.
593  // Remaining register bit fields are set to their reset values of 0.
594  //
595  ui32Trim = SetupGetTrimForXoscHfCtl(ui32Fcfg1Revision);
597 
598  //
599  // Set trim for DBLR_LOOP_FILTER_RESET_VOLTAGE in accordance to FCFG1 setting
600  // (This is bits [18:17] in DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL)
601  // (Using MASK4 write + 4 => writing to bits[19:16] => (4*4))
602  // (Assuming: DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_S = 17 and
603  // that DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_M = 0x00060000)
604  //
605  ui32Trim = SetupGetTrimForDblrLoopFilterResetVoltage( ui32Fcfg1Revision );
606  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 4 ) =
607  ( 0x60 | ( ui32Trim << 1 ));
608 
609  //
610  // Update DDI_0_OSC_ATESTCTL_ATESTLF_RCOSCLF_IBIAS_TRIM with data from
612  // This is DDI_0_OSC_O_ATESTCTL bit[7]
613  // ( DDI_0_OSC_O_ATESTCTL is currently hidden (but=0x00000020))
614  // Using MASK4 write + 1 => writing to bits[7:4]
615  //
616  ui32Trim = SetupGetTrimForRcOscLfIBiasTrim( ui32Fcfg1Revision );
617  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( 0x00000020 * 2 ) + 1 ) =
618  ( 0x80 | ( ui32Trim << 3 ));
619 
620  //
623  // This can be simplified since the registers are packed together in the same
624  // order both in FCFG1 and in the HW register.
625  // This spans DDI_0_OSC_O_LFOSCCTL bits[23:18]
626  // Using MASK8 write + 4 => writing to bits[23:16]
627  //
628  ui32Trim = SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio( ui32Fcfg1Revision );
629  HWREGH( AUX_DDI0_OSC_BASE + DDI_O_MASK8B + ( DDI_0_OSC_O_LFOSCCTL * 2 ) + 4 ) =
630  ( 0xFC00 | ( ui32Trim << 2 ));
631 
632  //
633  // Set trim the HPM_IBIAS_WAIT_CNT, LPM_IBIAS_WAIT_CNT and IDAC_STEP bit
634  // fields in the DDI0_OSC_O_RADCEXTCFG register in accordance to FCFG1 setting.
635  // Remaining register bit fields are set to their reset values of 0.
636  //
637  ui32Trim = SetupGetTrimForRadcExtCfg(ui32Fcfg1Revision);
639 
640  // Setting FORCE_KICKSTART_EN (ref. CC26_V1_BUG00261). Should also be done for PG2
641  // (This is bit 22 in DDI_0_OSC_O_CTL0)
643 }
644 
645 //*****************************************************************************
646 //
648 //
649 //*****************************************************************************
650 void
651 SetupAfterColdResetWakeupFromShutDownCfg3( uint32_t ccfg_ModeConfReg )
652 {
653  uint32_t fcfg1OscConf;
654  uint32_t ui32Trim;
655  uint32_t currentHfClock;
656  uint32_t ccfgExtLfClk;
657 
658  //
659  // Examin the XOSC_FREQ field to select 0x1=HPOSC, 0x2=48MHz XOSC, 0x3=24MHz XOSC
660  //
661  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_FREQ_M ) >> CCFG_MODE_CONF_XOSC_FREQ_S ) {
662  case 2 :
663  // XOSC source is a 48 MHz xtal
664  // Do nothing (since this is the reset setting)
665  break;
666  case 1 :
667  // XOSC source is HPOSC (trim the HPOSC if this is a chip with HPOSC, otherwise skip trimming and default to 24 MHz XOSC)
668 
669  fcfg1OscConf = HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF );
670 
671  if (( fcfg1OscConf & FCFG1_OSC_CONF_HPOSC_OPTION ) == 0 ) {
672  // This is a HPOSC chip, apply HPOSC settings
673  // Set bit DDI_0_OSC_CTL0_HPOSC_MODE_EN (this is bit 14 in DDI_0_OSC_O_CTL0)
675 
683 
696  break;
697  }
698  // Not a HPOSC chip - fall through to default
699  default :
700  // XOSC source is a 24 MHz xtal (default)
701  // Set bit DDI_0_OSC_CTL0_XTAL_IS_24M (this is bit 31 in DDI_0_OSC_O_CTL0)
703  break;
704  }
705 
706  //
707  // Set XOSC_HF in bypass mode if CCFG is configured for external TCXO
708  // Please note that it is up to the custommer to make sure that the external clock source is up and running before XOSC_HF can be used.
709  //
712  }
713 
714  // Clear DDI_0_OSC_CTL0_CLK_LOSS_EN (ClockLossEventEnable()). This is bit 9 in DDI_0_OSC_O_CTL0.
715  // This is typically already 0 except on Lizard where it is set in ROM-boot
717 
718  // Setting DDI_0_OSC_CTL1_XOSC_HF_FAST_START according to value found in FCFG1
719  ui32Trim = SetupGetTrimForXoscHfFastStart();
720  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_CTL1 * 2 )) = ( 0x30 | ui32Trim );
721 
722  //
723  // setup the LF clock based upon CCFG:MODE_CONF:SCLK_LF_OPTION
724  //
725  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_SCLK_LF_OPTION_M ) >> CCFG_MODE_CONF_SCLK_LF_OPTION_S ) {
726  case 0 : // XOSC_HF_DLF (XOSCHF/1536) -> SCLK_LF (=31250Hz)
728  SetupSetAonRtcSubSecInc( 0x8637BD );
729  break;
730  case 1 : // EXTERNAL signal -> SCLK_LF (frequency=2^38/CCFG_EXT_LF_CLK_RTC_INCREMENT)
731  // Set SCLK_LF to use the same source as SCLK_HF
732  // Can be simplified a bit since possible return values for HF matches LF settings
733  currentHfClock = OSCClockSourceGet( OSC_SRC_CLK_HF );
734  OSCClockSourceSet( OSC_SRC_CLK_LF, currentHfClock );
735  while( OSCClockSourceGet( OSC_SRC_CLK_LF ) != currentHfClock ) {
736  // Wait until switched
737  }
738  ccfgExtLfClk = HWREG( CCFG_BASE + CCFG_O_EXT_LF_CLK );
742  IOC_STD_INPUT | IOC_HYST_ENABLE ); // Route external clock to AON IOC w/hysteresis
743  // Set XOSC_LF in bypass mode to allow external 32k clock
745  // Fall through to set XOSC_LF as SCLK_LF source
746  case 2 : // XOSC_LF -> SLCK_LF (32768 Hz)
748  break;
749  default : // (=3) RCOSC_LF
751  break;
752  }
753 
754  //
755  // Update ADI_4_AUX_ADCREF1_VTRIM with value from FCFG1
756  //
757  HWREGB( AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF1 ) =
762 
763  //
764  // Set ADI_4_AUX:ADC0.SMPL_CYCLE_EXP to it's default minimum value (=3)
765  // (Note: Using MASK8B requires that the bits to be modified must be within the same
766  // byte boundary which is the case for the ADI_4_AUX_ADC0_SMPL_CYCLE_EXP field)
767  //
768  HWREGH( AUX_ADI4_BASE + ADI_O_MASK8B + ( ADI_4_AUX_O_ADC0 * 2 )) =
770 
771  //
772  // Sync with AON
773  //
774  SysCtrlAonSync();
775 }
776 
777 //*****************************************************************************
778 //
780 //
781 //*****************************************************************************
782 uint32_t
783 SetupGetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg )
784 {
785  uint32_t ui32Fcfg1Value ;
786  uint32_t ui32XoscHfRow ;
787  uint32_t ui32XoscHfCol ;
788  int32_t i32CustomerDeltaAdjust ;
789  uint32_t ui32TrimValue ;
790 
791  // Use device specific trim values located in factory configuration
792  // area for the XOSC_HF_COLUMN_Q12 and XOSC_HF_ROW_Q12 bit fields in
793  // the ANABYPASS_VALUE1 register. Value for the other bit fields
794  // are set to 0.
795 
796  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP);
797  ui32XoscHfRow = (( ui32Fcfg1Value &
800  ui32XoscHfCol = (( ui32Fcfg1Value &
803 
804  i32CustomerDeltaAdjust = 0;
805  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_CAP_MOD ) == 0 ) {
806  // XOSC_CAP_MOD = 0 means: CAP_ARRAY_DELTA is in use -> Apply compensation
807  // XOSC_CAPARRAY_DELTA is located in bit[15:8] of ccfg_ModeConfReg
808  // Note: HW_REV_DEPENDENT_IMPLEMENTATION. Field width is not given by
809  // a define and sign extension must therefore be hardcoded.
810  // ( A small test program is created verifying the code lines below:
811  // Ref.: ..\test\small_standalone_test_programs\CapArrayDeltaAdjust_test.c)
812  i32CustomerDeltaAdjust = ((int32_t)ccfg_ModeConfReg << 16 ) >> 24;
813 
814  while ( i32CustomerDeltaAdjust < 0 ) {
815  ui32XoscHfCol >>= 1; // COL 1 step down
816  if ( ui32XoscHfCol == 0 ) { // if COL below minimum
817  ui32XoscHfCol = 0xFFFF; // Set COL to maximum
818  ui32XoscHfRow >>= 1; // ROW 1 step down
819  if ( ui32XoscHfRow == 0 ) { // if ROW below minimum
820  ui32XoscHfRow = 1; // Set both ROW and COL
821  ui32XoscHfCol = 1; // to minimum
822  }
823  }
824  i32CustomerDeltaAdjust++;
825  }
826  while ( i32CustomerDeltaAdjust > 0 ) {
827  ui32XoscHfCol = ( ui32XoscHfCol << 1 ) | 1; // COL 1 step up
828  if ( ui32XoscHfCol > 0xFFFF ) { // if COL above maximum
829  ui32XoscHfCol = 1; // Set COL to minimum
830  ui32XoscHfRow = ( ui32XoscHfRow << 1 ) | 1; // ROW 1 step up
831  if ( ui32XoscHfRow > 0xF ) { // if ROW above maximum
832  ui32XoscHfRow = 0xF; // Set both ROW and COL
833  ui32XoscHfCol = 0xFFFF; // to maximum
834  }
835  }
836  i32CustomerDeltaAdjust--;
837  }
838  }
839 
840  ui32TrimValue = (( ui32XoscHfRow << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
841  ( ui32XoscHfCol << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
842 
843  return (ui32TrimValue);
844 }
845 
846 //*****************************************************************************
847 //
850 //
851 //*****************************************************************************
852 uint32_t
854 {
855  uint32_t ui32TrimValue;
856 
857  // Use device specific trim values located in factory configuration
858  // area
859  ui32TrimValue =
864 
865  ui32TrimValue |=
870 
871  return(ui32TrimValue);
872 }
873 
874 //*****************************************************************************
875 //
878 //
879 //*****************************************************************************
880 uint32_t
882 {
883  uint32_t ui32TrimValue;
884 
885  // Use device specific trim value located in factory configuration
886  // area
887  ui32TrimValue =
891 
892  return(ui32TrimValue);
893 }
894 
895 //*****************************************************************************
896 //
898 //
899 //*****************************************************************************
900 uint32_t
902 {
903  uint32_t ui32TrimValue;
904  uint32_t ui32Fcfg1Value;
905 
906  // Use device specific trim value located in factory configuration
907  // area. All defined register bit fields have corresponding trim
908  // value in the factory configuration area
909  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH2);
910  ui32TrimValue = ((ui32Fcfg1Value &
914  ui32TrimValue |= (((ui32Fcfg1Value &
918  ui32TrimValue |= (((ui32Fcfg1Value &
922  ui32TrimValue |= (((ui32Fcfg1Value &
926 
927  return(ui32TrimValue);
928 }
929 
930 //*****************************************************************************
931 //
933 //
934 //*****************************************************************************
935 uint32_t
937 {
938  uint32_t ui32TrimValue;
939  uint32_t ui32Fcfg1Value;
940 
941  // Use device specific trim values located in factory configuration
942  // area. All defined register bit fields have a corresponding trim
943  // value in the factory configuration area
944  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH1);
945  ui32TrimValue = (((ui32Fcfg1Value &
949  ui32TrimValue |= (((ui32Fcfg1Value &
953  ui32TrimValue |= (((ui32Fcfg1Value &
957  ui32TrimValue |= (((ui32Fcfg1Value &
961 
962  return(ui32TrimValue);
963 }
964 
965 //*****************************************************************************
966 //
968 //
969 //*****************************************************************************
970 uint32_t
971 SetupGetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision )
972 {
973  uint32_t ui32TrimValue ;
974  uint32_t ui32Fcfg1Value ;
975  uint32_t ibiasOffset ;
976  uint32_t ibiasInit ;
977  uint32_t modeConf1 ;
978  int32_t deltaAdjust ;
979 
980  // Use device specific trim values located in factory configuration
981  // area. Register bit fields without trim values in the factory
982  // configuration area will be set to the value of 0.
983  ui32Fcfg1Value = HWREG( FCFG1_BASE + FCFG1_O_AMPCOMP_CTRL1 );
984 
985  ibiasOffset = ( ui32Fcfg1Value &
988  ibiasInit = ( ui32Fcfg1Value &
991 
993  // Adjust with DELTA_IBIAS_OFFSET and DELTA_IBIAS_INIT from CCFG
994  modeConf1 = HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 );
995 
996  // Both fields are signed 4-bit values. This is an assumption when doing the sign extension.
997  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_OFFSET_S - 4 )) >> 28;
998  deltaAdjust += (int32_t)ibiasOffset;
999  if ( deltaAdjust < 0 ) {
1000  deltaAdjust = 0;
1001  }
1004  }
1005  ibiasOffset = (uint32_t)deltaAdjust;
1006 
1007  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_INIT_S - 4 )) >> 28;
1008  deltaAdjust += (int32_t)ibiasInit;
1009  if ( deltaAdjust < 0 ) {
1010  deltaAdjust = 0;
1011  }
1014  }
1015  ibiasInit = (uint32_t)deltaAdjust;
1016  }
1017  ui32TrimValue = ( ibiasOffset << DDI_0_OSC_AMPCOMPCTL_IBIAS_OFFSET_S ) |
1018  ( ibiasInit << DDI_0_OSC_AMPCOMPCTL_IBIAS_INIT_S ) ;
1019 
1020  ui32TrimValue |= (((ui32Fcfg1Value &
1024  ui32TrimValue |= (((ui32Fcfg1Value &
1028  ui32TrimValue |= (((ui32Fcfg1Value &
1032 
1033  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1034  ui32TrimValue |= ((( ui32Fcfg1Value &
1038  }
1039 
1040  return(ui32TrimValue);
1041 }
1042 
1043 //*****************************************************************************
1044 //
1046 //
1047 //*****************************************************************************
1048 uint32_t
1049 SetupGetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision )
1050 {
1051  uint32_t dblrLoopFilterResetVoltageValue = 0; // Reset value
1052 
1053  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1054  dblrLoopFilterResetVoltageValue = ( HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 ) &
1057  }
1058 
1059  return ( dblrLoopFilterResetVoltageValue );
1060 }
1061 
1062 //*****************************************************************************
1063 //
1065 //
1066 //*****************************************************************************
1067 uint32_t
1068 SetupGetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision )
1069 {
1070  uint32_t getTrimForAdcShModeEnValue = 1; // Recommended default setting
1071 
1072  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1073  getTrimForAdcShModeEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1076  }
1077 
1078  return ( getTrimForAdcShModeEnValue );
1079 }
1080 
1081 //*****************************************************************************
1082 //
1084 //
1085 //*****************************************************************************
1086 uint32_t
1087 SetupGetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision )
1088 {
1089  uint32_t getTrimForAdcShVbufEnValue = 1; // Recommended default setting
1090 
1091  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1092  getTrimForAdcShVbufEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1095  }
1096 
1097  return ( getTrimForAdcShVbufEnValue );
1098 }
1099 
1100 //*****************************************************************************
1101 //
1103 //
1104 //*****************************************************************************
1105 uint32_t
1106 SetupGetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision )
1107 {
1108  uint32_t getTrimForXoschfCtlValue = 0; // Recommended default setting
1109  uint32_t fcfg1Data;
1110 
1111  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1112  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1113  getTrimForXoschfCtlValue =
1114  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_PEAK_DET_ITRIM_M ) >>
1117 
1118  getTrimForXoschfCtlValue |=
1119  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HP_BUF_ITRIM_M ) >>
1122 
1123  getTrimForXoschfCtlValue |=
1124  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LP_BUF_ITRIM_M ) >>
1127  }
1128 
1129  return ( getTrimForXoschfCtlValue );
1130 }
1131 
1132 //*****************************************************************************
1133 //
1135 //
1136 //*****************************************************************************
1137 uint32_t
1139 {
1140  uint32_t ui32XoscHfFastStartValue ;
1141 
1142  // Get value from FCFG1
1143  ui32XoscHfFastStartValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1146 
1147  return ( ui32XoscHfFastStartValue );
1148 }
1149 
1150 //*****************************************************************************
1151 //
1153 //
1154 //*****************************************************************************
1155 uint32_t
1156 SetupGetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision )
1157 {
1158  uint32_t getTrimForRadcExtCfgValue = 0x403F8000; // Recommended default setting
1159  uint32_t fcfg1Data;
1160 
1161  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1162  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1163  getTrimForRadcExtCfgValue =
1164  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HPM_IBIAS_WAIT_CNT_M ) >>
1167 
1168  getTrimForRadcExtCfgValue |=
1169  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LPM_IBIAS_WAIT_CNT_M ) >>
1172 
1173  getTrimForRadcExtCfgValue |=
1174  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_IDAC_STEP_M ) >>
1177  }
1178 
1179  return ( getTrimForRadcExtCfgValue );
1180 }
1181 
1182 //*****************************************************************************
1183 //
1185 //
1186 //*****************************************************************************
1187 uint32_t
1188 SetupGetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision )
1189 {
1190  uint32_t trimForRcOscLfIBiasTrimValue = 0; // Default value
1191 
1192  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1193  trimForRcOscLfIBiasTrimValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1196  }
1197 
1198  return ( trimForRcOscLfIBiasTrimValue );
1199 }
1200 
1201 //*****************************************************************************
1202 //
1205 //
1206 //*****************************************************************************
1207 uint32_t
1209 {
1210  uint32_t trimForXoscLfRegulatorAndCmirrwrRatioValue = 0; // Default value for both fields
1211 
1212  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1213  trimForXoscLfRegulatorAndCmirrwrRatioValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1217  }
1218 
1219  return ( trimForXoscLfRegulatorAndCmirrwrRatioValue );
1220 }
1221 
1222 //*****************************************************************************
1223 //
1227 //
1228 //*****************************************************************************
1229 int32_t
1230 SetupSignExtendVddrTrimValue( uint32_t ui32VddrTrimVal )
1231 {
1232  //
1233  // The VDDR trim value is 5 bits representing the range from -10 to +21
1234  // (where -10=0x16, -1=0x1F, 0=0x00, 1=0x01 and +21=0x15)
1235  //
1236  int32_t i32SignedVddrVal = ui32VddrTrimVal;
1237  if ( i32SignedVddrVal > 0x15 ) {
1238  i32SignedVddrVal -= 0x20;
1239  }
1240  return ( i32SignedVddrVal );
1241 }
1242 
1243 //*****************************************************************************
1244 //
1248 //
1249 //*****************************************************************************
1250 void
1252 {
1253  //
1254  // - Make sure to enable aggressive VIMS clock gating for power optimization
1255  // Only for PG2 devices.
1256  // - Enable cache prefetch enable as default setting
1257  // (Slightly higher power consumption, but higher CPU performance)
1258  // - IF ( CCFG_..._DIS_GPRAM == 1 )
1259  // then: Enable cache (set cache mode = 1), even if set by ROM boot code
1260  // (This is done because it's not set by boot code when running inside
1261  // a debugger supporting the Halt In Boot (HIB) functionality).
1262  // else: Set MODE_GPRAM if not already set (see inline comments as well)
1263  //
1264  uint32_t vimsCtlMode0 ;
1265 
1266  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
1267  // Do nothing - wait for an eventual ongoing mode change to complete.
1268  // (There should typically be no wait time here, but need to be sure)
1269  }
1270 
1271  //
1272  // Note that Mode=0 is equal to MODE_GPRAM
1273  //
1274  vimsCtlMode0 = (( HWREG( VIMS_BASE + VIMS_O_CTL ) & ~VIMS_CTL_MODE_M ) | VIMS_CTL_DYN_CG_EN_M | VIMS_CTL_PREF_EN_M );
1275 
1276 
1278  // Enable cache (and hence disable GPRAM)
1279  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_CACHE );
1280  } else if (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_GPRAM ) {
1281  //
1282  // GPRAM is enabled in CCFG but not selected
1283  // Note: It is recommended to go via MODE_OFF when switching to MODE_GPRAM
1284  //
1285  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_OFF );
1286  while (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_OFF ) {
1287  // Do nothing - wait for an eventual mode change to complete (This goes fast).
1288  }
1289  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
1290  } else {
1291  // Correct mode, but make sure PREF_EN and DYN_CG_EN always are set
1292  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
1293  }
1294 }
1295 
1296 //*****************************************************************************
1297 //
1301 //
1302 //*****************************************************************************
1303 void
1304 SetupSetAonRtcSubSecInc( uint32_t subSecInc )
1305 {
1306  //
1307  // Loading a new RTCSUBSECINC value is done in 5 steps:
1308  // 1. Write bit[15:0] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC0
1309  // 2. Write bit[23:16] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC1
1311  // 4. Wait for AUX_WUC_RTCSUBSECINCCTL_UPD_ACK
1313  //
1315  HWREG( AUX_WUC_BASE + AUX_WUC_O_RTCSUBSECINC1 ) = (( subSecInc >> 16 ) & AUX_WUC_RTCSUBSECINC1_INC23_16_M );
1316 
1319  HWREG( AUX_WUC_BASE + AUX_WUC_O_RTCSUBSECINCCTL ) = 0;
1320 }
1321 
1322 //*****************************************************************************
1323 //
1328 //
1329 //*****************************************************************************
1330 void
1331 SetupSetVddrLevel( uint32_t ccfg_ModeConfReg )
1332 {
1333  uint32_t newTrimRaw ;
1334  int32_t targetTrim ;
1335  int32_t currentTrim ;
1336  int32_t deltaTrim ;
1337 
1338 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
1339  //
1340  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
1341  // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_HH
1342  //
1343  newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1346 // } else {
1347 // //
1348 // // VDDS_BOD_LEVEL = 0
1349 // // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_H
1350 // //
1351 // newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1354 // }
1355  targetTrim = SetupSignExtendVddrTrimValue( newTrimRaw );
1356  currentTrim = SetupSignExtendVddrTrimValue((
1357  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_DCDCCTL0 ) &
1360 
1361  if ( currentTrim != targetTrim ) {
1362  // Disable VDDR BOD
1364 
1365  while ( currentTrim != targetTrim ) {
1366  deltaTrim = targetTrim - currentTrim;
1367  if ( deltaTrim > 2 ) deltaTrim = 2;
1368  if ( deltaTrim < -2 ) deltaTrim = -2;
1369  currentTrim += deltaTrim;
1370 
1371  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1372 
1373  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL0 * 2 )) =
1374  ( ADI_3_REFSYS_DCDCCTL0_VDDR_TRIM_M << 8 ) | (( currentTrim <<
1377 
1378  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1379  }
1380 
1381  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1382  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1383  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one more SCLK_LF period before re-enabling VDDR BOD
1385  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // And finally wait for VDDR_LOSS_EN setting to propagate
1386  }
1387 }
static void SysCtrlAonSync(void)
Sync all accesses to the AON register interface.
Definition: sys_ctrl.h:196
#define IOC_PORT_AON_CLK32K
Definition: ioc.h:169
uint32_t SetupGetTrimForAmpcompTh1(void)
Returns the trim value to be used for the AMPCOMP_TH1 register in OSC_DIG.
Definition: setup.c:936
uint32_t SetupGetTrimForRcOscLfRtuneCtuneTrim(void)
Returns the trim value to be used for the RCOSCLF_RTUNE_TRIM and the RCOSCLF_CTUNE_TRIM bit fields in...
Definition: setup.c:853
uint32_t SetupGetTrimForAmpcompTh2(void)
Returns the trim value to be used for the AMPCOMP_TH2 register in OSC_DIG.
Definition: setup.c:901
uint32_t SetupGetTrimForDblrLoopFilterResetVoltage(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as DBLR_LOOP_FILTER_RESET_VOLTAGE setting.
Definition: setup.c:1049
void SetupAfterColdResetWakeupFromShutDownCfg3(uint32_t ccfg_ModeConfReg)
Third part of configuration required when waking up from shutdown.
Definition: setup.c:651
uint32_t SetupGetTrimForAdcShVbufEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_VBUF_EN setting.
Definition: setup.c:1087
#define AUX_WUC_POWER_DOWN
Definition: aux_wuc.h:95
void AUXWUCPowerCtrl(uint32_t ui32PowerMode)
Control the power to the AUX domain.
Definition: aux_wuc.c:274
uint32_t OSCClockSourceGet(uint32_t ui32SrcClk)
Get the source clock settings.
Definition: osc.c:160
void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift, uint16_t ui32Data)
Write a bitfield via the DDI using 16-bit maskable write.
Definition: ddi.c:131
#define IOC_STD_INPUT
Definition: ioc.h:292
uint32_t SetupGetTrimForRadcExtCfg(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the RADCEXTCFG register in OSC_DIG.
Definition: setup.c:1156
void ThisCodeIsBuiltForCC13xxHwRev20AndLater_HaltIfViolated(void)
Verifies that curent chip is built for CC13xx HwRev 2.0 or later and never returns if violated...
Definition: chipinfo.c:224
void SetupSetAonRtcSubSecInc(uint32_t subSecInc)
Doing the tricky stuff needed to enter new RTCSUBSECINC value.
Definition: setup.c:1304
uint32_t SetupGetTrimForRcOscLfIBiasTrim(uint32_t ui32Fcfg1Revision)
Returns the FCFG1 OSC_CONF_ATESTLF_RCOSCLF_IBIAS_TRIM.
Definition: setup.c:1188
void SetupTrimDevice(void)
Performs the necessary trim of the device which is not done in boot code.
Definition: setup.c:144
void SetupAfterColdResetWakeupFromShutDownCfg1(uint32_t ccfg_ModeConfReg)
First part of configuration required when waking up from shutdown.
Definition: setup.c:431
#define OSC_SRC_CLK_HF
Definition: osc.h:112
static void TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown(void)
Trims to be applied when coming from POWER_DOWN (also called when coming from SHUTDOWN and PIN_RESET)...
Definition: setup.c:285
#define OSC_XOSC_HF
Definition: osc.h:117
uint32_t SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio(uint32_t ui32Fcfg1Revision)
Returns XOSCLF_REGULATOR_TRIM and XOSCLF_CMIRRWR_RATIO as one packet spanning bits [5:0] in the retur...
Definition: setup.c:1208
int32_t SetupSignExtendVddrTrimValue(uint32_t ui32VddrTrimVal)
Sign extend the VDDR_TRIM setting (special format ranging from -10 to +21)
Definition: setup.c:1230
#define OSC_SRC_CLK_LF
Definition: osc.h:114
uint32_t SetupGetTrimForAnabypassValue1(uint32_t ccfg_ModeConfReg)
Returns the trim value to be used for the ANABYPASS_VALUE1 register in OSC_DIG.
Definition: setup.c:783
void SetupSetCacheModeAccordingToCcfgSetting(void)
Set correct VIMS_MODE according to CCFG setting (CACHE or GPRAM)
Definition: setup.c:1251
uint32_t SetupGetTrimForAdcShModeEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_MODE_EN setting.
Definition: setup.c:1068
uint32_t SetupGetTrimForAmpcompCtrl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the AMPCOMP_CTRL register in OSC_DIG.
Definition: setup.c:971
#define OSC_RCOSC_LF
Definition: osc.h:118
void IOCPortConfigureSet(uint32_t ui32IOId, uint32_t ui32PortId, uint32_t ui32IOConfig)
Set the configuration of an IO port.
Definition: ioc.c:96
static void TrimAfterColdResetWakeupFromShutDown(uint32_t ui32Fcfg1Revision)
Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET).
Definition: setup.c:301
#define IOC_HYST_ENABLE
Definition: ioc.h:216
void SetupSetVddrLevel(uint32_t ccfg_ModeConfReg)
Set VDDR boost mode (by setting VDDR_TRIM to FCFG1..VDDR_TRIM_HH and setting VDDS_BOD to max) ...
Definition: setup.c:1331
void DDI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Write a 32 bit value to a register in the DDI slave.
Definition: ddi.c:66
uint32_t SetupGetTrimForXoscHfFastStart(void)
Returns the trim value to be used as OSC_DIG:CTL1.XOSC_HF_FAST_START.
Definition: setup.c:1138
void OSCClockSourceSet(uint32_t ui32SrcClk, uint32_t ui32Osc)
Configure the oscillator input to the a source clock.
Definition: osc.c:101
void SetupAfterColdResetWakeupFromShutDownCfg2(uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg)
Second part of configuration required when waking up from shutdown.
Definition: setup.c:535
uint32_t SetupGetTrimForXoscHfCtl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the XOSCHFCTL register in OSC_DIG.
Definition: setup.c:1106
static void TrimAfterColdReset(void)
Trims to be applied when coming from PIN_RESET.
Definition: setup.c:418
#define OSC_XOSC_LF
Definition: osc.h:119
uint32_t SetupGetTrimForXoscHfIbiastherm(void)
Returns the trim value to be used for the XOSC_HF_IBIASTHERM bit field in the ANABYPASS_VALUE2 regist...
Definition: setup.c:881
static void AONWUCJtagPowerOff(void)
Request power off of the JTAG domain.
Definition: aon_wuc.h:816