CC13xx Driver Library
setup.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: setup.c
3 * Revised: 2016-05-27 11:23:10 +0200 (Fri, 27 May 2016)
4 * Revision: 46526
5 *
6 * Description: Setup file for CC13xx/CC26xx devices.
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 // Hardware headers
40 #include <inc/hw_memmap.h>
41 #include <inc/hw_types.h>
42 #include <inc/hw_adi.h>
43 #include <inc/hw_adi_0_rf.h>
44 #include <inc/hw_adi_1_synth.h>
45 #include <inc/hw_adi_2_refsys.h>
46 #include <inc/hw_adi_3_refsys.h>
47 #include <inc/hw_adi_4_aux.h>
48 #include <inc/hw_aon_ioc.h>
49 #include <inc/hw_aon_sysctl.h>
50 #include <inc/hw_aon_wuc.h>
51 #include <inc/hw_aux_wuc.h>
52 #include <inc/hw_ccfg.h>
53 #include <inc/hw_chip_def.h>
54 #include <inc/hw_ddi.h>
55 #include <inc/hw_flash.h>
56 #include <inc/hw_fcfg1.h>
57 #include <inc/hw_ddi_0_osc.h>
58 #include <inc/hw_prcm.h>
59 #include <inc/hw_vims.h>
60 #include <inc/hw_aon_batmon.h>
61 #include <inc/hw_aon_rtc.h>
62 // Driverlib headers
63 #include <driverlib/adi.h>
64 #include <driverlib/aon_batmon.h>
65 #include <driverlib/cpu.h>
66 #include <driverlib/chipinfo.h>
67 #include <driverlib/ddi.h>
68 #include <driverlib/ioc.h>
69 #include <driverlib/prcm.h>
70 #include <driverlib/setup.h>
71 #include <driverlib/sys_ctrl.h>
72 
73 // We need intrinsic functions for IAR (if used in source code)
74 #ifdef __IAR_SYSTEMS_ICC__
75 #include <intrinsics.h>
76 #endif
77 
78 //*****************************************************************************
79 //
80 // Function declarations
81 //
82 //*****************************************************************************
83 static uint32_t GetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision );
84 static uint32_t GetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision );
85 static uint32_t GetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision );
86 static uint32_t GetTrimForAmpcompTh1( void );
87 static uint32_t GetTrimForAmpcompTh2( void );
88 static uint32_t GetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg );
89 static uint32_t GetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision );
90 static uint32_t GetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision );
91 static uint32_t GetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision );
92 static uint32_t GetTrimForRcOscLfRtuneCtuneTrim( void );
93 static uint32_t GetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision );
94 static uint32_t GetTrimForXoscHfFastStart( void );
95 static uint32_t GetTrimForXoscHfIbiastherm( void );
96 static uint32_t GetTrimForXoscLfRegulatorAndCmirrwrRatio( uint32_t ui32Fcfg1Revision );
97 
98 int32_t SignExtendVddrTrimValue( uint32_t ui32VddrTrimVal );
99 static void HapiTrimDeviceColdReset( void );
100 static void HapiTrimDeviceShutDown( uint32_t ui32Fcfg1Revision );
101 static void HapiTrimDevicePowerDown( void );
102 
103 void SetVddrLevel( uint32_t ccfg_ModeConfReg );
104 
105 
106 //*****************************************************************************
107 //
109 //
110 //*****************************************************************************
111 #define DELAY_20_USEC 0x140
112 
113 
114 //*****************************************************************************
115 //
116 // Defined CPU delay macro with microseconds as input
117 // Quick check shows: (To be further investigated)
118 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 5 cycles
119 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 1, there is 4 cycles
120 // At 24 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 3 cycles
121 //
122 //*****************************************************************************
123 #define CPU_DELAY_MICRO_SECONDS( x ) \
124  CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )
125 
126 
127 //*****************************************************************************
128 //
132 //
133 //*****************************************************************************
134 static void
136 {
137  //
138  // - Make sure to enable aggressive VIMS clock gating for power optimization
139  // Only for PG2 devices.
140  // - Enable cache prefetch enable as default setting
141  // (Slightly higher power consumption, but higher CPU performance)
142  // - IF ( CCFG_..._DIS_GPRAM == 1 )
143  // then: Enable cache (set cache mode = 1), even if set by ROM boot code
144  // (This is done because it's not set by boot code when running inside
145  // a debugger supporting the Halt In Boot (HIB) functionality).
146  // else: Set MODE_GPRAM if not already set (see inline comments as well)
147  //
148  uint32_t vimsCtlMode0 ;
149 
150  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
151  // Do nothing - wait for an eventual ongoing mode change to complete.
152  // (There should typically be no wait time here, but need to be sure)
153  }
154 
155  //
156  // Note that Mode=0 is equal to MODE_GPRAM
157  //
158  vimsCtlMode0 = (( HWREG( VIMS_BASE + VIMS_O_CTL ) & ~VIMS_CTL_MODE_M ) | VIMS_CTL_DYN_CG_EN_M | VIMS_CTL_PREF_EN_M );
159 
160 
162  // Enable cache (and hence disable GPRAM)
163  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_CACHE );
164  } else if (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_GPRAM ) {
165  //
166  // GPRAM is enabled in CCFG but not selected
167  // Note: It is recommended to go via MODE_OFF when switching to MODE_GPRAM
168  //
169  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_OFF );
170  while (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_OFF ) {
171  // Do nothing - wait for an eventual mode change to complete (This goes fast).
172  }
173  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
174  } else {
175  // Correct mode, but make sure PREF_EN and DYN_CG_EN always are set
176  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
177  }
178 }
179 
180 
181 //*****************************************************************************
182 //
183 // Perform the necessary trim of the device which is not done in boot code
184 //
185 // This function should only execute coming from ROM boot. The current
186 // implementation does not take soft reset into account. However, it does no
187 // damage to execute it again. It only consumes time.
188 //
189 //*****************************************************************************
190 void
192 {
193  uint32_t ui32Fcfg1Revision;
194  uint32_t ui32AonSysResetctl;
195 
196  //
197  // Get layout revision of the factory configuration area
198  // (Handle undefined revision as revision = 0)
199  //
200  ui32Fcfg1Revision = HWREG(FCFG1_BASE + FCFG1_O_FCFG1_REVISION);
201  if ( ui32Fcfg1Revision == 0xFFFFFFFF ) {
202  ui32Fcfg1Revision = 0;
203  }
204 
205 
206  //
207  // This driverlib version and setup file is for CC13xx PG2.0 and later.
208  // Halt if violated
209  //
211 
212  //
213  // Enable standby in flash bank
214  //
216 
217  //
218  // Clock must always be enabled for the semaphore module (due to ADI/DDI HW workaround)
219  //
221 
222  //
223  // Warm resets on CC26XX complicates software design as much of our software
224  // expect that initialization is done from a full system reset.
225  // This includes RTC setup, oscillator configuration and AUX setup.
226  // To ensure a full reset of the device is done when customers get e.g. a Watchdog
227  // reset, the following is set here:
228  //
230 
231  //
232  // Select correct CACHE mode and set correct CACHE configuration
233  //
235 
236  // 1. Check for powerdown
237  // 2. Check for shutdown
238  // 3. Assume cold reset if none of the above.
239  //
240  // It is always assumed that the application will freeze the latches in
241  // AON_IOC when going to powerdown in order to retain the values on the IOs.
242  //
243  // NB. If this bit is not cleared before proceeding to powerdown, the IOs
244  // will all default to the reset configuration when restarting.
246  {
247  //
248  // NB. This should be calling a ROM implementation of required trim and
249  // compensation
250  // e.g. HapiTrimDevicePowerDown()
252  }
253  // Check for shutdown
254  //
255  // When device is going to shutdown the hardware will automatically clear
256  // the SLEEPDIS bit in the SLEEP register in the AON_SYSCTRL12 module.
257  // It is left for the application to assert this bit when waking back up,
258  // but not before the desired IO configuration has been re-established.
260  {
261  //
262  // NB. This should be calling a ROM implementation of required trim and
263  // compensation
264  // e.g. HapiTrimDeviceShutDown() -->
265  // HapiTrimDevicePowerDown();
266  HapiTrimDeviceShutDown(ui32Fcfg1Revision);
268  }
269  else
270  {
271  // Consider adding a check for soft reset to allow debugging to skip
272  // this section!!!
273  //
274  // NB. This should be calling a ROM implementation of required trim and
275  // compensation
276  // e.g. HapiTrimDeviceColdReset() -->
277  // HapiTrimDeviceShutDown() -->
278  // HapiTrimDevicePowerDown()
280  HapiTrimDeviceShutDown(ui32Fcfg1Revision);
282 
283  }
284 
285  //
286  // Set VIMS power domain control.
287  // PDCTL1VIMS = 0 ==> VIMS power domain is only powered when CPU power domain is powered
288  //
289  HWREG( PRCM_BASE + PRCM_O_PDCTL1VIMS ) = 0;
290 
291  //
292  // Configure optimal wait time for flash FSM in cases where flash pump
293  // wakes up from sleep
294  //
295  HWREG(FLASH_BASE + FLASH_O_FPAC1) = (HWREG(FLASH_BASE + FLASH_O_FPAC1) &
297  (0x139<<FLASH_FPAC1_PSLEEPTDIS_S);
298 
299  //
300  // And finally at the end of the flash boot process:
301  // SET BOOT_DET bits in AON_SYSCTL to 3 if already found to be 1
302  // Note: The BOOT_DET_x_CLR/SET bits must be manually cleared
303  //
304  if ((( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
307  {
308  ui32AonSysResetctl = ( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
312  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl;
313  }
314 
315  //
316  // Make sure there are no ongoing VIMS mode change when leaving trimDevice()
317  // (There should typically be no wait time here, but need to be sure)
318  //
319  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
320  // Do nothing - wait for an eventual ongoing mode change to complete.
321  }
322 }
323 
324 //*****************************************************************************
325 //
330 //
331 //*****************************************************************************
332 static void
334 {
335  //
336  // Currently no specific trim for Powerdown
337  //
338 }
339 
340 //*****************************************************************************
341 //
345 //
346 //*****************************************************************************
347 static void
348 SetAonRtcSubSecInc( uint32_t subSecInc )
349 {
350  //
351  // Loading a new RTCSUBSECINC value is done in 5 steps:
352  // 1. Write bit[15:0] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC0
353  // 2. Write bit[23:16] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC1
355  // 4. Wait for AUX_WUC_RTCSUBSECINCCTL_UPD_ACK
357  //
359  HWREG( AUX_WUC_BASE + AUX_WUC_O_RTCSUBSECINC1 ) = (( subSecInc >> 16 ) & AUX_WUC_RTCSUBSECINC1_INC23_16_M );
360 
364 }
365 
366 //*****************************************************************************
367 //
372 //
373 //*****************************************************************************
374 static void
375 HapiTrimDeviceShutDown(uint32_t ui32Fcfg1Revision)
376 {
377  uint32_t ui32Trim ;
378  uint32_t ccfg_ModeConfReg ;
379  uint32_t currentHfClock ;
380  uint32_t ccfgExtLfClk ;
381  int32_t i32VddrSleepTrim ;
382  int32_t i32VddrSleepDelta ;
383  uint32_t fcfg1OscConf ;
384  uint32_t mp1rev ;
385 
386  //
387  // Force AUX on and enable clocks
388  //
389  // No need to save the current status of the power/clock registers.
390  // At this point both AUX and AON should have been reset to 0x0.
391  //
393 
394  //
395  // Wait for power on on the AUX domain
396  //
398 
399  //
400  // Enable the clocks for AUX_DDI0_OSC and AUX_ADI4
401  //
404 
405  //
406  // Check in CCFG for alternative DCDC setting
407  //
409  //
410  // ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
411  // ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
412  // Using a single 4-bit masked write since layout is equal for both source and destination
413  //
414  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
416 
417  }
418 
419  //
420  // Enable for JTAG to be powered down (will still be powered on if debugger is connected)
421  //
423 
424  //
425  // read the MODE_CONF register in CCFG
426  //
427  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
428 
429  //
430  // Check for CC13xx boost mode
431  // The combination VDDR_EXT_LOAD=0 and VDDS_BOD_LEVEL=1 is defined to selct boost mode
432  //
433  if ((( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_EXT_LOAD ) == 0 ) &&
434  (( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) != 0 ) ) {
435  //
436  // Set VDDS_BOD trim - using masked write {MASK8:DATA8}
437  // - TRIM_VDDS_BOD is bits[7:3] of ADI3..REFSYSCTL1
438  // - Needs a positive transition on BOD_BG_TRIM_EN (bit[7] of REFSYSCTL3) to
439  // latch new VDDS BOD. Set to 0 first to guarantee a positive transition.
440  //
442 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
443  //
444  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
445  // - Max out the VDDS_BOD trim (=VDDS_BOD_POS_31)
446  //
447  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
450 // } else {
451 // //
452 // // VDDS_BOD_LEVEL = 0
453 // // - Set VDDS_BOD to FCFG1..TRIMBOD_H
454 // //
455 // HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
457 // ((( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
460 // }
462 
463  SetVddrLevel( ccfg_ModeConfReg );
464 
465  i32VddrSleepTrim = SignExtendVddrTrimValue((
466  HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
469  } else
470  {
471  i32VddrSleepTrim = SignExtendVddrTrimValue((
472  HWREG( FCFG1_BASE + FCFG1_O_LDO_TRIM ) &
475  }
476 
477  //
478  // Adjust the VDDR_TRIM_SLEEP value with value adjustable by customer (CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA)
479  // Read and sign extend VddrSleepDelta (in range -8 to +7)
480  //
481  i32VddrSleepDelta = ((((int32_t)ccfg_ModeConfReg )
482  << ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_S ))
483  >> ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W ));
484  // Calculate new VDDR sleep trim
485  i32VddrSleepTrim = ( i32VddrSleepTrim + i32VddrSleepDelta + 1 );
486  if ( i32VddrSleepTrim > 21 ) i32VddrSleepTrim = 21;
487  if ( i32VddrSleepTrim < -10 ) i32VddrSleepTrim = -10;
488  // Write adjusted value using MASKED write (MASK8)
489  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL1 * 2 )) = (( ADI_3_REFSYS_DCDCCTL1_VDDR_TRIM_SLEEP_M << 8 ) |
491 
492  //
493  // Do not allow DCDC to be enabled if in external regulator mode.
494  // Preventing this by setting both the RECHARGE and the ACTIVE bits bit in the CCFG_MODE_CONF copy register (ccfg_ModeConfReg).
495  //
498  }
499 
500  //
501  // set the RECHARGE source based upon CCFG:MODE_CONF:DCDC_RECHARGE
502  // Note: Inverse polarity
503  //
505  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_RECHARGE_S ) & 1 ) ^ 1 );
506 
507  //
508  // set the ACTIVE source based upon CCFG:MODE_CONF:DCDC_ACTIVE
509  // Note: Inverse polarity
510  //
512  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_ACTIVE_S ) & 1 ) ^ 1 );
513 
514  //
515  // Following sequence is required for using XOSCHF, if not included
516  // devices crashes when trying to switch to XOSCHF.
517  //
518  // Trim CAP settings. Get and set trim value for the ANABYPASS_VALUE1
519  // register
520  ui32Trim = GetTrimForAnabypassValue1( ccfg_ModeConfReg );
522 
523  // Trim RCOSC_LF. Get and set trim values for the RCOSCLF_RTUNE_TRIM and
524  // RCOSCLF_CTUNE_TRIM fields in the XOSCLF_RCOSCLF_CTRL register.
525  ui32Trim = GetTrimForRcOscLfRtuneCtuneTrim();
530  ui32Trim);
531 
532  // Trim XOSCHF IBIAS THERM. Get and set trim value for the
533  // XOSCHF IBIAS THERM bit field in the ANABYPASS_VALUE2 register. Other
534  // register bit fields are set to 0.
535  ui32Trim = GetTrimForXoscHfIbiastherm();
538 
539  // Trim AMPCOMP settings required before switch to XOSCHF
540  ui32Trim = GetTrimForAmpcompTh2();
542  ui32Trim = GetTrimForAmpcompTh1();
544  ui32Trim = GetTrimForAmpcompCtrl( ui32Fcfg1Revision );
546 
547  //
548  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_MODE_EN in accordance to FCFG1 setting
549  // This is bit[5] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
550  // Using MASK4 write + 1 => writing to bits[7:4]
551  //
552  ui32Trim = GetTrimForAdcShModeEn( ui32Fcfg1Revision );
553  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
554  ( 0x20 | ( ui32Trim << 1 ));
555 
556  //
557  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_VBUF_EN in accordance to FCFG1 setting
558  // This is bit[4] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
559  // Using MASK4 write + 1 => writing to bits[7:4]
560  //
561  ui32Trim = GetTrimForAdcShVbufEn( ui32Fcfg1Revision );
562  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
563  ( 0x10 | ( ui32Trim ));
564 
565  //
566  // Set trim for the PEAK_DET_ITRIM, HP_BUF_ITRIM and LP_BUF_ITRIM bit fields
567  // in the DDI0_OSC_O_XOSCHFCTL register in accordance to FCFG1 setting.
568  // Remaining register bit fields are set to their reset values of 0.
569  //
570  ui32Trim = GetTrimForXoscHfCtl(ui32Fcfg1Revision);
572 
573  //
574  // Set trim for DBLR_LOOP_FILTER_RESET_VOLTAGE in accordance to FCFG1 setting
575  // (This is bits [18:17] in DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL)
576  // (Using MASK4 write + 4 => writing to bits[19:16] => (4*4))
577  // (Assuming: DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_S = 17 and
578  // that DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_M = 0x00060000)
579  //
580  ui32Trim = GetTrimForDblrLoopFilterResetVoltage( ui32Fcfg1Revision );
581  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 4 ) =
582  ( 0x60 | ( ui32Trim << 1 ));
583 
584  //
585  // Update DDI_0_OSC_ATESTCTL_ATESTLF_RCOSCLF_IBIAS_TRIM with data from
587  // This is DDI_0_OSC_O_ATESTCTL bit[7]
588  // ( DDI_0_OSC_O_ATESTCTL is currently hidden (but=0x00000020))
589  // Using MASK4 write + 1 => writing to bits[7:4]
590  //
591  ui32Trim = GetTrimForRcOscLfIBiasTrim( ui32Fcfg1Revision );
592  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( 0x00000020 * 2 ) + 1 ) =
593  ( 0x80 | ( ui32Trim << 3 ));
594 
595  //
598  // This can be simplified since the registers are packed together in the same
599  // order both in FCFG1 and in the HW register.
600  // This spans DDI_0_OSC_O_LFOSCCTL bits[23:18]
601  // Using MASK8 write + 4 => writing to bits[23:16]
602  //
603  ui32Trim = GetTrimForXoscLfRegulatorAndCmirrwrRatio( ui32Fcfg1Revision );
604  HWREGH( AUX_DDI0_OSC_BASE + DDI_O_MASK8B + ( DDI_0_OSC_O_LFOSCCTL * 2 ) + 4 ) =
605  ( 0xFC00 | ( ui32Trim << 2 ));
606 
607  //
608  // Set trim the HPM_IBIAS_WAIT_CNT, LPM_IBIAS_WAIT_CNT and IDAC_STEP bit
609  // fields in the DDI0_OSC_O_RADCEXTCFG register in accordance to FCFG1 setting.
610  // Remaining register bit fields are set to their reset values of 0.
611  //
612  ui32Trim = GetTrimForRadcExtCfg(ui32Fcfg1Revision);
614 
615  // Setting FORCE_KICKSTART_EN (ref. CC26_V1_BUG00261). Should also be done for PG2
616  // (This is bit 22 in DDI_0_OSC_O_CTL0)
618 
619  //
620  // Increased margin between digital supply voltage and VDD BOD during standby.
621  // VTRIM_UDIG: signed 4 bits value to be incremented by 2 (max = 7)
622  // VTRIM_BOD: unsigned 4 bits value to be decremented by 1 (min = 0)
623  // This applies to chips with mp1rev < 542 for cc13xx and for mp1rev < 527 for cc26xx
624  //
625  mp1rev = ( HWREG( FCFG1_BASE + 0x00000314 ) & 0x0000FFFF );
626  if ( mp1rev < 542 ) {
627  uint32_t vtrim_bod = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 24 ) & 0xF ); // bit[27:24] unsigned
628  uint32_t vtrim_udig = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 16 ) & 0xF ); // bit[19:16] signed
629  if ( vtrim_bod > 0 ) {
630  vtrim_bod -= 1;
631  }
632  if ( vtrim_udig != 7 ) {
633  if ( vtrim_udig == 6 ) {
634  vtrim_udig = 7;
635  } else {
636  vtrim_udig = (( vtrim_udig + 2 ) & 0xF );
637  }
638  }
640  ( vtrim_udig << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_UDIG_S ) |
641  ( vtrim_bod << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_BOD_S ) ;
642  }
643 
644  //
645  // Examin the XOSC_FREQ field to select 0x1=HPOSC, 0x2=48MHz XOSC, 0x3=24MHz XOSC
646  //
647  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_FREQ_M ) >> CCFG_MODE_CONF_XOSC_FREQ_S ) {
648  case 2 :
649  // XOSC source is a 48 MHz xtal
650  // Do nothing (since this is the reset setting)
651  break;
652  case 1 :
653  // XOSC source is HPOSC (trim the HPOSC if this is a chip with HPOSC, otherwise skip trimming and default to 24 MHz XOSC)
654 
655  fcfg1OscConf = HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF );
656 
657  if (( fcfg1OscConf & FCFG1_OSC_CONF_HPOSC_OPTION ) == 0 ) {
658  // This is a HPOSC chip, apply HPOSC settings
659  // Set bit DDI_0_OSC_CTL0_HPOSC_MODE_EN (this is bit 14 in DDI_0_OSC_O_CTL0)
661 
669 
682  break;
683  }
684  // Not a HPOSC chip - fall through to default
685  default :
686  // XOSC source is a 24 MHz xtal (default)
687  // Set bit DDI_0_OSC_CTL0_XTAL_IS_24M (this is bit 31 in DDI_0_OSC_O_CTL0)
689  break;
690  }
691 
692  // Clear DDI_0_OSC_CTL0_CLK_LOSS_EN (ClockLossEventEnable()). This is bit 9 in DDI_0_OSC_O_CTL0.
693  // This is typically already 0 except on Lizard where it is set in ROM-boot
695 
696  // Setting DDI_0_OSC_CTL1_XOSC_HF_FAST_START according to value found in FCFG1
697  ui32Trim = GetTrimForXoscHfFastStart();
698  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_CTL1 * 2 )) = ( 0x30 | ui32Trim );
699 
700  //
701  // setup the LF clock based upon CCFG:MODE_CONF:SCLK_LF_OPTION
702  //
703  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_SCLK_LF_OPTION_M ) >> CCFG_MODE_CONF_SCLK_LF_OPTION_S ) {
704  case 0 : // XOSC_HF_DLF (XOSCHF/1536) -> SCLK_LF (=31250Hz)
706  SetAonRtcSubSecInc( 0x8637BD );
707  break;
708  case 1 : // EXTERNAL signal -> SCLK_LF (frequency=2^38/CCFG_EXT_LF_CLK_RTC_INCREMENT)
709  // Set SCLK_LF to use the same source as SCLK_HF
710  // Can be simplified a bit since possible return values for HF matches LF settings
711  currentHfClock = OSCClockSourceGet( OSC_SRC_CLK_HF );
712  OSCClockSourceSet( OSC_SRC_CLK_LF, currentHfClock );
713  while( OSCClockSourceGet( OSC_SRC_CLK_LF ) != currentHfClock ) {
714  // Wait until switched
715  }
716  ccfgExtLfClk = HWREG( CCFG_BASE + CCFG_O_EXT_LF_CLK );
720  IOC_STD_INPUT | IOC_HYST_ENABLE ); // Route external clock to AON IOC w/hysteresis
721  // Set XOSC_LF in bypass mode to allow external 32k clock
723  // Fall through to set XOSC_LF as SCLK_LF source
724  case 2 : // XOSC_LF -> SLCK_LF (32768 Hz)
726  break;
727  default : // (=3) RCOSC_LF
729  break;
730  }
731 
732  //
733  // Update ADI_4_AUX_ADCREF1_VTRIM with value from FCFG1
734  //
735  HWREGB( AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF1 ) =
740 
741  //
742  // Set ADI_4_AUX:ADC0.SMPL_CYCLE_EXP to it's default minimum value (=3)
743  // (Note: Using MASK8B requires that the bits to be modified must be within the same
744  // byte boundary which is the case for the ADI_4_AUX_ADC0_SMPL_CYCLE_EXP field)
745  //
746  HWREGH( AUX_ADI4_BASE + ADI_O_MASK8B + ( ADI_4_AUX_O_ADC0 * 2 )) =
748 
749  //
750  // Sync with AON
751  //
752  SysCtrlAonSync();
753 
754  //
755  // Allow AUX to power down
756  //
758 
759  //
760  // Leaving on AUX and clock for AUX_DDI0_OSC on but turn off clock for AUX_ADI4
761  //
763 
764  // Disable EFUSE clock
766 }
767 
768 //*****************************************************************************
769 //
773 //
774 //*****************************************************************************
775 int32_t
776 SignExtendVddrTrimValue( uint32_t ui32VddrTrimVal )
777 {
778  //
779  // The VDDR trim value is 5 bits representing the range from -10 to +21
780  // (where -10=0x16, -1=0x1F, 0=0x00, 1=0x01 and +21=0x15)
781  //
782  int32_t i32SignedVddrVal = ui32VddrTrimVal;
783  if ( i32SignedVddrVal > 0x15 ) {
784  i32SignedVddrVal -= 0x20;
785  }
786  return ( i32SignedVddrVal );
787 }
788 
789 //*****************************************************************************
790 //
794 //
795 //*****************************************************************************
796 static void
798 {
799  //
800  // Currently no specific trim for Cold Reset
801  //
802 }
803 
804 //*****************************************************************************
805 //
807 //
808 //*****************************************************************************
809 static uint32_t
810 GetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg )
811 {
812  uint32_t ui32Fcfg1Value ;
813  uint32_t ui32XoscHfRow ;
814  uint32_t ui32XoscHfCol ;
815  int32_t i32CustomerDeltaAdjust ;
816  uint32_t ui32TrimValue ;
817 
818  // Use device specific trim values located in factory configuration
819  // area for the XOSC_HF_COLUMN_Q12 and XOSC_HF_ROW_Q12 bit fields in
820  // the ANABYPASS_VALUE1 register. Value for the other bit fields
821  // are set to 0.
822 
823  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP);
824  ui32XoscHfRow = (( ui32Fcfg1Value &
827  ui32XoscHfCol = (( ui32Fcfg1Value &
830 
831  i32CustomerDeltaAdjust = 0;
832  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_CAP_MOD ) == 0 ) {
833  // XOSC_CAP_MOD = 0 means: CAP_ARRAY_DELTA is in use -> Apply compensation
834  // XOSC_CAPARRAY_DELTA is located in bit[15:8] of ccfg_ModeConfReg
835  // Note: HW_REV_DEPENDENT_IMPLEMENTATION. Field width is not given by
836  // a define and sign extension must therefore be hardcoded.
837  // ( A small test program is created verifying the code lines below:
838  // Ref.: ..\test\small_standalone_test_programs\CapArrayDeltaAdjust_test.c)
839  i32CustomerDeltaAdjust = ((int32_t)ccfg_ModeConfReg << 16 ) >> 24;
840 
841  while ( i32CustomerDeltaAdjust < 0 ) {
842  ui32XoscHfCol >>= 1; // COL 1 step down
843  if ( ui32XoscHfCol == 0 ) { // if COL below minimum
844  ui32XoscHfCol = 0xFFFF; // Set COL to maximum
845  ui32XoscHfRow >>= 1; // ROW 1 step down
846  if ( ui32XoscHfRow == 0 ) { // if ROW below minimum
847  ui32XoscHfRow = 1; // Set both ROW and COL
848  ui32XoscHfCol = 1; // to minimum
849  }
850  }
851  i32CustomerDeltaAdjust++;
852  }
853  while ( i32CustomerDeltaAdjust > 0 ) {
854  ui32XoscHfCol = ( ui32XoscHfCol << 1 ) | 1; // COL 1 step up
855  if ( ui32XoscHfCol > 0xFFFF ) { // if COL above maximum
856  ui32XoscHfCol = 1; // Set COL to minimum
857  ui32XoscHfRow = ( ui32XoscHfRow << 1 ) | 1; // ROW 1 step up
858  if ( ui32XoscHfRow > 0xF ) { // if ROW above maximum
859  ui32XoscHfRow = 0xF; // Set both ROW and COL
860  ui32XoscHfCol = 0xFFFF; // to maximum
861  }
862  }
863  i32CustomerDeltaAdjust--;
864  }
865  }
866 
867  ui32TrimValue = (( ui32XoscHfRow << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
868  ( ui32XoscHfCol << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
869 
870  return (ui32TrimValue);
871 }
872 
873 //*****************************************************************************
874 //
877 //
878 //*****************************************************************************
879 static uint32_t
881 {
882  uint32_t ui32TrimValue;
883 
884  // Use device specific trim values located in factory configuration
885  // area
886  ui32TrimValue =
891 
892  ui32TrimValue |=
897 
898  return(ui32TrimValue);
899 }
900 
901 //*****************************************************************************
902 //
905 //
906 //*****************************************************************************
907 static uint32_t
909 {
910  uint32_t ui32TrimValue;
911 
912  // Use device specific trim value located in factory configuration
913  // area
914  ui32TrimValue =
918 
919  return(ui32TrimValue);
920 }
921 
922 //*****************************************************************************
923 //
925 //
926 //*****************************************************************************
927 static uint32_t
929 {
930  uint32_t ui32TrimValue;
931  uint32_t ui32Fcfg1Value;
932 
933  // Use device specific trim value located in factory configuration
934  // area. All defined register bit fields have corresponding trim
935  // value in the factory configuration area
936  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH2);
937  ui32TrimValue = ((ui32Fcfg1Value &
941  ui32TrimValue |= (((ui32Fcfg1Value &
945  ui32TrimValue |= (((ui32Fcfg1Value &
949  ui32TrimValue |= (((ui32Fcfg1Value &
953 
954  return(ui32TrimValue);
955 }
956 
957 //*****************************************************************************
958 //
960 //
961 //*****************************************************************************
962 static uint32_t
964 {
965  uint32_t ui32TrimValue;
966  uint32_t ui32Fcfg1Value;
967 
968  // Use device specific trim values located in factory configuration
969  // area. All defined register bit fields have a corresponding trim
970  // value in the factory configuration area
971  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH1);
972  ui32TrimValue = (((ui32Fcfg1Value &
976  ui32TrimValue |= (((ui32Fcfg1Value &
980  ui32TrimValue |= (((ui32Fcfg1Value &
984  ui32TrimValue |= (((ui32Fcfg1Value &
988 
989  return(ui32TrimValue);
990 }
991 
992 //*****************************************************************************
993 //
995 //
996 //*****************************************************************************
997 static uint32_t
998 GetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision )
999 {
1000  uint32_t ui32TrimValue ;
1001  uint32_t ui32Fcfg1Value ;
1002  uint32_t ibiasOffset ;
1003  uint32_t ibiasInit ;
1004  uint32_t modeConf1 ;
1005  int32_t deltaAdjust ;
1006 
1007  // Use device specific trim values located in factory configuration
1008  // area. Register bit fields without trim values in the factory
1009  // configuration area will be set to the value of 0.
1010  ui32Fcfg1Value = HWREG( FCFG1_BASE + FCFG1_O_AMPCOMP_CTRL1 );
1011 
1012  ibiasOffset = ( ui32Fcfg1Value &
1015  ibiasInit = ( ui32Fcfg1Value &
1018 
1020  // Adjust with DELTA_IBIAS_OFFSET and DELTA_IBIAS_INIT from CCFG
1021  modeConf1 = HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 );
1022 
1023  // Both fields are signed 4-bit values. This is an assumption when doing the sign extension.
1024  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_OFFSET_S - 4 )) >> 28;
1025  deltaAdjust += (int32_t)ibiasOffset;
1026  if ( deltaAdjust < 0 ) {
1027  deltaAdjust = 0;
1028  }
1031  }
1032  ibiasOffset = (uint32_t)deltaAdjust;
1033 
1034  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_INIT_S - 4 )) >> 28;
1035  deltaAdjust += (int32_t)ibiasInit;
1036  if ( deltaAdjust < 0 ) {
1037  deltaAdjust = 0;
1038  }
1041  }
1042  ibiasInit = (uint32_t)deltaAdjust;
1043  }
1044  ui32TrimValue = ( ibiasOffset << DDI_0_OSC_AMPCOMPCTL_IBIAS_OFFSET_S ) |
1045  ( ibiasInit << DDI_0_OSC_AMPCOMPCTL_IBIAS_INIT_S ) ;
1046 
1047  ui32TrimValue |= (((ui32Fcfg1Value &
1051  ui32TrimValue |= (((ui32Fcfg1Value &
1055  ui32TrimValue |= (((ui32Fcfg1Value &
1059 
1060  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1061  ui32TrimValue |= ((( ui32Fcfg1Value &
1065  }
1066 
1067  return(ui32TrimValue);
1068 }
1069 
1070 //*****************************************************************************
1071 //
1073 //
1074 //*****************************************************************************
1075 static uint32_t
1076 GetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision )
1077 {
1078  uint32_t dblrLoopFilterResetVoltageValue = 0; // Reset value
1079 
1080  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1081  dblrLoopFilterResetVoltageValue = ( HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 ) &
1084  }
1085 
1086  return ( dblrLoopFilterResetVoltageValue );
1087 }
1088 
1089 //*****************************************************************************
1090 //
1092 //
1093 //*****************************************************************************
1094 static uint32_t
1095 GetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision )
1096 {
1097  uint32_t getTrimForAdcShModeEnValue = 1; // Recommended default setting
1098 
1099  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1100  getTrimForAdcShModeEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1103  }
1104 
1105  return ( getTrimForAdcShModeEnValue );
1106 }
1107 
1108 //*****************************************************************************
1109 //
1111 //
1112 //*****************************************************************************
1113 static uint32_t
1114 GetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision )
1115 {
1116  uint32_t getTrimForAdcShVbufEnValue = 1; // Recommended default setting
1117 
1118  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1119  getTrimForAdcShVbufEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1122  }
1123 
1124  return ( getTrimForAdcShVbufEnValue );
1125 }
1126 
1127 //*****************************************************************************
1128 //
1130 //
1131 //*****************************************************************************
1132 static uint32_t
1133 GetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision )
1134 {
1135  uint32_t getTrimForXoschfCtlValue = 0; // Recommended default setting
1136  uint32_t fcfg1Data;
1137 
1138  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1139  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1140  getTrimForXoschfCtlValue =
1141  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_PEAK_DET_ITRIM_M ) >>
1144 
1145  getTrimForXoschfCtlValue |=
1146  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HP_BUF_ITRIM_M ) >>
1149 
1150  getTrimForXoschfCtlValue |=
1151  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LP_BUF_ITRIM_M ) >>
1154  }
1155 
1156  return ( getTrimForXoschfCtlValue );
1157 }
1158 
1159 //*****************************************************************************
1160 //
1162 //
1163 //*****************************************************************************
1164 static uint32_t
1166 {
1167  uint32_t ui32XoscHfFastStartValue ;
1168 
1169  // Get value from FCFG1
1170  ui32XoscHfFastStartValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1173 
1174  return ( ui32XoscHfFastStartValue );
1175 }
1176 
1177 //*****************************************************************************
1178 //
1180 //
1181 //*****************************************************************************
1182 static uint32_t
1183 GetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision )
1184 {
1185  uint32_t getTrimForRadcExtCfgValue = 0x403F8000; // Recommended default setting
1186  uint32_t fcfg1Data;
1187 
1188  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1189  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1190  getTrimForRadcExtCfgValue =
1191  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HPM_IBIAS_WAIT_CNT_M ) >>
1194 
1195  getTrimForRadcExtCfgValue |=
1196  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LPM_IBIAS_WAIT_CNT_M ) >>
1199 
1200  getTrimForRadcExtCfgValue |=
1201  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_IDAC_STEP_M ) >>
1204  }
1205 
1206  return ( getTrimForRadcExtCfgValue );
1207 }
1208 
1209 //*****************************************************************************
1210 //
1212 //
1213 //*****************************************************************************
1214 static uint32_t
1215 GetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision )
1216 {
1217  uint32_t trimForRcOscLfIBiasTrimValue = 0; // Default value
1218 
1219  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1220  trimForRcOscLfIBiasTrimValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1223  }
1224 
1225  return ( trimForRcOscLfIBiasTrimValue );
1226 }
1227 
1228 //*****************************************************************************
1229 //
1232 //
1233 //*****************************************************************************
1234 static uint32_t
1235 GetTrimForXoscLfRegulatorAndCmirrwrRatio( uint32_t ui32Fcfg1Revision )
1236 {
1237  uint32_t trimForXoscLfRegulatorAndCmirrwrRatioValue = 0; // Default value for both fields
1238 
1239  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1240  trimForXoscLfRegulatorAndCmirrwrRatioValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1244  }
1245 
1246  return ( trimForXoscLfRegulatorAndCmirrwrRatioValue );
1247 }
1248 
1249 
1250 //*****************************************************************************
1251 //
1252 // SetVddrLevel()
1253 // Set VDDR boost mode (by setting VDDR_TRIM to FCFG1..VDDR_TRIM_HH and setting VDDS_BOD to max)
1254 //
1255 //*****************************************************************************
1256 void
1257 SetVddrLevel( uint32_t ccfg_ModeConfReg )
1258 {
1259  uint32_t newTrimRaw ;
1260  int32_t targetTrim ;
1261  int32_t currentTrim ;
1262  int32_t deltaTrim ;
1263 
1264 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
1265  //
1266  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
1267  // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_HH
1268  //
1269  newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1272 // } else {
1273 // //
1274 // // VDDS_BOD_LEVEL = 0
1275 // // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_H
1276 // //
1277 // newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1280 // }
1281  targetTrim = SignExtendVddrTrimValue( newTrimRaw );
1282  currentTrim = SignExtendVddrTrimValue((
1283  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_DCDCCTL0 ) &
1286 
1287  if ( currentTrim != targetTrim ) {
1288  // Disable VDDR BOD
1290 
1291  while ( currentTrim != targetTrim ) {
1292  deltaTrim = targetTrim - currentTrim;
1293  if ( deltaTrim > 2 ) deltaTrim = 2;
1294  if ( deltaTrim < -2 ) deltaTrim = -2;
1295  currentTrim += deltaTrim;
1296 
1297  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1298 
1299  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL0 * 2 )) =
1300  ( ADI_3_REFSYS_DCDCCTL0_VDDR_TRIM_M << 8 ) | (( currentTrim <<
1303 
1304  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1305  }
1306 
1307  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1308  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1309  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one more SCLK_LF period before re-enabling VDDR BOD
1311  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // And finally wait for VDDR_LOSS_EN setting to propagate
1312  }
1313 }
static void SysCtrlAonSync(void)
Sync all accesses to the AON register interface.
Definition: sys_ctrl.h:244
#define IOC_PORT_AON_CLK32K
Definition: ioc.h:169
static 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.h:235
#define AUX_WUC_POWER_DOWN
Definition: aux_wuc.h:95
static void HapiTrimDevicePowerDown(void)
Trims to be applied when coming from POWER_DOWN (also called when coming from SHUTDOWN and PIN_RESET)...
Definition: setup.c:333
static void HapiTrimDeviceShutDown(uint32_t ui32Fcfg1Revision)
Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET).
Definition: setup.c:375
static uint32_t GetTrimForRadcExtCfg(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the RADCEXTCFG register in OSC_DIG.
Definition: setup.c:1183
void AUXWUCPowerCtrl(uint32_t ui32PowerMode)
Control the power to the AUX domain.
Definition: aux_wuc.c:274
static uint32_t GetTrimForRcOscLfRtuneCtuneTrim(void)
Returns the trim value to be used for the RCOSCLF_RTUNE_TRIM and the RCOSCLF_CTUNE_TRIM bit fields in...
Definition: setup.c:880
uint32_t OSCClockSourceGet(uint32_t ui32SrcClk)
Get the source clock settings.
Definition: osc.c:145
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:108
#define IOC_STD_INPUT
Definition: ioc.h:292
int32_t SignExtendVddrTrimValue(uint32_t ui32VddrTrimVal)
Sign extend the VDDR_TRIM setting (special format ranging from -10 to +21)
Definition: setup.c:776
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:169
static uint32_t GetTrimForRcOscLfIBiasTrim(uint32_t ui32Fcfg1Revision)
Returns the FCFG1 OSC_CONF_ATESTLF_RCOSCLF_IBIAS_TRIM.
Definition: setup.c:1215
#define OSC_SRC_CLK_HF
Definition: osc.h:106
static uint32_t GetTrimForXoscLfRegulatorAndCmirrwrRatio(uint32_t ui32Fcfg1Revision)
Returns XOSCLF_REGULATOR_TRIM and XOSCLF_CMIRRWR_RATIO as one packet spanning bits [5:0] in the retur...
Definition: setup.c:1235
#define OSC_XOSC_HF
Definition: osc.h:111
#define OSC_SRC_CLK_LF
Definition: osc.h:108
static uint32_t GetTrimForAmpcompTh2(void)
Returns the trim value to be used for the AMPCOMP_TH2 register in OSC_DIG.
Definition: setup.c:928
static uint32_t GetTrimForAnabypassValue1(uint32_t ccfg_ModeConfReg)
Returns the trim value to be used for the ANABYPASS_VALUE1 register in OSC_DIG.
Definition: setup.c:810
static uint32_t GetTrimForDblrLoopFilterResetVoltage(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as DBLR_LOOP_FILTER_RESET_VOLTAGE setting.
Definition: setup.c:1076
static void HapiTrimDeviceColdReset(void)
Trims to be applied when coming from PIN_RESET.
Definition: setup.c:797
static uint32_t GetTrimForXoscHfFastStart(void)
Returns the trim value to be used as OSC_DIG:CTL1.XOSC_HF_FAST_START.
Definition: setup.c:1165
static uint32_t GetTrimForAdcShVbufEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_VBUF_EN setting.
Definition: setup.c:1114
#define OSC_RCOSC_LF
Definition: osc.h:112
void IOCPortConfigureSet(uint32_t ui32IOId, uint32_t ui32PortId, uint32_t ui32IOConfig)
Set the configuration of an IO port.
Definition: ioc.c:96
#define IOC_HYST_ENABLE
Definition: ioc.h:216
static uint32_t GetTrimForXoscHfCtl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the XOSCHFCTL register in OSC_DIG.
Definition: setup.c:1133
static uint32_t GetTrimForAdcShModeEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_MODE_EN setting.
Definition: setup.c:1095
static void SetAonRtcSubSecInc(uint32_t subSecInc)
Doing the tricky stuff needed to enter new RTCSUBSECINC value.
Definition: setup.c:348
static uint32_t GetTrimForXoscHfIbiastherm(void)
Returns the trim value to be used for the XOSC_HF_IBIASTHERM bit field in the ANABYPASS_VALUE2 regist...
Definition: setup.c:908
void OSCClockSourceSet(uint32_t ui32SrcClk, uint32_t ui32Osc)
Configure the oscillator input to the a source clock.
Definition: osc.c:86
static void SetupCacheModeAccordingToCcfgSetting(void)
Set correct VIMS_MODE according to CCFG setting (CACHE or GPRAM)
Definition: setup.c:135
static uint32_t GetTrimForAmpcompTh1(void)
Returns the trim value to be used for the AMPCOMP_TH1 register in OSC_DIG.
Definition: setup.c:963
void SetVddrLevel(uint32_t ccfg_ModeConfReg)
Definition: setup.c:1257
#define OSC_XOSC_LF
Definition: osc.h:113
static uint32_t GetTrimForAmpcompCtrl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the AMPCOMP_CTRL register in OSC_DIG.
Definition: setup.c:998
void trimDevice(void)
Performs the necessary trim of the device which is not done in boot code.
Definition: setup.c:191
static void AONWUCJtagPowerOff(void)
Request power off of the JTAG domain.
Definition: aon_wuc.h:816