Skip to content

Commit f11ff03

Browse files
committed
feat: Add net xmit status cb for application can block to get it
Current poll mode speed down net throughput, we can add a api for xmitting status cb, application can be blocked to wait usb idle.
1 parent 8d97f0e commit f11ff03

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/class/net/net_device.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ void tud_network_recv_renew(void)
114114
static void do_in_xfer(uint8_t *buf, uint16_t len)
115115
{
116116
can_xmit = false;
117+
118+
if (tud_network_idle_status_change_cb) {
119+
tud_network_idle_status_change_cb(can_xmit);
120+
}
121+
117122
usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_in, buf, len);
118123
}
119124

@@ -212,6 +217,9 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
212217

213218
// we are ready to transmit a packet
214219
can_xmit = true;
220+
if (tud_network_idle_status_change_cb) {
221+
tud_network_idle_status_change_cb(can_xmit);
222+
}
215223

216224
// prepare for incoming packets
217225
tud_network_recv_renew();
@@ -276,6 +284,9 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
276284
// Also should have opposite callback for application to disable network !!
277285
tud_network_init_cb();
278286
can_xmit = true; // we are ready to transmit a packet
287+
if (tud_network_idle_status_change_cb) {
288+
tud_network_idle_status_change_cb(can_xmit);
289+
}
279290
tud_network_recv_renew(); // prepare for incoming packets
280291
}
281292
}else
@@ -396,6 +407,9 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
396407
{
397408
/* we're finally finished */
398409
can_xmit = true;
410+
if (tud_network_idle_status_change_cb) {
411+
tud_network_idle_status_change_cb(can_xmit);
412+
}
399413
}
400414
}
401415

src/class/net/net_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
//--------------------------------------------------------------------+
4646
// Application API
4747
//--------------------------------------------------------------------+
48+
TU_ATTR_WEAK void tud_network_idle_status_change_cb(bool idle);
4849

4950
// client must provide this: initialize any network state back to the beginning
5051
void tud_network_init_cb(void);

0 commit comments

Comments
 (0)