📄 sysctl.c
字号:
//
case SYSCTL_RCC_OSCSRC_INT:
{
ulClk = 15000000;
break;
}
//
// The internal oscillator divided by four is the source clock. This
// is not an accurate clock (it is +/- 50%); what is used is the
// nominal.
//
case SYSCTL_RCC_OSCSRC_INT4:
{
ulClk = 15000000 / 4;
break;
}
//
// An unknown setting, so return a zero clock (i.e. an unknown clock
// rate).
//
default:
{
return(0);
}
}
//
// See if the PLL is being used.
//
if(!(ulRCC & SYSCTL_RCC_BYPASS))
{
//
// Get the PLL configuration.
//
ulPLL = HWREG(SYSCTL_PLLCFG);
//
// Compute the PLL output frequency based on its input frequency.
//
ulClk = ((ulClk * (((ulPLL & SYSCTL_PLLCFG_F_MASK) >>
SYSCTL_PLLCFG_F_SHIFT) + 2)) /
(((ulPLL & SYSCTL_PLLCFG_R_MASK) >>
SYSCTL_PLLCFG_R_SHIFT) + 2));
//
// See if the optional output divide by 2 is being used.
//
if(ulPLL & SYSCTL_PLLCFG_OD_2)
{
ulClk /= 2;
}
//
// See if the optional output divide by 4 is being used.
//
if(ulPLL & SYSCTL_PLLCFG_OD_4)
{
ulClk /= 4;
}
}
//
// See if the system divider is being used.
//
if(ulRCC & SYSCTL_RCC_USE_SYSDIV)
{
//
// Adjust the clock rate by the system clock divider.
//
ulClk /= ((ulRCC & SYSCTL_RCC_SYSDIV_MASK) >>
SYSCTL_RCC_SYSDIV_SHIFT) + 1;
}
//
// Return the computed clock rate.
//
return(ulClk);
}
//*****************************************************************************
//
//! Sets the PWM clock configuration.
//!
//! \param ulConfig is the configuration for the PWM clock; it must be one of
//! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
//! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
//! \b SYSCTL_PWMDIV_64.
//!
//! This function sets the rate of the clock provided to the PWM module as a
//! ratio of the processor clock. This clock is used by the PWM module to
//! generate PWM signals; its rate forms the basis for all PWM signals.
//!
//! \note The clocking of the PWM is dependent upon the system clock rate as
//! configured by SysCtlClockSet().
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlPWMClockSet(unsigned long ulConfig)
{
//
// Check the arguments.
//
ASSERT((ulConfig == SYSCTL_PWMDIV_1) ||
(ulConfig == SYSCTL_PWMDIV_2) ||
(ulConfig == SYSCTL_PWMDIV_4) ||
(ulConfig == SYSCTL_PWMDIV_8) ||
(ulConfig == SYSCTL_PWMDIV_16) ||
(ulConfig == SYSCTL_PWMDIV_32) ||
(ulConfig == SYSCTL_PWMDIV_64));
//
// Check that there is a PWM block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);
//
// Set the PWM clock configuration into the run-mode clock configuration
// register.
//
HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) &
~(SYSCTL_RCC_USE_PWMDIV | SYSCTL_RCC_PWMDIV_MASK)) |
ulConfig);
}
//*****************************************************************************
//
//! Gets the current PWM clock configuration.
//!
//! This function returns the current PWM clock configuration.
//!
//! \return The current PWM clock configuration; will be one of
//! \b SYSCTL_PWMDIV_1, \b SYSCTL_PWMDIV_2, \b SYSCTL_PWMDIV_4,
//! \b SYSCTL_PWMDIV_8, \b SYSCTL_PWMDIV_16, \b SYSCTL_PWMDIV_32, or
//! \b SYSCTL_PWMDIV_64.
//
//*****************************************************************************
unsigned long
SysCtlPWMClockGet(void)
{
//
// Check that there is a PWM block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_PWM);
//
// Return the current PWM clock configuration.
//
return(HWREG(SYSCTL_RCC) &
(SYSCTL_RCC_USE_PWMDIV | SYSCTL_RCC_PWMDIV_MASK));
}
//*****************************************************************************
//
//! Sets the sample rate of the ADC.
//!
//! \param ulSpeed is the desired sample rate of the ADC; must be one of
//! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
//! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
//!
//! This function sets the rate at which the ADC samples are captured by the
//! ADC block. The sampling speed may be limited by the hardware, so the
//! sample rate may end up being slower than requested. SysCtlADCSpeedGet()
//! will return the actual speed in use.
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlADCSpeedSet(unsigned long ulSpeed)
{
//
// Check the arguments.
//
ASSERT((ulSpeed == SYSCTL_ADCSPEED_1MSPS) ||
(ulSpeed == SYSCTL_ADCSPEED_500KSPS) ||
(ulSpeed == SYSCTL_ADCSPEED_250KSPS) ||
(ulSpeed == SYSCTL_ADCSPEED_125KSPS));
//
// Check that there is an ADC block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC);
//
// Set the ADC speed in run, sleep, and deep-sleep mode.
//
HWREG(SYSCTL_RCGC0) = ((HWREG(SYSCTL_RCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |
ulSpeed);
HWREG(SYSCTL_SCGC0) = ((HWREG(SYSCTL_SCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |
ulSpeed);
HWREG(SYSCTL_DCGC0) = ((HWREG(SYSCTL_DCGC0) & ~(SYSCTL_SET0_ADCSPD_MASK)) |
ulSpeed);
}
//*****************************************************************************
//
//! Gets the sample rate of the ADC.
//!
//! This function gets the current sample rate of the ADC.
//!
//! \return Returns the current ADC sample rate; will be one of
//! \b SYSCTL_ADCSPEED_1MSPS, \b SYSCTL_ADCSPEED_500KSPS,
//! \b SYSCTL_ADCSPEED_250KSPS, or \b SYSCTL_ADCSPEED_125KSPS.
//
//*****************************************************************************
unsigned long
SysCtlADCSpeedGet(void)
{
//
// Check that there is an ADC block on this part.
//
ASSERT(HWREG(SYSCTL_DC1) & SYSCTL_DC1_ADC);
//
// Return the current ADC speed.
//
return(HWREG(SYSCTL_RCGC0) & SYSCTL_SET0_ADCSPD_MASK);
}
//*****************************************************************************
//
//! Configures the internal oscillator verification timer.
//!
//! \param bEnable is a boolean that is \b true if the internal oscillator
//! verification timer should be enabled.
//!
//! This function allows the internal oscillator verification timer to be
//! enabled or disabled. When enabled, an interrupt will be generated if the
//! internal oscillator ceases to operate.
//!
//! \note Both oscillators (main and internal) must be enabled for this
//! verification timer to operate as the main oscillator will verify the
//! internal oscillator.
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlIOSCVerificationSet(tBoolean bEnable)
{
//
// Enable or disable the internal oscillator verification timer as
// requested.
//
if(bEnable)
{
HWREG(SYSCTL_RCC) |= SYSCTL_RCC_IOSCVER;
}
else
{
HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_IOSCVER);
}
}
//*****************************************************************************
//
//! Configures the main oscillator verification timer.
//!
//! \param bEnable is a boolean that is \b true if the main oscillator
//! verification timer should be enabled.
//!
//! This function allows the main oscillator verification timer to be enabled
//! or disabled. When enabled, an interrupt will be generated if the main
//! oscillator ceases to operate.
//!
//! \note Both oscillators (main and internal) must be enabled for this
//! verification timer to operate as the internal oscillator will verify the
//! main oscillator.
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlMOSCVerificationSet(tBoolean bEnable)
{
//
// Enable or disable the main oscillator verification timer as requested.
//
if(bEnable)
{
HWREG(SYSCTL_RCC) |= SYSCTL_RCC_MOSCVER;
}
else
{
HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCVER);
}
}
//*****************************************************************************
//
//! Configures the PLL verification timer.
//!
//! \param bEnable is a boolean that is \b true if the PLL verification timer
//! should be enabled.
//!
//! This function allows the PLL verification timer to be enabled or disabled.
//! When enabled, an interrupt will be generated if the PLL ceases to operate.
//!
//! \note The main oscillator must be enabled for this verification timer to
//! operate as it is used to check the PLL. Also, the verification timer
//! should be disabled while the PLL is being reconfigured via
//! SysCtlClockSet().
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlPLLVerificationSet(tBoolean bEnable)
{
//
// Enable or disable the PLL verification timer as requested.
//
if(bEnable)
{
HWREG(SYSCTL_RCC) |= SYSCTL_RCC_PLLVER;
}
else
{
HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_PLLVER);
}
}
//*****************************************************************************
//
//! Clears the clock verification status.
//!
//! This function clears the status of the clock verification timers, allowing
//! them to assert another failure if detected.
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlClkVerificationClear(void)
{
//
// Clear the clock verification.
//
HWREG(SYSCTL_CLKVCLR) = SYSCTL_CLKVCLR_CLR;
//
// The bit does not self-reset, so clear it.
//
HWREG(SYSCTL_CLKVCLR) = 0;
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -