fix(ledc): always allocate memory from internal ram

This commit is contained in:
Song Ruo Jing
2023-09-21 19:04:31 +08:00
parent 821f7b0498
commit f5f44e2ce5
4 changed files with 25 additions and 18 deletions

View File

@ -7,6 +7,7 @@
#include "esp_types.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/idf_additions.h"
#include "esp_log.h"
#include "esp_check.h"
#include "soc/gpio_periph.h"
@ -58,9 +59,6 @@ typedef struct {
ledc_fade_mode_t mode;
SemaphoreHandle_t ledc_fade_sem;
SemaphoreHandle_t ledc_fade_mux;
#if CONFIG_SPIRAM_USE_MALLOC
StaticQueue_t ledc_fade_sem_storage;
#endif
ledc_cb_t ledc_fade_callback;
void *cb_user_arg;
volatile ledc_fade_fsm_t fsm;
@ -992,7 +990,7 @@ static esp_err_t ledc_fade_channel_deinit(ledc_mode_t speed_mode, ledc_channel_t
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_mux = NULL;
}
if (s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem) {
vSemaphoreDelete(s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem);
vSemaphoreDeleteWithCaps(s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem);
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = NULL;
}
free(s_ledc_fade_rec[speed_mode][channel]);
@ -1008,23 +1006,13 @@ static esp_err_t ledc_fade_channel_init_check(ledc_mode_t speed_mode, ledc_chann
return ESP_FAIL;
}
if (s_ledc_fade_rec[speed_mode][channel] == NULL) {
#if CONFIG_SPIRAM_USE_MALLOC
// Always malloc internally since LEDC ISR is always placed in IRAM
s_ledc_fade_rec[speed_mode][channel] = (ledc_fade_t *) heap_caps_calloc(1, sizeof(ledc_fade_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (s_ledc_fade_rec[speed_mode][channel] == NULL) {
ledc_fade_channel_deinit(speed_mode, channel);
return ESP_ERR_NO_MEM;
}
memset(&s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem_storage, 0, sizeof(StaticQueue_t));
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = xSemaphoreCreateBinaryStatic(&s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem_storage);
#else
s_ledc_fade_rec[speed_mode][channel] = (ledc_fade_t *) calloc(1, sizeof(ledc_fade_t));
if (s_ledc_fade_rec[speed_mode][channel] == NULL) {
ledc_fade_channel_deinit(speed_mode, channel);
return ESP_ERR_NO_MEM;
}
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = xSemaphoreCreateBinary();
#endif
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = xSemaphoreCreateBinaryWithCaps(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
s_ledc_fade_rec[speed_mode][channel]->ledc_fade_mux = xSemaphoreCreateMutex();
xSemaphoreGive(s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem);
s_ledc_fade_rec[speed_mode][channel]->fsm = LEDC_FSM_IDLE;

View File

@ -4,5 +4,5 @@ set(srcs "test_app_main.c"
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity driver esp_timer
PRIV_REQUIRES unity driver esp_timer esp_psram
WHOLE_ARCHIVE)

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
@ -6,6 +6,7 @@ from pytest_embedded_idf import IdfDut
@pytest.mark.supported_targets
@pytest.mark.temp_skip_ci(targets=['esp32s3'], reason='skip due to duplication with test_ledc_psram')
@pytest.mark.generic
@pytest.mark.parametrize(
'config',
@ -17,3 +18,17 @@ from pytest_embedded_idf import IdfDut
)
def test_ledc(dut: IdfDut) -> None:
dut.run_all_single_board_cases()
@pytest.mark.esp32s3
@pytest.mark.octal_psram
@pytest.mark.parametrize(
'config',
[
'iram_safe',
'release',
],
indirect=True,
)
def test_ledc_psram(dut: IdfDut) -> None:
dut.run_all_single_board_cases()

View File

@ -0,0 +1,4 @@
CONFIG_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0