Ignore:
Timestamp:
2010-10-20T23:15:48Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
Children:
34586183
Parents:
b8507a1
Message:

Add virtual hub state machine

The virtual hub provided by vhcd now simulates a state machine for
each of its ports. Some of the transitions are not implemented but
basic port handling through port features shall work. Will add
comments later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/bus/usb/hcd/virtual/hub.c

    rb8507a1 r6c741e1d  
    140140        .descriptors = &descriptors,
    141141};
    142 
     142 
    143143hub_device_t hub_dev;
    144144
     
    147147        size_t i;
    148148        for (i = 0; i < HUB_PORT_COUNT; i++) {
    149                 hub_dev.ports[i].device = NULL;
    150                 hub_dev.ports[i].state = HUB_PORT_STATE_NOT_CONFIGURED;
    151         }
    152         hub_dev.status_change_bitmap = 0;
     149                hub_port_t *port = &hub_dev.ports[i];
     150               
     151                port->device = NULL;
     152                port->state = HUB_PORT_STATE_NOT_CONFIGURED;
     153                port->status_change = 0;
     154        }
    153155       
    154156        usbvirt_connect_local(&virthub_dev);
     
    161163        size_t i;
    162164        for (i = 0; i < HUB_PORT_COUNT; i++) {
    163                 if (hub_dev.ports[i].device != NULL) {
     165                hub_port_t *port = &hub_dev.ports[i];
     166               
     167                if (port->device != NULL) {
    164168                        continue;
    165169                }
    166                 hub_dev.ports[i].device = device;
    167                 // TODO - notify the host about change
    168                 // bad, bad but it will work somehow at least
    169                 hub_dev.ports[i].state = HUB_PORT_STATE_ENABLED;
    170                 hub_dev.status_change_bitmap |= (1 << (i+1));
     170               
     171                port->device = device;
     172               
     173                /*
     174                 * TODO:
     175                 * If the hub was configured, we can normally
     176                 * announce the plug-in.
     177                 * Otherwise, we will wait until hub is configured
     178                 * and announce changes in single burst.
     179                 */
     180                //if (port->state == HUB_PORT_STATE_DISCONNECTED) {
     181                        port->state = HUB_PORT_STATE_DISABLED;
     182                        set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     183                //}
     184               
    171185                return i;
    172186        }
     
    180194        size_t i;
    181195        for (i = 0; i < HUB_PORT_COUNT; i++) {
    182                 if (hub_dev.ports[i].device != device) {
     196                hub_port_t *port = &hub_dev.ports[i];
     197               
     198                if (port->device != device) {
    183199                        continue;
    184200                }
    185                 hub_dev.ports[i].device = NULL;
    186                 hub_dev.ports[i].state = HUB_PORT_STATE_DISCONNECTED;
    187                 hub_dev.status_change_bitmap |= (1 << (i+1));
    188                 // TODO - notify the host of the removal
     201               
     202                port->device = NULL;
     203                port->state = HUB_PORT_STATE_DISCONNECTED;
     204               
     205                set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    189206        }
    190207}
     
    202219}
    203220
     221void hub_check_port_changes(void)
     222{
     223        /* FIXME - what if HUB_PORT_COUNT is greater than 8. */
     224        uint8_t change_map = 0;
     225       
     226        size_t i;
     227        for (i = 0; i < HUB_PORT_COUNT; i++) {
     228                hub_port_t *port = &hub_dev.ports[i];
     229               
     230                if (port->status_change != 0) {
     231                        change_map |= (1 << (i + 1));
     232                }
     233        }
     234       
     235        /* FIXME - do not send when it has not changed since previous run. */
     236        if (change_map != 0) {
     237                virthub_dev.send_data(&virthub_dev, HUB_STATUS_CHANGE_PIPE,
     238                    &change_map, 1);
     239        }
     240}
    204241
    205242/**
Note: See TracChangeset for help on using the changeset viewer.