Changeset 71f211f in mainline for uspace/lib/usbdev/src/devpoll.c


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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.