Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/endpoint.c

    r9d58539 r563d9d0a  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup libusbhost
     28
     29/** @addtogroup drvusbuhcihc
    2930 * @{
    3031 */
     
    3839#include <usb/host/endpoint.h>
    3940
    40 /** Allocate ad initialize endpoint_t structure.
    41  * @param address USB address.
    42  * @param endpoint USB endpoint number.
    43  * @param direction Communication direction.
    44  * @param type USB transfer type.
    45  * @param speed Communication speed.
    46  * @param max_packet_size Maximum size of data packets.
    47  * @param bw Required bandwidth.
    48  * @return Pointer to initialized endpoint_t structure, NULL on failure.
    49  */
    50 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
     41endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
    5142    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    52     size_t max_packet_size, size_t bw)
     43    size_t max_packet_size)
    5344{
    5445        endpoint_t *instance = malloc(sizeof(endpoint_t));
     
    6051                instance->speed = speed;
    6152                instance->max_packet_size = max_packet_size;
    62                 instance->bandwidth = bw;
    6353                instance->toggle = 0;
    6454                instance->active = false;
     55                instance->destroy_hook = NULL;
    6556                instance->hc_data.data = NULL;
    6657                instance->hc_data.toggle_get = NULL;
    6758                instance->hc_data.toggle_set = NULL;
    68                 link_initialize(&instance->link);
    6959                fibril_mutex_initialize(&instance->guard);
    7060                fibril_condvar_initialize(&instance->avail);
     61                endpoint_clear_hc_data(instance);
    7162        }
    7263        return instance;
    7364}
    7465/*----------------------------------------------------------------------------*/
    75 /** Properly dispose of endpoint_t structure.
    76  * @param instance endpoint_t structure.
    77  */
    7866void endpoint_destroy(endpoint_t *instance)
    7967{
    8068        assert(instance);
    81         //TODO: Do something about waiting fibrils.
    8269        assert(!instance->active);
    83         assert(instance->hc_data.data == NULL);
     70        if (instance->hc_data.data) {
     71                assert(instance->destroy_hook);
     72                instance->destroy_hook(instance);
     73        }
    8474        free(instance);
    8575}
    8676/*----------------------------------------------------------------------------*/
    87 /** Set device specific data and hooks.
    88  * @param instance endpoint_t structure.
    89  * @param data device specific data.
    90  * @param toggle_get Hook to call when retrieving value of toggle bit.
    91  * @param toggle_set Hook to call when setting the value of toggle bit.
    92  */
    9377void endpoint_set_hc_data(endpoint_t *instance,
    94     void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int))
     78    void *data, void (*destroy_hook)(endpoint_t *),
     79    int (*toggle_get)(void *), void (*toggle_set)(void *, int))
    9580{
    9681        assert(instance);
    97         fibril_mutex_lock(&instance->guard);
     82        instance->destroy_hook = destroy_hook;
    9883        instance->hc_data.data = data;
    9984        instance->hc_data.toggle_get = toggle_get;
    10085        instance->hc_data.toggle_set = toggle_set;
    101         fibril_mutex_unlock(&instance->guard);
    10286}
    10387/*----------------------------------------------------------------------------*/
    104 /** Clear device specific data and hooks.
    105  * @param instance endpoint_t structure.
    106  * @note This function does not free memory pointed to by data pointer.
    107  */
    10888void endpoint_clear_hc_data(endpoint_t *instance)
    10989{
    11090        assert(instance);
    111         fibril_mutex_lock(&instance->guard);
     91        instance->destroy_hook = NULL;
    11292        instance->hc_data.data = NULL;
    11393        instance->hc_data.toggle_get = NULL;
    11494        instance->hc_data.toggle_set = NULL;
    115         fibril_mutex_unlock(&instance->guard);
    11695}
    11796/*----------------------------------------------------------------------------*/
    118 /** Mark the endpoint as active and block access for further fibrils.
    119  * @param instance endpoint_t structure.
    120  */
    12197void endpoint_use(endpoint_t *instance)
    12298{
     
    129105}
    130106/*----------------------------------------------------------------------------*/
    131 /** Mark the endpoint as inactive and allow access for further fibrils.
    132  * @param instance endpoint_t structure.
    133  */
    134107void endpoint_release(endpoint_t *instance)
    135108{
     
    141114}
    142115/*----------------------------------------------------------------------------*/
    143 /** Get the value of toggle bit.
    144  * @param instance endpoint_t structure.
    145  * @note Will use provided hook.
    146  */
    147116int endpoint_toggle_get(endpoint_t *instance)
    148117{
    149118        assert(instance);
    150         fibril_mutex_lock(&instance->guard);
    151119        if (instance->hc_data.toggle_get)
    152120                instance->toggle =
    153121                    instance->hc_data.toggle_get(instance->hc_data.data);
    154         const int ret = instance->toggle;
    155         fibril_mutex_unlock(&instance->guard);
    156         return ret;
     122        return (int)instance->toggle;
    157123}
    158124/*----------------------------------------------------------------------------*/
    159 /** Set the value of toggle bit.
    160  * @param instance endpoint_t structure.
    161  * @note Will use provided hook.
    162  */
    163125void endpoint_toggle_set(endpoint_t *instance, int toggle)
    164126{
    165127        assert(instance);
    166128        assert(toggle == 0 || toggle == 1);
    167         fibril_mutex_lock(&instance->guard);
    168         instance->toggle = toggle;
    169129        if (instance->hc_data.toggle_set)
    170130                instance->hc_data.toggle_set(instance->hc_data.data, toggle);
    171         fibril_mutex_unlock(&instance->guard);
     131        instance->toggle = toggle;
     132}
     133/*----------------------------------------------------------------------------*/
     134void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target)
     135{
     136        assert(instance);
     137        if (instance->address == target.address &&
     138            (instance->endpoint == target.endpoint || target.endpoint == 0))
     139                endpoint_toggle_set(instance, 0);
    172140}
    173141/**
Note: See TracChangeset for help on using the changeset viewer.