mirror of
https://github.com/hathach/tinyusb.git
synced 2026-04-01 12:23:34 +00:00
net: save actual ep_size from descriptor in netd_open instead of hardcoding 64/512
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com> Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/4c20b579-db28-4643-b062-81881adcf6c1
This commit is contained in:
@ -51,6 +51,7 @@ typedef struct {
|
||||
uint8_t ep_notif;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
|
||||
|
||||
bool ecm_mode;
|
||||
|
||||
@ -176,6 +177,9 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
|
||||
// Pair of endpoints
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
|
||||
|
||||
// Save the actual bulk endpoint size (IN and OUT assumed equal)
|
||||
_netd_itf.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
|
||||
|
||||
if (_netd_itf.ecm_mode) {
|
||||
// ECM by default is in-active, save the endpoint attribute
|
||||
// to open later when received setInterface
|
||||
@ -356,8 +360,7 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
/* data transmission finished */
|
||||
if (ep_addr == _netd_itf.ep_in) {
|
||||
/* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
|
||||
uint16_t const ep_size = (tud_speed_get() == TUSB_SPEED_HIGH) ? 512 : 64;
|
||||
if (xferred_bytes && (0 == (xferred_bytes % ep_size))) {
|
||||
if (xferred_bytes && (0 == (xferred_bytes % _netd_itf.ep_size))) {
|
||||
do_in_xfer(NULL, 0); /* a ZLP is needed */
|
||||
} else {
|
||||
/* we're finally finished */
|
||||
|
||||
@ -83,6 +83,7 @@ typedef struct {
|
||||
uint8_t itf_num; // interface number
|
||||
uint8_t itf_data_alt; // ==0 -> no endpoints, i.e. no network traffic, ==1 -> normal operation with two endpoints (spec, chapter 5.3)
|
||||
uint8_t rhport; // storage of \a rhport because some callbacks are done without it
|
||||
uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
|
||||
|
||||
// recv handling
|
||||
recv_ntb_t *recv_free_ntb[RECV_NTB_N]; // free list of recv NTBs
|
||||
@ -340,7 +341,7 @@ static xmit_ntb_t *xmit_get_next_ready_ntb(void) {
|
||||
static bool xmit_insert_required_zlp(uint8_t rhport, uint32_t xferred_bytes) {
|
||||
TU_LOG_DRV("xmit_insert_required_zlp(%d,%ld)\n", rhport, xferred_bytes);
|
||||
|
||||
uint16_t const ep_size = (tud_speed_get() == TUSB_SPEED_HIGH) ? 512 : 64;
|
||||
uint16_t const ep_size = ncm_interface.ep_size;
|
||||
if (xferred_bytes == 0 || xferred_bytes % ep_size != 0) {
|
||||
return false;
|
||||
}
|
||||
@ -906,6 +907,7 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16
|
||||
// a TUSB_DESC_ENDPOINT (actually two) must follow, open these endpoints
|
||||
TU_ASSERT(tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT, 0);
|
||||
TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &ncm_interface.ep_out, &ncm_interface.ep_in));
|
||||
ncm_interface.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
|
||||
drv_len += 2 * sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
return drv_len;
|
||||
|
||||
Reference in New Issue
Block a user