cpu/esp32: local buffer in send of esp_wifi
Instead of having a send buffer as member `esp_wifi` netdev, a local variable is used now as send buffer. This avoids the need for a locking mechanism and reduces the risk of deadlocks.
This commit is contained in:
parent
74cbc410b7
commit
3d5ef14650
@ -354,49 +354,44 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist)
|
|||||||
assert(netdev != NULL);
|
assert(netdev != NULL);
|
||||||
assert(iolist != NULL);
|
assert(iolist != NULL);
|
||||||
|
|
||||||
esp_wifi_netdev_t* dev = (esp_wifi_netdev_t*)netdev;
|
|
||||||
|
|
||||||
if (!_esp_wifi_dev.connected) {
|
if (!_esp_wifi_dev.connected) {
|
||||||
ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send");
|
ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send");
|
||||||
return -ENODEV;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&dev->dev_lock);
|
uint16_t tx_len = 0; /**< number of bytes in transmit buffer */
|
||||||
|
uint8_t tx_buf[ETHERNET_MAX_LEN]; /**< transmit buffer */
|
||||||
dev->tx_len = 0;
|
|
||||||
|
|
||||||
/* load packet data into TX buffer */
|
/* load packet data into TX buffer */
|
||||||
for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
|
for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
|
||||||
if (dev->tx_len + iol->iol_len > ETHERNET_MAX_LEN) {
|
if (tx_len + iol->iol_len > ETHERNET_MAX_LEN) {
|
||||||
mutex_unlock(&dev->dev_lock);
|
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
}
|
}
|
||||||
if (iol->iol_len) {
|
if (iol->iol_len) {
|
||||||
memcpy (dev->tx_buf + dev->tx_len, iol->iol_base, iol->iol_len);
|
memcpy (tx_buf + tx_len, iol->iol_base, iol->iol_len);
|
||||||
dev->tx_len += iol->iol_len;
|
tx_len += iol->iol_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
printf ("%s: send %d byte\n", __func__, dev->tx_len);
|
const ethernet_hdr_t* hdr = (const ethernet_hdr_t *)tx_buf;
|
||||||
/* esp_hexdump (dev->tx_buf, dev->tx_len, 'b', 16); */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int ret = 0;
|
ESP_WIFI_DEBUG("send %u byte to " MAC_STR,
|
||||||
|
(unsigned)tx_len, MAC_STR_ARG(hdr->dst));
|
||||||
|
#if MODULE_OD
|
||||||
|
od_hex_dump(tx_buf, tx_len, OD_WIDTH_DEFAULT);
|
||||||
|
#endif /* MODULE_OD */
|
||||||
|
#endif /* ENABLE_DEBUG */
|
||||||
|
|
||||||
/* send the the packet to the peer(s) mac address */
|
/* send the the packet to the peer(s) mac address */
|
||||||
if (esp_wifi_internal_tx(ESP_IF_WIFI_STA, dev->tx_buf, dev->tx_len) == ESP_OK) {
|
if (esp_wifi_internal_tx(ESP_IF_WIFI_STA, tx_buf, tx_len) == ESP_OK) {
|
||||||
ret = dev->tx_len;
|
|
||||||
netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
|
netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
|
||||||
|
return tx_len;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_WIFI_DEBUG("sending WiFi packet failed");
|
ESP_WIFI_DEBUG("sending WiFi packet failed");
|
||||||
ret = -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&dev->dev_lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _esp_wifi_recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
static int _esp_wifi_recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user