📄 lpc11xx_syscon.c
字号:
}
/*********************************************************************//**
* @brief Determines the divider value for the clkout_clk signal
* on the CLKOUT pin
* @param[in] DivVal Value of divider
*
* @return none
**********************************************************************/
void SYSCON_SetCLKOUTClockDiv(uint32_t DivVal)
{
CHECK_PARAM(PARAM_DIVVAL(DivVal));
LPC_SYSCON->CLKOUTDIV = DivVal;
}
/*********************************************************************//**
* @brief Configures the frequency range for the system oscillator.
* @param[in] bypass Enable or Disable system oscillator Bypass
* SYSCON_MOSC_FREQRANG_x Determines frequency range for
* Low-power oscillator, it can be:
* - SYSCON_MOSC_FREQRANG_1_20 : 1 - 20 MHz frequency range
* - SYSCON_MOSC_FREQRANG_15_25 : 15 - 25 MHz frequency range
* @return none
**********************************************************************/
void SysOscConfig (FunctionalState bypassState, uint32_t SYSCON_MOSC_FREQRANG_x)
{
uint32_t reg = 0;
if (bypassState == ENABLE) {
reg |= 1;
}
if (SYSCON_MOSC_FREQRANG_x == SYSCON_MOSC_FREQRANG_15_25) {
reg |= (uint32_t)1 << 1;
}
LPC_SYSCON->SYSOSCCTRL = reg;
}
/*********************************************************************//**
* @brief Configures the watchdog oscillator
* @param[in] div divider for Fclkana, wdt_osc_clk = Fclkana/(2 × (1 + DIVSEL))
* FreqSel Select watchdog oscillator analog output frequency (Fclkana)
* it can be:
* - SYSCON_WDT_FREQ_0_5 : 0.5 MHz
* - SYSCON_WDT_FREQ_0_8 : 0.8 MHz
* - SYSCON_WDT_FREQ_1_1 : 1.1 MHz
* - SYSCON_WDT_FREQ_1_4 : 1.4 MHz
* - SYSCON_WDT_FREQ_1_6 : 1.6 MHz (Reset)
* - SYSCON_WDT_FREQ_1_8 : 1.8 MHz
* - SYSCON_WDT_FREQ_2_0 : 2.0 MHz
* - SYSCON_WDT_FREQ_2_2 : 2.2 MHz
* - SYSCON_WDT_FREQ_2_4 : 2.4 MHz
* - SYSCON_WDT_FREQ_2_6 : 2.6 MHz
* - SYSCON_WDT_FREQ_2_7 : 2.7 MHz
* - SYSCON_WDT_FREQ_2_9 : 2.9 MHz
* - SYSCON_WDT_FREQ_3_1 : 3.1 MHz
* - SYSCON_WDT_FREQ_3_2 : 3.2 MHz
* - SYSCON_WDT_FREQ_3_4 : 3.4 MHz
* @return none
**********************************************************************/
void SYSCON_WDTOscConfig (uint32_t div, uint32_t FreqSel)
{
CHECK_PARAM(PARAM_WDTDIV(div));
CHECK_PARAM(PARAM_FREQSEL(FreqSel));
LPC_SYSCON->WDTOSCCTRL = div | (FreqSel << 5);
}
/*********************************************************************//**
* @brief Configures the watchdog oscillator
* @param[in] ClkSel WDT Clock source, it can be:
* - SYSCON_WDT_CLK_IRC : IRC oscillator
* - SYSCON_WDT_CLK_MCK : Main clock
* - SYSCON_WDT_CLK_WDTOSC : Watchdog oscillator
* @return none
**********************************************************************/
void SYSCON_WDTClkSel (uint32_t ClkSel)
{
CHECK_PARAM(PARAM_WDTCLKSEL(ClkSel));
LPC_SYSCON->WDTCLKSEL = ClkSel;
//SYSCON_WDTClkUpdate();
}
/*********************************************************************//**
* @brief Updates the clock source of the watchdog timer
* @param[in] None
* @return None
**********************************************************************/
void SYSCON_WDTClkUpdate (void)
{
LPC_SYSCON->WDTCLKUEN = 1;
LPC_SYSCON->WDTCLKUEN = 0;
LPC_SYSCON->WDTCLKUEN = 1;
while(!(LPC_SYSCON->WDTCLKUEN & 1));
}
/*********************************************************************//**
* @brief Configures the clkout_clk signal to be output on the CLKOUT pin
* @param[in] ClkSel CLKOUT clock source, it can be:
* - SYSCON_CLKOUT_CLK_IRC : IRC oscillator
* - SYSCON_CLKOUT_CLK_SYSOSC : System oscillator
* - SYSCON_CLKOUT_CLK_WDTOSC : Watchdog oscillator
* - SYSCON_CLKOUT_CLK_MCK : Main clock
* @return None
**********************************************************************/
void SYSCON_CLKOUTClkSel (uint32_t ClkSel)
{
if (ClkSel <= 3) {
LPC_SYSCON->CLKOUTCLKSEL = ClkSel;
//SYSCON_CLKOUTClkUpdate();
}
}
/*********************************************************************//**
* @brief Determines the divider value for the clkout_clk signal on
* the CLKOUT pin
* @param[in] DivVal Clock divider values (0 - 255)
* The clkout_clk can be shut down by setting the DivVal to 0x0.
* @return None
**********************************************************************/
void SYSCON_CLKOUTClkDiv (uint32_t DivVal)
{
CHECK_PARAM(PARAM_DIVVAL(DivVal));
LPC_SYSCON->CLKOUTDIV = DivVal;
}
/*********************************************************************//**
* @brief Updates the clock source of the CLKOUT pin
* @param[in] None
*
* @return None
**********************************************************************/
void SYSCON_CLKOUTClkUpdate (void)
{
LPC_SYSCON->CLKOUTUEN = 1;
LPC_SYSCON->CLKOUTUEN = 0;
LPC_SYSCON->CLKOUTUEN = 1;
while(!(LPC_SYSCON->CLKOUTUEN & 1));
}
/*********************************************************************//**
* @brief Captures the state (HIGH or LOW) of the PIO pins of ports 0,1,
* 2 and 3(pins PIO3_0 to PIO3_5) at power-on-reset.
* @param[in] portNum Port number, can be 0, 1, 2, 3
* @param[in] pinNum Pins number, can be 0-11 (if Port is 0,1,2) or
* 0-5 (if Port is 3)
*
* @return None
**********************************************************************/
FlagStatus SYSCON_GetPIORstState(uint32_t portNum, uint32_t pinNum)
{
FlagStatus pinSta = RESET;
uint32_t regTmp;
if((portNum<=2 && pinNum<=11) || (portNum==3 && pinNum<=5)) {
switch (portNum) {
case 0: // PIO0
regTmp = LPC_SYSCON->PIOPORCAP0;
if (regTmp & ((uint32_t)1<<pinNum)) {
pinSta = SET;
}
break;
case 1: // PIO1
regTmp = LPC_SYSCON->PIOPORCAP0 >> 12;
if (regTmp & ((uint32_t)1<<pinNum)) {
pinSta = SET;
}
break;
case 2: // PIO2
if (pinNum <= 7) {
regTmp = LPC_SYSCON->PIOPORCAP0 >> 24;
if (regTmp & ((uint32_t)1<<pinNum)) {
pinSta = SET;
}
} else {
regTmp = LPC_SYSCON->PIOPORCAP1;
if (regTmp & ((uint32_t)1<<(pinNum-8))) {
pinSta = SET;
}
}
break;
case 3: // PIO3
regTmp = LPC_SYSCON->PIOPORCAP1 >> 4;
if (regTmp & ((uint32_t)1<<pinNum)) {
pinSta = SET;
}
}
}
return pinSta;
}
/*********************************************************************//**
* @brief Control the power to the analog blocks
* @param[in] block Analog block, it can be
* - SYSCON_ABLOCK_IRCOUT : IRC oscillator output wake-up configuration
* - SYSCON_ABLOCK_IRC : IRC oscillator power-down wake-up configuration
* - SYSCON_ABLOCK_FLASH : Flash wake-up configuration
* - SYSCON_ABLOCK_BOD : BOD wake-up configuration
* - SYSCON_ABLOCK_ADC : ADC wake-up configuration
* - SYSCON_ABLOCK_SYSOSC : System oscillator wake-up configuration
* - SYSCON_ABLOCK_WDTOSC : Watchdog oscillator wake-up configuration
* - SYSCON_ABLOCK_SYSPLL : System PLL wake-up configuration
* @param[in] NewState power state, it can be:
* - ENABLE: Power
* - DISABLE: Powered down
*
* @return None
**********************************************************************/
void SYSCON_PowerCon (uint32_t block, FunctionalState NewState)
{
uint32_t reg;
reg = LPC_SYSCON->PDRUNCFG & SYSCON_ABLOCK_BITMASK;
reg |= 0x800;
if (NewState == ENABLE) {
LPC_SYSCON->PDRUNCFG = reg & ((~block) & SYSCON_ABLOCK_BITMASK);
} else if (NewState == DISABLE) {
LPC_SYSCON->PDRUNCFG = reg | (block & SYSCON_ABLOCK_BITMASK);
}
}
/*********************************************************************//**
* @brief Get Power state of analog blocks
* @param[in] block Analog block, it can be
* - SYSCON_ABLOCK_IRCOUT : IRC oscillator output wake-up configuration
* - SYSCON_ABLOCK_IRC : IRC oscillator power-down wake-up configuration
* - SYSCON_ABLOCK_FLASH : Flash wake-up configuration
* - SYSCON_ABLOCK_BOD : BOD wake-up configuration
* - SYSCON_ABLOCK_ADC : ADC wake-up configuration
* - SYSCON_ABLOCK_SYSOSC : System oscillator wake-up configuration
* - SYSCON_ABLOCK_WDTOSC : Watchdog oscillator wake-up configuration
* - SYSCON_ABLOCK_SYSPLL : System PLL wake-up configuration
* @param[in] None
*
* @return NewState power state, it can be:
* - ENABLE: Power
* - DISABLE: Powered down
**********************************************************************/
FunctionalState SYSCON_GetPowerSta (uint32_t block)
{
FunctionalState powerSta = DISABLE;
if(LPC_SYSCON->PDRUNCFG & (block & SYSCON_ABLOCK_BITMASK)) {
powerSta = DISABLE;
} else {
powerSta = ENABLE;
}
return powerSta;
}
/*********************************************************************//**
* @brief Indicate the state the chip must enter when the Deep-sleep
* mode is asserted by the ARM.
* @param[in] block Analog block, it can be
* - SYSCON_ABLOCK_IRCOUT : IRC oscillator output wake-up configuration
* - SYSCON_ABLOCK_IRC : IRC oscillator power-down wake-up configuration
* - SYSCON_ABLOCK_FLASH : Flash wake-up configuration
* - SYSCON_ABLOCK_BOD : BOD wake-up configuration
* - SYSCON_ABLOCK_ADC : ADC wake-up configuration
* - SYSCON_ABLOCK_SYSOSC : System oscillator wake-up configuration
* - SYSCON_ABLOCK_WDTOSC : Watchdog oscillator wake-up configuration
* - SYSCON_ABLOCK_SYSPLL : System PLL wake-up configuration
* @param[in] NewState power state, it can be:
* - ENABLE: Powered in Deep-sleep mode
* - DISABLE: Powered down in Deep-sleep mode
*
* @return None
**********************************************************************/
void SYSCON_DeepSleepPowerCon (uint32_t block, FunctionalState NewState)
{
uint32_t reg;
reg = LPC_SYSCON->PDSLEEPCFG & SYSCON_ABLOCK_BITMASK;
reg |= 0x800;
if (NewState == ENABLE) {
LPC_SYSCON->PDSLEEPCFG = reg & ((~block) & SYSCON_ABLOCK_BITMASK);
} else if (NewState == DISABLE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -