source: mainline/uspace/lib/usbhost/src/endpoint.c@ 3375bd4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3375bd4 was 3375bd4, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Merge mainline changes

Conflicts:
kernel/generic/src/console/console.c

size of klog, taken upstream

uspace/app/klog/klog.c

taken upstream (upstream fixed the broken output on huge load)

uspace/app/tester/Makefile
uspace/app/tester/tester.c
uspace/app/tester/tester.h

merged without problems

uspace/lib/c/include/as.h

merged without problems (upstream use bare declarations)

Also needed to fix some missing includes.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbuhcihc
30 * @{
31 */
32/** @file
33 * @brief UHCI host controller driver structure
34 */
35
36#include <assert.h>
37#include <stdlib.h>
38#include <errno.h>
39#include <usb/host/endpoint.h>
40
41int endpoint_init(endpoint_t *instance, usb_address_t address,
42 usb_endpoint_t endpoint, usb_direction_t direction,
43 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size)
44{
45 assert(instance);
46 instance->address = address;
47 instance->endpoint = endpoint;
48 instance->direction = direction;
49 instance->transfer_type = type;
50 instance->speed = speed;
51 instance->max_packet_size = max_packet_size;
52 instance->toggle = 0;
53 instance->active = false;
54 fibril_mutex_initialize(&instance->guard);
55 fibril_condvar_initialize(&instance->avail);
56 endpoint_clear_hc_data(instance);
57 return EOK;
58}
59/*----------------------------------------------------------------------------*/
60void endpoint_destroy(endpoint_t *instance)
61{
62 assert(instance);
63 assert(!instance->active);
64 free(instance);
65}
66/*----------------------------------------------------------------------------*/
67void endpoint_set_hc_data(endpoint_t *instance,
68 void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int))
69{
70 assert(instance);
71 instance->hc_data.data = data;
72 instance->hc_data.toggle_get = toggle_get;
73 instance->hc_data.toggle_set = toggle_set;
74}
75/*----------------------------------------------------------------------------*/
76void endpoint_clear_hc_data(endpoint_t *instance)
77{
78 assert(instance);
79 instance->hc_data.data = NULL;
80 instance->hc_data.toggle_get = NULL;
81 instance->hc_data.toggle_set = NULL;
82}
83/*----------------------------------------------------------------------------*/
84void endpoint_use(endpoint_t *instance)
85{
86 assert(instance);
87 fibril_mutex_lock(&instance->guard);
88 while (instance->active)
89 fibril_condvar_wait(&instance->avail, &instance->guard);
90 instance->active = true;
91 fibril_mutex_unlock(&instance->guard);
92}
93/*----------------------------------------------------------------------------*/
94void endpoint_release(endpoint_t *instance)
95{
96 assert(instance);
97 fibril_mutex_lock(&instance->guard);
98 instance->active = false;
99 fibril_mutex_unlock(&instance->guard);
100 fibril_condvar_signal(&instance->avail);
101}
102/*----------------------------------------------------------------------------*/
103int endpoint_toggle_get(endpoint_t *instance)
104{
105 assert(instance);
106 if (instance->hc_data.toggle_get)
107 instance->toggle =
108 instance->hc_data.toggle_get(instance->hc_data.data);
109 return (int)instance->toggle;
110}
111/*----------------------------------------------------------------------------*/
112void endpoint_toggle_set(endpoint_t *instance, int toggle)
113{
114 assert(instance);
115 assert(toggle == 0 || toggle == 1);
116 if (instance->hc_data.toggle_set)
117 instance->hc_data.toggle_set(instance->hc_data.data, toggle);
118 instance->toggle = toggle;
119}
120/*----------------------------------------------------------------------------*/
121void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target)
122{
123 assert(instance);
124 if (instance->address == target.address &&
125 (instance->endpoint == target.endpoint || target.endpoint == 0))
126 endpoint_toggle_set(instance, 0);
127}
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.