feat: supports lp uart wakeup
This commit is contained in:
@@ -70,7 +70,7 @@ static const char *UART_TAG = "uart";
|
||||
#define UART_CLKDIV_FRAG_BIT_WIDTH (3)
|
||||
#define UART_TX_IDLE_NUM_DEFAULT (0)
|
||||
#define UART_PATTERN_DET_QLEN_DEFAULT (10)
|
||||
#define UART_MIN_WAKEUP_THRESH (UART_LL_MIN_WAKEUP_THRESH)
|
||||
#define UART_MIN_WAKEUP_THRESH (UART_LL_WAKEUP_EDGE_THRED_MIN)
|
||||
|
||||
#if (SOC_UART_LP_NUM >= 1)
|
||||
#define UART_THRESHOLD_NUM(uart_num, field_name) ((uart_num < SOC_UART_HP_NUM) ? field_name : LP_##field_name)
|
||||
@@ -1945,7 +1945,7 @@ esp_err_t uart_set_wakeup_threshold(uart_port_t uart_num, int wakeup_threshold)
|
||||
ESP_RETURN_ON_FALSE((wakeup_threshold <= UART_THRESHOLD_NUM(uart_num, UART_ACTIVE_THRESHOLD_V) && wakeup_threshold >= UART_MIN_WAKEUP_THRESH), ESP_ERR_INVALID_ARG, UART_TAG,
|
||||
"wakeup_threshold out of bounds");
|
||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||
uart_hal_set_wakeup_thrd(&(uart_context[uart_num].hal), wakeup_threshold);
|
||||
uart_hal_set_wakeup_edge_thrd(&(uart_context[uart_num].hal), wakeup_threshold);
|
||||
HP_UART_PAD_CLK_ATOMIC() {
|
||||
uart_ll_enable_pad_sleep_clock(uart_context[uart_num].hal.dev, true);
|
||||
}
|
||||
@@ -1957,7 +1957,7 @@ esp_err_t uart_get_wakeup_threshold(uart_port_t uart_num, int *out_wakeup_thresh
|
||||
{
|
||||
ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_ERR_INVALID_ARG, UART_TAG, "uart_num error");
|
||||
ESP_RETURN_ON_FALSE((out_wakeup_threshold != NULL), ESP_ERR_INVALID_ARG, UART_TAG, "argument is NULL");
|
||||
uart_hal_get_wakeup_thrd(&(uart_context[uart_num].hal), (uint32_t *)out_wakeup_threshold);
|
||||
uart_hal_get_wakeup_edge_thrd(&(uart_context[uart_num].hal), (uint32_t *)out_wakeup_threshold);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING:
|
||||
*
|
||||
* This file is shared between the HP and LP cores.
|
||||
* Updates to this file should be made carefully and should not include FreeRTOS APIs or other IDF-specific functionalities, such as the interrupt allocator.
|
||||
*/
|
||||
|
||||
#include "driver/uart_wakeup.h"
|
||||
#include "hal/uart_hal.h"
|
||||
|
||||
#if SOC_UART_WAKEUP_SUPPORT_CHAR_SEQ_MODE
|
||||
static esp_err_t uart_char_seq_wk_configure(uart_dev_t *hw, const char* phrase)
|
||||
{
|
||||
if (phrase == NULL || phrase[0] == '\0') {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
uint32_t mask = 0;
|
||||
uint32_t index = 0;
|
||||
|
||||
while (index < SOC_UART_WAKEUP_CHARS_SEQ_MAX_LEN && phrase[index] != '\0') {
|
||||
if (phrase[index] == '*') {
|
||||
mask |= 1 << index;
|
||||
} else {
|
||||
uart_ll_set_char_seq_wk_char(hw, index, phrase[index]);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if (
|
||||
index == 0 ||
|
||||
phrase[index - 1] == '*' ||
|
||||
mask > 0xF
|
||||
) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uart_ll_set_wakeup_char_seq_mask(hw, mask);
|
||||
uart_ll_set_wakeup_char_seq_char_num(hw, index - 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_err_t uart_wakeup_setup(uart_port_t uart_num, const uart_wakeup_cfg_t *cfg)
|
||||
{
|
||||
|
||||
if (cfg == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uart_dev_t *hw = UART_LL_GET_HW(uart_num);
|
||||
|
||||
// This should be mocked at ll level if the selection of the UART wakeup mode is not supported by this SOC.
|
||||
uart_ll_set_wakeup_mode(hw, cfg->wakeup_mode);
|
||||
|
||||
switch (cfg->wakeup_mode) {
|
||||
#if SOC_UART_WAKEUP_SUPPORT_ACTIVE_THRESH_MODE
|
||||
case UART_WK_MODE_ACTIVE_THRESH:
|
||||
// UART_ACTIVE_THRESHOLD register has only 10 bits, and the min value is 3.
|
||||
if (cfg->rx_edge_threshold < UART_LL_WAKEUP_EDGE_THRED_MIN || cfg->rx_edge_threshold > UART_LL_WAKEUP_EDGE_THRED_MAX(hw)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uart_ll_set_wakeup_edge_thrd(hw, cfg->rx_edge_threshold);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
#if SOC_UART_WAKEUP_SUPPORT_FIFO_THRESH_MODE
|
||||
case UART_WK_MODE_FIFO_THRESH:
|
||||
if (cfg->rx_fifo_threshold > UART_LL_WAKEUP_FIFO_THRED_MAX(hw)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uart_ll_set_wakeup_fifo_thrd(hw, cfg->rx_fifo_threshold);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
#if SOC_UART_WAKEUP_SUPPORT_START_BIT_MODE
|
||||
case UART_WK_MODE_START_BIT:
|
||||
return ESP_OK;
|
||||
#endif
|
||||
#if SOC_UART_WAKEUP_SUPPORT_CHAR_SEQ_MODE
|
||||
case UART_WK_MODE_CHAR_SEQ:
|
||||
return uart_char_seq_wk_configure(hw, cfg->wake_chars_seq);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
Reference in New Issue
Block a user