-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.c
323 lines (286 loc) · 13.3 KB
/
setup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/******************************************************************************
* Filename: setup.c
* Revised: 2018-04-05 13:46:03 +0200 (Thu, 05 Apr 2018)
* Revision: 51853
*
* Description: Setup file for CC13xx/CC26xx devices.
*
* Copyright (c) 2015 - 2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3) Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
// Hardware headers
#include "../inc/hw_types.h"
#include "../inc/hw_memmap.h"
#include "../inc/hw_adi.h"
#include "../inc/hw_adi_2_refsys.h"
#include "../inc/hw_adi_3_refsys.h"
#include "../inc/hw_aon_ioc.h"
#include "../inc/hw_aon_sysctl.h"
#include "../inc/hw_aon_wuc.h"
#include "../inc/hw_aux_wuc.h"
#include "../inc/hw_ccfg.h"
#include "../inc/hw_fcfg1.h"
#include "../inc/hw_flash.h"
#include "../inc/hw_prcm.h"
#include "../inc/hw_vims.h"
// Driverlib headers
#include "aon_wuc.h"
#include "aux_wuc.h"
#include "chipinfo.h"
#include "setup.h"
#include "setup_rom.h"
//*****************************************************************************
//
// Handle support for DriverLib in ROM:
// This section will undo prototype renaming made in the header file
//
//*****************************************************************************
#if !defined(DOXYGEN)
#undef SetupTrimDevice
#define SetupTrimDevice NOROM_SetupTrimDevice
#endif
//*****************************************************************************
//
// Defined CPU delay macro with microseconds as input
// Quick check shows: (To be further investigated)
// At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 5 cycles
// At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 1, there is 4 cycles
// At 24 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 3 cycles
//
//*****************************************************************************
#define CPU_DELAY_MICRO_SECONDS( x ) \
CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )
//*****************************************************************************
//
// Function declarations
//
//*****************************************************************************
static void TrimAfterColdReset( void );
static void TrimAfterColdResetWakeupFromShutDown( uint32_t ui32Fcfg1Revision );
static void TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown( void );
//*****************************************************************************
//
// Perform the necessary trim of the device which is not done in boot code
//
// This function should only execute coming from ROM boot. The current
// implementation does not take soft reset into account. However, it does no
// damage to execute it again. It only consumes time.
//
//*****************************************************************************
void
SetupTrimDevice(void)
{
uint32_t ui32Fcfg1Revision;
uint32_t ui32AonSysResetctl;
// Get layout revision of the factory configuration area
// (Handle undefined revision as revision = 0)
ui32Fcfg1Revision = HWREG(FCFG1_BASE + FCFG1_O_FCFG1_REVISION);
if ( ui32Fcfg1Revision == 0xFFFFFFFF ) {
ui32Fcfg1Revision = 0;
}
// This driverlib version and setup file is for CC26x0R2 chips.
// Halt if violated
ThisLibraryIsFor_CC26x0R2_HaltIfViolated();
// Enable standby in flash bank
HWREGBITW( FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_STANDBY_BITN ) = 0;
// Clock must always be enabled for the semaphore module (due to ADI/DDI HW workaround)
HWREG( AUX_WUC_BASE + AUX_WUC_O_MODCLKEN1 ) = AUX_WUC_MODCLKEN1_SMPH;
// Warm resets on CC13x0 and CC26x0 complicates software design because much of
// our software expect that initialization is done from a full system reset.
// This includes RTC setup, oscillator configuration and AUX setup.
// To ensure a full reset of the device is done when customers get e.g. a Watchdog
// reset, the following is set here:
HWREGBITW( PRCM_BASE + PRCM_O_WARMRESET, PRCM_WARMRESET_WR_TO_PINRESET_BITN ) = 1;
// Select correct CACHE mode and set correct CACHE configuration
#if ( CCFG_BASE == CCFG_BASE_DEFAULT )
SetupSetCacheModeAccordingToCcfgSetting();
#else
NOROM_SetupSetCacheModeAccordingToCcfgSetting();
#endif
// 1. Check for powerdown
// 2. Check for shutdown
// 3. Assume cold reset if none of the above.
//
// It is always assumed that the application will freeze the latches in
// AON_IOC when going to powerdown in order to retain the values on the IOs.
//
// NB. If this bit is not cleared before proceeding to powerdown, the IOs
// will all default to the reset configuration when restarting.
if( ! ( HWREGBITW( AON_IOC_BASE + AON_IOC_O_IOCLATCH, AON_IOC_IOCLATCH_EN_BITN )))
{
// NB. This should be calling a ROM implementation of required trim and
// compensation
// e.g. TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
}
// Check for shutdown
//
// When device is going to shutdown the hardware will automatically clear
// the SLEEPDIS bit in the SLEEP register in the AON_SYSCTL module.
// It is left for the application to assert this bit when waking back up,
// but not before the desired IO configuration has been re-established.
else if( ! ( HWREGBITW( AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL, AON_SYSCTL_SLEEPCTL_IO_PAD_SLEEP_DIS_BITN )))
{
// NB. This should be calling a ROM implementation of required trim and
// compensation
// e.g. TrimAfterColdResetWakeupFromShutDown() -->
// TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
}
else
{
// Consider adding a check for soft reset to allow debugging to skip
// this section!!!
//
// NB. This should be calling a ROM implementation of required trim and
// compensation
// e.g. TrimAfterColdReset() -->
// TrimAfterColdResetWakeupFromShutDown() -->
// TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
TrimAfterColdReset();
TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
}
// Set VIMS power domain control.
// PDCTL1VIMS = 0 ==> VIMS power domain is only powered when CPU power domain is powered
HWREG( PRCM_BASE + PRCM_O_PDCTL1VIMS ) = 0;
// Configure optimal wait time for flash FSM in cases where flash pump
// wakes up from sleep
HWREG(FLASH_BASE + FLASH_O_FPAC1) = (HWREG(FLASH_BASE + FLASH_O_FPAC1) &
~FLASH_FPAC1_PSLEEPTDIS_M) |
(0x139<<FLASH_FPAC1_PSLEEPTDIS_S);
// And finally at the end of the flash boot process:
// SET BOOT_DET bits in AON_SYSCTL to 3 if already found to be 1
// Note: The BOOT_DET_x_CLR/SET bits must be manually cleared
if ((( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
( AON_SYSCTL_RESETCTL_BOOT_DET_1_M | AON_SYSCTL_RESETCTL_BOOT_DET_0_M )) >>
AON_SYSCTL_RESETCTL_BOOT_DET_0_S ) == 1 )
{
ui32AonSysResetctl = ( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
~( AON_SYSCTL_RESETCTL_BOOT_DET_1_CLR_M | AON_SYSCTL_RESETCTL_BOOT_DET_0_CLR_M |
AON_SYSCTL_RESETCTL_BOOT_DET_1_SET_M | AON_SYSCTL_RESETCTL_BOOT_DET_0_SET_M ));
HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl | AON_SYSCTL_RESETCTL_BOOT_DET_1_SET_M;
HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl;
}
// Make sure there are no ongoing VIMS mode change when leaving SetupTrimDevice()
// (There should typically be no wait time here, but need to be sure)
while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
// Do nothing - wait for an eventual ongoing mode change to complete.
}
}
//*****************************************************************************
//
//! \brief Trims to be applied when coming from POWER_DOWN (also called when
//! coming from SHUTDOWN and PIN_RESET).
//!
//! \return None
//
//*****************************************************************************
static void
TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown( void )
{
// Currently no specific trim for Powerdown
}
//*****************************************************************************
//
//! \brief Trims to be applied when coming from SHUTDOWN (also called when
//! coming from PIN_RESET).
//!
//! \param ui32Fcfg1Revision
//!
//! \return None
//
//*****************************************************************************
static void
TrimAfterColdResetWakeupFromShutDown(uint32_t ui32Fcfg1Revision)
{
uint32_t ccfg_ModeConfReg ;
// Force AUX on and enable clocks
//
// No need to save the current status of the power/clock registers.
// At this point both AUX and AON should have been reset to 0x0.
HWREG(AON_WUC_BASE + AON_WUC_O_AUXCTL) = AON_WUC_AUXCTL_AUX_FORCE_ON;
// Wait for power on on the AUX domain
while( ! ( HWREGBITW( AON_WUC_BASE + AON_WUC_O_PWRSTAT, AON_WUC_PWRSTAT_AUX_PD_ON_BITN )));
// Enable the clocks for AUX_DDI0_OSC and AUX_ADI4
HWREG(AUX_WUC_BASE + AUX_WUC_O_MODCLKEN0) = AUX_WUC_MODCLKEN0_AUX_DDI0_OSC |
AUX_WUC_MODCLKEN0_AUX_ADI4;
// Check in CCFG for alternative DCDC setting
if (( HWREG( CCFG_BASE + CCFG_O_SIZE_AND_DIS_FLAGS ) & CCFG_SIZE_AND_DIS_FLAGS_DIS_ALT_DCDC_SETTING ) == 0 ) {
// ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
// ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
// Using a single 4-bit masked write since layout is equal for both source and destination
HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
( HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 ) >> CCFG_MODE_CONF_1_ALT_DCDC_IPEAK_S ));
}
//
// Enable for JTAG to be powered down (will still be powered on if debugger is connected)
AONWUCJtagPowerOff();
// read the MODE_CONF register in CCFG
ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
// First part of trim done after cold reset and wakeup from shutdown:
// -Adjust the VDDR_TRIM_SLEEP value.
// -Configure DCDC.
SetupAfterColdResetWakeupFromShutDownCfg1( ccfg_ModeConfReg );
// Second part of trim done after cold reset and wakeup from shutdown:
// -Configure XOSC.
#if ( CCFG_BASE == CCFG_BASE_DEFAULT )
SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
#else
NOROM_SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
#endif
// Third part of trim done after cold reset and wakeup from shutdown:
// -Configure HPOSC.
// -Setup the LF clock.
#if ( CCFG_BASE == CCFG_BASE_DEFAULT )
SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
#else
NOROM_SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
#endif
// Allow AUX to power down
AUXWUCPowerCtrl( AUX_WUC_POWER_DOWN );
// Leaving on AUX and clock for AUX_DDI0_OSC on but turn off clock for AUX_ADI4
HWREG( AUX_WUC_BASE + AUX_WUC_O_MODCLKEN0 ) = AUX_WUC_MODCLKEN0_AUX_DDI0_OSC;
// Disable EFUSE clock
HWREGBITW( FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_EFUSECLK_BITN ) = 1;
}
//*****************************************************************************
//
//! \brief Trims to be applied when coming from PIN_RESET.
//!
//! \return None
//
//*****************************************************************************
static void
TrimAfterColdReset( void )
{
// Currently no specific trim for Cold Reset
}