Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esp32c6 pm rebased squashed #14726

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions arch/risc-v/src/common/espressif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ ifeq ($(CONFIG_ESP_MCPWM),y)
CHIP_CSRCS += esp_mcpwm.c
endif

ifeq ($(CONFIG_PM),y)
ifneq ($(CONFIG_ARCH_CUSTOM_PMINIT),y)
CHIP_CSRCS += esp_pminitialize.c
endif
CHIP_CSRCS += esp_pm.c
endif

#############################################################################
# Espressif HAL for 3rd Party Platforms
#############################################################################
Expand All @@ -146,11 +153,11 @@ endif

ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = e3899a2324c8e326db20f99f208e890fdd7a5b92
ESP_HAL_3RDPARTY_VERSION = ac829113bf5f6543a265a703f2af2558bc8affce
endif

ifndef ESP_HAL_3RDPARTY_URL
ESP_HAL_3RDPARTY_URL = https://github.com/espressif/esp-hal-3rdparty.git
ESP_HAL_3RDPARTY_URL = https://github.com/FelipeMdeO/esp-hal-3rdparty.git
endif

ifndef DISABLE_GIT_DEPTH
Expand Down
26 changes: 26 additions & 0 deletions arch/risc-v/src/common/espressif/esp_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,29 @@
up_enable_irq(ESP_IRQ_GPIO);
}
#endif

/**
* @brief Enable wakeup functionality for a specific GPIO pin.
*
* This function configures the specified GPIO pin to trigger a wakeup event
* based on the given interrupt type. It is typically used to wake up the system

Check failure on line 467 in arch/risc-v/src/common/espressif/esp_gpio.c

View workflow job for this annotation

GitHub Actions / check

Long line found
* from a low-power state when a specific condition is met on the GPIO pin.
*
* @param gpio_num The GPIO pin number to be configured for wakeup.
* @param mode The type of interrupt that will trigger the wakeup event.
* This parameter can be one of the following values:
* - GPIO_INTR_DISABLE: Disable GPIO interrupt
* - GPIO_INTR_POSEDGE: Interrupt on rising edge
* - GPIO_INTR_NEGEDGE: Interrupt on falling edge
* - GPIO_INTR_ANYEDGE: Interrupt on both rising and falling edges

Check failure on line 476 in arch/risc-v/src/common/espressif/esp_gpio.c

View workflow job for this annotation

GitHub Actions / check

Long line found
* - GPIO_INTR_LOW_LEVEL: Interrupt on low level
* - GPIO_INTR_HIGH_LEVEL: Interrupt on high level
*/

Check failure on line 479 in arch/risc-v/src/common/espressif/esp_gpio.c

View workflow job for this annotation

GitHub Actions / check

Missing blank line after comment
void gpio_wakeup_enable(uint32_t gpio_num, gpio_intrtype_t intr_type)
{
gpio_hal_set_intr_type(&g_gpio_hal, gpio_num, intr_type);
gpio_hal_wakeup_enable(&g_gpio_hal, gpio_num);
#if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO
gpio_hal_sleep_sel_dis(&g_gpio_hal, gpio_num);
#endif
}

Check failure on line 487 in arch/risc-v/src/common/espressif/esp_gpio.c

View workflow job for this annotation

GitHub Actions / check

Garbage follows right bracket
20 changes: 20 additions & 0 deletions arch/risc-v/src/common/espressif/esp_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,26 @@
# define esp_gpioirqdisable(irq)
#endif

/**
* @brief Enable wakeup functionality for a specific GPIO pin.
*
* This function configures the specified GPIO pin to trigger a wakeup event
* based on the given interrupt type. It is typically used to wake up the system

Check failure on line 317 in arch/risc-v/src/common/espressif/esp_gpio.h

View workflow job for this annotation

GitHub Actions / check

Long line found
* from a low-power state when a specific condition is met on the GPIO pin.
*
* @param gpio_num The GPIO pin number to be configured for wakeup.
* @param intr_type The type of interrupt that will trigger the wakeup event.
* This parameter can be one of the following values:
* - GPIO_INTR_DISABLE: Disable GPIO interrupt
* - GPIO_INTR_POSEDGE: Interrupt on rising edge
* - GPIO_INTR_NEGEDGE: Interrupt on falling edge
* - GPIO_INTR_ANYEDGE: Interrupt on both rising and falling edges

Check failure on line 326 in arch/risc-v/src/common/espressif/esp_gpio.h

View workflow job for this annotation

GitHub Actions / check

Long line found
* - GPIO_INTR_LOW_LEVEL: Interrupt on low level
* - GPIO_INTR_HIGH_LEVEL: Interrupt on high level
*/

void gpio_wakeup_enable(uint32_t gpio_num, gpio_intrtype_t intr_type);

#ifdef __cplusplus
}
#endif
Expand Down
79 changes: 79 additions & 0 deletions arch/risc-v/src/common/espressif/esp_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,32 @@
#include <arch/board/board.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/spinlock.h>

