Changeset b5ec347 in mainline


Ignore:
Timestamp:
2010-12-05T22:32:45Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7964475, 98d06b8
Parents:
45e9cc6
Message:

various convenience definitions
removing of usb_hcd_hub_info_t from public declarations
usb-side implementation of adding a new device (assign addressand enable port)

Location:
uspace
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/main.c

    r45e9cc6 rb5ec347  
    3030#include <errno.h>
    3131#include "usbhub.h"
     32#include "usbhub_private.h"
     33
     34
     35usb_general_list_t usb_hub_list;
    3236
    3337static driver_ops_t hub_driver_ops = {
     
    4246int main(int argc, char *argv[])
    4347{
     48        usb_lst_init(&usb_hub_list);
    4449        return driver_main(&hub_driver);
    4550}
  • uspace/drv/usbhub/usbhub.h

    r45e9cc6 rb5ec347  
    3838#define NAME "usbhub"
    3939
     40#include "usb/hcdhubd.h"
     41
     42
     43
     44/** Information about attached hub. */
     45typedef 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
    4053int usb_add_hub_device(device_t *);
    4154
  • uspace/drv/usbhub/utils.c

    r45e9cc6 rb5ec347  
    4343#include <usb/classes/hub.h>
    4444#include "usbhub.h"
     45#include "usbhub_private.h"
     46#include "port_status.h"
     47#include <usb/devreq.h>
    4548
    4649static void check_hub_changes(void);
     
    5457//*********************************************
    5558
     59//hub descriptor utils
    5660void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) {
    5761        //base size
     
    8589        uint8_t * sdescriptor = (uint8_t*) serialized_descriptor;
    8690        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);
    8892        //uint8_t size = sdescriptor[0];
    8993        result->ports_count = sdescriptor[2];
     
    102106}
    103107
     108//control transactions
     109int 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
     152int 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
     196usb_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
     202void usb_lst_init(usb_general_list_t * lst){
     203        lst->prev = lst;
     204        lst->next = lst;
     205        lst->data = NULL;
     206}
     207
     208void 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
     217void 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
     227void usb_lst_remove(usb_general_list_t* item){
     228        item->next->prev = item->prev;
     229        item->prev->next = item->next;
     230}
     231
     232
    104233
    105234//*********************************************
     
    109238//*********************************************
    110239
    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 
     240usb_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       
    114266        return result;
    115267}
     
    122274int usb_add_hub_device(device_t *dev) {
    123275        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    124 
    125         check_hub_changes();
     276        printf("[usb_hub] hub device\n");
    126277
    127278        /*
     
    132283
    133284        //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...
    136292
    137293        return EOK;
    138294        //return ENOTSUP;
    139295}
     296
     297
    140298
    141299
     
    146304         * Iterate through all hubs.
    147305         */
    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");
    149311                /*
    150312                 * Check status change pipe of this hub.
    151313                 */
     314               
    152315                usb_target_t target = {
    153316                        .address = 5,
    154317                        .endpoint = 1
    155318                };
     319                /// \TODO uncomment once it works correctly
     320                //target.address = usb_create_hub_info(lst_item)->device->address;
    156321
    157322                size_t port_count = 7;
     
    160325                 * Connect to respective HC.
    161326                 */
     327                /// \FIXME this is incorrect code: here
     328                /// must be used particular device instead of NULL
    162329                int hc = usb_drv_hc_connect(NULL, 0);
    163330                if (hc < 0) {
     
    174341                /*
    175342                 * 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,
    179345                                change_bitmap, byte_length, &actual_size,
    180346                                &handle);
    181347
    182348                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
    183425
    184426                /*
  • uspace/lib/usb/include/usb/classes/hub.h

    r45e9cc6 rb5ec347  
    213213usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
    214214
    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);
    222215
    223216
  • uspace/lib/usb/include/usb/hcdhubd.h

    r45e9cc6 rb5ec347  
    6565} usb_hcd_attached_device_info_t;
    6666
    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;
    7667
    7768/** Host controller device. */
Note: See TracChangeset for help on using the changeset viewer.