Ignore:
File:
1 edited

Legend:

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

    r9d58539 rf527f58  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup libusbhost
    2930 * @{
     
    3334 */
    3435
     36#include <usb/host/endpoint.h>
     37
    3538#include <assert.h>
    3639#include <stdlib.h>
    37 #include <errno.h>
    38 #include <usb/host/endpoint.h>
     40#include <atomic.h>
    3941
    4042/** Allocate ad initialize endpoint_t structure.
     
    5052endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    5153    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    52     size_t max_packet_size, size_t bw)
     54    size_t max_packet_size, unsigned packets, size_t bw,
     55    usb_address_t tt_address, unsigned tt_p)
    5356{
    5457        endpoint_t *instance = malloc(sizeof(endpoint_t));
    5558        if (instance) {
     59                atomic_set(&instance->refcnt, 0);
    5660                instance->address = address;
    5761                instance->endpoint = endpoint;
     
    6064                instance->speed = speed;
    6165                instance->max_packet_size = max_packet_size;
     66                instance->packets = packets;
    6267                instance->bandwidth = bw;
    6368                instance->toggle = 0;
    6469                instance->active = false;
     70                instance->tt.address = tt_address;
     71                instance->tt.port = tt_p;
    6572                instance->hc_data.data = NULL;
    6673                instance->hc_data.toggle_get = NULL;
     
    7279        return instance;
    7380}
    74 /*----------------------------------------------------------------------------*/
     81
    7582/** Properly dispose of endpoint_t structure.
    7683 * @param instance endpoint_t structure.
     
    7986{
    8087        assert(instance);
    81         //TODO: Do something about waiting fibrils.
    8288        assert(!instance->active);
    8389        assert(instance->hc_data.data == NULL);
    8490        free(instance);
    8591}
    86 /*----------------------------------------------------------------------------*/
     92
     93void endpoint_add_ref(endpoint_t *instance)
     94{
     95        atomic_inc(&instance->refcnt);
     96}
     97
     98void endpoint_del_ref(endpoint_t *instance)
     99{
     100        if (atomic_predec(&instance->refcnt) == 0)
     101                endpoint_destroy(instance);
     102}
     103
    87104/** Set device specific data and hooks.
    88105 * @param instance endpoint_t structure.
     
    101118        fibril_mutex_unlock(&instance->guard);
    102119}
    103 /*----------------------------------------------------------------------------*/
     120
    104121/** Clear device specific data and hooks.
    105122 * @param instance endpoint_t structure.
     
    109126{
    110127        assert(instance);
    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);
     128        endpoint_set_hc_data(instance, NULL, NULL, NULL);
    116129}
    117 /*----------------------------------------------------------------------------*/
     130
    118131/** Mark the endpoint as active and block access for further fibrils.
    119132 * @param instance endpoint_t structure.
     
    122135{
    123136        assert(instance);
     137        /* Add reference for active endpoint. */
     138        endpoint_add_ref(instance);
    124139        fibril_mutex_lock(&instance->guard);
    125140        while (instance->active)
     
    128143        fibril_mutex_unlock(&instance->guard);
    129144}
    130 /*----------------------------------------------------------------------------*/
     145
    131146/** Mark the endpoint as inactive and allow access for further fibrils.
    132147 * @param instance endpoint_t structure.
     
    139154        fibril_mutex_unlock(&instance->guard);
    140155        fibril_condvar_signal(&instance->avail);
     156        /* Drop reference for active endpoint. */
     157        endpoint_del_ref(instance);
    141158}
    142 /*----------------------------------------------------------------------------*/
     159
    143160/** Get the value of toggle bit.
    144161 * @param instance endpoint_t structure.
     
    156173        return ret;
    157174}
    158 /*----------------------------------------------------------------------------*/
     175
    159176/** Set the value of toggle bit.
    160177 * @param instance endpoint_t structure.
     
    171188        fibril_mutex_unlock(&instance->guard);
    172189}
     190
    173191/**
    174192 * @}
Note: See TracChangeset for help on using the changeset viewer.