#ifdef CONFIG_PM
#include "esp_sleep.h"
#include "esp_pm.h"
#include "esp_idle.h"
#endif

#ifdef CONFIG_RTC_DRIVER
#include "esp_hr_timer.h"
#endif

#ifdef CONFIG_SCHED_TICKLESS
#include "esp_tickless.h"
#endif

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#define EXPECTED_IDLE_TIME_US (10000)
#define EARLY_WAKEUP_US (200)

#define DEBUG_AUTOSLEEP 0

/****************************************************************************
* Public Functions
Expand All @@ -55,6 +77,59 @@
*
****************************************************************************/

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: up_idlepm
*
* Description:
* Perform IDLE state power management.
*
****************************************************************************/
#if defined(CONFIG_PM)

static void up_idlepm(void)
{

Check failure on line 94 in arch/risc-v/src/common/espressif/esp_idle.c

View workflow job for this annotation

GitHub Actions / check

Garbage follows left bracket

Check failure on line 94 in arch/risc-v/src/common/espressif/esp_idle.c

View workflow job for this annotation

GitHub Actions / check

Dangling whitespace at the end of line
irqstate_t flags;
flags = spin_lock_irqsave(NULL);

if ( esp_pm_lockstatus() == 0 )

Check failure on line 98 in arch/risc-v/src/common/espressif/esp_idle.c

View workflow job for this annotation

GitHub Actions / check

Space follows left parenthesis

Check failure on line 98 in arch/risc-v/src/common/espressif/esp_idle.c

View workflow job for this annotation

GitHub Actions / check

Space precedes right parenthesis
{
uint64_t sleep_us = up_get_idletime();
if ( (sleep_us > EXPECTED_IDLE_TIME_US) )
{
sleep_us -= EARLY_WAKEUP_US;
esp_wait_tx_done();
esp_sleep_enable_timer_wakeup(sleep_us);
esp_light_sleep_start();

if(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO)
{
#if DEBUG_AUTOSLEEP
printf("Wake up from gpio\n");
esp_wait_tx_done();
#endif
}

else
{
#if DEBUG_AUTOSLEEP
printf("Wake up from timer\n");
esp_wait_tx_done();
#endif
}
}
}
spin_unlock_irqrestore(NULL, flags);
}

#else
# define up_idlepm()
#endif


void up_idle(void)
{
#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_TIMER_INTS)
Expand All @@ -64,11 +139,15 @@

nxsched_process_timer();
#else

/* 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
*/

asm("WFI");

/* Perform IDLE mode power management */
up_idlepm();

#endif
}
31 changes: 31 additions & 0 deletions arch/risc-v/src/common/espressif/esp_idle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/****************************************************************************
* arch/risc-v/src/common/espressif/esp_idle.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_IDLE_H
#define __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_IDLE_H

/****************************************************************************
* Included Files
****************************************************************************/

void esp_wait_tx_done(void);

/* Add your function declarations and definitions here */

#endif /* __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_IDLE_H */
119 changes: 119 additions & 0 deletions arch/risc-v/src/common/espressif/esp_pm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/****************************************************************************
* arch/risc-v/src/common/espressif/esp_pm.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/power/pm.h>
#include <arch/board/board.h>

#ifdef CONFIG_PM

#include "esp_sleep.h"
#include "esp_gpio.h"
#include "esp_pm.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define WAKE_UP_GPIO 14
/****************************************************************************
* Private Types
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

/****************************************************************************
* Private Functions
****************************************************************************/

static _Atomic uint32_t pm_wakelock = 0;

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: esp_pm_lockacquire
*
* Description:
* Take a power management lock
*
****************************************************************************/

void IRAM_ATTR esp_pm_lockacquire(void)
{
++pm_wakelock;
}

/****************************************************************************
* Name: esp_pm_lockrelease
*
* Description:
* Release the lock taken using esp_pm_lockacquire.
*
****************************************************************************/

void IRAM_ATTR esp_pm_lockrelease(void)
{
if (pm_wakelock > 0)
{
--pm_wakelock;
}

}

/****************************************************************************
* Name: esp_pm_lockstatus
*
* Description:
* Return power management lock status.
*
****************************************************************************/

uint32_t IRAM_ATTR esp_pm_lockstatus(void)
{
return pm_wakelock;
}

/**
* @brief Initialize power management
*
* This function initializes the power management system.
*
* @note This function should be called during system initialization.
* @warning This function is not thread-safe and should be called only once.
*/

void esp_pm_init(void)
{
esp_gpiowrite(WAKE_UP_GPIO, 1);
esp_configgpio(WAKE_UP_GPIO, INPUT_FUNCTION | PULLUP);
gpio_wakeup_enable(WAKE_UP_GPIO, ONLOW);
esp_sleep_enable_gpio_wakeup();
}

#endif // CONFIG_PM
Loading
Loading