xtensa/esp32: Support auto-sleep
This commit is contained in:
parent
f50160f0e1
commit
f7db743152
@ -971,6 +971,34 @@ config ESP32_WIFI_STA_DISCONNECT_PM
|
||||
Select this option to enable power management for station when disconnected.
|
||||
Chip will do modem-sleep when RF module is not in use anymore.
|
||||
|
||||
config EXAMPLE_WIFI_LISTEN_INTERVAL
|
||||
int "WiFi listen interval"
|
||||
default 3
|
||||
help
|
||||
Interval for station to listen to beacon from AP. The unit of listen interval is one beacon interval.
|
||||
For example, if beacon interval is 100 ms and listen interval is 3, the interval for station to listen
|
||||
to beacon is 300 ms.
|
||||
|
||||
choice EXAMPLE_POWER_SAVE_MODE
|
||||
prompt "power save mode"
|
||||
default EXAMPLE_POWER_SAVE_NONE
|
||||
help
|
||||
Power save mode for the esp32 to use. Modem sleep mode includes minimum and maximum power save modes.
|
||||
In minimum power save mode, station wakes up every DTIM to receive beacon. Broadcast data will not be
|
||||
lost because it is transmitted after DTIM. However, it can not save much more power if DTIM is short
|
||||
for DTIM is determined by AP.
|
||||
In maximum power save mode, station wakes up every listen interval to receive beacon. Broadcast data
|
||||
may be lost because station may be in sleep state at DTIM time. If listen interval is longer, more power
|
||||
is saved but broadcast data is more easy to lose.
|
||||
|
||||
config EXAMPLE_POWER_SAVE_NONE
|
||||
bool "none"
|
||||
config EXAMPLE_POWER_SAVE_MIN_MODEM
|
||||
bool "minimum modem"
|
||||
config EXAMPLE_POWER_SAVE_MAX_MODEM
|
||||
bool "maximum modem"
|
||||
endchoice
|
||||
|
||||
endmenu # ESP32_WIRELESS
|
||||
|
||||
menu "Real-Time Timer"
|
||||
@ -1035,6 +1063,16 @@ config ESP32_AES_ACCELERATOR_TEST
|
||||
|
||||
endmenu # ESP32_AES_ACCELERATOR
|
||||
|
||||
config ESP32_AUTO_SLEEP
|
||||
bool "Auto-sleep"
|
||||
default n
|
||||
select PM
|
||||
select ESP32_RT_TIMER
|
||||
select ESP32_TIMER0
|
||||
select ESP32_TICKLESS
|
||||
---help---
|
||||
Enable ESP32 Auto-sleep
|
||||
|
||||
config ESP32_TICKLESS
|
||||
bool "Enable ESP32 tick-less OS"
|
||||
default n
|
||||
|
@ -22,6 +22,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
@ -30,6 +31,14 @@
|
||||
#include "esp32_pm.h"
|
||||
#include "xtensa.h"
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
#include "esp32_rt_timer.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_TICKLESS
|
||||
#include "esp32_tickless.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@ -41,6 +50,7 @@
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
#ifndef CONFIG_PM_ALARM_SEC
|
||||
# define CONFIG_PM_ALARM_SEC 15
|
||||
#endif
|
||||
@ -58,6 +68,14 @@
|
||||
#endif
|
||||
|
||||
#define PM_IDLE_DOMAIN 0 /* Revisit */
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define EXPECTED_IDLE_TIME_US (800)
|
||||
#define EARLY_WAKEUP_US (200)
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -75,9 +93,63 @@
|
||||
#ifdef CONFIG_PM
|
||||
static void up_idlepm(void)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
#ifdef CONFIG_ESP32_AUTO_SLEEP
|
||||
uint64_t sleep_us;
|
||||
uint64_t os_idle_us;
|
||||
uint64_t os_start_us;
|
||||
uint64_t os_end_us;
|
||||
uint64_t os_step_us;
|
||||
uint64_t hw_idle_us;
|
||||
uint64_t hw_start_us;
|
||||
uint64_t hw_end_us;
|
||||
uint64_t hw_step_us;
|
||||
uint64_t rtc_diff_us;
|
||||
struct timespec ts;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
if (esp32_pm_lockstatus() == 0)
|
||||
{
|
||||
os_idle_us = up_get_idletime();
|
||||
hw_idle_us = rt_timer_get_alarm();
|
||||
sleep_us = MIN(os_idle_us, hw_idle_us);
|
||||
if (sleep_us > EXPECTED_IDLE_TIME_US)
|
||||
{
|
||||
sleep_us -= EARLY_WAKEUP_US;
|
||||
|
||||
esp32_sleep_enable_timer_wakeup(sleep_us);
|
||||
|
||||
up_timer_gettime(&ts);
|
||||
os_start_us = (ts.tv_sec * USEC_PER_SEC +
|
||||
ts.tv_nsec / NSEC_PER_USEC);
|
||||
hw_start_us = rt_timer_time_us();
|
||||
|
||||
esp32_light_sleep_start(&rtc_diff_us);
|
||||
|
||||
hw_end_us = rt_timer_time_us();
|
||||
up_timer_gettime(&ts);
|
||||
os_end_us = (ts.tv_sec * USEC_PER_SEC +
|
||||
ts.tv_nsec / NSEC_PER_USEC);
|
||||
hw_step_us = rtc_diff_us - (hw_end_us - hw_start_us);
|
||||
os_step_us = rtc_diff_us - (os_end_us - os_start_us);
|
||||
DEBUGASSERT(hw_step_us > 0);
|
||||
DEBUGASSERT(os_step_us > 0);
|
||||
|
||||
/* Adjust current RT timer by a certain value. */
|
||||
|
||||
rt_timer_calibration(hw_step_us);
|
||||
|
||||
/* Adjust system time by a certain value. */
|
||||
|
||||
up_step_idletime((uint32_t)os_step_us);
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
#else /* CONFIG_ESP32_AUTO_SLEEP */
|
||||
static enum pm_state_e oldstate = PM_NORMAL;
|
||||
enum pm_state_e newstate;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
/* Decide, which power saving level can be obtained */
|
||||
@ -159,6 +231,7 @@ static void up_idlepm(void)
|
||||
pm_changestate(PM_IDLE_DOMAIN, PM_NORMAL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
# define up_idlepm()
|
||||
@ -191,10 +264,6 @@ void up_idle(void)
|
||||
nxsched_process_timer();
|
||||
#else
|
||||
|
||||
/* Perform IDLE mode power management */
|
||||
|
||||
up_idlepm();
|
||||
|
||||
/* This would be an appropriate place to put some MCU-specific logic to
|
||||
* sleep in a reduced power mode until an interrupt occurs to save power
|
||||
*/
|
||||
@ -202,5 +271,10 @@ void up_idle(void)
|
||||
#if XCHAL_HAVE_INTERRUPTS
|
||||
__asm__ __volatile__ ("waiti 0");
|
||||
#endif
|
||||
|
||||
/* Perform IDLE mode power management */
|
||||
|
||||
up_idlepm();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
@ -42,6 +43,14 @@
|
||||
#include "esp32_pm.h"
|
||||
#include "esp32_resetcause.h"
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
#include "esp32_rt_timer.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_TICKLESS
|
||||
#include "esp32_tickless.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@ -191,6 +200,7 @@ static struct esp32_sleep_config_t s_config =
|
||||
{ ESP_PD_OPTION_AUTO, ESP_PD_OPTION_AUTO, ESP_PD_OPTION_AUTO },
|
||||
.wakeup_triggers = 0
|
||||
};
|
||||
static volatile uint32_t pm_wakelock = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@ -836,7 +846,7 @@ static void RTC_IRAM_ATTR esp32_wake_deep_sleep(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32_sleep_enable_timer_wakeup(uint64_t time_in_us)
|
||||
void IRAM_ATTR esp32_sleep_enable_timer_wakeup(uint64_t time_in_us)
|
||||
{
|
||||
s_config.wakeup_triggers |= RTC_TIMER_TRIG_EN;
|
||||
s_config.sleep_duration = time_in_us;
|
||||
@ -849,14 +859,14 @@ void esp32_sleep_enable_timer_wakeup(uint64_t time_in_us)
|
||||
* Enter sleep mode
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* sleep_time - Actual sleep time
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 is returned on success or a negated errno value is returned
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_light_sleep_start(void)
|
||||
int esp32_light_sleep_start(uint64_t *sleep_time)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uint32_t pd_flags;
|
||||
@ -905,6 +915,12 @@ int esp32_light_sleep_start(void)
|
||||
|
||||
ret = esp32_light_sleep_inner(pd_flags, flash_enable_time_us,
|
||||
vddsdio_config);
|
||||
if (sleep_time)
|
||||
{
|
||||
*sleep_time = esp32_rtc_time_slowclk_to_us(esp32_rtc_time_get() -
|
||||
s_config.rtc_ticks_at_sleep_start, esp32_clk_slowclk_cal_get());
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
return ret;
|
||||
}
|
||||
@ -947,11 +963,42 @@ void esp32_pminit(void)
|
||||
|
||||
void esp32_pmstandby(uint64_t time_in_us)
|
||||
{
|
||||
uint64_t rtc_diff_us;
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
uint64_t hw_start_us;
|
||||
uint64_t hw_end_us;
|
||||
uint64_t hw_diff_us;
|
||||
#endif
|
||||
|
||||
/* don't power down XTAL — powering it up takes different time on. */
|
||||
|
||||
fflush(stdout);
|
||||
esp32_sleep_enable_timer_wakeup(time_in_us);
|
||||
esp32_light_sleep_start();
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
/* Get rt-timer timestamp before entering sleep */
|
||||
|
||||
hw_start_us = rt_timer_time_us();
|
||||
#endif
|
||||
|
||||
esp32_light_sleep_start(&rtc_diff_us);
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
/* Get rt-timer timestamp after waking up from sleep */
|
||||
|
||||
hw_end_us = rt_timer_time_us();
|
||||
hw_diff_us = hw_end_us - hw_start_us;
|
||||
DEBUGASSERT(rtc_diff_us > hw_diff_us);
|
||||
|
||||
rt_timer_calibration(rtc_diff_us - hw_diff_us);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_TICKLESS
|
||||
up_step_idletime((uint32_t)time_in_us);
|
||||
#endif
|
||||
|
||||
pwrinfo("Returned from auto-sleep, slept for %d ms\n",
|
||||
(uint32_t)(rtc_diff_us) / 1000);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1083,4 +1130,51 @@ void esp32_pmsleep(uint64_t time_in_us)
|
||||
esp32_deep_sleep_start();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockacquire
|
||||
*
|
||||
* Description:
|
||||
* Take a power management lock
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void IRAM_ATTR esp32_pm_lockacquire(void)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
flags = enter_critical_section();
|
||||
++pm_wakelock;
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockrelease
|
||||
*
|
||||
* Description:
|
||||
* Release the lock taken using esp32_pm_lockacquire.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void IRAM_ATTR esp32_pm_lockrelease(void)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
flags = enter_critical_section();
|
||||
--pm_wakelock;
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockstatus
|
||||
*
|
||||
* Description:
|
||||
* Return power management lock status.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t IRAM_ATTR esp32_pm_lockstatus(void)
|
||||
{
|
||||
return pm_wakelock;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PM */
|
@ -118,14 +118,14 @@ void esp32_sleep_enable_timer_wakeup(uint64_t time_in_us);
|
||||
* Enter sleep mode
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* sleep_time - Actual sleep time
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 is returned on success or a negated errno value is returned
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_light_sleep_start(void);
|
||||
int esp32_light_sleep_start(uint64_t *sleep_time);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pminit
|
||||
@ -207,6 +207,36 @@ void esp32_deep_sleep_start(void);
|
||||
|
||||
void esp32_pmsleep(uint64_t time_in_us);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockacquire
|
||||
*
|
||||
* Description:
|
||||
* Take a power management lock
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32_pm_lockacquire(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockrelease
|
||||
*
|
||||
* Description:
|
||||
* Release the lock taken using esp32_pm_lock.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32_pm_lockrelease(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_pm_lockstatus
|
||||
*
|
||||
* Description:
|
||||
* Return power management lock status.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t esp32_pm_lockstatus(void);
|
||||
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -568,7 +568,7 @@ void rt_timer_delete(FAR struct rt_timer_s *timer)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t rt_timer_time_us(void)
|
||||
uint64_t IRAM_ATTR rt_timer_time_us(void)
|
||||
{
|
||||
uint64_t counter;
|
||||
struct esp32_tim_dev_s *tim = s_esp32_tim_dev;
|
||||
@ -578,6 +578,74 @@ uint64_t rt_timer_time_us(void)
|
||||
return counter;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rt_timer_get_alarm
|
||||
*
|
||||
* Description:
|
||||
* Get the timestamp when the next timeout is expected to occur.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Timestamp of the nearest timer event, in microseconds.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t IRAM_ATTR rt_timer_get_alarm(void)
|
||||
{
|
||||
irqstate_t flags;
|
||||
uint64_t counter;
|
||||
struct esp32_tim_dev_s *tim = s_esp32_tim_dev;
|
||||
uint64_t alarm_value = 0;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
ESP32_TIM_GETCTR(tim, &counter);
|
||||
ESP32_TIM_GETALRVL(tim, &alarm_value);
|
||||
|
||||
if (alarm_value <= counter)
|
||||
{
|
||||
alarm_value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
alarm_value -= counter;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
|
||||
return alarm_value;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rt_timer_calibration
|
||||
*
|
||||
* Description:
|
||||
* Adjust current RT timer by a certain value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* time_us - adjustment to apply to RT timer, in microseconds
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void IRAM_ATTR rt_timer_calibration(uint64_t time_us)
|
||||
{
|
||||
uint64_t counter;
|
||||
struct esp32_tim_dev_s *tim = s_esp32_tim_dev;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = enter_critical_section();
|
||||
ESP32_TIM_GETCTR(tim, &counter);
|
||||
counter += time_us;
|
||||
ESP32_TIM_SETCTR(tim, counter);
|
||||
ESP32_TIM_RLD_NOW(tim);
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rt_timer_init
|
||||
*
|
||||
@ -678,3 +746,4 @@ void esp32_rt_timer_deinit(void)
|
||||
kthread_delete(s_pid);
|
||||
nxsem_destroy(&s_toutsem);
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,38 @@ void rt_timer_delete(FAR struct rt_timer_s *timer);
|
||||
|
||||
uint64_t rt_timer_time_us(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rt_timer_get_alarm
|
||||
*
|
||||
* Description:
|
||||
* Get the timestamp when the next timeout is expected to occur.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Timestamp of the nearest timer event, in microseconds.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t rt_timer_get_alarm(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rt_timer_calibration
|
||||
*
|
||||
* Description:
|
||||
* Adjust current RT timer by a certain value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* time_us - adjustment to apply to RT timer, in microseconds
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void rt_timer_calibration(uint64_t time_us);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rt_timer_init
|
||||
*
|
||||
|
@ -993,7 +993,7 @@ uint64_t IRAM_ATTR esp32_rtc_time_get(void)
|
||||
*
|
||||
* Input Parameters:
|
||||
* time_in_us - Time interval in microseconds
|
||||
* slow_clk_period - Period of slow clock in microseconds
|
||||
* slow_clk_period - Period of slow clock in microseconds
|
||||
*
|
||||
* Returned Value:
|
||||
* number of slow clock cycles
|
||||
@ -1010,6 +1010,46 @@ uint64_t IRAM_ATTR esp32_rtc_time_us_to_slowclk(uint64_t time_in_us,
|
||||
return (time_in_us << RTC_CLK_CAL_FRACT) / period;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rtc_time_slowclk_to_us
|
||||
*
|
||||
* Description:
|
||||
* Convert time interval from RTC_SLOW_CLK to microseconds
|
||||
*
|
||||
* Input Parameters:
|
||||
* time_in_us - Time interval in RTC_SLOW_CLK cycles
|
||||
* slow_clk_period - Period of slow clock in microseconds
|
||||
*
|
||||
* Returned Value:
|
||||
* Time interval in microseconds
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t IRAM_ATTR esp32_rtc_time_slowclk_to_us(uint64_t rtc_cycles,
|
||||
uint32_t period)
|
||||
{
|
||||
return (rtc_cycles * period) >> RTC_CLK_CAL_FRACT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_clk_slowclk_cal_get
|
||||
*
|
||||
* Description:
|
||||
* Get the calibration value of RTC slow clock.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* the calibration value obtained using rtc_clk_cal
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t IRAM_ATTR esp32_clk_slowclk_cal_get(void)
|
||||
{
|
||||
return getreg32(RTC_SLOW_CLK_CAL_REG);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rtc_bbpll_disable
|
||||
*
|
||||
|
@ -301,6 +301,39 @@ uint64_t esp32_rtc_time_get(void);
|
||||
|
||||
uint64_t esp32_rtc_time_us_to_slowclk(uint64_t time_in_us, uint32_t period);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rtc_time_slowclk_to_us
|
||||
*
|
||||
* Description:
|
||||
* Convert time interval from RTC_SLOW_CLK to microseconds
|
||||
*
|
||||
* Input Parameters:
|
||||
* time_in_us - Time interval in RTC_SLOW_CLK cycles
|
||||
* slow_clk_period - Period of slow clock in microseconds
|
||||
*
|
||||
* Returned Value:
|
||||
* Time interval in microseconds
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t esp32_rtc_time_slowclk_to_us(uint64_t rtc_cycles, uint32_t period);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_clk_slowclk_cal_get
|
||||
*
|
||||
* Description:
|
||||
* Get the calibration value of RTC slow clock.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* the calibration value obtained using rtc_clk_cal
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t esp32_clk_slowclk_cal_get(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_rtc_bbpll_disable
|
||||
*
|
||||
|
@ -60,6 +60,10 @@
|
||||
#include "esp32_rt_timer.h"
|
||||
#include "esp32_wifi_utils.h"
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
#include "esp32_pm.h"
|
||||
#endif
|
||||
|
||||
#include "espidf_wifi.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -90,6 +94,24 @@
|
||||
#define SSID_MAX_LEN (32)
|
||||
#define PWD_MAX_LEN (64)
|
||||
|
||||
#ifndef CONFIG_EXAMPLE_WIFI_LISTEN_INTERVAL
|
||||
#define CONFIG_EXAMPLE_WIFI_LISTEN_INTERVAL 3
|
||||
#endif
|
||||
|
||||
#define DEFAULT_LISTEN_INTERVAL CONFIG_EXAMPLE_WIFI_LISTEN_INTERVAL
|
||||
|
||||
/* CONFIG_POWER_SAVE_MODEM */
|
||||
|
||||
#if defined(CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MIN_MODEM
|
||||
#elif defined(CONFIG_EXAMPLE_POWER_SAVE_MAX_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MAX_MODEM
|
||||
#elif defined(CONFIG_EXAMPLE_POWER_SAVE_NONE)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#else
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -2100,7 +2122,7 @@ static void esp_evt_work_cb(FAR void *arg)
|
||||
case WIFI_ADPT_EVT_STA_START:
|
||||
wlinfo("WiFi sta start\n");
|
||||
g_sta_connected = false;
|
||||
ret = esp_wifi_set_ps(WIFI_PS_NONE);
|
||||
ret = esp_wifi_set_ps(DEFAULT_PS_MODE);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to close PS\n");
|
||||
@ -2334,24 +2356,30 @@ static void esp_dport_access_stall_other_cpu_end(void)
|
||||
* Name: wifi_apb80m_request
|
||||
*
|
||||
* Description:
|
||||
* Don't support
|
||||
* Take Wi-Fi lock in auto-sleep
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void wifi_apb80m_request(void)
|
||||
{
|
||||
#ifdef CONFIG_ESP32_AUTO_SLEEP
|
||||
esp32_pm_lockacquire();
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wifi_apb80m_release
|
||||
*
|
||||
* Description:
|
||||
* Don't support
|
||||
* Release Wi-Fi lock in auto-sleep
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void wifi_apb80m_release(void)
|
||||
{
|
||||
#ifdef CONFIG_ESP32_AUTO_SLEEP
|
||||
esp32_pm_lockrelease();
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -4870,13 +4898,6 @@ int esp_wifi_adapter_init(void)
|
||||
return OK;
|
||||
}
|
||||
|
||||
ret = esp32_rt_timer_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("Failed to initialize RT timer error=%d\n", ret);
|
||||
goto errout_init_timer;
|
||||
}
|
||||
|
||||
sq_init(&g_wifi_evt_queue);
|
||||
|
||||
#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM
|
||||
@ -4935,9 +4956,8 @@ int esp_wifi_adapter_init(void)
|
||||
errout_init_txdone:
|
||||
esp_wifi_deinit();
|
||||
errout_init_wifi:
|
||||
esp32_rt_timer_deinit();
|
||||
errout_init_timer:
|
||||
esp_wifi_lock(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -5213,6 +5233,7 @@ int esp_wifi_sta_password(struct iwreq *iwr, bool set)
|
||||
memcpy(wifi_cfg.sta.password, pdata, len);
|
||||
|
||||
wifi_cfg.sta.pmf_cfg.capable = true;
|
||||
wifi_cfg.sta.listen_interval = DEFAULT_LISTEN_INTERVAL;
|
||||
|
||||
ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg);
|
||||
if (ret)
|
||||
@ -5583,7 +5604,7 @@ int esp_wifi_sta_auth(struct iwreq *iwr, bool set)
|
||||
|
||||
if (set)
|
||||
{
|
||||
return -ENOSYS;
|
||||
return OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
79
boards/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig
Normal file
79
boards/xtensa/esp32/esp32-devkitc/configs/autopm/defconfig
Normal file
@ -0,0 +1,79 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_ARCH_LEDS is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
# CONFIG_NSH_CMDPARMS is not set
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-devkitc"
|
||||
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DRIVERS_IEEE80211=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_ESP32_AUTO_SLEEP=y
|
||||
CONFIG_ESP32_MTD_SIZE=0x80000
|
||||
CONFIG_ESP32_SPIFLASH=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_ESP32_WIFI_SAVE_PARAM=y
|
||||
CONFIG_ESP32_WIRELESS=y
|
||||
CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_SPIFFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETINIT_DHCPC=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPIFFS_NAME_MAX=48
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSTEM_DHCPC_RENEW=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_PING=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_WAPI=y
|
||||
CONFIG_WIRELESS_WAPI_CMDTOOL=y
|
||||
CONFIG_WIRELESS_WAPI_STACKSIZE=4096
|
@ -78,6 +78,10 @@
|
||||
# include "esp32_aes.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
# include "esp32_rt_timer.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_INPUT_BUTTONS
|
||||
# include <nuttx/input/buttons.h>
|
||||
#endif
|
||||
@ -186,6 +190,15 @@ int esp32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
ret = esp32_rt_timer_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize RT timer error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_WIRELESS
|
||||
ret = board_wlan_init();
|
||||
if (ret < 0)
|
||||
|
@ -0,0 +1,78 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
# CONFIG_NSH_CMDPARMS is not set
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-ethernet-kit"
|
||||
CONFIG_ARCH_BOARD_ESP32_ETHERNETKIT=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DRIVERS_IEEE80211=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_ESP32_AUTO_SLEEP=y
|
||||
CONFIG_ESP32_MTD_SIZE=0x80000
|
||||
CONFIG_ESP32_SPIFLASH=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_ESP32_WIFI_SAVE_PARAM=y
|
||||
CONFIG_ESP32_WIRELESS=y
|
||||
CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_SPIFFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETINIT_DHCPC=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPIFFS_NAME_MAX=48
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSTEM_DHCPC_RENEW=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_PING=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_WAPI=y
|
||||
CONFIG_WIRELESS_WAPI_CMDTOOL=y
|
||||
CONFIG_WIRELESS_WAPI_STACKSIZE=4096
|
@ -58,6 +58,10 @@
|
||||
# include "esp32_board_wdt.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
# include "esp32_rt_timer.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_WIRELESS
|
||||
# include "esp32_board_wlan.h"
|
||||
#endif
|
||||
@ -153,6 +157,15 @@ int esp32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
ret = esp32_rt_timer_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize RT timer error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_WIRELESS
|
||||
ret = board_wlan_init();
|
||||
if (ret < 0)
|
||||
|
@ -0,0 +1,79 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_ARCH_LEDS is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
# CONFIG_NSH_CMDPARMS is not set
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-wrover-kit"
|
||||
CONFIG_ARCH_BOARD_ESP32_WROVERKIT=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DRIVERS_IEEE80211=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_ESP32_AUTO_SLEEP=y
|
||||
CONFIG_ESP32_MTD_SIZE=0x80000
|
||||
CONFIG_ESP32_SPIFLASH=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_ESP32_WIFI_SAVE_PARAM=y
|
||||
CONFIG_ESP32_WIRELESS=y
|
||||
CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_SPIFFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETINIT_DHCPC=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_SOCKOPTS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPIFFS_NAME_MAX=48
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSTEM_DHCPC_RENEW=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_PING=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_WAPI=y
|
||||
CONFIG_WIRELESS_WAPI_CMDTOOL=y
|
||||
CONFIG_WIRELESS_WAPI_STACKSIZE=4096
|
@ -81,6 +81,10 @@
|
||||
# include <nuttx/video/fb.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
# include "esp32_rt_timer.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_DEV
|
||||
# include <nuttx/board.h>
|
||||
# include <nuttx/lcd/lcd_dev.h>
|
||||
@ -173,6 +177,15 @@ int esp32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_RT_TIMER
|
||||
ret = esp32_rt_timer_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize RT timer error\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_WIRELESS
|
||||
ret = board_wlan_init();
|
||||
if (ret < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user