Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipes.c

    r58563585 r9d58539  
    3535#include <usb/dev/pipes.h>
    3636#include <usb/dev/request.h>
    37 #include <usb/usb.h>
    38 #include <usb_iface.h>
    39 
     37#include <errno.h>
    4038#include <assert.h>
    41 #include <async.h>
    42 #include <errno.h>
    43 #include <mem.h>
    44 
     39
     40/** Prepare pipe for a long transfer.
     41 *
     42 * Long transfer is transfer consisting of several requests to the HC.
     43 * Calling this function is optional and it has positive effect of
     44 * improved performance because IPC session is initiated only once.
     45 *
     46 * @param pipe Pipe over which the transfer will happen.
     47 * @return Error code.
     48 */
     49int usb_pipe_start_long_transfer(usb_pipe_t *pipe)
     50{
     51        assert(pipe);
     52        assert(pipe->wire);
     53        assert(pipe->wire->hc_connection);
     54        return usb_hc_connection_open(pipe->wire->hc_connection);
     55}
     56/*----------------------------------------------------------------------------*/
     57/** Terminate a long transfer on a pipe.
     58 * @param pipe Pipe where to end the long transfer.
     59 * @return Error code.
     60 * @see usb_pipe_start_long_transfer
     61 */
     62int usb_pipe_end_long_transfer(usb_pipe_t *pipe)
     63{
     64        assert(pipe);
     65        assert(pipe->wire);
     66        assert(pipe->wire->hc_connection);
     67        return usb_hc_connection_close(pipe->wire->hc_connection);
     68}
     69/*----------------------------------------------------------------------------*/
    4570/** Try to clear endpoint halt of default control pipe.
    4671 *
     
    6085        pipe->auto_reset_halt = true;
    6186}
    62 
     87/*----------------------------------------------------------------------------*/
    6388/** Request a control read transfer on an endpoint pipe.
    6489 *
     
    96121        memcpy(&setup_packet, setup_buffer, 8);
    97122
    98         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    99123        size_t act_size = 0;
    100         const int rc = usb_read(exch, pipe->endpoint_no, setup_packet, buffer,
    101             buffer_size, &act_size);
    102         async_exchange_end(exch);
     124        const int rc = usb_device_control_read(pipe->wire,
     125            pipe->endpoint_no, setup_packet, buffer, buffer_size, &act_size);
    103126
    104127        if (rc == ESTALL) {
     
    112135        return rc;
    113136}
    114 
     137/*----------------------------------------------------------------------------*/
    115138/** Request a control write transfer on an endpoint pipe.
    116139 *
     
    150173        memcpy(&setup_packet, setup_buffer, 8);
    151174
    152         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    153         const int rc = usb_write(exch,
     175        const int rc = usb_device_control_write(pipe->wire,
    154176            pipe->endpoint_no, setup_packet, buffer, buffer_size);
    155         async_exchange_end(exch);
    156177
    157178        if (rc == ESTALL) {
     
    161182        return rc;
    162183}
    163 
     184/*----------------------------------------------------------------------------*/
    164185/** Request a read (in) transfer on an endpoint pipe.
    165186 *
     
    196217            return ENOTSUP;
    197218
    198         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    199219        size_t act_size = 0;
    200         const int rc =
    201             usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size);
    202         async_exchange_end(exch);
     220        const int rc = usb_device_read(pipe->wire,
     221            pipe->endpoint_no, buffer, size, &act_size);
    203222
    204223        if (rc == EOK && size_transfered != NULL) {
     
    208227        return rc;
    209228}
    210 
     229/*----------------------------------------------------------------------------*/
    211230/** Request a write (out) transfer on an endpoint pipe.
    212231 *
     
    237256            return ENOTSUP;
    238257
    239         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    240         const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size);
    241         async_exchange_end(exch);
    242         return rc;
    243 }
    244 
     258        return usb_device_write(pipe->wire,
     259            pipe->endpoint_no, buffer, size);
     260}
     261/*----------------------------------------------------------------------------*/
    245262/** Initialize USB endpoint pipe.
    246263 *
    247264 * @param pipe Endpoint pipe to be initialized.
     265 * @param connection Connection to the USB device backing this pipe (the wire).
    248266 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
    249267 * @param transfer_type Transfer type (e.g. interrupt or bulk).
     
    252270 * @return Error code.
    253271 */
    254 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no,
     272int usb_pipe_initialize(usb_pipe_t *pipe,
     273    usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
    255274    usb_transfer_type_t transfer_type, size_t max_packet_size,
    256     usb_direction_t direction, unsigned packets, usb_dev_session_t *bus_session)
    257 {
    258         assert(pipe);
    259 
     275    usb_direction_t direction)
     276{
     277        assert(pipe);
     278        assert(connection);
     279
     280        pipe->wire = connection;
    260281        pipe->endpoint_no = endpoint_no;
    261282        pipe->transfer_type = transfer_type;
    262         pipe->packets = packets;
    263283        pipe->max_packet_size = max_packet_size;
    264284        pipe->direction = direction;
    265285        pipe->auto_reset_halt = false;
    266         pipe->bus_session = bus_session;
    267286
    268287        return EOK;
    269288}
    270 
     289/*----------------------------------------------------------------------------*/
    271290/** Initialize USB endpoint pipe as the default zero control pipe.
    272291 *
    273292 * @param pipe Endpoint pipe to be initialized.
     293 * @param connection Connection to the USB device backing this pipe (the wire).
    274294 * @return Error code.
    275295 */
    276296int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
    277     usb_dev_session_t *bus_session)
    278 {
    279         assert(pipe);
    280 
    281         const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,
    282             CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, 1, bus_session);
     297    usb_device_connection_t *connection)
     298{
     299        assert(pipe);
     300        assert(connection);
     301
     302        int rc = usb_pipe_initialize(pipe, connection, 0, USB_TRANSFER_CONTROL,
     303            CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH);
    283304
    284305        pipe->auto_reset_halt = true;
     
    286307        return rc;
    287308}
    288 
     309/*----------------------------------------------------------------------------*/
    289310/** Register endpoint with the host controller.
    290311 *
     
    296317{
    297318        assert(pipe);
    298         assert(pipe->bus_session);
    299         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    300         if (!exch)
    301                 return ENOMEM;
    302         const int ret = usb_register_endpoint(exch, pipe->endpoint_no,
    303             pipe->transfer_type, pipe->direction, pipe->max_packet_size,
    304             pipe->packets, interval);
    305         async_exchange_end(exch);
    306         return ret;
    307 }
    308 
     319        assert(pipe->wire);
     320
     321        return usb_device_register_endpoint(pipe->wire,
     322           pipe->endpoint_no, pipe->transfer_type,
     323           pipe->direction, pipe->max_packet_size, interval);
     324}
     325/*----------------------------------------------------------------------------*/
    309326/** Revert endpoint registration with the host controller.
    310327 *
     
    315332{
    316333        assert(pipe);
    317         assert(pipe->bus_session);
    318         async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    319         if (!exch)
    320                 return ENOMEM;
    321         const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no,
    322             pipe->direction);
    323         async_exchange_end(exch);
    324         return ret;
     334        assert(pipe->wire);
     335
     336        return usb_device_unregister_endpoint(pipe->wire,
     337            pipe->endpoint_no, pipe->direction);
    325338}
    326339
Note: See TracChangeset for help on using the changeset viewer.