usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()

IMHO the current name is somewhat misleading:

- usb_drv_send() is blocking and we have usb_drv_send_nonblocking()
  for the non-blocking case. This inconsistent naming can only
  promote confusion. (And what would we call a blocking receive?)

- Other hardware abstraction APIs in Rockbox are usually blocking:
  storage, LCD, backlight, audio... in other words, blocking is the
  default expected behavior, with non-blocking calls being a rarity.

Change-Id: I05b41088d09eab582697674f4f06fdca0c8950af
This commit is contained in:
Aidan MacDonald 2021-09-19 10:54:26 +01:00
parent 99f333c64f
commit 672bbe434b
16 changed files with 36 additions and 38 deletions

View file

@ -531,9 +531,9 @@ static void in_callback(int ep, unsigned char *buf, int len)
usb_core_transfer_complete(ep, false, 0, len);
}
int usb_drv_recv(int ep, void* ptr, int length)
int usb_drv_recv_nonblocking(int ep, void* ptr, int length)
{
logf("usb_drv_recv(%d, 0x%x, %d)", ep, (int)ptr, length);
logf("usb_drv_recv_nonblocking(%d, 0x%x, %d)", ep, (int)ptr, length);
if(ep == EP_CONTROL && length == 0 && ptr == NULL)
{
usb_status_ack(ep, DIR_TX);

View file

@ -869,7 +869,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
/* This function begins a receive (on an OUT endpoint), it should not block
* so the actual receive is done in the interrupt handler.
*/
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
return mxx_queue(endpoint, ptr, length, false, false);
}

View file

@ -1333,7 +1333,7 @@ void usb_drv_release_endpoint(int endpoint)
usb_dw_target_enable_irq();
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
int epnum = EP_NUM(endpoint);
struct usb_dw_ep* dw_ep = usb_dw_get_ep(epnum, USB_DW_EPDIR_OUT);

View file

@ -68,8 +68,7 @@ void usb_drv_stall(int endpoint, bool stall,bool in);
bool usb_drv_stalled(int endpoint,bool in);
int usb_drv_send(int endpoint, void* ptr, int length);
int usb_drv_send_nonblocking(int endpoint, void* ptr, int length);
int usb_drv_recv(int endpoint, void* ptr, int length);
void usb_drv_ack(struct usb_ctrlrequest* req);
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length);
void usb_drv_set_address(int address);
void usb_drv_reset_endpoint(int endpoint, bool send);
bool usb_drv_powered(void);

View file

@ -412,12 +412,12 @@ void usb_drv_cancel_all_transfers(void)
restore_irq(flags);
}
int usb_drv_recv(int ep, void *ptr, int len)
int usb_drv_recv_nonblocking(int ep, void *ptr, int len)
{
struct usb_dev_dma_desc *uc_desc = endpoints[ep][1].uc_desc;
ep &= 0x7f;
logf("usb_drv_recv(%d,%x,%d)\n", ep, (int)ptr, len);
logf("usb_drv_recv_nonblocking(%d,%x,%d)\n", ep, (int)ptr, len);
if (len > USB_DMA_DESC_RXTX_BYTES)
panicf("usb_recv: len=%d > %d", len, USB_DMA_DESC_RXTX_BYTES);
@ -674,7 +674,8 @@ static void handle_out_ep(int ep)
* The usb_storage buffer is 63KB, but Linux sends 120KB.
* We get the first part, but upon re-enabling receive dma we
* get a 'buffer not available' error from the hardware, since
* we haven't gotten the next usb_drv_recv() from the stack yet.
* we haven't gotten the next usb_drv_recv_nonblocking() from
* the stack yet.
* It seems the NAK bit is ignored here and the HW tries to dma
* the incoming data anyway.
* In theory I think the BNA error should be recoverable, but

View file

@ -355,7 +355,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
}
/* Setup a receive transfer. (non blocking) */
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
logf("udc: recv(%x)", endpoint);
struct endpoint_t *ep;

View file

@ -1026,8 +1026,8 @@ static bool tnetv_handle_cppi(void)
if (rx_intstatus || tx_intstatus || rcv_sched)
{
/* Request calling again after short delay
* Needed when for example when OUT endpoint has pending
* data but the USB task did not call usb_drv_recv() yet.
* Needed when for example when OUT endpoint has pending data
* but the USB task did not call usb_drv_recv_nonblocking() yet.
*/
return true;
}
@ -1371,7 +1371,7 @@ int usb_drv_send_nonblocking(int endpoint, void* ptr, int length)
return _usb_drv_send(endpoint, ptr, length, false);
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
int epn = EP_NUM(endpoint);
struct ep_runtime_t *ep;
@ -1388,8 +1388,6 @@ int usb_drv_recv(int endpoint, void* ptr, int length)
return 0;
}
void usb_drv_ack(struct usb_ctrlrequest* req);
void usb_drv_set_address(int address)
{
UsbCtrlType usbCtrl;

View file

@ -593,7 +593,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return prime_transfer(EP_NUM(endpoint), ptr, length, true, true);
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
//logf("usbrecv(%x, %d)", ptr, length);
return prime_transfer(EP_NUM(endpoint), ptr, length, false, false);

View file

@ -166,7 +166,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
return 0;
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
ep_transfer(EP_NUM(endpoint), ptr, length, true);
return 0;

View file

@ -609,7 +609,7 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length)
return rc;
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
volatile struct tcc_ep *tcc_ep = &tcc_endpoints[endpoint & 0x7f];
int flags;

