Changeset aab02fb in mainline


Ignore:
Timestamp:
2010-10-26T22:21:45Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efedee77
Parents:
fa2a361
Message:

Debugging support for libusbvirt

Added methods debug and lib_debug to device structure to simplify
debugging. Each method gets as a parameter debug level describing
verbosity of the message and also message tag that allows filtering
based on message type (e.g. messages related to transactions, to
device requests etc.).

Location:
uspace
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/Makefile

    rfa2a361 raab02fb  
    3636        callback.c \
    3737        ctrlpipe.c \
     38        debug.c \
    3839        main.c \
    3940        stdreq.c \
  • uspace/lib/usbvirt/ctrlpipe.c

    rfa2a361 raab02fb  
    4545        ((value & GET_MIDBITS_MASK(size, shift)) >> shift)
    4646
    47 usb_address_t dev_new_address = -1;
     47
     48static const char *str_request_type(int type)
     49{
     50        switch (type) {
     51                case REQUEST_TYPE_STANDARD:
     52                        return "standard";
     53                case REQUEST_TYPE_CLASS:
     54                        return "class";
     55                default:
     56                        return "unknown";
     57        }
     58}
    4859
    4960/** Tell request type.
     
    5970int control_pipe(usbvirt_device_t *device, usbvirt_control_transfer_t *transfer)
    6071{
     72        device->lib_debug(device, 1, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
     73            "op on control pipe zero (request_size=%u)", transfer->request_size);
     74       
    6175        if (transfer->request_size < sizeof(usb_device_request_setup_packet_t)) {
    6276                return ENOMEM;
     
    6983       
    7084        int rc = EOK;
     85       
     86        device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
     87            "request type: %s", str_request_type(type));
    7188       
    7289        switch (type) {
     
    97114               
    98115                device->new_address = -1;
     116               
     117                device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
     118                    "device address changed to %d (state %s)",
     119                    device->address, str_device_state(device->state));
    99120        }
    100121       
  • uspace/lib/usbvirt/device.h

    rfa2a361 raab02fb  
    145145} usbvirt_control_transfer_t;
    146146
     147typedef enum {
     148        USBVIRT_DEBUGTAG_BASE = 1,
     149        USBVIRT_DEBUGTAG_TRANSACTION = 2,
     150        USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO = 4,
     151        USBVIRT_DEBUGTAG_ALL = 255
     152} usbvirt_debug_tags_t;
     153
    147154/** Virtual USB device. */
    148155struct usbvirt_device {
     
    186193        /** State information on control-transfer endpoints. */
    187194        usbvirt_control_transfer_t current_control_transfers[USB11_ENDPOINT_MAX];
     195       
     196        /* User debugging. */
     197       
     198        /** Debug print. */
     199        void (*debug)(usbvirt_device_t *dev, int level, uint8_t tag,
     200            const char *format, ...);
     201       
     202        /** Current debug level. */
     203        int debug_level;
     204       
     205        /** Bitmap of currently enabled tags. */
     206        uint8_t debug_enabled_tags;
     207       
     208        /* Library debugging. */
     209       
     210        /** Debug print. */
     211        void (*lib_debug)(usbvirt_device_t *dev, int level, uint8_t tag,
     212            const char *format, ...);
     213       
     214        /** Current debug level. */
     215        int lib_debug_level;
     216       
     217        /** Bitmap of currently enabled tags. */
     218        uint8_t lib_debug_enabled_tags;
    188219};
    189220
  • uspace/lib/usbvirt/main.c

    rfa2a361 raab02fb  
    124124        dev->control_transfer_reply = control_transfer_reply;
    125125       
     126        dev->debug = user_debug;
     127        dev->lib_debug = lib_debug;
     128       
    126129        dev->state = USBVIRT_STATE_DEFAULT;
    127130        dev->address = 0;
  • uspace/lib/usbvirt/private.h

    rfa2a361 raab02fb  
    6666    void *buffer, size_t size, size_t *data_size);
    6767
     68
     69void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
     70    const char *format, ...);
     71void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
     72    const char *format, ...);
     73   
     74static inline const char *str_device_state(usbvirt_device_state_t state)
     75{
     76        switch (state) {
     77                case USBVIRT_STATE_DEFAULT:
     78                        return "default";
     79                case USBVIRT_STATE_ADDRESS:
     80                        return "address";
     81                case USBVIRT_STATE_CONFIGURED:
     82                        return "configured";
     83                default:
     84                        return "unknown";
     85        }
     86}
     87
    6888#endif
    6989/**
  • uspace/lib/usbvirt/stdreq.c

    rfa2a361 raab02fb  
    187187    usb_device_request_setup_packet_t *request, uint8_t *data)
    188188{
     189        device->lib_debug(device, 3, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
     190            "handling standard request %d", request->request);
     191       
    189192        HANDLE_REQUEST(request, data, USB_DEVREQ_GET_DESCRIPTOR,
    190193            device, on_get_descriptor,
  • uspace/lib/usbvirt/transaction.c

    rfa2a361 raab02fb  
    6767    void *buffer, size_t size)
    6868{
     69        device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
     70            "setup transaction: endpoint=%d, size=%u", endpoint, size);
     71       
    6972        usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
    7073       
     
    97100    void *buffer, size_t size)
    98101{
     102        device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
     103            "out transaction: endpoint=%d, size=%u", endpoint, size);
     104       
    99105        /*
    100106         * First check whether it is a transaction over control pipe.
     
    151157    void *buffer, size_t size, size_t *data_size)
    152158{
     159        device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
     160            "in transaction: endpoint=%d, size=%u", endpoint, size);
     161       
    153162        /*
    154163         * First check whether it is a transaction over control pipe.
  • uspace/srv/hw/bus/usb/hcd/virtual/hub.c

    rfa2a361 raab02fb  
    141141        .ops = &hub_ops,
    142142        .descriptors = &descriptors,
     143        .lib_debug_level = 4,
     144        .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL
    143145};
    144146
Note: See TracChangeset for help on using the changeset viewer.