refactor(sdio): place sdio slave driver into a new component

This commit is contained in:
Armando 2023-11-14 17:06:40 +08:00
parent 4bb8f5c577
commit 22b4270a6b
29 changed files with 57 additions and 66 deletions

View File

@ -15,7 +15,6 @@ set(includes "include"
"ledc/include"
"parlio/include"
"rmt/include"
"sdio_slave/include"
"sigma_delta/include"
"temperature_sensor/include"
"touch_sensor/include"
@ -101,11 +100,6 @@ if(CONFIG_SOC_RMT_SUPPORTED)
list(APPEND ldfragments "rmt/linker.lf")
endif()
# SDIO Slave related source files
if(CONFIG_SOC_SDIO_SLAVE_SUPPORTED)
list(APPEND srcs "sdio_slave/sdio_slave.c")
endif()
# Sigma-Delta Modulation related source files
if(CONFIG_SOC_SDM_SUPPORTED)
list(APPEND srcs "sigma_delta/sdm.c"
@ -164,7 +158,7 @@ else()
# for backward compatibility, the driver component needs to
# have a public dependency on other "esp_driver_foo" components
esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm
esp_driver_sdmmc esp_driver_sdspi esp_driver_ana_cmpr esp_driver_i2s
esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio
LDFRAGMENTS ${ldfragments}
)
endif()

View File

@ -92,16 +92,6 @@ components/driver/test_apps/rs485:
temporary: true
reason: lack of runners
components/driver/test_apps/sdio/sdio_common_tests/host_sdmmc:
enable:
- if: IDF_TARGET == "esp32"
temporary: false
reason: always use ESP32 SDMMC as host
components/driver/test_apps/sdio/sdio_common_tests/sdio:
disable:
- if: SOC_SDIO_SLAVE_SUPPORTED != 1
components/driver/test_apps/sigma_delta:
disable:
- if: SOC_SDM_SUPPORTED != 1

View File

@ -0,0 +1,13 @@
set(srcs)
set(public_include "include")
# SDIO Slave related source files
if(CONFIG_SOC_SDIO_SLAVE_SUPPORTED)
list(APPEND srcs "src/sdio_slave.c")
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES esp_driver_gpio esp_ringbuf
)

View File