View file

@ -743,7 +743,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return 0;
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
int flags;
struct usb_endpoint *ep;

View file

@ -1118,7 +1118,7 @@ int usb_drv_send(int endpoint, void* ptr, int length)
return -1;
}
int usb_drv_recv(int endpoint, void* ptr, int length)
int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
{
int flags;
struct usb_endpoint *ep;

View file

@ -674,7 +674,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
if (ptr != response_data)
memcpy(response_data, ptr, length);
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, length);
}
}
@ -725,7 +725,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
case USB_REQ_GET_CONFIGURATION: {
logf("usb_core: GET_CONFIG");
response_data[0] = (usb_state == ADDRESS ? 0 : 1);
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 1);
break;
}
@ -759,7 +759,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
case USB_REQ_GET_STATUS:
response_data[0] = 0;
response_data[1] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2);
break;
default:
@ -781,7 +781,7 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
case USB_REQ_GET_INTERFACE:
logf("usb_core: GET_INTERFACE");
response_data[0] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 1);
break;
case USB_REQ_CLEAR_FEATURE:
@ -791,7 +791,7 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
case USB_REQ_GET_STATUS:
response_data[0] = 0;
response_data[1] = 0;
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2);
break;
default:
@ -860,7 +860,7 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req)
response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex),
EP_DIR(req->wIndex));
usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2);
break;
default:

View file

@ -693,7 +693,7 @@ static int usb_hid_set_report(struct usb_ctrlrequest *req)
}
memset(buf, 0, length);
usb_drv_recv(EP_CONTROL, buf, length);
usb_drv_recv_nonblocking(EP_CONTROL, buf, length);
#ifdef LOGF_ENABLE
if (buf[1] & 0x01)
@ -772,7 +772,7 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest)
if (dest != orig_dest)
{
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest);
return true;
}
@ -809,7 +809,7 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest)
if (dest != orig_dest)
{
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest);
}
else

View file

@ -294,7 +294,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
if (req->wLength == sizeof(line_coding))
{
/* Receive line coding into local copy */
usb_drv_recv(EP_CONTROL, &line_coding, sizeof(line_coding));
usb_drv_recv_nonblocking(EP_CONTROL, &line_coding, sizeof(line_coding));
usb_drv_send(EP_CONTROL, NULL, 0); /* ack */
handled = true;
}
@ -316,7 +316,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
if (req->wLength == sizeof(line_coding))
{
/* Send back line coding so host is happy */
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, &line_coding, sizeof(line_coding));
handled = true;
}
@ -329,7 +329,7 @@ bool usb_serial_control_request(struct usb_ctrlrequest* req, unsigned char* dest
void usb_serial_init_connection(void)
{
/* prime rx endpoint */
usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer);
usb_drv_recv_nonblocking(ep_out, receive_buffer, sizeof receive_buffer);
/* we come here too after a bus reset, so reset some data */
buffer_transitlength = 0;
@ -420,7 +420,7 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length)
/* Data received. TODO : Do something with it ? */
/* Get the next bit */
usb_drv_recv(ep_out, receive_buffer, sizeof receive_buffer);
usb_drv_recv_nonblocking(ep_out, receive_buffer, sizeof receive_buffer);
break;
case USB_DIR_IN:

View file

@ -470,7 +470,7 @@ void usb_storage_init_connection(void)
ramdisk_buffer = tb.transfer_buffer + ALLOCATE_BUFFER_SIZE;
#endif
#endif
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE);
usb_drv_recv_nonblocking(ep_out, cbw_buffer, MAX_CBW_SIZE);
int i;
for(i=0;i<storage_num_drives();i++) {
@ -685,7 +685,7 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des
if(skip_first) (*tb.max_lun) --;
#endif
logf("ums: getmaxlun");
usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */
usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */
usb_drv_send(EP_CONTROL, tb.max_lun, 1);
handled = true;
break;
@ -1187,14 +1187,14 @@ static void send_command_failed_result(void)
#if CONFIG_RTC
static void receive_time(void)
{
usb_drv_recv(ep_out, tb.transfer_buffer, 12);
usb_drv_recv_nonblocking(ep_out, tb.transfer_buffer, 12);
state = RECEIVING_TIME;
}
#endif /* CONFIG_RTC */
static void receive_block_data(void *data,int size)
{
usb_drv_recv(ep_out, data, size);
usb_drv_recv_nonblocking(ep_out, data, size);
state = RECEIVING_BLOCKS;
}
@ -1210,7 +1210,7 @@ static void send_csw(int status)
state = WAITING_FOR_CSW_COMPLETION_OR_COMMAND;
//logf("CSW: %X",status);
/* Already start waiting for the next command */
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE);
usb_drv_recv_nonblocking(ep_out, cbw_buffer, MAX_CBW_SIZE);
/* The next completed transfer will be either the CSW one
* or the new command */