Do some have experience or knowledge within this ?
Here are some of the transmit and recieve in the USB part :
Code: Select all
bool tud_network_recv_cb(const uint8_t *src, uint16_t size) {
if (src == NULL) {
ESP_LOGE(TAG, "Invalid source pointer");
return false;
}
if (size == 0) {
ESP_LOGE(TAG, "Invalid data size: %d", size);
return false;
}
if (tud_rx_len < 1) {
memcpy(tud_rx_buf, src, size);
tud_rx_len = size; //set tud_rx_len ONLY after finish copying
// "Give" the semaphore, signalling that data was received:
xSemaphoreGive(tud_data_recd_sem);
return true;
}else{
//unable to receive, busy
ESP_LOGW(TAG, "tud_network_recv_cb busy.");
return false;
}
}
Code: Select all
static void task(void *arg){
esp_netif_t *netif = (esp_netif_t *) arg;
size_t hs;
while(1){
/* Try and "take" the semaphore. This task will "sleep" until either the
semaphore is "given" by another task/ISR or the timeout (e.g. 10000ms) elapses. */
if ( xSemaphoreTake(tud_data_recd_sem, 10000 / portTICK_PERIOD_MS) == pdTRUE ) {
// Data was received!
if (tud_rx_len > 0){
esp_netif_receive(netif, tud_rx_buf, tud_rx_len, NULL);
//ESP_LOGI(TAG,"%x, %x, %x, %x, %x, %x, %x, %x",tud_rx_buf[0],tud_rx_buf[1],tud_rx_buf[2],tud_rx_buf[3],tud_rx_buf[4], tud_rx_buf[5], tud_rx_buf[6], tud_rx_buf[7]);
tud_network_recv_renew();
tud_rx_len = 0; //indicate buf is now read
hs = xPortGetFreeHeapSize();
//ESP_LOGI(TAG, "rx heap check (%u).", hs);
}
} else {
// Semaphore take timed out after 10000ms, i.e. no data received within 10000ms. Do we care?
ESP_LOGI(TAG, "no data received in the last 10s, will continue to wait.");
}
}
}
Code: Select all
static esp_err_t netsuite_io_transmit(void *h, void *buffer, size_t len) {
for (;;) {
if (!tud_ready()) {
return ESP_FAIL;
}
if (tud_network_can_xmit()) {
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p) {
memcpy(p->payload, buffer, len);
tud_network_xmit(p, 0);
pbuf_free(p);
return ESP_OK;
} else {
return ESP_FAIL;
}
}
}
}