test: move 'driver/test/esp_serial_slave_link' to 'driver/test-apps/components' and make it be a component

This commit is contained in:
wanlei
2022-11-07 14:11:55 +08:00
parent f31ecbb42b
commit 45cf44e5c8
17 changed files with 209 additions and 152 deletions

View File

@@ -1,9 +1,6 @@
idf_component_register( idf_component_register(
SRC_DIRS . SRC_DIRS .
PRIV_INCLUDE_DIRS include PRIV_INCLUDE_DIRS include
PRIV_REQUIRES cmock test_utils test_driver_utils driver nvs_flash esp_timer esp_adc esp_event esp_wifi PRIV_REQUIRES test_utils driver nvs_flash esp_timer esp_event test_driver_utils esp_serial_slave_link
) )
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
# A local copy of idf-extra-components esp_serial_slave_link, for stabilities of the SDIO test
add_subdirectory(esp_serial_slave_link)

View File

@@ -1,11 +0,0 @@
set(srcs "essl.c" "essl_sdio.c" "essl_spi.c")
set(include "include")
set(priv_include "." "include/esp_serial_slave_link")
set(priv_req idf::sdmmc idf::driver)
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
target_sources(${COMPONENT_LIB} PRIVATE "${srcs}")
target_include_directories(${COMPONENT_LIB} PUBLIC ${include})
target_include_directories(${COMPONENT_LIB} PRIVATE ${priv_include})
target_link_libraries(${COMPONENT_LIB} PRIVATE ${priv_req})

View File

@@ -0,0 +1,6 @@
idf_component_register(
SRCS "essl.c" "essl_sdio.c" "essl_spi.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "." "include/esp_serial_slave_link"
REQUIRES sdmmc driver
)

View File

