Browse Source

add usb errno, do not use system errno

sakumisu 2 years ago
parent
commit
14f1f597f1

+ 7 - 7
class/audio/usbh_audio.c

@@ -62,7 +62,7 @@ int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t s
     uint8_t altsetting = 1;
 
     if (audio_class->is_opened) {
-        return -EMFILE;
+        return 0;
     }
 
     for (uint8_t i = 0; i < audio_class->module_num; i++) {
@@ -79,7 +79,7 @@ int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t s
         }
     }
 
-    return -ENODEV;
+    return -USB_ERR_NODEV;
 
 freq_found:
 
@@ -138,7 +138,7 @@ int usbh_audio_close(struct usbh_audio *audio_class, const char *name)
     }
 
     if (intf == 0xff) {
-        return -ENODEV;
+        return -USB_ERR_NODEV;
     }
 
     USB_LOG_INFO("Close audio module :%s\r\n", name);
@@ -182,7 +182,7 @@ int usbh_audio_set_volume(struct usbh_audio *audio_class, const char *name, uint
     }
 
     if (intf == 0xff) {
-        return -ENODEV;
+        return -USB_ERR_NODEV;
     }
 
     setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
@@ -214,7 +214,7 @@ int usbh_audio_set_mute(struct usbh_audio *audio_class, const char *name, uint8_
     }
 
     if (intf == 0xff) {
-        return -ENODEV;
+        return -USB_ERR_NODEV;
     }
 
     setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
