usb: use negative values for error codes

This will allow usb_read_sync() to return a combined error code / size
read integer.
This commit is contained in:
Lephe 2023-03-04 11:01:28 +01:00
parent f4e13afa84
commit eb1f9a35a1
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 25 additions and 26 deletions

View file

@ -29,32 +29,32 @@ enum {
/* There are no interfaces */
USB_OPEN_NO_INTERFACE = 1,
/* There are more interfaces than supported (16) */
USB_OPEN_TOO_MANY_INTERFACES,
USB_OPEN_TOO_MANY_INTERFACES = -2,
/* There are not enough endpoint numbers for every interface, or there
are not enough pipes to set them up */
USB_OPEN_TOO_MANY_ENDPOINTS,
USB_OPEN_TOO_MANY_ENDPOINTS = -3,
/* There is not enough FIFO memory to use the requested buffer sizes */
USB_OPEN_NOT_ENOUGH_MEMORY,
USB_OPEN_NOT_ENOUGH_MEMORY = -4,
/* Information is missing, such as buffer size for some endpoints */
USB_OPEN_MISSING_DATA,
USB_OPEN_MISSING_DATA = -5,
/* Invalid parameters: bad endpoint numbers, bad buffer sizes... */
USB_OPEN_INVALID_PARAMS,
USB_OPEN_INVALID_PARAMS = -6,
/* USB interfaces are already opened */
USB_OPEN_ALREADY_OPEN,
USB_OPEN_ALREADY_OPEN = -7,
/* General timeout for a sync_timeout call */
USB_TIMEOUT = -8,
/* This pipe is busy with another call */
USB_BUSY = -9,
/* This pipe is busy (returned by usb_write_async()) */
USB_WRITE_BUSY,
/* Both FIFO controllers are busy, none is available to transfer */
USB_WRITE_NOFIFO,
/* Timeout */
USB_WRITE_TIMEOUT,
/* This pipe is busy (returned by usb_commit_async()) */
USB_COMMIT_BUSY,
USB_WRITE_NOFIFO = -10,
/* This pipe has no ongoing transfer to commit */
USB_COMMIT_INACTIVE,
/* Timeout */
USB_COMMIT_TIMEOUT,
USB_COMMIT_INACTIVE = -11,
/* This pipe is currently not receiving any data */
USB_READ_IDLE = -12,
/* No FIFO controller is available */
USB_READ_NOFIFO = -13,
};
/* usb_open(): Open the USB link

View file

@ -366,7 +366,7 @@ int usb_write_async(int pipe, void const *data, int size, bool use_dma,
{
asyncio_op_t *t = &pipe_transfers[pipe];
if(asyncio_op_busy(t))
return USB_WRITE_BUSY;
return USB_BUSY;
/* If this if the first write of a series, find a controller. */
/* TODO: usb_write_async(): TOC/TOU race on controller being free */
@ -401,17 +401,17 @@ int usb_write_sync_timeout(int pipe, void const *data, int size, bool use_dma,
break;
if(rc == USB_WRITE_NOFIFO)
USB_LOG("USB_WRITE_NOFIFO\n");
if(rc != USB_WRITE_BUSY)
if(rc != USB_BUSY)
return rc;
if(timeout_elapsed(timeout))
return USB_WRITE_TIMEOUT;
return USB_TIMEOUT;
sleep();
}
while(!flag)
{
if(timeout_elapsed(timeout))
return USB_WRITE_TIMEOUT;
return USB_TIMEOUT;
sleep();
}
return 0;
@ -426,7 +426,7 @@ int usb_commit_async(int pipe, gint_call_t callback)
{
asyncio_op_t *t = &pipe_transfers[pipe];
if(asyncio_op_busy(t))
return USB_COMMIT_BUSY;
return USB_BUSY;
if(t->type != ASYNCIO_WRITE || t->controller == NOF)
return USB_COMMIT_INACTIVE;
@ -473,10 +473,10 @@ int usb_commit_sync_timeout(int pipe, timeout_t const *timeout)
int rc = usb_commit_async(pipe, GINT_CALL_SET(&flag));
if(rc == 0)
break;
if(rc != USB_COMMIT_BUSY)
if(rc != USB_BUSY)
return rc;
if(timeout_elapsed(timeout))
return USB_COMMIT_TIMEOUT;
return USB_TIMEOUT;
sleep();
}
@ -484,7 +484,7 @@ int usb_commit_sync_timeout(int pipe, timeout_t const *timeout)
while(!flag)
{
if(timeout_elapsed(timeout))
return USB_COMMIT_TIMEOUT;
return USB_TIMEOUT;
sleep();
}
return 0;
@ -495,7 +495,6 @@ void usb_commit_sync(int pipe)
usb_commit_sync_timeout(pipe, NULL);
}
/* usb_pipe_write_bemp(): Callback for the BEMP interrupt on a pipe */
void usb_pipe_write_bemp(int pipe)
{
asyncio_op_t *t = &pipe_transfers[pipe];