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

Changeset 710f518 in mainline


Ignore:
Timestamp:
2010-11-28T17:43:45Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
36bcf84f, fb1dca09
Parents:
a3dfb2e
Message:

Add remote implementation of USBHC interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/remotedrv.c

    ra3dfb2e r710f518  
    4242
    4343static int remote_get_address(device_t *, devman_handle_t, usb_address_t *);
     44
    4445static int remote_interrupt_out(device_t *, usb_target_t, void *, size_t,
    4546    usbhc_iface_transfer_out_callback_t, void *);
     
    4748    usbhc_iface_transfer_in_callback_t, void *);
    4849
     50static int remote_control_write_setup(device_t *, usb_target_t,
     51    void *, size_t,
     52    usbhc_iface_transfer_out_callback_t, void *);
     53static int remote_control_write_data(device_t *, usb_target_t,
     54    void *, size_t,
     55    usbhc_iface_transfer_out_callback_t, void *);
     56static int remote_control_write_status(device_t *, usb_target_t,
     57    usbhc_iface_transfer_in_callback_t, void *);
     58
     59static int remote_control_read_setup(device_t *, usb_target_t,
     60    void *, size_t,
     61    usbhc_iface_transfer_out_callback_t, void *);
     62static int remote_control_read_data(device_t *, usb_target_t,
     63    void *, size_t,
     64    usbhc_iface_transfer_in_callback_t, void *);
     65static int remote_control_read_status(device_t *, usb_target_t,
     66    usbhc_iface_transfer_out_callback_t, void *);
     67
    4968/** Implementation of USB HC interface. */
    5069usbhc_iface_t usbhc_interface = {
    5170        .tell_address = remote_get_address,
    5271        .interrupt_out = remote_interrupt_out,
    53         .interrupt_in = remote_interrupt_in
     72        .interrupt_in = remote_interrupt_in,
     73        .control_write_setup = remote_control_write_setup,
     74        .control_write_data = remote_control_write_data,
     75        .control_write_status = remote_control_write_status,
     76        .control_read_setup = remote_control_read_setup,
     77        .control_read_data = remote_control_read_data,
     78        .control_read_status = remote_control_read_status
    5479};
    5580
     
    224249}
    225250
    226 /** Callback for IN transfers.
    227  * This callback is called by implementation of HC operations.
    228  *
    229  * @param hc Host controller that processed the transfer.
    230  * @param outcome Transfer outcome.
    231  * @param actual_size Size of actually received data.
    232  * @param arg Custom argument.
    233  */
    234 static void remote_in_callback(usb_hc_device_t *hc,
    235     usb_transaction_outcome_t outcome, size_t actual_size, void *arg)
    236 {
    237         transfer_info_t *transfer = (transfer_info_t *) arg;
    238         transfer->in_callback(hc->generic, outcome, actual_size, transfer->arg);
    239 
    240         transfer_info_destroy(transfer);
    241 }
    242 
    243 /** Start an IN transfer.
     251/** Start a SETUP transfer.
    244252 *
    245253 * @param dev Device that shall process the transfer.
     
    252260 * @return Error code.
    253261 */
     262static int remote_setup_transfer(device_t *dev, usb_target_t target,
     263    usb_transfer_type_t transfer_type, void *data, size_t size,
     264    usbhc_iface_transfer_out_callback_t callback, void *arg)
     265{
     266        usb_hc_device_t *hc = (usb_hc_device_t *) dev->driver_data;
     267
     268        if ((hc->transfer_ops == NULL)
     269            || (hc->transfer_ops->transfer_setup == NULL)) {
     270                return ENOTSUP;
     271        }
     272
     273        transfer_info_t *transfer = transfer_info_create(
     274            create_attached_device_info(target.address),
     275            create_endpoint_info(target.endpoint,
     276                USB_DIRECTION_OUT, transfer_type),
     277            arg);
     278        transfer->out_callback = callback;
     279
     280        int rc = hc->transfer_ops->transfer_setup(hc,
     281            transfer->device, transfer->endpoint,
     282            data, size,
     283            remote_out_callback, transfer);
     284
     285        if (rc != EOK) {
     286                transfer_info_destroy(transfer);
     287                return rc;
     288        }
     289
     290        return EOK;
     291}
     292
     293/** Callback for IN transfers.
     294 * This callback is called by implementation of HC operations.
     295 *
     296 * @param hc Host controller that processed the transfer.
     297 * @param outcome Transfer outcome.
     298 * @param actual_size Size of actually received data.
     299 * @param arg Custom argument.
     300 */
     301static void remote_in_callback(usb_hc_device_t *hc,
     302    usb_transaction_outcome_t outcome, size_t actual_size, void *arg)
     303{
     304        transfer_info_t *transfer = (transfer_info_t *) arg;
     305        transfer->in_callback(hc->generic, outcome, actual_size, transfer->arg);
     306
     307        transfer_info_destroy(transfer);
     308}
     309
     310/** Start an IN transfer.
     311 *
     312 * @param dev Device that shall process the transfer.
     313 * @param target Target device for the data.
     314 * @param transfer_type Transfer type.
     315 * @param data Data buffer.
     316 * @param size Size of data buffer.
     317 * @param callback Callback after transfer is complete.
     318 * @param arg Custom argument to the callback.
     319 * @return Error code.
     320 */
    254321static int remote_in_transfer(device_t *dev, usb_target_t target,
    255322    usb_transfer_type_t transfer_type, void *data, size_t size,
     
    320387
    321388
     389int remote_control_write_setup(device_t *device, usb_target_t target,
     390    void *buffer, size_t size,
     391    usbhc_iface_transfer_out_callback_t callback, void *arg)
     392{
     393        return remote_setup_transfer(device, target, USB_TRANSFER_CONTROL,
     394            buffer, size, callback, arg);
     395}
     396
     397int remote_control_write_data(device_t *device, usb_target_t target,
     398    void *buffer, size_t size,
     399    usbhc_iface_transfer_out_callback_t callback, void *arg)
     400{
     401        return remote_out_transfer(device, target, USB_TRANSFER_CONTROL,
     402            buffer, size, callback, arg);
     403}
     404
     405int remote_control_write_status(device_t *device, usb_target_t target,
     406    usbhc_iface_transfer_in_callback_t callback, void *arg)
     407{
     408        return remote_in_transfer(device, target, USB_TRANSFER_CONTROL,
     409            NULL, 0, callback, arg);
     410}
     411
     412int remote_control_read_setup(device_t *device, usb_target_t target,
     413    void *buffer, size_t size,
     414    usbhc_iface_transfer_out_callback_t callback, void *arg)
     415{
     416        return remote_setup_transfer(device, target, USB_TRANSFER_CONTROL,
     417            buffer, size, callback, arg);
     418}
     419
     420int remote_control_read_data(device_t *dev, usb_target_t target,
     421    void *buffer, size_t size,
     422    usbhc_iface_transfer_in_callback_t callback, void *arg)
     423{
     424        return remote_in_transfer(dev, target, USB_TRANSFER_CONTROL,
     425            buffer, size, callback, arg);
     426}
     427
     428int remote_control_read_status(device_t *device, usb_target_t target,
     429    usbhc_iface_transfer_out_callback_t callback, void *arg)
     430{
     431        return remote_out_transfer(device, target, USB_TRANSFER_CONTROL,
     432            NULL, 0, callback, arg);
     433}
     434
    322435/**
    323436 * @}
Note: See TracChangeset for help on using the changeset viewer.