Changeset 2703331b in mainline
- Timestamp:
- 2011-11-26T14:12:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b81410f
- Parents:
- 3ddbd38
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devpoll.c
r3ddbd38 r2703331b 46 46 /** Data needed for polling. */ 47 47 typedef 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 *); 48 usb_device_auto_polling_t auto_polling; 55 49 56 50 usb_device_t *dev; … … 75 69 = &polling_data->dev->pipes[polling_data->pipe_index].pipe; 76 70 77 if (polling_data-> debug > 0) {71 if (polling_data->auto_polling.debug > 0) { 78 72 usb_endpoint_mapping_t *mapping 79 73 = &polling_data->dev->pipes[polling_data->pipe_index]; … … 90 84 91 85 size_t failed_attempts = 0; 92 while (failed_attempts <= polling_data-> max_failures) {86 while (failed_attempts <= polling_data->auto_polling.max_failures) { 93 87 int rc; 94 88 … … 97 91 polling_data->request_size, &actual_size); 98 92 99 if (polling_data-> debug > 1) {93 if (polling_data->auto_polling.debug > 1) { 100 94 if (rc == EOK) { 101 95 usb_log_debug( … … 113 107 114 108 /* If the pipe stalled, we can try to reset the stall. */ 115 if ((rc == ESTALL) && (polling_data->auto_ clear_halt)) {109 if ((rc == ESTALL) && (polling_data->auto_polling.auto_clear_halt)) { 116 110 /* 117 111 * We ignore error here as this is usually a futile … … 124 118 125 119 if (rc != EOK) { 126 if (polling_data-> on_error != NULL) {127 bool cont = polling_data-> on_error(120 if (polling_data->auto_polling.on_error != NULL) { 121 bool cont = polling_data->auto_polling.on_error( 128 122 polling_data->dev, rc, 129 123 polling_data->custom_arg); 130 124 if (!cont) { 131 125 failed_attempts 132 = polling_data-> max_failures;126 = polling_data->auto_polling.max_failures; 133 127 } 134 128 } … … 138 132 139 133 /* We have the data, execute the callback now. */ 140 bool carry_on = polling_data->on_data(polling_data->dev,141 polling_data-> buffer, actual_size,134 const bool carry_on = polling_data->auto_polling.on_data( 135 polling_data->dev, polling_data->buffer, actual_size, 142 136 polling_data->custom_arg); 143 137 … … 151 145 152 146 /* Take a rest before next request. */ 153 async_usleep(polling_data-> delay);154 } 155 156 if (polling_data-> on_polling_end != NULL) {157 polling_data-> on_polling_end(polling_data->dev,147 async_usleep(polling_data->auto_polling.delay); 148 } 149 150 if (polling_data->auto_polling.on_polling_end != NULL) { 151 polling_data->auto_polling.on_polling_end(polling_data->dev, 158 152 failed_attempts > 0, polling_data->custom_arg); 159 153 } 160 154 161 if (polling_data-> debug > 0) {155 if (polling_data->auto_polling.debug > 0) { 162 156 if (failed_attempts > 0) { 163 157 usb_log_error( … … 278 272 polling_data->custom_arg = arg; 279 273 280 polling_data->debug = polling->debug; 281 polling_data->max_failures = polling->max_failures; 282 if (polling->delay >= 0) { 283 polling_data->delay = (useconds_t) polling->delay; 284 } else { 285 polling_data->delay = (useconds_t) dev->pipes[pipe_index] 286 .descriptor->poll_interval; 287 } 288 polling_data->auto_clear_halt = polling->auto_clear_halt; 289 290 polling_data->on_data = polling->on_data; 291 polling_data->on_polling_end = polling->on_polling_end; 292 polling_data->on_error = polling->on_error; 274 /* Copy provided settings. */ 275 polling_data->auto_polling = *polling; 276 277 /* Negative value means use descriptor provided value. */ 278 if (polling->delay < 0) { 279 polling_data->auto_polling.delay = 280 (int) dev->pipes[pipe_index].descriptor->poll_interval; 281 } 293 282 294 283 fid_t fibril = fibril_create(polling_fibril, polling_data);
Note:
See TracChangeset
for help on using the changeset viewer.