+ usb_add_status_handler_end :
+ usb_status_handler_end;
+ }
+}
+
+static bool rx_done;
+static size_t rx_size;
+
+static void usb_endpointRead_complete(int ep)
+{
+ if (UNLIKELY(ep >= ENP_MAX_NUMB))
+ {
+ ASSERT(0);
+ return;
+ }
+ ASSERT(!(ep & 0x01));
+
+ rx_done = true;
+ rx_size = ep_cnfg[ep].size;
+}
+
+ssize_t usb_endpointRead(int ep, void *buffer, ssize_t size)
+{
+ int ep_num = usb_ep_logical_to_hw(ep);
+
+ /* Non-blocking read for EP0 */
+ if (ep_num == CTRL_ENP_OUT)
+ {
+ size = usb_size(size, usb_le16_to_cpu(setup_packet.wLength));
+ if (!size)
+ usb_status_handler(ep_num);
+ else
+ __usb_ep_read(ep_num, buffer, size,
+ usb_status_handler);
+ return size;
+ }
+ if (UNLIKELY(!size))
+ return 0;
+ size = MIN(size, USB_RX_MAX_SIZE);
+ rx_done = false;
+ rx_size = 0;
+
+ /* Blocking read */
+ __usb_ep_read(ep_num, buffer, size, usb_endpointRead_complete);
+ while (!rx_done)
+ cpu_relax();
+
+ return rx_size;
+}
+
+static bool tx_done;
+static size_t tx_size;
+
+static void usb_endpointWrite_complete(int ep)
+{
+ if (UNLIKELY(ep >= ENP_MAX_NUMB))
+ {
+ ASSERT(0);
+ return;