Skip to content

Commit d24830e

Browse files
committed
Merge branch 'feat/improve_raw_tp' into 'feature/esp_as_mcu_host'
feat/improve_raw_tp Improve SDIO raw throughput by doing only block transfers See merge request app-frameworks/esp_hosted!485
2 parents 6cd21f8 + 8b1e926 commit d24830e

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ ESP32XX_SPI_CLK_FREQ_RANGE_MAX := 40
359359

360360
choice ESP_SDIO_RX_OPTIMIZATION
361361
bool "SDIO Receive Optimization"
362-
default ESP_SDIO_OPTIMIZATION_RX_NONE
362+
default ESP_SDIO_OPTIMIZATION_RX_STREAMING_MODE
363363

364364
config ESP_SDIO_OPTIMIZATION_RX_NONE
365365
bool "No optimization"

host/drivers/transport/sdio/sdio_drv.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,20 @@ static void sdio_write_task(void const* pvParameters)
363363
do {
364364
len_to_send = data_left;
365365

366+
#if H_SDIO_TX_BLOCK_ONLY_XFER
367+
/* Extend the transfer length to do block only transfers.
368+
* This is safe as slave only reads up to data_left, which
369+
* is not changed here. Rest of data is discarded by
370+
* slave.
371+
*/
372+
uint32_t block_send_len = ((len_to_send + ESP_BLOCK_SIZE - 1) / ESP_BLOCK_SIZE) * ESP_BLOCK_SIZE;
373+
374+
ret = g_h.funcs->_h_sdio_write_block(ESP_SLAVE_CMD53_END_ADDR - data_left,
375+
pos, block_send_len, ACQUIRE_LOCK);
376+
#else
366377
ret = g_h.funcs->_h_sdio_write_block(ESP_SLAVE_CMD53_END_ADDR - data_left,
367378
pos, len_to_send, ACQUIRE_LOCK);
379+
#endif
368380
if (ret) {
369381
ESP_LOGE(TAG, "%s: %d: Failed to send data: %d %ld %ld", __func__,
370382
retries, ret, len_to_send, data_left);
@@ -535,6 +547,11 @@ static esp_err_t sdio_push_data_to_queue(uint8_t * buf, uint32_t buf_len)
535547
// return a buffer big enough to contain the data
536548
static uint8_t * sdio_rx_get_buffer(uint32_t len)
537549
{
550+
#if H_SDIO_RX_BLOCK_ONLY_XFER
551+
// we need to allocate enough memory to hold the padded data
552+
len = ((len + ESP_BLOCK_SIZE - 1) / ESP_BLOCK_SIZE) * ESP_BLOCK_SIZE;
553+
#endif
554+
538555
// (re)allocate a buffer big enough to contain the data stream
539556
if (len > recv_buf_size) {
540557
if (recv_buf) {
@@ -703,9 +720,20 @@ static void sdio_read_task(void const* pvParameters)
703720
do {
704721
len_to_read = data_left;
705722

723+
#if H_SDIO_RX_BLOCK_ONLY_XFER
724+
/* Extend the transfer length to do block only transfers.
725+
* This is safe as slave will pad data with 0, which we
726+
* will ignore.
727+
*/
728+
uint32_t block_read_len = ((len_to_read + ESP_BLOCK_SIZE - 1) / ESP_BLOCK_SIZE) * ESP_BLOCK_SIZE;
729+
ret = g_h.funcs->_h_sdio_read_block(
730+
ESP_SLAVE_CMD53_END_ADDR - data_left,
731+
pos, block_read_len, ACQUIRE_LOCK);
732+
#else
706733
ret = g_h.funcs->_h_sdio_read_block(
707734
ESP_SLAVE_CMD53_END_ADDR - data_left,
708735
pos, len_to_read, ACQUIRE_LOCK);
736+
#endif
709737
if (ret) {
710738
ESP_LOGE(TAG, "%s: Failed to read data - %d %ld %ld",
711739
__func__, ret, len_to_read, data_left);

host/port/esp_hosted_config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ so feel free to change these if needed.
142142
#define H_SDIO_TX_LEN_TO_TRANSFER(x) ((x + 3) & (~3))
143143
#define H_SDIO_RX_LEN_TO_TRANSFER(x) ((x + 3) & (~3))
144144

145+
/* Do Block Mode only transfers
146+
*
147+
* When enabled, SDIO only uses block mode transfers for higher
148+
* throughput. Data lengths are padded to multiples of ESP_BLOCK_SIZE.
149+
*
150+
* This is safe for the SDIO slave:
151+
* - for Host Tx: slave will ignore extra data sent by Host
152+
* - for Host Rx: slave will send extra 0 data, ignored by Host
153+
*/
154+
#define H_SDIO_TX_BLOCK_ONLY_XFER (1)
155+
#define H_SDIO_RX_BLOCK_ONLY_XFER (1)
156+
145157
// workarounds for some SDIO transfer errors that may occur
146158
#if 0
147159
/* Below workarounds could be enabled for non-ESP MCUs to test first

slave/main/Kconfig.projbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ menu "Example Configuration"
240240

241241
config ESP_SDIO_STREAMING_MODE
242242
bool "Enable SDIO Streaming Mode"
243-
default n
243+
default y
244244
help
245245
Enable Streaming Mode. Host to receive queued data from slave
246246
as one stream instead of individual packets. This can improve
@@ -545,7 +545,7 @@ menu "Example Configuration"
545545
config ESP_RAW_TP_REPORT_INTERVAL
546546
depends on ESP_RAW_THROUGHPUT_TRANSPORT
547547
int "RawTP: periodic duration to report stats accumulated"
548-
default 1
548+
default 10
549549

550550
config ESP_PKT_STATS
551551
bool "Transport level packet stats"

slave/main/app_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ void app_main()
926926

927927
while (1) {
928928
MEM_DUMP("mem_dump");
929-
sleep(2);
929+
sleep(10);
930930
}
931931

932932
}

slave/main/stats.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ static void stats_timer_func(void* arg)
196196
double actual_bandwidth_tx = 0;
197197
int32_t div = 1024;
198198

199-
actual_bandwidth_tx = (test_raw_tp_tx_len*8);
200-
actual_bandwidth_rx = (test_raw_tp_rx_len*8);
199+
actual_bandwidth_tx = (test_raw_tp_tx_len*8)/TEST_RAW_TP__TIMEOUT;
200+
actual_bandwidth_rx = (test_raw_tp_rx_len*8)/TEST_RAW_TP__TIMEOUT;
201201
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
202-
ESP_LOGI(TAG,"%lu-%lu sec Rx: %.2f Tx: %.2f kbps", cur, cur + 1, actual_bandwidth_rx/div, actual_bandwidth_tx/div);
202+
ESP_LOGI(TAG,"%lu-%lu sec Rx: %.2f Tx: %.2f kbps", cur, cur + TEST_RAW_TP__TIMEOUT, actual_bandwidth_rx/div, actual_bandwidth_tx/div);
203203
#else
204-
ESP_LOGI(TAG,"%u-%u sec Rx: %.2f Tx: %.2f kbps", cur, cur + 1, actual_bandwidth_rx/div, actual_bandwidth_tx/div);
204+
ESP_LOGI(TAG,"%u-%u sec Rx: %.2f Tx: %.2f kbps", cur, cur + TEST_RAW_TP__TIMEOUT, actual_bandwidth_rx/div, actual_bandwidth_tx/div);
205205
#endif
206-
cur++;
206+
cur += TEST_RAW_TP__TIMEOUT;
207207
test_raw_tp_rx_len = test_raw_tp_tx_len = 0;
208208
#endif
209209
#if ESP_PKT_STATS
@@ -239,7 +239,6 @@ static void start_timer_to_display_stats(int periodic_time_sec)
239239
void process_test_capabilities(uint8_t capabilities)
240240
{
241241
ESP_LOGD(TAG, "capabilites: %d", capabilities);
242-
start_timer_to_display_stats(TEST_RAW_TP__TIMEOUT);
243242
if ((capabilities & ESP_TEST_RAW_TP__ESP_TO_HOST) ||
244243
(capabilities & ESP_TEST_RAW_TP__BIDIRECTIONAL)) {
245244
assert(xTaskCreate(raw_tp_tx_task , "raw_tp_tx_task",
@@ -257,7 +256,7 @@ void create_debugging_tasks(void)
257256
CONFIG_ESP_DEFAULT_TASK_PRIO, NULL) == pdTRUE);
258257
#endif
259258

260-
#if ESP_PKT_STATS
259+
#if TEST_RAW_TP || ESP_PKT_STATS
261260
start_timer_to_display_stats(ESP_PKT_STATS_REPORT_INTERVAL);
262261
#endif
263262
}

0 commit comments

Comments
 (0)