@@ -4,10 +4,12 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "essl.h" #include "essl.h"
#include "essl_internal.h" #include "essl_internal.h"
#include "esp_log.h"
#include "freertos/task.h"
#define TIME_EXPIRED_SINCE_CORE(start, end, timeout, max) (bool)((end)>=(start)? \ #define TIME_EXPIRED_SINCE_CORE(start, end, timeout, max) (bool)((end)>=(start)? \
((end)-(start)>(timeout)) :\ ((end)-(start)>(timeout)) :\
@@ -142,7 +144,7 @@ esp_err_t essl_get_tx_buffer_num(essl_handle_t handle, uint32_t *out_tx_num, uin
if (handle == NULL || out_tx_num == NULL) { if (handle == NULL || out_tx_num == NULL) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if (handle->update_tx_buffer_num == NULL|| handle->get_tx_buffer_num == NULL) { if (handle->update_tx_buffer_num == NULL || handle->get_tx_buffer_num == NULL) {
return ESP_ERR_NOT_SUPPORTED; return ESP_ERR_NOT_SUPPORTED;
} }
@@ -160,7 +162,7 @@ esp_err_t essl_get_rx_data_size(essl_handle_t handle, uint32_t *out_rx_size, uin
if (handle == NULL || out_rx_size == NULL) { if (handle == NULL || out_rx_size == NULL) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
if (handle->update_rx_data_size == NULL|| handle->get_rx_data_size == NULL) { if (handle->update_rx_data_size == NULL || handle->get_rx_data_size == NULL) {
return ESP_ERR_NOT_SUPPORTED; return ESP_ERR_NOT_SUPPORTED;
} }

View File

@@ -12,23 +12,23 @@
/** Context used by the ``esp_serial_slave_link`` component. /** Context used by the ``esp_serial_slave_link`` component.
*/ */
struct essl_dev_t { struct essl_dev_t {
void* args; void *args;
esp_err_t (*init)(void* ctx, uint32_t wait_ms); esp_err_t (*init)(void *ctx, uint32_t wait_ms);
esp_err_t (*wait_for_ready)(void *ctx, uint32_t wait_ms); esp_err_t (*wait_for_ready)(void *ctx, uint32_t wait_ms);
esp_err_t (*update_tx_buffer_num)(void *ctx, uint32_t wait_ms); esp_err_t (*update_tx_buffer_num)(void *ctx, uint32_t wait_ms);
esp_err_t (*update_rx_data_size)(void *ctx, uint32_t wait_ms); esp_err_t (*update_rx_data_size)(void *ctx, uint32_t wait_ms);
esp_err_t (*send_packet)(void *ctx, const void* start, size_t length, uint32_t wait_ms); esp_err_t (*send_packet)(void *ctx, const void *start, size_t length, uint32_t wait_ms);
esp_err_t (*get_packet)(void *ctx, void* out_data, size_t size, uint32_t wait_ms); esp_err_t (*get_packet)(void *ctx, void *out_data, size_t size, uint32_t wait_ms);
esp_err_t (*write_reg)(void *ctx, uint8_t addr, uint8_t value, uint8_t* value_o, uint32_t wait_ms); esp_err_t (*write_reg)(void *ctx, uint8_t addr, uint8_t value, uint8_t *value_o, uint32_t wait_ms);
esp_err_t (*read_reg)(void *ctx, uint8_t add, uint8_t *value_o, uint32_t wait_ms); esp_err_t (*read_reg)(void *ctx, uint8_t add, uint8_t *value_o, uint32_t wait_ms);
esp_err_t (*wait_int)(void *ctx, uint32_t wait_ms); esp_err_t (*wait_int)(void *ctx, uint32_t wait_ms);
esp_err_t (*clear_intr)(void* ctx, uint32_t intr_mask, uint32_t wait_ms); esp_err_t (*clear_intr)(void *ctx, uint32_t intr_mask, uint32_t wait_ms);
esp_err_t (*get_intr)(void* ctx, uint32_t* intr_raw, uint32_t *intr_st, uint32_t wait_ms); esp_err_t (*get_intr)(void *ctx, uint32_t *intr_raw, uint32_t *intr_st, uint32_t wait_ms);
esp_err_t (*set_intr_ena)(void* ctx, uint32_t ena_mask, uint32_t wait_ms); esp_err_t (*set_intr_ena)(void *ctx, uint32_t ena_mask, uint32_t wait_ms);
esp_err_t (*get_intr_ena)(void* ctx, uint32_t* ena_mask_o, uint32_t wait_ms); esp_err_t (*get_intr_ena)(void *ctx, uint32_t *ena_mask_o, uint32_t wait_ms);
esp_err_t (*send_slave_intr)(void* ctx, uint32_t intr_mask, uint32_t wait_ms); esp_err_t (*send_slave_intr)(void *ctx, uint32_t intr_mask, uint32_t wait_ms);
uint32_t (*get_tx_buffer_num)(void *ctx); uint32_t (*get_tx_buffer_num)(void *ctx);
uint32_t (*get_rx_data_size)(void *ctx); uint32_t (*get_rx_data_size)(void *ctx);

View File

@@ -4,11 +4,13 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "essl_sdio.h"
#include "esp_log.h"
#include "freertos/task.h"
#include "essl_internal.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "esp_log.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_defs.h"
#include "essl_internal.h"
#include "essl_sdio.h"
#if SOC_SDIO_SLAVE_SUPPORTED #if SOC_SDIO_SLAVE_SUPPORTED
#include "soc/host_reg.h" #include "soc/host_reg.h"
@@ -48,21 +50,21 @@ static const char TAG[] = "essl_sdio";
.reset_cnt = essl_sdio_reset_cnt, \ .reset_cnt = essl_sdio_reset_cnt, \
} }
typedef struct{ typedef struct {
//common part //common part
uint16_t buffer_size; uint16_t buffer_size;
///< 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. ///< 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. ///< Buffer size of the slave pre-defined between host and slave before communication.
size_t tx_sent_buffers; ///< Counter holding the amount of buffers already sent to ESP32 slave. Should be set to 0 when initialization. size_t tx_sent_buffers; ///< Counter holding the amount of buffers already sent to ESP32 slave. Should be set to 0 when initialization.
size_t tx_sent_buffers_latest; ///< The latest reading (from the slave) of counter holding the amount of buffers loaded. Should be set to 0 when initialization. size_t tx_sent_buffers_latest; ///< The latest reading (from the slave) of counter holding the amount of buffers loaded. Should be set to 0 when initialization.
size_t rx_got_bytes; ///< Counter holding the amount of bytes already received from ESP32 slave. Should be set to 0 when initialization. size_t rx_got_bytes; ///< Counter holding the amount of bytes already received from ESP32 slave. Should be set to 0 when initialization.
size_t rx_got_bytes_latest; ///< The latest reading (from the slave) of counter holding the amount of bytes to send. Should be set to 0 when initialization. size_t rx_got_bytes_latest; ///< The latest reading (from the slave) of counter holding the amount of bytes to send. Should be set to 0 when initialization.
sdmmc_card_t* card; ///< Initialized sdmmc_cmd card sdmmc_card_t *card; ///< Initialized sdmmc_cmd card
uint16_t block_size; uint16_t block_size;
///< If this is too large, it takes time to send stuff bits; while if too small, intervals between blocks cost much. ///< If this is too large, it takes time to send stuff bits; while if too small, intervals between blocks cost much.
///< Should be set according to length of data, and larger than ``TRANS_LEN_MAX/511``. ///< Should be set according to length of data, and larger than ``TRANS_LEN_MAX/511``.
///< Block size of the SDIO function 1. After the initialization this will hold the value the slave really do. Valid value is 1-2048. ///< Block size of the SDIO function 1. After the initialization this will hold the value the slave really do. Valid value is 1-2048.
} essl_sdio_context_t; } essl_sdio_context_t;
@@ -71,31 +73,31 @@ esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms);
static inline esp_err_t essl_sdio_write_byte(sdmmc_card_t *card, uint32_t addr, uint8_t val, uint8_t *val_o) static inline esp_err_t essl_sdio_write_byte(sdmmc_card_t *card, uint32_t addr, uint8_t val, uint8_t *val_o)
{ {
return sdmmc_io_write_byte(card, 1, addr&0x3FF, val, val_o); return sdmmc_io_write_byte(card, 1, addr & 0x3FF, val, val_o);
} }
static inline esp_err_t essl_sdio_write_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val, int len) static inline esp_err_t essl_sdio_write_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val, int len)
{ {
return sdmmc_io_write_bytes(card, 1, addr&0x3FF, val, len); return sdmmc_io_write_bytes(card, 1, addr & 0x3FF, val, len);
} }
static inline esp_err_t essl_sdio_read_byte(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o) static inline esp_err_t essl_sdio_read_byte(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o)
{ {
return sdmmc_io_read_byte(card, 1, addr&0x3FF, val_o); return sdmmc_io_read_byte(card, 1, addr & 0x3FF, val_o);
} }
static inline esp_err_t essl_sdio_read_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o, int len) static inline esp_err_t essl_sdio_read_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o, int len)
{ {
return sdmmc_io_read_bytes(card, 1, addr&0x3FF, val_o, len); return sdmmc_io_read_bytes(card, 1, addr & 0x3FF, val_o, len);
} }
esp_err_t essl_sdio_init_dev(essl_handle_t *out_handle, const essl_sdio_config_t *config) esp_err_t essl_sdio_init_dev(essl_handle_t *out_handle, const essl_sdio_config_t *config)
{ {
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
essl_sdio_context_t* arg = NULL; essl_sdio_context_t *arg = NULL;
essl_dev_t* dev = NULL; essl_dev_t *dev = NULL;
arg = (essl_sdio_context_t*)heap_caps_malloc(sizeof(essl_sdio_context_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); arg = (essl_sdio_context_t *)heap_caps_malloc(sizeof(essl_sdio_context_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
dev = (essl_dev_t*)heap_caps_malloc(sizeof(essl_dev_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); dev = (essl_dev_t *)heap_caps_malloc(sizeof(essl_dev_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (arg == NULL || dev == NULL) { if (arg == NULL || dev == NULL) {
ret = ESP_ERR_NO_MEM; ret = ESP_ERR_NO_MEM;
@@ -124,78 +126,96 @@ cleanup:
esp_err_t essl_sdio_deinit_dev(essl_handle_t handle) esp_err_t essl_sdio_deinit_dev(essl_handle_t handle)
{ {
if (handle) free (handle->args); if (handle) {
free (handle->args);
}
free(handle); free(handle);
return ESP_OK; return ESP_OK;
} }
esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms) esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
esp_err_t err; esp_err_t err;
uint8_t ioe = 0; uint8_t ioe = 0;
sdmmc_card_t* card = ctx->card; sdmmc_card_t *card = ctx->card;
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_ENABLE, &ioe); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_ENABLE, &ioe);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "IOE: 0x%02x", ioe); return err;
}
ESP_LOGD(TAG, "IOE: 0x%02"PRIx8, ioe);
uint8_t ior = 0; uint8_t ior = 0;
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "IOR: 0x%02x", ior); return err;
}
ESP_LOGD(TAG, "IOR: 0x%02"PRIx8, ior);
// enable function 1 // enable function 1
ioe |= FUNC1_EN_MASK; ioe |= FUNC1_EN_MASK;
err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_FN_ENABLE, ioe, &ioe); err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_FN_ENABLE, ioe, &ioe);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "IOE: 0x%02x", ioe); return err;
}
ESP_LOGD(TAG, "IOE: 0x%02"PRIx8, ioe);
// wait for the card to become ready // wait for the card to become ready
while ((ior & FUNC1_EN_MASK) == 0) { while ((ior & FUNC1_EN_MASK) == 0) {
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "IOR: 0x%02x", ior); return err;
}
ESP_LOGD(TAG, "IOR: 0x%02"PRIx8, ior);
} }
// get interrupt status // get interrupt status
uint8_t ie = 0; uint8_t ie = 0;
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_INT_ENABLE, &ie); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_INT_ENABLE, &ie);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG,"IE: 0x%02x", ie); return err;
}
ESP_LOGD(TAG, "IE: 0x%02"PRIx8, ie);
// enable interrupts for function 1&2 and master enable // enable interrupts for function 1&2 and master enable
ie |= BIT(0) | FUNC1_EN_MASK; ie |= BIT(0) | FUNC1_EN_MASK;
err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_INT_ENABLE, ie, &ie); err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_INT_ENABLE, ie, &ie);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "IE: 0x%02x", ie); return err;
}
ESP_LOGD(TAG, "IE: 0x%02"PRIx8, ie);
// get bus width register // get bus width register
uint8_t bus_width = 0; uint8_t bus_width = 0;
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, &bus_width); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, &bus_width);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG,"BUS_WIDTH: 0x%02x", bus_width); return err;
}
ESP_LOGD(TAG, "BUS_WIDTH: 0x%02"PRIx8, bus_width);
// enable continuous SPI interrupts // enable continuous SPI interrupts
bus_width |= CCCR_BUS_WIDTH_ECSI; bus_width |= CCCR_BUS_WIDTH_ECSI;
err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, bus_width, &bus_width); err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, bus_width, &bus_width);
if (err != ESP_OK) return err; if (err != ESP_OK) {
ESP_LOGD(TAG, "BUS_WIDTH: 0x%02x", bus_width); return err;
}
ESP_LOGD(TAG, "BUS_WIDTH: 0x%02"PRIx8, bus_width);
uint16_t bs = 512; uint16_t bs = 512;
const uint8_t* bs_u8 = (const uint8_t*) &bs; const uint8_t *bs_u8 = (const uint8_t *) &bs;
uint16_t bs_read = 0; uint16_t bs_read = 0;
uint8_t* bs_read_u8 = (uint8_t*) &bs_read; uint8_t *bs_read_u8 = (uint8_t *) &bs_read;
// Set block sizes for functions 0 to 512 bytes // Set block sizes for functions 0 to 512 bytes
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
ESP_LOGD(TAG, "Function 0 BS: %04x", (int) bs_read); ESP_LOGD(TAG, "Function 0 BS: %d", (unsigned int) bs_read);
ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL)); ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL));
ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL)); ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
ESP_LOGD(TAG, "Function 0 BS: %04x", (int) bs_read); ESP_LOGD(TAG, "Function 0 BS: %d", (unsigned int) bs_read);
// Set block sizes for functions 1 to given value (default value = 512). // Set block sizes for functions 1 to given value (default value = 512).
if (ctx->block_size > 0 && ctx->block_size <= 2048) { if (ctx->block_size > 0 && ctx->block_size <= 2048) {
@@ -206,13 +226,13 @@ esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
size_t offset = SD_IO_FBR_START * 1; size_t offset = SD_IO_FBR_START * 1;
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
ESP_LOGD(TAG, "Function 1 BS: %04x", (int) bs_read); ESP_LOGD(TAG, "Function 1 BS: %d", (unsigned int) bs_read);
ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL)); ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL));
ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL)); ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1])); ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
ESP_LOGD(TAG, "Function 1 BS: %04x", (int) bs_read); ESP_LOGD(TAG, "Function 1 BS: %d", (unsigned int) bs_read);
if (bs_read != ctx->block_size) { if (bs_read != ctx->block_size) {
ESP_LOGW(TAG, "Function1 block size %d different than set value %d", bs_read, ctx->block_size); ESP_LOGW(TAG, "Function1 block size %d different than set value %d", bs_read, ctx->block_size);
@@ -225,12 +245,14 @@ esp_err_t essl_sdio_wait_for_ready(void *arg, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "wait_for_ioready"); ESP_LOGV(TAG, "wait_for_ioready");
esp_err_t err; esp_err_t err;
sdmmc_card_t *card = ((essl_sdio_context_t*)arg)->card; sdmmc_card_t *card = ((essl_sdio_context_t *)arg)->card;
// wait for the card to become ready // wait for the card to become ready
uint8_t ior = 0; uint8_t ior = 0;
while ((ior & FUNC1_EN_MASK) == 0) { while ((ior & FUNC1_EN_MASK) == 0) {
err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior); err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
if (err != ESP_OK) return err; if (err != ESP_OK) {
return err;
}
ESP_LOGD(TAG, "IOR: 0x%02x", ior); ESP_LOGD(TAG, "IOR: 0x%02x", ior);
} }
return ESP_OK; return ESP_OK;
@@ -238,9 +260,9 @@ esp_err_t essl_sdio_wait_for_ready(void *arg, uint32_t wait_ms)
esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uint32_t wait_ms) esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
uint16_t buffer_size = ctx->buffer_size; uint16_t buffer_size = ctx->buffer_size;
int buffer_used = (length + buffer_size - 1)/buffer_size; int buffer_used = (length + buffer_size - 1) / buffer_size;
esp_err_t err; esp_err_t err;
if (essl_sdio_get_tx_buffer_num(arg) < buffer_used) { if (essl_sdio_get_tx_buffer_num(arg) < buffer_used) {
@@ -257,7 +279,7 @@ esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uin
ESP_LOGV(TAG, "send_packet: len: %d", length); ESP_LOGV(TAG, "send_packet: len: %d", length);
uint8_t *start_ptr = (uint8_t*)start; uint8_t *start_ptr = (uint8_t *)start;
uint32_t len_remain = length; uint32_t len_remain = length;
do { do {
const int block_size = 512; const int block_size = 512;
@@ -266,7 +288,7 @@ esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uin
* higher effeciency. The length is determined by the SDIO address, and * higher effeciency. The length is determined by the SDIO address, and
* the remainning will be discard by the slave hardware. * the remainning will be discard by the slave hardware.
*/ */
int block_n = len_remain/block_size; int block_n = len_remain / block_size;
int len_to_send; int len_to_send;
if (block_n) { if (block_n) {
len_to_send = block_n * block_size; len_to_send = block_n * block_size;
@@ -275,7 +297,9 @@ esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uin
len_to_send = len_remain; len_to_send = len_remain;
err = sdmmc_io_write_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start_ptr, (len_to_send + 3) & (~3)); err = sdmmc_io_write_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start_ptr, (len_to_send + 3) & (~3));
} }
if (err != ESP_OK) return err; if (err != ESP_OK) {
return err;
}
start_ptr += len_to_send; start_ptr += len_to_send;
len_remain -= len_to_send; len_remain -= len_to_send;
} while (len_remain); } while (len_remain);
@@ -286,7 +310,7 @@ esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uin
esp_err_t essl_sdio_get_packet(void *arg, void *out_data, size_t size, uint32_t wait_ms) esp_err_t essl_sdio_get_packet(void *arg, void *out_data, size_t size, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
esp_err_t err; esp_err_t err;
ESP_LOGV(TAG, "get_packet: read size=%d", size); ESP_LOGV(TAG, "get_packet: read size=%d", size);
@@ -306,7 +330,7 @@ esp_err_t essl_sdio_get_packet(void *arg, void *out_data, size_t size, uint32_t
const int block_size = 512; //currently our driver don't support block size other than 512 const int block_size = 512; //currently our driver don't support block size other than 512
int len_to_send; int len_to_send;
int block_n = len_remain/block_size; int block_n = len_remain / block_size;
if (block_n != 0) { if (block_n != 0) {
len_to_send = block_n * block_size; len_to_send = block_n * block_size;
err = sdmmc_io_read_blocks(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, len_to_send); err = sdmmc_io_read_blocks(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, len_to_send);
@@ -319,52 +343,58 @@ esp_err_t essl_sdio_get_packet(void *arg, void *out_data, size_t size, uint32_t
*/ */
err = sdmmc_io_read_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, (len_to_send + 3) & (~3)); err = sdmmc_io_read_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, (len_to_send + 3) & (~3));
} }
if (err != ESP_OK) return err; if (err != ESP_OK) {
return err;
}
start += len_to_send; start += len_to_send;
len_remain -= len_to_send; len_remain -= len_to_send;
ctx->rx_got_bytes += len_to_send; ctx->rx_got_bytes += len_to_send;
} while(len_remain!=0); } while (len_remain != 0);
return err; return err;
} }
uint32_t essl_sdio_get_tx_buffer_num(void *arg) uint32_t essl_sdio_get_tx_buffer_num(void *arg)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
ESP_LOGV(TAG, "tx latest: %d, sent: %d", ctx->tx_sent_buffers_latest, ctx->tx_sent_buffers); ESP_LOGV(TAG, "tx latest: %d, sent: %d", ctx->tx_sent_buffers_latest, ctx->tx_sent_buffers);
return (ctx->tx_sent_buffers_latest + TX_BUFFER_MAX - ctx->tx_sent_buffers)%TX_BUFFER_MAX; return (ctx->tx_sent_buffers_latest + TX_BUFFER_MAX - ctx->tx_sent_buffers) % TX_BUFFER_MAX;
} }
esp_err_t essl_sdio_update_tx_buffer_num(void *arg, uint32_t wait_ms) esp_err_t essl_sdio_update_tx_buffer_num(void *arg, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
uint32_t len; uint32_t len;
esp_err_t err; esp_err_t err;
err = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_TOKEN_RDATA_REG, (uint8_t *) &len, 4); err = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_TOKEN_RDATA_REG, (uint8_t *) &len, 4);
if (err != ESP_OK) return err; if (err != ESP_OK) {
len = (len>>16)&TX_BUFFER_MASK; return err;
}
len = (len >> 16)&TX_BUFFER_MASK;
ctx->tx_sent_buffers_latest = len; ctx->tx_sent_buffers_latest = len;
ESP_LOGV(TAG, "update_tx_buffer_num: %d", len); ESP_LOGV(TAG, "update_tx_buffer_num: %d", (unsigned int)len);
return ESP_OK; return ESP_OK;
} }
uint32_t essl_sdio_get_rx_data_size(void *arg) uint32_t essl_sdio_get_rx_data_size(void *arg)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
ESP_LOGV(TAG, "rx latest: %d, read: %d", ctx->rx_got_bytes_latest, ctx->rx_got_bytes); ESP_LOGV(TAG, "rx latest: %d, read: %d", ctx->rx_got_bytes_latest, ctx->rx_got_bytes);
return (ctx->rx_got_bytes_latest + RX_BYTE_MAX - ctx->rx_got_bytes)%RX_BYTE_MAX; return (ctx->rx_got_bytes_latest + RX_BYTE_MAX - ctx->rx_got_bytes) % RX_BYTE_MAX;
} }
esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms) esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
uint32_t len; uint32_t len;
esp_err_t err; esp_err_t err;
ESP_LOGV(TAG, "get_rx_data_size: got_bytes: %d", ctx->rx_got_bytes); ESP_LOGV(TAG, "get_rx_data_size: got_bytes: %d", ctx->rx_got_bytes);
err = essl_sdio_read_bytes(ctx->card, HOST_SLCHOST_PKT_LEN_REG, (uint8_t *) &len, 4); err = essl_sdio_read_bytes(ctx->card, HOST_SLCHOST_PKT_LEN_REG, (uint8_t *) &len, 4);
if (err != ESP_OK) return err; if (err != ESP_OK) {
return err;
}
len &= RX_BYTE_MASK; len &= RX_BYTE_MASK;
ctx->rx_got_bytes_latest = len; ctx->rx_got_bytes_latest = len;
return ESP_OK; return ESP_OK;
@@ -373,80 +403,95 @@ esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms)
esp_err_t essl_sdio_write_reg(void *arg, uint8_t addr, uint8_t value, uint8_t *value_o, uint32_t wait_ms) esp_err_t essl_sdio_write_reg(void *arg, uint8_t addr, uint8_t value, uint8_t *value_o, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "write_reg: %08X", value); ESP_LOGV(TAG, "write_reg: 0x%02"PRIX8, value);
// addrress over range // addrress over range
if (addr >= 60) return ESP_ERR_INVALID_ARG; if (addr >= 60) {
return ESP_ERR_INVALID_ARG;
}
//W7 is reserved for interrupts //W7 is reserved for interrupts
if (addr >= 28) addr += 4; if (addr >= 28) {
return essl_sdio_write_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W_REG(addr), value, value_o); addr += 4;
}
return essl_sdio_write_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W_REG(addr), value, value_o);
} }
esp_err_t essl_sdio_read_reg(void *arg, uint8_t add, uint8_t *value_o, uint32_t wait_ms) esp_err_t essl_sdio_read_reg(void *arg, uint8_t add, uint8_t *value_o, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "read_reg"); ESP_LOGV(TAG, "read_reg");
// address over range // address over range
if (add >= 60) return ESP_ERR_INVALID_ARG; if (add >= 60) {
return ESP_ERR_INVALID_ARG;
}
//W7 is reserved for interrupts //W7 is reserved for interrupts
if (add >= 28) add += 4; if (add >= 28) {
esp_err_t ret = essl_sdio_read_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W_REG(add), value_o); add += 4;
ESP_LOGV(TAG, "reg: %08X", *value_o); }
esp_err_t ret = essl_sdio_read_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W_REG(add), value_o);
ESP_LOGV(TAG, "reg: %02"PRIX8, *value_o);
return ret; return ret;
} }
esp_err_t essl_sdio_clear_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms) esp_err_t essl_sdio_clear_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "clear_intr: %08X", intr_mask); ESP_LOGV(TAG, "clear_intr: %08"PRIX32, intr_mask);
return essl_sdio_write_bytes(((essl_sdio_context_t *) arg)->card, HOST_SLC0HOST_INT_CLR_REG, (uint8_t *) &intr_mask, 4); return essl_sdio_write_bytes(((essl_sdio_context_t *) arg)->card, HOST_SLC0HOST_INT_CLR_REG, (uint8_t *) &intr_mask, 4);
} }
esp_err_t essl_sdio_get_intr(void *arg, uint32_t *intr_raw, uint32_t *intr_st, uint32_t wait_ms) esp_err_t essl_sdio_get_intr(void *arg, uint32_t *intr_raw, uint32_t *intr_st, uint32_t wait_ms)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
esp_err_t r; esp_err_t r;
ESP_LOGV(TAG, "get_intr"); ESP_LOGV(TAG, "get_intr");
if (intr_raw == NULL && intr_st == NULL) return ESP_ERR_INVALID_ARG; if (intr_raw == NULL && intr_st == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (intr_raw != NULL) { if (intr_raw != NULL) {
r= essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_RAW_REG, (uint8_t *) intr_raw, 4); r = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_RAW_REG, (uint8_t *) intr_raw, 4);
if (r != ESP_OK) return r; if (r != ESP_OK) {
return r;
}
} }
if (intr_st != NULL) { if (intr_st != NULL) {
r = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_ST_REG, (uint8_t *) intr_st, 4); r = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_ST_REG, (uint8_t *) intr_st, 4);
if (r != ESP_OK) return r; if (r != ESP_OK) {
return r;
}
} }
return ESP_OK; return ESP_OK;
} }
esp_err_t essl_sdio_set_intr_ena(void *arg, uint32_t ena_mask, uint32_t wait_ms) esp_err_t essl_sdio_set_intr_ena(void *arg, uint32_t ena_mask, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "set_intr_ena: %08X", ena_mask); ESP_LOGV(TAG, "set_intr_ena: %08"PRIX32, ena_mask);
return essl_sdio_write_bytes(((essl_sdio_context_t*)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG, return essl_sdio_write_bytes(((essl_sdio_context_t *)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG,
(uint8_t *) &ena_mask, 4); (uint8_t *) &ena_mask, 4);
} }
esp_err_t essl_sdio_get_intr_ena(void *arg, uint32_t *ena_mask_o, uint32_t wait_ms) esp_err_t essl_sdio_get_intr_ena(void *arg, uint32_t *ena_mask_o, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "get_intr_ena"); ESP_LOGV(TAG, "get_intr_ena");
esp_err_t ret = essl_sdio_read_bytes(((essl_sdio_context_t*)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG, esp_err_t ret = essl_sdio_read_bytes(((essl_sdio_context_t *)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG,
(uint8_t *) ena_mask_o, 4); (uint8_t *) ena_mask_o, 4);
ESP_LOGV(TAG, "ena: %08X", *ena_mask_o); ESP_LOGV(TAG, "ena: %08"PRIX32, *ena_mask_o);
return ret; return ret;
} }
esp_err_t essl_sdio_send_slave_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms) esp_err_t essl_sdio_send_slave_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms)
{ {
ESP_LOGV(TAG, "send_slave_intr: %02x", intr_mask); //Only 8 bits available
return essl_sdio_write_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W7_REG + 0, intr_mask, NULL); ESP_LOGV(TAG, "send_slave_intr: %02"PRIx8, (uint8_t)intr_mask);
return essl_sdio_write_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W7_REG + 0, (uint8_t)intr_mask, NULL);
} }
esp_err_t essl_sdio_wait_int(void *arg, uint32_t wait_ms) esp_err_t essl_sdio_wait_int(void *arg, uint32_t wait_ms)
{ {
return sdmmc_io_wait_int(((essl_sdio_context_t*)arg)->card, wait_ms); return sdmmc_io_wait_int(((essl_sdio_context_t *)arg)->card, wait_ms);
} }
void essl_sdio_reset_cnt(void *arg) void essl_sdio_reset_cnt(void *arg)
{ {
essl_sdio_context_t* ctx = arg; essl_sdio_context_t *ctx = arg;
ctx->rx_got_bytes = 0; ctx->rx_got_bytes = 0;
ctx->tx_sent_buffers = 0; ctx->tx_sent_buffers = 0;
} }

