Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/poll.h

    r338729c r8d2dd7f2  
    11/*
    22 * Copyright (c) 2011 Vojtech Horky
    3  * Copyright (c) 2017 Petr Manek
    43 * All rights reserved.
    54 *
     
    4443#include <stddef.h>
    4544#include <stdint.h>
    46 #include <fibril_synch.h>
    4745
    48 
    49 /** USB automated polling. */
    50 typedef 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 
    62         /** Data buffer of at least `request_size`. User is responsible for its allocation. */
    63         uint8_t *buffer;
    64 
     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;
    6564        /** Callback when data arrives.
    6665         *
     
    7372        bool (*on_data)(usb_device_t *dev, uint8_t *data, size_t data_size,
    7473            void *arg);
    75 
    76 
    77         /** Optional parameters - user can customize them, but they are defaulted to
    78          *  some reasonable values.
    79          */
    80 
    81         /** Level of debugging messages from auto polling.
    82          * 0 - nothing (default)
    83          * 1 - inform about errors and polling start/end
    84          * 2 - also dump every retrieved buffer
    85          */
    86         int debug;
    87 
    88         /** Maximum number of consecutive errors before polling termination (default 3). */
    89         size_t max_failures;
    90 
    91         /** Delay between poll requests in milliseconds.
    92          * By default, value from endpoint descriptor used.
    93          */
    94         int delay;
    95 
    96         /** Whether to automatically try to clear the HALT feature after
    97          * the endpoint stalls (true by default).
    98          */
    99         bool auto_clear_halt;
    100 
    101         /** Argument to pass to callbacks (default NULL). */
    102         void *arg;
    103 
    10474        /** Callback when polling is terminated.
    10575         *
     
    11080        void (*on_polling_end)(usb_device_t *dev, bool due_to_errors,
    11181            void *arg);
    112 
    11382        /** Callback when error occurs.
    11483         *
     
    11988         */
    12089        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;
    12193
     94typedef bool (*usb_polling_callback_t)(usb_device_t *, uint8_t *, size_t, void *);
     95typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
    12296
    123         /** Internal parameters - user is not expected to set them. Messing with them
    124          *  can result in unexpected behavior if you do not know what you are doing.
    125          */
     97extern int usb_device_auto_polling(usb_device_t *, usb_endpoint_t,
     98    const usb_device_auto_polling_t *, size_t);
    12699
    127         /** Fibril used for polling. */
    128         fid_t fibril;
     100extern int usb_device_auto_poll(usb_device_t *, usb_endpoint_t,
     101    usb_polling_callback_t, size_t, int, usb_polling_terminted_callback_t, void *);
    129102
    130         /** True if polling is currently in operation. */
    131         volatile bool running;
     103extern int usb_device_auto_polling_desc(usb_device_t *,
     104    const usb_endpoint_description_t *, const usb_device_auto_polling_t *,
     105    size_t);
    132106
    133         /** True if polling should terminate as soon as possible. */
    134         volatile bool joining;
    135 
    136         /** Synchronization primitives for joining polling end. */
    137         fibril_mutex_t guard;
    138         fibril_condvar_t cv;
    139 } usb_polling_t;
    140 
    141 int usb_polling_init(usb_polling_t *);
    142 void usb_polling_fini(usb_polling_t *);
    143 
    144 int usb_polling_start(usb_polling_t *);
    145 int usb_polling_join(usb_polling_t *);
     107extern int usb_device_auto_poll_desc(usb_device_t *,
     108    const usb_endpoint_description_t *, usb_polling_callback_t, size_t, int,
     109    usb_polling_terminted_callback_t, void *);
    146110
    147111#endif
Note: See TracChangeset for help on using the changeset viewer.