summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
author54fire <[email protected]>2026-08-17 14:48:32 +0800
committerGitHub <[email protected]>2026-08-17 14:48:32 +0800
commit60911ffd9ed6aaacf768dfd557508d0b40170664 (patch)
tree7e38cdec71f07b3afc42d206585ba4809d522516 /common
parent1bfc83ad46301553c8b626446417273b18abca6e (diff)
feat(class/cdc/usbd_ncm): 添加usb device ncm功能 (#433)
* 添加usb device ncm功能 * fix(class/cdc/usbd_ncm): address review findings - fix compile failure when CONFIG_USBDEV_CDC_NCM_USING_LWIP is disabled - fix GET/SET_NTB_INPUT_SIZE operating on the OUT direction size, and honor the negotiated IN limit in the transmit path - set tx busy flag before submitting the transfer to avoid a race that could block transmit permanently - follow the ndp chain via wNextNdpIndex so chained datagrams are not dropped, and access ntb fields with LE helpers instead of assuming a little-endian target - reject oversized frames instead of transmitting truncated ones - register endpoints only once when initializing both interfaces - wait for tx completion with a timeout in the demo instead of an unbounded busy wait - make usbd_cdc_ncm.h self-contained Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Diffstat (limited to 'common')
-rw-r--r--common/usb_util.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/common/usb_util.h b/common/usb_util.h
index 521bf27f..97e0917c 100644
--- a/common/usb_util.h
+++ b/common/usb_util.h
@@ -185,6 +185,26 @@
(field)[3] = (uint8_t)((value) >> 0); \
} while (0)
+#define GET_LE16(field) \
+ (((uint16_t)(field)[0] << 0) | ((uint16_t)(field)[1] << 8))
+
+#define GET_LE32(field) \
+ (((uint32_t)(field)[0] << 0) | ((uint32_t)(field)[1] << 8) | ((uint32_t)(field)[2] << 16) | ((uint32_t)(field)[3] << 24))
+
+#define SET_LE16(field, value) \
+ do { \
+ (field)[0] = (uint8_t)((value) >> 0); \
+ (field)[1] = (uint8_t)((value) >> 8); \
+ } while (0)
+
+#define SET_LE32(field, value) \
+ do { \
+ (field)[0] = (uint8_t)((value) >> 0); \
+ (field)[1] = (uint8_t)((value) >> 8); \
+ (field)[2] = (uint8_t)((value) >> 16); \
+ (field)[3] = (uint8_t)((value) >> 24); \
+ } while (0)
+
#define WBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF)
#define DBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF), (((x) >> 16) & 0xFF), (((x) >> 24) & 0xFF)