View File

@@ -9,13 +9,15 @@
#include "esp_log.h" #include "esp_log.h"
#include "esp_check.h" #include "esp_check.h"
#include "esp_memory_utils.h" #include "esp_memory_utils.h"
#include "driver/spi_master.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "essl_internal.h"
#include "essl_spi.h" #include "driver/spi_master.h"
#include "hal/spi_types.h" #include "hal/spi_types.h"
#include "hal/spi_ll.h" #include "hal/spi_ll.h"
#include "essl_internal.h"
#include "essl_spi.h"
/** /**
* Initialise device function list of SPI by this macro. * Initialise device function list of SPI by this macro.
*/ */
@@ -107,7 +109,7 @@ esp_err_t essl_spi_rdbuf(spi_device_handle_t spi, uint8_t *out_data, int addr, i
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_transmit(spi, (spi_transaction_t*)&t); return spi_device_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_rdbuf_polling(spi_device_handle_t spi, uint8_t *out_data, int addr, int len, uint32_t flags) esp_err_t essl_spi_rdbuf_polling(spi_device_handle_t spi, uint8_t *out_data, int addr, int len, uint32_t flags)
@@ -123,7 +125,7 @@ esp_err_t essl_spi_rdbuf_polling(spi_device_handle_t spi, uint8_t *out_data, int
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_polling_transmit(spi, (spi_transaction_t*)&t); return spi_device_polling_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_wrbuf(spi_device_handle_t spi, const uint8_t *data, int addr, int len, uint32_t flags) esp_err_t essl_spi_wrbuf(spi_device_handle_t spi, const uint8_t *data, int addr, int len, uint32_t flags)
@@ -138,7 +140,7 @@ esp_err_t essl_spi_wrbuf(spi_device_handle_t spi, const uint8_t *data, int addr,
}, },
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_transmit(spi, (spi_transaction_t*)&t); return spi_device_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_wrbuf_polling(spi_device_handle_t spi, const uint8_t *data, int addr, int len, uint32_t flags) esp_err_t essl_spi_wrbuf_polling(spi_device_handle_t spi, const uint8_t *data, int addr, int len, uint32_t flags)
@@ -153,7 +155,7 @@ esp_err_t essl_spi_wrbuf_polling(spi_device_handle_t spi, const uint8_t *data, i
}, },
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_polling_transmit(spi, (spi_transaction_t*)&t); return spi_device_polling_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_rddma_seg(spi_device_handle_t spi, uint8_t *out_data, int seg_len, uint32_t flags) esp_err_t essl_spi_rddma_seg(spi_device_handle_t spi, uint8_t *out_data, int seg_len, uint32_t flags)
@@ -167,7 +169,7 @@ esp_err_t essl_spi_rddma_seg(spi_device_handle_t spi, uint8_t *out_data, int seg
}, },
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_transmit(spi, (spi_transaction_t*)&t); return spi_device_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_rddma_done(spi_device_handle_t spi, uint32_t flags) esp_err_t essl_spi_rddma_done(spi_device_handle_t spi, uint32_t flags)
@@ -184,15 +186,17 @@ esp_err_t essl_spi_rddma(spi_device_handle_t spi, uint8_t *out_data, int len, in
if (!esp_ptr_dma_capable(out_data) || ((intptr_t)out_data % 4) != 0) { if (!esp_ptr_dma_capable(out_data) || ((intptr_t)out_data % 4) != 0) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
seg_len = (seg_len > 0)? seg_len : len; seg_len = (seg_len > 0) ? seg_len : len;
uint8_t* read_ptr = out_data; uint8_t *read_ptr = out_data;
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
while (len > 0) { while (len > 0) {
int send_len = MIN(seg_len, len); int send_len = MIN(seg_len, len);
ret = essl_spi_rddma_seg(spi, read_ptr, send_len, flags); ret = essl_spi_rddma_seg(spi, read_ptr, send_len, flags);
if (ret != ESP_OK) return ret; if (ret != ESP_OK) {
return ret;
}
len -= send_len; len -= send_len;
read_ptr += send_len; read_ptr += send_len;
@@ -211,7 +215,7 @@ esp_err_t essl_spi_wrdma_seg(spi_device_handle_t spi, const uint8_t *data, int s
}, },
.dummy_bits = get_hd_dummy_bits(flags), .dummy_bits = get_hd_dummy_bits(flags),
}; };
return spi_device_transmit(spi, (spi_transaction_t*)&t); return spi_device_transmit(spi, (spi_transaction_t *)&t);
} }
esp_err_t essl_spi_wrdma_done(spi_device_handle_t spi, uint32_t flags) esp_err_t essl_spi_wrdma_done(spi_device_handle_t spi, uint32_t flags)
@@ -228,13 +232,15 @@ esp_err_t essl_spi_wrdma(spi_device_handle_t spi, const uint8_t *data, int len,
if (!esp_ptr_dma_capable(data)) { if (!esp_ptr_dma_capable(data)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
seg_len = (seg_len > 0)? seg_len : len; seg_len = (seg_len > 0) ? seg_len : len;
while (len > 0) { while (len > 0) {
int send_len = MIN(seg_len, len); int send_len = MIN(seg_len, len);
esp_err_t ret = essl_spi_wrdma_seg(spi, data, send_len, flags); esp_err_t ret = essl_spi_wrdma_seg(spi, data, send_len, flags);
if (ret != ESP_OK) return ret; if (ret != ESP_OK) {
return ret;
}
len -= send_len; len -= send_len;
data += send_len; data += send_len;
@@ -329,8 +335,8 @@ static uint32_t essl_spi_get_rx_data_size(void *arg)
static esp_err_t essl_spi_update_rx_data_size(void *arg, uint32_t wait_ms) static esp_err_t essl_spi_update_rx_data_size(void *arg, uint32_t wait_ms)
{ {
essl_spi_context_t *ctx = arg; essl_spi_context_t *ctx = arg;
uint32_t updated_size; uint32_t updated_size = 0;
uint32_t previous_size; uint32_t previous_size = 0;
esp_err_t ret; esp_err_t ret;
ret = essl_spi_rdbuf_polling(ctx->spi, (uint8_t *)&previous_size, ctx->master_in.rx_sync_reg, sizeof(uint32_t), 0); ret = essl_spi_rdbuf_polling(ctx->spi, (uint8_t *)&previous_size, ctx->master_in.rx_sync_reg, sizeof(uint32_t), 0);
@@ -350,7 +356,7 @@ static esp_err_t essl_spi_update_rx_data_size(void *arg, uint32_t wait_ms)
} }
if (updated_size == previous_size) { if (updated_size == previous_size) {
ctx->master_in.slave_tx_bytes = updated_size; ctx->master_in.slave_tx_bytes = updated_size;
ESP_LOGV(TAG, "updated: slave prepared tx buffer is: %d bytes", updated_size); ESP_LOGV(TAG, "updated: slave prepared tx buffer is: %d bytes", (unsigned int)updated_size);
return ret; return ret;
} }
previous_size = updated_size; previous_size = updated_size;
@@ -419,8 +425,8 @@ static uint32_t essl_spi_get_tx_buffer_num(void *arg)
static esp_err_t essl_spi_update_tx_buffer_num(void *arg, uint32_t wait_ms) static esp_err_t essl_spi_update_tx_buffer_num(void *arg, uint32_t wait_ms)
{ {
essl_spi_context_t *ctx = arg; essl_spi_context_t *ctx = arg;
uint32_t updated_num; uint32_t updated_num = 0;
uint32_t previous_size; uint32_t previous_size = 0;
esp_err_t ret; esp_err_t ret;
ret = essl_spi_rdbuf_polling(ctx->spi, (uint8_t *)&previous_size, ctx->master_out.tx_sync_reg, sizeof(uint32_t), 0); ret = essl_spi_rdbuf_polling(ctx->spi, (uint8_t *)&previous_size, ctx->master_out.tx_sync_reg, sizeof(uint32_t), 0);
@@ -440,7 +446,7 @@ static esp_err_t essl_spi_update_tx_buffer_num(void *arg, uint32_t wait_ms)
} }
if (updated_num == previous_size) { if (updated_num == previous_size) {
ctx->master_out.slave_rx_buf_num = updated_num; ctx->master_out.slave_rx_buf_num = updated_num;
ESP_LOGV(TAG, "updated: slave prepared rx buffer: %d", updated_num); ESP_LOGV(TAG, "updated: slave prepared rx buffer: %d", (unsigned int)updated_num);
return ret; return ret;
} }
previous_size = updated_num; previous_size = updated_num;
@@ -469,12 +475,12 @@ esp_err_t essl_spi_send_packet(void *arg, const void *data, size_t size, uint32_
} }
//Slave still did not load a sufficient amount of buffers //Slave still did not load a sufficient amount of buffers
if (essl_spi_get_tx_buffer_num(arg) < buf_num_to_use) { if (essl_spi_get_tx_buffer_num(arg) < buf_num_to_use) {
ESP_LOGV(TAG, "slave buffer: %d is not enough, %d is required", ctx->master_out.slave_rx_buf_num, ctx->master_out.sent_buf_num + buf_num_to_use); ESP_LOGV(TAG, "slave buffer: %"PRIu32" is not enough, %"PRIu32" is required", (uint32_t)ctx->master_out.slave_rx_buf_num, (uint32_t)ctx->master_out.sent_buf_num + buf_num_to_use);
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
} }
ESP_LOGV(TAG, "send_packet: size to write is: %d", size); ESP_LOGV(TAG, "send_packet: size to write is: %zu", size);
ret = essl_spi_wrdma_seg(ctx->spi, data, size, 0); ret = essl_spi_wrdma_seg(ctx->spi, data, size, 0);
if (ret != ESP_OK) { if (ret != ESP_OK) {
return ret; return ret;

View File

@@ -6,15 +6,16 @@
#pragma once #pragma once
#include "sdmmc_cmd.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
struct essl_dev_t; struct essl_dev_t;
/// Handle of an ESSL device /// Handle of an ESSL device
typedef struct essl_dev_t* essl_handle_t; typedef struct essl_dev_t *essl_handle_t;
/** /**
* @brief Initialize the slave. * @brief Initialize the slave.
@@ -219,3 +220,7 @@ esp_err_t essl_get_intr_ena(essl_handle_t handle, uint32_t *ena_mask_o, uint32_t
* - One of the error codes from SDMMC host controller * - One of the error codes from SDMMC host controller
*/ */
esp_err_t essl_send_slave_intr(essl_handle_t handle, uint32_t intr_mask, uint32_t wait_ms); esp_err_t essl_send_slave_intr(essl_handle_t handle, uint32_t intr_mask, uint32_t wait_ms);
#ifdef __cplusplus
}
#endif

View File

@@ -9,10 +9,13 @@
#pragma once #pragma once
#include "esp_err.h" #include "esp_err.h"
#include "driver/sdmmc_host.h"
#include "esp_serial_slave_link/essl.h" #include "esp_serial_slave_link/essl.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h" #ifdef __cplusplus
#include "driver/sdmmc_defs.h" extern "C" {
#endif
/// Configuration for the ESSL SDIO device /// Configuration for the ESSL SDIO device
typedef struct { typedef struct {
@@ -238,3 +241,7 @@ esp_err_t essl_sdio_send_slave_intr(void *arg, uint32_t intr_mask, uint32_t wait
void essl_sdio_reset_cnt(void *arg); void essl_sdio_reset_cnt(void *arg);
/** @endcond */ /** @endcond */
#ifdef __cplusplus
}
#endif

View File

@@ -7,12 +7,12 @@
#pragma once #pragma once
#include "esp_err.h" #include "esp_err.h"
#include "driver/spi_master.h"
#include "esp_serial_slave_link/essl.h" #include "esp_serial_slave_link/essl.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
/// Configuration of ESSL SPI device /// Configuration of ESSL SPI device

View File

@@ -103,9 +103,9 @@ INPUT = \
$(PROJECT_PATH)/components/driver/include/driver/touch_sensor_common.h \ $(PROJECT_PATH)/components/driver/include/driver/touch_sensor_common.h \
$(PROJECT_PATH)/components/driver/include/driver/twai.h \ $(PROJECT_PATH)/components/driver/include/driver/twai.h \
$(PROJECT_PATH)/components/driver/include/driver/uart.h \ $(PROJECT_PATH)/components/driver/include/driver/uart.h \
$(PROJECT_PATH)/components/driver/test/esp_serial_slave_link/include/esp_serial_slave_link/essl_sdio.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl_sdio.h \
$(PROJECT_PATH)/components/driver/test/esp_serial_slave_link/include/esp_serial_slave_link/essl_spi.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl_spi.h \
$(PROJECT_PATH)/components/driver/test/esp_serial_slave_link/include/esp_serial_slave_link/essl.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h \
$(PROJECT_PATH)/components/efuse/$(IDF_TARGET)/include/esp_efuse_chip.h \ $(PROJECT_PATH)/components/efuse/$(IDF_TARGET)/include/esp_efuse_chip.h \
$(PROJECT_PATH)/components/efuse/include/esp_efuse.h \ $(PROJECT_PATH)/components/efuse/include/esp_efuse.h \
$(PROJECT_PATH)/components/esp_adc/include/esp_adc/adc_cali_scheme.h \ $(PROJECT_PATH)/components/esp_adc/include/esp_adc/adc_cali_scheme.h \