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

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

usbdev: add polling join mechanism

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