Changeset 71f211f in mainline


Ignore:
Timestamp:
2018-01-13T20:47:58Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8a0c52a
Parents:
7dddd7b
git-author:
Petr Manek <petr.manek@…> (2018-01-13 20:44:08)
git-committer:
Petr Manek <petr.manek@…> (2018-01-13 20:47:58)
Message:

usbdev: refactor polling data structs

Symbols related to USB device endpoint polling have been moved around
and renamed in this commit.

usb_device_auto_polling_t, which has the semantics of a configuration
parameter struct, has been renamed to usb_device_polling_config_t.

usb_device_auto_polling() is now called usb_device_poll().

A new data structure, usb_device_polling_t, has been introduced to
serve as a user handle to the active polling process (WIP).

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r7dddd7b r71f211f  
    164164
    165165        /* Start hub operation. */
    166         const usb_device_auto_polling_t auto_polling = {
     166        const usb_device_polling_config_t config = {
    167167                .debug = 1,
    168168                .auto_clear_halt = true,
     
    178178            usb_device_get_mapped_ep_desc(hub_dev->usb_device,
    179179            &hub_status_change_endpoint_description);
    180         opResult = usb_device_auto_polling(hub_dev->usb_device, epm,
    181             &auto_polling, ((hub_dev->port_count + 1 + 7) / 8));
     180        opResult = usb_device_poll(hub_dev->usb_device, epm, &config,
     181            ((hub_dev->port_count + 1 + 7) / 8), &hub_dev->polling);
    182182       
    183183        if (opResult != EOK) {
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r7dddd7b r71f211f  
    4444#include <usb/dev/pipes.h>
    4545#include <usb/dev/driver.h>
     46#include <usb/dev/poll.h>
    4647
    4748#include <fibril_synch.h>
     
    5960        /** Generic usb device data*/
    6061        usb_device_t *usb_device;
    61 
     62        /** Data polling handle. */
     63        usb_device_polling_t *polling;
    6264        /** Number of pending operations on the mutex to prevent shooting
    6365         * ourselves in the foot.
  • uspace/drv/hid/usbhid/main.c

    r7dddd7b r71f211f  
    9090         * This will create a separate fibril that will query the device
    9191         * for the data continuously. */
    92         const usb_device_auto_polling_t auto_polling = {
     92        const usb_device_polling_config_t config = {
    9393                .debug = 1,
    9494                .auto_clear_halt = true,
     
    101101        };
    102102
    103         rc = usb_device_auto_polling(dev, hid_dev->poll_pipe_mapping,
    104             &auto_polling, hid_dev->poll_pipe_mapping->pipe.desc.max_transfer_size);
     103        rc = usb_device_poll(dev, hid_dev->poll_pipe_mapping, &config,
     104            hid_dev->poll_pipe_mapping->pipe.desc.max_transfer_size, &hid_dev->polling);
    105105
    106106        if (rc != EOK) {
  • uspace/drv/hid/usbhid/usbhid.h

    r7dddd7b r71f211f  
    4343#include <usb/dev/pipes.h>
    4444#include <usb/dev/driver.h>
     45#include <usb/dev/poll.h>
    4546#include <usb/hid/hid.h>
    4647#include <stdbool.h>
     
    107108        usb_endpoint_mapping_t *poll_pipe_mapping;
    108109
     110        /** Device polling handle. */
     111        usb_device_polling_t *polling;
     112
    109113        /** Subdrivers. */
    110114        usb_hid_subdriver_t *subdrivers;
  • uspace/lib/usbdev/include/usb/dev/poll.h

    r7dddd7b r71f211f  
    4444#include <stdint.h>
    4545
     46/** Automated polling instance. */
     47typedef struct usb_device_polling usb_device_polling_t;
     48
    4649/** Parameters and callbacks for automated polling. */
    47 typedef struct {
     50typedef struct usb_device_polling_config {
    4851        /** Level of debugging messages from auto polling.
    4952         * 0 - nothing
     
    5255         */
    5356        int debug;
     57
    5458        /** Maximum number of consecutive errors before polling termination. */
    5559        size_t max_failures;
     60
    5661        /** Delay between poll requests in milliseconds.
    5762         * Set to negative value to use value from endpoint descriptor.
    5863         */
    5964        int delay;
     65
    6066        /** Whether to automatically try to clear the HALT feature after
    6167         * the endpoint stalls.
    6268         */
    6369        bool auto_clear_halt;
     70
    6471        /** Callback when data arrives.
    6572         *
     
    7279        bool (*on_data)(usb_device_t *dev, uint8_t *data, size_t data_size,
    7380            void *arg);
     81
    7482        /** Callback when polling is terminated.
    7583         *
     
    8088        void (*on_polling_end)(usb_device_t *dev, bool due_to_errors,
    8189            void *arg);
     90
    8291        /** Callback when error occurs.
    8392         *
     
    8897         */
    8998        bool (*on_error)(usb_device_t *dev, int err_code, void *arg);
     99
    90100        /** Argument to pass to callbacks. */
    91101        void *arg;
    92 } usb_device_auto_polling_t;
     102} usb_device_polling_config_t;
    93103
    94 typedef bool (*usb_polling_callback_t)(usb_device_t *, uint8_t *, size_t, void *);
    95 typedef bool (*usb_polling_error_callback_t)(usb_device_t *, int, void *);
    96 typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
    97 
    98 extern int usb_device_auto_polling(usb_device_t *, usb_endpoint_mapping_t *,
    99     const usb_device_auto_polling_t *, size_t);
     104extern int usb_device_poll(usb_device_t *, usb_endpoint_mapping_t *,
     105    const usb_device_polling_config_t *, size_t, usb_device_polling_t **);
    100106
    101107#endif
  • uspace/lib/usbdev/src/devpoll.c

    r7dddd7b r71f211f  
    5353#include <stdint.h>
    5454
    55 /** Maximum number of failed consecutive requests before announcing failure. */
    56 #define MAX_FAILED_ATTEMPTS 3
    57 
    58 /** Data needed for polling. */
    59 typedef struct {
     55/** Private automated polling instance data. */
     56struct usb_device_polling {
    6057        /** Parameters for automated polling. */
    61         usb_device_auto_polling_t auto_polling;
     58        usb_device_polling_config_t config;
    6259
    6360        /** USB device to poll. */
    6461        usb_device_t *dev;
     62
    6563        /** Device enpoint mapping to use for polling. */
    6664        usb_endpoint_mapping_t *polling_mapping;
     65
    6766        /** Size of the recieved data. */
    6867        size_t request_size;
     68
    6969        /** Data buffer. */
    7070        uint8_t *buffer;
    71 } polling_data_t;
     71};
    7272
    7373
    7474/** Polling fibril.
    7575 *
    76  * @param arg Pointer to polling_data_t.
     76 * @param arg Pointer to usb_device_polling_t.
    7777 * @return Always EOK.
    7878 */
     
    8080{
    8181        assert(arg);
    82         const polling_data_t *data = arg;
     82        const usb_device_polling_t *data = arg;
     83
    8384        /* Helper to reduce typing. */
    84         const usb_device_auto_polling_t *params = &data->auto_polling;
     85        const usb_device_polling_config_t *params = &data->config;
    8586
    8687        usb_pipe_t *pipe = &data->polling_mapping->pipe;
     
    202203 * @param dev Device to be periodically polled.
    203204 * @param epm Endpoint mapping to use.
    204  * @param polling Polling settings.
     205 * @param config Polling settings.
    205206 * @param req_size How many bytes to ask for in each request.
    206207 * @return Error code.
    207208 * @retval EOK New fibril polling the device was already started.
    208209 */
    209 int usb_device_auto_polling(usb_device_t *dev, usb_endpoint_mapping_t *epm,
    210     const usb_device_auto_polling_t *polling, size_t req_size)
     210int usb_device_poll(usb_device_t *dev, usb_endpoint_mapping_t *epm,
     211    const usb_device_polling_config_t *config, size_t req_size,
     212    usb_device_polling_t **handle)
    211213{
    212214        int rc;
    213         if (!dev || !polling || !polling->on_data)
     215        if (!dev || !config || !config->on_data)
    214216                return EBADMEM;
    215217
     
    221223                return EINVAL;
    222224
    223         polling_data_t *polling_data = malloc(sizeof(polling_data_t));
    224         if (!polling_data)
     225        usb_device_polling_t *instance = malloc(sizeof(usb_device_polling_t));
     226        if (!instance)
    225227                return ENOMEM;
    226228
    227229        /* Fill-in the data. */
    228         polling_data->buffer = malloc(req_size);
    229         if (polling_data->buffer == NULL) {
     230        instance->buffer = malloc(req_size);
     231        if (!instance->buffer) {
    230232                rc = ENOMEM;
    231                 goto err_polling_data;
    232         }
    233         polling_data->request_size = req_size;
    234         polling_data->dev = dev;
    235         polling_data->polling_mapping = epm;
     233                goto err_instance;
     234        }
     235        instance->request_size = req_size;
     236        instance->dev = dev;
     237        instance->polling_mapping = epm;
    236238
    237239        /* Copy provided settings. */
    238         polling_data->auto_polling = *polling;
     240        instance->config = *config;
    239241
    240242        /* Negative value means use descriptor provided value. */
    241         if (polling->delay < 0) {
    242                 polling_data->auto_polling.delay =
    243                     epm->descriptor->poll_interval;
    244         }
    245 
    246         fid_t fibril = fibril_create(polling_fibril, polling_data);
     243        if (config->delay < 0) {
     244                instance->config.delay = epm->descriptor->poll_interval;
     245        }
     246
     247        fid_t fibril = fibril_create(polling_fibril, instance);
    247248        if (!fibril) {
    248249                rc = ENOMEM;
     
    251252        fibril_add_ready(fibril);
    252253
     254        if (handle)
     255                *handle = instance;
     256
    253257        /* Fibril launched. That fibril will free the allocated data. */
    254258        return EOK;
    255259
    256260err_buffer:
    257         free(polling_data->buffer);
    258 err_polling_data:
    259         free(polling_data);
     261        free(instance->buffer);
     262err_instance:
     263        free(instance);
    260264        return rc;
    261265}
Note: See TracChangeset for help on using the changeset viewer.