Ignore:
Timestamp:
2010-10-10T11:53:05Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b8100da
Parents:
bc9a629
Message:

Virtual HCD refactoring

Splitted into more files, added more comments.

File:
1 edited

Legend:

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

    rbc9a629 rb371844  
    6868static link_t transaction_from_device_list;
    6969
    70 
     70/** Pending transaction details. */
    7171typedef struct {
     72        /** Linked-list link. */
    7273        link_t link;
     74        /** Device address. */
    7375        usb_target_t target;
     76        /** Direction of the transaction. */
    7477        usb_direction_t direction;
     78        /** Transfer type. */
    7579        usb_transfer_type_t type;
     80        /** Transaction data buffer. */
    7681        void * buffer;
     82        /** Transaction data length. */
    7783        size_t len;
     84        /** Callback after transaction is done. */
    7885        hc_transaction_done_callback_t callback;
     86        /** Argument to the callback. */
    7987        void * callback_arg;
    8088} transaction_t;
     
    96104}
    97105
     106/** Call transaction callback.
     107 * Calling this callback informs the backend that transaction was processed.
     108 */
    98109static void process_transaction_with_outcome(transaction_t * transaction,
    99110    usb_transaction_outcome_t outcome)
     
    103114            usb_str_transaction_outcome(outcome));
    104115       
    105         dprintf("  callback %p (%p, %u, %d, %p)", transaction->callback,
    106             transaction->buffer, transaction->len, outcome,
    107             transaction->callback_arg);
    108        
    109116        transaction->callback(transaction->buffer, transaction->len, outcome,
    110117            transaction->callback_arg);
    111         dprintf("callback processed");
    112 }
    113 
    114 #if 0
    115 static void process_transaction(transaction_t * transaction)
    116 {
    117         static unsigned int seed = 4089;
    118        
    119         unsigned int roulette = pseudo_random(&seed);
    120         usb_transaction_outcome_t outcome = USB_OUTCOME_OK;
    121        
    122         PROB_TEST(outcome, USB_OUTCOME_BABBLE, PROB_OUTCOME_BABBLE, roulette);
    123         PROB_TEST(outcome, USB_OUTCOME_CRCERROR, PROB_OUTCOME_CRCERROR, roulette);
    124        
    125         process_transaction_with_outcome(transaction, outcome);
    126 }
    127 #endif
    128 
     118}
     119
     120/** Host controller manager main function.
     121 */
    129122void hc_manager(void)
    130123{
     
    150143                virtdev_connection_t *dev = virtdev_find_by_address(
    151144                    transaction->target.address);
     145                usb_transaction_outcome_t outcome = USB_OUTCOME_OK;
     146               
    152147                if (dev != NULL) {
    153                         dprintf("sending data to device at %d.%d (phone %d)\n",
     148                        dprintf("sending data to device at %d.%d (phone %d)",
    154149                            dev->address, transaction->target.endpoint,
    155150                            dev->phone);
     
    173168                                rc = (int)answer_rc;
    174169                        }
     170                       
     171                        if (rc != EOK) {
     172                                outcome = USB_OUTCOME_BABBLE;
     173                        }
    175174                } else {
    176                         process_transaction_with_outcome(transaction,
    177                             USB_OUTCOME_OK);
     175                        outcome = USB_OUTCOME_CRCERROR;
    178176                }
    179177               
     178                process_transaction_with_outcome(transaction, outcome);
     179               
    180180                free(transaction);
    181181        }
    182182}
    183183
     184/** Create new transaction
     185 */
    184186static transaction_t *transaction_create(usb_transfer_type_t type, usb_target_t target,
    185187    usb_direction_t direction,
     
    201203}
    202204
    203 
     205/** Add transaction directioned towards the device.
     206 */
    204207void hc_add_transaction_to_device(usb_transfer_type_t type, usb_target_t target,
    205208    void * buffer, size_t len,
     
    211214}
    212215
     216/** Add transaction directioned from the device.
     217 */
    213218void hc_add_transaction_from_device(usb_transfer_type_t type, usb_target_t target,
    214219    void * buffer, size_t len,
     
    220225}
    221226
     227/** Fill data to existing transaction from device.
     228 */
    222229int hc_fillin_transaction_from_device(usb_transfer_type_t type, usb_target_t target,
    223230    void * buffer, size_t len)
    224231{
    225232        dprintf("finding transaction to fill data in...");
     233        int rc;
     234       
    226235        /*
    227236         * Find correct transaction envelope in the list.
    228237         */
    229238        if (list_empty(&transaction_from_device_list)) {
    230                 return ENOENT;
     239                rc = ENOENT;
     240                goto leave;
    231241        }
    232242       
     
    243253        }
    244254        if (transaction == NULL) {
    245                 return ENOENT;
     255                rc = ENOENT;
     256                goto leave;
    246257        }
    247258       
     
    253264        if (transaction->len < len) {
    254265                process_transaction_with_outcome(transaction, USB_OUTCOME_BABBLE);
    255                 return ENOMEM;
     266                rc = ENOMEM;
     267                goto leave;
    256268        }
    257269       
     
    264276        process_transaction_with_outcome(transaction, USB_OUTCOME_OK);
    265277       
    266         dprintf(" ...transaction " TRANSACTION_FORMAT " sent back",
     278        dprintf("  ...transaction " TRANSACTION_FORMAT " sent back",
    267279            TRANSACTION_PRINTF(*transaction));
    268280       
    269281       
    270282        free(transaction);
    271        
    272         return EOK;
     283        rc = EOK;
     284       
     285leave:
     286        dprintf("  ...fill-in transaction: %s", str_error(rc));
     287       
     288        return rc;
    273289}
    274290
Note: See TracChangeset for help on using the changeset viewer.