Changeset 17412546 in mainline for uspace/lib/usbhost/src/endpoint.c


Ignore:
Timestamp:
2011-10-29T20:17:51Z (13 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.