@@ -275,7 +275,7 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_audio *audio_class = usbh_audio_class_alloc();
     if (audio_class == NULL) {
         USB_LOG_ERR("Fail to alloc audio_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     audio_class->hport = hport;
@@ -384,7 +384,7 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
     }
 
     if ((input_offset != output_offset) && (input_offset != feature_unit_offset) && (input_offset != format_offset)) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     audio_class->module_num = input_offset;

+ 1 - 1
class/cdc/usbd_cdc_ecm.c

@@ -186,7 +186,7 @@ int usbd_cdc_ecm_eth_tx(struct pbuf *p)
     uint8_t *buffer;
 
     if (g_cdc_ecm_tx_data_length > 0) {
-        return -EBUSY;
+        return -USB_ERR_BUSY;
     }
 
     if (p->tot_len > sizeof(g_cdc_ecm_tx_buffer)) {

+ 1 - 1
class/cdc/usbh_cdc_acm.c

@@ -96,7 +96,7 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_cdc_acm *cdc_acm_class = usbh_cdc_acm_class_alloc();
     if (cdc_acm_class == NULL) {
         USB_LOG_ERR("Fail to alloc cdc_acm_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     cdc_acm_class->hport = hport;

+ 1 - 1
class/hid/usbh_hid.c

@@ -110,7 +110,7 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_hid *hid_class = usbh_hid_class_alloc();
     if (hid_class == NULL) {
         USB_LOG_ERR("Fail to alloc hid_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     hid_class->hport = hport;

+ 1 - 1
class/hub/usbh_hub.c

@@ -333,7 +333,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_hub *hub = usbh_hub_class_alloc();
     if (hub == NULL) {
         USB_LOG_ERR("Fail to alloc hub_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     hub->hub_addr = hport->dev_addr;

+ 6 - 5
class/msc/usbh_msc.c

@@ -155,12 +155,12 @@ static int usbh_bulk_cbw_csw_xfer(struct usbh_msc *msc_class, struct CBW *cbw, s
     /* check csw status */
     if (csw->dSignature != MSC_CSW_Signature) {
         USB_LOG_ERR("csw signature error\r\n");
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     if (csw->bStatus != 0) {
         USB_LOG_ERR("csw bStatus %d\r\n", csw->bStatus);
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 __err_exit:
     return nbytes < 0 ? (int)nbytes : 0;
@@ -255,7 +255,7 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_msc *msc_class = usbh_msc_class_alloc();
     if (msc_class == NULL) {
         USB_LOG_ERR("Fail to alloc msc_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     msc_class->hport = hport;
@@ -283,13 +283,14 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
         uint8_t num = 0;
         while (1) {
             config = &g_msc_modeswitch_config[num];
-            if (config) {
+            if (config && config->name) {
                 if ((hport->device_desc.idVendor == config->vid) &&
                     (hport->device_desc.idProduct == config->pid)) {
                     USB_LOG_INFO("%s usb_modeswitch enable\r\n", config->name);
                     usbh_msc_modeswitch(msc_class, config->message_content);
                     return 0;
                 }
+                num++;
             } else {
                 break;
             }
@@ -321,7 +322,7 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
         USB_LOG_INFO("Block num:%d,block size:%d\r\n", (unsigned int)msc_class->blocknum, (unsigned int)msc_class->blocksize);
     } else {
         USB_LOG_ERR("Invalid block size\r\n");
-        return -ERANGE;
+        return -USB_ERR_RANGE;
     }
 
     snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, msc_class->sdchar);

+ 4 - 4
class/video/usbh_video.c

@@ -143,7 +143,7 @@ int usbh_video_open(struct usbh_video *video_class,
     uint8_t step;
 
     if (video_class->is_opened) {
-        return -EMFILE;
+        return 0;
     }
 
     for (uint8_t i = 0; i < video_class->num_of_formats; i++) {
@@ -161,11 +161,11 @@ int usbh_video_open(struct usbh_video *video_class,
     }
 
     if (found == false) {
-        return -ENODEV;
+        return -USB_ERR_NODEV;
     }
 
     if (altsetting > (video_class->num_of_intf_altsettings - 1)) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     /* Open video step:
@@ -348,7 +348,7 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
     struct usbh_video *video_class = usbh_video_class_alloc();
     if (video_class == NULL) {
         USB_LOG_ERR("Fail to alloc video_class\r\n");
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     video_class->hport = hport;

+ 1 - 1
class/wireless/usbd_rndis.c

@@ -512,7 +512,7 @@ int usbd_rndis_eth_tx(struct pbuf *p)
     }
 
     if (g_rndis_tx_data_length > 0) {
-        return -EBUSY;
+        return -USB_ERR_BUSY;
     }
 
     if (p->tot_len > sizeof(g_rndis_tx_buffer)) {

+ 20 - 316
common/usb_errno.h

@@ -1,320 +1,24 @@
 /*
- * Apache NuttX
- * Copyright 2020 The Apache Software Foundation
+ * Copyright (c) 2023, sakumisu
  *
  * SPDX-License-Identifier: Apache-2.0
  */
-#ifndef __INCLUDE_ERRNO_H
-#define __INCLUDE_ERRNO_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Convenience/compatibility definition.  If the errno is accessed from the
- * internal OS code, then the OS code should use the set_errno() and
- * get_errno().  Currently, those are just placeholders but would be needed
- * in the KERNEL mode build in order to instantiate the process address
- * environment as necessary to access the TLS-based errno variable.
- */
-
-/* Definitions of error numbers and the string that would be
- * returned by strerror().
- */
-#ifndef CONFIG_USB_ERROR_USE_SYSTEM
-
-#define EPERM               1
-#define EPERM_STR           "Operation not permitted"
-#define ENOENT              2
-#define ENOENT_STR          "No such file or directory"
-#define ESRCH               3
-#define ESRCH_STR           "No such process"
-#define EINTR               4
-#define EINTR_STR           "Interrupted system call"
-#define EIO                 5
-#define EIO_STR             "I/O error"
-#define ENXIO               6
-#define ENXIO_STR           "No such device or address"
-#define E2BIG               7
-#define E2BIG_STR           "Arg list too long"
-#define ENOEXEC             8
-#define ENOEXEC_STR         "Exec format error"
-#define EBADF               9
-#define EBADF_STR           "Bad file number"
-#define ECHILD              10
-#define ECHILD_STR          "No child processes"
-#define EAGAIN              11
-#define EWOULDBLOCK         EAGAIN
-#define EAGAIN_STR          "Try again"
-#define ENOMEM              12
-#define ENOMEM_STR          "Out of memory"
-#define EACCES              13
-#define EACCES_STR          "Permission denied"
-#define EFAULT              14                         /* Linux errno extension */
-#define EFAULT_STR          "Bad address"
-#define ENOTBLK             15
-#define ENOTBLK_STR         "Block device required"
-#define EBUSY               16
-#define EBUSY_STR           "Device or resource busy"
-#define EEXIST              17
-#define EEXIST_STR          "File exists"
-#define EXDEV               18
-#define EXDEV_STR           "Cross-device link"
-#define ENODEV              19
-#define ENODEV_STR          "No such device"
-#define ENOTDIR             20
-#define ENOTDIR_STR         "Not a directory"
-#define EISDIR              21
-#define EISDIR_STR          "Is a directory"
-#define EINVAL              22
-#define EINVAL_STR          "Invalid argument"
-#define ENFILE              23
-#define ENFILE_STR          "File table overflow"
-#define EMFILE              24
-#define EMFILE_STR          "Too many open files"
-#define ENOTTY              25
-#define ENOTTY_STR          "Not a typewriter"
-#define ETXTBSY             26
-#define ETXTBSY_STR         "Text file busy"
-#define EFBIG               27
-#define EFBIG_STR           "File too large"
-#define ENOSPC              28
-#define ENOSPC_STR          "No space left on device"
-#define ESPIPE              29
-#define ESPIPE_STR          "Illegal seek"
-#define EROFS               30
-#define EROFS_STR           "Read-only file system"
-#define EMLINK              31
-#define EMLINK_STR          "Too many links"
-#define EPIPE               32
-#define EPIPE_STR           "Broken pipe"
-#define EDOM                33
-#define EDOM_STR            "Math argument out of domain of func"
-#define ERANGE              34
-#define ERANGE_STR          "Math result not representable"
-#define ENOMSG              35
-#define ENOMSG_STR          "No message of desired type"
-#define EIDRM               36
-#define EIDRM_STR           "Identifier removed"
-#define ECHRNG              37                         /* Linux errno extension */
-#define ECHRNG_STR          "Channel number out of range"
-#define EL2NSYNC            38                         /* Linux errno extension */
-#define EL2NSYNC_STR        "Level 2 not synchronized"
-#define EL3HLT              39                         /* Linux errno extension */
-#define EL3HLT_STR          "Level 3 halted"
-#define EL3RST              40                         /* Linux errno extension */
-#define EL3RST_STR          "Level 3 reset"
-#define ELNRNG              41                         /* Linux errno extension */
-#define ELNRNG_STR          "Link number out of range"
-#define EUNATCH             42                         /* Linux errno extension */
-#define EUNATCH_STR         "Protocol driver not attached"
-#define ENOCSI              43                         /* Linux errno extension */
-#define ENOCSI_STR          "No CSI structure available"
-#define EL2HLT              44                         /* Linux errno extension */
-#define EL2HLT_STR          "Level 2 halted"
-#define EDEADLK             45
-#define EDEADLK_STR         "Resource deadlock would occur"
-#define ENOLCK              46
-#define ENOLCK_STR          "No record locks available"
-
-#define EBADE               50                         /* Linux errno extension */
-#define EBADE_STR           "Invalid exchange"
-#define EBADR               51                         /* Linux errno extension */
-#define EBADR_STR           "Invalid request descriptor"
-#define EXFULL              52                         /* Linux errno extension */
-#define EXFULL_STR          "Exchange full"
-#define ENOANO              53                         /* Linux errno extension */
-#define ENOANO_STR          "No anode"
-#define EBADRQC             54                         /* Linux errno extension */
-#define EBADRQC_STR         "Invalid request code"
-#define EBADSLT             55                         /* Linux errno extension */
-#define EBADSLT_STR         "Invalid slot"
-#define EDEADLOCK           56                         /* Linux errno extension */
-#define EDEADLOCK_STR       "File locking deadlock error"
-#define EBFONT              57                         /* Linux errno extension */
-#define EBFONT_STR          "Bad font file format"
-
-#define ENOSTR              60
-#define ENOSTR_STR          "Device not a stream"
-#define ENODATA             61
-#define ENODATA_STR         "No data available"
-#define ETIME               62
-#define ETIME_STR           "Timer expired"
-#define ENOSR               63
-#define ENOSR_STR           "Out of streams resources"
-#define ENONET              64                         /* Linux errno extension */
-#define ENONET_STR          "Machine is not on the network"
-#define ENOPKG              65                         /* Linux errno extension */
-#define ENOPKG_STR          "Package not installed"
-#define EREMOTE             66                         /* Linux errno extension */
-#define EREMOTE_STR         "Object is remote"
-#define ENOLINK             67
-#define ENOLINK_STR         "Link has been severed"
-#define EADV                68                         /* Linux errno extension */
-#define EADV_STR            "Advertise error"
-#define ESRMNT              69                         /* Linux errno extension */
-#define ESRMNT_STR          "Srmount error"
-#define ECOMM               70                         /* Linux errno extension */
-#define ECOMM_STR           "Communication error on send"
-#define EPROTO              71
-#define EPROTO_STR          "Protocol error"
-
-#define EMULTIHOP           74
-#define EMULTIHOP_STR       "Multihop attempted"
-#define ELBIN               75                         /* Linux errno extension */
-#define ELBIN_STR           "Inode is remote"
-#define EDOTDOT             76                         /* Linux errno extension */
-#define EDOTDOT_STR         "RFS specific error"
-#define EBADMSG             77
-#define EBADMSG_STR         "Not a data message"
-
-#define EFTYPE              79
-#define EFTYPE_STR          "Inappropriate file type or format"
-#define ENOTUNIQ            80                         /* Linux errno extension */
-#define ENOTUNIQ_STR        "Name not unique on network"
-#define EBADFD              81                         /* Linux errno extension */
-#define EBADFD_STR          "File descriptor in bad state"
-#define EREMCHG             82                         /* Linux errno extension */
-#define EREMCHG_STR         "Remote address changed"
-#define ELIBACC             83                         /* Linux errno extension */
-#define ELIBACC_STR         "Can not access a needed shared library"
-#define ELIBBAD             84                         /* Linux errno extension */
-#define ELIBBAD_STR         "Accessing a corrupted shared library"
-#define ELIBSCN             85                         /* Linux errno extension */
-#define ELIBSCN_STR         ".lib section in a.out corrupted"
-#define ELIBMAX             86                         /* Linux errno extension */
-#define ELIBMAX_STR         "Attempting to link in too many shared libraries"
-#define ELIBEXEC            87                         /* Linux errno extension */
-#define ELIBEXEC_STR        "Cannot exec a shared library directly"
-#define ENOSYS              88
-#define ENOSYS_STR          "Function not implemented"
-#define ENMFILE             89                         /* Cygwin */
-#define ENMFILE_STR         "No more files"
-#define ENOTEMPTY           90
-#define ENOTEMPTY_STR       "Directory not empty"
-#define ENAMETOOLONG        91
-#define ENAMETOOLONG_STR    "File name too long"
-#define ELOOP               92
-#define ELOOP_STR           "Too many symbolic links encountered"
-
-#define EOPNOTSUPP          95
-#define EOPNOTSUPP_STR      "Operation not supported on transport endpoint"
-#define EPFNOSUPPORT        96
-#define EPFNOSUPPORT_STR    "Protocol family not supported"
-
-#define ECONNRESET          104
-#define ECONNRESET_STR      "Connection reset by peer"
-#define ENOBUFS             105
-#define ENOBUFS_STR         "No buffer space available"
-#define EAFNOSUPPORT        106
-#define EAFNOSUPPORT_STR    "Address family not supported by protocol"
-#define EPROTOTYPE          107
-#define EPROTOTYPE_STR      "Protocol wrong type for socket"
-#define ENOTSOCK            108
-#define ENOTSOCK_STR        "Socket operation on non-socket"
-#define ENOPROTOOPT         109
-#define ENOPROTOOPT_STR     "Protocol not available"
-#define ESHUTDOWN           110                         /* Linux errno extension */
-#define ESHUTDOWN_STR       "Cannot send after transport endpoint shutdown"
-#define ECONNREFUSED        111
-#define ECONNREFUSED_STR    "Connection refused"
-#define EADDRINUSE          112
-#define EADDRINUSE_STR      "Address already in use"
-#define ECONNABORTED        113
-#define ECONNABORTED_STR    "Software caused connection abort"
-#define ENETUNREACH         114
-#define ENETUNREACH_STR     "Network is unreachable"
-#define ENETDOWN            115
-#define ENETDOWN_STR        "Network is down"
-#define ETIMEDOUT           116
-#define ETIMEDOUT_STR       "Connection timed out"
-#define EHOSTDOWN           117
-#define EHOSTDOWN_STR       "Host is down"
-#define EHOSTUNREACH        118
-#define EHOSTUNREACH_STR    "No route to host"
-#define EINPROGRESS         119
-#define EINPROGRESS_STR     "Operation now in progress"
-#define EALREADY            120
-#define EALREADY_STR        "Socket already connected"
-#define EDESTADDRREQ        121
-#define EDESTADDRREQ_STR    "Destination address required"
-#define EMSGSIZE            122
-#define EMSGSIZE_STR        "Message too long"
-#define EPROTONOSUPPORT     123
-#define EPROTONOSUPPORT_STR "Protocol not supported"
-#define ESOCKTNOSUPPORT     124                         /* Linux errno extension */
-#define ESOCKTNOSUPPORT_STR "Socket type not supported"
-#define EADDRNOTAVAIL       125
-#define EADDRNOTAVAIL_STR   "Cannot assign requested address"
-#define ENETRESET           126
-#define ENETRESET_STR       "Network dropped connection because of reset"
-#define EISCONN             127
-#define EISCONN_STR         "Transport endpoint is already connected"
-#define ENOTCONN            128
-#define ENOTCONN_STR        "Transport endpoint is not connected"
-#define ETOOMANYREFS        129
-#define ETOOMANYREFS_STR    "Too many references: cannot splice"
-#define EPROCLIM            130
-#define EPROCLIM_STR        "Limit would be exceeded by attempted fork"
-#define EUSERS              131
-#define EUSERS_STR          "Too many users"
-#define EDQUOT              132
-#define EDQUOT_STR          "Quota exceeded"
-#define ESTALE              133
-#define ESTALE_STR          "Stale NFS file handle"
-#define ENOTSUP             134
-#define ENOTSUP_STR         "Not supported"
-#define ENOMEDIUM           135                         /* Linux errno extension */
-#define ENOMEDIUM_STR       "No medium found"
-#define ENOSHARE            136                         /* Cygwin */
-#define ENOSHARE_STR        "No such host or network path"
-#define ECASECLASH          137                         /* Cygwin */
-#define ECASECLASH_STR      "Filename exists with different case"
-#define EILSEQ              138
-#define EILSEQ_STR          "Illegal byte sequence"
-#define EOVERFLOW           139
-#define EOVERFLOW_STR       "Value too large for defined data type"
-#define ECANCELED           140
-#define ECANCELED_STR       "Operation cancelled"
-#define ENOTRECOVERABLE     141
-#define ENOTRECOVERABLE_STR "State not recoverable"
-#define EOWNERDEAD          142
-#define EOWNERDEAD_STR      "Previous owner died"
-#define ESTRPIPE            143                         /* Linux errno extension */
-#define ESTRPIPE_STR        "Streams pipe error"
-
-#define __ELASTERROR        2000                        /* Users can add values starting here */
-#else
-#include <errno.h>
-#endif
-/****************************************************************************
- * Public Type Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
-
-/* Return a pointer to the thread specific errno. */
-
-int *__errno(void);
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __INCLUDE_ERRNO_H */
+#ifndef USB_ERRNO_H
+#define USB_ERRNO_H
+
+#define USB_ERR_NOMEM    1
+#define USB_ERR_INVAL    2
+#define USB_ERR_NODEV    3
+#define USB_ERR_NOTCONN  4
+#define USB_ERR_NOTSUPP  5
+#define USB_ERR_BUSY     6
+#define USB_ERR_RANGE    7
+#define USB_ERR_STALL    8
+#define USB_ERR_BABBLE   9
+#define USB_ERR_NAK      10
+#define USB_ERR_DT       11
+#define USB_ERR_IO       12
+#define USB_ERR_SHUTDOWN 13
+#define USB_ERR_TIMEOUT  14
+
+#endif /* USB_ERRNO_H */

+ 1 - 1
common/usb_hc.h

@@ -90,7 +90,7 @@ int usbh_submit_urb(struct usbh_urb *urb);
 /**
  * @brief Cancel a transfer request.
  *
- * This function will call When calls usbh_submit_urb and return -ETIMEOUT or -ESHUTDOWN.
+ * This function will call When calls usbh_submit_urb and return -USB_ERR_TIMEOUT or -USB_ERR_SHUTDOWN.
  *
  * @param urb Usb request block.
  * @return  On success will return 0, and others indicate fail.

+ 9 - 9
core/usbh_core.c

@@ -58,7 +58,7 @@ static int usbh_allocate_devaddr(struct usbh_devaddr_map *devgen)
         }
 
         if (startaddr == devaddr) {
-            return -ENOMEM;
+            return -USB_ERR_NOMEM;
         }
     }
 }
@@ -126,10 +126,10 @@ static int parse_device_descriptor(struct usbh_hubport *hport, struct usb_device
 {
     if (desc->bLength != USB_SIZEOF_DEVICE_DESC) {
         USB_LOG_ERR("invalid device bLength 0x%02x\r\n", desc->bLength);
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     } else if (desc->bDescriptorType != USB_DESCRIPTOR_TYPE_DEVICE) {
         USB_LOG_ERR("unexpected device descriptor 0x%02x\r\n", desc->bDescriptorType);
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     } else {
         if (length <= 8) {
             return 0;
@@ -182,10 +182,10 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config
 
     if (desc->bLength != USB_SIZEOF_CONFIG_DESC) {
         USB_LOG_ERR("invalid config bLength 0x%02x\r\n", desc->bLength);
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     } else if (desc->bDescriptorType != USB_DESCRIPTOR_TYPE_CONFIGURATION) {
         USB_LOG_ERR("unexpected config descriptor 0x%02x\r\n", desc->bDescriptorType);
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     } else {
         if (length <= USB_SIZEOF_CONFIG_DESC) {
             return 0;
@@ -227,15 +227,15 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config
                     cur_ep = 0;
                     if (cur_iface > (CONFIG_USBHOST_MAX_INTERFACES - 1)) {
                         USB_LOG_ERR("Interface num overflow\r\n");
-                        return -ENOMEM;
+                        return -USB_ERR_NOMEM;
                     }
                     if (cur_alt_setting > (CONFIG_USBHOST_MAX_INTF_ALTSETTINGS - 1)) {
                         USB_LOG_ERR("Interface altsetting num overflow\r\n");
-                        return -ENOMEM;
+                        return -USB_ERR_NOMEM;
                     }
                     if (cur_ep_num > CONFIG_USBHOST_MAX_ENDPOINTS) {
                         USB_LOG_ERR("Endpoint num overflow\r\n");
-                        return -ENOMEM;
+                        return -USB_ERR_NOMEM;
                     }
 #if 0
                     USB_LOG_DBG("Interface Descriptor:\r\n");
@@ -548,7 +548,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
     USB_LOG_INFO("The device has %d interfaces\r\n", ((struct usb_configuration_descriptor *)ep0_request_buffer)->bNumInterfaces);
     hport->raw_config_desc = usb_malloc(wTotalLength);
     if (hport->raw_config_desc == NULL) {
-        ret = -ENOMEM;
+        ret = -USB_ERR_NOMEM;
         USB_LOG_ERR("No memory to alloc for raw_config_desc\r\n");
         goto errout;
     }

+ 8 - 8
osal/usb_osal_freertos.c

@@ -36,9 +36,9 @@ void usb_osal_sem_delete(usb_osal_sem_t sem)
 int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout)
 {
     if (timeout == USB_OSAL_WAITING_FOREVER) {
-        return (xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY) == pdPASS) ? 0 : -ETIMEDOUT;
+        return (xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
     } else {
-        return (xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -ETIMEDOUT;
+        return (xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
     }
 }
 
@@ -56,7 +56,7 @@ int usb_osal_sem_give(usb_osal_sem_t sem)
         ret = xSemaphoreGive((SemaphoreHandle_t)sem);
     }
 
-    return (ret == pdPASS) ? 0 : -ETIMEDOUT;
+    return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
 }
 
 void usb_osal_sem_reset(usb_osal_sem_t sem)
@@ -76,12 +76,12 @@ void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
 
 int usb_osal_mutex_take(usb_osal_mutex_t mutex)
 {
-    return (xSemaphoreTake((SemaphoreHandle_t)mutex, portMAX_DELAY) == pdPASS) ? 0 : -ETIMEDOUT;
+    return (xSemaphoreTake((SemaphoreHandle_t)mutex, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
 }
 
 int usb_osal_mutex_give(usb_osal_mutex_t mutex)
 {
-    return (xSemaphoreGive((SemaphoreHandle_t)mutex) == pdPASS) ? 0 : -ETIMEDOUT;
+    return (xSemaphoreGive((SemaphoreHandle_t)mutex) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
 }
 
 usb_osal_mq_t usb_osal_mq_create(uint32_t max_msgs)
@@ -99,15 +99,15 @@ int usb_osal_mq_send(usb_osal_mq_t mq, uintptr_t addr)
         portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
     }
 
-    return (ret == pdPASS) ? 0 : -ETIMEDOUT;
+    return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
 }
 
 int usb_osal_mq_recv(usb_osal_mq_t mq, uintptr_t *addr, uint32_t timeout)
 {
     if (timeout == USB_OSAL_WAITING_FOREVER) {
-        return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -ETIMEDOUT;
+        return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
     } else {
-        return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -ETIMEDOUT;
+        return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
     }
 }
 

+ 4 - 4
osal/usb_osal_rtthread.c

@@ -46,9 +46,9 @@ int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout)
         result = rt_sem_take((rt_sem_t)sem, rt_tick_from_millisecond(timeout));
     }
     if (result == -RT_ETIMEOUT) {
-        ret = -ETIMEDOUT;
+        ret = -USB_ERR_TIMEOUT;
     } else if (result == -RT_ERROR) {
-        ret = -EINVAL;
+        ret = -USB_ERR_INVAL;
     } else {
         ret = 0;
     }
@@ -107,9 +107,9 @@ int usb_osal_mq_recv(usb_osal_mq_t mq, uintptr_t *addr, uint32_t timeout)
         result = rt_mq_recv((rt_mq_t)mq, addr, sizeof(uintptr_t), rt_tick_from_millisecond(timeout));
     }
     if (result == -RT_ETIMEOUT) {
-        ret = -ETIMEDOUT;
+        ret = -USB_ERR_TIMEOUT;
     } else if (result == -RT_ERROR) {
-        ret = -EINVAL;
+        ret = -USB_ERR_INVAL;
     } else {
         ret = 0;
     }

+ 34 - 36
port/dwc2/usb_hc_dwc2.c

@@ -552,7 +552,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
@@ -562,7 +562,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_GET_DESCRIPTOR:
@@ -577,7 +577,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
         switch (setup->bRequest) {
             case HUB_REQUEST_CLEAR_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -601,12 +601,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_PORT_FEATURE_C_RESET:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -620,12 +620,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                         break;
 
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_GET_STATUS:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
                 hprt0 = USB_OTG_HPRT;
 
@@ -678,20 +678,20 @@ int usbh_submit_urb(struct usbh_urb *urb)
     int chidx;
 
     if (!urb || !urb->hport || !urb->ep) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     /* dma addr must be aligned 4 bytes */
     if ((((uint32_t)urb->setup) & 0x03) || (((uint32_t)urb->transfer_buffer) & 0x03)) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     if (!(USB_OTG_HPRT & USB_OTG_HPRT_PCSTS) || !urb->hport->connected) {
-        return -ENODEV;
+        return -USB_ERR_NOTCONN;
     }
 
-    if (urb->errorcode == -EBUSY) {
-        return -EBUSY;
+    if (urb->errorcode == -USB_ERR_BUSY) {
+        return -USB_ERR_BUSY;
     }
 
     flags = usb_osal_enter_critical_section();
@@ -699,7 +699,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
     chidx = dwc2_chan_alloc();
     if (chidx == -1) {
         usb_osal_leave_critical_section(flags);
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     chan = &g_dwc2_hcd.chan_pool[chidx];
@@ -707,7 +707,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
     chan->urb = urb;
 
     urb->hcpriv = chan;
-    urb->errorcode = -EBUSY;
+    urb->errorcode = -USB_ERR_BUSY;
     urb->actual_length = 0;
 
     usb_osal_leave_critical_section(flags);
@@ -751,7 +751,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
     size_t flags;
 
     if (!urb || !urb->hcpriv) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     flags = usb_osal_enter_critical_section();
@@ -764,11 +764,9 @@ int usbh_kill_urb(struct usbh_urb *urb)
     chan->urb = NULL;
     urb->hcpriv = NULL;
 
-    dwc2_chan_free(chan);
-
     if (urb->timeout) {
         urb->timeout = 0;
-        urb->errorcode = -ESHUTDOWN;
+        urb->errorcode = -USB_ERR_SHUTDOWN;
         usb_osal_sem_give(chan->waitsem);
     } else {
         dwc2_chan_free(chan);
@@ -822,45 +820,45 @@ static void dwc2_inchan_irq_handler(uint8_t ch_num)
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_XFRC);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
     } else if ((chan_intstatus & USB_OTG_HCINT_AHBERR) == USB_OTG_HCINT_AHBERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_AHBERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_STALL) == USB_OTG_HCINT_STALL) {
-        urb->errorcode = -EPERM;
+        urb->errorcode = -USB_ERR_STALL;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_STALL);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
     } else if ((chan_intstatus & USB_OTG_HCINT_NAK) == USB_OTG_HCINT_NAK) {
-        urb->errorcode = -EAGAIN;
+        urb->errorcode = -USB_ERR_NAK;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
     } else if ((chan_intstatus & USB_OTG_HCINT_ACK) == USB_OTG_HCINT_ACK) {
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_ACK);
     } else if ((chan_intstatus & USB_OTG_HCINT_NYET) == USB_OTG_HCINT_NYET) {
-        urb->errorcode = -EAGAIN;
+        urb->errorcode = -USB_ERR_NAK;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NYET);
     } else if ((chan_intstatus & USB_OTG_HCINT_TXERR) == USB_OTG_HCINT_TXERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_TXERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_BBERR) == USB_OTG_HCINT_BBERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_BABBLE;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_BBERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_FRMOR) == USB_OTG_HCINT_FRMOR) {
-        urb->errorcode = -EPIPE;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_FRMOR);
     } else if ((chan_intstatus & USB_OTG_HCINT_DTERR) == USB_OTG_HCINT_DTERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_DT;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
@@ -896,7 +894,7 @@ static void dwc2_inchan_irq_handler(uint8_t ch_num)
             } else {
                 dwc2_urb_waitup(urb);
             }
-        } else if (urb->errorcode == -EAGAIN) {
+        } else if (urb->errorcode == -USB_ERR_NAK) {
             /* re-activate the channel */
             if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
                 dwc2_control_urb_init(ch_num, urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
@@ -929,44 +927,44 @@ static void dwc2_outchan_irq_handler(uint8_t ch_num)
         dwc2_halt(ch_num);
         USB_UNMASK_HALT_HC_INT(ch_num);
     } else if ((chan_intstatus & USB_OTG_HCINT_AHBERR) == USB_OTG_HCINT_AHBERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_AHBERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_STALL) == USB_OTG_HCINT_STALL) {
-        urb->errorcode = -EPERM;
+        urb->errorcode = -USB_ERR_STALL;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_STALL);
     } else if ((chan_intstatus & USB_OTG_HCINT_NAK) == USB_OTG_HCINT_NAK) {
-        urb->errorcode = -EAGAIN;
+        urb->errorcode = -USB_ERR_NAK;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
     } else if ((chan_intstatus & USB_OTG_HCINT_ACK) == USB_OTG_HCINT_ACK) {
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_ACK);
     } else if ((chan_intstatus & USB_OTG_HCINT_NYET) == USB_OTG_HCINT_NYET) {
-        urb->errorcode = -EAGAIN;
+        urb->errorcode = -USB_ERR_NAK;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NYET);
     } else if ((chan_intstatus & USB_OTG_HCINT_TXERR) == USB_OTG_HCINT_TXERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_TXERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_BBERR) == USB_OTG_HCINT_BBERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_BABBLE;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_BBERR);
     } else if ((chan_intstatus & USB_OTG_HCINT_FRMOR) == USB_OTG_HCINT_FRMOR) {
-        urb->errorcode = -EPIPE;
+        urb->errorcode = -USB_ERR_IO;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_FRMOR);
     } else if ((chan_intstatus & USB_OTG_HCINT_DTERR) == USB_OTG_HCINT_DTERR) {
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_DT;
         USB_UNMASK_HALT_HC_INT(ch_num);
         dwc2_halt(ch_num);
         CLEAR_HC_INT(ch_num, USB_OTG_HCINT_DTERR);
@@ -1013,7 +1011,7 @@ static void dwc2_outchan_irq_handler(uint8_t ch_num)
             } else {
                 dwc2_urb_waitup(urb);
             }
-        } else if (urb->errorcode == -EAGAIN) {
+        } else if (urb->errorcode == -USB_ERR_NAK) {
             /* re-activate the channel */
             if (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) == USB_ENDPOINT_TYPE_CONTROL) {
                 dwc2_control_urb_init(ch_num, urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);

+ 25 - 25
port/ehci/usb_hc_ehci.c

@@ -701,13 +701,13 @@ static void ehci_check_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh)
         urb->errorcode = 0;
     } else {
         if (token & QTD_TOKEN_STATUS_BABBLE) {
-            urb->errorcode = -EOVERFLOW;
+            urb->errorcode = -USB_ERR_BABBLE;
             urb->data_toggle = 0;
         } else if (token & QTD_TOKEN_STATUS_HALTED) {
-            urb->errorcode = -EPERM;
+            urb->errorcode = -USB_ERR_STALL;
             urb->data_toggle = 0;
         } else if (token & (QTD_TOKEN_STATUS_DBERR | QTD_TOKEN_STATUS_XACTERR)) {
-            urb->errorcode = -EIO;
+            urb->errorcode = -USB_ERR_IO;
         }
     }
 
