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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7dddd7b was 7dddd7b, checked in by Petr Manek <petr.manek@…>, 7 years ago

usbdev: refactor polling

Until now, device polling had to be executed by calling one of four
proxy functions, which served as a syntax sugar and had no clear
distinction between each other (not to mention misleading names and high
number of arguments).

In this commit, the four mentioned functions are discarded in favor of
one main function, which was proxied by them either way. The number of
arguments have decreased in favor of named struct fields in the auto
polling config structure.

Drivers, which make use of polling, such as usbhid and usbhub were
updated to the latest API design.

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