Ignore:
Timestamp:
2010-10-24T16:43:40Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
355f7c2
Parents:
b8a3cda
Message:

Virtual USB overhaul almost complete

The virtual HC, hub and keyboard are rewritten after changes to HCD API.
Comments will be added later.

File:
1 edited

Legend:

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

    rb8a3cda r7a7bfeb3  
    4848#include "hc.h"
    4949#include "devices.h"
     50#include "hub.h"
    5051
    5152#define USLEEP_BASE (500 * 1000)
     
    6566        } while (0)
    6667
    67 static link_t transaction_to_device_list;
    68 static link_t transaction_from_device_list;
     68static link_t transaction_list;
    6969
    70 #define TRANSACTION_FORMAT "T[%d:%d (%d)]"
     70#define TRANSACTION_FORMAT "T[%d:%d (%d) %d]"
    7171#define TRANSACTION_PRINTF(t) \
    7272        (t).target.address, (t).target.endpoint, \
    73         (int)(t).len
     73        (int)(t).len, (int)(t).type
    7474
    7575#define transaction_get_instance(lnk) \
     
    100100void hc_manager(void)
    101101{
    102         list_initialize(&transaction_to_device_list);
    103         list_initialize(&transaction_from_device_list);
     102        list_initialize(&transaction_list);
    104103       
    105104        static unsigned int seed = 4573;
     
    110109                async_usleep(USLEEP_BASE + (pseudo_random(&seed) % USLEEP_VAR));
    111110               
    112                 if (list_empty(&transaction_to_device_list)) {
     111                if (list_empty(&transaction_list)) {
    113112                        continue;
    114113                }
    115114               
    116                 link_t *first_transaction_link = transaction_to_device_list.next;
     115                dprintf("virtual hub has address %d:*.", virthub_dev.address);
     116               
     117                link_t *first_transaction_link = transaction_list.next;
    117118                transaction_t *transaction
    118119                    = transaction_get_instance(first_transaction_link);
    119120                list_remove(first_transaction_link);
     121               
     122                dprintf("processing transaction " TRANSACTION_FORMAT "",
     123                    TRANSACTION_PRINTF(*transaction));
    120124               
    121125                usb_transaction_outcome_t outcome;
     
    157161            setup ? USBVIRT_TRANSACTION_SETUP : USBVIRT_TRANSACTION_OUT, target,
    158162            buffer, len, callback, arg);
    159         list_append(&transaction->link, &transaction_to_device_list);
     163        list_append(&transaction->link, &transaction_list);
    160164}
    161165
     
    168172        transaction_t *transaction = transaction_create(USBVIRT_TRANSACTION_IN,
    169173            target, buffer, len, callback, arg);
    170         list_append(&transaction->link, &transaction_from_device_list);
    171 }
    172 
    173 /** Fill data to existing transaction from device.
    174  */
    175 int hc_fillin_transaction_from_device(usb_target_t target,
    176     void * buffer, size_t len)
    177 {
    178         dprintf("finding transaction to fill data in (%d:%d)...",
    179             target.address, target.endpoint);
    180         int rc;
    181        
    182         /*
    183          * Find correct transaction envelope in the list.
    184          */
    185         if (list_empty(&transaction_from_device_list)) {
    186                 rc = ENOENT;
    187                 goto leave;
    188         }
    189        
    190         transaction_t *transaction = NULL;
    191         link_t *pos = transaction_from_device_list.next;
    192        
    193         while (pos != &transaction_from_device_list) {
    194                 transaction_t *t = transaction_get_instance(pos);
    195                 if (usb_target_same(t->target, target)) {
    196                         transaction = t;
    197                         break;
    198                 }
    199                 pos = pos->next;
    200         }
    201         if (transaction == NULL) {
    202                 rc = ENOENT;
    203                 goto leave;
    204         }
    205        
    206         /*
    207          * Remove the transaction from the list as it will be processed now.
    208          */
    209         list_remove(&transaction->link);
    210        
    211         if (transaction->len < len) {
    212                 process_transaction_with_outcome(transaction, USB_OUTCOME_BABBLE);
    213                 rc = ENOMEM;
    214                 goto leave;
    215         }
    216        
    217         /*
    218          * Copy the data and finish processing the transaction.
    219          */
    220         transaction->len = len;
    221         memcpy(transaction->buffer, buffer, len);
    222        
    223         process_transaction_with_outcome(transaction, USB_OUTCOME_OK);
    224        
    225         dprintf("  ...transaction " TRANSACTION_FORMAT " sent back",
    226             TRANSACTION_PRINTF(*transaction));
    227        
    228        
    229         free(transaction);
    230         rc = EOK;
    231        
    232 leave:
    233         dprintf("  ...fill-in transaction: %s", str_error(rc));
    234        
    235         return rc;
     174        list_append(&transaction->link, &transaction_list);
    236175}
    237176
Note: See TracChangeset for help on using the changeset viewer.