Changeset b5ec347 in mainline
- Timestamp:
- 2010-12-05T22:32:45Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7964475, 98d06b8
- Parents:
- 45e9cc6
- Location:
- uspace
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/main.c
r45e9cc6 rb5ec347 30 30 #include <errno.h> 31 31 #include "usbhub.h" 32 #include "usbhub_private.h" 33 34 35 usb_general_list_t usb_hub_list; 32 36 33 37 static driver_ops_t hub_driver_ops = { … … 42 46 int main(int argc, char *argv[]) 43 47 { 48 usb_lst_init(&usb_hub_list); 44 49 return driver_main(&hub_driver); 45 50 } -
uspace/drv/usbhub/usbhub.h
r45e9cc6 rb5ec347 38 38 #define NAME "usbhub" 39 39 40 #include "usb/hcdhubd.h" 41 42 43 44 /** Information about attached hub. */ 45 typedef struct { 46 /** Number of ports. */ 47 int port_count; 48 /** General device info. */ 49 usb_hcd_attached_device_info_t * device; 50 } usb_hub_info_t; 51 52 40 53 int usb_add_hub_device(device_t *); 41 54 -
uspace/drv/usbhub/utils.c
r45e9cc6 rb5ec347 43 43 #include <usb/classes/hub.h> 44 44 #include "usbhub.h" 45 #include "usbhub_private.h" 46 #include "port_status.h" 47 #include <usb/devreq.h> 45 48 46 49 static void check_hub_changes(void); … … 54 57 //********************************************* 55 58 59 //hub descriptor utils 56 60 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) { 57 61 //base size … … 85 89 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 86 90 if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL; 87 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t));91 usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t); 88 92 //uint8_t size = sdescriptor[0]; 89 93 result->ports_count = sdescriptor[2]; … … 102 106 } 103 107 108 //control transactions 109 int usb_drv_sync_control_read( 110 int phone, usb_target_t target, 111 usb_device_request_setup_packet_t * request, 112 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size 113 ){ 114 usb_handle_t handle; 115 int opResult; 116 //setup 117 opResult = usb_drv_async_control_read_setup(phone, target, 118 request, sizeof(usb_device_request_setup_packet_t), 119 &handle); 120 if(opResult!=EOK){ 121 return opResult; 122 } 123 opResult = usb_drv_async_wait_for(handle); 124 if(opResult!=EOK){ 125 return opResult; 126 } 127 //read 128 opResult = usb_drv_async_control_read_data(phone, target, 129 rcvd_buffer, rcvd_size, actual_size, 130 &handle); 131 if(opResult!=EOK){ 132 return opResult; 133 } 134 opResult = usb_drv_async_wait_for(handle); 135 if(opResult!=EOK){ 136 return opResult; 137 } 138 //finalize 139 opResult = usb_drv_async_control_read_status(phone, target, 140 &handle); 141 if(opResult!=EOK){ 142 return opResult; 143 } 144 opResult = usb_drv_async_wait_for(handle); 145 if(opResult!=EOK){ 146 return opResult; 147 } 148 return EOK; 149 } 150 151 152 int usb_drv_sync_control_write( 153 int phone, usb_target_t target, 154 usb_device_request_setup_packet_t * request, 155 void * sent_buffer, size_t sent_size 156 ){ 157 usb_handle_t handle; 158 int opResult; 159 //setup 160 opResult = usb_drv_async_control_write_setup(phone, target, 161 request, sizeof(usb_device_request_setup_packet_t), 162 &handle); 163 if(opResult!=EOK){ 164 return opResult; 165 } 166 opResult = usb_drv_async_wait_for(handle); 167 if(opResult!=EOK){ 168 return opResult; 169 } 170 //write 171 opResult = usb_drv_async_control_write_data(phone, target, 172 sent_buffer, sent_size, 173 &handle); 174 if(opResult!=EOK){ 175 return opResult; 176 } 177 opResult = usb_drv_async_wait_for(handle); 178 if(opResult!=EOK){ 179 return opResult; 180 } 181 //finalize 182 opResult = usb_drv_async_control_write_status(phone, target, 183 &handle); 184 if(opResult!=EOK){ 185 return opResult; 186 } 187 opResult = usb_drv_async_wait_for(handle); 188 if(opResult!=EOK){ 189 return opResult; 190 } 191 return EOK; 192 } 193 194 //list implementation 195 196 usb_general_list_t * usb_lst_create(void){ 197 usb_general_list_t* result = usb_new(usb_general_list_t); 198 usb_lst_init(result); 199 return result; 200 } 201 202 void usb_lst_init(usb_general_list_t * lst){ 203 lst->prev = lst; 204 lst->next = lst; 205 lst->data = NULL; 206 } 207 208 void usb_lst_prepend(usb_general_list_t* item, void* data){ 209 usb_general_list_t* appended = usb_new(usb_general_list_t); 210 appended->data=data; 211 appended->next=item; 212 appended->prev=item->prev; 213 item->prev->next = appended; 214 item->prev = appended; 215 } 216 217 void usb_lst_append(usb_general_list_t* item, void* data){ 218 usb_general_list_t* appended =usb_new(usb_general_list_t); 219 appended->data=data; 220 appended->next=item->next; 221 appended->prev=item; 222 item->next->prev = appended; 223 item->next = appended; 224 } 225 226 227 void usb_lst_remove(usb_general_list_t* item){ 228 item->next->prev = item->prev; 229 item->prev->next = item->next; 230 } 231 232 104 233 105 234 //********************************************* … … 109 238 //********************************************* 110 239 111 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 112 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 113 240 usb_hub_info_t * usb_create_hub_info(device_t * device) { 241 usb_hub_info_t* result = usb_new(usb_hub_info_t); 242 //result->device = device; 243 result->port_count = -1; 244 245 //get hc connection 246 int hc = usb_drv_hc_connect(NULL, 0); 247 printf("[usb_hub] phone to hc = %d\n",hc); 248 if (hc < 0) { 249 return result; 250 } 251 //get some hub info 252 253 usb_address_t addr = usb_drv_get_my_address(hc,device); 254 printf("[usb_hub] addres of newly created hub = %d\n",addr); 255 /*if(addr<0){ 256 //return result; 257 258 }*/ 259 result->device = usb_new(usb_hcd_attached_device_info_t); 260 result->device->address=addr; 261 //hub configuration? 262 printf("[usb_hub] hub info created\n"); 263 264 265 114 266 return result; 115 267 } … … 122 274 int usb_add_hub_device(device_t *dev) { 123 275 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 124 125 check_hub_changes(); 276 printf("[usb_hub] hub device\n"); 126 277 127 278 /* … … 132 283 133 284 //create the hub structure 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 135 (void)hub_info; 285 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 286 usb_lst_append(&usb_hub_list, hub_info); 287 printf("[usb_hub] hub info added to list\n"); 288 //(void)hub_info; 289 check_hub_changes(); 290 printf("[usb_hub] hub dev added\n"); 291 //test port status type... 136 292 137 293 return EOK; 138 294 //return ENOTSUP; 139 295 } 296 297 140 298 141 299 … … 146 304 * Iterate through all hubs. 147 305 */ 148 for (; false; ) { 306 usb_general_list_t * lst_item; 307 for (lst_item = usb_hub_list.next; 308 lst_item != &usb_hub_list; 309 lst_item = lst_item->next) { 310 printf("[usb_hub] checking hub changes\n"); 149 311 /* 150 312 * Check status change pipe of this hub. 151 313 */ 314 152 315 usb_target_t target = { 153 316 .address = 5, 154 317 .endpoint = 1 155 318 }; 319 /// \TODO uncomment once it works correctly 320 //target.address = usb_create_hub_info(lst_item)->device->address; 156 321 157 322 size_t port_count = 7; … … 160 325 * Connect to respective HC. 161 326 */ 327 /// \FIXME this is incorrect code: here 328 /// must be used particular device instead of NULL 162 329 int hc = usb_drv_hc_connect(NULL, 0); 163 330 if (hc < 0) { … … 174 341 /* 175 342 * Send the request. 176 * FIXME: check returned value for possible errors 177 */ 178 usb_drv_async_interrupt_in(hc, target, 343 */ 344 int opResult = usb_drv_async_interrupt_in(hc, target, 179 345 change_bitmap, byte_length, &actual_size, 180 346 &handle); 181 347 182 348 usb_drv_async_wait_for(handle); 349 350 if(opResult!=EOK){ 351 printf("[usb_hub] something went wrong while getting status of hub\n"); 352 continue; 353 } 354 unsigned int port; 355 for(port=0;port<port_count;++port){ 356 bool interrupt = (((uint8_t*)change_bitmap)[port/8]>>(port%8))%2; 357 if(interrupt){ 358 printf("[usb_hub] interrupt at port %d\n",port); 359 //determine type of change 360 usb_port_status_t status; 361 size_t rcvd_size; 362 usb_device_request_setup_packet_t request; 363 usb_hub_set_port_status_request(&request,port); 364 365 opResult = usb_drv_sync_control_read( 366 hc, target, 367 &request, 368 &status, 4, &rcvd_size 369 ); 370 if(opResult!=EOK){ 371 continue; 372 } 373 if(rcvd_size!=sizeof(usb_port_status_t)){ 374 continue; 375 } 376 377 if(usb_port_connect_change(&status)){ 378 printf("[usb_hub] some connectionchanged\n"); 379 usb_drv_reserve_default_address(hc); 380 //enable port 381 usb_hub_set_enable_port_request(&request,port); 382 opResult = usb_drv_sync_control_write( 383 hc, target, 384 &request, 385 NULL, 0 386 ); 387 if(opResult!=EOK){ 388 continue; 389 } 390 //set address 391 usb_address_t new_device_address = 392 usb_drv_request_address(hc); 393 usb_hub_set_set_address_request 394 (&request,new_device_address); 395 opResult = usb_drv_sync_control_write( 396 hc, target, 397 &request, 398 NULL, 0 399 ); 400 //some other work with drivers 401 /// \TODO do the work with drivers 402 403 404 usb_drv_release_default_address(hc); 405 }else{ 406 printf("[usb_hub] no supported event occured\n"); 407 } 408 /// \TODO handle other changes 409 /// \TODO debug log for various situations 410 411 412 413 /* 414 //configure device 415 usb_drv_reserve_default_address(hc); 416 417 usb_address_t new_device_address = usb_drv_request_address(hc); 418 419 420 usb_drv_release_default_address(hc); 421 * */ 422 } 423 } 424 183 425 184 426 /* -
uspace/lib/usb/include/usb/classes/hub.h
r45e9cc6 rb5ec347 213 213 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 214 214 215 /**216 * @brief create hub structure instance217 *218 * @param device219 * @return220 */221 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device);222 215 223 216 -
uspace/lib/usb/include/usb/hcdhubd.h
r45e9cc6 rb5ec347 65 65 } usb_hcd_attached_device_info_t; 66 66 67 /** Information about attached hub. */68 typedef struct {69 /** Number of ports. */70 size_t port_count;71 /** General device info. */72 usb_hcd_attached_device_info_t *device;73 /** Link to other hubs. */74 link_t link;75 } usb_hcd_hub_info_t;76 67 77 68 /** Host controller device. */
Note:
See TracChangeset
for help on using the changeset viewer.