Once the transaction has completed, the associated waiting structure will be used to notify the driver that the transaction has completed. If the transaction failed with an error, the pipe may have become halted and the driver will have to take action to clear the error condition and restart the pipe.
If a pipe has become halted indicated by a transaction result of USB_TRANSACTION_RESULT_HALTED the pipe must be cleared before any more transactions can be performed. This is achieved using the usb_pipe_clear(USB_PipeClear (SWI&5538D)) specifying the USB_PIPE_CLEAR_ACTIVATE flag.
A device may stall a pipe indicated by a transaction result of USB_TRANSACTION_RESULT_STALL. This condition is distinct from a simple halt and requires special steps to clear the condition if the limitations are acceptable the driver may simply call the support routine usb_clear_pipe_halt. If this is unacceptable a routine such as the following may be used.
int pipe_clear_stall(usb_pipe_t * defpipe, usb_pipe_t * pipe, usb_io_buffer * urb) { int result; waiting *req; waiting wait; wait.size = sizeof(wait); wait.mode = WAITING_TYPE_LOOP; req=usb_send_clear_halt(pipe,defpipe, urb,wait, &result); if (result != USB_RESULT_OK) { /* need to do some error recovery */ return -1; } result = usb_request_get_state(req, NULL); if(result != USB_TRANSACTION_RESULT_OK) { /* need to do some error recovery */ return -1; } usb_pipe_clear(pipe, USB_PIPE_CLEAR_TOGGLE | USB_PIPE_CLEAR_ACTIVATE); return 0; } |
The full list of result codes can be found Table A.3, “Request States”. However the most common ones are listed in more detail here.
The transaction completed normally, further transactions may be attempted.
The transaction is still in progress. This indicates to a driver that the transaction has yet to complete, and another attempt to read the status should be made later.
The transaction was halted by the device. For a normal pipe, the state of the pipe is set to halted and the pending transactions cleared.
For a control transaction, this means that the device did not accept the transaction, but the pipe is not placed into the halted state. Further transactions can be attempted on this pipe.
For receives, this is generated if the size of the transaction returned from the device is not equal to the URBs used_size field if the USB_TRANSACTION_EXACT_SIZE flag is set.
For transmits, this means that the driver attempted to send too much data to the endpoint for the device to handle.