Changeset 47e3a8e in mainline
- Timestamp:
- 2010-10-15T16:32:57Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 186d630
- Parents:
- 73301a0
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/device.h
r73301a0 r47e3a8e 106 106 } usbvirt_descriptors_t; 107 107 108 /** Possible states of virtual USB device. 109 * Notice that these are not 1:1 mappings to those in USB specification. 110 */ 111 typedef enum { 112 USBVIRT_STATE_DEFAULT, 113 USBVIRT_STATE_ADDRESS, 114 USBVIRT_STATE_CONFIGURED 115 } usbvirt_device_state_t; 108 116 117 /** Virtual USB device. */ 109 118 typedef struct usbvirt_device { 110 119 /** Callback device operations. */ … … 126 135 usbvirt_descriptors_t *descriptors; 127 136 137 /** Current device state. */ 138 usbvirt_device_state_t state; 139 /** Device address. */ 140 usb_address_t address; 128 141 129 142 /* Private attributes. */ -
uspace/lib/usbvirt/main.c
r73301a0 r47e3a8e 50 50 static void handle_data_to_device(ipc_callid_t iid, ipc_call_t icall) 51 51 { 52 usb_endpoint_t endpoint = IPC_GET_ARG1(icall); 52 usb_address_t address = IPC_GET_ARG1(icall); 53 usb_endpoint_t endpoint = IPC_GET_ARG2(icall); 54 55 if (address != device->address) { 56 ipc_answer_0(iid, EADDRNOTAVAIL); 57 return; 58 } 53 59 54 60 size_t len; … … 95 101 } 96 102 103 static void device_init(usbvirt_device_t *dev) 104 { 105 dev->send_data = usbvirt_data_to_host; 106 dev->state = USBVIRT_STATE_DEFAULT; 107 dev->address = 0; 108 } 109 97 110 int usbvirt_data_to_host(struct usbvirt_device *dev, 98 111 usb_endpoint_t endpoint, void *buffer, size_t size) … … 112 125 int rc; 113 126 114 req = async_send_ 1(phone,127 req = async_send_2(phone, 115 128 IPC_M_USBVIRT_DATA_FROM_DEVICE, 129 dev->address, 116 130 endpoint, 117 131 &answer_data); … … 174 188 175 189 dev->vhcd_phone_ = hcd_phone; 176 dev ->send_data = usbvirt_data_to_host;190 device_init(dev); 177 191 178 192 device = dev; -
uspace/lib/usbvirt/stdreq.c
r73301a0 r47e3a8e 118 118 119 119 /* 120 * TODO: inform the HC that device has new address assigned. 120 * TODO: handle when this request is invalid (e.g. 121 * setting address when in configured state). 121 122 */ 123 if (new_address == 0) { 124 device->state = USBVIRT_STATE_DEFAULT; 125 } else { 126 device->state = USBVIRT_STATE_ADDRESS; 127 } 128 129 device->address = new_address; 130 122 131 return EOK; 123 132 } -
uspace/srv/hw/bus/usb/hcd/virtual/conndev.c
r73301a0 r47e3a8e 46 46 virtdev_connection_t *dev) 47 47 { 48 usb_endpoint_t endpoint = IPC_GET_ARG1(icall);49 48 usb_target_t target = { 50 .address = dev->address,51 .endpoint = endpoint49 .address = IPC_GET_ARG1(icall), 50 .endpoint = IPC_GET_ARG2(icall) 52 51 }; 53 52 … … 80 79 assert(dev != NULL); 81 80 82 dprintf("phone%#x: virtual device %d connected [%d]",83 phone_hash, dev->id , dev->address);81 dprintf("phone%#x: virtual device %d connected", 82 phone_hash, dev->id); 84 83 85 84 while (true) { … … 93 92 ipc_hangup(dev->phone); 94 93 ipc_answer_0(callid, EOK); 95 dprintf("phone%#x: device %d [%d]hang-up",96 phone_hash, dev->id , dev->address);94 dprintf("phone%#x: device %d hang-up", 95 phone_hash, dev->id); 97 96 return; 98 97 -
uspace/srv/hw/bus/usb/hcd/virtual/devices.c
r73301a0 r47e3a8e 44 44 45 45 #include <usbvirt/ids.h> 46 #include <usbvirt/hub.h> 46 47 47 48 #include "devices.h" … … 63 64 switch (id) { 64 65 case USBVIRT_DEV_KEYBOARD_ID: 65 dev = virtdev_add_device( 66 USBVIRT_DEV_KEYBOARD_ADDRESS, phone); 66 dev = virtdev_add_device(phone); 67 67 break; 68 68 default: … … 84 84 } 85 85 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 *dev95 = list_get_instance(pos, virtdev_connection_t, link);96 if (dev->address == address) {97 return dev;98 }99 }100 101 return NULL;102 }103 104 86 /** Create virtual device. 105 87 * … … 109 91 * @retval NULL Out of memory or address already occupied. 110 92 */ 111 virtdev_connection_t *virtdev_add_device( usb_address_t address,int phone)93 virtdev_connection_t *virtdev_add_device(int phone) 112 94 { 113 link_t *pos;114 list_foreach(pos, &devices) {115 virtdev_connection_t *dev116 = list_get_instance(pos, virtdev_connection_t, link);117 if (dev->address == address) {118 return NULL;119 }120 }121 122 95 virtdev_connection_t *dev = (virtdev_connection_t *) 123 96 malloc(sizeof(virtdev_connection_t)); 124 97 dev->phone = phone; 125 dev->address = address;126 98 list_append(&dev->link, &devices); 127 99 … … 137 109 } 138 110 111 /** Send data to all connected devices. 112 * 113 * @param transaction Transaction to be sent over the bus. 114 */ 115 usb_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 139 151 /** 140 152 * @} -
uspace/srv/hw/bus/usb/hcd/virtual/devices.h
r73301a0 r47e3a8e 39 39 #include <usb/hcd.h> 40 40 41 #include "hc.h" 42 41 43 /** Connected virtual device. */ 42 44 typedef struct { 43 /** Assigned USB address. */44 usb_address_t address;45 45 /** Phone used when sending data to device. */ 46 46 int phone; … … 52 52 53 53 virtdev_connection_t *virtdev_recognise(int, int); 54 virtdev_connection_t *virtdev_find_by_address(usb_address_t); 55 virtdev_connection_t *virtdev_add_device(usb_address_t, int); 54 virtdev_connection_t *virtdev_add_device(int); 56 55 void virtdev_destroy_device(virtdev_connection_t *); 56 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *); 57 57 58 58 #endif -
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
r73301a0 r47e3a8e 68 68 static link_t transaction_from_device_list; 69 69 70 /** Pending transaction details. */71 typedef struct {72 /** Linked-list link. */73 link_t link;74 /** Device address. */75 usb_target_t target;76 /** Direction of the transaction. */77 usb_direction_t direction;78 /** Transfer type. */79 usb_transfer_type_t type;80 /** Transaction data buffer. */81 void * buffer;82 /** Transaction data length. */83 size_t len;84 /** Callback after transaction is done. */85 hc_transaction_done_callback_t callback;86 /** Argument to the callback. */87 void * callback_arg;88 } transaction_t;89 90 70 #define TRANSACTION_FORMAT "T[%d:%d %s %s (%d)]" 91 71 #define TRANSACTION_PRINTF(t) \ … … 136 116 } 137 117 138 link_t * 139 transaction_t * 118 link_t *first_transaction_link = transaction_to_device_list.next; 119 transaction_t *transaction 140 120 = transaction_get_instance(first_transaction_link); 141 121 list_remove(first_transaction_link); 142 122 143 virtdev_connection_t *dev = virtdev_find_by_address( 144 transaction->target.address); 145 usb_transaction_outcome_t outcome = USB_OUTCOME_OK; 146 147 if (dev != NULL) { 148 dprintf("sending data to device at %d.%d (phone %d)", 149 dev->address, transaction->target.endpoint, 150 dev->phone); 151 ipc_call_t answer_data; 152 ipcarg_t answer_rc; 153 aid_t req; 154 int rc; 155 156 req = async_send_2(dev->phone, 157 IPC_M_USBVIRT_DATA_TO_DEVICE, 158 transaction->target.endpoint, 159 transaction->type, 160 &answer_data); 161 162 rc = async_data_write_start(dev->phone, 163 transaction->buffer, transaction->len); 164 if (rc != EOK) { 165 async_wait_for(req, NULL); 166 } else { 167 async_wait_for(req, &answer_rc); 168 rc = (int)answer_rc; 169 } 170 171 if (rc != EOK) { 172 outcome = USB_OUTCOME_BABBLE; 173 } 174 } else { 175 outcome = USB_OUTCOME_CRCERROR; 176 } 123 usb_transaction_outcome_t outcome; 124 outcome = virtdev_send_to_all(transaction); 177 125 178 126 process_transaction_with_outcome(transaction, outcome); -
uspace/srv/hw/bus/usb/hcd/virtual/hc.h
r73301a0 r47e3a8e 48 48 usb_transaction_outcome_t outcome, void *arg); 49 49 50 /** Pending transaction details. */ 51 typedef struct { 52 /** Linked-list link. */ 53 link_t link; 54 /** Device address. */ 55 usb_target_t target; 56 /** Direction of the transaction. */ 57 usb_direction_t direction; 58 /** Transfer type. */ 59 usb_transfer_type_t type; 60 /** Transaction data buffer. */ 61 void * buffer; 62 /** Transaction data length. */ 63 size_t len; 64 /** Callback after transaction is done. */ 65 hc_transaction_done_callback_t callback; 66 /** Argument to the callback. */ 67 void * callback_arg; 68 } transaction_t; 69 50 70 void hc_manager(void); 51 71
Note:
See TracChangeset
for help on using the changeset viewer.