Changeset 0816c2e in mainline


Ignore:
Timestamp:
2013-01-04T11:22:10Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b4c1c95
Parents:
17bbb28
Message:

libusbhost: Add hcd endpoint manipulation wrappers

Location:
uspace/lib/usbhost
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r17bbb28 r0816c2e  
    8282}
    8383
     84int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
     85    usb_transfer_type_t type, size_t max_packet_size, size_t size);
     86
     87int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir);
     88
    8489int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
    8590    void *data, size_t size, uint64_t setup_data,
  • uspace/lib/usbhost/src/hcd.c

    r17bbb28 r0816c2e  
    6262        hcd->ep_remove_hook = NULL;
    6363}
     64
     65/** Calls ep_add_hook upon endpoint registration.
     66 * @param ep Endpoint to be registered.
     67 * @param arg hcd_t in disguise.
     68 * @return Error code.
     69 */
     70static int register_helper(endpoint_t *ep, void *arg)
     71{
     72        hcd_t *hcd = arg;
     73        assert(ep);
     74        assert(hcd);
     75        if (hcd->ep_add_hook)
     76                return hcd->ep_add_hook(hcd, ep);
     77        return EOK;
     78}
     79
     80
     81/** Calls ep_remove_hook upon endpoint removal.
     82 * @param ep Endpoint to be unregistered.
     83 * @param arg hcd_t in disguise.
     84 */
     85static void unregister_helper(endpoint_t *ep, void *arg)
     86{
     87        hcd_t *hcd = arg;
     88        assert(ep);
     89        assert(hcd);
     90        if (hcd->ep_remove_hook)
     91                hcd->ep_remove_hook(hcd, ep);
     92}
     93
     94int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
     95    usb_transfer_type_t type, size_t max_packet_size, size_t size)
     96{
     97        assert(hcd);
     98        usb_speed_t speed = USB_SPEED_MAX;
     99        const int ret = usb_device_manager_get_info_by_address(
     100            &hcd->dev_manager, target.address, NULL, &speed);
     101        if (ret != EOK) {
     102                return ret;
     103        }
     104        return usb_endpoint_manager_add_ep(&hcd->ep_manager, target.address,
     105            target.endpoint, dir, type, speed, max_packet_size, size,
     106            register_helper, hcd);
     107}
     108
     109int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir)
     110{
     111        assert(hcd);
     112        return usb_endpoint_manager_remove_ep(&hcd->ep_manager, target.address,
     113            target.endpoint, dir, unregister_helper, hcd);
     114}
     115
    64116
    65117typedef struct {
  • uspace/lib/usbhost/src/iface.c

    r17bbb28 r0816c2e  
    4242#include "ddf_helpers.h"
    4343
    44 /** Calls ep_add_hook upon endpoint registration.
    45  * @param ep Endpoint to be registered.
    46  * @param arg hcd_t in disguise.
    47  * @return Error code.
    48  */
    49 static int register_helper(endpoint_t *ep, void *arg)
    50 {
    51         hcd_t *hcd = arg;
    52         assert(ep);
    53         assert(hcd);
    54         if (hcd->ep_add_hook)
    55                 return hcd->ep_add_hook(hcd, ep);
    56         return EOK;
    57 }
    58 
    59 /** Calls ep_remove_hook upon endpoint removal.
    60  * @param ep Endpoint to be unregistered.
    61  * @param arg hcd_t in disguise.
    62  */
    63 static void unregister_helper(endpoint_t *ep, void *arg)
    64 {
    65         hcd_t *hcd = arg;
    66         assert(ep);
    67         assert(hcd);
    68         if (hcd->ep_remove_hook)
    69                 hcd->ep_remove_hook(hcd, ep);
    70 }
    71 
    7244/** Calls ep_remove_hook upon endpoint removal. Prints warning.
    7345 * @param ep Endpoint to be unregistered.
     
    181153        assert(hcd);
    182154        const size_t size = max_packet_size;
    183         usb_speed_t speed = USB_SPEED_MAX;
    184         const int ret = usb_device_manager_get_info_by_address(
    185             &hcd->dev_manager, address, NULL, &speed);
    186         if (ret != EOK) {
    187                 return ret;
    188         }
    189 
    190         usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
     155        const usb_target_t target = {{.address = address, .endpoint = endpoint}};
     156       
     157        usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
    191158            address, endpoint, usb_str_transfer_type(transfer_type),
    192             usb_str_direction(direction), usb_str_speed(speed),
    193             max_packet_size, interval);
    194 
    195         return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint,
    196             direction, transfer_type, speed, max_packet_size, size,
    197             register_helper, hcd);
     159            usb_str_direction(direction), max_packet_size, interval);
     160
     161        return hcd_add_ep(hcd, target, direction, transfer_type,
     162            max_packet_size, size);
    198163}
    199164
     
    212177        hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
    213178        assert(hcd);
     179        const usb_target_t target = {{.address = address, .endpoint = endpoint}};
    214180        usb_log_debug("Unregister endpoint %d:%d %s.\n",
    215181            address, endpoint, usb_str_direction(direction));
    216         return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address,
    217             endpoint, direction, unregister_helper, hcd);
     182        return hcd_remove_ep(hcd, target, direction);
    218183}
    219184
Note: See TracChangeset for help on using the changeset viewer.