@@ -760,7 +760,7 @@ static int usbh_reset_port(const uint8_t port)
         usb_osal_msleep(1);
         timeout++;
         if (timeout > 100) {
-            return -ETIMEDOUT;
+            return -USB_ERR_TIMEOUT;
         }
     }
 
@@ -787,11 +787,11 @@ int usb_hc_init(void)
 
     if (sizeof(struct ehci_qh_hw) % 32) {
         USB_LOG_ERR("struct ehci_qh_hw is not align 32\r\n");
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
     if (sizeof(struct ehci_qtd_hw) % 32) {
         USB_LOG_ERR("struct ehci_qtd_hw is not align 32\r\n");
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     for (uint8_t index = 0; index < CONFIG_USB_EHCI_QH_NUM; index++) {
@@ -846,7 +846,7 @@ int usb_hc_init(void)
         usb_osal_msleep(1);
         timeout++;
         if (timeout > 100) {
-            return -ETIMEDOUT;
+            return -USB_ERR_TIMEOUT;
         }
     }
 
@@ -890,7 +890,7 @@ int usb_hc_init(void)
         usb_osal_msleep(1);
         timeout++;
         if (timeout > 100) {
-            return -ETIMEDOUT;
+            return -USB_ERR_TIMEOUT;
         }
     }
 #ifdef CONFIG_USB_EHCI_PORT_POWER
@@ -929,7 +929,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
@@ -939,7 +939,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_GET_DESCRIPTOR:
@@ -954,7 +954,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
         switch (setup->bRequest) {
             case HUB_REQUEST_CLEAR_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -994,12 +994,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_PORT_FEATURE_C_RESET:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -1025,12 +1025,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                         break;
 
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_NOTSUPP;
                 }
                 break;
             case HUB_REQUEST_GET_STATUS:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
                 temp = EHCI_HCOR->portsc[port - 1];
 
@@ -1087,7 +1087,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
     struct usbh_hubport *hport;
 
     if (!urb || !urb->hport || !urb->ep) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     /* find active hubport in roothub */
@@ -1099,17 +1099,17 @@ int usbh_submit_urb(struct usbh_urb *urb)
     }
 
     if (!urb->hport->connected || !(EHCI_HCOR->portsc[hport->port - 1] & EHCI_PORTSC_CCS)) {
-        return -ENODEV;
+        return -USB_ERR_NOTCONN;
     }
 
