forked from xuos/xiuos
Modify header files
This commit is contained in:
parent
cb397c2c9e
commit
7968c89e5d
|
@ -1,6 +1,304 @@
|
|||
/*
|
||||
* Apache NuttX
|
||||
* Copyright 2020 The Apache Software Foundation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_ERROR_H_
|
||||
#define USB_ERROR_H_
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,146 @@
|
|||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef USB_HC_H_
|
||||
#define USB_HC_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*usbh_complete_callback_t)(void *arg, int nbytes);
|
||||
typedef void *usbh_pipe_t;
|
||||
|
||||
struct usbh_bus;
|
||||
|
||||
/**
|
||||
* @brief USB Endpoint Configuration.
|
||||
*
|
||||
* Structure containing the USB endpoint configuration.
|
||||
*/
|
||||
struct usbh_endpoint_cfg {
|
||||
struct usbh_hubport *hport;
|
||||
uint8_t ep_addr; /* Endpoint addr with direction */
|
||||
uint8_t ep_type; /* Endpoint type */
|
||||
uint16_t ep_mps; /* Endpoint max packet size */
|
||||
uint8_t ep_interval; /* Endpoint interval */
|
||||
uint8_t mult; /* Endpoint additional transcation */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief USB Iso Configuration.
|
||||
*
|
||||
* Structure containing the USB Iso configuration.
|
||||
*/
|
||||
struct usbh_iso_frame_packet {
|
||||
uint8_t *transfer_buffer;
|
||||
uint32_t transfer_buffer_length;
|
||||
uint32_t actual_length;
|
||||
int errorcode;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief USB Urb Configuration.
|
||||
*
|
||||
* Structure containing the USB Urb configuration.
|
||||
*/
|
||||
struct usbh_urb {
|
||||
usbh_pipe_t pipe;
|
||||
struct usb_setup_packet *setup;
|
||||
uint8_t *transfer_buffer;
|
||||
uint32_t transfer_buffer_length;
|
||||
int transfer_flags;
|
||||
uint32_t actual_length;
|
||||
uint32_t timeout;
|
||||
int errorcode;
|
||||
uint32_t num_of_iso_packets;
|
||||
uint32_t start_frame;
|
||||
usbh_complete_callback_t complete;
|
||||
void *arg;
|
||||
struct usbh_iso_frame_packet iso_packet[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb host controller hardware init.
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usb_hc_init(uint32_t id);
|
||||
|
||||
/**
|
||||
* @brief Get frame number.
|
||||
*
|
||||
* @return frame number.
|
||||
*/
|
||||
uint16_t usbh_get_frame_number(void);
|
||||
/**
|
||||
* @brief control roothub.
|
||||
*
|
||||
* @param usb usb bus instance
|
||||
* @param setup setup request buffer.
|
||||
* @param buf buf for reading response or write data.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbh_roothub_control(struct usbh_bus *usb, struct usb_setup_packet *setup, uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @brief reconfig endpoint pipe.
|
||||
*
|
||||
* @param pipe A memory allocated for pipe.
|
||||
* @param dev_addr device address.
|
||||
* @param ep_mps endpoint max packet size.
|
||||
* @param mult endpoint additional transcation
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbh_ep_pipe_reconfigure(struct usbh_bus *usb, usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult);
|
||||
|
||||
/**
|
||||
* @brief Allocate pipe for endpoint
|
||||
*
|
||||
* @param pipe A memory location provided by the caller in which to save the allocated pipe.
|
||||
* @param ep_cfg Describes the endpoint info to be allocated.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg);
|
||||
|
||||
/**
|
||||
* @brief Free a pipe in which saves endpoint info.
|
||||
*
|
||||
* @param pipe A memory location provided by the caller in which to free the allocated endpoint info.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbh_pipe_free(usbh_pipe_t pipe);
|
||||
|
||||
/**
|
||||
* @brief Submit a usb transfer request to an endpoint.
|
||||
*
|
||||
* If timeout is not zero, this function will be in poll transfer mode,
|
||||
* otherwise will be in async transfer mode.
|
||||
*
|
||||
* @param urb Usb request block.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param urb Usb request block.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbh_kill_urb(struct usbh_urb *urb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,460 @@
|
|||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_LIST_H_
|
||||
#define USB_LIST_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* usb_container_of - return the member address of ptr, if the type of ptr is the
|
||||
* struct type.
|
||||
*/
|
||||
#define usb_container_of(ptr, type, member) \
|
||||
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* Single List structure
|
||||
*/
|
||||
struct usb_slist_node {
|
||||
struct usb_slist_node *next; /**< point to next node. */
|
||||
};
|
||||
typedef struct usb_slist_node usb_slist_t; /**< Type for single list. */
|
||||
|
||||
/**
|
||||
* @brief initialize a single list
|
||||
*
|
||||
* @param l the single list to be initialized
|
||||
*/
|
||||
static inline void usb_slist_init(usb_slist_t *l)
|
||||
{
|
||||
l->next = NULL;
|
||||
}
|
||||
|
||||
static inline void usb_slist_add_head(usb_slist_t *l, usb_slist_t *n)
|
||||
{
|
||||
n->next = l->next;
|
||||
l->next = n;
|
||||
}
|
||||
|
||||
static inline void usb_slist_add_tail(usb_slist_t *l, usb_slist_t *n)
|
||||
{
|
||||
usb_slist_t *tmp = l;
|
||||
|
||||
while (tmp->next) {
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
/* append the node to the tail */
|
||||
tmp->next = n;
|
||||
n->next = NULL;
|
||||
}
|
||||
|
||||
static inline void usb_slist_insert(usb_slist_t *l, usb_slist_t *next, usb_slist_t *n)
|
||||
{
|
||||
if (!next) {
|
||||
usb_slist_add_tail(next, l);
|
||||
return;
|
||||
}
|
||||
|
||||
while (l->next) {
|
||||
if (l->next == next) {
|
||||
l->next = n;
|
||||
n->next = next;
|
||||
}
|
||||
|
||||
l = l->next;
|
||||
}
|
||||
}
|
||||
|
||||
static inline usb_slist_t *usb_slist_remove(usb_slist_t *l, usb_slist_t *n)
|
||||
{
|
||||
usb_slist_t *tmp = l;
|
||||
/* remove slist head */
|
||||
while (tmp->next && tmp->next != n) {
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
/* remove node */
|
||||
if (tmp->next != (usb_slist_t *)0) {
|
||||
tmp->next = tmp->next->next;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static inline unsigned int usb_slist_len(const usb_slist_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const usb_slist_t *list = l->next;
|
||||
|
||||
while (list != NULL) {
|
||||
list = list->next;
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline unsigned int usb_slist_contains(usb_slist_t *l, usb_slist_t *n)
|
||||
{
|
||||
while (l->next) {
|
||||
if (l->next == n) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline usb_slist_t *usb_slist_head(usb_slist_t *l)
|
||||
{
|
||||
return l->next;
|
||||
}
|
||||
|
||||
static inline usb_slist_t *usb_slist_tail(usb_slist_t *l)
|
||||
{
|
||||
while (l->next) {
|
||||
l = l->next;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static inline usb_slist_t *usb_slist_next(usb_slist_t *n)
|
||||
{
|
||||
return n->next;
|
||||
}
|
||||
|
||||
static inline int usb_slist_isempty(usb_slist_t *l)
|
||||
{
|
||||
return l->next == NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief initialize a slist object
|
||||
*/
|
||||
#define USB_SLIST_OBJECT_INIT(object) \
|
||||
{ \
|
||||
NULL \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief initialize a slist object
|
||||
*/
|
||||
#define USB_SLIST_DEFINE(slist) \
|
||||
usb_slist_t slist = { NULL }
|
||||
|
||||
/**
|
||||
* @brief get the struct for this single list node
|
||||
* @param node the entry point
|
||||
* @param type the type of structure
|
||||
* @param member the name of list in structure
|
||||
*/
|
||||
#define usb_slist_entry(node, type, member) \
|
||||
usb_container_of(node, type, member)
|
||||
|
||||
/**
|
||||
* usb_slist_first_entry - get the first element from a slist
|
||||
* @ptr: the slist head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the slist_struct within the struct.
|
||||
*
|
||||
* Note, that slist is expected to be not empty.
|
||||
*/
|
||||
#define usb_slist_first_entry(ptr, type, member) \
|
||||
usb_slist_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* usb_slist_tail_entry - get the tail element from a slist
|
||||
* @ptr: the slist head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the slist_struct within the struct.
|
||||
*
|
||||
* Note, that slist is expected to be not empty.
|
||||
*/
|
||||
#define usb_slist_tail_entry(ptr, type, member) \
|
||||
usb_slist_entry(usb_slist_tail(ptr), type, member)
|
||||
|
||||
/**
|
||||
* usb_slist_first_entry_or_null - get the first element from a slist
|
||||
* @ptr: the slist head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the slist_struct within the struct.
|
||||
*
|
||||
* Note, that slist is expected to be not empty.
|
||||
*/
|
||||
#define usb_slist_first_entry_or_null(ptr, type, member) \
|
||||
(usb_slist_isempty(ptr) ? NULL : usb_slist_first_entry(ptr, type, member))
|
||||
|
||||
/**
|
||||
* usb_slist_for_each - iterate over a single list
|
||||
* @pos: the usb_slist_t * to use as a loop cursor.
|
||||
* @head: the head for your single list.
|
||||
*/
|
||||
#define usb_slist_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != NULL; pos = pos->next)
|
||||
|
||||
#define usb_slist_for_each_safe(pos, next, head) \
|
||||
for (pos = (head)->next, next = pos->next; pos; \
|
||||
pos = next, next = pos->next)
|
||||
|
||||
/**
|
||||
* usb_slist_for_each_entry - iterate over single list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your single list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define usb_slist_for_each_entry(pos, head, member) \
|
||||
for (pos = usb_slist_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (NULL); \
|
||||
pos = usb_slist_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
#define usb_slist_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = usb_slist_entry((head)->next, typeof(*pos), member), \
|
||||
n = usb_slist_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (NULL); \
|
||||
pos = n, n = usb_slist_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* Double List structure
|
||||
*/
|
||||
struct usb_dlist_node {
|
||||
struct usb_dlist_node *next; /**< point to next node. */
|
||||
struct usb_dlist_node *prev; /**< point to prev node. */
|
||||
};
|
||||
typedef struct usb_dlist_node usb_dlist_t; /**< Type for lists. */
|
||||
|
||||
/**
|
||||
* @brief initialize a list
|
||||
*
|
||||
* @param l list to be initialized
|
||||
*/
|
||||
static inline void usb_dlist_init(usb_dlist_t *l)
|
||||
{
|
||||
l->next = l->prev = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node after a list
|
||||
*
|
||||
* @param l list to insert it
|
||||
* @param n new node to be inserted
|
||||
*/
|
||||
static inline void usb_dlist_insert_after(usb_dlist_t *l, usb_dlist_t *n)
|
||||
{
|
||||
l->next->prev = n;
|
||||
n->next = l->next;
|
||||
|
||||
l->next = n;
|
||||
n->prev = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node before a list
|
||||
*
|
||||
* @param n new node to be inserted
|
||||
* @param l list to insert it
|
||||
*/
|
||||
static inline void usb_dlist_insert_before(usb_dlist_t *l, usb_dlist_t *n)
|
||||
{
|
||||
l->prev->next = n;
|
||||
n->prev = l->prev;
|
||||
|
||||
l->prev = n;
|
||||
n->next = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief remove node from list.
|
||||
* @param n the node to remove from the list.
|
||||
*/
|
||||
static inline void usb_dlist_remove(usb_dlist_t *n)
|
||||
{
|
||||
n->next->prev = n->prev;
|
||||
n->prev->next = n->next;
|
||||
|
||||
n->next = n->prev = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief move node from list.
|
||||
* @param n the node to remove from the list.
|
||||
*/
|
||||
static inline void usb_dlist_move_head(usb_dlist_t *l, usb_dlist_t *n)
|
||||
{
|
||||
usb_dlist_remove(n);
|
||||
usb_dlist_insert_after(l, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief move node from list.
|
||||
* @param n the node to remove from the list.
|
||||
*/
|
||||
static inline void usb_dlist_move_tail(usb_dlist_t *l, usb_dlist_t *n)
|
||||
{
|
||||
usb_dlist_remove(n);
|
||||
usb_dlist_insert_before(l, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests whether a list is empty
|
||||
* @param l the list to test.
|
||||
*/
|
||||
static inline int usb_dlist_isempty(const usb_dlist_t *l)
|
||||
{
|
||||
return l->next == l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the list length
|
||||
* @param l the list to get.
|
||||
*/
|
||||
static inline unsigned int usb_dlist_len(const usb_dlist_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const usb_dlist_t *p = l;
|
||||
|
||||
while (p->next != l) {
|
||||
p = p->next;
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief initialize a dlist object
|
||||
*/
|
||||
#define USB_DLIST_OBJECT_INIT(object) \
|
||||
{ \
|
||||
&(object), &(object) \
|
||||
}
|
||||
/**
|
||||
* @brief initialize a dlist object
|
||||
*/
|
||||
#define USB_DLIST_DEFINE(list) \
|
||||
usb_dlist_t list = { &(list), &(list) }
|
||||
|
||||
/**
|
||||
* @brief get the struct for this entry
|
||||
* @param node the entry point
|
||||
* @param type the type of structure
|
||||
* @param member the name of list in structure
|
||||
*/
|
||||
#define usb_dlist_entry(node, type, member) \
|
||||
usb_container_of(node, type, member)
|
||||
|
||||
/**
|
||||
* dlist_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define usb_dlist_first_entry(ptr, type, member) \
|
||||
usb_dlist_entry((ptr)->next, type, member)
|
||||
/**
|
||||
* dlist_first_entry_or_null - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define usb_dlist_first_entry_or_null(ptr, type, member) \
|
||||
(usb_dlist_isempty(ptr) ? NULL : usb_dlist_first_entry(ptr, type, member))
|
||||
|
||||
/**
|
||||
* usb_dlist_for_each - iterate over a list
|
||||
* @pos: the usb_dlist_t * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define usb_dlist_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* usb_dlist_for_each_prev - iterate over a list
|
||||
* @pos: the dlist_t * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define usb_dlist_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||
|
||||
/**
|
||||
* usb_dlist_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the dlist_t * to use as a loop cursor.
|
||||
* @n: another dlist_t * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define usb_dlist_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
#define usb_dlist_for_each_prev_safe(pos, n, head) \
|
||||
for (pos = (head)->prev, n = pos->prev; pos != (head); \
|
||||
pos = n, n = pos->prev)
|
||||
/**
|
||||
* usb_dlist_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define usb_dlist_for_each_entry(pos, head, member) \
|
||||
for (pos = usb_dlist_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = usb_dlist_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* usb_usb_dlist_for_each_entry_reverse - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define usb_dlist_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = usb_dlist_entry((head)->prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = usb_dlist_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* usb_usb_dlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define usb_dlist_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = usb_dlist_entry((head)->next, typeof(*pos), member), \
|
||||
n = usb_dlist_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = usb_dlist_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* usb_usb_dlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define usb_dlist_for_each_entry_safe_reverse(pos, n, head, member) \
|
||||
for (pos = usb_dlist_entry((head)->prev, typeof(*pos), field), \
|
||||
n = usb_dlist_entry(pos->member.prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = usb_dlist_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_LOG_H_
|
||||
#define USB_LOG_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* DEBUG level */
|
||||
#define USB_DBG_ERROR 0
|
||||
#define USB_DBG_WARNING 1
|
||||
#define USB_DBG_INFO 2
|
||||
#define USB_DBG_LOG 3
|
||||
|
||||
#ifndef USB_DBG_TAG
|
||||
#define USB_DBG_TAG "USB"
|
||||
#endif
|
||||
/*
|
||||
* The color for terminal (foreground)
|
||||
* BLACK 30
|
||||
* RED 31
|
||||
* GREEN 32
|
||||
* YELLOW 33
|
||||
* BLUE 34
|
||||
* PURPLE 35
|
||||
* CYAN 36
|
||||
* WHITE 37
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_USB_PRINTF_COLOR_ENABLE
|
||||
#define _USB_DBG_COLOR(n) CONFIG_USB_PRINTF("\033[" #n "m")
|
||||
#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
|
||||
CONFIG_USB_PRINTF("\033[" #color_n "m[" lvl_name "/" USB_DBG_TAG "] ")
|
||||
#define _USB_DBG_LOG_X_END \
|
||||
CONFIG_USB_PRINTF("\033[0m")
|
||||
#else
|
||||
#define _USB_DBG_COLOR(n)
|
||||
#define _USB_DBG_LOG_HDR(lvl_name, color_n) \
|
||||
CONFIG_USB_PRINTF("[" lvl_name "/" USB_DBG_TAG "] ")
|
||||
#define _USB_DBG_LOG_X_END
|
||||
#endif
|
||||
|
||||
#define usb_dbg_log_line(lvl, color_n, fmt, ...) \
|
||||
do { \
|
||||
_USB_DBG_LOG_HDR(lvl, color_n); \
|
||||
CONFIG_USB_PRINTF(fmt, ##__VA_ARGS__); \
|
||||
_USB_DBG_LOG_X_END; \
|
||||
} while (0)
|
||||
|
||||
#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_LOG)
|
||||
#define USB_LOG_DBG(fmt, ...) usb_dbg_log_line("D", 0, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_DBG(...) {}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_INFO)
|
||||
#define USB_LOG_INFO(fmt, ...) usb_dbg_log_line("I", 32, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_INFO(...) {}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_WARNING)
|
||||
#define USB_LOG_WRN(fmt, ...) usb_dbg_log_line("W", 33, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_WRN(...) {}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_USB_DBG_LEVEL >= USB_DBG_ERROR)
|
||||
#define USB_LOG_ERR(fmt, ...) usb_dbg_log_line("E", 31, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define USB_LOG_ERR(...) {}
|
||||
#endif
|
||||
|
||||
#define USB_LOG_RAW(...) CONFIG_USB_PRINTF(__VA_ARGS__)
|
||||
|
||||
void usb_assert(const char *filename, int linenum);
|
||||
#define USB_ASSERT(f) \
|
||||
do { \
|
||||
if (!(f)) \
|
||||
usb_assert(__FILE__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,207 @@
|
|||
/*
|
||||
* Copyright (c) 2022, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef USB_UTIL_H_
|
||||
#define USB_TIIL_H_
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
#ifndef __USED
|
||||
#define __USED __attribute__((used))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed))
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION __packed union
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#ifndef __USED
|
||||
#define __USED __attribute__((used))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed, aligned(1)))
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#elif defined(__ICCARM__) || defined(__ICCRX__)
|
||||
#ifndef __USED
|
||||
#if __ICCARM_V8
|
||||
#define __USED __attribute__((used))
|
||||
#else
|
||||
#define __USED __root
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __WEAK
|
||||
#if __ICCARM_V8
|
||||
#define __WEAK __attribute__((weak))
|
||||
#else
|
||||
#define __WEAK _Pragma("__weak")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED
|
||||
#if __ICCARM_V8
|
||||
#define __PACKED __attribute__((packed, aligned(1)))
|
||||
#else
|
||||
/* Needs IAR language extensions */
|
||||
#define __PACKED __packed
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED_STRUCT
|
||||
#if __ICCARM_V8
|
||||
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
|
||||
#else
|
||||
/* Needs IAR language extensions */
|
||||
#define __PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __PACKED_UNION
|
||||
#if __ICCARM_V8
|
||||
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
|
||||
#else
|
||||
/* Needs IAR language extensions */
|
||||
#define __PACKED_UNION __packed union
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGNED
|
||||
#if __ICCARM_V8
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#elif (__VER__ >= 7080000)
|
||||
/* Needs IAR language extensions */
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#else
|
||||
#warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
|
||||
#define __ALIGNED(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN_BEGIN
|
||||
#define __ALIGN_BEGIN
|
||||
#endif
|
||||
#ifndef __ALIGN_END
|
||||
#define __ALIGN_END __attribute__((aligned(4)))
|
||||
#endif
|
||||
|
||||
#ifndef ARG_UNUSED
|
||||
#define ARG_UNUSED(x) (void)(x)
|
||||
#endif
|
||||
|
||||
#ifndef LO_BYTE
|
||||
#define LO_BYTE(x) ((uint8_t)(x & 0x00FF))
|
||||
#endif
|
||||
|
||||
#ifndef HI_BYTE
|
||||
#define HI_BYTE(x) ((uint8_t)((x & 0xFF00) >> 8))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef BCD
|
||||
#define BCD(x) ((((x) / 10) << 4) | ((x) % 10))
|
||||
#endif
|
||||
|
||||
#ifdef BIT
|
||||
#undef BIT
|
||||
#define BIT(n) (1UL << (n))
|
||||
#else
|
||||
#define BIT(n) (1UL << (n))
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(array) \
|
||||
((int)((sizeof(array) / sizeof((array)[0]))))
|
||||
#endif
|
||||
|
||||
#ifndef BSWAP16
|
||||
#define BSWAP16(u16) (__builtin_bswap16(u16))
|
||||
#endif
|
||||
#ifndef BSWAP32
|
||||
#define BSWAP32(u32) (__builtin_bswap32(u32))
|
||||
#endif
|
||||
|
||||
#define GET_BE16(field) \
|
||||
(((uint16_t)(field)[0] << 8) | ((uint16_t)(field)[1]))
|
||||
|
||||
#define GET_BE32(field) \
|
||||
(((uint32_t)(field)[0] << 24) | ((uint32_t)(field)[1] << 16) | ((uint32_t)(field)[2] << 8) | ((uint32_t)(field)[3] << 0))
|
||||
|
||||
#define SET_BE16(field, value) \
|
||||
do { \
|
||||
(field)[0] = (uint8_t)((value) >> 8); \
|
||||
(field)[1] = (uint8_t)((value) >> 0); \
|
||||
} while (0)
|
||||
|
||||
#define SET_BE24(field, value) \
|
||||
do { \
|
||||
(field)[0] = (uint8_t)((value) >> 16); \
|
||||
(field)[1] = (uint8_t)((value) >> 8); \
|
||||
(field)[2] = (uint8_t)((value) >> 0); \
|
||||
} while (0)
|
||||
|
||||
#define SET_BE32(field, value) \
|
||||
do { \
|
||||
(field)[0] = (uint8_t)((value) >> 24); \
|
||||
(field)[1] = (uint8_t)((value) >> 16); \
|
||||
(field)[2] = (uint8_t)((value) >> 8); \
|
||||
(field)[3] = (uint8_t)((value) >> 0); \
|
||||
} while (0)
|
||||
|
||||
#define WBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF)
|
||||
#define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF)
|
||||
|
||||
#define PP_NARG(...) \
|
||||
PP_NARG_(__VA_ARGS__, PP_RSEQ_N())
|
||||
#define PP_NARG_(...) \
|
||||
PP_ARG_N(__VA_ARGS__)
|
||||
#define PP_ARG_N( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
_61, _62, _63, N, ...) N
|
||||
#define PP_RSEQ_N() \
|
||||
63, 62, 61, 60, \
|
||||
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
|
||||
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
|
||||
39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
|
||||
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
|
||||
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
|
||||
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#include "usbh_core.h"
|
||||
#include "usb_hc.h"
|
||||
#include "usb_errno.h"
|
||||
#include "usb_log.h"
|
||||
#include "usb_list.h"
|
||||
#include "usb_util.h"
|
||||
// #include "libserial.h"
|
||||
|
||||
int main(){
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue