Changeset 43f698b in mainline


Ignore:
Timestamp:
2011-01-30T21:41:53Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54b5625
Parents:
6865243c
Message:

Add prototype implementation of endpoint pipe functions

Location:
uspace/lib/usb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/pipes.h

    r6865243c r43f698b  
    4949        /** Handle of the host controller device is connected to. */
    5050        devman_handle_t hc_handle;
     51        /** Address of the device. */
     52        usb_address_t address;
    5153} usb_device_connection_t;
    5254
  • uspace/lib/usb/include/usb/usb.h

    r6865243c r43f698b  
    5252typedef enum {
    5353        USB_DIRECTION_IN,
    54         USB_DIRECTION_OUT
     54        USB_DIRECTION_OUT,
     55        USB_DIRECTION_BOTH
    5556} usb_direction_t;
    5657
  • uspace/lib/usb/src/pipes.c

    r6865243c r43f698b  
    4545#include <usb/pipes.h>
    4646#include <errno.h>
     47#include <assert.h>
     48#include <usb/usbdrv.h>
     49
     50#define _PREPARE_TARGET(varname, pipe) \
     51        usb_target_t varname = { \
     52                .address = (pipe)->wire->address, \
     53                .endpoint = (pipe)->endpoint_no \
     54        }
    4755
    4856/** Initialize connection to USB device.
     
    5563    device_t *device)
    5664{
    57         return ENOTSUP;
     65        assert(connection);
     66        assert(device);
     67
     68        int rc;
     69        devman_handle_t hc_handle;
     70        usb_address_t my_address;
     71
     72        rc = usb_drv_find_hc(device, &hc_handle);
     73        if (rc != EOK) {
     74                return rc;
     75        }
     76
     77        int hc_phone = devman_device_connect(hc_handle, 0);
     78        if (hc_phone < 0) {
     79                return hc_phone;
     80        }
     81
     82        my_address = usb_drv_get_my_address(hc_phone, device);
     83        if (my_address < 0) {
     84                return my_address;
     85        }
     86
     87        connection->hc_handle = hc_handle;
     88        connection->address = my_address;
     89        return EOK;
    5890}
    5991
     
    72104    usb_transfer_type_t transfer_type, usb_direction_t direction)
    73105{
    74         return ENOTSUP;
     106        assert(pipe);
     107        assert(connection);
     108
     109        pipe->wire = connection;
     110        pipe->hc_phone = -1;
     111        pipe->endpoint_no = endpoint_no;
     112        pipe->transfer_type = transfer_type;
     113        pipe->direction = direction;
     114
     115        return EOK;
    75116}
    76117
     
    85126    usb_device_connection_t *connection)
    86127{
    87         return ENOTSUP;
     128        assert(pipe);
     129        assert(connection);
     130
     131        int rc = usb_endpoint_pipe_initialize(pipe, connection,
     132            0, USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH);
     133
     134        return rc;
    88135}
    89136
     
    106153int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *pipe)
    107154{
    108         return ENOTSUP;
     155        assert(pipe);
     156
     157        if (pipe->hc_phone >= 0) {
     158                return EBUSY;
     159        }
     160
     161        int phone = devman_device_connect(pipe->wire->hc_handle, 0);
     162        if (phone < 0) {
     163                return phone;
     164        }
     165
     166        pipe->hc_phone = phone;
     167
     168        return EOK;
    109169}
    110170
     
    119179int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *pipe)
    120180{
    121         return ENOTSUP;
     181        assert(pipe);
     182
     183        if (pipe->hc_phone < 0) {
     184                return ENOENT;
     185        }
     186
     187        int rc = ipc_hangup(pipe->hc_phone);
     188        if (rc != EOK) {
     189                return rc;
     190        }
     191
     192        pipe->hc_phone = -1;
     193
     194        return EOK;
    122195}
    123196
     
    134207    void *buffer, size_t size, size_t *size_transfered)
    135208{
    136         return ENOTSUP;
     209        assert(pipe);
     210
     211        int rc;
     212        usb_handle_t handle;
     213
     214        rc = usb_endpoint_pipe_async_read(pipe, buffer, size, size_transfered,
     215            &handle);
     216        if (rc != EOK) {
     217                return rc;
     218        }
     219
     220        rc = usb_endpoint_pipe_wait_for(pipe, handle);
     221        return rc;
    137222}
    138223
     
    147232    void *buffer, size_t size)
    148233{
    149         return ENOTSUP;
     234        assert(pipe);
     235
     236        int rc;
     237        usb_handle_t handle;
     238
     239        rc = usb_endpoint_pipe_async_write(pipe, buffer, size, &handle);
     240        if (rc != EOK) {
     241                return rc;
     242        }
     243
     244        rc = usb_endpoint_pipe_wait_for(pipe, handle);
     245        return rc;
    150246}
    151247
     
    204300    usb_handle_t *handle)
    205301{
    206         return ENOTSUP;
     302        assert(pipe);
     303
     304        if (pipe->hc_phone < 0) {
     305                return EBADF;
     306        }
     307
     308        if (pipe->direction != USB_DIRECTION_IN) {
     309                return EBADF;
     310        }
     311
     312        int rc;
     313        _PREPARE_TARGET(target, pipe);
     314
     315        switch (pipe->transfer_type) {
     316                case USB_TRANSFER_INTERRUPT:
     317                        rc = usb_drv_async_interrupt_in(pipe->hc_phone, target,
     318                            buffer, size, size_transfered, handle);
     319                        break;
     320                case USB_TRANSFER_CONTROL:
     321                        rc = EBADF;
     322                        break;
     323                default:
     324                        rc = ENOTSUP;
     325                        break;
     326        }
     327
     328        return rc;
    207329}
    208330
     
    220342    usb_handle_t *handle)
    221343{
    222         return ENOTSUP;
     344        assert(pipe);
     345
     346        if (pipe->hc_phone < 0) {
     347                return EBADF;
     348        }
     349
     350        if (pipe->direction != USB_DIRECTION_OUT) {
     351                return EBADF;
     352        }
     353
     354        int rc;
     355        _PREPARE_TARGET(target, pipe);
     356
     357        switch (pipe->transfer_type) {
     358                case USB_TRANSFER_INTERRUPT:
     359                        rc = usb_drv_async_interrupt_out(pipe->hc_phone, target,
     360                            buffer, size, handle);
     361                        break;
     362                case USB_TRANSFER_CONTROL:
     363                        rc = EBADF;
     364                        break;
     365                default:
     366                        rc = ENOTSUP;
     367                        break;
     368        }
     369
     370        return rc;
    223371}
    224372
     
    278426int usb_endpoint_pipe_wait_for(usb_endpoint_pipe_t *pipe, usb_handle_t handle)
    279427{
    280         return ENOTSUP;
     428        return usb_drv_async_wait_for(handle);
    281429}
    282430
Note: See TracChangeset for help on using the changeset viewer.