Changeset 9dbfd288 in mainline
- Timestamp:
- 2011-11-28T18:01:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7711296
- Parents:
- 69b9740
- Location:
- uspace/lib/usbdev/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devpoll.c
r69b9740 r9dbfd288 63 63 static int polling_fibril(void *arg) 64 64 { 65 polling_data_t *polling_data = (polling_data_t *) arg; 66 assert(polling_data); 65 assert(arg); 66 const polling_data_t *data = arg; 67 /* Helper to reduce typing. */ 68 const usb_device_auto_polling_t *params = &data->auto_polling; 67 69 68 70 usb_pipe_t *pipe 69 = & polling_data->dev->pipes[polling_data->pipe_index].pipe;70 71 if (p olling_data->auto_polling.debug > 0) {71 = &data->dev->pipes[data->pipe_index].pipe; 72 73 if (params->debug > 0) { 72 74 const usb_endpoint_mapping_t *mapping 73 = & polling_data->dev->pipes[polling_data->pipe_index];75 = &data->dev->pipes[data->pipe_index]; 74 76 usb_log_debug("Poll%p: started polling of `%s' - " \ 75 77 "interface %d (%s,%d,%d), %zuB/%zu.\n", 76 polling_data, 77 polling_data->dev->ddf_dev->name, 78 data, data->dev->ddf_dev->name, 78 79 (int) mapping->interface->interface_number, 79 80 usb_str_class(mapping->interface->interface_class), 80 81 (int) mapping->interface->interface_subclass, 81 82 (int) mapping->interface->interface_protocol, 82 polling_data->request_size, pipe->max_packet_size);83 data->request_size, pipe->max_packet_size); 83 84 } 84 85 85 86 usb_pipe_start_long_transfer(pipe); 86 87 size_t failed_attempts = 0; 87 while (failed_attempts <= p olling_data->auto_polling.max_failures) {88 while (failed_attempts <= params->max_failures) { 88 89 size_t actual_size; 89 const int rc = usb_pipe_read(pipe, polling_data->buffer,90 polling_data->request_size, &actual_size);91 92 if (p olling_data->auto_polling.debug > 1) {90 const int rc = usb_pipe_read(pipe, data->buffer, 91 data->request_size, &actual_size); 92 93 if (params->debug > 1) { 93 94 if (rc == EOK) { 94 95 usb_log_debug( 95 96 "Poll%p: received: '%s' (%zuB).\n", 96 polling_data,97 usb_debug_str_buffer( polling_data->buffer,97 data, 98 usb_debug_str_buffer(data->buffer, 98 99 actual_size, 16), 99 100 actual_size); … … 101 102 usb_log_debug( 102 103 "Poll%p: polling failed: %s.\n", 103 polling_data, str_error(rc));104 data, str_error(rc)); 104 105 } 105 106 } 106 107 107 108 /* If the pipe stalled, we can try to reset the stall. */ 108 if ((rc == ESTALL) && (p olling_data->auto_polling.auto_clear_halt)) {109 if ((rc == ESTALL) && (params->auto_clear_halt)) { 109 110 /* 110 111 * We ignore error here as this is usually a futile … … 112 113 */ 113 114 usb_request_clear_endpoint_halt( 114 & polling_data->dev->ctrl_pipe, pipe->endpoint_no);115 &data->dev->ctrl_pipe, pipe->endpoint_no); 115 116 } 116 117 117 118 if (rc != EOK) { 118 if (polling_data->auto_polling.on_error != NULL) { 119 bool cont = polling_data->auto_polling.on_error( 120 polling_data->dev, rc, 121 polling_data->custom_arg); 122 if (!cont) { 123 failed_attempts 124 = polling_data->auto_polling.max_failures; 125 } 119 ++failed_attempts; 120 const bool cont = (params->on_error == NULL) ? true : 121 params->on_error(data->dev, rc, data->custom_arg); 122 if (!cont) { 123 failed_attempts = params->max_failures; 126 124 } 127 failed_attempts++;128 125 continue; 129 126 } 130 127 131 128 /* We have the data, execute the callback now. */ 132 const bool carry_on = polling_data->auto_polling.on_data(133 polling_data->dev, polling_data->buffer, actual_size,134 polling_data->custom_arg);129 assert(params->on_data); 130 const bool carry_on = params->on_data( 131 data->dev, data->buffer, actual_size, data->custom_arg); 135 132 136 133 if (!carry_on) { 134 /* This is user requested abort, erases failures. */ 137 135 failed_attempts = 0; 138 136 break; … … 143 141 144 142 /* Take a rest before next request. */ 145 async_usleep(p olling_data->auto_polling.delay);143 async_usleep(params->delay); 146 144 } 147 145 148 146 usb_pipe_end_long_transfer(pipe); 149 if (polling_data->auto_polling.on_polling_end != NULL) { 150 polling_data->auto_polling.on_polling_end(polling_data->dev,151 failed_attempts > 0, polling_data->custom_arg); 152 }153 154 if (polling_data->auto_polling.debug > 0) {155 if (failed_attempts > 0) { 156 usb_log_error(157 "Polling of device `%s' terminated: %s.\n",158 polling_data->dev->ddf_dev->name,159 "recurring failures ");147 148 const bool failed = failed_attempts > 0; 149 150 if (params->on_polling_end != NULL) { 151 params->on_polling_end(data->dev, failed, data->custom_arg); 152 } 153 154 if (params->debug > 0) { 155 if (failed) { 156 usb_log_error("Polling of device `%s' terminated: " 157 "recurring failures.\n", data->dev->ddf_dev->name); 160 158 } else { 161 usb_log_debug( 162 "Polling of device `%s' terminated by user.\n", 163 polling_data->dev->ddf_dev->name 164 ); 159 usb_log_debug("Polling of device `%s' terminated: " 160 "driver request.\n", data->dev->ddf_dev->name); 165 161 } 166 162 } 167 163 168 164 /* Free the allocated memory. */ 169 free( polling_data->buffer);170 free( polling_data);165 free(data->buffer); 166 free(data); 171 167 172 168 return EOK; -
uspace/lib/usbdev/src/hub.c
r69b9740 r9dbfd288 219 219 * request or requests for descriptors when creating match ids). 220 220 */ 221 int usb_hc_new_device_wrapper(ddf_dev_t *parent, usb_hc_connection_t *connection,222 usb_ speed_t dev_speed,221 int usb_hc_new_device_wrapper(ddf_dev_t *parent, 222 usb_hc_connection_t *connection, usb_speed_t dev_speed, 223 223 int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address, 224 224 ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
Note:
See TracChangeset
for help on using the changeset viewer.