Changeset 71f211f in mainline
- Timestamp:
- 2018-01-13T20:47:58Z (7 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)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/usbhub.c
r7dddd7b r71f211f 164 164 165 165 /* Start hub operation. */ 166 const usb_device_ auto_polling_t auto_polling = {166 const usb_device_polling_config_t config = { 167 167 .debug = 1, 168 168 .auto_clear_halt = true, … … 178 178 usb_device_get_mapped_ep_desc(hub_dev->usb_device, 179 179 &hub_status_change_endpoint_description); 180 opResult = usb_device_ auto_polling(hub_dev->usb_device, epm,181 &auto_polling, ((hub_dev->port_count + 1 + 7) / 8));180 opResult = usb_device_poll(hub_dev->usb_device, epm, &config, 181 ((hub_dev->port_count + 1 + 7) / 8), &hub_dev->polling); 182 182 183 183 if (opResult != EOK) { -
uspace/drv/bus/usb/usbhub/usbhub.h
r7dddd7b r71f211f 44 44 #include <usb/dev/pipes.h> 45 45 #include <usb/dev/driver.h> 46 #include <usb/dev/poll.h> 46 47 47 48 #include <fibril_synch.h> … … 59 60 /** Generic usb device data*/ 60 61 usb_device_t *usb_device; 61 62 /** Data polling handle. */ 63 usb_device_polling_t *polling; 62 64 /** Number of pending operations on the mutex to prevent shooting 63 65 * ourselves in the foot. -
uspace/drv/hid/usbhid/main.c
r7dddd7b r71f211f 90 90 * This will create a separate fibril that will query the device 91 91 * for the data continuously. */ 92 const usb_device_ auto_polling_t auto_polling = {92 const usb_device_polling_config_t config = { 93 93 .debug = 1, 94 94 .auto_clear_halt = true, … … 101 101 }; 102 102 103 rc = usb_device_ auto_polling(dev, hid_dev->poll_pipe_mapping,104 &auto_polling, hid_dev->poll_pipe_mapping->pipe.desc.max_transfer_size);103 rc = usb_device_poll(dev, hid_dev->poll_pipe_mapping, &config, 104 hid_dev->poll_pipe_mapping->pipe.desc.max_transfer_size, &hid_dev->polling); 105 105 106 106 if (rc != EOK) { -
uspace/drv/hid/usbhid/usbhid.h
r7dddd7b r71f211f 43 43 #include <usb/dev/pipes.h> 44 44 #include <usb/dev/driver.h> 45 #include <usb/dev/poll.h> 45 46 #include <usb/hid/hid.h> 46 47 #include <stdbool.h> … … 107 108 usb_endpoint_mapping_t *poll_pipe_mapping; 108 109 110 /** Device polling handle. */ 111 usb_device_polling_t *polling; 112 109 113 /** Subdrivers. */ 110 114 usb_hid_subdriver_t *subdrivers; -
uspace/lib/usbdev/include/usb/dev/poll.h
r7dddd7b r71f211f 44 44 #include <stdint.h> 45 45 46 /** Automated polling instance. */ 47 typedef struct usb_device_polling usb_device_polling_t; 48 46 49 /** Parameters and callbacks for automated polling. */ 47 typedef struct {50 typedef struct usb_device_polling_config { 48 51 /** Level of debugging messages from auto polling. 49 52 * 0 - nothing … … 52 55 */ 53 56 int debug; 57 54 58 /** Maximum number of consecutive errors before polling termination. */ 55 59 size_t max_failures; 60 56 61 /** Delay between poll requests in milliseconds. 57 62 * Set to negative value to use value from endpoint descriptor. 58 63 */ 59 64 int delay; 65 60 66 /** Whether to automatically try to clear the HALT feature after 61 67 * the endpoint stalls. 62 68 */ 63 69 bool auto_clear_halt; 70 64 71 /** Callback when data arrives. 65 72 * … … 72 79 bool (*on_data)(usb_device_t *dev, uint8_t *data, size_t data_size, 73 80 void *arg); 81 74 82 /** Callback when polling is terminated. 75 83 * … … 80 88 void (*on_polling_end)(usb_device_t *dev, bool due_to_errors, 81 89 void *arg); 90 82 91 /** Callback when error occurs. 83 92 * … … 88 97 */ 89 98 bool (*on_error)(usb_device_t *dev, int err_code, void *arg); 99 90 100 /** Argument to pass to callbacks. */ 91 101 void *arg; 92 } usb_device_ auto_polling_t;102 } usb_device_polling_config_t; 93 103 94 typedef bool (*usb_polling_callback_t)(usb_device_t *, uint8_t *, size_t, void *); 95 typedef bool (*usb_polling_error_callback_t)(usb_device_t *, int, void *); 96 typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *); 97 98 extern int usb_device_auto_polling(usb_device_t *, usb_endpoint_mapping_t *, 99 const usb_device_auto_polling_t *, size_t); 104 extern int usb_device_poll(usb_device_t *, usb_endpoint_mapping_t *, 105 const usb_device_polling_config_t *, size_t, usb_device_polling_t **); 100 106 101 107 #endif -
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.