diff --git a/components/esp_modem/examples/modem_psm/CMakeLists.txt b/components/esp_modem/examples/modem_psm/CMakeLists.txt new file mode 100644 index 000000000..ca0ca4bc5 --- /dev/null +++ b/components/esp_modem/examples/modem_psm/CMakeLists.txt @@ -0,0 +1,10 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS "../..") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(modem_psm) diff --git a/components/esp_modem/examples/modem_psm/README.md b/components/esp_modem/examples/modem_psm/README.md new file mode 100644 index 000000000..11788508a --- /dev/null +++ b/components/esp_modem/examples/modem_psm/README.md @@ -0,0 +1,32 @@ +# Modem Power Saving Mode, sleep modes example + + +## Overview + +This example demonstrates Power Saving Mode(PSM) in Sim70XX modems along with Deep sleep and Light Sleep modes in esp32. +This example enables Power saving mode in Sim70XX modem and tries to synchronise the sleep cycle of the modem with esp32. +When the modem wakes up from PSM sleep it wakes up the esp32. While the modem is awake esp32 goes to light sleep. + +This example is tested on a SIM7080 modem. + +## Supported devices + +This example is supported only on ESP32, ESP32-S2 and ESP32-S3. + +## Configuration + +* EXAMPLE_MODEM_UART_TX_PIN: Connect this pin to the UART Tx pin of the modem. +* EXAMPLE_MODEM_UART_RX_PIN: Connect this pin to the UART Rx pin of the modem. +* EXAMPLE_MODEM_PWRKEY_PIN: Connect this pin to the PWRKEY pin of the modem. +* EXAMPLE_MODEM_STATUS_PIN: Connect this pin to the Status pin of the modem. + + The status pin might not be exposed on a modem. It needs to tapped out from the LED indicator marked as STS. + +* EXAMPLE_MODEM_LIGHT_SLEEP_DURATION: Duration for which the esp32 will go into light sleep, while the modem is awake. + + If the esp32 goes into deep sleep while the modem is awake, esp32 will be awaken by the STATUS pin. So it's recommended to go to light sleep while the modem is awake. + +* EXAMPLE_MODEM_T3412_PERIODIC_TAU: T3412 timer is the duration of one awake and sleep cycle of the modem in PSM. +* EXAMPLE_MODEM_T3324_ACTIVE_TIME: T3324 timer is the duration for which the modem stays PSM. + + The timeout information is coded in bit format for T3412 and T3324 timer. diff --git a/components/esp_modem/examples/modem_psm/main/CMakeLists.txt b/components/esp_modem/examples/modem_psm/main/CMakeLists.txt new file mode 100644 index 000000000..cf40f6aec --- /dev/null +++ b/components/esp_modem/examples/modem_psm/main/CMakeLists.txt @@ -0,0 +1,3 @@ + +idf_component_register(SRCS "modem_psm.c" + INCLUDE_DIRS ".") diff --git a/components/esp_modem/examples/modem_psm/main/Kconfig.projbuild b/components/esp_modem/examples/modem_psm/main/Kconfig.projbuild new file mode 100644 index 000000000..c40bffeef --- /dev/null +++ b/components/esp_modem/examples/modem_psm/main/Kconfig.projbuild @@ -0,0 +1,109 @@ + +menu "Example Configuration" + + choice EXAMPLE_MODEM_DEVICE + prompt "Choose supported modem device (DCE)" + default EXAMPLE_MODEM_DEVICE_SIM7080 + help + Select modem device connected to the ESP DTE. + config EXAMPLE_MODEM_DEVICE_SIM7070 + bool "SIM7070" + help + SIM7070 is Multi-Band CAT M and NB IoT module. + config EXAMPLE_MODEM_DEVICE_SIM7080 + bool "SIM7080" + help + SIM7080 is Multi-Band CAT M and NB IoT module. + endchoice + + menu "UART Configuration" + config EXAMPLE_MODEM_UART_TX_PIN + int "TXD Pin Number" + default 4 + range 0 31 + help + Pin number of UART TX. + + config EXAMPLE_MODEM_UART_RX_PIN + int "RXD Pin Number" + default 5 + range 0 31 + help + Pin number of UART RX. + + config EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE + int "UART Event Task Stack Size" + range 2000 6000 + default 4096 + help + Stack size of UART event task. + + config EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY + int "UART Event Task Priority" + range 3 22 + default 5 + help + Priority of UART event task. + + config EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE + int "UART Event Queue Size" + range 10 40 + default 30 + help + Length of UART event queue. + + config EXAMPLE_MODEM_UART_TX_BUFFER_SIZE + int "UART TX Buffer Size" + range 256 2048 + default 512 + help + Buffer size of UART TX buffer. + + config EXAMPLE_MODEM_UART_RX_BUFFER_SIZE + int "UART RX Buffer Size" + range 256 2048 + default 1024 + help + Buffer size of UART RX buffer. + endmenu + + config EXAMPLE_MODEM_PWRKEY_PIN + int "PWRKEY Pin Number" + default 18 + range 0 31 + help + Pin number connected to modem's power key pin. + + config EXAMPLE_MODEM_STATUS_PIN + int "STATUS Pin Number" + default 19 + range 0 31 + help + Pin number connected to modem's status pin. + + config EXAMPLE_MODEM_LIGHT_SLEEP_DURATION + int "Light Sleep Duration" + default 10 + range 0 15000 + help + Duration in seconds, of which the esp32 goes into light sleep while the modem is awake. + + config EXAMPLE_MODEM_PPP_APN + string "Set MODEM APN" + default "internet" + help + Set APN (Access Point Name), a logical name to choose data network + + config EXAMPLE_MODEM_T3412_PERIODIC_TAU + string "T3412 Requester Periodic TAU" + default "00000100" + help + T3412 timer, i.e the duration of one awake and sleep cycle of the modem in PSM. + + config EXAMPLE_MODEM_T3324_ACTIVE_TIME + string "T3324 Requester Active Time" + default "00000001" + help + T3324 timer, i.e the duration for which the modem stays PSM. + +endmenu diff --git a/components/esp_modem/examples/modem_psm/main/modem_psm.c b/components/esp_modem/examples/modem_psm/main/modem_psm.c new file mode 100644 index 000000000..e85fa0c7a --- /dev/null +++ b/components/esp_modem/examples/modem_psm/main/modem_psm.c @@ -0,0 +1,202 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +/* + * Power Saving Mode(PSM) in Sim70XX modems along with + * Deep sleep and Light Sleep modes in esp32. +*/ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "esp_log.h" +#include "driver/uart.h" +#include "string.h" +#include "driver/gpio.h" +#include "esp_sleep.h" +#include "driver/rtc_io.h" +#include "esp_modem_api.h" +#include "esp_event.h" +#include "sdkconfig.h" + + +#define BUF_SIZE 1024 + +#define TXD_PIN ((gpio_num_t)CONFIG_EXAMPLE_MODEM_UART_TX_PIN) +#define RXD_PIN ((gpio_num_t)CONFIG_EXAMPLE_MODEM_UART_RX_PIN) +#define GPIO_INPUT_STATUS ((gpio_num_t)CONFIG_EXAMPLE_MODEM_STATUS_PIN) +#define GPIO_OUTPUT_PWRKEY ((gpio_num_t)CONFIG_EXAMPLE_MODEM_PWRKEY_PIN) +#define GPIO_OUTPUT_PIN_SEL (1ULL<