2 * -------------------------------------------
\r
3 * CC3220 SDK - v0.10.00.00
\r
4 * -------------------------------------------
\r
6 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions
\r
12 * Redistributions of source code must retain the above copyright
\r
13 * notice, this list of conditions and the following disclaimer.
\r
15 * Redistributions in binary form must reproduce the above copyright
\r
16 * notice, this list of conditions and the following disclaimer in the
\r
17 * documentation and/or other materials provided with the
\r
20 * Neither the name of Texas Instruments Incorporated nor the names of
\r
21 * its contributors may be used to endorse or promote products derived
\r
22 * from this software without specific prior written permission.
\r
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
38 //*****************************************************************************
\r
40 //! \addtogroup PRCM_Power_Reset_Clock_Module_api
\r
43 //*****************************************************************************
\r
45 #include "inc/hw_types.h"
\r
46 #include "inc/hw_ints.h"
\r
47 #include "inc/hw_memmap.h"
\r
48 #include "inc/hw_apps_rcm.h"
\r
49 #include "inc/hw_gprcm.h"
\r
50 #include "inc/hw_hib1p2.h"
\r
51 #include "inc/hw_hib3p3.h"
\r
52 #include "inc/hw_ocp_shared.h"
\r
53 #include "inc/hw_common_reg.h"
\r
55 #include "interrupt.h"
\r
61 //*****************************************************************************
\r
63 //*****************************************************************************
\r
64 #define PRCM_SOFT_RESET 0x00000001
\r
65 #define PRCM_ENABLE_STATUS 0x00000002
\r
66 #define SYS_CLK 80000000
\r
67 #define XTAL_CLK 40000000
\r
70 //*****************************************************************************
\r
71 // CC3200 does not have a true RTC capability. However, API(s) in this file
\r
72 // provide an effective mechanism to support RTC feature in the device.
\r
74 // The implementation to support RTC has been kept very simple. A set of
\r
75 // HIB Memory Registers in conjunction with Slow Clock Counter are used
\r
76 // to render RTC information to users. Core principle of design involves
\r
77 // two steps (a) establish an association between user provided wall-clock
\r
78 // and slow clock counter. (b) store reference value of this associattion
\r
79 // in HIB Registers. This reference value and SCC value are then combined
\r
80 // to create real-world calendar time.
\r
82 // Across HIB cycles, value stored in HIB Registers is retained and slow
\r
83 // clock counter continues to tick, thereby, this arragement is relevant
\r
84 // and valid as long as device has a (tickle) battery power.
\r
86 // Further, provision also has been made to set an alarm. When it RTC value
\r
87 // matches that of set for alarm, an interrupt is generated.
\r
89 // HIB MEM REG0 and REG1 are reserved for TI.
\r
91 // If RTC feature is not used, then HIB REG2 & REG3 are available to user.
\r
93 // Lower half of REG0 is used for TI HW ECO.
\r
94 //*****************************************************************************
\r
95 #define RTC_U64MSEC_MK(u32Secs, u16Msec) (((unsigned long long)u32Secs << 10)|\
\r
98 #define RTC_SECS_IN_U64MSEC(u64Msec) ((unsigned long)(u64Msec >> 10))
\r
99 #define RTC_MSEC_IN_U64MSEC(u64Msec) ((unsigned short)(u64Msec & 0x3FF))
\r
101 #define RTC_SECS_U32_REG_ADDR (HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG3)
\r
102 #define RTC_MSEC_U16_REG_ADDR (HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG2+2)
\r
104 #define RTC_U32SECS_REG (HWREG(RTC_SECS_U32_REG_ADDR))
\r
105 #define RTC_U16MSEC_REG (*(unsigned short*)RTC_MSEC_U16_REG_ADDR)
\r
107 //*****************************************************************************
\r
108 // Register Access and Updates
\r
110 // Tick of SCC has a resolution of 32768Hz, meaning 1 sec is equal to 32768
\r
111 // clock ticks. Ideal way of getting time in millisecond will involve floating
\r
112 // point arithmetic (division by 32.768). To avoid this, we simply divide it by
\r
113 // 32, which will give a range from 0 -1023(instead of 0-999). To use this
\r
114 // output correctly we have to take care of this inaccuracy externally.
\r
115 // following wrapper can be used to convert the value from cycles to
\r
118 // CYCLES_U16MS(cycles) ((cycles *1000)/ 1024),
\r
120 // Similarly, before setting the value, it must be first converted (from ms to
\r
123 // U16MS_CYCLES(msec) ((msec *1024)/1000)
\r
125 // Note: There is a precision loss of 1 ms with the above scheme.
\r
127 //*****************************************************************************
\r
128 #define SCC_U64MSEC_GET() (PRCMSlowClkCtrGet() >> 5)
\r
129 #define SCC_U64MSEC_MATCH_SET(u64Msec) (PRCMSlowClkCtrMatchSet(u64Msec << 5))
\r
130 #define SCC_U64MSEC_MATCH_GET() (PRCMSlowClkCtrMatchGet() >> 5)
\r
132 //*****************************************************************************
\r
134 // Bit: 31 is used to indicate use of RTC. If set as '1', RTC feature is used.
\r
135 // Bits: 30 to 26 are reserved, available to software for use
\r
136 // Bits: 25 to 16 are used to save millisecond part of RTC reference.
\r
137 // Bits: 15 to 0 are being used for HW Changes / ECO
\r
139 //*****************************************************************************
\r
141 //*****************************************************************************
\r
143 //*****************************************************************************
\r
144 static void RTCUseSet(void)
\r
146 unsigned short usRegValue;
\r
148 usRegValue = RTC_U16MSEC_REG | (1 << 15);
\r
150 UtilsDelay((80*200)/3);
\r
152 RTC_U16MSEC_REG = usRegValue;
\r
155 //*****************************************************************************
\r
156 // Checks if RTC-USE bit is set
\r
157 //*****************************************************************************
\r
158 static tBoolean IsRTCUsed(void)
\r
160 unsigned short usRegValue;
\r
162 usRegValue = RTC_U16MSEC_REG;
\r
164 UtilsDelay((80*200)/3);
\r
166 return ((usRegValue & (1 << 15))? true : false);
\r
169 //*****************************************************************************
\r
170 // Read 16-bit mSecs
\r
171 //*****************************************************************************
\r
172 static unsigned short RTCU16MSecRegRead(void)
\r
174 unsigned short usRegValue;
\r
176 usRegValue = RTC_U16MSEC_REG;
\r
178 UtilsDelay((80*200)/3);
\r
180 return (usRegValue & 0x3FF);
\r
183 //*****************************************************************************
\r
184 // Write 16-bit mSecs
\r
185 //*****************************************************************************
\r
186 static void RTCU16MSecRegWrite(unsigned short u16Msec)
\r
188 unsigned short usRegValue;
\r
190 usRegValue = RTC_U16MSEC_REG;
\r
192 UtilsDelay((80*200)/3);
\r
194 RTC_U16MSEC_REG = ((usRegValue & ~0x3FF) |u16Msec);
\r
197 //*****************************************************************************
\r
198 // Read 32-bit Secs
\r
199 //*****************************************************************************
\r
200 static unsigned long RTCU32SecRegRead(void)
\r
202 return (PRCMHIBRegRead(RTC_SECS_U32_REG_ADDR));
\r
205 //*****************************************************************************
\r
206 // Write 32-bit Secs
\r
207 //*****************************************************************************
\r
208 static void RTCU32SecRegWrite(unsigned long u32Msec)
\r
210 PRCMHIBRegWrite(RTC_SECS_U32_REG_ADDR, u32Msec);
\r
213 //*****************************************************************************
\r
215 //*****************************************************************************
\r
216 #define IS_RTC_USED() IsRTCUsed()
\r
217 #define RTC_USE_SET() RTCUseSet()
\r
219 #define RTC_U16MSEC_REG_RD() RTCU16MSecRegRead()
\r
220 #define RTC_U16MSEC_REG_WR(u16Msec) RTCU16MSecRegWrite(u16Msec)
\r
222 #define RTC_U32SECS_REG_RD() RTCU32SecRegRead()
\r
223 #define RTC_U32SECS_REG_WR(u32Secs) RTCU32SecRegWrite(u32Secs)
\r
225 #define SELECT_SCC_U42BITS(u64Msec) (u64Msec & 0x3ffffffffff)
\r
227 //*****************************************************************************
\r
228 // Global Peripheral clock and rest Registers
\r
229 //*****************************************************************************
\r
230 static const PRCM_PeriphRegs_t PRCM_PeriphRegsList[] =
\r
233 {APPS_RCM_O_CAMERA_CLK_GATING, APPS_RCM_O_CAMERA_SOFT_RESET },
\r
234 {APPS_RCM_O_MCASP_CLK_GATING, APPS_RCM_O_MCASP_SOFT_RESET },
\r
235 {APPS_RCM_O_MMCHS_CLK_GATING, APPS_RCM_O_MMCHS_SOFT_RESET },
\r
236 {APPS_RCM_O_MCSPI_A1_CLK_GATING, APPS_RCM_O_MCSPI_A1_SOFT_RESET },
\r
237 {APPS_RCM_O_MCSPI_A2_CLK_GATING, APPS_RCM_O_MCSPI_A2_SOFT_RESET },
\r
238 {APPS_RCM_O_UDMA_A_CLK_GATING, APPS_RCM_O_UDMA_A_SOFT_RESET },
\r
239 {APPS_RCM_O_GPIO_A_CLK_GATING, APPS_RCM_O_GPIO_A_SOFT_RESET },
\r
240 {APPS_RCM_O_GPIO_B_CLK_GATING, APPS_RCM_O_GPIO_B_SOFT_RESET },
\r
241 {APPS_RCM_O_GPIO_C_CLK_GATING, APPS_RCM_O_GPIO_C_SOFT_RESET },
\r
242 {APPS_RCM_O_GPIO_D_CLK_GATING, APPS_RCM_O_GPIO_D_SOFT_RESET },
\r
243 {APPS_RCM_O_GPIO_E_CLK_GATING, APPS_RCM_O_GPIO_E_SOFT_RESET },
\r
244 {APPS_RCM_O_WDOG_A_CLK_GATING, APPS_RCM_O_WDOG_A_SOFT_RESET },
\r
245 {APPS_RCM_O_UART_A0_CLK_GATING, APPS_RCM_O_UART_A0_SOFT_RESET },
\r
246 {APPS_RCM_O_UART_A1_CLK_GATING, APPS_RCM_O_UART_A1_SOFT_RESET },
\r
247 {APPS_RCM_O_GPT_A0_CLK_GATING , APPS_RCM_O_GPT_A0_SOFT_RESET },
\r
248 {APPS_RCM_O_GPT_A1_CLK_GATING, APPS_RCM_O_GPT_A1_SOFT_RESET },
\r
249 {APPS_RCM_O_GPT_A2_CLK_GATING, APPS_RCM_O_GPT_A2_SOFT_RESET },
\r
250 {APPS_RCM_O_GPT_A3_CLK_GATING, APPS_RCM_O_GPT_A3_SOFT_RESET },
\r
251 {APPS_RCM_O_CRYPTO_CLK_GATING, APPS_RCM_O_CRYPTO_SOFT_RESET },
\r
252 {APPS_RCM_O_MCSPI_S0_CLK_GATING, APPS_RCM_O_MCSPI_S0_SOFT_RESET },
\r
253 {APPS_RCM_O_I2C_CLK_GATING, APPS_RCM_O_I2C_SOFT_RESET }
\r
257 //*****************************************************************************
\r
259 //! Performs a software reset of a MCU and associated peripherals
\r
261 //! \param bIncludeSubsystem is \b true to reset associated peripherals.
\r
263 //! This function performs a software reset of a MCU and associated peripherals.
\r
264 //! To reset the associated peripheral, the parameter \e bIncludeSubsystem
\r
265 //! should be set to \b true.
\r
269 //*****************************************************************************
\r
270 void PRCMMCUReset(tBoolean bIncludeSubsystem)
\r
272 if(bIncludeSubsystem)
\r
275 // Reset Apps processor and associated peripheral
\r
277 HWREG(GPRCM_BASE+ GPRCM_O_APPS_SOFT_RESET) = 0x2;
\r
282 // Reset Apps processor only
\r
284 HWREG(GPRCM_BASE+ GPRCM_O_APPS_SOFT_RESET) = 0x1;
\r
288 // Wait for system to enter hibernate
\r
301 //*****************************************************************************
\r
303 //! Gets the reason for a reset.
\r
305 //! This function returns the reason(s) for a reset. The reset reason are:-
\r
306 //! -\b PRCM_POWER_ON - Device is powering up.
\r
307 //! -\b PRCM_LPDS_EXIT - Device is exiting from LPDS.
\r
308 //! -\b PRCM_CORE_RESET - Device is exiting soft core only reset
\r
309 //! -\b PRCM_MCU_RESET - Device is exiting soft subsystem reset.
\r
310 //! -\b PRCM_WDT_RESET - Device was reset by watchdog.
\r
311 //! -\b PRCM_SOC_RESET - Device is exting SOC reset.
\r
312 //! -\b PRCM_HIB_EXIT - Device is exiting hibernate.
\r
314 //! \return Returns one of the cause defined above.
\r
316 //*****************************************************************************
\r
317 unsigned long PRCMSysResetCauseGet()
\r
319 unsigned long ulWakeupStatus;
\r
322 // Read the Reset status
\r
324 ulWakeupStatus = (HWREG(GPRCM_BASE+ GPRCM_O_APPS_RESET_CAUSE) & 0xFF);
\r
327 // For hibernate do additional check.
\r
329 if(ulWakeupStatus == PRCM_POWER_ON)
\r
331 if(PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_WAKE_STATUS) & 0x1)
\r
333 ulWakeupStatus = PRCM_HIB_EXIT;
\r
335 if( (HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) & (0x00000280)) == 0x00000280 )
\r
337 ulWakeupStatus = PRCM_WDT_RESET;
\r
341 else if((ulWakeupStatus == PRCM_LPDS_EXIT) &&
\r
342 !(HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG1) & (1 <<2)) )
\r
344 if(HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) & (0x1<<8))
\r
346 ulWakeupStatus = PRCM_POWER_ON;
\r
353 return ulWakeupStatus;
\r
356 //*****************************************************************************
\r
358 //! Enable clock(s) to peripheral.
\r
360 //! \param ulPeripheral is one of the valid peripherals
\r
361 //! \param ulClkFlags are bitmask of clock(s) to be enabled.
\r
363 //! This function enables the clock for the specified peripheral. Peripherals
\r
364 //! are by default clock gated (disabled) and generates a bus fault if
\r
367 //! The parameter \e ulClkFlags can be logical OR of the following:
\r
368 //! -\b PRCM_RUN_MODE_CLK - Ungates clock to the peripheral
\r
369 //! -\b PRCM_SLP_MODE_CLK - Keeps the clocks ungated in sleep.
\r
373 //*****************************************************************************
\r
375 PRCMPeripheralClkEnable(unsigned long ulPeripheral, unsigned long ulClkFlags)
\r
378 // Enable the specified peripheral clocks, Nothing to be done for PRCM_ADC
\r
379 // as it is a dummy define for pinmux utility code generation
\r
381 if(ulPeripheral != PRCM_ADC)
\r
383 HWREG(ARCM_BASE + PRCM_PeriphRegsList[ulPeripheral].ulClkReg) |= ulClkFlags;
\r
387 // Checking ROM Version less than 2.x.x.
\r
388 // Only for driverlib backward compatibility
\r
390 if( (HWREG(0x00000400) & 0xFFFF) < 2 )
\r
393 // Set the default clock for camera
\r
395 if(ulPeripheral == PRCM_CAMERA)
\r
397 HWREG(ARCM_BASE + APPS_RCM_O_CAMERA_CLK_GEN) = 0x0404;
\r
402 //*****************************************************************************
\r
404 //! Disables clock(s) to peripheral.
\r
406 //! \param ulPeripheral is one of the valid peripherals
\r
407 //! \param ulClkFlags are bitmask of clock(s) to be enabled.
\r
409 //! This function disable the clock for the specified peripheral. Peripherals
\r
410 //! are by default clock gated (disabled) and generated a bus fault if
\r
413 //! The parameter \e ulClkFlags can be logical OR bit fields as defined in
\r
414 //! PRCMEnablePeripheral().
\r
418 //*****************************************************************************
\r
420 PRCMPeripheralClkDisable(unsigned long ulPeripheral, unsigned long ulClkFlags)
\r
423 // Disable the specified peripheral clocks
\r
425 HWREG(ARCM_BASE + PRCM_PeriphRegsList[ulPeripheral].ulClkReg) &= ~ulClkFlags;
\r
428 //*****************************************************************************
\r
430 //! Gets the input clock for the specified peripheral.
\r
432 //! \param ulPeripheral is one of the valid peripherals.
\r
434 //! This function gets the input clock for the specified peripheral.
\r
436 //! The parameter \e ulPeripheral has the same definition as that in
\r
437 //! PRCMPeripheralClkEnable();
\r
439 //! \return Returns input clock frequency for specified peripheral.
\r
441 //*****************************************************************************
\r
443 PRCMPeripheralClockGet(unsigned long ulPeripheral)
\r
445 unsigned long ulClockFreq;
\r
446 unsigned long ulHiPulseDiv;
\r
447 unsigned long ulLoPulseDiv;
\r
450 // Get the clock based on specified peripheral.
\r
452 if(((ulPeripheral == PRCM_SSPI) | (ulPeripheral == PRCM_LSPI)
\r
453 | (ulPeripheral == PRCM_GSPI)))
\r
457 else if(ulPeripheral == PRCM_CAMERA)
\r
459 ulHiPulseDiv = ((HWREG(ARCM_BASE + APPS_RCM_O_CAMERA_CLK_GEN) >> 8) & 0x07);
\r
460 ulLoPulseDiv = (HWREG(ARCM_BASE + APPS_RCM_O_CAMERA_CLK_GEN)& 0xFF);
\r
462 else if(ulPeripheral == PRCM_SDHOST)
\r
464 ulHiPulseDiv = ((HWREG(ARCM_BASE + APPS_RCM_O_MMCHS_CLK_GEN) >> 8) & 0x07);
\r
465 ulLoPulseDiv = (HWREG(ARCM_BASE + APPS_RCM_O_MMCHS_CLK_GEN)& 0xFF);
\r
473 // Compute the clock freq. from the divider value
\r
475 ulClockFreq = (240000000/((ulHiPulseDiv + 1) + (ulLoPulseDiv + 1)));
\r
478 // Return the clock rate.
\r
480 return ulClockFreq;
\r
483 //*****************************************************************************
\r
485 //! Performs a software reset of a peripheral.
\r
487 //! \param ulPeripheral is one of the valid peripheral.
\r
489 //! This function does soft reset of the specified peripheral
\r
493 //*****************************************************************************
\r
495 PRCMPeripheralReset(unsigned long ulPeripheral)
\r
497 volatile unsigned long ulDelay;
\r
499 if( ulPeripheral != PRCM_DTHE)
\r
502 // Assert the reset
\r
504 HWREG(ARCM_BASE + PRCM_PeriphRegsList[ulPeripheral].ulRstReg)
\r
505 |= PRCM_SOFT_RESET;
\r
507 // Delay a little bit.
\r
509 for(ulDelay = 0; ulDelay < 16; ulDelay++)
\r
514 // Deassert the reset
\r
516 HWREG(ARCM_BASE+PRCM_PeriphRegsList[ulPeripheral].ulRstReg)
\r
517 &= ~PRCM_SOFT_RESET;
\r
521 //*****************************************************************************
\r
523 //! Determines if a peripheral is ready.
\r
525 //! \param ulPeripheral is one of the valid modules
\r
527 //! This function determines if a particular peripheral is ready to be
\r
528 //! accessed. The peripheral may be in a non-ready state if it is not enabled,
\r
529 //! is being held in reset, or is in the process of becoming ready after being
\r
530 //! enabled or taken out of reset.
\r
532 //! \return Returns \b true if the peripheral is ready, \b false otherwise.
\r
534 //*****************************************************************************
\r
536 PRCMPeripheralStatusGet(unsigned long ulPeripheral)
\r
538 unsigned long ReadyBit;
\r
541 // Read the ready bit status
\r
543 ReadyBit = HWREG(ARCM_BASE + PRCM_PeriphRegsList[ulPeripheral].ulRstReg);
\r
544 ReadyBit = ReadyBit & PRCM_ENABLE_STATUS;
\r
556 // Module is not ready
\r
562 //*****************************************************************************
\r
564 //! Configure I2S fracactional divider
\r
566 //! \param ulI2CClkFreq is the required input clock for McAPS module
\r
568 //! This function configures I2S fractional divider. By default this
\r
569 //! divider is set to output 24 Mhz clock to I2S module.
\r
571 //! The minimum frequency that can be obtained by configuring this divider is
\r
573 //! (240000KHz/1023.99) = 234.377 KHz
\r
577 //*****************************************************************************
\r
579 PRCMI2SClockFreqSet(unsigned long ulI2CClkFreq)
\r
581 unsigned long long ullDiv;
\r
582 unsigned short usInteger;
\r
583 unsigned short usFrac;
\r
585 ullDiv = (((unsigned long long)240000000 * 65536)/ulI2CClkFreq);
\r
587 usInteger = (ullDiv/65536);
\r
588 usFrac = (ullDiv%65536);
\r
590 HWREG(ARCM_BASE + APPS_RCM_O_MCASP_FRAC_CLK_CONFIG0) =
\r
591 ((usInteger & 0x3FF) << 16 | usFrac);
\r
594 //*****************************************************************************
\r
596 //! Sets the LPDS exit PC and SP restore vlaues.
\r
598 //! \param ulStackPtr is the SP restore value.
\r
599 //! \param ulProgCntr is the PC restore value
\r
601 //! This function sets the LPDS exit PC and SP restore vlaues. Setting
\r
602 //! \e ulProgCntr to a non-zero value, forces bootloader to jump to that
\r
603 //! address with Stack Pointer initialized to \e ulStackPtr on LPDS exit,
\r
604 //! otherwise the application's vector table entries are used.
\r
608 //*****************************************************************************
\r
610 PRCMLPDSRestoreInfoSet(unsigned long ulStackPtr, unsigned long ulProgCntr)
\r
613 // ROM Version 2.x.x or greater
\r
615 if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
\r
618 // Set The SP Value
\r
620 HWREG(0x4402E160) = ulStackPtr;
\r
623 // Set The PC Value
\r
625 HWREG(0x4402E198) = ulProgCntr;
\r
631 // Set The SP Value
\r
633 HWREG(0x4402E18C) = ulStackPtr;
\r
636 // Set The PC Value
\r
638 HWREG(0x4402E190) = ulProgCntr;
\r
642 //*****************************************************************************
\r
644 //! Puts the system into Low Power Deel Sleep (LPDS) power mode.
\r
646 //! This function puts the system into Low Power Deel Sleep (LPDS) power mode.
\r
647 //! A call to this function never returns and the execution starts from Reset.
\r
648 //! \sa PRCMLPDSRestoreInfoSet().
\r
652 //! \note External debugger will always disconnect whenever the system
\r
653 //! enters LPDS and debug interface is shutdown until next POR reset. In order
\r
654 //! to avoid this and allow for connecting back the debugger after waking up
\r
655 //! from LPDS \sa PRCMLPDSEnterKeepDebugIf().
\r
658 //*****************************************************************************
\r
662 unsigned long ulChipId;
\r
665 // Read the Chip ID
\r
667 ulChipId = ((HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG2) >> 16) & 0x1F);
\r
670 // Check if flash exists
\r
672 if( (0x11 == ulChipId) || (0x19 == ulChipId))
\r
676 // Disable the flash
\r
681 #ifndef KEEP_TESTPD_ALIVE
\r
686 HWREG(0x4402E168) |= (1<<9);
\r
690 // Set bandgap duty cycle to 1
\r
692 HWREG(HIB1P2_BASE + HIB1P2_O_BGAP_DUTY_CYCLING_EXIT_CFG) = 0x1;
\r
697 HWREG(ARCM_BASE + APPS_RCM_O_APPS_LPDS_REQ)
\r
698 = APPS_RCM_APPS_LPDS_REQ_APPS_LPDS_REQ;
\r
701 // Wait for system to enter LPDS
\r
716 //*****************************************************************************
\r
718 //! Puts the system into Low Power Deel Sleep (LPDS) power mode keeping
\r
719 //! debug interface alive.
\r
721 //! This function puts the system into Low Power Deel Sleep (LPDS) power mode
\r
722 //! keeping debug interface alive. A call to this function never returns and the
\r
723 //! execution starts from Reset \sa PRCMLPDSRestoreInfoSet().
\r
727 //! \note External debugger will always disconnect whenever the system
\r
728 //! enters LPDS, using this API will allow connecting back the debugger after
\r
729 //! waking up from LPDS. This API is recommended for development purposes
\r
730 //! only as it adds to the current consumption of the system.
\r
733 //*****************************************************************************
\r
735 PRCMLPDSEnterKeepDebugIf()
\r
737 unsigned long ulChipId;
\r
740 // Read the Chip ID
\r
742 ulChipId = ((HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG2) >> 16) & 0x1F);
\r
745 // Check if flash exists
\r
747 if( (0x11 == ulChipId) || (0x19 == ulChipId))
\r
751 // Disable the flash
\r
757 // Set bandgap duty cycle to 1
\r
759 HWREG(HIB1P2_BASE + HIB1P2_O_BGAP_DUTY_CYCLING_EXIT_CFG) = 0x1;
\r
764 HWREG(ARCM_BASE + APPS_RCM_O_APPS_LPDS_REQ)
\r
765 = APPS_RCM_APPS_LPDS_REQ_APPS_LPDS_REQ;
\r
768 // Wait for system to enter LPDS
\r
782 //*****************************************************************************
\r
784 //! Enable the individual LPDS wakeup source(s).
\r
786 //! \param ulLpdsWakeupSrc is logical OR of wakeup sources.
\r
788 //! This function enable the individual LPDS wakeup source(s) and following
\r
789 //! three wakeup sources (\e ulLpdsWakeupSrc ) are supported by the device.
\r
790 //! -\b PRCM_LPDS_HOST_IRQ
\r
791 //! -\b PRCM_LPDS_GPIO
\r
792 //! -\b PRCM_LPDS_TIMER
\r
796 //*****************************************************************************
\r
798 PRCMLPDSWakeupSourceEnable(unsigned long ulLpdsWakeupSrc)
\r
800 unsigned long ulRegVal;
\r
803 // Read the current wakup sources
\r
805 ulRegVal = HWREG(GPRCM_BASE+ GPRCM_O_APPS_LPDS_WAKEUP_CFG);
\r
808 // Enable individual wakeup source
\r
810 ulRegVal = ((ulRegVal | ulLpdsWakeupSrc) & 0x91);
\r
813 // Set the configuration in the register
\r
815 HWREG(GPRCM_BASE+ GPRCM_O_APPS_LPDS_WAKEUP_CFG) = ulRegVal;
\r
818 //*****************************************************************************
\r
820 //! Disable the individual LPDS wakeup source(s).
\r
822 //! \param ulLpdsWakeupSrc is logical OR of wakeup sources.
\r
824 //! This function enable the individual LPDS wakeup source(s) and following
\r
825 //! three wake up sources (\e ulLpdsWakeupSrc ) are supported by the device.
\r
826 //! -\b PRCM_LPDS_HOST_IRQ
\r
827 //! -\b PRCM_LPDS_GPIO
\r
828 //! -\b PRCM_LPDS_TIMER
\r
832 //*****************************************************************************
\r
834 PRCMLPDSWakeupSourceDisable(unsigned long ulLpdsWakeupSrc)
\r
836 HWREG(GPRCM_BASE+ GPRCM_O_APPS_LPDS_WAKEUP_CFG) &= ~ulLpdsWakeupSrc;
\r
840 //*****************************************************************************
\r
842 //! Get LPDS wakeup cause
\r
844 //! This function gets LPDS wakeup caouse
\r
846 //! \return Returns values enumerated as described in
\r
847 //! PRCMLPDSWakeupSourceEnable().
\r
849 //*****************************************************************************
\r
851 PRCMLPDSWakeupCauseGet()
\r
853 return (HWREG(GPRCM_BASE+ GPRCM_O_APPS_LPDS_WAKEUP_SRC));
\r
856 //*****************************************************************************
\r
858 //! Sets LPDS wakeup Timer
\r
860 //! \param ulTicks is number of 32.768 KHz clocks
\r
862 //! This function sets internal LPDS wakeup timer running at 32.768 KHz. The
\r
863 //! timer is only configured if the parameter \e ulTicks is in valid range i.e.
\r
864 //! from 21 to 2^32.
\r
866 //! \return Returns \b true on success, \b false otherwise.
\r
868 //*****************************************************************************
\r
870 PRCMLPDSIntervalSet(unsigned long ulTicks)
\r
873 // Check sleep is atleast for 21 cycles
\r
874 // If not set the sleep time to 21 cycles
\r
881 HWREG(GPRCM_BASE + GPRCM_O_APPS_LPDS_WAKETIME_WAKE_CFG) = ulTicks;
\r
882 HWREG(GPRCM_BASE + GPRCM_O_APPS_LPDS_WAKETIME_OPP_CFG) = ulTicks-20;
\r
885 //*****************************************************************************
\r
887 //! Selects the GPIO for LPDS wakeup
\r
889 //! \param ulGPIOPin is one of the valid GPIO fro LPDS wakeup.
\r
890 //! \param ulType is the wakeup trigger type.
\r
892 //! This function setects the wakeup GPIO for LPDS wakeup and can be
\r
893 //! used to select one out of 7 pre-defined GPIO(s).
\r
895 //! The parameter \e ulLpdsGPIOSel should be one of the following:-
\r
896 //! -\b PRCM_LPDS_GPIO2
\r
897 //! -\b PRCM_LPDS_GPIO4
\r
898 //! -\b PRCM_LPDS_GPIO13
\r
899 //! -\b PRCM_LPDS_GPIO17
\r
900 //! -\b PRCM_LPDS_GPIO11
\r
901 //! -\b PRCM_LPDS_GPIO24
\r
902 //! -\b PRCM_LPDS_GPIO26
\r
904 //! The parameter \e ulType sets the trigger type and can be one of the
\r
906 //! - \b PRCM_LPDS_LOW_LEVEL
\r
907 //! - \b PRCM_LPDS_HIGH_LEVEL
\r
908 //! - \b PRCM_LPDS_FALL_EDGE
\r
909 //! - \b PRCM_LPDS_RISE_EDGE
\r
913 //*****************************************************************************
\r
915 PRCMLPDSWakeUpGPIOSelect(unsigned long ulGPIOPin, unsigned long ulType)
\r
918 // Set the wakeup GPIO
\r
920 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_LPDS_GPIO_SEL, ulGPIOPin);
\r
923 // Set the trigger type.
\r
925 HWREG(GPRCM_BASE + GPRCM_O_APPS_GPIO_WAKE_CONF) = (ulType & 0x3);
\r
928 //*****************************************************************************
\r
930 //! Puts the system into Sleep.
\r
932 //! This function puts the system into sleep power mode. System exits the power
\r
933 //! state on any one of the available interrupt. On exit from sleep mode the
\r
934 //! function returns to the calling function with all the processor core
\r
935 //! registers retained.
\r
939 //*****************************************************************************
\r
949 //*****************************************************************************
\r
951 //! Enable SRAM column retention during LPDS Power mode(s)
\r
953 //! \param ulSramColSel is bit mask of valid SRAM columns.
\r
954 //! \param ulModeFlags is the bit mask of power modes.
\r
956 //! This functions enables the SRAM retention. The device supports configurable
\r
957 //! SRAM column retention in Low Power Deep Sleep (LPDS). Each column is of
\r
960 //! The parameter \e ulSramColSel should be logical OR of the following:-
\r
961 //! -\b PRCM_SRAM_COL_1
\r
962 //! -\b PRCM_SRAM_COL_2
\r
963 //! -\b PRCM_SRAM_COL_3
\r
964 //! -\b PRCM_SRAM_COL_4
\r
966 //! The parameter \e ulModeFlags selects the power modes and sholud be logical
\r
967 //! OR of one or more of the following
\r
968 //! -\b PRCM_SRAM_LPDS_RET
\r
972 //****************************************************************************
\r
974 PRCMSRAMRetentionEnable(unsigned long ulSramColSel, unsigned long ulModeFlags)
\r
976 if(ulModeFlags & PRCM_SRAM_LPDS_RET)
\r
979 // Configure LPDS SRAM retention register
\r
981 HWREG(GPRCM_BASE+ GPRCM_O_APPS_SRAM_LPDS_CFG) = (ulSramColSel & 0xF);
\r
985 //*****************************************************************************
\r
987 //! Disable SRAM column retention during LPDS Power mode(s).
\r
989 //! \param ulSramColSel is bit mask of valid SRAM columns.
\r
990 //! \param ulFlags is the bit mask of power modes.
\r
992 //! This functions disable the SRAM retention. The device supports configurable
\r
993 //! SRAM column retention in Low Power Deep Sleep (LPDS). Each column is
\r
996 //! The parameter \e ulSramColSel should be logical OR of the following:-
\r
997 //! -\b PRCM_SRAM_COL_1
\r
998 //! -\b PRCM_SRAM_COL_2
\r
999 //! -\b PRCM_SRAM_COL_3
\r
1000 //! -\b PRCM_SRAM_COL_4
\r
1002 //! The parameter \e ulFlags selects the power modes and sholud be logical OR
\r
1003 //! of one or more of the following
\r
1004 //! -\b PRCM_SRAM_LPDS_RET
\r
1008 //****************************************************************************
\r
1010 PRCMSRAMRetentionDisable(unsigned long ulSramColSel, unsigned long ulFlags)
\r
1012 if(ulFlags & PRCM_SRAM_LPDS_RET)
\r
1015 // Configure LPDS SRAM retention register
\r
1017 HWREG(GPRCM_BASE+ GPRCM_O_APPS_SRAM_LPDS_CFG) &= ~(ulSramColSel & 0xF);
\r
1022 //*****************************************************************************
\r
1024 //! Enables individual HIB wakeup source(s).
\r
1026 //! \param ulHIBWakupSrc is logical OR of valid HIB wakeup sources.
\r
1028 //! This function enables individual HIB wakeup source(s). The paramter
\r
1029 //! \e ulHIBWakupSrc is the bit mask of HIB wakeup sources and should be
\r
1030 //! logical OR of one or more of the follwoing :-
\r
1031 //! -\b PRCM_HIB_SLOW_CLK_CTR
\r
1032 //! -\b PRCM_HIB_GPIO2
\r
1033 //! -\b PRCM_HIB_GPIO4
\r
1034 //! -\b PRCM_HIB_GPIO13
\r
1035 //! -\b PRCM_HIB_GPIO17
\r
1036 //! -\b PRCM_HIB_GPIO11
\r
1037 //! -\b PRCM_HIB_GPIO24
\r
1038 //! -\b PRCM_HIB_GPIO26
\r
1042 //*****************************************************************************
\r
1044 PRCMHibernateWakeupSourceEnable(unsigned long ulHIBWakupSrc)
\r
1046 unsigned long ulRegValue;
\r
1049 // Read the RTC register
\r
1051 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN);
\r
1054 // Enable the RTC as wakeup source if specified
\r
1056 ulRegValue |= (ulHIBWakupSrc & 0x1);
\r
1059 // Enable HIB wakeup sources
\r
1061 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN,ulRegValue);
\r
1064 // REad the GPIO wakeup configuration register
\r
1066 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_EN);
\r
1069 // Enable the specified GPIOs a wakeup sources
\r
1071 ulRegValue |= ((ulHIBWakupSrc>>16)&0xFF);
\r
1074 // Write the new register configuration
\r
1076 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_EN,ulRegValue);
\r
1079 //*****************************************************************************
\r
1081 //! Disable individual HIB wakeup source(s).
\r
1083 //! \param ulHIBWakupSrc is logical OR of valid HIB wakeup sources.
\r
1085 //! This function disable individual HIB wakeup source(s). The paramter
\r
1086 //! \e ulHIBWakupSrc is same as bit fileds defined in
\r
1087 //! PRCMEnableHibernateWakeupSource()
\r
1091 //*****************************************************************************
\r
1093 PRCMHibernateWakeupSourceDisable(unsigned long ulHIBWakupSrc)
\r
1095 unsigned long ulRegValue;
\r
1098 // Read the RTC register
\r
1100 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN);
\r
1103 // Disable the RTC as wakeup source if specified
\r
1105 ulRegValue &= ~(ulHIBWakupSrc & 0x1);
\r
1108 // Disable HIB wakeup sources
\r
1110 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN,ulRegValue);
\r
1113 // Read the GPIO wakeup configuration register
\r
1115 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_EN);
\r
1118 // Enable the specified GPIOs a wakeup sources
\r
1120 ulRegValue &= ~((ulHIBWakupSrc>>16)&0xFF);
\r
1123 // Write the new register configuration
\r
1125 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_EN,ulRegValue);
\r
1129 //*****************************************************************************
\r
1131 //! Get hibernate wakeup cause
\r
1133 //! This function gets the hibernate wakeup cause.
\r
1135 //! \return Returns \b PRCM_HIB_WAKEUP_CAUSE_SLOW_CLOCK or
\r
1136 //! \b PRCM_HIB_WAKEUP_CAUSE_GPIO
\r
1138 //*****************************************************************************
\r
1140 PRCMHibernateWakeupCauseGet()
\r
1143 // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
\r
1145 if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
\r
1147 return ((PRCMHIBRegRead((OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8))>>2)&0xF);
\r
1155 //*****************************************************************************
\r
1157 //! Sets Hibernate wakeup Timer
\r
1159 //! \param ullTicks is number of 32.768 KHz clocks
\r
1161 //! This function sets internal hibernate wakeup timer running at 32.768 KHz.
\r
1163 //! \return Returns \b true on success, \b false otherwise.
\r
1165 //*****************************************************************************
\r
1167 PRCMHibernateIntervalSet(unsigned long long ullTicks)
\r
1169 unsigned long long ullRTCVal;
\r
1172 // Latch the RTC vlaue
\r
1174 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_READ ,0x1);
\r
1177 // Read latched values as 2 32-bit vlaues
\r
1179 ullRTCVal = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_TIMER_MSW);
\r
1180 ullRTCVal = ullRTCVal << 32;
\r
1181 ullRTCVal |= PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_LSW);
\r
1184 // Add the interval
\r
1186 ullRTCVal = ullRTCVal + ullTicks;
\r
1189 // Set RTC match value
\r
1191 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_LSW_CONF,
\r
1192 (unsigned long)(ullRTCVal));
\r
1193 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_MSW_CONF,
\r
1194 (unsigned long)(ullRTCVal>>32));
\r
1198 //*****************************************************************************
\r
1200 //! Selects the GPIO(s) for hibernate wakeup
\r
1202 //! \param ulGPIOBitMap is the bit-map of valid hibernate wakeup GPIO.
\r
1203 //! \param ulType is the wakeup trigger type.
\r
1205 //! This function setects the wakeup GPIO for hibernate and can be
\r
1206 //! used to select any combination of 7 pre-defined GPIO(s).
\r
1208 //! This function enables individual HIB wakeup source(s). The paramter
\r
1209 //! \e ulGPIOBitMap should be one of the follwoing :-
\r
1210 //! -\b PRCM_HIB_GPIO2
\r
1211 //! -\b PRCM_HIB_GPIO4
\r
1212 //! -\b PRCM_HIB_GPIO13
\r
1213 //! -\b PRCM_HIB_GPIO17
\r
1214 //! -\b PRCM_HIB_GPIO11
\r
1215 //! -\b PRCM_HIB_GPIO24
\r
1216 //! -\b PRCM_HIB_GPIO26
\r
1218 //! The parameter \e ulType sets the trigger type and can be one of the
\r
1220 //! - \b PRCM_HIB_LOW_LEVEL
\r
1221 //! - \b PRCM_HIB_HIGH_LEVEL
\r
1222 //! - \b PRCM_HIB_FALL_EDGE
\r
1223 //! - \b PRCM_HIB_RISE_EDGE
\r
1227 //*****************************************************************************
\r
1229 PRCMHibernateWakeUpGPIOSelect(unsigned long ulGPIOBitMap, unsigned long ulType)
\r
1231 unsigned char ucLoop;
\r
1232 unsigned long ulRegValue;
\r
1235 // Shift the bits to extract the GPIO selection
\r
1237 ulGPIOBitMap >>= 16;
\r
1240 // Set the configuration for each GPIO
\r
1242 for(ucLoop=0; ucLoop < 7; ucLoop++)
\r
1244 if(ulGPIOBitMap & (1<<ucLoop))
\r
1246 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_CONF);
\r
1247 ulRegValue = (ulRegValue & (~(0x3 << (ucLoop*2)))) | (ulType <<(ucLoop*2));
\r
1248 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_GPIO_WAKE_CONF, ulRegValue);
\r
1253 //*****************************************************************************
\r
1255 //! Puts the system into Hibernate
\r
1257 //! This function puts the system into Hibernate. The device enters HIB
\r
1258 //! immediately and on exit from HIB device core starts its execution from
\r
1259 //! reset thus the function never returns.
\r
1263 //*****************************************************************************
\r
1265 PRCMHibernateEnter()
\r
1269 // Request hibernate.
\r
1271 PRCMHIBRegWrite((HIB3P3_BASE+HIB3P3_O_MEM_HIB_REQ),0x1);
\r
1274 // Wait for system to enter hibernate
\r
1287 //*****************************************************************************
\r
1289 //! Gets the current value of the internal slow clock counter
\r
1291 //! This function latches and reads the internal RTC running at 32.768 Khz
\r
1293 //! \return 64-bit current counter vlaue.
\r
1295 //*****************************************************************************
\r
1296 unsigned long long
\r
1297 PRCMSlowClkCtrGet()
\r
1299 unsigned long long ullRTCVal;
\r
1302 // Latch the RTC vlaue
\r
1304 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_READ, 0x1);
\r
1307 // Read latched values as 2 32-bit vlaues
\r
1309 ullRTCVal = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_TIMER_MSW);
\r
1310 ullRTCVal = ullRTCVal << 32;
\r
1311 ullRTCVal |= PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_LSW);
\r
1316 //*****************************************************************************
\r
1318 //! Gets the current value of the internal slow clock counter
\r
1320 //! This function is similar to \sa PRCMSlowClkCtrGet() but reads the counter
\r
1321 //! value from a relatively faster interface using an auto-latch mechainsm.
\r
1323 //! \note Due to the nature of implemetation of auto latching, when using this
\r
1324 //! API, the recommendation is to read the value thrice and identify the right
\r
1325 //! value (as 2 out the 3 read values will always be correct and with a max. of
\r
1328 //! \return 64-bit current counter vlaue.
\r
1330 //*****************************************************************************
\r
1331 unsigned long long PRCMSlowClkCtrFastGet(void)
\r
1333 unsigned long long ullRTCVal;
\r
1336 // Read as 2 32-bit values
\r
1338 ullRTCVal = HWREG(HIB1P2_BASE + HIB1P2_O_HIB_RTC_TIMER_MSW_1P2);
\r
1339 ullRTCVal = ullRTCVal << 32;
\r
1340 ullRTCVal |= HWREG(HIB1P2_BASE + HIB1P2_O_HIB_RTC_TIMER_LSW_1P2);
\r
1346 //*****************************************************************************
\r
1348 //! Sets slow clock counter match value to interrupt the processor.
\r
1350 //! \param ullValue is the match value.
\r
1352 //! This function sets the match value for slow clock counter. This is use
\r
1353 //! to interrupt the processor when RTC counts to the specified value.
\r
1357 //*****************************************************************************
\r
1358 void PRCMSlowClkCtrMatchSet(unsigned long long ullValue)
\r
1361 // Set RTC match value
\r
1363 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_LSW_CONF,
\r
1364 (unsigned long)(ullValue));
\r
1365 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_MSW_CONF,
\r
1366 (unsigned long)(ullValue>>32));
\r
1369 //*****************************************************************************
\r
1371 //! Gets slow clock counter match value.
\r
1373 //! This function gets the match value for slow clock counter. This is use
\r
1374 //! to interrupt the processor when RTC counts to the specified value.
\r
1378 //*****************************************************************************
\r
1379 unsigned long long PRCMSlowClkCtrMatchGet()
\r
1381 unsigned long long ullValue;
\r
1384 // Get RTC match value
\r
1386 ullValue = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_MSW_CONF);
\r
1387 ullValue = ullValue<<32;
\r
1388 ullValue |= PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_LSW_CONF);
\r
1391 // Return the value
\r
1397 //*****************************************************************************
\r
1399 //! Write to On-Chip Retention (OCR) register.
\r
1401 //! This function writes to On-Chip retention register. The device supports two
\r
1402 //! 4-byte OCR register which are retained across all power mode.
\r
1404 //! The parameter \e ucIndex is an index of the OCR and can be \b 0 or \b 1.
\r
1406 //! These registers are shared by the RTC implementation (if Driverlib RTC
\r
1407 //! APIs are used), ROM, and user application.
\r
1409 //! When RTC APIs in use:
\r
1411 //! |-----------------------------------------------|
\r
1413 //! |-----------------------------------------------|
\r
1414 //! |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|
\r
1415 //! |-----------------------------------------------|
\r
1416 //! | Reserved by RTC APIs - YY |
\r
1417 //! |-----------------------------------------------|
\r
1418 //! |15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
\r
1419 //! |-----------------------------------------------|
\r
1420 //! | Reserved by RTC APIs - YY |
\r
1421 //! |-----------------------------------------------|
\r
1424 //! |-----------------------------------------------|
\r
1426 //! |-----------------------------------------------|
\r
1427 //! |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|
\r
1428 //! |-----------------------------------------------|
\r
1429 //! | Reserved by RTC APIs - YY |
\r
1430 //! |-----------------------------------------------|
\r
1431 //! |15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
\r
1432 //! |-----------------------------------------------|
\r
1433 //! |YY| For User Application |XX|
\r
1434 //! |-----------------------------------------------|
\r
1436 //! YY => Reserved by RTC APIs. If Driverlib RTC APIs are used
\r
1437 //! XX => Reserved by ROM
\r
1440 //! When RTC APIs are not in use:
\r
1442 //! |-----------------------------------------------|
\r
1444 //! |-----------------------------------------------|
\r
1445 //! |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|
\r
1446 //! |-----------------------------------------------|
\r
1447 //! | For User Application |
\r
1448 //! |-----------------------------------------------|
\r
1449 //! |15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
\r
1450 //! |-----------------------------------------------|
\r
1451 //! | For User Application |
\r
1452 //! |-----------------------------------------------|
\r
1455 //! |-----------------------------------------------|
\r
1457 //! |-----------------------------------------------|
\r
1458 //! |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|
\r
1459 //! |-----------------------------------------------|
\r
1460 //! | For User Application |
\r
1461 //! |-----------------------------------------------|
\r
1462 //! |15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
\r
1463 //! |-----------------------------------------------|
\r
1464 //! | For User Application |XX|
\r
1465 //! |-----------------------------------------------|
\r
1467 //! XX => Reserved by ROM
\r
1473 //*****************************************************************************
\r
1474 void PRCMOCRRegisterWrite(unsigned char ucIndex, unsigned long ulRegValue)
\r
1476 unsigned long ulVal;
\r
1479 // Compuitr the offset
\r
1481 ucIndex = ucIndex << 2;
\r
1484 // If bit 0 is reserved
\r
1486 if( (HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) & (0x00000080)) &&
\r
1489 ulVal = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG2 + ucIndex);
\r
1490 ulRegValue = ((ulRegValue << 0x1) | (ulVal & (0x1)));
\r
1494 // Write thr value
\r
1496 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG2 + ucIndex,ulRegValue);
\r
1500 //*****************************************************************************
\r
1502 //! Read from On-Chip Retention (OCR) register.
\r
1504 //! This function reads from On-Chip retention register. The device supports two
\r
1505 //! 4-byte OCR register which are retained across all power mode.
\r
1507 //! The parameter \e ucIndex is an index of the OCR and can be \b 0 or \b 1.
\r
1509 //! \sa PRCMOCRRegisterWrite() for the register usage details.
\r
1513 //*****************************************************************************
\r
1514 unsigned long PRCMOCRRegisterRead(unsigned char ucIndex)
\r
1516 unsigned long ulRet;
\r
1519 // Read the OCR register
\r
1521 ulRet = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_REG2 + (ucIndex << 2));
\r
1524 // If bit 0 is reserved
\r
1526 if( (HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) & (0x00000080)) &&
\r
1529 ulRet = ulRet >> 0x1;
\r
1533 // Return the read value.
\r
1538 //*****************************************************************************
\r
1540 //! Registers an interrupt handler for the PRCM.
\r
1542 //! \param pfnHandler is a pointer to the function to be called when the
\r
1543 //! interrupt is activated.
\r
1545 //! This function does the actual registering of the interrupt handler. This
\r
1546 //! function enables the global interrupt in the interrupt controller;
\r
1550 //*****************************************************************************
\r
1551 void PRCMIntRegister(void (*pfnHandler)(void))
\r
1554 // Register the interrupt handler.
\r
1556 IntRegister(INT_PRCM, pfnHandler);
\r
1559 // Enable the PRCM interrupt.
\r
1561 IntEnable(INT_PRCM);
\r
1564 //*****************************************************************************
\r
1566 //! Unregisters an interrupt handler for the PRCM.
\r
1568 //! This function does the actual unregistering of the interrupt handler. It
\r
1569 //! clears the handler to be called when a PRCM interrupt occurs. This
\r
1570 //! function also masks off the interrupt in the interrupt controller so that
\r
1571 //! the interrupt handler no longer is called.
\r
1575 //*****************************************************************************
\r
1576 void PRCMIntUnregister()
\r
1579 // Enable the UART interrupt.
\r
1581 IntDisable(INT_PRCM);
\r
1584 // Register the interrupt handler.
\r
1586 IntUnregister(INT_PRCM);
\r
1589 //*****************************************************************************
\r
1591 //! Enables individual PRCM interrupt sources.
\r
1593 //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
\r
1595 //! This function enables the indicated ARCM interrupt sources. Only the
\r
1596 //! sources that are enabled can be reflected to the processor interrupt;
\r
1597 //! disabled sources have no effect on the processor.
\r
1599 //! The \e ulIntFlags parameter is the logical OR of any of the following:
\r
1600 //! -\b PRCM_INT_SLOW_CLK_CTR
\r
1603 //*****************************************************************************
\r
1604 void PRCMIntEnable(unsigned long ulIntFlags)
\r
1606 unsigned long ulRegValue;
\r
1608 if(ulIntFlags & PRCM_INT_SLOW_CLK_CTR )
\r
1611 // Enable PRCM interrupt
\r
1613 HWREG(ARCM_BASE + APPS_RCM_O_APPS_RCM_INTERRUPT_ENABLE) |= 0x4;
\r
1616 // Enable RTC interrupt
\r
1618 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_ENABLE);
\r
1619 ulRegValue |= 0x1;
\r
1620 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_ENABLE, ulRegValue);
\r
1624 //*****************************************************************************
\r
1626 //! Disables individual PRCM interrupt sources.
\r
1628 //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
\r
1630 //! This function disables the indicated ARCM interrupt sources. Only the
\r
1631 //! sources that are enabled can be reflected to the processor interrupt;
\r
1632 //! disabled sources have no effect on the processor.
\r
1634 //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags
\r
1635 //! parameter to PRCMEnableInterrupt().
\r
1639 //*****************************************************************************
\r
1640 void PRCMIntDisable(unsigned long ulIntFlags)
\r
1642 unsigned long ulRegValue;
\r
1644 if(ulIntFlags & PRCM_INT_SLOW_CLK_CTR )
\r
1647 // Disable PRCM interrupt
\r
1649 HWREG(ARCM_BASE + APPS_RCM_O_APPS_RCM_INTERRUPT_ENABLE) &= ~0x4;
\r
1652 // Disable RTC interrupt
\r
1654 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_ENABLE);
\r
1655 ulRegValue &= ~0x1;
\r
1656 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_IRQ_ENABLE, ulRegValue);
\r
1660 //*****************************************************************************
\r
1662 //! Gets the current interrupt status.
\r
1664 //! This function returns the PRCM interrupt status of interrupts that are
\r
1665 //! allowed to reflect to the processor. The interrupts are cleared on read.
\r
1667 //! \return Returns the current interrupt status.
\r
1669 //*****************************************************************************
\r
1670 unsigned long PRCMIntStatus()
\r
1672 return HWREG(ARCM_BASE + APPS_RCM_O_APPS_RCM_INTERRUPT_STATUS);
\r
1675 //*****************************************************************************
\r
1677 //! Mark the function of RTC as being used
\r
1679 //! This function marks in HW that feature to maintain calendar time in device
\r
1680 //! is being used.
\r
1682 //! Specifically, this feature reserves user's HIB Register-1 accessed through
\r
1683 //! PRCMOCRRegisterWrite(1) for internal work / purpose, therefore, the stated
\r
1684 //! register is not available to user. Also, users must not excercise the Slow
\r
1685 //! Clock Counter API(s), if RTC has been set for use.
\r
1687 //! The RTC feature, if set or marked, can be only reset either through reboot
\r
1688 //! or power cycle.
\r
1692 //*****************************************************************************
\r
1693 void PRCMRTCInUseSet()
\r
1699 //*****************************************************************************
\r
1701 //! Ascertain whether function of RTC is being used
\r
1703 //! This function indicates whether function of RTC is being used on the device
\r
1706 //! This routine should be utilized by the application software, when returning
\r
1707 //! from low-power, to confirm that RTC has been put to use and may not need to
\r
1708 //! set the value of the RTC.
\r
1710 //! The RTC feature, if set or marked, can be only reset either through reboot
\r
1711 //! or power cycle.
\r
1715 //*****************************************************************************
\r
1716 tBoolean PRCMRTCInUseGet()
\r
1718 return IS_RTC_USED()? true : false;
\r
1721 //*****************************************************************************
\r
1723 //! Set the calendar time in the device.
\r
1725 //! \param ulSecs refers to the seconds part of the calendar time
\r
1726 //! \param usMsec refers to the fractional (ms) part of the second
\r
1728 //! This function sets the specified calendar time in the device. The calendar
\r
1729 //! time is outlined in terms of seconds and milliseconds. However, the device
\r
1730 //! makes no assumption about the origin or reference of the calendar time.
\r
1732 //! The device uses the indicated calendar value to update and maintain the
\r
1733 //! wall-clock time across active and low power states.
\r
1735 //! The function PRCMRTCInUseSet() must be invoked prior to use of this feature.
\r
1739 //*****************************************************************************
\r
1740 void PRCMRTCSet(unsigned long ulSecs, unsigned short usMsec)
\r
1742 unsigned long long ullMsec = 0;
\r
1744 if(IS_RTC_USED()) {
\r
1745 ullMsec = RTC_U64MSEC_MK(ulSecs, usMsec) - SCC_U64MSEC_GET();
\r
1747 RTC_U32SECS_REG_WR(RTC_SECS_IN_U64MSEC(ullMsec));
\r
1748 RTC_U16MSEC_REG_WR(RTC_MSEC_IN_U64MSEC(ullMsec));
\r
1754 //*****************************************************************************
\r
1756 //! Get the instantaneous calendar time from the device.
\r
1758 //! \param ulSecs refers to the seconds part of the calendar time
\r
1759 //! \param usMsec refers to the fractional (ms) part of the second
\r
1761 //! This function fetches the instantaneous value of the ticking calendar time
\r
1762 //! from the device. The calendar time is outlined in terms of seconds and
\r
1765 //! The device provides the calendar value that has been maintained across
\r
1766 //! active and low power states.
\r
1768 //! The function PRCMRTCSet() must have been invoked once to set a reference.
\r
1772 //*****************************************************************************
\r
1773 void PRCMRTCGet(unsigned long *ulSecs, unsigned short *usMsec)
\r
1775 unsigned long long ullMsec = 0;
\r
1777 if(IS_RTC_USED()) {
\r
1778 ullMsec = RTC_U64MSEC_MK(RTC_U32SECS_REG_RD(),
\r
1779 RTC_U16MSEC_REG_RD());
\r
1780 ullMsec += SCC_U64MSEC_GET();
\r
1783 *ulSecs = RTC_SECS_IN_U64MSEC(ullMsec);
\r
1784 *usMsec = RTC_MSEC_IN_U64MSEC(ullMsec);
\r
1789 //*****************************************************************************
\r
1791 //! Set a calendar time alarm.
\r
1793 //! \param ulSecs refers to the seconds part of the calendar time
\r
1794 //! \param usMsec refers to the fractional (ms) part of the second
\r
1796 //! This function sets an wall-clock alarm in the device to be reported for a
\r
1797 //! futuristic calendar time. The calendar time is outlined in terms of seconds
\r
1798 //! and milliseconds.
\r
1800 //! The device provides uses the calendar value that has been maintained across
\r
1801 //! active and low power states to report attainment of alarm time.
\r
1803 //! The function PRCMRTCSet() must have been invoked once to set a reference.
\r
1807 //*****************************************************************************
\r
1808 void PRCMRTCMatchSet(unsigned long ulSecs, unsigned short usMsec)
\r
1810 unsigned long long ullMsec = 0;
\r
1812 if(IS_RTC_USED()) {
\r
1813 ullMsec = RTC_U64MSEC_MK(ulSecs, usMsec);
\r
1814 ullMsec -= RTC_U64MSEC_MK(RTC_U32SECS_REG_RD(),
\r
1815 RTC_U16MSEC_REG_RD());
\r
1816 SCC_U64MSEC_MATCH_SET(SELECT_SCC_U42BITS(ullMsec));
\r
1822 //*****************************************************************************
\r
1824 //! Get a previously set calendar time alarm.
\r
1826 //! \param ulSecs refers to the seconds part of the calendar time
\r
1827 //! \param usMsec refers to the fractional (ms) part of the second
\r
1829 //! This function fetches from the device a wall-clock alarm that would have
\r
1830 //! been previously set in the device. The calendar time is outlined in terms
\r
1831 //! of seconds and milliseconds.
\r
1833 //! If no alarm was set in the past, then this function would fetch a random
\r
1836 //! The function PRCMRTCMatchSet() must have been invoked once to set an alarm.
\r
1840 //*****************************************************************************
\r
1841 void PRCMRTCMatchGet(unsigned long *ulSecs, unsigned short *usMsec)
\r
1843 unsigned long long ullMsec = 0;
\r
1845 if(IS_RTC_USED()) {
\r
1846 ullMsec = SCC_U64MSEC_MATCH_GET();
\r
1847 ullMsec += RTC_U64MSEC_MK(RTC_U32SECS_REG_RD(),
\r
1848 RTC_U16MSEC_REG_RD());
\r
1851 *ulSecs = RTC_SECS_IN_U64MSEC(ullMsec);
\r
1852 *usMsec = RTC_MSEC_IN_U64MSEC(ullMsec);
\r
1857 //*****************************************************************************
\r
1859 //! MCU Initialization Routine
\r
1861 //! This function contains all the mandatory bug fixes, ECO enables,
\r
1862 //! initializations for both CC3200 and CC3220.
\r
1864 //! \note \b ###IMPORTANT### : This is a routine which should be one of the
\r
1865 //! first things to be executed after control comes to MCU Application code.
\r
1869 //*****************************************************************************
\r
1870 void PRCMCC3200MCUInit()
\r
1873 if( PRCMSysResetCauseGet() != PRCM_LPDS_EXIT )
\r
1875 if( 0x00010001 == HWREG(0x00000400) )
\r
1878 #ifndef REMOVE_CC3200_ES_1_2_1_CODE
\r
1880 unsigned long ulRegVal;
\r
1883 // DIG DCDC NFET SEL and COT mode disable
\r
1885 HWREG(0x4402F010) = 0x30031820;
\r
1886 HWREG(0x4402F00C) = 0x04000000;
\r
1888 UtilsDelay(32000);
\r
1891 // ANA DCDC clock config
\r
1893 HWREG(0x4402F11C) = 0x099;
\r
1894 HWREG(0x4402F11C) = 0x0AA;
\r
1895 HWREG(0x4402F11C) = 0x1AA;
\r
1898 // PA DCDC clock config
\r
1900 HWREG(0x4402F124) = 0x099;
\r
1901 HWREG(0x4402F124) = 0x0AA;
\r
1902 HWREG(0x4402F124) = 0x1AA;
\r
1905 // TD Flash timing configurations in case of MCU WDT reset
\r
1907 if((HWREG(0x4402D00C) & 0xFF) == 0x00000005)
\r
1909 HWREG(0x400F707C) |= 0x01840082;
\r
1910 HWREG(0x400F70C4)= 0x1;
\r
1911 HWREG(0x400F70C4)= 0x0;
\r
1915 // Take I2C semaphore
\r
1917 ulRegVal = HWREG(0x400F7000);
\r
1918 ulRegVal = (ulRegVal & ~0x3) | 0x1;
\r
1919 HWREG(0x400F7000) = ulRegVal;
\r
1922 // Take GPIO semaphore
\r
1924 ulRegVal = HWREG(0x400F703C);
\r
1925 ulRegVal = (ulRegVal & ~0x3FF) | 0x155;
\r
1926 HWREG(0x400F703C) = ulRegVal;
\r
1929 // Enable 32KHz internal RC oscillator
\r
1931 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_INT_OSC_CONF, 0x00000101);
\r
1934 // Delay for a little bit.
\r
1939 // Enable 16MHz clock
\r
1941 HWREG(HIB1P2_BASE+HIB1P2_O_CM_OSC_16M_CONFIG) = 0x00010008;
\r
1944 // Delay for a little bit.
\r
1948 #endif // REMOVE_CC3200_ES_1_2_1_CODE
\r
1954 unsigned long ulRegValue;
\r
1957 // DIG DCDC LPDS ECO Enable
\r
1959 HWREG(0x4402F064) |= 0x800000;
\r
1962 // Enable hibernate ECO for PG 1.32 devices only. With this ECO enabled,
\r
1963 // any hibernate wakeup source will be kept maked until the device enters
\r
1964 // hibernate completely (analog + digital)
\r
1966 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG0);
\r
1967 PRCMHIBRegWrite(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG0, ulRegValue | (1<<4));
\r
1970 // Handling the clock switching (for 1.32 only)
\r
1972 HWREG(0x4402E16C) |= 0x3C;
\r
1979 PRCMPeripheralClkEnable(PRCM_UDMA,PRCM_RUN_MODE_CLK);
\r
1984 PRCMPeripheralReset(PRCM_UDMA);
\r
1989 PRCMPeripheralClkDisable(PRCM_UDMA,PRCM_RUN_MODE_CLK);
\r
1994 if(PRCMSysResetCauseGet()== PRCM_POWER_ON)
\r
1996 PRCMHIBRegWrite(0x4402F804,0x1);
\r
2002 if(((HWREG(0x4402F0C8) & 0xFF) == 0x2))
\r
2004 HWREG(0x4402E110) = ((HWREG(0x4402E110) & ~0xC0F) | 0x2);
\r
2005 HWREG(0x4402E114) = ((HWREG(0x4402E110) & ~0xC0F) | 0x2);
\r
2009 // Override JTAG mux
\r
2011 HWREG(0x4402E184) |= 0x2;
\r
2014 // Change UART pins(55,57) mode to PIN_MODE_0 if they are in PIN_MODE_1
\r
2016 if( (HWREG(0x4402E0A4) & 0xF) == 0x1)
\r
2018 HWREG(0x4402E0A4) = ((HWREG(0x4402E0A4) & ~0xF));
\r
2021 if( (HWREG(0x4402E0A8) & 0xF) == 0x1)
\r
2023 HWREG(0x4402E0A8) = ((HWREG(0x4402E0A8) & ~0xF));
\r
2027 // DIG DCDC VOUT trim settings based on PROCESS INDICATOR
\r
2029 if(((HWREG(0x4402DC78) >> 22) & 0xF) == 0xE)
\r
2031 HWREG(0x4402F0B0) = ((HWREG(0x4402F0B0) & ~(0x00FC0000))|(0x32 << 18));
\r
2035 HWREG(0x4402F0B0) = ((HWREG(0x4402F0B0) & ~(0x00FC0000))|(0x29 << 18));
\r
2039 // Enable SOFT RESTART in case of DIG DCDC collapse
\r
2041 HWREG(0x4402FC74) &= ~(0x10000000);
\r
2044 // Required only if ROM version is lower than 2.x.x
\r
2046 if( (HWREG(0x00000400) & 0xFFFF) < 2 )
\r
2049 // Disable the sleep for ANA DCDC
\r
2051 HWREG(0x4402F0A8) |= 0x00000004 ;
\r
2053 else if( (HWREG(0x00000400) >> 16) >= 1 )
\r
2056 // Enable NWP force reset and HIB on WDT reset
\r
2057 // Enable direct boot path for flash
\r
2059 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) |= ((7<<5) | 0x1);
\r
2060 if((HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG2) & 0x1) )
\r
2062 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG2) &= ~0x1;
\r
2063 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_SPARE_REG_8) |= (1<<9);
\r
2066 // Clear the RTC hib wake up source
\r
2068 HWREG(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN) &= ~0x1;
\r
2071 // Reset RTC match value
\r
2073 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_WAKE_LSW_CONF) = 0;
\r
2074 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_WAKE_MSW_CONF) = 0;
\r
2079 unsigned long efuse_reg2;
\r
2080 unsigned long ulDevMajorVer, ulDevMinorVer;
\r
2082 // Read the device identification register
\r
2084 efuse_reg2= HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG2);
\r
2087 // Read the ROM mojor and minor version
\r
2089 ulDevMajorVer = ((efuse_reg2 >> 28) & 0xF);
\r
2090 ulDevMinorVer = ((efuse_reg2 >> 24) & 0xF);
\r
2092 if(((ulDevMajorVer == 0x3) && (ulDevMinorVer == 0)) || (ulDevMajorVer < 0x3))
\r
2094 unsigned int Scratch, PreRegulatedMode;
\r
2096 // 0x4402F840 => 6th bit
\931
\94 indicates device is in pre-regulated mode.
\r
2097 PreRegulatedMode = (HWREG(0x4402F840) >> 6) & 1;
\r
2099 if( PreRegulatedMode)
\r
2101 Scratch = HWREG(0x4402F028);
\r
2102 Scratch &= 0xFFFFFF7F; // <7:7> = 0
\r
2103 HWREG(0x4402F028) = Scratch;
\r
2105 Scratch = HWREG(0x4402F010);
\r
2106 Scratch &= 0x0FFFFFFF; // <31:28> = 0
\r
2107 Scratch |= 0x10000000; // <31:28> = 1
\r
2108 HWREG(0x4402F010) = Scratch;
\r
2112 Scratch = HWREG(0x4402F024);
\r
2114 Scratch &= 0xFFFFFFF0; // <3:0> = 0
\r
2115 Scratch |= 0x00000001; // <3:0> = 1
\r
2116 Scratch &= 0xFFFFF0FF; // <11:8> = 0000
\r
2117 Scratch |= 0x00000500; // <11:8> = 0101
\r
2118 Scratch &= 0xFFFE7FFF; // <16:15> = 0000
\r
2119 Scratch |= 0x00010000; // <16:15> = 10
\r
2121 HWREG(0x4402F024) = Scratch;
\r
2123 Scratch = HWREG(0x4402F028);
\r
2125 Scratch &= 0xFFFFFF7F; // <7:7> = 0
\r
2126 Scratch &= 0x0FFFFFFF; // <31:28> = 0
\r
2127 Scratch &= 0xFF0FFFFF; // <23:20> = 0
\r
2128 Scratch |= 0x00300000; // <23:20> = 0011
\r
2129 Scratch &= 0xFFF0FFFF; // <19:16> = 0
\r
2130 Scratch |= 0x00030000; // <19:16> = 0011
\r
2132 HWREG(0x4402F028) = Scratch;
\r
2133 HWREG(0x4402F010) &= 0x0FFFFFFF; // <31:28> = 0
\r
2138 unsigned int Scratch, PreRegulatedMode;
\r
2140 // 0x4402F840 => 6th bit
\931
\94 indicates device is in pre-regulated mode.
\r
2141 PreRegulatedMode = (HWREG(0x4402F840) >> 6) & 1;
\r
2143 Scratch = HWREG(0x4402F028);
\r
2144 Scratch &= 0xFFFFFF7F; // <7:7> = 0
\r
2145 HWREG(0x4402F028) = Scratch;
\r
2147 HWREG(0x4402F010) &= 0x0FFFFFFF; // <31:28> = 0
\r
2148 if( PreRegulatedMode)
\r
2150 HWREG(0x4402F010) |= 0x10000000; // <31:28> = 1
\r
2156 unsigned long ulRegVal;
\r
2159 // I2C Configuration
\r
2161 ulRegVal = HWREG(COMMON_REG_BASE + COMMON_REG_O_I2C_Properties_Register);
\r
2162 ulRegVal = (ulRegVal & ~0x3) | 0x1;
\r
2163 HWREG(COMMON_REG_BASE + COMMON_REG_O_I2C_Properties_Register) = ulRegVal;
\r
2166 // GPIO configuration
\r
2168 ulRegVal = HWREG(COMMON_REG_BASE + COMMON_REG_O_GPIO_properties_register);
\r
2169 ulRegVal = (ulRegVal & ~0x3FF) | 0x155;
\r
2170 HWREG(COMMON_REG_BASE + COMMON_REG_O_GPIO_properties_register) = ulRegVal;
\r
2175 //*****************************************************************************
\r
2177 //! Reads 32-bit value from register at specified address
\r
2179 //! \param ulRegAddr is the address of register to be read.
\r
2181 //! This function reads 32-bit value from the register as specified by
\r
2184 //! \return Return the value of the register.
\r
2186 //*****************************************************************************
\r
2187 unsigned long PRCMHIBRegRead(unsigned long ulRegAddr)
\r
2189 unsigned long ulValue;
\r
2192 // Read the Reg value
\r
2194 ulValue = HWREG(ulRegAddr);
\r
2197 // Wait for 200 uSec
\r
2199 UtilsDelay((80*200)/3);
\r
2202 // Return the value
\r
2207 //*****************************************************************************
\r
2209 //! Writes 32-bit value to register at specified address
\r
2211 //! \param ulRegAddr is the address of register to be read.
\r
2212 //! \param ulValue is the 32-bit value to be written.
\r
2214 //! This function writes 32-bit value passed as \e ulValue to the register as
\r
2215 //! specified by \e ulRegAddr
\r
2219 //*****************************************************************************
\r
2220 void PRCMHIBRegWrite(unsigned long ulRegAddr, unsigned long ulValue)
\r
2223 // Read the Reg value
\r
2225 HWREG(ulRegAddr) = ulValue;
\r
2228 // Wait for 200 uSec
\r
2230 UtilsDelay((80*200)/3);
\r
2233 //*****************************************************************************
\r
2235 //! \param ulDivider is clock frequency divider value
\r
2236 //! \param ulWidth is the width of the high pulse
\r
2238 //! This function sets the input frequency for camera module.
\r
2240 //! The frequency is calculated as follows:
\r
2242 //! f_out = 240MHz/ulDivider;
\r
2244 //! The parameter \e ulWidth sets the width of the high pulse.
\r
2248 //! ulDivider = 4;
\r
2251 //! f_out = 30 MHz and 50% duty cycle
\r
2255 //! ulDivider = 4;
\r
2258 //! f_out = 30 MHz and 25% duty cycle
\r
2260 //! \return 0 on success, 1 on error
\r
2262 //*****************************************************************************
\r
2263 unsigned long PRCMCameraFreqSet(unsigned char ulDivider, unsigned char ulWidth)
\r
2265 if(ulDivider > ulWidth && ulWidth != 0 )
\r
2268 // Set the hifh pulse width
\r
2271 APPS_RCM_O_CAMERA_CLK_GEN) = (((ulWidth & 0x07) -1) << 8);
\r
2274 // Set the low pulse width
\r
2277 APPS_RCM_O_CAMERA_CLK_GEN) = ((ulDivider - ulWidth - 1) & 0x07);
\r
2290 //*****************************************************************************
\r
2292 //! Enable the IO value retention
\r
2294 //! \param ulIORetGrpFlags is one of the valid IO groups.
\r
2296 //! This function enables the IO retention for group of pins as specified by
\r
2297 //! \e ulIORetGrpFlags parameter. Enabling retention will immediately lock the
\r
2298 //! digital pins, in the specified group, to their current state (0 or 1).
\r
2299 //! Output pins can only be driven when retention is disabled.
\r
2301 //! The parameter \e ulIORetGrpFlags can be logical OR of one or
\r
2302 //! more of the following:
\r
2303 //! -\b PRCM_IO_RET_GRP_0 - All the pins except sFlash and JTAG interface
\r
2304 //! -\b PRCM_IO_RET_GRP_1 - sFlash interface pins 11,12,13,14
\r
2305 //! -\b PRCM_IO_RET_GRP_2 - JTAG TDI and TDO interface pins 16,17
\r
2306 //! -\b PRCM_IO_RET_GRP_3 - JTAG TCK and TMS interface pins 19,20
\r
2308 //! \note Use case is to park the pins when entering HIB.
\r
2312 //*****************************************************************************
\r
2313 void PRCMIORetentionEnable(unsigned long ulIORetGrpFlags)
\r
2317 // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
\r
2319 if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
\r
2322 // Disable IO Pad to ODI Path
\r
2324 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG) |= 0x00001F00;
\r
2327 // 0b'0 in bit 5 for JTAG PADS
\r
2328 // 0b'0 in bit 0 for all other IOs
\r
2330 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG) &= ~(0x00000023);
\r
2333 // Enable retention for GRP0
\r
2335 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_0 )
\r
2337 HWREG(HIB3P3_BASE+HIB3P3_O_MEM_PAD_OEN_RET33_CONF) |= 0x5;
\r
2341 // Enable retention for GRP1
\r
2343 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_1 )
\r
2345 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG0) |= ((0x3<<5));
\r
2349 // Enable retention for GRP2
\r
2351 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_2 )
\r
2353 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_JTAG_CONF) |= 0x00000101;
\r
2357 // Enable retention for GRP3
\r
2359 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_3 )
\r
2361 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_JTAG_CONF) |= 0x00000204;
\r
2366 //*****************************************************************************
\r
2368 //! Disable the IO value retention
\r
2370 //! \param ulIORetGrpFlags is one of the valid IO groups.
\r
2372 //! This function disable the IO retention for group of pins as specified by
\r
2373 //! \e ulIORetGrpFlags parameter. Disabling retention will unlock the
\r
2374 //! digital pins in the specified group. Output pins can only be driven when
\r
2375 //! retention is disabled.
\r
2377 //! The parameter \e ulIORetGrpFlags can be logical OR of one or
\r
2378 //! more of the following:
\r
2379 //! -\b PRCM_IO_RET_GRP_0 - All the pins except sFlash and JTAG interface
\r
2380 //! -\b PRCM_IO_RET_GRP_1 - sFlash interface pins 11,12,13,14
\r
2381 //! -\b PRCM_IO_RET_GRP_2 - JTAG TDI and TDO interface pins 16,17
\r
2382 //! -\b PRCM_IO_RET_GRP_3 - JTAG TCK and TMS interface pins 19,20
\r
2384 //! \note Use case is to un-park the pins when exiting HIB
\r
2388 //*****************************************************************************
\r
2389 void PRCMIORetentionDisable(unsigned long ulIORetGrpFlags)
\r
2392 // Supported only in ES2.00 and Later devices i.e. ROM Version 2.x.x or greater
\r
2394 if( (HWREG(0x00000400) & 0xFFFF) >= 2 )
\r
2398 // Enable IO Pad to ODI Path
\r
2400 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG) &= ~(0x00001F00);
\r
2403 // 0b'1 in bit 5 for JTAG PADS
\r
2404 // 0b'1 in bit 0 for all other IOs
\r
2406 HWREG(OCP_SHARED_BASE + OCP_SHARED_O_GPIO_PAD_CMN_CONFIG) |= 0x00000023;
\r
2409 // Disable retention for GRP0
\r
2411 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_0 )
\r
2413 HWREG(HIB3P3_BASE+HIB3P3_O_MEM_PAD_OEN_RET33_CONF) &= ~0x5;
\r
2417 // Disable retention for GRP1
\r
2419 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_1 )
\r
2421 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_HIB_REG0) &= ~((0x3<<5));
\r
2425 // Disable retention for GRP2
\r
2427 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_2 )
\r
2429 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_JTAG_CONF) &= ~0x00000101;
\r
2433 // Disable retention for GRP3
\r
2435 if( ulIORetGrpFlags & PRCM_IO_RET_GRP_3 )
\r
2437 HWREG(HIB3P3_BASE + HIB3P3_O_MEM_JTAG_CONF) &= ~0x00000204;
\r
2443 //*****************************************************************************
\r
2445 //! Gets the device type
\r
2447 //! This function returns bit-packed value representing the device type
\r
2449 //! The returned value is logical OR of one or more of the following:-
\r
2451 //! -\b PRCM_DEV_TYPE_FLAG_R - R variant
\r
2452 //! -\b PRCM_DEV_TYPE_FLAG_F - F variant
\r
2453 //! -\b PRCM_DEV_TYPE_FLAG_Z - Z variant
\r
2454 //! -\b PRCM_DEV_TYPE_FLAG_SECURE - Device is secure
\r
2455 //! -\b PRCM_DEV_TYPE_FLAG_PRE_PROD - Device is a pre-production part
\r
2456 //! -\b PRCM_DEV_TYPE_FLAG_3200 - Device is CC3200
\r
2457 //! -\b PRCM_DEV_TYPE_FLAG_3220 - Device is CC3220
\r
2458 //! -\b PRCM_DEV_TYPE_FLAG_REV1 - Device Rev 1
\r
2459 //! -\b PRCM_DEV_TYPE_FLAG_REV2 - Device Rev 2
\r
2461 //! Pre-defined helper macros:-
\r
2463 //! -\b PRCM_DEV_TYPE_PRE_CC3200R - Pre-Production CC3200R
\r
2464 //! -\b PRCM_DEV_TYPE_PRE_CC3200F - Pre-Production CC3200F
\r
2465 //! -\b PRCM_DEV_TYPE_PRE_CC3200Z - Pre-Production CC3200Z
\r
2466 //! -\b PRCM_DEV_TYPE_CC3200R - Production CC3200R
\r
2467 //! -\b PRCM_DEV_TYPE_PRE_CC3220R - Pre-Production CC3220R
\r
2468 //! -\b PRCM_DEV_TYPE_PRE_CC3220F - Pre-Production CC3220F
\r
2469 //! -\b PRCM_DEV_TYPE_PRE_CC3220Z - Pre-Production CC3220Z
\r
2470 //! -\b PRCM_DEV_TYPE_CC3220R - Production CC3220R
\r
2471 //! -\b PRCM_DEV_TYPE_PRE_CC3220RS - Pre-Production CC3220RS
\r
2472 //! -\b PRCM_DEV_TYPE_PRE_CC3220FS - Pre-Production CC3220FS
\r
2473 //! -\b PRCM_DEV_TYPE_PRE_CC3220ZS - Pre-Production CC3220ZS
\r
2474 //! -\b PRCM_DEV_TYPE_CC3220RS - Production CC3220RS
\r
2475 //! -\b PRCM_DEV_TYPE_CC3220FS - Production CC3220FS
\r
2477 //! \return Returns, bit-packed value representing the device type,
\r
2478 //! or 0 if device is unknown
\r
2480 //*****************************************************************************
\r
2481 unsigned long PRCMDeviceTypeGet()
\r
2483 unsigned long ulDevType;
\r
2484 unsigned long ulChipId;
\r
2485 unsigned long ulDevMajorVer;
\r
2486 unsigned long ulDevMinorVer;
\r
2489 // Read the device identification register
\r
2491 ulChipId = HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG2);
\r
2494 // Read the ROM mojor and minor version
\r
2496 ulDevMajorVer = ((ulChipId >> 28) & 0xF);
\r
2497 ulDevMinorVer = ((ulChipId >> 24) & 0xF);
\r
2500 ulChipId = ((HWREG(GPRCM_BASE + GPRCM_O_GPRCM_EFUSE_READ_REG2) >> 16) & 0x1F);
\r
2503 // Get the device variant from the chip id
\r
2505 switch((ulChipId & 0xF))
\r
2508 // It is R variant
\r
2511 ulDevType = PRCM_DEV_TYPE_FLAG_R;
\r
2515 // It is F variant, non secure F variant is always Pre-Production
\r
2518 ulDevType = PRCM_DEV_TYPE_FLAG_F|PRCM_DEV_TYPE_FLAG_PRE_PROD;
\r
2522 // It is Z variant and is always Pre-Production
\r
2525 ulDevType = PRCM_DEV_TYPE_FLAG_Z|PRCM_DEV_TYPE_FLAG_PRE_PROD;
\r
2532 ulDevType = PRCM_DEV_TYPE_FLAG_R|PRCM_DEV_TYPE_FLAG_SECURE;
\r
2539 ulDevType = PRCM_DEV_TYPE_FLAG_F|PRCM_DEV_TYPE_FLAG_SECURE;
\r
2543 // It is secure Z variant and variant is always Pre-Production
\r
2546 ulDevType = PRCM_DEV_TYPE_FLAG_Z|PRCM_DEV_TYPE_FLAG_SECURE|
\r
2547 PRCM_DEV_TYPE_FLAG_PRE_PROD;
\r
2551 // Undefined variant
\r
2557 if( ulDevType != 0 )
\r
2559 if( ulDevMajorVer == 0x3 )
\r
2561 ulDevType |= PRCM_DEV_TYPE_FLAG_3220;
\r
2563 else if( ulDevMajorVer == 0x2 )
\r
2565 ulDevType |= (PRCM_DEV_TYPE_FLAG_PRE_PROD|PRCM_DEV_TYPE_FLAG_3220);
\r
2567 if( ((ulDevType & PRCM_DEV_TYPE_FLAG_Z) != 0) )
\r
2569 if((ulDevMinorVer == 0x0))
\r
2571 ulDevType |= PRCM_DEV_TYPE_FLAG_REV1;
\r
2575 ulDevType |= PRCM_DEV_TYPE_FLAG_REV2;
\r
2580 if((ulDevMinorVer == 0x1))
\r
2582 ulDevType |= PRCM_DEV_TYPE_FLAG_REV1;
\r
2588 if( (ulDevMinorVer == 0x4))
\r
2590 if( ((ulDevType & PRCM_DEV_TYPE_FLAG_Z) != 0))
\r
2592 ulDevType |= (PRCM_DEV_TYPE_FLAG_PRE_PROD|PRCM_DEV_TYPE_FLAG_3220);
\r
2596 ulDevType |= PRCM_DEV_TYPE_FLAG_3200;
\r
2601 ulDevType |= (PRCM_DEV_TYPE_FLAG_PRE_PROD|PRCM_DEV_TYPE_FLAG_3200);
\r
2612 //****************************************************************************
\r
2614 //! Used to trigger a hibernate cycle for the device using RTC
\r
2616 //! This API can be used to do a clean reboot of device.
\r
2618 //! \note This routine should only be exercised after all the network processing
\r
2619 //! has been stopped. To stop network processing use \b sl_stop API from
\r
2620 //! simplelink library.
\r
2624 //****************************************************************************
\r
2625 void PRCMHibernateCycleTrigger()
\r
2627 unsigned long ulRegValue;
\r
2628 unsigned long long ullRTCVal;
\r
2631 // Read the RTC register
\r
2633 ulRegValue = PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN);
\r
2636 // Enable the RTC as wakeup source if specified
\r
2638 ulRegValue |= (PRCM_HIB_SLOW_CLK_CTR & 0x1);
\r
2641 // Enable HIB wakeup sources
\r
2643 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_EN,ulRegValue);
\r
2646 // Latch the RTC vlaue
\r
2648 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_READ ,0x1);
\r
2651 // Read latched values as 2 32-bit vlaues
\r
2653 ullRTCVal = PRCMHIBRegRead(HIB3P3_BASE + HIB3P3_O_MEM_HIB_RTC_TIMER_MSW);
\r
2654 ullRTCVal = ullRTCVal << 32;
\r
2655 ullRTCVal |= PRCMHIBRegRead(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_TIMER_LSW);
\r
2658 //Considering worst case execution times of ROM,RAM,Flash value of 160 is used
\r
2660 ullRTCVal = ullRTCVal + 160;
\r
2663 // Set RTC match value
\r
2665 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_LSW_CONF,
\r
2666 (unsigned long)(ullRTCVal));
\r
2667 PRCMHIBRegWrite(HIB3P3_BASE+HIB3P3_O_MEM_HIB_RTC_WAKE_MSW_CONF,
\r
2668 (unsigned long)(ullRTCVal>>32));
\r
2670 // Note : Any addition of code after this line would need a change in
\r
2671 // ullTicks Interval currently set to 160
\r
2675 // Request hibernate.
\r
2677 PRCMHIBRegWrite((HIB3P3_BASE+HIB3P3_O_MEM_HIB_REQ),0x1);
\r
2680 // Wait for system to enter hibernate
\r
2694 //*****************************************************************************
\r
2696 // Close the Doxygen group.
\r
2699 //*****************************************************************************
\r