mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
/********************************** (C) COPYRIGHT *******************************
|
||
* File Name : SLEEP.c
|
||
* Author : WCH
|
||
* Version : V1.2
|
||
* Date : 2022/01/18
|
||
* Description : ˯<><CBAF><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||
* SPDX-License-Identifier: Apache-2.0
|
||
*******************************************************************************/
|
||
|
||
/******************************************************************************/
|
||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||
#include "HAL.h"
|
||
|
||
/*******************************************************************************
|
||
* @fn CH58X_LowPower
|
||
*
|
||
* @brief <20><><EFBFBD><EFBFBD>˯<EFBFBD><CBAF>
|
||
*
|
||
* @param time - <20><><EFBFBD>ѵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>㣨RTC<54><43><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
||
*
|
||
* @return state.
|
||
*/
|
||
uint32_t CH58X_LowPower(uint32_t time)
|
||
{
|
||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||
uint32_t tmp, irq_status;
|
||
|
||
SYS_DisableAllIrq(&irq_status);
|
||
tmp = RTC_GetCycle32k();
|
||
if((time < tmp) || ((time - tmp) < 30))
|
||
{ // <20><><EFBFBD><EFBFBD>˯<EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||
SYS_RecoverIrq(irq_status);
|
||
return 2;
|
||
}
|
||
RTC_SetTignTime(time);
|
||
SYS_RecoverIrq(irq_status);
|
||
#if(DEBUG == Debug_UART1) // ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1>Ϣ<EFBFBD><CFA2>Ҫ<EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||
while((R8_UART1_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
||
{
|
||
__nop();
|
||
}
|
||
#endif
|
||
// LOW POWER-sleepģʽ
|
||
if(!RTCTigFlag)
|
||
{
|
||
LowPower_Sleep(RB_PWR_RAM2K | RB_PWR_RAM30K | RB_PWR_EXTEND);
|
||
if(!RTCTigFlag) // ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>ѷ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>Ҫע<D2AA><D7A2><EFBFBD><EFBFBD>ʱ32M<32><4D><EFBFBD><EFBFBD>δ<EFBFBD>ȶ<EFBFBD>
|
||
{
|
||
time += WAKE_UP_RTC_MAX_TIME;
|
||
if(time > 0xA8C00000)
|
||
{
|
||
time -= 0xA8C00000;
|
||
}
|
||
RTC_SetTignTime(time);
|
||
LowPower_Idle();
|
||
}
|
||
HSECFG_Current(HSE_RCur_100); // <20><>Ϊ<EFBFBD><EFBFBD><EEB6A8><EFBFBD><EFBFBD>(<28><EFBFBD><CDB9>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HSEƫ<45>õ<EFBFBD><C3B5><EFBFBD>)
|
||
}
|
||
else
|
||
{
|
||
return 3;
|
||
}
|
||
#endif
|
||
return 0;
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* @fn HAL_SleepInit
|
||
*
|
||
* @brief <20><><EFBFBD><EFBFBD>˯<EFBFBD><EFBFBD><DFBB>ѵķ<D1B5>ʽ - RTC<54><43><EFBFBD>ѣ<EFBFBD><D1A3><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||
*
|
||
* @param None.
|
||
*
|
||
* @return None.
|
||
*/
|
||
void HAL_SleepInit(void)
|
||
{
|
||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
|
||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
|
||
SAFEOPERATE;
|
||
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC<54><43><EFBFBD><EFBFBD>
|
||
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // <20><><EFBFBD><EFBFBD>ģʽ
|
||
R8_SAFE_ACCESS_SIG = 0; //
|
||
PFIC_EnableIRQ(RTC_IRQn);
|
||
#endif
|
||
}
|