00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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