Changes in / [7964475:cdc1aa1] in mainline
- Location:
- uspace
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/main.c
r7964475 rcdc1aa1 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;36 32 37 33 static driver_ops_t hub_driver_ops = { … … 46 42 int main(int argc, char *argv[]) 47 43 { 48 usb_lst_init(&usb_hub_list);49 44 return driver_main(&hub_driver); 50 45 } -
uspace/drv/usbhub/usbhub.h
r7964475 rcdc1aa1 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 53 40 int usb_add_hub_device(device_t *); 54 41 -
uspace/drv/usbhub/utils.c
r7964475 rcdc1aa1 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>48 45 49 46 static void check_hub_changes(void); … … 57 54 //********************************************* 58 55 59 //hub descriptor utils60 56 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) { 61 57 //base size … … 89 85 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 90 86 if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL; 91 usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t);87 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t)); 92 88 //uint8_t size = sdescriptor[0]; 93 89 result->ports_count = sdescriptor[2]; … … 106 102 } 107 103 108 //control transactions109 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_size113 ){114 usb_handle_t handle;115 int opResult;116 //setup117 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 //read128 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 //finalize139 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_size156 ){157 usb_handle_t handle;158 int opResult;159 //setup160 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 //write171 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 //finalize182 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 implementation195 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 233 104 234 105 //********************************************* … … 238 109 //********************************************* 239 110 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 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 266 114 return result; 267 115 } … … 274 122 int usb_add_hub_device(device_t *dev) { 275 123 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 276 printf("[usb_hub] hub device\n"); 124 125 check_hub_changes(); 277 126 278 127 /* … … 283 132 284 133 //create the hub structure 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... 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 135 (void)hub_info; 292 136 293 137 return EOK; 294 138 //return ENOTSUP; 295 139 } 296 297 298 140 299 141 … … 304 146 * Iterate through all hubs. 305 147 */ 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"); 148 for (; false; ) { 311 149 /* 312 150 * Check status change pipe of this hub. 313 151 */ 314 315 152 usb_target_t target = { 316 153 .address = 5, 317 154 .endpoint = 1 318 155 }; 319 /// \TODO uncomment once it works correctly320 //target.address = usb_create_hub_info(lst_item)->device->address;321 156 322 157 size_t port_count = 7; … … 325 160 * Connect to respective HC. 326 161 */ 327 /// \FIXME this is incorrect code: here328 /// must be used particular device instead of NULL329 162 int hc = usb_drv_hc_connect(NULL, 0); 330 163 if (hc < 0) { … … 341 174 /* 342 175 * Send the request. 343 */ 344 int opResult = usb_drv_async_interrupt_in(hc, target, 176 * FIXME: check returned value for possible errors 177 */ 178 usb_drv_async_interrupt_in(hc, target, 345 179 change_bitmap, byte_length, &actual_size, 346 180 &handle); 347 181 348 182 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 change360 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_size369 );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 port381 usb_hub_set_enable_port_request(&request,port);382 opResult = usb_drv_sync_control_write(383 hc, target,384 &request,385 NULL, 0386 );387 if(opResult!=EOK){388 continue;389 }390 //set address391 usb_address_t new_device_address =392 usb_drv_request_address(hc);393 usb_hub_set_set_address_request394 (&request,new_device_address);395 opResult = usb_drv_sync_control_write(396 hc, target,397 &request,398 NULL, 0399 );400 //some other work with drivers401 /// \TODO do the work with drivers402 403 404 usb_drv_release_default_address(hc);405 }else{406 printf("[usb_hub] no supported event occured\n");407 }408 /// \TODO handle other changes409 /// \TODO debug log for various situations410 411 412 413 /*414 //configure device415 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 425 183 426 184 /* -
uspace/lib/usb/include/usb/classes/hub.h
r7964475 rcdc1aa1 213 213 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 214 214 215 /** 216 * @brief create hub structure instance 217 * 218 * @param device 219 * @return 220 */ 221 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device); 215 222 216 223 -
uspace/lib/usb/include/usb/hcdhubd.h
r7964475 rcdc1aa1 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; 67 76 68 77 /** Host controller device. */
Note:
See TracChangeset
for help on using the changeset viewer.