source: mainline/uspace/lib/usbdev/include/usb/dev/poll.h@ bb70637

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bb70637 was bb70637, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

usb: Rework polling to accept either ep numbers or descriptions.

Switch usbhub and usbhid to new polling.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
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 libusbdev
30 * @{
31 */
32/** @file
33 * USB device polling functions.
34 */
35#ifndef LIBUSBDEV_POLL_H_
36#define LIBUSBDEV_POLL_H_
37
38#include <usb/dev/driver.h>
39#include <time.h>
40
41/** Parameters and callbacks for automated polling. */
42typedef struct {
43 /** Level of debugging messages from auto polling.
44 * 0 - nothing
45 * 1 - inform about errors and polling start/end
46 * 2 - also dump every retrieved buffer
47 */
48 int debug;
49 /** Maximum number of consecutive errors before polling termination. */
50 size_t max_failures;
51 /** Delay between poll requests in milliseconds.
52 * Set to negative value to use value from endpoint descriptor.
53 */
54 int delay;
55 /** Whether to automatically try to clear the HALT feature after
56 * the endpoint stalls.
57 */
58 bool auto_clear_halt;
59 /** Callback when data arrives.
60 *
61 * @param dev Device that was polled.
62 * @param data Data buffer (in USB endianness).
63 * @param data_size Size of the @p data buffer in bytes.
64 * @param arg Custom argument.
65 * @return Whether to continue in polling.
66 */
67 bool (*on_data)(usb_device_t *dev, uint8_t *data, size_t data_size,
68 void *arg);
69 /** Callback when polling is terminated.
70 *
71 * @param dev Device where the polling was terminated.
72 * @param due_to_errors Whether polling stopped due to several failures.
73 * @param arg Custom argument.
74 */
75 void (*on_polling_end)(usb_device_t *dev, bool due_to_errors,
76 void *arg);
77 /** Callback when error occurs.
78 *
79 * @param dev Device where error occurred.
80 * @param err_code Error code (as returned from usb_pipe_read).
81 * @param arg Custom argument.
82 * @return Whether to continue in polling.
83 */
84 bool (*on_error)(usb_device_t *dev, int err_code, void *arg);
85 /** Argument to pass to callbacks. */
86 void *arg;
87} usb_device_auto_polling_t;
88
89typedef bool (*usb_polling_callback_t)(usb_device_t *, uint8_t *, size_t, void *);
90typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
91
92int usb_device_auto_polling(usb_device_t *, usb_endpoint_t,
93 const usb_device_auto_polling_t *, size_t);
94
95int usb_device_auto_poll(usb_device_t *, usb_endpoint_t,
96 usb_polling_callback_t, size_t, int, usb_polling_terminted_callback_t, void *);
97
98int usb_device_auto_polling_desc(usb_device_t *,
99 const usb_endpoint_description_t *, const usb_device_auto_polling_t *,
100 size_t);
101
102int usb_device_auto_poll_desc(usb_device_t *,
103 const usb_endpoint_description_t *, usb_polling_callback_t, size_t, int,
104 usb_polling_terminted_callback_t, void *);
105
106#endif
107/**
108 * @}
109 */
Note: See TracBrowser for help on using the repository browser.