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)) :\

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"
@@ -124,7 +126,9 @@ 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;
} }
@@ -137,50 +141,66 @@ esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
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;
@@ -189,13 +209,13 @@ esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
// 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);
@@ -230,7 +250,9 @@ esp_err_t essl_sdio_wait_for_ready(void *arg, uint32_t wait_ms)
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;
@@ -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);
@@ -319,7 +343,9 @@ 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;
@@ -342,10 +368,12 @@ esp_err_t essl_sdio_update_tx_buffer_num(void *arg, uint32_t wait_ms)
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) {
return err;
}
len = (len >> 16)&TX_BUFFER_MASK; 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;
} }
@@ -364,7 +392,9 @@ esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms)
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,11 +403,15 @@ 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) {
addr += 4;
}
return essl_sdio_write_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W_REG(addr), value, value_o); return essl_sdio_write_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W_REG(addr), value, value_o);
} }
@@ -385,17 +419,21 @@ esp_err_t essl_sdio_read_reg(void *arg, uint8_t add, uint8_t *value_o, uint32_t
{ {
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) {
add += 4;
}
esp_err_t ret = essl_sdio_read_byte(((essl_sdio_context_t *)arg)->card, HOST_SLCHOST_CONF_W_REG(add), 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: %08X", *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);
} }
@@ -404,22 +442,28 @@ esp_err_t essl_sdio_get_intr(void *arg, uint32_t *intr_raw, uint32_t *intr_st, u
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);
} }
@@ -429,14 +473,15 @@ esp_err_t essl_sdio_get_intr_ena(void *arg, uint32_t *ena_mask_o, uint32_t wait_
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)

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.
*/ */
@@ -192,7 +194,9 @@ esp_err_t essl_spi_rddma(spi_device_handle_t spi, uint8_t *out_data, int len, in
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;
@@ -234,7 +238,9 @@ esp_err_t essl_spi_wrdma(spi_device_handle_t spi, const uint8_t *data, int len,
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,11 +6,12 @@
#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
@@ -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 \