Skip to content

Commit

Permalink
Merge branch 'bugfix/slave_sdio' into 'feature/esp_as_mcu_host'
Browse files Browse the repository at this point in the history
bugfix/slave_sdio Track number of buffers currently in Tx queue

See merge request app-frameworks/esp_hosted!499
  • Loading branch information
mantriyogesh committed Sep 11, 2024
2 parents ed6195d + e07f0a9 commit 9ba38db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions slave/main/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct hosted_mempool * hosted_mempool_create(void *pre_allocated_mem,

if (!pre_allocated_mem) {
/* no pre-allocated mem, allocate new */
heap = (uint8_t *)CALLOC( MEMPOOL_ALIGNED(OS_MEMPOOL_BYTES(
num_blocks,block_size)), 1);
heap = (uint8_t *)CALLOC(1, MEMPOOL_ALIGNED(OS_MEMPOOL_BYTES(
num_blocks,block_size)));
if (!heap) {
ESP_LOGE(TAG, "mempool create failed, no mem\n");
return NULL;
Expand All @@ -53,8 +53,8 @@ struct hosted_mempool * hosted_mempool_create(void *pre_allocated_mem,
}
}

new = (struct hosted_mempool*)CALLOC(sizeof(struct hosted_mempool), 1);
pool = (struct os_mempool *)CALLOC(sizeof(struct os_mempool), 1);
new = (struct hosted_mempool*)CALLOC(1, sizeof(struct hosted_mempool));
pool = (struct os_mempool *)CALLOC(1, sizeof(struct os_mempool));

if(!new || !pool) {
goto free_buffs;
Expand Down
21 changes: 20 additions & 1 deletion slave/main/sdio_slave_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ interface_handle_t if_handle_g;
static const char TAG[] = "SDIO_SLAVE";

#define SDIO_RX_QUEUE_SIZE CONFIG_ESP_SDIO_RX_Q_SIZE

#if !SIMPLIFIED_SDIO_SLAVE
static SemaphoreHandle_t sdio_rx_sem;
static QueueHandle_t sdio_rx_queue[MAX_PRIORITY_QUEUES];
static SemaphoreHandle_t sdio_send_queue_sem = NULL; // to count number of Tx bufs in IDF SDIO driver
#endif

#define SDIO_SLAVE_TO_HOST_INT_BIT7 7
#define SDIO_SLAVE_TO_HOST_INT_BIT6 6
Expand Down Expand Up @@ -71,8 +75,10 @@ static int32_t sdio_write(interface_handle_t *handle, interface_buffer_handle_t
static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *buf_handle);
static esp_err_t sdio_reset(interface_handle_t *handle);
static void sdio_deinit(interface_handle_t *handle);
#if !SIMPLIFIED_SDIO_SLAVE
static void sdio_rx_task(void* pvParameters);
static void sdio_tx_done_task(void* pvParameters);
#endif

if_ops_t if_ops = {
.init = sdio_init,
Expand Down Expand Up @@ -108,6 +114,7 @@ static inline void sdio_buffer_tx_free(void *buf)
hosted_mempool_free(buf_mp_tx_g, buf);
}

#if !SIMPLIFIED_SDIO_SLAVE
static void start_rx_data_throttling_if_needed(void)
{
uint32_t queue_load;
Expand Down Expand Up @@ -154,6 +161,7 @@ static void stop_rx_data_throttling_if_needed(void)
}
}
}
#endif

interface_context_t *interface_insert_driver(int (*event_handler)(uint8_t val))
{
Expand Down Expand Up @@ -252,6 +260,7 @@ void generate_startup_event(uint8_t cap, uint32_t ext_cap)
ESP_HEXLOGD("sdio_tx_init", buf_handle.payload, buf_handle.payload_len);

#if !SIMPLIFIED_SDIO_SLAVE
xSemaphoreTake(sdio_send_queue_sem, portMAX_DELAY);
ret = sdio_slave_send_queue(buf_handle.payload, buf_handle.payload_len,
buf_handle.payload, portMAX_DELAY);
#else
Expand All @@ -275,8 +284,10 @@ static void sdio_read_done(void *handle)

static interface_handle_t * sdio_init(void)
{
esp_err_t ret = ESP_OK;
#if !SIMPLIFIED_SDIO_SLAVE
uint16_t prio_q_idx = 0;
#endif
esp_err_t ret = ESP_OK;
sdio_slave_buf_handle_t handle = {0};
sdio_slave_config_t config = {
#if CONFIG_ESP_SDIO_STREAMING_MODE
Expand Down Expand Up @@ -317,6 +328,9 @@ static interface_handle_t * sdio_init(void)
#endif

#if !SIMPLIFIED_SDIO_SLAVE
sdio_send_queue_sem = xSemaphoreCreateCounting(SDIO_SLAVE_QUEUE_SIZE, SDIO_SLAVE_QUEUE_SIZE);
assert(sdio_send_queue_sem);

sdio_rx_sem = xSemaphoreCreateCounting(SDIO_RX_QUEUE_SIZE*3, 0);
assert(sdio_rx_sem != NULL);

Expand Down Expand Up @@ -391,6 +405,7 @@ static void sdio_tx_done_task(void* pvParameters)
ESP_LOGE(TAG, "sdio_slave_send_get_finished() error");
continue;
}
xSemaphoreGive(sdio_send_queue_sem);
sdio_buffer_tx_free(sendbuf_p);
}
}
Expand Down Expand Up @@ -448,6 +463,7 @@ static int32_t sdio_write(interface_handle_t *handle, interface_buffer_handle_t
ESP_HEXLOGD("sdio_tx", sendbuf, min(32,total_len));

#if !SIMPLIFIED_SDIO_SLAVE
xSemaphoreTake(sdio_send_queue_sem, portMAX_DELAY);
ret = sdio_slave_send_queue(sendbuf, total_len, sendbuf, portMAX_DELAY);
#else
ret = sdio_slave_transmit(sendbuf, total_len);
Expand Down Expand Up @@ -656,6 +672,9 @@ static esp_err_t sdio_reset(interface_handle_t *handle)
ret = sdio_slave_send_get_finished(&handle, 0);
if (ret != ESP_OK)
break;
#if !SIMPLIFIED_SDIO_SLAVE
xSemaphoreGive(sdio_send_queue_sem);
#endif

if (handle) {
ret = sdio_slave_recv_load_buf(handle);
Expand Down

0 comments on commit 9ba38db

Please sign in to comment.