Changeset 5e168be1 in mainline


Ignore:
Timestamp:
2011-04-14T10:22:06Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fa0f53b
Parents:
8989f48f
Message:

Optional debugging messages for auto polling

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/devpoll.h

    r8989f48f r5e168be1  
    4040
    4141typedef struct {
     42        /** Level of debugging messages from auto polling.
     43         * 0 - nothing
     44         * 1 - inform about errors and polling start/end
     45         * 2 - also dump every retrieved buffer
     46         */
     47        int debug;
    4248        /** Maximum number of consecutive errors before polling termination. */
    4349        size_t max_failures;
  • uspace/lib/usb/src/devpoll.c

    r8989f48f r5e168be1  
    3636#include <usb/request.h>
    3737#include <usb/debug.h>
     38#include <usb/classes/classes.h>
    3839#include <errno.h>
    3940#include <str_error.h>
     
    4546/** Data needed for polling. */
    4647typedef struct {
     48        int debug;
    4749        size_t max_failures;
    4850        useconds_t delay;
     
    7375            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
    7476       
    75         usb_log_debug("Pipe interface number: %d, protocol: %d, subclass: %d, max packet size: %d\n",
    76             polling_data->dev->pipes[polling_data->pipe_index].interface_no,
    77             polling_data->dev->pipes[polling_data->pipe_index].description->interface_protocol,
    78             polling_data->dev->pipes[polling_data->pipe_index].description->interface_subclass,
    79             pipe->max_packet_size);
     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        }
    8090
    8191        size_t failed_attempts = 0;
     
    8696                rc = usb_pipe_read(pipe, polling_data->buffer,
    8797                    polling_data->request_size, &actual_size);
     98
     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                }
    88113
    89114                /* If the pipe stalled, we can try to reset the stall. */
     
    129154        }
    130155
    131         if (failed_attempts > 0) {
    132                 usb_log_error(
    133                     "Polling of device `%s' terminated: recurring failures.\n",
    134                     polling_data->dev->ddf_dev->name);
    135         }
    136 
    137156        if (polling_data->on_polling_end != NULL) {
    138157                polling_data->on_polling_end(polling_data->dev,
    139158                    failed_attempts > 0, polling_data->custom_arg);
     159        }
     160
     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                }
    140173        }
    141174
     
    186219        }
    187220
     221        auto_polling->debug = 1;
    188222        auto_polling->auto_clear_halt = true;
    189223        auto_polling->delay = 0;
     
    252286        polling_data->custom_arg = arg;
    253287
     288        polling_data->debug = polling->debug;
    254289        polling_data->max_failures = polling->max_failures;
    255290        if (polling->delay >= 0) {
Note: See TracChangeset for help on using the changeset viewer.