CC26xx Driver Library
setup_rom.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: setup_rom.c
3 * Revised: 2016-07-07 19:12:02 +0200 (to, 07 jul 2016)
4 * Revision: 46848
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 <inc/hw_memmap.h>
42 #include <inc/hw_adi.h>
43 #include <inc/hw_adi_2_refsys.h>
44 #include <inc/hw_adi_3_refsys.h>
45 #include <inc/hw_adi_4_aux.h>
46 #include <inc/hw_aon_batmon.h>
47 #include <inc/hw_aon_sysctl.h>
48 #include <inc/hw_ccfg.h>
49 #include <inc/hw_ddi_0_osc.h>
50 #include <inc/hw_fcfg1.h>
51 // Driverlib headers
52 #include <driverlib/ddi.h>
53 #include <driverlib/ioc.h>
54 #include <driverlib/osc.h>
55 #include <driverlib/sys_ctrl.h>
56 #include <driverlib/setup_rom.h>
57 // ##### INCLUDE IN ROM BEGIN #####
58 // We need intrinsic functions for IAR (if used in source code)
59 #ifdef __IAR_SYSTEMS_ICC__
60 #include <intrinsics.h>
61 #endif
62 // ##### INCLUDE IN ROM END #####
63 
64 //*****************************************************************************
65 //
66 // Handle support for DriverLib in ROM:
67 // This section will undo prototype renaming made in the header file
68 //
69 //*****************************************************************************
70 #if !defined(DOXYGEN)
71  #undef SetupAfterColdResetWakeupFromShutDownCfg1
72  #define SetupAfterColdResetWakeupFromShutDownCfg1 NOROM_SetupAfterColdResetWakeupFromShutDownCfg1
73  #undef SetupAfterColdResetWakeupFromShutDownCfg2
74  #define SetupAfterColdResetWakeupFromShutDownCfg2 NOROM_SetupAfterColdResetWakeupFromShutDownCfg2
75  #undef SetupAfterColdResetWakeupFromShutDownCfg3
76  #define SetupAfterColdResetWakeupFromShutDownCfg3 NOROM_SetupAfterColdResetWakeupFromShutDownCfg3
77  #undef SetupGetTrimForAdcShModeEn
78  #define SetupGetTrimForAdcShModeEn NOROM_SetupGetTrimForAdcShModeEn
79  #undef SetupGetTrimForAdcShVbufEn
80  #define SetupGetTrimForAdcShVbufEn NOROM_SetupGetTrimForAdcShVbufEn
81  #undef SetupGetTrimForAmpcompCtrl
82  #define SetupGetTrimForAmpcompCtrl NOROM_SetupGetTrimForAmpcompCtrl
83  #undef SetupGetTrimForAmpcompTh1
84  #define SetupGetTrimForAmpcompTh1 NOROM_SetupGetTrimForAmpcompTh1
85  #undef SetupGetTrimForAmpcompTh2
86  #define SetupGetTrimForAmpcompTh2 NOROM_SetupGetTrimForAmpcompTh2
87  #undef SetupGetTrimForAnabypassValue1
88  #define SetupGetTrimForAnabypassValue1 NOROM_SetupGetTrimForAnabypassValue1
89  #undef SetupGetTrimForDblrLoopFilterResetVoltage
90  #define SetupGetTrimForDblrLoopFilterResetVoltage NOROM_SetupGetTrimForDblrLoopFilterResetVoltage
91  #undef SetupGetTrimForRadcExtCfg
92  #define SetupGetTrimForRadcExtCfg NOROM_SetupGetTrimForRadcExtCfg
93  #undef SetupGetTrimForRcOscLfIBiasTrim
94  #define SetupGetTrimForRcOscLfIBiasTrim NOROM_SetupGetTrimForRcOscLfIBiasTrim
95  #undef SetupGetTrimForRcOscLfRtuneCtuneTrim
96  #define SetupGetTrimForRcOscLfRtuneCtuneTrim NOROM_SetupGetTrimForRcOscLfRtuneCtuneTrim
97  #undef SetupGetTrimForXoscHfCtl
98  #define SetupGetTrimForXoscHfCtl NOROM_SetupGetTrimForXoscHfCtl
99  #undef SetupGetTrimForXoscHfFastStart
100  #define SetupGetTrimForXoscHfFastStart NOROM_SetupGetTrimForXoscHfFastStart
101  #undef SetupGetTrimForXoscHfIbiastherm
102  #define SetupGetTrimForXoscHfIbiastherm NOROM_SetupGetTrimForXoscHfIbiastherm
103  #undef SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
104  #define SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio NOROM_SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio
105  #undef SetupSetCacheModeAccordingToCcfgSetting
106  #define SetupSetCacheModeAccordingToCcfgSetting NOROM_SetupSetCacheModeAccordingToCcfgSetting
107  #undef SetupSetAonRtcSubSecInc
108  #define SetupSetAonRtcSubSecInc NOROM_SetupSetAonRtcSubSecInc
109 #endif
110 
111 //*****************************************************************************
112 //
113 // Function declarations
114 //
115 //*****************************************************************************
116 
117 //*****************************************************************************
118 //
120 //
121 //*****************************************************************************
122 void
123 SetupAfterColdResetWakeupFromShutDownCfg1( uint32_t ccfg_ModeConfReg )
124 {
125  int32_t i32VddrSleepTrim;
126  int32_t i32VddrSleepDelta;
127 
128  {
129  i32VddrSleepTrim = SetupSignExtendVddrTrimValue((
130  HWREG( FCFG1_BASE + FCFG1_O_LDO_TRIM ) &
133  }
134 
135  //
136  // Adjust the VDDR_TRIM_SLEEP value with value adjustable by customer (CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA)
137  // Read and sign extend VddrSleepDelta (in range -8 to +7)
138  //
139  i32VddrSleepDelta = ((((int32_t)ccfg_ModeConfReg )
140  << ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_S ))
141  >> ( 32 - CCFG_MODE_CONF_VDDR_TRIM_SLEEP_DELTA_W ));
142  // Calculate new VDDR sleep trim
143  i32VddrSleepTrim = ( i32VddrSleepTrim + i32VddrSleepDelta + 1 );
144  if ( i32VddrSleepTrim > 21 ) i32VddrSleepTrim = 21;
145  if ( i32VddrSleepTrim < -10 ) i32VddrSleepTrim = -10;
146  // Write adjusted value using MASKED write (MASK8)
147  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL1 * 2 )) = (( ADI_3_REFSYS_DCDCCTL1_VDDR_TRIM_SLEEP_M << 8 ) |
149 
150  //
151  // 1.
152  // Do not allow DCDC to be enabled if in external regulator mode.
153  // Preventing this by setting both the RECHARGE and the ACTIVE bits bit in the CCFG_MODE_CONF copy register (ccfg_ModeConfReg).
154  //
155  // 2.
156  // Adjusted battery monitor low limit in internal regulator mode.
157  // This is done by setting AON_BATMON_FLASHPUMPP0_LOWLIM=0 in internal regulator mode.
158  //
161  } else {
163  }
164 
165  //
166  // set the RECHARGE source based upon CCFG:MODE_CONF:DCDC_RECHARGE
167  // Note: Inverse polarity
168  //
170  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_RECHARGE_S ) & 1 ) ^ 1 );
171 
172  //
173  // set the ACTIVE source based upon CCFG:MODE_CONF:DCDC_ACTIVE
174  // Note: Inverse polarity
175  //
177  ((( ccfg_ModeConfReg >> CCFG_MODE_CONF_DCDC_ACTIVE_S ) & 1 ) ^ 1 );
178 }
179 
180 //*****************************************************************************
181 //
183 //
184 //*****************************************************************************
185 void
186 SetupAfterColdResetWakeupFromShutDownCfg2( uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg )
187 {
188  uint32_t ui32Trim;
189 
190  //
191  // Following sequence is required for using XOSCHF, if not included
192  // devices crashes when trying to switch to XOSCHF.
193  //
194  // Trim CAP settings. Get and set trim value for the ANABYPASS_VALUE1
195  // register
196  ui32Trim = SetupGetTrimForAnabypassValue1( ccfg_ModeConfReg );
198 
199  // Trim RCOSC_LF. Get and set trim values for the RCOSCLF_RTUNE_TRIM and
200  // RCOSCLF_CTUNE_TRIM fields in the XOSCLF_RCOSCLF_CTRL register.
206  ui32Trim);
207 
208  // Trim XOSCHF IBIAS THERM. Get and set trim value for the
209  // XOSCHF IBIAS THERM bit field in the ANABYPASS_VALUE2 register. Other
210  // register bit fields are set to 0.
211  ui32Trim = SetupGetTrimForXoscHfIbiastherm();
214 
215  // Trim AMPCOMP settings required before switch to XOSCHF
216  ui32Trim = SetupGetTrimForAmpcompTh2();
218  ui32Trim = SetupGetTrimForAmpcompTh1();
220  ui32Trim = SetupGetTrimForAmpcompCtrl( ui32Fcfg1Revision );
222 
223  //
224  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_MODE_EN in accordance to FCFG1 setting
225  // This is bit[5] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
226  // Using MASK4 write + 1 => writing to bits[7:4]
227  //
228  ui32Trim = SetupGetTrimForAdcShModeEn( ui32Fcfg1Revision );
229  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
230  ( 0x20 | ( ui32Trim << 1 ));
231 
232  //
233  // Set trim for DDI_0_OSC_ADCDOUBLERNANOAMPCTL_ADC_SH_VBUF_EN in accordance to FCFG1 setting
234  // This is bit[4] in the DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL register
235  // Using MASK4 write + 1 => writing to bits[7:4]
236  //
237  ui32Trim = SetupGetTrimForAdcShVbufEn( ui32Fcfg1Revision );
238  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 1 ) =
239  ( 0x10 | ( ui32Trim ));
240 
241  //
242  // Set trim for the PEAK_DET_ITRIM, HP_BUF_ITRIM and LP_BUF_ITRIM bit fields
243  // in the DDI0_OSC_O_XOSCHFCTL register in accordance to FCFG1 setting.
244  // Remaining register bit fields are set to their reset values of 0.
245  //
246  ui32Trim = SetupGetTrimForXoscHfCtl(ui32Fcfg1Revision);
248 
249  //
250  // Set trim for DBLR_LOOP_FILTER_RESET_VOLTAGE in accordance to FCFG1 setting
251  // (This is bits [18:17] in DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL)
252  // (Using MASK4 write + 4 => writing to bits[19:16] => (4*4))
253  // (Assuming: DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_S = 17 and
254  // that DDI_0_OSC_ADCDOUBLERNANOAMPCTL_DBLR_LOOP_FILTER_RESET_VOLTAGE_M = 0x00060000)
255  //
256  ui32Trim = SetupGetTrimForDblrLoopFilterResetVoltage( ui32Fcfg1Revision );
257  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_ADCDOUBLERNANOAMPCTL * 2 ) + 4 ) =
258  ( 0x60 | ( ui32Trim << 1 ));
259 
260  //
261  // Update DDI_0_OSC_ATESTCTL_ATESTLF_RCOSCLF_IBIAS_TRIM with data from
263  // This is DDI_0_OSC_O_ATESTCTL bit[7]
264  // ( DDI_0_OSC_O_ATESTCTL is currently hidden (but=0x00000020))
265  // Using MASK4 write + 1 => writing to bits[7:4]
266  //
267  ui32Trim = SetupGetTrimForRcOscLfIBiasTrim( ui32Fcfg1Revision );
268  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( 0x00000020 * 2 ) + 1 ) =
269  ( 0x80 | ( ui32Trim << 3 ));
270 
271  //
274  // This can be simplified since the registers are packed together in the same
275  // order both in FCFG1 and in the HW register.
276  // This spans DDI_0_OSC_O_LFOSCCTL bits[23:18]
277  // Using MASK8 write + 4 => writing to bits[23:16]
278  //
279  ui32Trim = SetupGetTrimForXoscLfRegulatorAndCmirrwrRatio( ui32Fcfg1Revision );
280  HWREGH( AUX_DDI0_OSC_BASE + DDI_O_MASK8B + ( DDI_0_OSC_O_LFOSCCTL * 2 ) + 4 ) =
281  ( 0xFC00 | ( ui32Trim << 2 ));
282 
283  //
284  // Set trim the HPM_IBIAS_WAIT_CNT, LPM_IBIAS_WAIT_CNT and IDAC_STEP bit
285  // fields in the DDI0_OSC_O_RADCEXTCFG register in accordance to FCFG1 setting.
286  // Remaining register bit fields are set to their reset values of 0.
287  //
288  ui32Trim = SetupGetTrimForRadcExtCfg(ui32Fcfg1Revision);
290 
291  // Setting FORCE_KICKSTART_EN (ref. CC26_V1_BUG00261). Should also be done for PG2
292  // (This is bit 22 in DDI_0_OSC_O_CTL0)
294 }
295 
296 //*****************************************************************************
297 //
299 //
300 //*****************************************************************************
301 void
302 SetupAfterColdResetWakeupFromShutDownCfg3( uint32_t ccfg_ModeConfReg )
303 {
304  uint32_t fcfg1OscConf;
305  uint32_t ui32Trim;
306  uint32_t currentHfClock;
307  uint32_t ccfgExtLfClk;
308 
309  //
310  // Examin the XOSC_FREQ field to select 0x1=HPOSC, 0x2=48MHz XOSC, 0x3=24MHz XOSC
311  //
312  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_FREQ_M ) >> CCFG_MODE_CONF_XOSC_FREQ_S ) {
313  case 2 :
314  // XOSC source is a 48 MHz xtal
315  // Do nothing (since this is the reset setting)
316  break;
317  case 1 :
318  // XOSC source is HPOSC (trim the HPOSC if this is a chip with HPOSC, otherwise skip trimming and default to 24 MHz XOSC)
319 
320  fcfg1OscConf = HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF );
321 
322  if (( fcfg1OscConf & FCFG1_OSC_CONF_HPOSC_OPTION ) == 0 ) {
323  // This is a HPOSC chip, apply HPOSC settings
324  // Set bit DDI_0_OSC_CTL0_HPOSC_MODE_EN (this is bit 14 in DDI_0_OSC_O_CTL0)
326 
334 
347  break;
348  }
349  // Not a HPOSC chip - fall through to default
350  default :
351  // XOSC source is a 24 MHz xtal (default)
352  // Set bit DDI_0_OSC_CTL0_XTAL_IS_24M (this is bit 31 in DDI_0_OSC_O_CTL0)
354  break;
355  }
356 
357  //
358  // Set XOSC_HF in bypass mode if CCFG is configured for external TCXO
359  // 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.
360  //
363  }
364 
365  // Clear DDI_0_OSC_CTL0_CLK_LOSS_EN (ClockLossEventEnable()). This is bit 9 in DDI_0_OSC_O_CTL0.
366  // This is typically already 0 except on Lizard where it is set in ROM-boot
368 
369  // Setting DDI_0_OSC_CTL1_XOSC_HF_FAST_START according to value found in FCFG1
370  ui32Trim = SetupGetTrimForXoscHfFastStart();
371  HWREGB( AUX_DDI0_OSC_BASE + DDI_O_MASK4B + ( DDI_0_OSC_O_CTL1 * 2 )) = ( 0x30 | ui32Trim );
372 
373  //
374  // setup the LF clock based upon CCFG:MODE_CONF:SCLK_LF_OPTION
375  //
376  switch (( ccfg_ModeConfReg & CCFG_MODE_CONF_SCLK_LF_OPTION_M ) >> CCFG_MODE_CONF_SCLK_LF_OPTION_S ) {
377  case 0 : // XOSC_HF_DLF (XOSCHF/1536) -> SCLK_LF (=31250Hz)
379  SetupSetAonRtcSubSecInc( 0x8637BD );
380  break;
381  case 1 : // EXTERNAL signal -> SCLK_LF (frequency=2^38/CCFG_EXT_LF_CLK_RTC_INCREMENT)
382  // Set SCLK_LF to use the same source as SCLK_HF
383  // Can be simplified a bit since possible return values for HF matches LF settings
384  currentHfClock = OSCClockSourceGet( OSC_SRC_CLK_HF );
385  OSCClockSourceSet( OSC_SRC_CLK_LF, currentHfClock );
386  while( OSCClockSourceGet( OSC_SRC_CLK_LF ) != currentHfClock ) {
387  // Wait until switched
388  }
389  ccfgExtLfClk = HWREG( CCFG_BASE + CCFG_O_EXT_LF_CLK );
393  IOC_STD_INPUT | IOC_HYST_ENABLE ); // Route external clock to AON IOC w/hysteresis
394  // Set XOSC_LF in bypass mode to allow external 32k clock
396  // Fall through to set XOSC_LF as SCLK_LF source
397  case 2 : // XOSC_LF -> SLCK_LF (32768 Hz)
399  break;
400  default : // (=3) RCOSC_LF
402  break;
403  }
404 
405  //
406  // Update ADI_4_AUX_ADCREF1_VTRIM with value from FCFG1
407  //
408  HWREGB( AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF1 ) =
413 
414  //
415  // Set ADI_4_AUX:ADC0.SMPL_CYCLE_EXP to it's default minimum value (=3)
416  // (Note: Using MASK8B requires that the bits to be modified must be within the same
417  // byte boundary which is the case for the ADI_4_AUX_ADC0_SMPL_CYCLE_EXP field)
418  //
419  HWREGH( AUX_ADI4_BASE + ADI_O_MASK8B + ( ADI_4_AUX_O_ADC0 * 2 )) =
421 
422  //
423  // Sync with AON
424  //
425  SysCtrlAonSync();
426 }
427 
428 //*****************************************************************************
429 //
431 //
432 //*****************************************************************************
433 uint32_t
434 SetupGetTrimForAnabypassValue1( uint32_t ccfg_ModeConfReg )
435 {
436  uint32_t ui32Fcfg1Value ;
437  uint32_t ui32XoscHfRow ;
438  uint32_t ui32XoscHfCol ;
439  int32_t i32CustomerDeltaAdjust ;
440  uint32_t ui32TrimValue ;
441 
442  // Use device specific trim values located in factory configuration
443  // area for the XOSC_HF_COLUMN_Q12 and XOSC_HF_ROW_Q12 bit fields in
444  // the ANABYPASS_VALUE1 register. Value for the other bit fields
445  // are set to 0.
446 
447  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP);
448  ui32XoscHfRow = (( ui32Fcfg1Value &
451  ui32XoscHfCol = (( ui32Fcfg1Value &
454 
455  i32CustomerDeltaAdjust = 0;
456  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_XOSC_CAP_MOD ) == 0 ) {
457  // XOSC_CAP_MOD = 0 means: CAP_ARRAY_DELTA is in use -> Apply compensation
458  // XOSC_CAPARRAY_DELTA is located in bit[15:8] of ccfg_ModeConfReg
459  // Note: HW_REV_DEPENDENT_IMPLEMENTATION. Field width is not given by
460  // a define and sign extension must therefore be hardcoded.
461  // ( A small test program is created verifying the code lines below:
462  // Ref.: ..\test\small_standalone_test_programs\CapArrayDeltaAdjust_test.c)
463  i32CustomerDeltaAdjust = ((int32_t)ccfg_ModeConfReg << 16 ) >> 24;
464 
465  while ( i32CustomerDeltaAdjust < 0 ) {
466  ui32XoscHfCol >>= 1; // COL 1 step down
467  if ( ui32XoscHfCol == 0 ) { // if COL below minimum
468  ui32XoscHfCol = 0xFFFF; // Set COL to maximum
469  ui32XoscHfRow >>= 1; // ROW 1 step down
470  if ( ui32XoscHfRow == 0 ) { // if ROW below minimum
471  ui32XoscHfRow = 1; // Set both ROW and COL
472  ui32XoscHfCol = 1; // to minimum
473  }
474  }
475  i32CustomerDeltaAdjust++;
476  }
477  while ( i32CustomerDeltaAdjust > 0 ) {
478  ui32XoscHfCol = ( ui32XoscHfCol << 1 ) | 1; // COL 1 step up
479  if ( ui32XoscHfCol > 0xFFFF ) { // if COL above maximum
480  ui32XoscHfCol = 1; // Set COL to minimum
481  ui32XoscHfRow = ( ui32XoscHfRow << 1 ) | 1; // ROW 1 step up
482  if ( ui32XoscHfRow > 0xF ) { // if ROW above maximum
483  ui32XoscHfRow = 0xF; // Set both ROW and COL
484  ui32XoscHfCol = 0xFFFF; // to maximum
485  }
486  }
487  i32CustomerDeltaAdjust--;
488  }
489  }
490 
491  ui32TrimValue = (( ui32XoscHfRow << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
492  ( ui32XoscHfCol << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
493 
494  return (ui32TrimValue);
495 }
496 
497 //*****************************************************************************
498 //
501 //
502 //*****************************************************************************
503 uint32_t
505 {
506  uint32_t ui32TrimValue;
507 
508  // Use device specific trim values located in factory configuration
509  // area
510  ui32TrimValue =
515 
516  ui32TrimValue |=
521 
522  return(ui32TrimValue);
523 }
524 
525 //*****************************************************************************
526 //
529 //
530 //*****************************************************************************
531 uint32_t
533 {
534  uint32_t ui32TrimValue;
535 
536  // Use device specific trim value located in factory configuration
537  // area
538  ui32TrimValue =
542 
543  return(ui32TrimValue);
544 }
545 
546 //*****************************************************************************
547 //
549 //
550 //*****************************************************************************
551 uint32_t
553 {
554  uint32_t ui32TrimValue;
555  uint32_t ui32Fcfg1Value;
556 
557  // Use device specific trim value located in factory configuration
558  // area. All defined register bit fields have corresponding trim
559  // value in the factory configuration area
560  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH2);
561  ui32TrimValue = ((ui32Fcfg1Value &
565  ui32TrimValue |= (((ui32Fcfg1Value &
569  ui32TrimValue |= (((ui32Fcfg1Value &
573  ui32TrimValue |= (((ui32Fcfg1Value &
577 
578  return(ui32TrimValue);
579 }
580 
581 //*****************************************************************************
582 //
584 //
585 //*****************************************************************************
586 uint32_t
588 {
589  uint32_t ui32TrimValue;
590  uint32_t ui32Fcfg1Value;
591 
592  // Use device specific trim values located in factory configuration
593  // area. All defined register bit fields have a corresponding trim
594  // value in the factory configuration area
595  ui32Fcfg1Value = HWREG(FCFG1_BASE + FCFG1_O_AMPCOMP_TH1);
596  ui32TrimValue = (((ui32Fcfg1Value &
600  ui32TrimValue |= (((ui32Fcfg1Value &
604  ui32TrimValue |= (((ui32Fcfg1Value &
608  ui32TrimValue |= (((ui32Fcfg1Value &
612 
613  return(ui32TrimValue);
614 }
615 
616 //*****************************************************************************
617 //
619 //
620 //*****************************************************************************
621 uint32_t
622 SetupGetTrimForAmpcompCtrl( uint32_t ui32Fcfg1Revision )
623 {
624  uint32_t ui32TrimValue ;
625  uint32_t ui32Fcfg1Value ;
626  uint32_t ibiasOffset ;
627  uint32_t ibiasInit ;
628  uint32_t modeConf1 ;
629  int32_t deltaAdjust ;
630 
631  // Use device specific trim values located in factory configuration
632  // area. Register bit fields without trim values in the factory
633  // configuration area will be set to the value of 0.
634  ui32Fcfg1Value = HWREG( FCFG1_BASE + FCFG1_O_AMPCOMP_CTRL1 );
635 
636  ibiasOffset = ( ui32Fcfg1Value &
639  ibiasInit = ( ui32Fcfg1Value &
642 
644  // Adjust with DELTA_IBIAS_OFFSET and DELTA_IBIAS_INIT from CCFG
645  modeConf1 = HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 );
646 
647  // Both fields are signed 4-bit values. This is an assumption when doing the sign extension.
648  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_OFFSET_S - 4 )) >> 28;
649  deltaAdjust += (int32_t)ibiasOffset;
650  if ( deltaAdjust < 0 ) {
651  deltaAdjust = 0;
652  }
655  }
656  ibiasOffset = (uint32_t)deltaAdjust;
657 
658  deltaAdjust = ((int32_t)modeConf1 << ( 32 - CCFG_MODE_CONF_1_DELTA_IBIAS_INIT_S - 4 )) >> 28;
659  deltaAdjust += (int32_t)ibiasInit;
660  if ( deltaAdjust < 0 ) {
661  deltaAdjust = 0;
662  }
665  }
666  ibiasInit = (uint32_t)deltaAdjust;
667  }
668  ui32TrimValue = ( ibiasOffset << DDI_0_OSC_AMPCOMPCTL_IBIAS_OFFSET_S ) |
669  ( ibiasInit << DDI_0_OSC_AMPCOMPCTL_IBIAS_INIT_S ) ;
670 
671  ui32TrimValue |= (((ui32Fcfg1Value &
675  ui32TrimValue |= (((ui32Fcfg1Value &
679  ui32TrimValue |= (((ui32Fcfg1Value &
683 
684  if ( ui32Fcfg1Revision >= 0x00000022 ) {
685  ui32TrimValue |= ((( ui32Fcfg1Value &
689  }
690 
691  return(ui32TrimValue);
692 }
693 
694 //*****************************************************************************
695 //
697 //
698 //*****************************************************************************
699 uint32_t
700 SetupGetTrimForDblrLoopFilterResetVoltage( uint32_t ui32Fcfg1Revision )
701 {
702  uint32_t dblrLoopFilterResetVoltageValue = 0; // Reset value
703 
704  if ( ui32Fcfg1Revision >= 0x00000020 ) {
705  dblrLoopFilterResetVoltageValue = ( HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 ) &
708  }
709 
710  return ( dblrLoopFilterResetVoltageValue );
711 }
712 
713 //*****************************************************************************
714 //
716 //
717 //*****************************************************************************
718 uint32_t
719 SetupGetTrimForAdcShModeEn( uint32_t ui32Fcfg1Revision )
720 {
721  uint32_t getTrimForAdcShModeEnValue = 1; // Recommended default setting
722 
723  if ( ui32Fcfg1Revision >= 0x00000022 ) {
724  getTrimForAdcShModeEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
727  }
728 
729  return ( getTrimForAdcShModeEnValue );
730 }
731 
732 //*****************************************************************************
733 //
735 //
736 //*****************************************************************************
737 uint32_t
738 SetupGetTrimForAdcShVbufEn( uint32_t ui32Fcfg1Revision )
739 {
740  uint32_t getTrimForAdcShVbufEnValue = 1; // Recommended default setting
741 
742  if ( ui32Fcfg1Revision >= 0x00000022 ) {
743  getTrimForAdcShVbufEnValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
746  }
747 
748  return ( getTrimForAdcShVbufEnValue );
749 }
750 
751 //*****************************************************************************
752 //
754 //
755 //*****************************************************************************
756 uint32_t
757 SetupGetTrimForXoscHfCtl( uint32_t ui32Fcfg1Revision )
758 {
759  uint32_t getTrimForXoschfCtlValue = 0; // Recommended default setting
760  uint32_t fcfg1Data;
761 
762  if ( ui32Fcfg1Revision >= 0x00000020 ) {
763  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
764  getTrimForXoschfCtlValue =
765  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_PEAK_DET_ITRIM_M ) >>
768 
769  getTrimForXoschfCtlValue |=
770  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HP_BUF_ITRIM_M ) >>
773 
774  getTrimForXoschfCtlValue |=
775  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LP_BUF_ITRIM_M ) >>
778  }
779 
780  return ( getTrimForXoschfCtlValue );
781 }
782 
783 //*****************************************************************************
784 //
786 //
787 //*****************************************************************************
788 uint32_t
790 {
791  uint32_t ui32XoscHfFastStartValue ;
792 
793  // Get value from FCFG1
794  ui32XoscHfFastStartValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
797 
798  return ( ui32XoscHfFastStartValue );
799 }
800 
801 //*****************************************************************************
802 //
804 //
805 //*****************************************************************************
806 uint32_t
807 SetupGetTrimForRadcExtCfg( uint32_t ui32Fcfg1Revision )
808 {
809  uint32_t getTrimForRadcExtCfgValue = 0x403F8000; // Recommended default setting
810  uint32_t fcfg1Data;
811 
812  if ( ui32Fcfg1Revision >= 0x00000020 ) {
813  fcfg1Data = HWREG( FCFG1_BASE + FCFG1_O_MISC_OTP_DATA_1 );
814  getTrimForRadcExtCfgValue =
815  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_HPM_IBIAS_WAIT_CNT_M ) >>
818 
819  getTrimForRadcExtCfgValue |=
820  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_LPM_IBIAS_WAIT_CNT_M ) >>
823 
824  getTrimForRadcExtCfgValue |=
825  ( ( ( fcfg1Data & FCFG1_MISC_OTP_DATA_1_IDAC_STEP_M ) >>
828  }
829 
830  return ( getTrimForRadcExtCfgValue );
831 }
832 
833 //*****************************************************************************
834 //
836 //
837 //*****************************************************************************
838 uint32_t
839 SetupGetTrimForRcOscLfIBiasTrim( uint32_t ui32Fcfg1Revision )
840 {
841  uint32_t trimForRcOscLfIBiasTrimValue = 0; // Default value
842 
843  if ( ui32Fcfg1Revision >= 0x00000022 ) {
844  trimForRcOscLfIBiasTrimValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
847  }
848 
849  return ( trimForRcOscLfIBiasTrimValue );
850 }
851 
852 //*****************************************************************************
853 //
856 //
857 //*****************************************************************************
858 uint32_t
860 {
861  uint32_t trimForXoscLfRegulatorAndCmirrwrRatioValue = 0; // Default value for both fields
862 
863  if ( ui32Fcfg1Revision >= 0x00000022 ) {
864  trimForXoscLfRegulatorAndCmirrwrRatioValue = ( HWREG( FCFG1_BASE + FCFG1_O_OSC_CONF ) &
868  }
869 
870  return ( trimForXoscLfRegulatorAndCmirrwrRatioValue );
871 }
872 
873 //*****************************************************************************
874 //
878 //
879 //*****************************************************************************
880 void
882 {
883  //
884  // - Make sure to enable aggressive VIMS clock gating for power optimization
885  // Only for PG2 devices.
886  // - Enable cache prefetch enable as default setting
887  // (Slightly higher power consumption, but higher CPU performance)
888  // - IF ( CCFG_..._DIS_GPRAM == 1 )
889  // then: Enable cache (set cache mode = 1), even if set by ROM boot code
890  // (This is done because it's not set by boot code when running inside
891  // a debugger supporting the Halt In Boot (HIB) functionality).
892  // else: Set MODE_GPRAM if not already set (see inline comments as well)
893  //
894  uint32_t vimsCtlMode0 ;
895 
896  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
897  // Do nothing - wait for an eventual ongoing mode change to complete.
898  // (There should typically be no wait time here, but need to be sure)
899  }
900 
901  //
902  // Note that Mode=0 is equal to MODE_GPRAM
903  //
904  vimsCtlMode0 = (( HWREG( VIMS_BASE + VIMS_O_CTL ) & ~VIMS_CTL_MODE_M ) | VIMS_CTL_DYN_CG_EN_M | VIMS_CTL_PREF_EN_M );
905 
906 
908  // Enable cache (and hence disable GPRAM)
909  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_CACHE );
910  } else if (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_GPRAM ) {
911  //
912  // GPRAM is enabled in CCFG but not selected
913  // Note: It is recommended to go via MODE_OFF when switching to MODE_GPRAM
914  //
915  HWREG( VIMS_BASE + VIMS_O_CTL ) = ( vimsCtlMode0 | VIMS_CTL_MODE_OFF );
916  while (( HWREG( VIMS_BASE + VIMS_O_STAT ) & VIMS_STAT_MODE_M ) != VIMS_STAT_MODE_OFF ) {
917  // Do nothing - wait for an eventual mode change to complete (This goes fast).
918  }
919  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
920  } else {
921  // Correct mode, but make sure PREF_EN and DYN_CG_EN always are set
922  HWREG( VIMS_BASE + VIMS_O_CTL ) = vimsCtlMode0;
923  }
924 }
925 
926 //*****************************************************************************
927 //
931 //
932 //*****************************************************************************
933 void
934 SetupSetAonRtcSubSecInc( uint32_t subSecInc )
935 {
936  //
937  // Loading a new RTCSUBSECINC value is done in 5 steps:
938  // 1. Write bit[15:0] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC0
939  // 2. Write bit[23:16] of new SUBSECINC value to AUX_WUC_O_RTCSUBSECINC1
941  // 4. Wait for AUX_WUC_RTCSUBSECINCCTL_UPD_ACK
943  //
945  HWREG( AUX_WUC_BASE + AUX_WUC_O_RTCSUBSECINC1 ) = (( subSecInc >> 16 ) & AUX_WUC_RTCSUBSECINC1_INC23_16_M );
946 
950 }
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_rom.c:587
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_rom.c:504
uint32_t SetupGetTrimForAmpcompTh2(void)
Returns the trim value to be used for the AMPCOMP_TH2 register in OSC_DIG.
Definition: setup_rom.c:552
uint32_t SetupGetTrimForDblrLoopFilterResetVoltage(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as DBLR_LOOP_FILTER_RESET_VOLTAGE setting.
Definition: setup_rom.c:700
void SetupAfterColdResetWakeupFromShutDownCfg3(uint32_t ccfg_ModeConfReg)
Third part of configuration required when waking up from shutdown.
Definition: setup_rom.c:302
uint32_t SetupGetTrimForAdcShVbufEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_VBUF_EN setting.
Definition: setup_rom.c:738
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_rom.c:807
void SetupSetAonRtcSubSecInc(uint32_t subSecInc)
Doing the tricky stuff needed to enter new RTCSUBSECINC value.
Definition: setup_rom.c:934
uint32_t SetupGetTrimForRcOscLfIBiasTrim(uint32_t ui32Fcfg1Revision)
Returns the FCFG1 OSC_CONF_ATESTLF_RCOSCLF_IBIAS_TRIM.
Definition: setup_rom.c:839
void SetupAfterColdResetWakeupFromShutDownCfg1(uint32_t ccfg_ModeConfReg)
First part of configuration required when waking up from shutdown.
Definition: setup_rom.c:123
#define OSC_SRC_CLK_HF
Definition: osc.h:112
#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_rom.c:859
#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_rom.c:434
void SetupSetCacheModeAccordingToCcfgSetting(void)
Set correct VIMS_MODE according to CCFG setting (CACHE or GPRAM)
Definition: setup_rom.c:881
uint32_t SetupGetTrimForAdcShModeEn(uint32_t ui32Fcfg1Revision)
Returns the trim value from FCFG1 to be used as ADC_SH_MODE_EN setting.
Definition: setup_rom.c:719
uint32_t SetupGetTrimForAmpcompCtrl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the AMPCOMP_CTRL register in OSC_DIG.
Definition: setup_rom.c:622
#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
#define IOC_HYST_ENABLE
Definition: ioc.h:216
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_rom.c:789
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_rom.c:186
uint32_t SetupGetTrimForXoscHfCtl(uint32_t ui32Fcfg1Revision)
Returns the trim value to be used for the XOSCHFCTL register in OSC_DIG.
Definition: setup_rom.c:757
#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_rom.c:532
static int32_t SetupSignExtendVddrTrimValue(uint32_t ui32VddrTrimVal)
Sign extend the VDDR_TRIM setting (special format ranging from -10 to +21)
Definition: setup_rom.h:232