89 lines
2.4 KiB
C
Raw Normal View History

2022-03-26 20:51:40 +08:00
/********************************** (C) COPYRIGHT *******************************
* File Name : SLEEP.c
* Author : WCH
* Version : V1.2
* Date : 2022/01/18
* Description : ˯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
* 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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD><EFBFBD>
*
* @param time - <EFBFBD><EFBFBD><EFBFBD>ѵ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>
*
* @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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD>߻<EFBFBD><EFBFBD>ѵķ<EFBFBD>ʽ - RTC<EFBFBD><EFBFBD><EFBFBD>ѣ<EFBFBD><EFBFBD><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
}