Changeset 4deca9b in mainline for uspace/lib/usb
- Timestamp:
- 2011-04-12T11:43:35Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 651b352
- Parents:
- 1324ff3 (diff), 910ca3f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib/usb
- Files:
-
- 5 edited
-
include/usb/host/batch.h (modified) (3 diffs)
-
include/usb/host/device_keeper.h (modified) (2 diffs)
-
include/usb/host/usb_endpoint_manager.h (modified) (2 diffs)
-
src/host/batch.c (modified) (6 diffs)
-
src/host/device_keeper.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/host/batch.h
r1324ff3 r4deca9b 43 43 typedef struct usb_transfer_batch usb_transfer_batch_t; 44 44 struct usb_transfer_batch { 45 endpoint_t *ep; 45 46 link_t link; 46 usb_target_t target;47 usb_transfer_type_t transfer_type;48 usb_speed_t speed;49 usb_direction_t direction;50 47 usbhc_iface_transfer_in_callback_t callback_in; 51 48 usbhc_iface_transfer_out_callback_t callback_out; 49 void *arg; 52 50 char *buffer; 53 char * transport_buffer;51 char *data_buffer; 54 52 size_t buffer_size; 55 53 char *setup_buffer; 56 54 size_t setup_size; 57 size_t max_packet_size;58 55 size_t transfered_size; 59 56 void (*next_step)(usb_transfer_batch_t *); 60 57 int error; 61 58 ddf_fun_t *fun; 62 void *arg;63 endpoint_t *ep;64 59 void *private_data; 65 60 }; … … 67 62 void usb_transfer_batch_init( 68 63 usb_transfer_batch_t *instance, 69 usb_target_t target, 70 usb_transfer_type_t transfer_type, 71 usb_speed_t speed, 72 size_t max_packet_size, 64 endpoint_t *ep, 73 65 char *buffer, 74 char * transport_buffer,66 char *data_buffer, 75 67 size_t buffer_size, 76 68 char *setup_buffer, … … 80 72 void *arg, 81 73 ddf_fun_t *fun, 82 endpoint_t *ep,83 74 void *private_data 84 75 ); -
uspace/lib/usb/include/usb/host/device_keeper.h
r1324ff3 r4deca9b 54 54 usb_speed_t speed; 55 55 bool occupied; 56 link_t endpoints;57 uint16_t control_used;58 56 devman_handle_t handle; 59 57 }; … … 65 63 struct usb_device_info devices[USB_ADDRESS_COUNT]; 66 64 fibril_mutex_t guard; 67 fibril_condvar_t change;68 65 usb_address_t last_address; 69 66 } usb_device_keeper_t; 70 67 71 68 void usb_device_keeper_init(usb_device_keeper_t *instance); 72 73 void usb_device_keeper_reserve_default_address(74 usb_device_keeper_t *instance, usb_speed_t speed);75 76 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance);77 78 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,79 usb_target_t target, const uint8_t *setup_data);80 69 81 70 usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance, -
uspace/lib/usb/include/usb/host/usb_endpoint_manager.h
r1324ff3 r4deca9b 66 66 endpoint_t *ep, size_t data_size); 67 67 68 int usb_endpoint_manager_register_ep_wait(usb_endpoint_manager_t *instance,69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,70 void *data, void (*data_remove_callback)(void* data, void* arg), void *arg,71 size_t bw);72 73 68 int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance, 74 69 usb_address_t address, usb_endpoint_t ep, usb_direction_t direction); … … 80 75 void usb_endpoint_manager_reset_if_need( 81 76 usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data); 77 78 static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance, 79 usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction, 80 usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size, 81 size_t data_size) 82 { 83 endpoint_t *ep = malloc(sizeof(endpoint_t)); 84 if (ep == NULL) 85 return ENOMEM; 86 87 int ret = endpoint_init(ep, address, endpoint, direction, type, speed, 88 max_packet_size); 89 if (ret != EOK) { 90 free(ep); 91 return ret; 92 } 93 94 ret = usb_endpoint_manager_register_ep(instance, ep, data_size); 95 if (ret != EOK) { 96 endpoint_destroy(ep); 97 return ret; 98 } 99 return EOK; 100 } 82 101 #endif 83 102 /** -
uspace/lib/usb/src/host/batch.c
r1324ff3 r4deca9b 41 41 void usb_transfer_batch_init( 42 42 usb_transfer_batch_t *instance, 43 usb_target_t target, 44 usb_transfer_type_t transfer_type, 45 usb_speed_t speed, 46 size_t max_packet_size, 43 endpoint_t *ep, 47 44 char *buffer, 48 char * transport_buffer,45 char *data_buffer, 49 46 size_t buffer_size, 50 47 char *setup_buffer, … … 54 51 void *arg, 55 52 ddf_fun_t *fun, 56 endpoint_t *ep,57 53 void *private_data 58 54 ) … … 60 56 assert(instance); 61 57 link_initialize(&instance->link); 62 instance->target = target; 63 instance->transfer_type = transfer_type; 64 instance->speed = speed; 65 instance->direction = ep->direction; 58 instance->ep = ep; 66 59 instance->callback_in = func_in; 67 60 instance->callback_out = func_out; 68 61 instance->arg = arg; 69 62 instance->buffer = buffer; 70 instance-> transport_buffer = transport_buffer;63 instance->data_buffer = data_buffer; 71 64 instance->buffer_size = buffer_size; 72 65 instance->setup_buffer = setup_buffer; 73 66 instance->setup_size = setup_size; 74 instance->max_packet_size = max_packet_size;75 67 instance->fun = fun; 76 68 instance->private_data = private_data; … … 78 70 instance->next_step = NULL; 79 71 instance->error = EOK; 80 instance->ep = ep;81 72 endpoint_use(instance->ep); 82 73 } … … 105 96 assert(instance); 106 97 assert(instance->callback_in); 98 assert(instance->ep); 107 99 108 100 /* We are data in, we need data */ 109 memcpy(instance->buffer, instance->transport_buffer, 110 instance->buffer_size); 101 memcpy(instance->buffer, instance->data_buffer, instance->buffer_size); 111 102 112 103 usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n", 113 instance, 114 instance->target.address, instance->target.endpoint, 115 usb_str_speed(instance->speed), 116 usb_str_transfer_type_short(instance->transfer_type), 117 instance->transfered_size, 118 str_error(instance->error), instance->error); 104 instance, instance->ep->address, instance->ep->endpoint, 105 usb_str_speed(instance->ep->speed), 106 usb_str_transfer_type_short(instance->ep->transfer_type), 107 instance->transfered_size, str_error(instance->error), instance->error); 119 108 120 109 instance->callback_in(instance->fun, instance->error, … … 132 121 133 122 usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n", 134 instance, 135 instance->target.address, instance->target.endpoint, 136 usb_str_speed(instance->speed), 137 usb_str_transfer_type_short(instance->transfer_type), 123 instance, instance->ep->address, instance->ep->endpoint, 124 usb_str_speed(instance->ep->speed), 125 usb_str_transfer_type_short(instance->ep->transfer_type), 138 126 str_error(instance->error), instance->error); 139 127 -
uspace/lib/usb/src/host/device_keeper.c
r1324ff3 r4deca9b 48 48 { 49 49 assert(instance); 50 fibril_mutex_initialize(&instance->guard);51 fibril_condvar_initialize(&instance->change);52 instance->last_address = 0;53 50 unsigned i = 0; 54 51 for (; i < USB_ADDRESS_COUNT; ++i) { … … 60 57 // (it is needed to allow smooth registration at default address) 61 58 instance->devices[0].occupied = true; 59 instance->last_address = 0; 60 fibril_mutex_initialize(&instance->guard); 62 61 } 63 /*----------------------------------------------------------------------------*/64 /** Attempt to obtain address 0, blocks.65 *66 * @param[in] instance Device keeper structure to use.67 * @param[in] speed Speed of the device requesting default address.68 */69 void usb_device_keeper_reserve_default_address(70 usb_device_keeper_t *instance, usb_speed_t speed)71 {72 assert(instance);73 fibril_mutex_lock(&instance->guard);74 while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {75 fibril_condvar_wait(&instance->change, &instance->guard);76 }77 instance->devices[USB_ADDRESS_DEFAULT].occupied = true;78 instance->devices[USB_ADDRESS_DEFAULT].speed = speed;79 fibril_mutex_unlock(&instance->guard);80 }81 /*----------------------------------------------------------------------------*/82 /** Attempt to obtain address 0, blocks.83 *84 * @param[in] instance Device keeper structure to use.85 * @param[in] speed Speed of the device requesting default address.86 */87 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)88 {89 assert(instance);90 fibril_mutex_lock(&instance->guard);91 instance->devices[USB_ADDRESS_DEFAULT].occupied = false;92 fibril_mutex_unlock(&instance->guard);93 fibril_condvar_signal(&instance->change);94 }95 /*----------------------------------------------------------------------------*/96 62 /*----------------------------------------------------------------------------*/ 97 63 /** Get a free USB address … … 120 86 assert(new_address != USB_ADDRESS_DEFAULT); 121 87 assert(instance->devices[new_address].occupied == false); 88 122 89 instance->devices[new_address].occupied = true; 123 90 instance->devices[new_address].speed = speed; 124 91 instance->last_address = new_address; 92 125 93 fibril_mutex_unlock(&instance->guard); 126 94 return new_address; … … 138 106 assert(instance); 139 107 fibril_mutex_lock(&instance->guard); 108 140 109 assert(address > 0); 141 110 assert(address <= USB11_ADDRESS_MAX); 142 111 assert(instance->devices[address].occupied); 112 143 113 instance->devices[address].handle = handle; 144 114 fibril_mutex_unlock(&instance->guard); … … 159 129 fibril_mutex_lock(&instance->guard); 160 130 assert(instance->devices[address].occupied); 131 161 132 instance->devices[address].occupied = false; 162 133 fibril_mutex_unlock(&instance->guard); … … 177 148 while (address <= USB11_ADDRESS_MAX) { 178 149 if (instance->devices[address].handle == handle) { 150 assert(instance->devices[address].occupied); 179 151 fibril_mutex_unlock(&instance->guard); 180 152 return address; … … 198 170 assert(address >= 0); 199 171 assert(address <= USB11_ADDRESS_MAX); 172 200 173 return instance->devices[address].speed; 201 174 }
Note:
See TracChangeset
for help on using the changeset viewer.
