Changeset 7a7bfeb3 in mainline for uspace/srv/hw/bus/usb/hcd/virtual/hc.c
- Timestamp:
- 2010-10-24T16:43:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 355f7c2
- Parents:
- b8a3cda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
rb8a3cda r7a7bfeb3 48 48 #include "hc.h" 49 49 #include "devices.h" 50 #include "hub.h" 50 51 51 52 #define USLEEP_BASE (500 * 1000) … … 65 66 } while (0) 66 67 67 static link_t transaction_to_device_list; 68 static link_t transaction_from_device_list; 68 static link_t transaction_list; 69 69 70 #define TRANSACTION_FORMAT "T[%d:%d (%d) ]"70 #define TRANSACTION_FORMAT "T[%d:%d (%d) %d]" 71 71 #define TRANSACTION_PRINTF(t) \ 72 72 (t).target.address, (t).target.endpoint, \ 73 (int)(t).len 73 (int)(t).len, (int)(t).type 74 74 75 75 #define transaction_get_instance(lnk) \ … … 100 100 void hc_manager(void) 101 101 { 102 list_initialize(&transaction_to_device_list); 103 list_initialize(&transaction_from_device_list); 102 list_initialize(&transaction_list); 104 103 105 104 static unsigned int seed = 4573; … … 110 109 async_usleep(USLEEP_BASE + (pseudo_random(&seed) % USLEEP_VAR)); 111 110 112 if (list_empty(&transaction_ to_device_list)) {111 if (list_empty(&transaction_list)) { 113 112 continue; 114 113 } 115 114 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; 117 118 transaction_t *transaction 118 119 = transaction_get_instance(first_transaction_link); 119 120 list_remove(first_transaction_link); 121 122 dprintf("processing transaction " TRANSACTION_FORMAT "", 123 TRANSACTION_PRINTF(*transaction)); 120 124 121 125 usb_transaction_outcome_t outcome; … … 157 161 setup ? USBVIRT_TRANSACTION_SETUP : USBVIRT_TRANSACTION_OUT, target, 158 162 buffer, len, callback, arg); 159 list_append(&transaction->link, &transaction_ to_device_list);163 list_append(&transaction->link, &transaction_list); 160 164 } 161 165 … … 168 172 transaction_t *transaction = transaction_create(USBVIRT_TRANSACTION_IN, 169 173 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); 236 175 } 237 176
Note:
See TracChangeset
for help on using the changeset viewer.