Changeset 37f7cfe in mainline
- Timestamp:
- 2010-12-13T01:11:27Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 75732da, a9b6bec
- Parents:
- 682b697 (diff), f9a0cef (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
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
r682b697 r37f7cfe 55 55 #include "stdreq.h" 56 56 57 #define LOOPS 5 57 /** Pause between individual key-presses in seconds. */ 58 #define KEY_PRESS_DELAY 2 58 59 #define NAME "virt-usb-kbd" 59 60 … … 83 84 } 84 85 86 /** Compares current and last status of pressed keys. 87 * 88 * @warning Has side-efect - changes status_last field. 89 * 90 * @param status_now Status now. 91 * @param status_last Last status. 92 * @param len Size of status. 93 * @return Whether they are the same. 94 */ 95 static bool keypress_check_with_last_request(uint8_t *status_now, 96 uint8_t *status_last, size_t len) 97 { 98 bool same = true; 99 size_t i; 100 for (i = 0; i < len; i++) { 101 if (status_now[i] != status_last[i]) { 102 status_last[i] = status_now[i]; 103 same = false; 104 } 105 } 106 return same; 107 } 108 85 109 static int on_request_for_data(struct usbvirt_device *dev, 86 110 usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size) 87 111 { 112 static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE]; 113 88 114 if (size < 2 + KB_MAX_KEYS_AT_ONCE) { 89 115 return EINVAL; … … 101 127 } 102 128 129 if (keypress_check_with_last_request(data, last_data, 130 2 + KB_MAX_KEYS_AT_ONCE)) { 131 *actual_size = 0; 132 return EOK; 133 } 134 103 135 memcpy(buffer, &data, *actual_size); 104 136 … … 152 184 .ops = &keyboard_ops, 153 185 .descriptors = &descriptors, 186 .lib_debug_level = 3, 187 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL, 154 188 .name = "keyboard" 155 189 }; … … 177 211 printf("\n"); 178 212 179 fibril_sleep( 1);213 fibril_sleep(KEY_PRESS_DELAY); 180 214 } 181 215 … … 223 257 224 258 printf("%s: Simulating keyboard events...\n", NAME); 225 while (1){259 while (1) { 226 260 kb_process_events(&status, keyboard_events, keyboard_events_count, 227 261 on_keyboard_change); -
uspace/drv/usbhub/main.c
r682b697 r37f7cfe 50 50 while(true){ 51 51 usb_hub_check_hub_changes(); 52 async_usleep(1000 0000);52 async_usleep(1000 * 1000); 53 53 } 54 54 return 0; -
uspace/drv/usbhub/usbhub_private.h
r682b697 r37f7cfe 182 182 } 183 183 184 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address, 185 int port_index, 186 usb_hub_class_feature_t feature) { 187 usb_target_t target = { 188 .address = address, 189 .endpoint = 0 190 }; 191 usb_device_request_setup_packet_t clear_request = { 192 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, 193 .request = USB_DEVREQ_CLEAR_FEATURE, 194 .length = 0, 195 .index = port_index 196 }; 197 clear_request.value = feature; 198 return usb_drv_psync_control_write(hc, target, &clear_request, 199 sizeof(clear_request), NULL, 0); 200 } 201 184 202 185 203 -
uspace/drv/usbhub/utils.c
r682b697 r37f7cfe 506 506 int hc, uint16_t port, usb_target_t target) { 507 507 508 usb_device_request_setup_packet_t request;509 508 int opResult; 510 509 printf("[usb_hub] finalizing add device\n"); 511 usb_address_t new_device_address = 512 usb_drv_request_address(hc); 513 usb_hub_set_set_address_request 514 (&request, new_device_address); 515 opResult = usb_drv_sync_control_write( 516 hc, target, 517 &request, 518 NULL, 0 519 ); 510 opResult = usb_hub_clear_port_feature(hc, target.address, 511 port, USB_HUB_FEATURE_C_PORT_RESET); 512 if (opResult != EOK) { 513 goto release; 514 } 515 516 /* Request address at from host controller. */ 517 usb_address_t new_device_address = usb_drv_request_address(hc); 518 if (new_device_address < 0) { 519 printf("[usb_hub] failed to get free USB address\n"); 520 opResult = new_device_address; 521 goto release; 522 } 523 printf("[usb_hub] setting new address\n"); 524 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 525 new_device_address); 526 520 527 if (opResult != EOK) { 521 528 printf("[usb_hub] could not set address for new device\n"); 522 //will retry later... 523 return; 524 } 525 529 goto release; 530 } 531 532 release: 533 printf("[usb_hub] releasing default address\n"); 526 534 usb_drv_release_default_address(hc); 535 if (opResult != EOK) { 536 return; 537 } 527 538 528 539 devman_handle_t child_handle; 529 540 opResult = usb_drv_register_child_in_devman(hc, hub->device, 530 new_device_address, &child_handle);541 new_device_address, &child_handle); 531 542 if (opResult != EOK) { 532 543 printf("[usb_hub] could not start driver for new device \n"); … … 543 554 printf("[usb_hub] new device address %d, handle %d\n", 544 555 new_device_address, child_handle); 545 sleep(60);546 556 547 557 } … … 620 630 //something connected/disconnected 621 631 if (usb_port_connect_change(&status)) { 632 opResult = usb_hub_clear_port_feature(hc, target.address, 633 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 634 // TODO: check opResult 622 635 if (usb_port_dev_connected(&status)) { 623 636 printf("[usb_hub] some connection changed\n"); … … 629 642 //port reset 630 643 if (usb_port_reset_completed(&status)) { 631 printf("[usb_hub] finalizing add device\n");644 printf("[usb_hub] port reset complete\n"); 632 645 if (usb_port_enabled(&status)) { 633 646 usb_hub_finalize_add_device(hub, hc, port, target); … … 670 683 lst_item != &usb_hub_list; 671 684 lst_item = lst_item->next) { 672 printf("[usb_hub] checking hub changes\n");673 685 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 674 686 /* … … 679 691 target.address = hub_info->usb_device->address; 680 692 target.endpoint = 1;/// \TODO get from endpoint descriptor 681 printf("checking changes for hub at addr %d \n",target.address); 693 printf("[usb_hub] checking changes for hub at addr %d\n", 694 target.address); 682 695 683 696 size_t port_count = hub_info->port_count; -
uspace/drv/usbkbd/main.c
r682b697 r37f7cfe 39 39 #define NAME "usbkbd" 40 40 41 static const usb_endpoint_t CONTROL_EP = 0; 41 #define GUESSED_POLL_ENDPOINT 1 42 42 43 43 /* … … 155 155 156 156 // default endpoint 157 kbd_dev-> default_ep = CONTROL_EP;157 kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT; 158 158 159 159 /* … … 204 204 usb_target_t poll_target = { 205 205 .address = kbd_dev->address, 206 .endpoint = kbd_dev-> default_ep206 .endpoint = kbd_dev->poll_endpoint 207 207 }; 208 208 209 209 while (true) { 210 async_usleep(1000 * 1000); 210 211 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 211 212 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); -
uspace/drv/vhc/hc.c
r682b697 r37f7cfe 50 50 #include "hub.h" 51 51 52 #define USLEEP_BASE (0 * 5 00* 1000)52 #define USLEEP_BASE (0 * 5 * 1000) 53 53 54 #define USLEEP_VAR 50 0054 #define USLEEP_VAR 50 55 55 56 56 #define SHORTENING_VAR 15 … … 89 89 usb_transaction_outcome_t outcome) 90 90 { 91 dprintf(3, " processing transaction " TRANSACTION_FORMAT ", outcome: %s",91 dprintf(3, "transaction " TRANSACTION_FORMAT " done, outcome: %s", 92 92 TRANSACTION_PRINTF(*transaction), 93 93 usb_str_transaction_outcome(outcome)); … … 116 116 char ports[HUB_PORT_COUNT + 2]; 117 117 hub_get_port_statuses(ports, HUB_PORT_COUNT + 1); 118 dprintf( 0, "virtual hub: addr=%d ports=%s",118 dprintf(4, "virtual hub: addr=%d ports=%s", 119 119 virthub_dev.address, ports); 120 120 … … 124 124 list_remove(first_transaction_link); 125 125 126 127 dprintf(0, "about to process " TRANSACTION_FORMAT " (vhub:%s)", 128 TRANSACTION_PRINTF(*transaction), ports); 129 126 130 dprintf(3, "processing transaction " TRANSACTION_FORMAT "", 127 131 TRANSACTION_PRINTF(*transaction)); -
uspace/drv/vhc/hcd.c
r682b697 r37f7cfe 110 110 printf("%s: virtual USB host controller driver.\n", NAME); 111 111 112 usb_dprintf_enable(NAME, 2);112 usb_dprintf_enable(NAME, 0); 113 113 114 114 fid_t fid = fibril_create(hc_manager_fibril, NULL); -
uspace/drv/vhc/hub.c
r682b697 r37f7cfe 144 144 .ops = &hub_ops, 145 145 .descriptors = &descriptors, 146 .lib_debug_level = 1,146 .lib_debug_level = 0, 147 147 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL 148 148 }; … … 181 181 hub_port_t *port = &hub_dev.ports[i]; 182 182 183 port->index = (int) i ;183 port->index = (int) i + 1; 184 184 port->device = NULL; 185 185 port->state = HUB_PORT_STATE_NOT_CONFIGURED; 186 186 port->status_change = 0; 187 fibril_mutex_initialize(&port->guard); 187 188 } 188 189 … … 225 226 for (i = 0; i < HUB_PORT_COUNT; i++) { 226 227 hub_port_t *port = &hub_dev.ports[i]; 228 fibril_mutex_lock(&port->guard); 227 229 228 230 if (port->device != NULL) { 231 fibril_mutex_unlock(&port->guard); 229 232 continue; 230 233 } … … 241 244 //if (port->state == HUB_PORT_STATE_DISCONNECTED) { 242 245 port->state = HUB_PORT_STATE_DISABLED; 243 set_port_status_change (port, HUB_STATUS_C_PORT_CONNECTION);246 set_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 244 247 //} 245 248 249 fibril_mutex_unlock(&port->guard); 250 246 251 return i; 247 252 } -
uspace/drv/vhc/hubintern.h
r682b697 r37f7cfe 37 37 38 38 #include "hub.h" 39 #include <fibril_synch.h> 39 40 40 41 /** Endpoint number for status change pipe. */ … … 124 125 hub_port_state_t state; 125 126 uint16_t status_change; 127 fibril_mutex_t guard; 126 128 } hub_port_t; 127 129 … … 139 141 void clear_port_status_change(hub_port_t *, uint16_t); 140 142 void set_port_status_change(hub_port_t *, uint16_t); 143 void set_port_status_change_nl(hub_port_t *, uint16_t); 141 144 142 145 -
uspace/drv/vhc/hubops.c
r682b697 r37f7cfe 67 67 void *buffer, size_t size, size_t *actual_size); 68 68 static void set_port_state(hub_port_t *, hub_port_state_t); 69 static void clear_port_status_change_nl(hub_port_t *, uint16_t); 70 static void set_port_state_nl(hub_port_t *, hub_port_state_t); 69 71 70 72 /** Standard USB requests. */ … … 135 137 async_usleep(change->delay); 136 138 139 fibril_mutex_lock(&change->port->guard); 137 140 if (change->port->state == change->old_state) { 138 set_port_state(change->port, change->new_state); 139 } 141 set_port_state_nl(change->port, change->new_state); 142 } 143 fibril_mutex_unlock(&change->port->guard); 140 144 141 145 free(change); … … 166 170 void set_port_state(hub_port_t *port, hub_port_state_t state) 167 171 { 168 dprintf(1, "setting port %d state to %d (%c)", port->index, 169 state, hub_port_state_as_char(state)); 172 fibril_mutex_lock(&port->guard); 173 set_port_state_nl(port, state); 174 fibril_mutex_unlock(&port->guard); 175 } 176 177 void set_port_state_nl(hub_port_t *port, hub_port_state_t state) 178 { 179 180 dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)", 181 port->index, 182 state, hub_port_state_as_char(state), 183 hub_port_state_as_char(port->state), 184 (unsigned int) port->status_change); 170 185 171 186 if (state == HUB_PORT_STATE_POWERED_OFF) { 172 clear_port_status_change (port, HUB_STATUS_C_PORT_CONNECTION);173 clear_port_status_change (port, HUB_STATUS_C_PORT_ENABLE);174 clear_port_status_change (port, HUB_STATUS_C_PORT_RESET);187 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 188 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE); 189 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 175 190 } 176 191 if (state == HUB_PORT_STATE_RESUMING) { … … 184 199 if ((port->state == HUB_PORT_STATE_RESETTING) 185 200 && (state == HUB_PORT_STATE_ENABLED)) { 186 set_port_status_change (port, HUB_STATUS_C_PORT_RESET);201 set_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 187 202 } 188 203 … … 212 227 _GET_PORT(port, portindex); 213 228 229 fibril_mutex_lock(&port->guard); 230 int rc = ENOTSUP; 231 214 232 switch (feature) { 215 233 case USB_HUB_FEATURE_PORT_ENABLE: 216 234 if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED) 217 235 && (port->state != HUB_PORT_STATE_POWERED_OFF)) { 218 set_port_state(port, HUB_PORT_STATE_DISABLED); 219 } 220 return EOK; 236 set_port_state_nl(port, HUB_PORT_STATE_DISABLED); 237 } 238 rc = EOK; 239 break; 221 240 222 241 case USB_HUB_FEATURE_PORT_SUSPEND: 223 242 if (port->state != HUB_PORT_STATE_SUSPENDED) { 224 return EOK; 225 } 226 set_port_state(port, HUB_PORT_STATE_RESUMING); 227 return EOK; 243 rc = EOK; 244 break; 245 } 246 set_port_state_nl(port, HUB_PORT_STATE_RESUMING); 247 rc = EOK; 248 break; 228 249 229 250 case USB_HUB_FEATURE_PORT_POWER: 230 251 if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) { 231 set_port_state(port, HUB_PORT_STATE_POWERED_OFF); 232 } 233 return EOK; 252 set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF); 253 } 254 rc = EOK; 255 break; 234 256 235 257 case USB_HUB_FEATURE_C_PORT_CONNECTION: 236 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 237 return EOK; 258 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 259 rc = EOK; 260 break; 238 261 239 262 case USB_HUB_FEATURE_C_PORT_ENABLE: 240 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE); 241 return EOK; 263 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE); 264 rc = EOK; 265 break; 242 266 243 267 case USB_HUB_FEATURE_C_PORT_SUSPEND: 244 clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND); 245 return EOK; 268 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND); 269 rc = EOK; 270 break; 246 271 247 272 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: 248 clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT); 249 return EOK; 250 } 251 252 return ENOTSUP; 273 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT); 274 rc = EOK; 275 break; 276 277 case USB_HUB_FEATURE_C_PORT_RESET: 278 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 279 rc = EOK; 280 break; 281 } 282 283 fibril_mutex_unlock(&port->guard); 284 285 return rc; 253 286 } 254 287 … … 285 318 _GET_PORT(port, portindex); 286 319 320 fibril_mutex_lock(&port->guard); 321 287 322 uint32_t status; 288 323 status = MAKE_BYTE( … … 312 347 status |= (port->status_change << 16); 313 348 349 fibril_mutex_unlock(&port->guard); 350 314 351 dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex, 315 352 (unsigned int) status); … … 327 364 _GET_PORT(port, portindex); 328 365 366 fibril_mutex_lock(&port->guard); 367 368 int rc = ENOTSUP; 369 329 370 switch (feature) { 330 371 case USB_HUB_FEATURE_PORT_RESET: 331 372 if (port->state != HUB_PORT_STATE_POWERED_OFF) { 332 set_port_state(port, HUB_PORT_STATE_RESETTING); 333 } 334 return EOK; 373 set_port_state_nl(port, HUB_PORT_STATE_RESETTING); 374 } 375 rc = EOK; 376 break; 335 377 336 378 case USB_HUB_FEATURE_PORT_SUSPEND: 337 379 if (port->state == HUB_PORT_STATE_ENABLED) { 338 set_port_state(port, HUB_PORT_STATE_SUSPENDED); 339 } 340 return EOK; 380 set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED); 381 } 382 rc = EOK; 383 break; 341 384 342 385 case USB_HUB_FEATURE_PORT_POWER: 343 386 if (port->state == HUB_PORT_STATE_POWERED_OFF) { 344 set_port_state(port, HUB_PORT_STATE_DISCONNECTED); 345 } 346 return EOK; 347 } 348 return ENOTSUP; 387 set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED); 388 } 389 rc = EOK; 390 break; 391 } 392 393 fibril_mutex_unlock(&port->guard); 394 return rc; 349 395 } 350 396 … … 416 462 } 417 463 464 void clear_port_status_change_nl(hub_port_t *port, uint16_t change) 465 { 466 port->status_change &= (~change); 467 dprintf(2, "cleared port %d status change %d (%u)", port->index, 468 (int)change, (unsigned int) port->status_change); 469 } 470 471 void set_port_status_change_nl(hub_port_t *port, uint16_t change) 472 { 473 port->status_change |= change; 474 dprintf(2, "set port %d status change %d (%u)", port->index, 475 (int)change, (unsigned int) port->status_change); 476 477 } 478 418 479 void clear_port_status_change(hub_port_t *port, uint16_t change) 419 480 { 420 port->status_change &= (~change); 481 fibril_mutex_lock(&port->guard); 482 clear_port_status_change_nl(port, change); 483 fibril_mutex_unlock(&port->guard); 421 484 } 422 485 423 486 void set_port_status_change(hub_port_t *port, uint16_t change) 424 487 { 425 port->status_change |= change; 488 fibril_mutex_lock(&port->guard); 489 set_port_status_change_nl(port, change); 490 fibril_mutex_unlock(&port->guard); 426 491 } 427 492 … … 441 506 hub_port_t *port = &hub_dev.ports[i]; 442 507 508 fibril_mutex_lock(&port->guard); 443 509 if (port->status_change != 0) { 444 510 change_map |= (1 << (i + 1)); 445 511 } 512 fibril_mutex_unlock(&port->guard); 446 513 } 447 514 -
uspace/lib/usb/include/usb/classes/hid.h
r682b697 r37f7cfe 100 100 device_t *device; 101 101 usb_address_t address; 102 usb_endpoint_t default_ep;102 usb_endpoint_t poll_endpoint; 103 103 usb_hid_report_parser_t *parser; 104 104 } usb_hid_dev_kbd_t; -
uspace/lib/usbvirt/callback.c
r682b697 r37f7cfe 155 155 * If the request was processed, we will send data back. 156 156 */ 157 if ( rc == EOK) {157 if ((rc == EOK) && (expected_len > 0)) { 158 158 size_t receive_len; 159 159 ipc_callid_t callid;
Note:
See TracChangeset
for help on using the changeset viewer.