Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WiFi packet flow control #455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions esp_hosted_fg/esp/esp_driver/network_adapter/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ interface_handle_t *if_handle = NULL;
static QueueHandle_t meta_to_host_queue = NULL;
static QueueHandle_t to_host_queue[MAX_PRIORITY_QUEUES] = {NULL};

#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
static interface_buffer_handle_t s_wifi_tx_buffer_handle[BUFFER_NUM];
#endif


static protocomm_t *pc_pserial;

Expand Down Expand Up @@ -369,7 +373,7 @@ void process_serial_rx_pkt(uint8_t *buf)
}
}

void process_rx_pkt(interface_buffer_handle_t *buf_handle)
int process_rx_pkt(interface_buffer_handle_t *buf_handle)
{
struct esp_payload_header *header = NULL;
uint8_t *payload = NULL;
Expand All @@ -385,6 +389,11 @@ void process_rx_pkt(interface_buffer_handle_t *buf_handle)

if ((buf_handle->if_type == ESP_STA_IF) && station_connected) {
/* Forward data to wlan driver */
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
if (esp_wifi_internal_tx(ESP_IF_WIFI_STA, payload, payload_len) == ESP_ERR_NO_MEM) {
ret = ESP_FAIL;
}
#else
int retry = 6;

do {
Expand All @@ -399,10 +408,17 @@ void process_rx_pkt(interface_buffer_handle_t *buf_handle)
}

} while (ret && retry);
#endif
/*ESP_LOG_BUFFER_HEXDUMP("spi_sta_rx", payload, payload_len, ESP_LOG_INFO);*/
} else if (buf_handle->if_type == ESP_AP_IF && softap_started) {
/* Forward data to wlan driver */
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
if (esp_wifi_internal_tx(ESP_IF_WIFI_AP, payload, payload_len) == ESP_ERR_NO_MEM) {
ret = ESP_FAIL;
}
#else
esp_wifi_internal_tx(ESP_IF_WIFI_AP, payload, payload_len);
#endif
} else if (buf_handle->if_type == ESP_SERIAL_IF) {
process_serial_rx_pkt(buf_handle->payload);
}
Expand All @@ -418,17 +434,32 @@ void process_rx_pkt(interface_buffer_handle_t *buf_handle)
#endif

/* Free buffer handle */
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
if (ret == ESP_OK && buf_handle->free_buf_handle && buf_handle->priv_buffer_handle) {
buf_handle->free_buf_handle(buf_handle->priv_buffer_handle);
buf_handle->priv_buffer_handle = NULL;
}
return ret;
#else
if (buf_handle->free_buf_handle && buf_handle->priv_buffer_handle) {
buf_handle->free_buf_handle(buf_handle->priv_buffer_handle);
buf_handle->priv_buffer_handle = NULL;
}
return 0;
#endif
}

/* Get data from host */
void recv_task(void* pvParameters)
{
interface_buffer_handle_t buf_handle = {0};

#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
memset(s_wifi_tx_buffer_handle, 0, sizeof(s_wifi_tx_buffer_handle));
uint32_t start_index = 0;
uint32_t store_num = 0;
#endif

for (;;) {

if (!datapath) {
Expand All @@ -439,14 +470,39 @@ void recv_task(void* pvParameters)

/* receive data from transport layer */
if (if_context && if_context->if_ops && if_context->if_ops->read) {
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
TickType_t wait_tick = store_num ? 1 : portMAX_DELAY;
int len = if_context->if_ops->read(if_handle, &buf_handle, wait_tick);
while (store_num) {
if (process_rx_pkt(&s_wifi_tx_buffer_handle[start_index]) != ESP_OK) {
break;
}
start_index++;
store_num--;
if (start_index >= BUFFER_NUM) {
start_index = 0;
}
}
#else
int len = if_context->if_ops->read(if_handle, &buf_handle);
#endif
if (len <= 0) {
usleep(10*1000);
continue;
}
}

#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
if (process_rx_pkt(&buf_handle) != ESP_OK) {
uint32_t end_index = start_index + store_num;
if (end_index >= BUFFER_NUM) {
end_index -= BUFFER_NUM;
}
s_wifi_tx_buffer_handle[end_index] = buf_handle;
store_num++;
}
#else
process_rx_pkt(&buf_handle);
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions esp_hosted_fg/esp/esp_driver/network_adapter/main/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#error "SDIO is not supported for this chipset"
#endif

#include "sdio_slave_api.h"

#endif

typedef enum {
Expand Down Expand Up @@ -78,7 +80,11 @@ typedef struct {
typedef struct {
interface_handle_t * (*init)(void);
int32_t (*write)(interface_handle_t *handle, interface_buffer_handle_t *buf_handle);
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
int (*read)(interface_handle_t *handle, interface_buffer_handle_t *buf_handle, TickType_t wait);
#else
int (*read)(interface_handle_t *handle, interface_buffer_handle_t *buf_handle);
#endif
esp_err_t (*reset)(interface_handle_t *handle);
void (*deinit)(interface_handle_t *handle);
} if_ops_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#define SDIO_SLAVE_QUEUE_SIZE 20
#define BUFFER_SIZE 1536 /* 512*3 */
#define BUFFER_NUM 10

static uint8_t sdio_slave_rx_buffer[BUFFER_NUM][BUFFER_SIZE];

#define SDIO_MEMPOOL_NUM_BLOCKS 40
Expand All @@ -43,7 +43,7 @@ static const char TAG[] = "SDIO_SLAVE";

static interface_handle_t * sdio_init(void);
static int32_t sdio_write(interface_handle_t *handle, interface_buffer_handle_t *buf_handle);
static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *buf_handle);
static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *buf_handle, TickType_t wait);
static esp_err_t sdio_reset(interface_handle_t *handle);
static void sdio_deinit(interface_handle_t *handle);

Expand Down Expand Up @@ -339,7 +339,7 @@ static int32_t sdio_write(interface_handle_t *handle, interface_buffer_handle_t
return buf_handle->payload_len;
}

static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *buf_handle)
static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *buf_handle, TickType_t wait)
{
esp_err_t ret = ESP_OK;
struct esp_payload_header *header = NULL;
Expand All @@ -359,7 +359,7 @@ static int sdio_read(interface_handle_t *if_handle, interface_buffer_handle_t *b
return ESP_FAIL;

ret = sdio_slave_recv(&(buf_handle->sdio_buf_handle), &(buf_handle->payload),
&(sdio_read_len), portMAX_DELAY);
&(sdio_read_len), wait);
if (ret) {
ESP_LOGD(TAG, "sdio_slave_recv returned failure");
return ESP_FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
#error "SDIO is not supported for ESP32S2. Please use SPI"
#endif

#define BUFFER_NUM 10

#endif
Loading