Changeset a6add7a in mainline for uspace/lib/usb/src
- Timestamp:
- 2011-03-04T23:35:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 960bee9
- Parents:
- d78a32f
- Location:
- uspace/lib/usb/src
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/debug.c
rd78a32f ra6add7a 31 31 */ 32 32 /** @file 33 * @brief Debugging support.33 * Debugging and logging support. 34 34 */ 35 35 #include <adt/list.h> … … 40 40 #include <usb/debug.h> 41 41 42 /** Debugging tag. */43 typedef struct {44 /** Linked list member. */45 link_t link;46 /** Tag name.47 * We always have a private copy of the name.48 */49 char *tag;50 /** Enabled level of debugging. */51 int level;52 } usb_debug_tag_t;53 54 /** Get instance of usb_debug_tag_t from link_t. */55 #define USB_DEBUG_TAG_INSTANCE(iterator) \56 list_get_instance(iterator, usb_debug_tag_t, link)57 58 /** List of all known tags. */59 static LIST_INITIALIZE(tag_list);60 /** Mutex guard for the list of all tags. */61 static FIBRIL_MUTEX_INITIALIZE(tag_list_guard);62 63 42 /** Level of logging messages. */ 64 43 static usb_log_level_t log_level = USB_LOG_LEVEL_WARNING; 44 65 45 /** Prefix for logging messages. */ 66 46 static const char *log_prefix = "usb"; 47 67 48 /** Serialization mutex for logging functions. */ 68 49 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 50 51 /** File where to store the log. */ 69 52 static FILE *log_stream = NULL; 70 53 71 /** Find or create new tag with given name.72 *73 * @param tagname Tag name.74 * @return Debug tag structure.75 * @retval NULL Out of memory.76 */77 static usb_debug_tag_t *get_tag(const char *tagname)78 {79 link_t *link;80 for (link = tag_list.next; \81 link != &tag_list; \82 link = link->next) {83 usb_debug_tag_t *tag = USB_DEBUG_TAG_INSTANCE(link);84 if (str_cmp(tag->tag, tagname) == 0) {85 return tag;86 }87 }88 89 /*90 * Tag not found, we will create a new one.91 */92 usb_debug_tag_t *new_tag = malloc(sizeof(usb_debug_tag_t));93 int rc = asprintf(&new_tag->tag, "%s", tagname);94 if (rc < 0) {95 free(new_tag);96 return NULL;97 }98 list_initialize(&new_tag->link);99 new_tag->level = 1;100 101 /*102 * Append it to the end of known tags.103 */104 list_append(&new_tag->link, &tag_list);105 106 return new_tag;107 }108 109 /** Print debugging information.110 * If the tag is used for the first time, its structures are automatically111 * created and initial verbosity level is set to 1.112 *113 * @param tagname Tag name.114 * @param level Level (verbosity) of the message.115 * @param format Formatting string for printf().116 */117 void usb_dprintf(const char *tagname, int level, const char *format, ...)118 {119 fibril_mutex_lock(&tag_list_guard);120 usb_debug_tag_t *tag = get_tag(tagname);121 if (tag == NULL) {122 printf("USB debug: FATAL ERROR - failed to create tag.\n");123 goto leave;124 }125 126 if (tag->level < level) {127 goto leave;128 }129 130 va_list args;131 va_start(args, format);132 133 printf("[%s:%d]: ", tagname, level);134 vprintf(format, args);135 136 va_end(args);137 138 leave:139 fibril_mutex_unlock(&tag_list_guard);140 }141 142 /** Enable debugging prints for given tag.143 *144 * Setting level to <i>n</i> will cause that only printing messages145 * with level lower or equal to <i>n</i> will be printed.146 *147 * @param tagname Tag name.148 * @param level Enabled level.149 */150 void usb_dprintf_enable(const char *tagname, int level)151 {152 fibril_mutex_lock(&tag_list_guard);153 usb_debug_tag_t *tag = get_tag(tagname);154 if (tag == NULL) {155 printf("USB debug: FATAL ERROR - failed to create tag.\n");156 goto leave;157 }158 159 tag->level = level;160 161 leave:162 fibril_mutex_unlock(&tag_list_guard);163 }164 54 165 55 /** Enable logging. … … 182 72 } 183 73 184 74 /** Get log level name prefix. 75 * 76 * @param level Log level. 77 * @return String prefix for the message. 78 */ 185 79 static const char *log_level_name(usb_log_level_t level) 186 80 { … … 256 150 /* string + terminator + number width (enough for 4GB)*/ 257 151 #define REMAINDER_STR_LEN (5 + 1 + 10) 152 153 /** How many bytes to group together. */ 258 154 #define BUFFER_DUMP_GROUP_SIZE 4 155 156 /** Size of the string for buffer dumps. */ 259 157 #define BUFFER_DUMP_LEN 240 /* Ought to be enough for everybody ;-). */ 158 159 /** Fibril local storage for the dumped buffer. */ 260 160 static fibril_local char buffer_dump[BUFFER_DUMP_LEN]; 261 161 -
uspace/lib/usb/src/dp.c
rd78a32f ra6add7a 32 32 /** 33 33 * @file 34 * @brief USB descriptor parser (implementation). 34 * USB descriptor parser (implementation). 35 * 36 * The descriptor parser is a generic parser for structure, where individual 37 * items are stored in single buffer and each item begins with length followed 38 * by type. These types are organized into tree hierarchy. 39 * 40 * The parser is able of only two actions: find first child and find next 41 * sibling. 35 42 */ 36 43 #include <stdio.h> -
uspace/lib/usb/src/dump.c
rd78a32f ra6add7a 31 31 */ 32 32 /** @file 33 * @briefDescriptor dumping.33 * Descriptor dumping. 34 34 */ 35 35 #include <adt/list.h> … … 43 43 #include <usb/classes/hid.h> 44 44 45 /** Mapping between descriptor id and dumping function. */ 45 46 typedef struct { 47 /** Descriptor id. */ 46 48 int id; 49 /** Dumping function. */ 47 50 void (*dump)(FILE *, const char *, const char *, 48 51 const uint8_t *, size_t); … … 66 69 const uint8_t *, size_t); 67 70 71 /** Descriptor dumpers mapping. */ 68 72 static descriptor_dump_t descriptor_dumpers[] = { 69 73 { USB_DESCTYPE_DEVICE, usb_dump_descriptor_device }, … … 273 277 const uint8_t *descriptor, size_t descriptor_length) 274 278 { 279 /* TODO */ 275 280 } 276 281 … … 279 284 const uint8_t *descriptor, size_t descriptor_length) 280 285 { 286 /* TODO */ 281 287 } 282 288 -
uspace/lib/usb/src/hub.c
rd78a32f ra6add7a 144 144 /** Wrapper for registering attached device to the hub. 145 145 * 146 * The @p enable_port function is expected to enable si ngalling on given146 * The @p enable_port function is expected to enable signaling on given 147 147 * port. 148 148 * The two arguments to it can have arbitrary meaning … … 152 152 * 153 153 * If the @p enable_port fails (i.e. does not return EOK), the device 154 * addition is cancel led.154 * addition is canceled. 155 155 * The return value is then returned (it is good idea to use different 156 156 * error codes than those listed as return codes by this function itself). … … 159 159 * @param connection Opened connection to host controller. 160 160 * @param dev_speed New device speed. 161 * @param enable_port Function for enabling signal ling through the port the161 * @param enable_port Function for enabling signaling through the port the 162 162 * device is attached to. 163 163 * @param port_no Port number (passed through to @p enable_port). … … 201 201 202 202 /* 203 * Enable the port (i.e. allow signal ling through this port).203 * Enable the port (i.e. allow signaling through this port). 204 204 */ 205 205 rc = enable_port(port_no, arg); -
uspace/lib/usb/src/recognise.c
rd78a32f ra6add7a 31 31 */ 32 32 /** @file 33 * @brief Functions for recognising kindof attached devices.33 * Functions for recognition of attached devices. 34 34 */ 35 35 #include <sys/types.h> … … 44 44 #include <assert.h> 45 45 46 /** Index to append after device name for uniqueness. */ 46 47 static size_t device_name_index = 0; 48 /** Mutex guard for device_name_index. */ 47 49 static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex); 48 50 51 /** DDF operations of child devices. */ 49 52 ddf_dev_ops_t child_ops = { 50 53 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl 51 54 }; 52 55 56 /** Get integer part from BCD coded number. */ 53 57 #define BCD_INT(a) (((unsigned int)(a)) / 256) 58 /** Get fraction part from BCD coded number (as an integer, no less). */ 54 59 #define BCD_FRAC(a) (((unsigned int)(a)) % 256) 55 60 61 /** Format for BCD coded number to be used in printf. */ 56 62 #define BCD_FMT "%x.%x" 63 /** Arguments to printf for BCD coded number. */ 57 64 #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a)) 58 65 … … 113 120 } 114 121 122 /** Add match id to list or return with error code. 123 * 124 * @param match_ids List of match ids. 125 * @param score Match id score. 126 * @param format Format of the matching string 127 * @param ... Arguments for the format. 128 */ 115 129 #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \ 116 130 do { \ -
uspace/lib/usb/src/request.c
rd78a32f ra6add7a 110 110 * (must be in USB endianness). 111 111 * @param data Buffer where to store data accepted during the DATA stage. 112 * (they will come in USB endian ess).112 * (they will come in USB endianness). 113 113 * @param data_size Size of the @p data buffer 114 114 * (in native endianness). … … 161 161 * the new address. 162 162 * 163 * @see usb_drv_reserve_default_address164 * @see usb_drv_release_default_address165 * @see usb_drv_request_address166 * @see usb_drv_release_address167 * @see usb_drv_bind_address168 *169 163 * @param pipe Control endpoint pipe (session must be already started). 170 164 * @param new_address New USB address to be set (in native endianness). … … 528 522 return EEMPTY; 529 523 } 530 /* Sub stract first 2 bytes (length and descriptor type). */524 /* Subtract first 2 bytes (length and descriptor type). */ 531 525 string_descriptor_size -= 2; 532 526 … … 548 542 size_t i; 549 543 for (i = 0; i < langs_count; i++) { 550 /* Language code from the descriptor is in USB endian ess. */544 /* Language code from the descriptor is in USB endianness. */ 551 545 /* FIXME: is this really correct? */ 552 546 uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8) … … 569 563 * 570 564 * @param[in] pipe Control endpoint pipe (session must be already started). 571 * @param[in] index String index (in native endian ess),565 * @param[in] index String index (in native endianness), 572 566 * first index has number 1 (index from descriptors can be used directly). 573 * @param[in] lang String language (in native endian ess).567 * @param[in] lang String language (in native endianness). 574 568 * @param[out] string_ptr Where to store allocated string in native encoding. 575 569 * @return Error code. … … 613 607 goto leave; 614 608 } 615 /* Sub stract first 2 bytes (length and descriptor type). */609 /* Subtract first 2 bytes (length and descriptor type). */ 616 610 string_size -= 2; 617 611 -
uspace/lib/usb/src/usb.c
rd78a32f ra6add7a 31 31 */ 32 32 /** @file 33 * @brief Base USB types.33 * Common USB functions. 34 34 */ 35 35 #include <usb/usb.h> … … 37 37 38 38 39 /** String representation for USB transfer type. */ 39 /** String representation for USB transfer type. 40 * 41 * @param t Transfer type. 42 * @return Transfer type as a string (in English). 43 */ 40 44 const char * usb_str_transfer_type(usb_transfer_type_t t) 41 45 {
Note:
See TracChangeset
for help on using the changeset viewer.