CC13xx Driver Library
setup.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: setup.c
3 * Revised: 2015-11-12 09:09:18 +0100 (Thu, 12 Nov 2015)
4 * Revision: 45045
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 // Need to know the CCFG:MODE_CONF.VDDR_TRIM_SLEEP_DELTA field width in order
129 // to sign extend correctly but this is however not defined in the hardware
130 // description fields and is therefore defined separately here.
131 //*****************************************************************************
132 #define CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_WIDTH 4
133 
134 
135 //*****************************************************************************
136 //
140 //
141 //*****************************************************************************
142 static void
144 {
145  //
146  // - Make sure to enable aggressive VIMS clock gating for power optimization
147  // Only for PG2 devices.
148  // - Enable cache prefetch enable as default setting
149  // (Slightly higher power consumption, but higher CPU performance)
150  // - IF ( CCFG_..._DIS_GPRAM == 1 )
151  // then: Enable cache (set cache mode = 1), even if set by ROM boot code
152  // (This is done because it's not set by boot code when running inside
153  // a debugger supporting the Halt In Boot (HIB) functionality).
154  // else: Set MODE_GPRAM if not already set (see inline comments as well)
155  //
156  uint32_t vimsCtlMode0 ;
157 
158  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
159  // Do nothing - wait for an eventual ongoing mode change to complete.
160  // (There should typically be no wait time here, but need to be sure)
161  }
162 
163  //
164  // Note that Mode=0 is equal to MODE_GPRAM
165  //
166  vimsCtlMode0 = (( HWREG( VIMS_BASE + VIMS_O_CTL ) & ~VIMS_CTL_MODE_M ) | VIMS_CTL_DYN_CG_EN_M | VIMS_CTL_PREF_EN_M );
167 
168 
170  // Enable cache (and hence disable GPRAM)
171  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_CACHE );
172  } else if (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_GPRAM ) {
173  //
174  // GPRAM is enabled in CCFG but not selected
175  // Note: It is recommended to go via MODE_OFF when switching to MODE_GPRAM
176  //
177  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_OFF );
178  while (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_OFF ) {
179  // Do nothing - wait for an eventual mode change to complete (This goes fast).
180  }
181  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
182  } else {
183  // Correct mode, but make sure PREF_EN and DYN_CG_EN always are set
184  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
185  }
186 }
187 
188 
189 //*****************************************************************************
190 //
191 // Perform the necessary trim of the device which is not done in boot code
192 //
193 // This function should only execute coming from ROM boot. The current
194 // implementation does not take soft reset into account. However, it does no
195 // damage to execute it again. It only consumes time.
196 //
197 //*****************************************************************************
198 void
200 {
201  uint32_t ui32Fcfg1Revision;
202  uint32_t ui32AonSysResetctl;
203 
204  //
205  // Get layout revision of the factory configuration area
206  // (Handle undefined revision as revision = 0)
207  //
208  ui32Fcfg1Revision = HWREG(FCFG1_BASE + FCFG1_O_FCFG1_REVISION);
209  if ( ui32Fcfg1Revision == 0xFFFFFFFF ) {
210  ui32Fcfg1Revision = 0;
211  }
212 
213 
214  //
215  // This driverlib version and setup file is for CC13xx PG2.0 and later.
216  // Halt if violated
217  //
219 
220  //
221  // Enable standby in flash bank
222  //
224 
225  //
226  // Clock must always be enabled for the semaphore module (due to ADI/DDI HW workaround)
227  //
229 
230  //
231  // Warm resets on CC26XX complicates software design as much of our software
232  // expect that initialization is done from a full system reset.
233  // This includes RTC setup, oscillator configuration and AUX setup.
234  // To ensure a full reset of the device is done when customers get e.g. a Watchdog
235  // reset, the following is set here:
236  //
238 
239  //
240  // Select correct CACHE mode and set correct CACHE configuration
241  //
243 
244  // 1. Check for powerdown
245  // 2. Check for shutdown
246  // 3. Assume cold reset if none of the above.
247  //
248  // It is always assumed that the application will freeze the latches in
249  // AON_IOC when going to powerdown in order to retain the values on the IOs.
250  //
251  // NB. If this bit is not cleared before proceeding to powerdown, the IOs
252  // will all default to the reset configuration when restarting.
254  {
255  //
256  // NB. This should be calling a ROM implementation of required trim and
257  // compensation
258  // e.g. HapiTrimDevicePowerDown()
260  }
261  // Check for shutdown
262  //
263  // When device is going to shutdown the hardware will automatically clear
264  // the SLEEPDIS bit in the SLEEP register in the AON_SYSCTRL12 module.
265  // It is left for the application to assert this bit when waking back up,
266  // but not before the desired IO configuration has been re-established.
268  {
269  //
270  // NB. This should be calling a ROM implementation of required trim and
271  // compensation
272  // e.g. HapiTrimDeviceShutDown() -->
273  // HapiTrimDevicePowerDown();
274  HapiTrimDeviceShutDown(ui32Fcfg1Revision);
276  }
277  else
278  {
279  // Consider adding a check for soft reset to allow debugging to skip
280  // this section!!!
281  //
282  // NB. This should be calling a ROM implementation of required trim and
283  // compensation
284  // e.g. HapiTrimDeviceColdReset() -->
285  // HapiTrimDeviceShutDown() -->
286  // HapiTrimDevicePowerDown()
288  HapiTrimDeviceShutDown(ui32Fcfg1Revision);
290 
291  }
292 
293  //
294  // Set VIMS power domain control.
295  // PDCTL1VIMS = 0 ==> VIMS power domain is only powered when CPU power domain is powered
296  //
297  HWREG( PRCM_BASE + PRCM_O_PDCTL1VIMS ) = 0;
298 
299  //
300  // Configure optimal wait time for flash FSM in cases where flash pump
301  // wakes up from sleep
302  //
303  HWREG(FLASH_BASE + FLASH_O_FPAC1) = (HWREG(FLASH_BASE + FLASH_O_FPAC1) &
305  (0x139<<FLASH_FPAC1_PSLEEPTDIS_S);
306 
307  //
308  // And finally at the end of the flash boot process:
309  // SET BOOT_DET bits in AON_SYSCTL to 3 if already found to be 1
310  // Note: The BOOT_DET_x_CLR/SET bits must be manually cleared
311  //
312  if ((( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
315  {
316  ui32AonSysResetctl = ( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
320  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl;
321  }
322 
323  //
324  // Make sure there are no ongoing VIMS mode change when leaving trimDevice()
325  // (There should typically be no wait time here, but need to be sure)
326  //
327  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
328  // Do nothing - wait for an eventual ongoing mode change to complete.
329  }
330 }
331 
332 //*****************************************************************************
333 //
338 //
339 //*****************************************************************************
340 static void
342 {
343  //
344  // Currently no specific trim for Powerdown
345  //
346 }
347 
348 //*****************************************************************************
349 //
353 //
354 //*****************************************************************************
355 static void
356 SetAonRtcSubSecInc( uint32_t subSecInc )
357 {
358  //
359  // Loading a new RTCSUBSECINC value is done in 5 steps:
360  // 1. Write bit[15:0] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC0
361  // 2. Write bit[23:16] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC1
363  // 4. Wait for AUX_WUC_RTCSUBSECINCCTL_UPD_ACK
365  //
367  HWREG( AUX_WUC_BASE + AUX_WUC_O_RTCSUBSECINC1 ) = (( subSecInc >> 16 ) & AUX_WUC_RTCSUBSECINC1_INC23_16_M );
368 
372 }
373 
374 //*****************************************************************************
375 //
380 //
381 //*****************************************************************************
382 static void
383 HapiTrimDeviceShutDown(uint32_t ui32Fcfg1Revision)
384 {
385  uint32_t ui32Trim ;
386  uint32_t ccfg_ModeConfReg ;
387  uint32_t currentHfClock ;
388  uint32_t ccfgExtLfClk ;
389  int32_t i32VddrSleepTrim ;
390  int32_t i32VddrSleepDelta ;
391  uint32_t fcfg1OscConf ;
392 
393  //
394  // Force AUX on and enable clocks
395  //
396  // No need to save the current status of the power/clock registers.
397  // At this point both AUX and AON should have been reset to 0x0.
398  //
400 
401  //
402  // Wait for power on on the AUX domain
403  //
405 
406  //
407  // Enable the clocks for AUX_DDI0_OSC and AUX_ADI4
408  //
411 
412  //
413  // It's found to be optimal to override the FCFG1..DCDC_IPEAK setting as follows:
414  // if ( alternative DCDC setting in CCFG is enabled ) ADI3..IPEAK = CCFG..DCDC_IPEAK
415  // else ADI3..IPEAK = 2
416  //
418  //
419  // ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
420  // ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
421  // Using a single 4-bit masked write since layout is equal for both source and destination
422  //
423  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
425 
426  // Shall use FCFG1 setting for CC13xx
427  } else {
428  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = 0x72;
429  }
430 
431  //
432  // Enable for JTAG to be powered down (will still be powered on if debugger is connected)
433  //
435 
436  //
437  // read the MODE_CONF register in CCFG
438  //
439  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
440 
441  //
442  // Check for CC13xx boost mode
443  // The combination VDDR_EXT_LOAD=0 and VDDS_BOD_LEVEL=1 is defined to selct boost mode
444  //
445  if ((( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_EXT_LOAD ) == 0 ) &&
446  (( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) != 0 ) ) {
447  //
448  // Set VDDS_BOD trim - using masked write {MASK8:DATA8}
449  // - TRIM_VDDS_BOD is bits[7:3] of ADI3..REFSYSCTL1
450  // - Needs a positive transition on BOD_BG_TRIM_EN (bit[7] of REFSYSCTL3) to
451  // latch new VDDS BOD. Set to 0 first to guarantee a positive transition.
452  //
454 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
455  //
456  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
457  // - Max out the VDDS_BOD trim (=VDDS_BOD_POS_31)
458  //
459  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
462 // } else {
463 // //
464 // // VDDS_BOD_LEVEL = 0
465 // // - Set VDDS_BOD to FCFG1..TRIMBOD_H
466 // //
467 // HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_REFSYSCTL1 * 2 )) =
469 // ((( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
472 // }
474 
475  SetVddrLevel( ccfg_ModeConfReg );
476 
477  i32VddrSleepTrim = SignExtendVddrTrimValue((
478  HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
481  } else
482  {
483  i32VddrSleepTrim = SignExtendVddrTrimValue((
484  HWREG( FCFG1_BASE + FCFG1_O_LDO_TRIM ) &
487  }
488 
489  //
490  // Adjust the VDDR_TRIM_SLEEP value with value adjustable by customer (CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA)
491  // Read and sign extend VddrSleepDelta (in range -8 to +7)
492  //
493  i32VddrSleepDelta = ((((int32_t)ccfg_ModeConfReg )
496  // Calculate new VDDR sleep trim
497  i32VddrSleepTrim = ( i32VddrSleepTrim + i32VddrSleepDelta + 1 );
498  if ( i32VddrSleepTrim > 21 ) i32VddrSleepTrim = 21;
499  if ( i32VddrSleepTrim < -10 ) i32VddrSleepTrim = -10;
500  // Write adjusted value using MASKED write (MASK8)
501  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL1 * 2 )) = (( ADI_3_REFSYS_DCDCCTL1_VDDR_TRIM_SLEEP_M << 8 ) |
503 
504  //
505  // set the RECHARGE source based upon CCFG:MODE_CONF:DCDC_RECHARGE
506  // Note: Inverse polarity
507  //
509  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_RECHARGE_S ) & 1 ) ^ 1 );
510 
511  //
512  // set the ACTIVE source based upon CCFG:MODE_CONF:DCDC_ACTIVE
513  // Note: Inverse polarity
514  //
516  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_ACTIVE_S ) & 1 ) ^ 1 );
517 
518  //
519  // Following sequence is required for using XOSCHF, if not included
520  // devices crashes when trying to switch to XOSCHF.
521  //
522  // Trim CAP settings. Get and set trim value for the ANABYPASS_VALUE1
523  // register
524  ui32Trim = GetTrimForAnabypassValue1( ccfg_ModeConfReg );
526 
527  // Trim RCOSC_LF. Get and set trim values for the RCOSCLF_RTUNE_TRIM and
528  // RCOSCLF_CTUNE_TRIM fields in the XOSCLF_RCOSCLF_CTRL register.
529  ui32Trim = GetTrimForRcOscLfRtuneCtuneTrim();
534  ui32Trim);
535 
536  // Trim XOSCHF IBIAS THERM. Get and set trim value for the
537  // XOSCHF IBIAS THERM bit field in the ANABYPASS_VALUE2 register. Other
538  // register bit fields are set to 0.
539  ui32Trim = GetTrimForXoscHfIbiastherm();
542 
543  // Trim AMPCOMP settings required before switch to XOSCHF
544  ui32Trim = GetTrimForAmpcompTh2();
546  ui32Trim = GetTrimForAmpcompTh1();
548  ui32Trim = GetTrimForAmpcompCtrl( ui32Fcfg1Revision );
550 
551  //
552  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_MODE_EN in accordance to FCFG1 setting
553  // This is bit[5] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
554  // Using MASK4 write + 1 => writing to bits[7:4]
555  //
556  ui32Trim = GetTrimForAdcShModeEn( ui32Fcfg1Revision );
557  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
558  ( 0x20 | ( ui32Trim << 1 ));
559 
560  //
561  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_VBUF_EN in accordance to FCFG1 setting
562  // This is bit[4] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
563  // Using MASK4 write + 1 => writing to bits[7:4]
564  //
565  ui32Trim = GetTrimForAdcShVbufEn( ui32Fcfg1Revision );
566  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
567  ( 0x10 | ( ui32Trim ));
568 
569  //
570  // Set trim for the PEAK_DET_ITRIM, HP_BUF_ITRIM and LP_BUF_ITRIM bit fields
571  // in the DDI0_OSC_O_XOSCHFCTL register in accordance to FCFG1 setting.
572  // Remaining register bit fields are set to their reset values of 0.
573  //
574  ui32Trim = GetTrimForXoscHfCtl(ui32Fcfg1Revision);
576 
577  //
578  // Set trim for DBLR_LOOP_FILTER_RESET_VOLTAGE in accordance to FCFG1 setting
579  // (This is bits [18:17] in DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL)
580  // (Using MASK4 write + 4 => writing to bits[19:16] => (4*4))
581  // (Assuming: DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_S = 17 and
582  // that DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_M = 0x00060000)
583  //
584  ui32Trim = GetTrimForDblrLoopFilterResetVoltage( ui32Fcfg1Revision );
585  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 4 ) =
586  ( 0x60 | ( ui32Trim << 1 ));
587 
588  //
589  // Update DDI_0_OSC_ATESTCTL_ATESTLF_RCOSCLF_IBIAS_TRIM with data from
591  // This is DDI_0_OSC_O_ATESTCTL bit[7]
592  // ( DDI_0_OSC_O_ATESTCTL is currently hidden (but=0x00000020))
593  // Using MASK4 write + 1 => writing to bits[7:4]
594  //
595  ui32Trim = GetTrimForRcOscLfIBiasTrim( ui32Fcfg1Revision );
596  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( 0x00000020 * 2 ) + 1 ) =
597  ( 0x80 | ( ui32Trim << 3 ));
598 
599  //
602  // This can be simplified since the registers are packed together in the same
603  // order both in FCFG1 and in the HW register.
604  // This spans DDI_0_OSC_O_LFOSCCTL bits[23:18]
605  // Using MASK8 write + 4 => writing to bits[23:16]
606  //
607  ui32Trim = GetTrimForXoscLfRegulatorAndCmirrwrRatio( ui32Fcfg1Revision );
608  HWREGH( AUX_DDI0_OSC_BASE + DDI_O_MASK8B + ( DDI_0_OSC_O_LFOSCCTL * 2 ) + 4 ) =
609  ( 0xFC00 | ( ui32Trim << 2 ));
610 
611  //
612  // Set trim the HPM_IBIAS_WAIT_CNT, LPM_IBIAS_WAIT_CNT and IDAC_STEP bit
613  // fields in the DDI0_OSC_O_RADCEXTCFG register in accordance to FCFG1 setting.
614  // Remaining register bit fields are set to their reset values of 0.
615  //
616  ui32Trim = GetTrimForRadcExtCfg(ui32Fcfg1Revision);
618 
619  // Setting FORCE_KICKSTART_EN (ref. CC26_V1_BUG00261). Should also be done for PG2
620  // (This is bit 22 in DDI_0_OSC_O_CTL0)
622 
623  //
624  // Examin the XOSC_FREQ field to select 0x1=HPOSC, 0x2=48MHz XOSC, 0x3=24MHz XOSC
625  //
626  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_FREQ_M ) >> CCFG_MODE_CONF_XOSC_FREQ_S ) {
627  case 2 :
628  // XOSC source is a 48 MHz xtal
629  // Do nothing (since this is the reset setting)
630  break;
631  case 1 :
632  // XOSC source is HPOSC (trim the HPOSC if this is a chip with HPOSC, otherwise skip trimming and default to 24 MHz XOSC)
633 
634  fcfg1OscConf = HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF );
635 
636  if (( fcfg1OscConf & FCFG1_OSC_CONF_HPOSC_OPTION ) == 0 ) {
637  // This is a HPOSC chip, apply HPOSC settings
638  // Set bit DDI_0_OSC_CTL0_HPOSC_MODE_EN (this is bit 14 in DDI_0_OSC_O_CTL0)
640 
648 
661  break;
662  }
663  // Not a HPOSC chip - fall through to default
664  default :
665  // XOSC source is a 24 MHz xtal (default)
666  // Set bit DDI_0_OSC_CTL0_XTAL_IS_24M (this is bit 31 in DDI_0_OSC_O_CTL0)
668  break;
669  }
670 
671  // Clear DDI_0_OSC_CTL0_CLK_LOSS_EN (ClockLossEventEnable()). This is bit 9 in DDI_0_OSC_O_CTL0.
672  // This is typically already 0 except on Lizard where it is set in ROM-boot
674 
675  // Setting DDI_0_OSC_CTL1_XOSC_HF_FAST_START according to value found in FCFG1
676  ui32Trim = GetTrimForXoscHfFastStart();
677  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_CTL1 * 2 )) = ( 0x30 | ui32Trim );
678 
679  //
680  // setup the LF clock based upon CCFG:MODE_CONF:SCLK_LF_OPTION
681  //
682  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_SCLK_LF_OPTION_M ) >> CCFG_MODE_CONF_SCLK_LF_OPTION_S ) {
683  case 0 : // XOSC_HF_DLF (XOSCHF/1536) -> SCLK_LF (=31250Hz)
685  SetAonRtcSubSecInc( 0x8637BD );
686  break;
687  case 1 : // EXTERNAL signal -> SCLK_LF (frequency=2^38/CCFG_EXT_LF_CLK_RTC_INCREMENT)
688  // Set SCLK_LF to use the same source as SCLK_HF
689  // Can be simplified a bit since possible return values for HF matches LF settings
690  currentHfClock = OSCClockSourceGet( OSC_SRC_CLK_HF );
691  OSCClockSourceSet( OSC_SRC_CLK_LF, currentHfClock );
692  while( OSCClockSourceGet( OSC_SRC_CLK_LF ) != currentHfClock ) {
693  // Wait until switched
694  }
695  ccfgExtLfClk = HWREG( CCFG_BASE + CCFG_O_EXT_LF_CLK );
699  IOC_STD_INPUT | IOC_HYST_ENABLE ); // Route external clock to AON IOC w/hysteresis
700  // Set XOSC_LF in bypass mode to allow external 32k clock
702  // Fall through to set XOSC_LF as SCLK_LF source
703  case 2 : // XOSC_LF -> SLCK_LF (32768 Hz)
705  break;
706  default : // (=3) RCOSC_LF
708  break;
709  }
710 
711  //
712  // Update ADI_4_AUX_ADCREF1_VTRIM with value from FCFG1
713  //
714  HWREGB( AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF1 ) =
719 
720  //
721  // Set ADI_4_AUX:ADC0.SMPL_CYCLE_EXP to it's default minimum value (=3)
722  // (Note: Using MASK8B requires that the bits to be modified must be within the same
723  // byte boundary which is the case for the ADI_4_AUX_ADC0_SMPL_CYCLE_EXP field)
724  //
725  HWREGH( AUX_ADI4_BASE + ADI_O_MASK8B + ( ADI_4_AUX_O_ADC0 * 2 )) =
727 
728  //
729  // Sync with AON
730  //
731  SysCtrlAonSync();
732 
733  //
734  // Allow AUX to power down
735  //
737 
738  //
739  // Leaving on AUX and clock for AUX_DDI0_OSC on but turn off clock for AUX_ADI4
740  //
742 
743  // Disable EFUSE clock
745 }
746 
747 //*****************************************************************************
748 //
752 //
753 //*****************************************************************************
754 int32_t
755 SignExtendVddrTrimValue( uint32_t ui32VddrTrimVal )
756 {
757  //
758  // The VDDR trim value is 5 bits representing the range from -10 to +21
759  // (where -10=0x16, -1=0x1F, 0=0x00, 1=0x01 and +21=0x15)
760  //
761  int32_t i32SignedVddrVal = ui32VddrTrimVal;
762  if ( i32SignedVddrVal > 0x15 ) {
763  i32SignedVddrVal -= 0x20;
764  }
765  return ( i32SignedVddrVal );
766 }
767 
768 //*****************************************************************************
769 //
773 //
774 //*****************************************************************************
775 static void
777 {
778  //
779  // Currently no specific trim for Cold Reset
780  //
781 }
782 
783 //*****************************************************************************
784 //
786 //
787 //*****************************************************************************
788 static uint32_t
789 GetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg )
790 {
791  uint32_t ui32Fcfg1Value ;
792  uint32_t ui32XoscHfRow ;
793  uint32_t ui32XoscHfCol ;
794  int32_t i32CustomerDeltaAdjust ;
795  uint32_t ui32TrimValue ;
796 
797  // Use device specific trim values located in factory configuration
798  // area for the XOSC_HF_COLUMN_Q12 and XOSC_HF_ROW_Q12 bit fields in
799  // the ANABYPASS_VALUE1 register. Value for the other bit fields
800  // are set to 0.
801 
802  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP);
803  ui32XoscHfRow = (( ui32Fcfg1Value &
806  ui32XoscHfCol = (( ui32Fcfg1Value &
809 
810  i32CustomerDeltaAdjust = 0;
811  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_CAP_MOD ) == 0 ) {
812  // XOSC_CAP_MOD = 0 means: CAP_ARRAY_DELTA is in use -> Apply compensation
813  // XOSC_CAPARRAY_DELTA is located in bit[15:8] of ccfg_ModeConfReg
814  // Note: HW_REV_DEPENDENT_IMPLEMENTATION. Field width is not given by
815  // a define and sign extension must therefore be hardcoded.
816  // ( A small test program is created verifying the code lines below:
817  // Ref.: ..\test\small_standalone_test_programs\CapArrayDeltaAdjust_test.c)
818  i32CustomerDeltaAdjust = ((int32_t)ccfg_ModeConfReg << 16 ) >> 24;
819 
820  while ( i32CustomerDeltaAdjust < 0 ) {
821  ui32XoscHfCol >>= 1; // COL 1 step down
822  if ( ui32XoscHfCol == 0 ) { // if COL below minimum
823  ui32XoscHfCol = 0xFFFF; // Set COL to maximum
824  ui32XoscHfRow >>= 1; // ROW 1 step down
825  if ( ui32XoscHfRow == 0 ) { // if ROW below minimum
826  ui32XoscHfRow = 1; // Set both ROW and COL
827  ui32XoscHfCol = 1; // to minimum
828  }
829  }
830  i32CustomerDeltaAdjust++;
831  }
832  while ( i32CustomerDeltaAdjust > 0 ) {
833  ui32XoscHfCol = ( ui32XoscHfCol << 1 ) | 1; // COL 1 step up
834  if ( ui32XoscHfCol > 0xFFFF ) { // if COL above maximum
835  ui32XoscHfCol = 1; // Set COL to minimum
836  ui32XoscHfRow = ( ui32XoscHfRow << 1 ) | 1; // ROW 1 step up
837  if ( ui32XoscHfRow > 0xF ) { // if ROW above maximum
838  ui32XoscHfRow = 0xF; // Set both ROW and COL
839  ui32XoscHfCol = 0xFFFF; // to maximum
840  }
841  }
842  i32CustomerDeltaAdjust--;
843  }
844  }
845 
846  ui32TrimValue = (( ui32XoscHfRow << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
847  ( ui32XoscHfCol << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
848 
849  return (ui32TrimValue);
850 }
851 
852 //*****************************************************************************
853 //
856 //
857 //*****************************************************************************
858 static uint32_t
860 {
861  uint32_t ui32TrimValue;
862 
863  // Use device specific trim values located in factory configuration
864  // area
865  ui32TrimValue =
870 
871  ui32TrimValue |=
876 
877  return(ui32TrimValue);
878 }
879 
880 //*****************************************************************************
881 //
884 //
885 //*****************************************************************************
886 static uint32_t
888 {
889  uint32_t ui32TrimValue;
890 
891  // Use device specific trim value located in factory configuration
892  // area
893  ui32TrimValue =
897 
898  return(ui32TrimValue);
899 }
900 
901 //*****************************************************************************
902 //
904 //
905 //*****************************************************************************
906 static uint32_t
908 {
909  uint32_t ui32TrimValue;
910  uint32_t ui32Fcfg1Value;
911 
912  // Use device specific trim value located in factory configuration
913  // area. All defined register bit fields have corresponding trim
914  // value in the factory configuration area
915  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH2);
916  ui32TrimValue = ((ui32Fcfg1Value &
920  ui32TrimValue |= (((ui32Fcfg1Value &
924  ui32TrimValue |= (((ui32Fcfg1Value &
928  ui32TrimValue |= (((ui32Fcfg1Value &
932 
933  return(ui32TrimValue);
934 }
935 
936 //*****************************************************************************
937 //
939 //
940 //*****************************************************************************
941 static uint32_t
943 {
944  uint32_t ui32TrimValue;
945  uint32_t ui32Fcfg1Value;
946 
947  // Use device specific trim values located in factory configuration
948  // area. All defined register bit fields have a corresponding trim
949  // value in the factory configuration area
950  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH1);
951  ui32TrimValue = (((ui32Fcfg1Value &
955  ui32TrimValue |= (((ui32Fcfg1Value &
959  ui32TrimValue |= (((ui32Fcfg1Value &
963  ui32TrimValue |= (((ui32Fcfg1Value &
967 
968  return(ui32TrimValue);
969 }
970 
971 //*****************************************************************************
972 //
974 //
975 //*****************************************************************************
976 static uint32_t
977 GetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision )
978 {
979  uint32_t ui32TrimValue ;
980  uint32_t ui32Fcfg1Value ;
981  uint32_t ibiasOffset ;
982  uint32_t ibiasInit ;
983  uint32_t modeConf1 ;
984  int32_t deltaAdjust ;
985 
986  // Use device specific trim values located in factory configuration
987  // area. Register bit fields without trim values in the factory
988  // configuration area will be set to the value of 0.
989  ui32Fcfg1Value = HWREG( FCFG1_BASE + FCFG1_O_AMPCOMP_CTRL1 );
990 
991  ibiasOffset = ( ui32Fcfg1Value &
994  ibiasInit = ( ui32Fcfg1Value &
997 
999  // Adjust with DELTA_IBIAS_OFFSET and DELTA_IBIAS_INIT from CCFG
1000  modeConf1 = HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 );
1001 
1002  // Both fields are signed 4-bit values. This is an assumption when doing the sign extension.
1003  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_OFFSET_S - 4 )) >> 28;
1004  deltaAdjust += (int32_t)ibiasOffset;
1005  if ( deltaAdjust < 0 ) {
1006  deltaAdjust = 0;
1007  }
1010  }
1011  ibiasOffset = (uint32_t)deltaAdjust;
1012 
1013  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_INIT_S - 4 )) >> 28;
1014  deltaAdjust += (int32_t)ibiasInit;
1015  if ( deltaAdjust < 0 ) {
1016  deltaAdjust = 0;
1017  }
1020  }
1021  ibiasInit = (uint32_t)deltaAdjust;
1022  }
1023  ui32TrimValue = ( ibiasOffset << DDI_0_OSC_AMPCOMPCTL_IBIAS_OFFSET_S ) |
1024  ( ibiasInit << DDI_0_OSC_AMPCOMPCTL_IBIAS_INIT_S ) ;
1025 
1026  ui32TrimValue |= (((ui32Fcfg1Value &
1030  ui32TrimValue |= (((ui32Fcfg1Value &
1034  ui32TrimValue |= (((ui32Fcfg1Value &
1038 
1039  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1040  ui32TrimValue |= ((( ui32Fcfg1Value &
1044  }
1045 
1046  return(ui32TrimValue);
1047 }
1048 
1049 //*****************************************************************************
1050 //
1052 //
1053 //*****************************************************************************
1054 static uint32_t
1055 GetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision )
1056 {
1057  uint32_t dblrLoopFilterResetVoltageValue = 0; // Reset value
1058 
1059  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1060  dblrLoopFilterResetVoltageValue = ( HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 ) &
1063  }
1064 
1065  return ( dblrLoopFilterResetVoltageValue );
1066 }
1067 
1068 //*****************************************************************************
1069 //
1071 //
1072 //*****************************************************************************
1073 static uint32_t
1074 GetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision )
1075 {
1076  uint32_t getTrimForAdcShModeEnValue = 1; // Recommended default setting
1077 
1078  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1079  getTrimForAdcShModeEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1082  }
1083 
1084  return ( getTrimForAdcShModeEnValue );
1085 }
1086 
1087 //*****************************************************************************
1088 //
1090 //
1091 //*****************************************************************************
1092 static uint32_t
1093 GetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision )
1094 {
1095  uint32_t getTrimForAdcShVbufEnValue = 1; // Recommended default setting
1096 
1097  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1098  getTrimForAdcShVbufEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1101  }
1102 
1103  return ( getTrimForAdcShVbufEnValue );
1104 }
1105 
1106 //*****************************************************************************
1107 //
1109 //
1110 //*****************************************************************************
1111 static uint32_t
1112 GetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision )
1113 {
1114  uint32_t getTrimForXoschfCtlValue = 0; // Recommended default setting
1115  uint32_t fcfg1Data;
1116 
1117  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1118  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1119  getTrimForXoschfCtlValue =
1120  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_PEAK_DET_ITRIM_M ) >>
1123 
1124  getTrimForXoschfCtlValue |=
1125  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HP_BUF_ITRIM_M ) >>
1128 
1129  getTrimForXoschfCtlValue |=
1130  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LP_BUF_ITRIM_M ) >>
1133  }
1134 
1135  return ( getTrimForXoschfCtlValue );
1136 }
1137 
1138 //*****************************************************************************
1139 //
1141 //
1142 //*****************************************************************************
1143 static uint32_t
1145 {
1146  uint32_t ui32XoscHfFastStartValue ;
1147 
1148  // Get value from FCFG1
1149  ui32XoscHfFastStartValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1152 
1153  return ( ui32XoscHfFastStartValue );
1154 }
1155 
1156 //*****************************************************************************
1157 //
1159 //
1160 //*****************************************************************************
1161 static uint32_t
1162 GetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision )
1163 {
1164  uint32_t getTrimForRadcExtCfgValue = 0x403F8000; // Recommended default setting
1165  uint32_t fcfg1Data;
1166 
1167  if ( ui32Fcfg1Revision >= 0x00000020 ) {
1168  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
1169  getTrimForRadcExtCfgValue =
1170  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HPM_IBIAS_WAIT_CNT_M ) >>
1173 
1174  getTrimForRadcExtCfgValue |=
1175  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LPM_IBIAS_WAIT_CNT_M ) >>
1178 
1179  getTrimForRadcExtCfgValue |=
1180  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_IDAC_STEP_M ) >>
1183  }
1184 
1185  return ( getTrimForRadcExtCfgValue );
1186 }
1187 
1188 //*****************************************************************************
1189 //
1191 //
1192 //*****************************************************************************
1193 static uint32_t
1194 GetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision )
1195 {
1196  uint32_t trimForRcOscLfIBiasTrimValue = 0; // Default value
1197 
1198  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1199  trimForRcOscLfIBiasTrimValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1202  }
1203 
1204  return ( trimForRcOscLfIBiasTrimValue );
1205 }
1206 
1207 //*****************************************************************************
1208 //
1211 //
1212 //*****************************************************************************
1213 static uint32_t
1214 GetTrimForXoscLfRegulatorAndCmirrwrRatio( uint32_t ui32Fcfg1Revision )
1215 {
1216  uint32_t trimForXoscLfRegulatorAndCmirrwrRatioValue = 0; // Default value for both fields
1217 
1218  if ( ui32Fcfg1Revision >= 0x00000022 ) {
1219  trimForXoscLfRegulatorAndCmirrwrRatioValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
1223  }
1224 
1225  return ( trimForXoscLfRegulatorAndCmirrwrRatioValue );
1226 }
1227 
1228 
1229 //*****************************************************************************
1230 //
1231 // SetVddrLevel()
1232 // Set VDDR boost mode (by setting VDDR_TRIM to FCFG1..VDDR_TRIM_HH and setting VDDS_BOD to max)
1233 //
1234 //*****************************************************************************
1235 void
1236 SetVddrLevel( uint32_t ccfg_ModeConfReg )
1237 {
1238  uint32_t newTrimRaw ;
1239  int32_t targetTrim ;
1240  int32_t currentTrim ;
1241  int32_t deltaTrim ;
1242 
1243 // if ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) {
1244  //
1245  // VDDS_BOD_LEVEL = 1 means that boost mode is selected
1246  // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_HH
1247  //
1248  newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1251 // } else {
1252 // //
1253 // // VDDS_BOD_LEVEL = 0
1254 // // - Step up VDDR_TRIM to FCFG1..VDDR_TRIM_H
1255 // //
1256 // newTrimRaw = (( HWREG( FCFG1_BASE + FCFG1_O_VOLT_TRIM ) &
1259 // }
1260  targetTrim = SignExtendVddrTrimValue( newTrimRaw );
1261  currentTrim = SignExtendVddrTrimValue((
1262  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_DCDCCTL0 ) &
1265 
1266  if ( currentTrim != targetTrim ) {
1267  // Disable VDDR BOD
1269 
1270  while ( currentTrim != targetTrim ) {
1271  deltaTrim = targetTrim - currentTrim;
1272  if ( deltaTrim > 2 ) deltaTrim = 2;
1273  if ( deltaTrim < -2 ) deltaTrim = -2;
1274  currentTrim += deltaTrim;
1275 
1276  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1277 
1278  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL0 * 2 )) =
1279  ( ADI_3_REFSYS_DCDCCTL0_VDDR_TRIM_M << 8 ) | (( currentTrim <<
1282 
1283  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1284  }
1285 
1286  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one SCLK_LF period
1287  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ) = 1; // Force SCLK_LF period wait on next read
1288  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait one more SCLK_LF period before re-enabling VDDR BOD
1290  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // And finally wait for VDDR_LOSS_EN setting to propagate
1291  }
1292 }
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:341
static void HapiTrimDeviceShutDown(uint32_t ui32Fcfg1Revision)
Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET).
Definition: setup.c:383
static uint32_t GetTrimForRadcExtCfg(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the RADCEXTCFG register in OSC_DIG.
Definition: setup.c:1162
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:859
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:755
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:170
static uint32_t GetTrimForRcOscLfIBiasTrim(uint32_t ui32Fcfg1Revision)
Returns the FCFG1 OSC_CONF_ATESTLF_RCOSCLF_IBIAS_TRIM.
Definition: setup.c:1194
#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:1214
#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:907
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:789
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:1055
static void HapiTrimDeviceColdReset(void)
Trims to be applied when coming from PIN_RESET.
Definition: setup.c:776
static uint32_t GetTrimForXoscHfFastStart(void)
Returns the trim value to be used as OSC_DIG:CTL1.XOSC_HF_FAST_START.
Definition: setup.c:1144
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:1093
#define CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_WIDTH
Definition: setup.c:132
#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:1112
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:1074
static void SetAonRtcSubSecInc(uint32_t subSecInc)
Doing the tricky stuff needed to enter new RTCSUBSECINC value.
Definition: setup.c:356
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:887
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:143
static uint32_t GetTrimForAmpcompTh1(void)
Returns the trim value to be used for the AMPCOMP_TH1 register in OSC_DIG.
Definition: setup.c:942
void SetVddrLevel(uint32_t ccfg_ModeConfReg)
Definition: setup.c:1236
#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:977
void trimDevice(void)
Performs the necessary trim of the device which is not done in boot code.
Definition: setup.c:199
static void AONWUCJtagPowerOff(void)
Request power off of the JTAG domain.
Definition: aon_wuc.h:816