Changeset 71f211f in mainline for uspace/lib/usbdev/src/devpoll.c
- Timestamp:
- 2018-01-13T20:47:58Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8a0c52a
- Parents:
- 7dddd7b
- git-author:
- Petr Manek <petr.manek@…> (2018-01-13 20:44:08)
- git-committer:
- Petr Manek <petr.manek@…> (2018-01-13 20:47:58)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devpoll.c
r7dddd7b r71f211f 53 53 #include <stdint.h> 54 54 55 /** Maximum number of failed consecutive requests before announcing failure. */ 56 #define MAX_FAILED_ATTEMPTS 3 57 58 /** Data needed for polling. */ 59 typedef struct { 55 /** Private automated polling instance data. */ 56 struct usb_device_polling { 60 57 /** Parameters for automated polling. */ 61 usb_device_ auto_polling_t auto_polling;58 usb_device_polling_config_t config; 62 59 63 60 /** USB device to poll. */ 64 61 usb_device_t *dev; 62 65 63 /** Device enpoint mapping to use for polling. */ 66 64 usb_endpoint_mapping_t *polling_mapping; 65 67 66 /** Size of the recieved data. */ 68 67 size_t request_size; 68 69 69 /** Data buffer. */ 70 70 uint8_t *buffer; 71 } polling_data_t;71 }; 72 72 73 73 74 74 /** Polling fibril. 75 75 * 76 * @param arg Pointer to polling_data_t.76 * @param arg Pointer to usb_device_polling_t. 77 77 * @return Always EOK. 78 78 */ … … 80 80 { 81 81 assert(arg); 82 const polling_data_t *data = arg; 82 const usb_device_polling_t *data = arg; 83 83 84 /* Helper to reduce typing. */ 84 const usb_device_ auto_polling_t *params = &data->auto_polling;85 const usb_device_polling_config_t *params = &data->config; 85 86 86 87 usb_pipe_t *pipe = &data->polling_mapping->pipe; … … 202 203 * @param dev Device to be periodically polled. 203 204 * @param epm Endpoint mapping to use. 204 * @param polling Polling settings.205 * @param config Polling settings. 205 206 * @param req_size How many bytes to ask for in each request. 206 207 * @return Error code. 207 208 * @retval EOK New fibril polling the device was already started. 208 209 */ 209 int usb_device_auto_polling(usb_device_t *dev, usb_endpoint_mapping_t *epm, 210 const usb_device_auto_polling_t *polling, size_t req_size) 210 int usb_device_poll(usb_device_t *dev, usb_endpoint_mapping_t *epm, 211 const usb_device_polling_config_t *config, size_t req_size, 212 usb_device_polling_t **handle) 211 213 { 212 214 int rc; 213 if (!dev || ! polling || !polling->on_data)215 if (!dev || !config || !config->on_data) 214 216 return EBADMEM; 215 217 … … 221 223 return EINVAL; 222 224 223 polling_data_t *polling_data = malloc(sizeof(polling_data_t));224 if (! polling_data)225 usb_device_polling_t *instance = malloc(sizeof(usb_device_polling_t)); 226 if (!instance) 225 227 return ENOMEM; 226 228 227 229 /* Fill-in the data. */ 228 polling_data->buffer = malloc(req_size);229 if ( polling_data->buffer == NULL) {230 instance->buffer = malloc(req_size); 231 if (!instance->buffer) { 230 232 rc = ENOMEM; 231 goto err_ polling_data;232 } 233 polling_data->request_size = req_size;234 polling_data->dev = dev;235 polling_data->polling_mapping = epm;233 goto err_instance; 234 } 235 instance->request_size = req_size; 236 instance->dev = dev; 237 instance->polling_mapping = epm; 236 238 237 239 /* Copy provided settings. */ 238 polling_data->auto_polling = *polling;240 instance->config = *config; 239 241 240 242 /* Negative value means use descriptor provided value. */ 241 if (polling->delay < 0) { 242 polling_data->auto_polling.delay = 243 epm->descriptor->poll_interval; 244 } 245 246 fid_t fibril = fibril_create(polling_fibril, polling_data); 243 if (config->delay < 0) { 244 instance->config.delay = epm->descriptor->poll_interval; 245 } 246 247 fid_t fibril = fibril_create(polling_fibril, instance); 247 248 if (!fibril) { 248 249 rc = ENOMEM; … … 251 252 fibril_add_ready(fibril); 252 253 254 if (handle) 255 *handle = instance; 256 253 257 /* Fibril launched. That fibril will free the allocated data. */ 254 258 return EOK; 255 259 256 260 err_buffer: 257 free( polling_data->buffer);258 err_ polling_data:259 free( polling_data);261 free(instance->buffer); 262 err_instance: 263 free(instance); 260 264 return rc; 261 265 }
Note:
See TracChangeset
for help on using the changeset viewer.