Changes in / [0146d41:8d517c3] in mainline


Ignore:
Location:
uspace
Files:
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/main.c

    r0146d41 r8d517c3  
    4242
    4343#include <usb/devdrv.h>
    44 #include <usb/devpoll.h>
    4544
    4645#include "usbhid.h"
  • uspace/drv/usbhub/usbhub.c

    r0146d41 r8d517c3  
    4545#include <usb/request.h>
    4646#include <usb/classes/hub.h>
    47 #include <usb/devpoll.h>
    4847#include <stdio.h>
    4948
  • uspace/drv/usbkbd/main.c

    r0146d41 r8d517c3  
    4242
    4343#include <usb/devdrv.h>
    44 #include <usb/devpoll.h>
    4544
    4645#include "kbddev.h"
  • uspace/drv/usbmouse/main.c

    r0146d41 r8d517c3  
    3636#include "mouse.h"
    3737#include <usb/debug.h>
    38 #include <usb/devpoll.h>
    3938#include <errno.h>
    4039#include <str_error.h>
  • uspace/lib/usb/include/usb/devdrv.h

    r0146d41 r8d517c3  
    162162    usb_endpoint_description_t **);
    163163
     164typedef bool (*usb_polling_callback_t)(usb_device_t *,
     165    uint8_t *, size_t, void *);
     166typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
     167
     168int usb_device_auto_poll(usb_device_t *, size_t,
     169    usb_polling_callback_t, size_t, usb_polling_terminted_callback_t, void *);
     170
    164171int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
    165172int usb_device_create_pipes(ddf_dev_t *, usb_device_connection_t *,
  • uspace/lib/usb/include/usb/pipes.h

    r0146d41 r8d517c3  
    9999        /** Number of active transfers over the pipe. */
    100100        int refcount;
    101 
    102         /** Whether to automatically reset halt on the endpoint.
    103          * Valid only for control endpoint zero.
    104          */
    105         bool auto_reset_halt;
    106101} usb_pipe_t;
    107102
  • uspace/lib/usb/src/devpoll.c

    r0146d41 r8d517c3  
    3333 * USB device driver framework - automatic interrupt polling.
    3434 */
    35 #include <usb/devpoll.h>
     35#include <usb/devdrv.h>
    3636#include <usb/request.h>
    3737#include <usb/debug.h>
    38 #include <usb/classes/classes.h>
    3938#include <errno.h>
    4039#include <str_error.h>
     
    4645/** Data needed for polling. */
    4746typedef struct {
    48         int debug;
    49         size_t max_failures;
    50         useconds_t delay;
    51         bool auto_clear_halt;
    52         bool (*on_data)(usb_device_t *, uint8_t *, size_t, void *);
    53         void (*on_polling_end)(usb_device_t *, bool, void *);
    54         bool (*on_error)(usb_device_t *, int, void *);
    55 
    5647        usb_device_t *dev;
    5748        size_t pipe_index;
     49        usb_polling_callback_t callback;
     50        usb_polling_terminted_callback_t terminated_callback;
    5851        size_t request_size;
    5952        uint8_t *buffer;
    6053        void *custom_arg;
    6154} polling_data_t;
    62 
    6355
    6456/** Polling fibril.
     
    7567            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
    7668       
    77         if (polling_data->debug > 0) {
    78                 usb_endpoint_mapping_t *mapping
    79                     = &polling_data->dev->pipes[polling_data->pipe_index];
    80                 usb_log_debug("Poll0x%x: started polling of `%s' - " \
    81                     "interface %d (%s,%d,%d), %zuB/%zu.\n",
    82                     polling_data,
    83                     polling_data->dev->ddf_dev->name,
    84                     (int) mapping->interface->interface_number,
    85                     usb_str_class(mapping->interface->interface_class),
    86                     (int) mapping->interface->interface_subclass,
    87                     (int) mapping->interface->interface_protocol,
    88                     polling_data->request_size, pipe->max_packet_size);
    89         }
     69        usb_log_debug("Pipe interface number: %d, protocol: %d, subclass: %d, max packet size: %d\n",
     70            polling_data->dev->pipes[polling_data->pipe_index].interface_no,
     71            polling_data->dev->pipes[polling_data->pipe_index].description->interface_protocol,
     72            polling_data->dev->pipes[polling_data->pipe_index].description->interface_subclass,
     73            pipe->max_packet_size);
    9074
    9175        size_t failed_attempts = 0;
    92         while (failed_attempts <= polling_data->max_failures) {
     76        while (failed_attempts < MAX_FAILED_ATTEMPTS) {
    9377                int rc;
    9478
     
    9781                    polling_data->request_size, &actual_size);
    9882
    99                 if (polling_data->debug > 1) {
    100                         if (rc == EOK) {
    101                                 usb_log_debug(
    102                                     "Poll0x%x: received: '%s' (%zuB).\n",
    103                                     polling_data,
    104                                     usb_debug_str_buffer(polling_data->buffer,
    105                                         actual_size, 16),
    106                                     actual_size);
    107                         } else {
    108                                 usb_log_debug(
    109                                     "Poll0x%x: polling failed: %s.\n",
    110                                     polling_data, str_error(rc));
    111                         }
    112                 }
    113 
    114                 /* If the pipe stalled, we can try to reset the stall. */
    115                 if ((rc == ESTALL) && (polling_data->auto_clear_halt)) {
    116                         /*
    117                          * We ignore error here as this is usually a futile
    118                          * attempt anyway.
    119                          */
    120                         usb_request_clear_endpoint_halt(
    121                             &polling_data->dev->ctrl_pipe,
    122                             pipe->endpoint_no);
    123                 }
     83               
     84//              if (rc == ESTALL) {
     85//                      usb_log_debug("Seding clear feature...\n");
     86//                      usb_request_clear_feature(pipe, USB_REQUEST_TYPE_STANDARD,
     87//                        USB_REQUEST_RECIPIENT_ENDPOINT, 0, pipe->endpoint_no);
     88//                      continue;
     89//              }
    12490
    12591                if (rc != EOK) {
    126                         if (polling_data->on_error != NULL) {
    127                                 bool cont = polling_data->on_error(
    128                                     polling_data->dev, rc,
    129                                     polling_data->custom_arg);
    130                                 if (!cont) {
    131                                         failed_attempts
    132                                             = polling_data->max_failures;
    133                                 }
    134                         }
    13592                        failed_attempts++;
    13693                        continue;
     
    13895
    13996                /* We have the data, execute the callback now. */
    140                 bool carry_on = polling_data->on_data(polling_data->dev,
     97                bool carry_on = polling_data->callback(polling_data->dev,
    14198                    polling_data->buffer, actual_size,
    14299                    polling_data->custom_arg);
     
    149106                /* Reset as something might be only a temporary problem. */
    150107                failed_attempts = 0;
    151 
    152                 /* Take a rest before next request. */
    153                 async_usleep(polling_data->delay);
    154108        }
    155109
    156         if (polling_data->on_polling_end != NULL) {
    157                 polling_data->on_polling_end(polling_data->dev,
    158                     failed_attempts > 0, polling_data->custom_arg);
     110        if (failed_attempts > 0) {
     111                usb_log_error(
     112                    "Polling of device `%s' terminated: recurring failures.\n",
     113                    polling_data->dev->ddf_dev->name);
    159114        }
    160115
    161         if (polling_data->debug > 0) {
    162                 if (failed_attempts > 0) {
    163                         usb_log_error(
    164                             "Polling of device `%s' terminated: %s.\n",
    165                             polling_data->dev->ddf_dev->name,
    166                             "recurring failures");
    167                 } else {
    168                         usb_log_debug(
    169                             "Polling of device `%s' terminated by user.\n",
    170                             polling_data->dev->ddf_dev->name
    171                         );
    172                 }
     116        if (polling_data->terminated_callback != NULL) {
     117                polling_data->terminated_callback(polling_data->dev,
     118                    failed_attempts > 0, polling_data->custom_arg);
    173119        }
    174120
     
    213159        }
    214160
    215         usb_device_auto_polling_t *auto_polling
    216             = malloc(sizeof(usb_device_auto_polling_t));
    217         if (auto_polling == NULL) {
    218                 return ENOMEM;
    219         }
    220 
    221         auto_polling->debug = 1;
    222         auto_polling->auto_clear_halt = true;
    223         auto_polling->delay = 0;
    224         auto_polling->max_failures = MAX_FAILED_ATTEMPTS;
    225         auto_polling->on_data = callback;
    226         auto_polling->on_polling_end = terminated_callback;
    227         auto_polling->on_error = NULL;
    228 
    229         int rc = usb_device_auto_polling(dev, pipe_index, auto_polling,
    230            request_size, arg);
    231 
    232         free(auto_polling);
    233 
    234         return rc;
    235 }
    236 
    237 /** Start automatic device polling over interrupt in pipe.
    238  *
    239  * The polling settings is copied thus it is okay to destroy the structure
    240  * after this function returns.
    241  *
    242  * @warning There is no guarantee when the request to the device
    243  * will be sent for the first time (it is possible that this
    244  * first request would be executed prior to return from this function).
    245  *
    246  * @param dev Device to be periodically polled.
    247  * @param pipe_index Index of the endpoint pipe used for polling.
    248  * @param polling Polling settings.
    249  * @param request_size How many bytes to ask for in each request.
    250  * @param arg Custom argument (passed as is to the callbacks).
    251  * @return Error code.
    252  * @retval EOK New fibril polling the device was already started.
    253  */
    254 int usb_device_auto_polling(usb_device_t *dev, size_t pipe_index,
    255     usb_device_auto_polling_t *polling,
    256     size_t request_size, void *arg)
    257 {
    258         if (dev == NULL) {
    259                 return EBADMEM;
    260         }
    261         if (pipe_index >= dev->pipes_count) {
    262                 return EINVAL;
    263         }
    264         if ((dev->pipes[pipe_index].pipe->transfer_type != USB_TRANSFER_INTERRUPT)
    265             || (dev->pipes[pipe_index].pipe->direction != USB_DIRECTION_IN)) {
    266                 return EINVAL;
    267         }
    268         if ((polling == NULL) || (polling->on_data == NULL)) {
    269                 return EBADMEM;
    270         }
    271 
    272161        polling_data_t *polling_data = malloc(sizeof(polling_data_t));
    273162        if (polling_data == NULL) {
     
    275164        }
    276165
    277         /* Fill-in the data. */
    278         polling_data->buffer = malloc(sizeof(request_size));
     166        /* Allocate now to prevent immediate failure in the polling fibril. */
     167        polling_data->buffer = malloc(request_size);
    279168        if (polling_data->buffer == NULL) {
    280169                free(polling_data);
    281170                return ENOMEM;
    282171        }
    283         polling_data->request_size = request_size;
    284172        polling_data->dev = dev;
    285173        polling_data->pipe_index = pipe_index;
     174        polling_data->callback = callback;
     175        polling_data->terminated_callback = terminated_callback;
     176        polling_data->request_size = request_size;
    286177        polling_data->custom_arg = arg;
    287 
    288         polling_data->debug = polling->debug;
    289         polling_data->max_failures = polling->max_failures;
    290         if (polling->delay >= 0) {
    291                 polling_data->delay = (useconds_t) polling->delay;
    292         } else {
    293                 polling_data->delay = (useconds_t) dev->pipes[pipe_index]
    294                     .descriptor->poll_interval;
    295         }
    296         polling_data->auto_clear_halt = polling->auto_clear_halt;
    297 
    298         polling_data->on_data = polling->on_data;
    299         polling_data->on_polling_end = polling->on_polling_end;
    300         polling_data->on_error = polling->on_error;
    301178
    302179        fid_t fibril = fibril_create(polling_fibril, polling_data);
     
    304181                free(polling_data->buffer);
    305182                free(polling_data);
     183                /* FIXME: better error code. */
    306184                return ENOMEM;
    307185        }
    308186        fibril_add_ready(fibril);
    309187
    310         /* Fibril launched. That fibril will free the allocated data. */
     188        /* The allocated buffer etc. will be freed by the fibril. */
    311189
    312190        return EOK;
  • uspace/lib/usb/src/pipesinit.c

    r0146d41 r8d517c3  
    365365        pipe->direction = direction;
    366366        pipe->refcount = 0;
    367         pipe->auto_reset_halt = false;
    368367
    369368        return EOK;
     
    386385            0, USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE,
    387386            USB_DIRECTION_BOTH);
    388 
    389         pipe->auto_reset_halt = true;
    390387
    391388        return rc;
  • uspace/lib/usb/src/pipesio.c

    r0146d41 r8d517c3  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
    51 #include <usb/request.h>
    5251#include "pipepriv.h"
    5352
     
    308307}
    309308
    310 /** Try to clear endpoint halt of default control pipe.
    311  *
    312  * @param pipe Pipe for control endpoint zero.
    313  */
    314 static void clear_self_endpoint_halt(usb_pipe_t *pipe)
    315 {
    316         assert(pipe != NULL);
    317 
    318         if (!pipe->auto_reset_halt || (pipe->endpoint_no != 0)) {
    319                 return;
    320         }
    321 
    322 
    323         /* Prevent indefinite recursion. */
    324         pipe->auto_reset_halt = false;
    325         usb_request_clear_endpoint_halt(pipe, 0);
    326         pipe->auto_reset_halt = true;
    327 }
    328 
    329309
    330310/** Request a control read transfer, no checking of input parameters.
     
    457437            data_buffer, data_buffer_size, &act_size);
    458438
    459         if (rc == ESTALL) {
    460                 clear_self_endpoint_halt(pipe);
    461         }
    462 
    463439        pipe_drop_ref(pipe);
    464440
     
    587563            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
    588564
    589         if (rc == ESTALL) {
    590                 clear_self_endpoint_halt(pipe);
    591         }
    592 
    593565        pipe_drop_ref(pipe);
    594566
Note: See TracChangeset for help on using the changeset viewer.