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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cede6f8 was ae3a941, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usb: cstyle

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[5e07e2b5]1/*
2 * Copyright (c) 2011 Vojtech Horky
[338729c]3 * Copyright (c) 2017 Petr Manek
[5e07e2b5]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[160b75e]30/** @addtogroup libusbdev
[5e07e2b5]31 * @{
32 */
33/** @file
34 * USB device polling functions.
35 */
[7d521e24]36#ifndef LIBUSBDEV_POLL_H_
37#define LIBUSBDEV_POLL_H_
[5e07e2b5]38
[c01987c]39#include <usb/usb.h>
40#include <usb/dev/device.h>
41#include <usb/dev/pipes.h>
42
43#include <stdbool.h>
[8d2dd7f2]44#include <stddef.h>
45#include <stdint.h>
[8b71f3e]46#include <fibril_synch.h>
[8989f48f]47
[71f211f]48
[8b71f3e]49/** USB automated polling. */
50typedef struct usb_polling {
51 /** Mandatory parameters - user is expected to configure these. */
52
53 /** USB device to poll. */
54 usb_device_t *device;
55
56 /** Device enpoint mapping to use for polling. */
57 usb_endpoint_mapping_t *ep_mapping;
58
59 /** Size of the recieved data. */
60 size_t request_size;
61
[ae3a941]62 /**
63 * Data buffer of at least `request_size`. User is responsible for its
64 * allocation.
65 */
[8b71f3e]66 uint8_t *buffer;
67
68 /** Callback when data arrives.
69 *
70 * @param dev Device that was polled.
71 * @param data Data buffer (in USB endianness).
72 * @param data_size Size of the @p data buffer in bytes.
73 * @param arg Custom argument.
74 * @return Whether to continue in polling.
75 */
76 bool (*on_data)(usb_device_t *dev, uint8_t *data, size_t data_size,
77 void *arg);
78
79
[ae3a941]80 /**
81 * Optional parameters - user can customize them, but they are
82 * defaulted to some reasonable values.
[8b71f3e]83 */
84
[5e168be1]85 /** Level of debugging messages from auto polling.
[8b71f3e]86 * 0 - nothing (default)
[5e168be1]87 * 1 - inform about errors and polling start/end
88 * 2 - also dump every retrieved buffer
89 */
90 int debug;
[71f211f]91
[ae3a941]92 /**
93 * Maximum number of consecutive errors before polling termination
94 * (default 3).
95 */
[8989f48f]96 size_t max_failures;
[71f211f]97
[8989f48f]98 /** Delay between poll requests in milliseconds.
[8b71f3e]99 * By default, value from endpoint descriptor used.
[8989f48f]100 */
101 int delay;
[71f211f]102
[8989f48f]103 /** Whether to automatically try to clear the HALT feature after
[8b71f3e]104 * the endpoint stalls (true by default).
[8989f48f]105 */
106 bool auto_clear_halt;
[71f211f]107
[8b71f3e]108 /** Argument to pass to callbacks (default NULL). */
109 void *arg;
[71f211f]110
[8989f48f]111 /** Callback when polling is terminated.
112 *
113 * @param dev Device where the polling was terminated.
114 * @param due_to_errors Whether polling stopped due to several failures.
115 * @param arg Custom argument.
116 */
117 void (*on_polling_end)(usb_device_t *dev, bool due_to_errors,
118 void *arg);
[71f211f]119
[8989f48f]120 /** Callback when error occurs.
121 *
122 * @param dev Device where error occurred.
123 * @param err_code Error code (as returned from usb_pipe_read).
124 * @param arg Custom argument.
125 * @return Whether to continue in polling.
126 */
[5a6cc679]127 bool (*on_error)(usb_device_t *dev, errno_t err_code, void *arg);
[71f211f]128
[5e07e2b5]129
[ae3a941]130 /**
131 * Internal parameters - user is not expected to set them. Messing with
132 * them can result in unexpected behavior if you do not know what you
133 * are doing.
[8b71f3e]134 */
135
136 /** Fibril used for polling. */
137 fid_t fibril;
138
139 /** True if polling is currently in operation. */
140 volatile bool running;
141
142 /** True if polling should terminate as soon as possible. */
143 volatile bool joining;
144
145 /** Synchronization primitives for joining polling end. */
146 fibril_mutex_t guard;
147 fibril_condvar_t cv;
148} usb_polling_t;
149
[5a6cc679]150errno_t usb_polling_init(usb_polling_t *);
[8b71f3e]151void usb_polling_fini(usb_polling_t *);
[bb70637]152
[5a6cc679]153errno_t usb_polling_start(usb_polling_t *);
154errno_t usb_polling_join(usb_polling_t *);
[8a0c52a]155
[5e07e2b5]156#endif
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.