mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
cpu/esp32/periph_rtc: funcs for enter/exit sleep
This commit is contained in:
parent
b1ec6953a3
commit
f4aa253645
44
cpu/esp32/include/rtc_arch.h
Normal file
44
cpu/esp32/include/rtc_arch.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_esp32
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Architecture specific RTC functions for ESP32
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef RTC_ARCH_H
|
||||
#define RTC_ARCH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Called before the power management enters a light or deep sleep mode
|
||||
* @param mode sleep mode that is entered
|
||||
* @return time to sleep in us
|
||||
*/
|
||||
uint64_t rtc_pm_sleep_enter(unsigned mode);
|
||||
|
||||
/**
|
||||
* @brief Called after the power management left light sleep mode
|
||||
* @param cause wake-up cause
|
||||
*/
|
||||
void rtc_pm_sleep_exit(uint32_t cause);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RTC_ARCH_H */
|
||||
@ -52,6 +52,7 @@
|
||||
|
||||
#include "cpu.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "log.h"
|
||||
#include "irq_arch.h"
|
||||
#include "periph/rtc.h"
|
||||
@ -345,9 +346,21 @@ static void IRAM_ATTR _rtc_timer_handler(void* arg)
|
||||
irq_isr_exit();
|
||||
}
|
||||
|
||||
void rtc_handle_pending_alarm(void)
|
||||
uint64_t rtc_pm_sleep_enter(unsigned mode)
|
||||
{
|
||||
(void)mode;
|
||||
if (_rtc_alarm_cb) {
|
||||
uint64_t sleep = (_sys_alarm_time - _sys_get_time()) * US_PER_SEC;
|
||||
esp_sleep_enable_timer_wakeup(sleep);
|
||||
return sleep;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rtc_pm_sleep_exit(uint32_t cause)
|
||||
{
|
||||
/* call the RTC time was the wakeup source and an RTC alarm was set */
|
||||
if (cause == ESP_SLEEP_WAKEUP_TIMER && _rtc_alarm_cb) {
|
||||
_rtc_alarm_cb(_rtc_alarm_arg);
|
||||
_rtc_alarm_cb = 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user