@ -18,18 +18,17 @@ extern "C" {
typedef void(*sdio_event_cb_t)(uint8_t event);
/// Configuration of SDIO slave
typedef struct {
sdio_slave_timing_t timing; ///< timing of sdio_slave. see `sdio_slave_timing_t`.
sdio_slave_sending_mode_t sending_mode; ///< mode of sdio_slave. `SDIO_SLAVE_MODE_STREAM` if the data needs to be sent as much as possible; `SDIO_SLAVE_MODE_PACKET` if the data should be sent in packets.
int send_queue_size; ///< max buffers that can be queued before sending.
size_t recv_buffer_size;
///< If buffer_size is too small, it costs more CPU time to handle larger number of buffers.
///< If buffer_size is too large, the space larger than the transaction length is left blank but still counts a buffer, and the buffers are easily run out.
///< Should be set according to length of data really transferred.
///< All data that do not fully fill a buffer is still counted as one buffer. E.g. 10 bytes data costs 2 buffers if the size is 8 bytes per buffer.
///< Buffer size of the slave pre-defined between host and slave before communication. All receive buffer given to the driver should be larger than this.
///< If buffer_size is too small, it costs more CPU time to handle larger number of buffers.
///< If buffer_size is too large, the space larger than the transaction length is left blank but still counts a buffer, and the buffers are easily run out.
///< Should be set according to length of data really transferred.
///< All data that do not fully fill a buffer is still counted as one buffer. E.g. 10 bytes data costs 2 buffers if the size is 8 bytes per buffer.
///< Buffer size of the slave pre-defined between host and slave before communication. All receive buffer given to the driver should be larger than this.
sdio_event_cb_t event_cb; ///< when the host interrupts slave, this callback will be called with interrupt number (0-7).
uint32_t flags; ///< Features to be enabled for the slave, combinations of ``SDIO_SLAVE_FLAG_*``.
#define SDIO_SLAVE_FLAG_DAT2_DISABLED BIT(0) /**< It is required by the SD specification that all 4 data
@ -282,7 +281,6 @@ void sdio_slave_clear_host_int(sdio_slave_hostint_t mask);
*/
esp_err_t sdio_slave_wait_int(int pos, TickType_t wait);
#ifdef __cplusplus
}
#endif

View File

@ -75,8 +75,6 @@ The driver of FIFOs works as below:
driver also fix the STAILQ_NEXT pointer of the last descriptor so that the descriptors are now in a ring again.
*/
#include <string.h>
#include "driver/sdio_slave.h"
#include "soc/sdio_slave_periph.h"
@ -92,7 +90,6 @@ The driver of FIFOs works as below:
#include "hal/sdio_slave_hal.h"
#include "hal/gpio_hal.h"
#define SDIO_SLAVE_CHECK(res, str, ret_val) do { if(!(res)){\
SDIO_SLAVE_LOGE("%s", str);\
return ret_val;\
@ -103,7 +100,6 @@ static const char TAG[] = "sdio_slave";
#define SDIO_SLAVE_LOGE(s, ...) ESP_LOGE(TAG, "%s(%d): "s, __FUNCTION__,__LINE__,##__VA_ARGS__)
#define SDIO_SLAVE_LOGW(s, ...) ESP_LOGW(TAG, "%s: "s, __FUNCTION__,##__VA_ARGS__)
// sdio_slave_buf_handle_t is of type recv_desc_t*;
typedef struct recv_desc_s {
union {
@ -122,7 +118,6 @@ typedef struct recv_desc_s {
};
} recv_desc_t;
typedef TAILQ_HEAD(recv_tailq_head_s, recv_desc_s) recv_tailq_t;
typedef struct {

View File

@ -0,0 +1,17 @@
components/esp_driver_sdio/test_apps/sdio/sdio_common_tests/host_sdmmc:
enable:
- if: IDF_TARGET == "esp32"
temporary: false
reason: always use ESP32 SDMMC as host
depends_components:
- sdmmc
- esp_driver_sdmmc
- esp_driver_sdio
components/esp_driver_sdio/test_apps/sdio/sdio_common_tests/sdio:
disable:
- if: SOC_SDIO_SLAVE_SUPPORTED != 1
depends_components:
- sdmmc
- esp_driver_sdmmc
- esp_driver_sdio

View File

@ -14,7 +14,6 @@
static size_t before_free_8bit;
static size_t before_free_32bit;
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
@ -46,7 +45,5 @@ void app_main(void)
printf("/____/_____/___/\\____/ /____/_____/_/ /_/_/ /_/\\____/ \n");
printf(" \n");
unity_run_menu();
}

View File

@ -38,7 +38,6 @@ typedef struct {
bool check_data;
} test_sdio_param_t;
/*---------------------------------------------------------------
Host Init Settings
---------------------------------------------------------------*/
@ -91,7 +90,6 @@ static void s_send_finish_test(essl_handle_t handle)
essl_send_slave_intr(handle, BIT(7), TEST_TIMEOUT_MAX);
}
/*---------------------------------------------------------------
Function Tests
---------------------------------------------------------------*/
@ -132,8 +130,6 @@ TEST_CASE("SDIO_SDMMC: test interrupt", "[sdio]")
sdmmc_host_deinit();
}
/*---------------------------------------------------------------
SDMMC_SDIO: test register
---------------------------------------------------------------*/
@ -168,8 +164,6 @@ TEST_CASE("SDIO_SDMMC: test register", "[sdio]")
sdmmc_host_deinit();
}
/*---------------------------------------------------------------
SDMMC_SDIO: test reset
---------------------------------------------------------------*/
@ -213,7 +207,6 @@ TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
sdmmc_host_deinit();
}
/*---------------------------------------------------------------
Transaction Tests
---------------------------------------------------------------*/
@ -285,7 +278,6 @@ TEST_CASE("SDIO_SDMMC: test from host (Performance)", "[sdio_speed]")
test_from_host(false);
}
static void test_to_host(bool check_data)
{
//prepare buffer
@ -329,15 +321,15 @@ static void test_to_host(bool check_data)
remain_length -= rcv_len;
} while (remain_length > 0);
int64_t c_time_ms = ccomp_timer_stop()/1000;
int64_t c_time_ms = ccomp_timer_stop() / 1000;
int64_t end_us = esp_timer_get_time();
uint32_t total_time_ms = (end_us - pre_us)/1000;
uint32_t total_time_ms = (end_us - pre_us) / 1000;
ESP_LOGI(TAG, "test done, total time: %" PRIu32 " ms (%d ms compensated), bytes transferred: %"PRIu32, total_time_ms, (int)c_time_ms, expected_length);
uint32_t throughput_byte_per_ms = expected_length / c_time_ms;
ESP_LOGI(TAG, "Throughput: compensated %"PRIu32"KB/s %.2lf MB/s, typical %.2lf MB/s",
throughput_byte_per_ms, throughput_byte_per_ms/1000., expected_length/(total_time_ms*1000.));
throughput_byte_per_ms, throughput_byte_per_ms / 1000., expected_length / (total_time_ms * 1000.));
esp_rom_delay_us(50 * 1000);
s_send_finish_test(handle);

