Ignore:
File:
1 edited

Legend:

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

    r9d58539 rd93f5afb  
    3838#include <assert.h>
    3939
    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  */
    49 int 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  */
    62 int 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 /*----------------------------------------------------------------------------*/
    7040/** Try to clear endpoint halt of default control pipe.
    7141 *
     
    8555        pipe->auto_reset_halt = true;
    8656}
    87 /*----------------------------------------------------------------------------*/
     57
    8858/** Request a control read transfer on an endpoint pipe.
    8959 *
     
    12191        memcpy(&setup_packet, setup_buffer, 8);
    12292
     93        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    12394        size_t act_size = 0;
    124         const int rc = usb_device_control_read(pipe->wire,
     95        const int rc = usb_read(exch,
    12596            pipe->endpoint_no, setup_packet, buffer, buffer_size, &act_size);
     97        async_exchange_end(exch);
    12698
    12799        if (rc == ESTALL) {
     
    135107        return rc;
    136108}
    137 /*----------------------------------------------------------------------------*/
     109
    138110/** Request a control write transfer on an endpoint pipe.
    139111 *
     
    173145        memcpy(&setup_packet, setup_buffer, 8);
    174146
    175         const int rc = usb_device_control_write(pipe->wire,
     147        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     148        const int rc = usb_write(exch,
    176149            pipe->endpoint_no, setup_packet, buffer, buffer_size);
     150        async_exchange_end(exch);
    177151
    178152        if (rc == ESTALL) {
     
    182156        return rc;
    183157}
    184 /*----------------------------------------------------------------------------*/
     158
    185159/** Request a read (in) transfer on an endpoint pipe.
    186160 *
     
    217191            return ENOTSUP;
    218192
     193        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
    219194        size_t act_size = 0;
    220         const int rc = usb_device_read(pipe->wire,
    221             pipe->endpoint_no, buffer, size, &act_size);
     195        const int rc =
     196            usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size);
     197        async_exchange_end(exch);
    222198
    223199        if (rc == EOK && size_transfered != NULL) {
     
    227203        return rc;
    228204}
    229 /*----------------------------------------------------------------------------*/
     205
    230206/** Request a write (out) transfer on an endpoint pipe.
    231207 *
     
    256232            return ENOTSUP;
    257233
    258         return usb_device_write(pipe->wire,
    259             pipe->endpoint_no, buffer, size);
    260 }
    261 /*----------------------------------------------------------------------------*/
     234        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     235        const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size);
     236        async_exchange_end(exch);
     237        return rc;
     238}
     239
    262240/** Initialize USB endpoint pipe.
    263241 *
    264242 * @param pipe Endpoint pipe to be initialized.
    265  * @param connection Connection to the USB device backing this pipe (the wire).
    266243 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
    267244 * @param transfer_type Transfer type (e.g. interrupt or bulk).
     
    270247 * @return Error code.
    271248 */
    272 int usb_pipe_initialize(usb_pipe_t *pipe,
    273     usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
     249int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no,
    274250    usb_transfer_type_t transfer_type, size_t max_packet_size,
    275     usb_direction_t direction)
    276 {
    277         assert(pipe);
    278         assert(connection);
    279 
    280         pipe->wire = connection;
     251    usb_direction_t direction, usb_dev_session_t *bus_session)
     252{
     253        assert(pipe);
     254
    281255        pipe->endpoint_no = endpoint_no;
    282256        pipe->transfer_type = transfer_type;
     
    284258        pipe->direction = direction;
    285259        pipe->auto_reset_halt = false;
     260        pipe->bus_session = bus_session;
    286261
    287262        return EOK;
    288263}
    289 /*----------------------------------------------------------------------------*/
     264
    290265/** Initialize USB endpoint pipe as the default zero control pipe.
    291266 *
    292267 * @param pipe Endpoint pipe to be initialized.
    293  * @param connection Connection to the USB device backing this pipe (the wire).
    294268 * @return Error code.
    295269 */
    296270int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
    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);
     271    usb_dev_session_t *bus_session)
     272{
     273        assert(pipe);
     274
     275        const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,
     276            CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, bus_session);
    304277
    305278        pipe->auto_reset_halt = true;
     
    307280        return rc;
    308281}
    309 /*----------------------------------------------------------------------------*/
     282
    310283/** Register endpoint with the host controller.
    311284 *
     
    317290{
    318291        assert(pipe);
    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 /*----------------------------------------------------------------------------*/
     292        assert(pipe->bus_session);
     293        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     294        if (!exch)
     295                return ENOMEM;
     296        const int ret = usb_register_endpoint(exch, pipe->endpoint_no,
     297            pipe->transfer_type, pipe->direction, pipe->max_packet_size,
     298            interval);
     299        async_exchange_end(exch);
     300        return ret;
     301}
     302
    326303/** Revert endpoint registration with the host controller.
    327304 *
     
    332309{
    333310        assert(pipe);
    334         assert(pipe->wire);
    335 
    336         return usb_device_unregister_endpoint(pipe->wire,
    337             pipe->endpoint_no, pipe->direction);
     311        assert(pipe->bus_session);
     312        async_exch_t *exch = async_exchange_begin(pipe->bus_session);
     313        if (!exch)
     314                return ENOMEM;
     315        const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no,
     316            pipe->direction);
     317        async_exchange_end(exch);
     318        return ret;
    338319}
    339320
Note: See TracChangeset for help on using the changeset viewer.