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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 91173333 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
RevLine 
[5e07e2b5]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
[160b75e]29/** @addtogroup libusbdev
[5e07e2b5]30 * @{
31 */
32/** @file
33 * USB device polling functions.
34 */
[7d521e24]35#ifndef LIBUSBDEV_POLL_H_
36#define LIBUSBDEV_POLL_H_
[5e07e2b5]37
[c01987c]38#include <usb/usb.h>
39#include <usb/dev/device.h>
40#include <usb/dev/pipes.h>
41
42#include <stdbool.h>
[8d2dd7f2]43#include <stddef.h>
44#include <stdint.h>
[8989f48f]45
[71f211f]46/** Automated polling instance. */
47typedef struct usb_device_polling usb_device_polling_t;
48
[6e3c005]49/** Parameters and callbacks for automated polling. */
[71f211f]50typedef struct usb_device_polling_config {
[5e168be1]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;
[71f211f]57
[8989f48f]58 /** Maximum number of consecutive errors before polling termination. */
59 size_t max_failures;
[71f211f]60
[8989f48f]61 /** Delay between poll requests in milliseconds.
62 * Set to negative value to use value from endpoint descriptor.
63 */
64 int delay;
[71f211f]65
[8989f48f]66 /** Whether to automatically try to clear the HALT feature after
67 * the endpoint stalls.
68 */
69 bool auto_clear_halt;
[71f211f]70
[8989f48f]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);
[71f211f]81
[8989f48f]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);
[71f211f]90
[8989f48f]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);
[71f211f]99
[a0487a2]100 /** Argument to pass to callbacks. */
101 void *arg;
[71f211f]102} usb_device_polling_config_t;
[5e07e2b5]103
[8a0c52a]104int usb_device_poll(usb_device_t *, usb_endpoint_mapping_t *,
[71f211f]105 const usb_device_polling_config_t *, size_t, usb_device_polling_t **);
[bb70637]106
[8a0c52a]107int usb_device_poll_join(usb_device_polling_t *);
108
[5e07e2b5]109#endif
110/**
111 * @}
112 */
Note: See TracBrowser for help on using the repository browser.