usb_endpoint_manager.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Jan Vesely
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00039 #ifndef LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H
00040 #define LIBUSBHOST_HOST_YSB_ENDPOINT_MANAGER_H
00041 
00042 #include <stdlib.h>
00043 #include <adt/hash_table.h>
00044 #include <fibril_synch.h>
00045 #include <usb/usb.h>
00046 #include <usb/host/endpoint.h>
00047 
00048 #define BANDWIDTH_TOTAL_USB11 12000000
00049 #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
00050 
00051 typedef struct usb_endpoint_manager {
00052         hash_table_t ep_table;
00053         fibril_mutex_t guard;
00054         fibril_condvar_t change;
00055         size_t free_bw;
00056 } usb_endpoint_manager_t;
00057 
00058 size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
00059     size_t size, size_t max_packet_size);
00060 
00061 int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
00062     size_t available_bandwidth);
00063 
00064 void usb_endpoint_manager_destroy(usb_endpoint_manager_t *instance);
00065 
00066 int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
00067     endpoint_t *ep, size_t data_size);
00068 
00069 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance,
00070     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
00071 
00072 endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
00073     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
00074     size_t *bw);
00075 
00076 void usb_endpoint_manager_reset_if_need(
00077     usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data);
00078 
00079 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
00080     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
00081     usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
00082     size_t data_size)
00083 {
00084         endpoint_t *ep = malloc(sizeof(endpoint_t));
00085         if (ep == NULL)
00086                 return ENOMEM;
00087 
00088         int ret = endpoint_init(ep, address, endpoint, direction, type, speed,
00089             max_packet_size);
00090         if (ret != EOK) {
00091                 free(ep);
00092                 return ret;
00093         }
00094 
00095         ret = usb_endpoint_manager_register_ep(instance, ep, data_size);
00096         if (ret != EOK) {
00097                 endpoint_destroy(ep);
00098                 return ret;
00099         }
00100         return EOK;
00101 }
00102 #endif
00103 

Generated on Thu Jun 2 07:45:49 2011 for HelenOS/USB by  doxygen 1.4.7