Changeset 17412546 in mainline


Ignore:
Timestamp:
2011-10-29T20:17:51Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c44a5f1
Parents:
549ff23
Message:

libusbhost: endpoint_t: extend mutex protection, add doxygen comments.

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r549ff23 r17412546  
    4141#include <usb/usb.h>
    4242
     43/** Host controller side endpoint structure. */
    4344typedef struct endpoint {
     45        /** Part of linked list. */
    4446        link_t link;
     47        /** USB address. */
    4548        usb_address_t address;
     49        /** USB endpoint number. */
    4650        usb_endpoint_t endpoint;
     51        /** Communication direction. */
    4752        usb_direction_t direction;
     53        /** USB transfer type. */
    4854        usb_transfer_type_t transfer_type;
     55        /** Communication speed. */
    4956        usb_speed_t speed;
     57        /** Maximum size of data packets. */
    5058        size_t max_packet_size;
     59        /** Necessary bandwidth. */
    5160        size_t bandwidth;
     61        /** Value of the toggle bit. */
    5262        unsigned toggle:1;
     63        /** True if there is a batch using this scheduled for this endpoint. */
     64        volatile bool active;
     65        /** Protects resources and active status changes. */
    5366        fibril_mutex_t guard;
     67        /** Signals change of active status. */
    5468        fibril_condvar_t avail;
    55         volatile bool active;
     69        /** Optional device specific data. */
    5670        struct {
     71                /** Device specific data. */
    5772                void *data;
     73                /** Callback to get the value of toggle bit. */
    5874                int (*toggle_get)(void *);
     75                /** Callback to set the value of toggle bit. */
    5976                void (*toggle_set)(void *, int);
    6077        } hc_data;
     
    7693void endpoint_toggle_set(endpoint_t *instance, int toggle);
    7794
     95/** list_get_instance wrapper.
     96 * @param item Pointer to link member.
     97 * @return Pointer to enpoint_t structure.
     98 */
    7899static inline endpoint_t * endpoint_get_instance(link_t *item)
    79100{
  • uspace/lib/usbhost/src/endpoint.c

    r549ff23 r17412546  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup drvusbuhcihc
     28/** @addtogroup libusbhost
    3029 * @{
    3130 */
     
    3938#include <usb/host/endpoint.h>
    4039
     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 */
    4150endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    4251    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
     
    6069                fibril_mutex_initialize(&instance->guard);
    6170                fibril_condvar_initialize(&instance->avail);
    62                 endpoint_clear_hc_data(instance);
    6371        }
    6472        return instance;
    6573}
    6674/*----------------------------------------------------------------------------*/
     75/** Properly dispose of endpoint_t structure.
     76 * @param instance endpoint_t structure.
     77 */
    6778void endpoint_destroy(endpoint_t *instance)
    6879{
    6980        assert(instance);
     81        //TODO: Do something about waiting fibrils.
    7082        assert(!instance->active);
    7183        assert(instance->hc_data.data == NULL);
     
    7385}
    7486/*----------------------------------------------------------------------------*/
     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 */
    7593void endpoint_set_hc_data(endpoint_t *instance,
    7694    void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int))
    7795{
    7896        assert(instance);
     97        fibril_mutex_lock(&instance->guard);
    7998        instance->hc_data.data = data;
    8099        instance->hc_data.toggle_get = toggle_get;
    81100        instance->hc_data.toggle_set = toggle_set;
     101        fibril_mutex_unlock(&instance->guard);
    82102}
    83103/*----------------------------------------------------------------------------*/
     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 */
    84108void endpoint_clear_hc_data(endpoint_t *instance)
    85109{
    86110        assert(instance);
     111        fibril_mutex_lock(&instance->guard);
    87112        instance->hc_data.data = NULL;
    88113        instance->hc_data.toggle_get = NULL;
    89114        instance->hc_data.toggle_set = NULL;
     115        fibril_mutex_unlock(&instance->guard);
    90116}
    91117/*----------------------------------------------------------------------------*/
     118/** Mark the endpoint as active and block access for further fibrils.
     119 * @param instance endpoint_t structure.
     120 */
    92121void endpoint_use(endpoint_t *instance)
    93122{
     
    100129}
    101130/*----------------------------------------------------------------------------*/
     131/** Mark the endpoint as inactive and allow access for further fibrils.
     132 * @param instance endpoint_t structure.
     133 */
    102134void endpoint_release(endpoint_t *instance)
    103135{
     
    109141}
    110142/*----------------------------------------------------------------------------*/
     143/** Get the value of toggle bit.
     144 * @param instance endpoint_t structure.
     145 * @note Will use provided hook.
     146 */
    111147int endpoint_toggle_get(endpoint_t *instance)
    112148{
    113149        assert(instance);
     150        fibril_mutex_lock(&instance->guard);
    114151        if (instance->hc_data.toggle_get)
    115152                instance->toggle =
    116153                    instance->hc_data.toggle_get(instance->hc_data.data);
    117         return (int)instance->toggle;
     154        const int ret = instance->toggle;
     155        fibril_mutex_unlock(&instance->guard);
     156        return ret;
    118157}
    119158/*----------------------------------------------------------------------------*/
     159/** Set the value of toggle bit.
     160 * @param instance endpoint_t structure.
     161 * @note Will use provided hook.
     162 */
    120163void endpoint_toggle_set(endpoint_t *instance, int toggle)
    121164{
    122165        assert(instance);
    123166        assert(toggle == 0 || toggle == 1);
     167        fibril_mutex_lock(&instance->guard);
     168        instance->toggle = toggle;
    124169        if (instance->hc_data.toggle_set)
    125170                instance->hc_data.toggle_set(instance->hc_data.data, toggle);
    126         instance->toggle = toggle;
     171        fibril_mutex_unlock(&instance->guard);
    127172}
    128173/**
Note: See TracChangeset for help on using the changeset viewer.