Changeset b371844 in mainline for uspace/srv/hw/bus/usb/hcd/virtual/hc.c
- Timestamp:
- 2010-10-10T11:53:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b8100da
- Parents:
- bc9a629
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
rbc9a629 rb371844 68 68 static link_t transaction_from_device_list; 69 69 70 70 /** Pending transaction details. */ 71 71 typedef struct { 72 /** Linked-list link. */ 72 73 link_t link; 74 /** Device address. */ 73 75 usb_target_t target; 76 /** Direction of the transaction. */ 74 77 usb_direction_t direction; 78 /** Transfer type. */ 75 79 usb_transfer_type_t type; 80 /** Transaction data buffer. */ 76 81 void * buffer; 82 /** Transaction data length. */ 77 83 size_t len; 84 /** Callback after transaction is done. */ 78 85 hc_transaction_done_callback_t callback; 86 /** Argument to the callback. */ 79 87 void * callback_arg; 80 88 } transaction_t; … … 96 104 } 97 105 106 /** Call transaction callback. 107 * Calling this callback informs the backend that transaction was processed. 108 */ 98 109 static void process_transaction_with_outcome(transaction_t * transaction, 99 110 usb_transaction_outcome_t outcome) … … 103 114 usb_str_transaction_outcome(outcome)); 104 115 105 dprintf(" callback %p (%p, %u, %d, %p)", transaction->callback,106 transaction->buffer, transaction->len, outcome,107 transaction->callback_arg);108 109 116 transaction->callback(transaction->buffer, transaction->len, outcome, 110 117 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 */ 129 122 void hc_manager(void) 130 123 { … … 150 143 virtdev_connection_t *dev = virtdev_find_by_address( 151 144 transaction->target.address); 145 usb_transaction_outcome_t outcome = USB_OUTCOME_OK; 146 152 147 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)", 154 149 dev->address, transaction->target.endpoint, 155 150 dev->phone); … … 173 168 rc = (int)answer_rc; 174 169 } 170 171 if (rc != EOK) { 172 outcome = USB_OUTCOME_BABBLE; 173 } 175 174 } else { 176 process_transaction_with_outcome(transaction, 177 USB_OUTCOME_OK); 175 outcome = USB_OUTCOME_CRCERROR; 178 176 } 179 177 178 process_transaction_with_outcome(transaction, outcome); 179 180 180 free(transaction); 181 181 } 182 182 } 183 183 184 /** Create new transaction 185 */ 184 186 static transaction_t *transaction_create(usb_transfer_type_t type, usb_target_t target, 185 187 usb_direction_t direction, … … 201 203 } 202 204 203 205 /** Add transaction directioned towards the device. 206 */ 204 207 void hc_add_transaction_to_device(usb_transfer_type_t type, usb_target_t target, 205 208 void * buffer, size_t len, … … 211 214 } 212 215 216 /** Add transaction directioned from the device. 217 */ 213 218 void hc_add_transaction_from_device(usb_transfer_type_t type, usb_target_t target, 214 219 void * buffer, size_t len, … … 220 225 } 221 226 227 /** Fill data to existing transaction from device. 228 */ 222 229 int hc_fillin_transaction_from_device(usb_transfer_type_t type, usb_target_t target, 223 230 void * buffer, size_t len) 224 231 { 225 232 dprintf("finding transaction to fill data in..."); 233 int rc; 234 226 235 /* 227 236 * Find correct transaction envelope in the list. 228 237 */ 229 238 if (list_empty(&transaction_from_device_list)) { 230 return ENOENT; 239 rc = ENOENT; 240 goto leave; 231 241 } 232 242 … … 243 253 } 244 254 if (transaction == NULL) { 245 return ENOENT; 255 rc = ENOENT; 256 goto leave; 246 257 } 247 258 … … 253 264 if (transaction->len < len) { 254 265 process_transaction_with_outcome(transaction, USB_OUTCOME_BABBLE); 255 return ENOMEM; 266 rc = ENOMEM; 267 goto leave; 256 268 } 257 269 … … 264 276 process_transaction_with_outcome(transaction, USB_OUTCOME_OK); 265 277 266 dprintf(" ...transaction " TRANSACTION_FORMAT " sent back",278 dprintf(" ...transaction " TRANSACTION_FORMAT " sent back", 267 279 TRANSACTION_PRINTF(*transaction)); 268 280 269 281 270 282 free(transaction); 271 272 return EOK; 283 rc = EOK; 284 285 leave: 286 dprintf(" ...fill-in transaction: %s", str_error(rc)); 287 288 return rc; 273 289 } 274 290
Note:
See TracChangeset
for help on using the changeset viewer.