View File

@ -14,7 +14,6 @@
static size_t before_free_8bit;
static size_t before_free_32bit;
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);

View File

@ -25,7 +25,6 @@
static const char *TAG = "test_sdio";
/*---------------------------------------------------------------
Slave Init Settings
---------------------------------------------------------------*/
@ -69,8 +68,6 @@ static void s_slave_init(sdio_slave_sending_mode_t mode)
TEST_ESP_OK(sdio_slave_initialize(&slave_config));
}
#include "esp_rom_sys.h"
/*---------------------------------------------------------------
Function Tests
---------------------------------------------------------------*/
@ -141,7 +138,6 @@ TEST_CASE("SDIO_Slave: test reset", "[sdio]")
TEST_ASSERT_EQUAL(i, arg);
}
WORD_ALIGNED_ATTR uint8_t host_tx_buffer[TEST_RESET_DATA_LEN] = {};
for (int i = 0; i < TEST_RESET_BUF_NUMS; i++) {
test_fill_random_to_buffer(i, host_tx_buffer, TEST_RESET_DATA_LEN);
@ -159,7 +155,6 @@ TEST_CASE("SDIO_Slave: test reset", "[sdio]")
sdio_slave_deinit();
}
/*---------------------------------------------------------------
Transaction Tests
---------------------------------------------------------------*/
@ -178,7 +173,6 @@ static void test_from_host(bool check_data)
TEST_ASSERT(slave_rx_buffer[i]);
}
for (int i = 0; i < TEST_TARNS_PARAM_NUMS; i++) {
//slave init
s_slave_init(SDIO_SLAVE_SEND_STREAM);
@ -214,7 +208,6 @@ static void test_from_host(bool check_data)
TEST_ESP_OK(sdio_slave_recv_load_buf(used_buf_handle));
}
wait_for_finish(&s_test_slv_ctx);
sdio_slave_stop();
sdio_slave_deinit();
@ -226,7 +219,6 @@ static void test_from_host(bool check_data)
test_destroy_buffer_pool();
}
TEST_CASE("SDIO_Slave: test from host", "[sdio]")
{
test_from_host(true);
@ -237,7 +229,6 @@ TEST_CASE("SDIO_Slave: test from host (Performance)", "[sdio_speed]")
test_from_host(false);
}
/*---------------------------------------------------------------
To Host Tests
---------------------------------------------------------------*/
@ -262,7 +253,7 @@ static void test_to_host(void)
do {
void* arg;
//when the queue is full, do a blocking wait for 10ms, otherwise non-blocking
err = sdio_slave_send_get_finished(&arg, QUEUE_FULL()? 1: 0);
err = sdio_slave_send_get_finished(&arg, QUEUE_FULL() ? 1 : 0);
if (err == ESP_OK) {
s_test_slv_ctx.queued_cnt --;
continue;
@ -283,7 +274,6 @@ static void test_to_host(void)
s_test_slv_ctx.queued_cnt--;
}
wait_for_finish(&s_test_slv_ctx);
sdio_slave_stop();
sdio_slave_deinit();

View File

@ -11,12 +11,10 @@
#include <stdbool.h>
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TEST_RX_BUFFER_SIZE 2048
/*---------------------------------------------------------------

View File

@ -88,16 +88,7 @@ INPUT = \
$(PROJECT_PATH)/components/driver/rmt/include/driver/rmt_rx.h \
$(PROJECT_PATH)/components/driver/rmt/include/driver/rmt_tx.h \
$(PROJECT_PATH)/components/driver/rmt/include/driver/rmt_types.h \
$(PROJECT_PATH)/components/driver/sdio_slave/include/driver/sdio_slave.h \
$(PROJECT_PATH)/components/driver/sigma_delta/include/driver/sdm.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_host.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_types.h \
$(PROJECT_PATH)/components/esp_driver_sdspi/include/driver/sdspi_host.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_common.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_master.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave_hd.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave.h \
$(PROJECT_PATH)/components/driver/temperature_sensor/include/driver/temperature_sensor.h \
$(PROJECT_PATH)/components/driver/touch_sensor/include/driver/touch_sensor_common.h \
$(PROJECT_PATH)/components/driver/twai/include/driver/twai.h \
@ -143,6 +134,15 @@ INPUT = \
$(PROJECT_PATH)/components/esp_driver_i2s/include/driver/i2s_tdm.h \
$(PROJECT_PATH)/components/esp_driver_i2s/include/driver/i2s_types.h \
$(PROJECT_PATH)/components/esp_driver_pcnt/include/driver/pulse_cnt.h \
$(PROJECT_PATH)/components/esp_driver_sdio/include/driver/sdio_slave.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_default_configs.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_host.h \
$(PROJECT_PATH)/components/esp_driver_sdmmc/include/driver/sdmmc_types.h \
$(PROJECT_PATH)/components/esp_driver_sdspi/include/driver/sdspi_host.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_common.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_master.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave_hd.h \
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_driver.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_mac.h \

View File

@ -11,6 +11,8 @@ In order to control the dependence of other components on drivers at a smaller g
- `esp_driver_spi` - Driver for GPSPI
- `esp_driver_mcpwm` - Driver for Motor Control PWM
- `esp_driver_sdmmc` - Driver for SDMMC
- `esp_driver_sdspi` - Driver for SDSPI
- `esp_driver_sdio` - Driver for SDIO
- `esp_driver_ana_cmpr` - Driver for Analog Comparator
- `esp_driver_i2s` - Driver for I2S

View File

@ -11,6 +11,8 @@
- `esp_driver_spi` - 通用 SPI 驱动
- `esp_driver_mcpwm` - 电机控制 PWM 驱动
- `esp_driver_sdmmc` - SDMMC 驱动
- `esp_driver_sdspi` - SDSPI 驱动
- `esp_driver_sdio` - SDIO 驱动
- `esp_driver_ana_cmpr` - 模拟比较器驱动
- `esp_driver_i2s` - I2S 驱动

View File

@ -260,6 +260,8 @@ examples/peripherals/sdio/host:
- if: IDF_TARGET != "esp32"
temporary: true
reason: lack of runners
depends_components:
- esp_driver_sdio
examples/peripherals/sdio/slave:
disable:
@ -268,6 +270,8 @@ examples/peripherals/sdio/slave:
- if: IDF_TARGET != "esp32"
temporary: true
reason: lack of runners
depends_components:
- esp_driver_sdio
examples/peripherals/secure_element/atecc608_ecdsa:
enable: