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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 58563585 was 58563585, checked in by Martin Decky <martin@…>, 9 years ago

code review and cstyle cleanup (no change in functionality)

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