Ignore:
File:
1 edited

Legend:

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

    rf527f58 r9d58539  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    2928/** @addtogroup libusbhost
    3029 * @{
     
    3433 */
    3534
    36 #include <usb/host/endpoint.h>
    37 
    3835#include <assert.h>
    3936#include <stdlib.h>
    40 #include <atomic.h>
     37#include <errno.h>
     38#include <usb/host/endpoint.h>
    4139
    4240/** Allocate ad initialize endpoint_t structure.
     
    5250endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    5351    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    54     size_t max_packet_size, unsigned packets, size_t bw,
    55     usb_address_t tt_address, unsigned tt_p)
     52    size_t max_packet_size, size_t bw)
    5653{
    5754        endpoint_t *instance = malloc(sizeof(endpoint_t));
    5855        if (instance) {
    59                 atomic_set(&instance->refcnt, 0);
    6056                instance->address = address;
    6157                instance->endpoint = endpoint;
     
    6460                instance->speed = speed;
    6561                instance->max_packet_size = max_packet_size;
    66                 instance->packets = packets;
    6762                instance->bandwidth = bw;
    6863                instance->toggle = 0;
    6964                instance->active = false;
    70                 instance->tt.address = tt_address;
    71                 instance->tt.port = tt_p;
    7265                instance->hc_data.data = NULL;
    7366                instance->hc_data.toggle_get = NULL;
     
    7972        return instance;
    8073}
    81 
     74/*----------------------------------------------------------------------------*/
    8275/** Properly dispose of endpoint_t structure.
    8376 * @param instance endpoint_t structure.
     
    8679{
    8780        assert(instance);
     81        //TODO: Do something about waiting fibrils.
    8882        assert(!instance->active);
    8983        assert(instance->hc_data.data == NULL);
    9084        free(instance);
    9185}
    92 
    93 void endpoint_add_ref(endpoint_t *instance)
    94 {
    95         atomic_inc(&instance->refcnt);
    96 }
    97 
    98 void endpoint_del_ref(endpoint_t *instance)
    99 {
    100         if (atomic_predec(&instance->refcnt) == 0)
    101                 endpoint_destroy(instance);
    102 }
    103 
     86/*----------------------------------------------------------------------------*/
    10487/** Set device specific data and hooks.
    10588 * @param instance endpoint_t structure.
     
    118101        fibril_mutex_unlock(&instance->guard);
    119102}
    120 
     103/*----------------------------------------------------------------------------*/
    121104/** Clear device specific data and hooks.
    122105 * @param instance endpoint_t structure.
     
    126109{
    127110        assert(instance);
    128         endpoint_set_hc_data(instance, NULL, NULL, NULL);
     111        fibril_mutex_lock(&instance->guard);
     112        instance->hc_data.data = NULL;
     113        instance->hc_data.toggle_get = NULL;
     114        instance->hc_data.toggle_set = NULL;
     115        fibril_mutex_unlock(&instance->guard);
    129116}
    130 
     117/*----------------------------------------------------------------------------*/
    131118/** Mark the endpoint as active and block access for further fibrils.
    132119 * @param instance endpoint_t structure.
     
    135122{
    136123        assert(instance);
    137         /* Add reference for active endpoint. */
    138         endpoint_add_ref(instance);
    139124        fibril_mutex_lock(&instance->guard);
    140125        while (instance->active)
     
    143128        fibril_mutex_unlock(&instance->guard);
    144129}
    145 
     130/*----------------------------------------------------------------------------*/
    146131/** Mark the endpoint as inactive and allow access for further fibrils.
    147132 * @param instance endpoint_t structure.
     
    154139        fibril_mutex_unlock(&instance->guard);
    155140        fibril_condvar_signal(&instance->avail);
    156         /* Drop reference for active endpoint. */
    157         endpoint_del_ref(instance);
    158141}
    159 
     142/*----------------------------------------------------------------------------*/
    160143/** Get the value of toggle bit.
    161144 * @param instance endpoint_t structure.
     
    173156        return ret;
    174157}
    175 
     158/*----------------------------------------------------------------------------*/
    176159/** Set the value of toggle bit.
    177160 * @param instance endpoint_t structure.
     
    188171        fibril_mutex_unlock(&instance->guard);
    189172}
    190 
    191173/**
    192174 * @}
Note: See TracChangeset for help on using the changeset viewer.