Ignore:
Timestamp:
2010-10-15T16:32:57Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
186d630
Parents:
73301a0
Message:

Virtual USB device tracks its address

Now, each virtual device tracks its address and its state.

The virtual HC dispatches all transactions to all devices, thus
more precisely simulating situation on USB. The usbvirt framework
then decides whether it can accept the data or not, based on
their destination address.

File:
1 edited

Legend:

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

    r73301a0 r47e3a8e  
    4444
    4545#include <usbvirt/ids.h>
     46#include <usbvirt/hub.h>
    4647
    4748#include "devices.h"
     
    6364        switch (id) {
    6465                case USBVIRT_DEV_KEYBOARD_ID:
    65                         dev = virtdev_add_device(
    66                             USBVIRT_DEV_KEYBOARD_ADDRESS, phone);
     66                        dev = virtdev_add_device(phone);
    6767                        break;
    6868                default:
     
    8484}
    8585
    86 /** Find virtual device by its USB address.
    87  *
    88  * @retval NULL No virtual device at given address.
    89  */
    90 virtdev_connection_t *virtdev_find_by_address(usb_address_t address)
    91 {
    92         link_t *pos;
    93         list_foreach(pos, &devices) {
    94                 virtdev_connection_t *dev
    95                     = list_get_instance(pos, virtdev_connection_t, link);
    96                 if (dev->address == address) {
    97                         return dev;
    98                 }
    99         }
    100        
    101         return NULL;
    102 }
    103 
    10486/** Create virtual device.
    10587 *
     
    10991 * @retval NULL Out of memory or address already occupied.
    11092 */
    111 virtdev_connection_t *virtdev_add_device(usb_address_t address, int phone)
     93virtdev_connection_t *virtdev_add_device(int phone)
    11294{
    113         link_t *pos;
    114         list_foreach(pos, &devices) {
    115                 virtdev_connection_t *dev
    116                     = list_get_instance(pos, virtdev_connection_t, link);
    117                 if (dev->address == address) {
    118                         return NULL;
    119                 }
    120         }
    121        
    12295        virtdev_connection_t *dev = (virtdev_connection_t *)
    12396            malloc(sizeof(virtdev_connection_t));
    12497        dev->phone = phone;
    125         dev->address = address;
    12698        list_append(&dev->link, &devices);
    12799       
     
    137109}
    138110
     111/** Send data to all connected devices.
     112 *
     113 * @param transaction Transaction to be sent over the bus.
     114 */
     115usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction)
     116{
     117        link_t *pos;
     118        list_foreach(pos, &devices) {
     119                virtdev_connection_t *dev
     120                    = list_get_instance(pos, virtdev_connection_t, link);
     121               
     122                ipc_call_t answer_data;
     123                ipcarg_t answer_rc;
     124                aid_t req;
     125                int rc;
     126               
     127                req = async_send_3(dev->phone,
     128                    IPC_M_USBVIRT_DATA_TO_DEVICE,
     129                    transaction->target.address,
     130                    transaction->target.endpoint,
     131                    transaction->type,
     132                    &answer_data);
     133               
     134                rc = async_data_write_start(dev->phone,
     135                    transaction->buffer, transaction->len);
     136                if (rc != EOK) {
     137                        async_wait_for(req, NULL);
     138                } else {
     139                        async_wait_for(req, &answer_rc);
     140                        rc = (int)answer_rc;
     141                }
     142        }
     143       
     144        /*
     145         * TODO: maybe screw some transactions to get more
     146         * real-life image.
     147         */
     148        return USB_OUTCOME_OK;
     149}
     150
    139151/**
    140152 * @}
Note: See TracChangeset for help on using the changeset viewer.