-    if ((urb->errorcode == -EBUSY) && (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
-        return -EBUSY;
+    if ((urb->errorcode == -USB_ERR_BUSY) && (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes) != USB_ENDPOINT_TYPE_ISOCHRONOUS)) {
+        return -USB_ERR_BUSY;
     }
 
     flags = usb_osal_enter_critical_section();
 
     urb->hcpriv = NULL;
-    urb->errorcode = -EBUSY;
+    urb->errorcode = -USB_ERR_BUSY;
     urb->actual_length = 0;
 
     usb_osal_leave_critical_section(flags);
@@ -1118,21 +1118,21 @@ int usbh_submit_urb(struct usbh_urb *urb)
         case USB_ENDPOINT_TYPE_CONTROL:
             qh = ehci_control_urb_init(urb, urb->setup, urb->transfer_buffer, urb->transfer_buffer_length);
             if (qh == NULL) {
-                return -ENOMEM;
+                return -USB_ERR_NOMEM;
             }
             urb->hcpriv = qh;
             break;
         case USB_ENDPOINT_TYPE_BULK:
             qh = ehci_bulk_urb_init(urb, urb->transfer_buffer, urb->transfer_buffer_length);
             if (qh == NULL) {
-                return -ENOMEM;
+                return -USB_ERR_NOMEM;
             }
             urb->hcpriv = qh;
             break;
         case USB_ENDPOINT_TYPE_INTERRUPT:
             qh = ehci_intr_urb_init(urb, urb->transfer_buffer, urb->transfer_buffer_length);
             if (qh == NULL) {
-                return -ENOMEM;
+                return -USB_ERR_NOMEM;
             }
             urb->hcpriv = qh;
             break;
@@ -1169,7 +1169,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
     size_t flags;
 
     if (!urb || !urb->hcpriv) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     flags = usb_osal_enter_critical_section();
@@ -1210,7 +1210,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
 
     if (urb->timeout) {
         urb->timeout = 0;
-        urb->errorcode = -ESHUTDOWN;
+        urb->errorcode = -USB_ERR_SHUTDOWN;
         usb_osal_sem_give(qh->waitsem);
     } else {
         ehci_qh_free(qh);

+ 24 - 24
port/musb/usb_hc_musb.c

@@ -489,7 +489,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_INVAL;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
@@ -499,7 +499,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_FEATURE_HUB_C_OVERCURRENT:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_INVAL;
                 }
                 break;
             case HUB_REQUEST_GET_DESCRIPTOR:
@@ -514,7 +514,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
         switch (setup->bRequest) {
             case HUB_REQUEST_CLEAR_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -536,12 +536,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                     case HUB_PORT_FEATURE_C_RESET:
                         break;
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_INVAL;
                 }
                 break;
             case HUB_REQUEST_SET_FEATURE:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 switch (setup->wValue) {
@@ -554,12 +554,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
                         break;
 
                     default:
-                        return -EPIPE;
+                        return -USB_ERR_INVAL;
                 }
                 break;
             case HUB_REQUEST_GET_STATUS:
                 if (!port || port > nports) {
-                    return -EPIPE;
+                    return -USB_ERR_INVAL;
                 }
 
                 status = 0;
@@ -597,15 +597,15 @@ int usbh_submit_urb(struct usbh_urb *urb)
     int ret = 0;
 
     if (!urb || !urb->hport || !urb->ep) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     if (!urb->hport->connected) {
-        return -ENODEV;
+        return -USB_ERR_NOTCONN;
     }
 
-    if (urb->errorcode == -EBUSY) {
-        return -EBUSY;
+    if (urb->errorcode == -USB_ERR_BUSY) {
+        return -USB_ERR_BUSY;
     }
 
     flags = usb_osal_enter_critical_section();
@@ -613,7 +613,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
     chidx = musb_pipe_alloc();
     if (chidx == -1) {
         usb_osal_leave_critical_section(flags);
-        return -ENOMEM;
+        return -USB_ERR_NOMEM;
     }
 
     pipe = &g_musb_hcd.pipe_pool[chidx];
@@ -621,7 +621,7 @@ int usbh_submit_urb(struct usbh_urb *urb)
     pipe->urb = urb;
 
     urb->hcpriv = pipe;
-    urb->errorcode = -EBUSY;
+    urb->errorcode = -USB_ERR_BUSY;
     urb->actual_length = 0;
 
     usb_osal_leave_critical_section(flags);
@@ -666,7 +666,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
     size_t flags;
 
     if (!urb || !urb->hcpriv) {
-        return -EINVAL;
+        return -USB_ERR_INVAL;
     }
 
     flags = usb_osal_enter_critical_section();
@@ -677,7 +677,7 @@ int usbh_kill_urb(struct usbh_urb *urb)
 
     if (urb->timeout) {
         urb->timeout = 0;
-        urb->errorcode = -ESHUTDOWN;
+        urb->errorcode = -USB_ERR_SHUTDOWN;
         usb_osal_sem_give(pipe->waitsem);
     } else {
         musb_pipe_free(pipe);
@@ -729,7 +729,7 @@ void handle_ep0(void)
     if (ep0_status & USB_CSRL0_STALLED) {
         HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_CSRL0_STALLED;
         usb_ep0_state = USB_EP0_STATE_SETUP;
-        urb->errorcode = -EPERM;
+        urb->errorcode = -USB_ERR_STALL;
         musb_urb_waitup(urb);
         return;
     }
@@ -737,14 +737,14 @@ void handle_ep0(void)
         HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_CSRL0_ERROR;
         musb_fifo_flush(0);
         usb_ep0_state = USB_EP0_STATE_SETUP;
-        urb->errorcode = -EIO;
+        urb->errorcode = -USB_ERR_IO;
         musb_urb_waitup(urb);
         return;
     }
     if (ep0_status & USB_CSRL0_STALL) {
         HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_CSRL0_STALL;
         usb_ep0_state = USB_EP0_STATE_SETUP;
-        urb->errorcode = -EPERM;
+        urb->errorcode = -USB_ERR_STALL;
         musb_urb_waitup(urb);
         return;
     }
@@ -901,15 +901,15 @@ void USBH_IRQHandler(void)
 
             if (ep_csrl_status & USB_TXCSRL1_ERROR) {
                 HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_TXCSRL1_ERROR;
-                urb->errorcode = -EIO;
+                urb->errorcode = -USB_ERR_IO;
                 goto pipe_wait;
             } else if (ep_csrl_status & USB_TXCSRL1_NAKTO) {
                 HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_TXCSRL1_NAKTO;
-                urb->errorcode = -EBUSY;
+                urb->errorcode = -USB_ERR_NAK;
                 goto pipe_wait;
             } else if (ep_csrl_status & USB_TXCSRL1_STALL) {
                 HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) &= ~USB_TXCSRL1_STALL;
-                urb->errorcode = -EPERM;
+                urb->errorcode = -USB_ERR_STALL;
                 goto pipe_wait;
             } else {
                 uint32_t size = urb->transfer_buffer_length;
@@ -947,15 +947,15 @@ void USBH_IRQHandler(void)
 
             if (ep_csrl_status & USB_RXCSRL1_ERROR) {
                 HWREGB(USB_BASE + MUSB_IND_RXCSRL_OFFSET) &= ~USB_RXCSRL1_ERROR;
-                urb->errorcode = -EIO;
+                urb->errorcode = -USB_ERR_IO;
                 goto pipe_wait;
             } else if (ep_csrl_status & USB_RXCSRL1_NAKTO) {
                 HWREGB(USB_BASE + MUSB_IND_RXCSRL_OFFSET) &= ~USB_RXCSRL1_NAKTO;
-                urb->errorcode = -EBUSY;
+                urb->errorcode = -USB_ERR_NAK;
                 goto pipe_wait;
             } else if (ep_csrl_status & USB_RXCSRL1_STALL) {
                 HWREGB(USB_BASE + MUSB_IND_RXCSRL_OFFSET) &= ~USB_RXCSRL1_STALL;
-                urb->errorcode = -EPERM;
+                urb->errorcode = -USB_ERR_STALL;
                 goto pipe_wait;
             } else if (ep_csrl_status & USB_RXCSRL1_RXRDY) {
                 uint32_t size = urb->transfer_buffer_length;