Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 34586183 in mainline


Ignore:
Timestamp:
2010-10-22T12:38:50Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
master
Children:
b791e3e
Parents:
6c741e1d
Message:

Add transfer-type methods to libusb

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/hcd.c

    r6c741e1d r34586183  
    211211}
    212212
     213
     214static int send_buffer(int phone, ipcarg_t method, usb_target_t target,
     215    void *buffer, size_t size, usb_transaction_handle_t * transaction_handle)
     216{
     217        if (phone < 0) {
     218                return EINVAL;
     219        }
     220       
     221        if ((buffer == NULL) && (size > 0)) {
     222                return EINVAL;
     223        }
     224
     225        ipc_call_t answer_data;
     226        ipcarg_t answer_rc;
     227        aid_t req;
     228        int rc;
     229       
     230        req = async_send_3(phone,
     231            method,
     232            target.address, target.endpoint,
     233            size,
     234            &answer_data);
     235       
     236        if (size > 0) {
     237                rc = async_data_write_start(phone, buffer, size);
     238                if (rc != EOK) {
     239                        async_wait_for(req, NULL);
     240                        return rc;
     241                }
     242        }
     243       
     244        async_wait_for(req, &answer_rc);
     245        rc = (int)answer_rc;
     246        if (rc != EOK) {
     247                return rc;
     248        }
     249       
     250        if (transaction_handle != NULL) {
     251                *transaction_handle = IPC_GET_ARG1(answer_data);
     252        }
     253       
     254        return EOK;
     255}
     256
     257
     258static int prep_receive_data(int phone, ipcarg_t method, usb_target_t target,
     259    size_t size, usb_transaction_handle_t * transaction_handle)
     260{
     261        if (phone < 0) {
     262                return EINVAL;
     263        }
     264       
     265        usb_transaction_handle_t handle;
     266       
     267        int rc = ipc_call_sync_3_1(phone,
     268            method,
     269            target.address, target.endpoint,
     270            size,
     271            &handle);
     272       
     273        if (rc != EOK) {
     274                return rc;
     275        }
     276       
     277        if (transaction_handle != NULL) {
     278                *transaction_handle = handle;
     279        }
     280       
     281        return EOK;
     282}
     283
     284
     285int usb_hcd_transfer_interrupt_out(int hcd_phone, usb_target_t target,
     286    void *buffer, size_t size, usb_transaction_handle_t *handle)
     287{
     288        return send_buffer(hcd_phone, IPC_M_USB_HCD_INTERRUPT_OUT,
     289            target, buffer, size, handle);
     290}
     291
     292int usb_hcd_transfer_interrupt_in(int hcd_phone, usb_target_t target,
     293    size_t size, usb_transaction_handle_t *handle)
     294{
     295        return prep_receive_data(hcd_phone, IPC_M_USB_HCD_INTERRUPT_IN,
     296            target, size, handle);
     297}
     298
     299int usb_hcd_transfer_control_write_setup(int hcd_phone, usb_target_t target,
     300    void *buffer, size_t size, usb_transaction_handle_t *handle)
     301{
     302        return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_SETUP,
     303            target, buffer, size, handle);
     304}
     305
     306int usb_hcd_transfer_control_write_data(int hcd_phone, usb_target_t target,
     307    void *buffer, size_t size, usb_transaction_handle_t *handle)
     308{
     309        return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_DATA,
     310            target, buffer, size, handle);
     311       
     312}
     313int usb_hcd_transfer_control_write_status(int hcd_phone, usb_target_t target,
     314    usb_transaction_handle_t *handle)
     315{
     316        usb_transaction_handle_t h;
     317        int rc = ipc_call_sync_2_1(hcd_phone,
     318            IPC_M_USB_HCD_CONTROL_WRITE_STATUS,
     319            target.address, target.endpoint,
     320            &h);
     321        if (rc != EOK) {
     322                return rc;
     323        }
     324       
     325        if (handle != NULL) {
     326                *handle = h;
     327        }
     328       
     329        return rc;
     330}
     331
     332int usb_hcd_transfer_control_read_setup(int hcd_phone, usb_target_t target,
     333    void *buffer, size_t size, usb_transaction_handle_t *handle)
     334{
     335        return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_SETUP,
     336            target, buffer, size, handle);
     337}
     338int usb_hcd_transfer_control_read_data(int hcd_phone, usb_target_t target,
     339    size_t size, usb_transaction_handle_t *handle)
     340{
     341        return prep_receive_data(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_DATA,
     342           target, size, handle);
     343}
     344int usb_hcd_transfer_control_read_status(int hcd_phone, usb_target_t target,
     345    usb_transaction_handle_t *handle)
     346{
     347        usb_transaction_handle_t h;
     348        int rc = ipc_call_sync_2_1(hcd_phone,
     349            IPC_M_USB_HCD_CONTROL_READ_STATUS,
     350            target.address, target.endpoint,
     351            &h);
     352        if (rc != EOK) {
     353                return rc;
     354        }
     355       
     356        if (handle != NULL) {
     357                *handle = h;
     358        }
     359       
     360        return rc;
     361}
     362
     363
     364
    213365/**
    214366 * @}
  • uspace/lib/usb/hcd.h

    r6c741e1d r34586183  
    5656} usb_transaction_outcome_t;
    5757
     58/** USB packet identifier. */
     59typedef enum {
     60#define _MAKE_PID_NIBBLE(tag, type) \
     61        ((uint8_t)(((tag) << 2) | (type)))
     62#define _MAKE_PID(tag, type) \
     63        ( \
     64            _MAKE_PID_NIBBLE(tag, type) \
     65            | ((~_MAKE_PID_NIBBLE(tag, type)) << 4) \
     66        )
     67        USB_PID_OUT = _MAKE_PID(0, 1),
     68        USB_PID_IN = _MAKE_PID(2, 1),
     69        USB_PID_SOF = _MAKE_PID(1, 1),
     70        USB_PID_SETUP = _MAKE_PID(3, 1),
     71       
     72        USB_PID_DATA0 = _MAKE_PID(0 ,3),
     73        USB_PID_DATA1 = _MAKE_PID(2 ,3),
     74       
     75        USB_PID_ACK = _MAKE_PID(0 ,2),
     76        USB_PID_NAK = _MAKE_PID(2 ,2),
     77        USB_PID_STALL = _MAKE_PID(3 ,2),
     78       
     79        USB_PID_PRE = _MAKE_PID(3 ,0),
     80        /* USB_PID_ = _MAKE_PID( ,), */
     81#undef _MAKE_PID
     82#undef _MAKE_PID_NIBBLE
     83} usb_packet_id;
     84
    5885const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
    5986
     
    116143         * - buffer size (in bytes):
    117144         */
    118         IPC_M_USB_HCD_TRANSACTION_SIZE
     145        IPC_M_USB_HCD_TRANSACTION_SIZE,
     146       
     147       
     148        IPC_M_USB_HCD_INTERRUPT_OUT,
     149        IPC_M_USB_HCD_INTERRUPT_IN,
     150       
     151        IPC_M_USB_HCD_CONTROL_WRITE_SETUP,
     152        IPC_M_USB_HCD_CONTROL_WRITE_DATA,
     153        IPC_M_USB_HCD_CONTROL_WRITE_STATUS,
     154       
     155        IPC_M_USB_HCD_CONTROL_READ_SETUP,
     156        IPC_M_USB_HCD_CONTROL_READ_DATA,
     157        IPC_M_USB_HCD_CONTROL_READ_STATUS,
     158        /* IPC_M_USB_HCD_ */
    119159} usb_hcd_method_t;
    120160
     
    143183        /** Notification about a serious trouble with HC.
    144184         */
    145         IPC_M_USB_HCD_CONTROLLER_FAILURE
     185        IPC_M_USB_HCD_CONTROLLER_FAILURE,
     186       
     187       
     188        IPC_M_USB_HCD_INTERRUPT_OUT_DONE,
     189        IPC_M_USB_HCD_INTERRUPT_IN_DONE,
     190       
     191        IPC_M_USB_HCD_CONTROL_WRITE_SETUP_DONE,
     192        IPC_M_USB_HCD_CONTROL_WRITE_DATA_DONE,
     193        IPC_M_USB_HCD_CONTROL_WRITE_STATUS_DONE,
     194       
     195        IPC_M_USB_HCD_CONTROL_READ_SETUP_DONE,
     196        IPC_M_USB_HCD_CONTROL_READ_DATA_DONE,
     197        IPC_M_USB_HCD_CONTROL_READ_STATUS_DONE,
     198       
     199        /* IPC_M_USB_HCD_ */
    146200} usb_hcd_callback_method_t;
    147201
     
    152206int usb_hcd_prepare_data_reception(int, usb_target_t, usb_transfer_type_t,
    153207    size_t, usb_transaction_handle_t *);
     208
     209
     210int usb_hcd_transfer_interrupt_out(int, usb_target_t,
     211    void *, size_t, usb_transaction_handle_t *);
     212int usb_hcd_transfer_interrupt_in(int, usb_target_t,
     213    size_t, usb_transaction_handle_t *);
     214
     215int usb_hcd_transfer_control_write_setup(int, usb_target_t,
     216    void *, size_t, usb_transaction_handle_t *);
     217int usb_hcd_transfer_control_write_data(int, usb_target_t,
     218    void *, size_t, usb_transaction_handle_t *);
     219int usb_hcd_transfer_control_write_status(int, usb_target_t,
     220    usb_transaction_handle_t *);
     221
     222int usb_hcd_transfer_control_read_setup(int, usb_target_t,
     223    void *, size_t, usb_transaction_handle_t *);
     224int usb_hcd_transfer_control_read_data(int, usb_target_t,
     225    size_t, usb_transaction_handle_t *);
     226int usb_hcd_transfer_control_read_status(int, usb_target_t,
     227    usb_transaction_handle_t *);
    154228
    155229#endif
Note: See TracChangeset for help on using the changeset viewer.