esp32c3 tcp的发送速度很慢
Posted: Sat Mar 16, 2024 9:16 am
我现在使用esp32c3的ap模式,通过spi口接收数据,然后把数据通过wifi tcp连接发送给电脑,我使用examples/wifi/iperf例子测速发现速度可以达到15Mbits/sec。我从spi口接收数据后直接放到Ringbuffer中,然后在另一个线程中读Ringbuffer通过wifi发送,但spi接收速度最高只能120KByte/sec,否则Ringbuffer会爆。我按文档(https://docs.espressif.com/projects/esp ... erformance)中说的修改过一些参数,但完全没有作用,下面的我的代码,请帮我看下有没有问题。谢谢
Code: Select all
void spi_slave_task(void *pvParameters)
{
esp_err_t ret;
spi_slave_transaction_t t;
memset(&t, 0, sizeof(t));
uint8_t *recvbuf = (uint8_t *)malloc(SPI_RX_MAX * sizeof(uint8_t));
if(recvbuf == NULL)
{
ESP_LOGE(SPI_SLAVE, "Receive buffer memory allocation failed!");
return;
}
while(1) {
memset(recvbuf, 0x00, SPI_RX_MAX);
//Set up a transaction of 128 bytes to send/receive
t.length=SPI_RX_MAX*8;
t.rx_buffer=recvbuf;
ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
UBaseType_t res = xRingbufferSend(buf_handle, recvbuf, t.trans_len/8, pdMS_TO_TICKS(10));
if (res != pdTRUE) {
ESP_LOGE(SPI_SLAVE, "Failed to send item\n");
}
}
}
void wifi_send_task(void *pvParameters)
{
while(1) {
size_t item_size;
char *item = (char *)xRingbufferReceiveUpTo(buf_handle, &item_size, pdMS_TO_TICKS(10), SPI_RX_MAX*2);
if (item != NULL) {
// 如果网络连接,通过网络发送数
if(tcp_is_connect == true) {
int written = send(tcp_sock, item, item_size, 0);
if (written < 0) {
ESP_LOGE(SPI_SLAVE, "Error occurred during sending: errno %d", errno);
}
}
vRingbufferReturnItem(buf_handle, (void *)item);
}
}
}
void spi_slave_task_init(void)
{
buf_handle = xRingbufferCreate(64*1024, RINGBUF_TYPE_BYTEBUF);
if (buf_handle == NULL) {
ESP_LOGE(SPI_SLAVE, "Failed to create ring buffer\n");
}
spi_slave_init();
xTaskCreate(spi_slave_task, "spi_slave", 2048, NULL, 5, NULL);
xTaskCreate(wifi_send_task, "wifi_send", 2048, NULL, 6, NULL);
}