Changeset b8a3cda in mainline
- Timestamp:
- 2010-10-22T14:57:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a7bfeb3
- Parents:
- 954ea70
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usb/example.c
r954ea70 rb8a3cda 46 46 47 47 #include <usb/hcd.h> 48 #include <usb/devreq.h> 48 49 49 50 #define LOOPS 5 … … 87 88 ipc_answer_0(callid, EOK); 88 89 break; 90 89 91 case IPC_M_USB_HCD_DATA_RECEIVED: 90 92 printf("%s: << Data received over USB (handle %d, outcome %s).\n", … … 95 97 break; 96 98 } 97 rc = async_data_write_accept(&buffer, false, 98 1, MAX_SIZE_RECEIVE, 99 0, &len); 100 if (rc != EOK) { 101 ipc_answer_0(callid, rc); 102 break; 99 len = IPC_GET_ARG3(call); 100 if (len > 0) { 101 rc = async_data_write_accept(&buffer, false, 102 1, MAX_SIZE_RECEIVE, 103 0, &len); 104 if (rc != EOK) { 105 ipc_answer_0(callid, rc); 106 break; 107 } 108 free(buffer); 103 109 } 104 110 printf("%s: << Received %uB long buffer (handle %d).\n", … … 106 112 ipc_answer_0(callid, EOK); 107 113 break; 114 115 case IPC_M_PHONE_HUNGUP: 116 printf("%s: hang-up.\n", NAME); 117 return; 118 108 119 default: 109 ipc_answer_0(callid, EINVAL); 120 printf("%s: method %d called.\n", NAME, IPC_GET_METHOD(call)); 121 ipc_answer_0(callid, EOK); 110 122 break; 111 123 } … … 122 134 } 123 135 124 char data[] = "Hullo, World!"; 125 int data_len = sizeof(data)/sizeof(data[0]); 136 usb_target_t target = {0, 0}; 137 usb_device_request_setup_packet_t setup_packet = { 138 .request_type = 0, 139 .request = USB_DEVREQ_SET_ADDRESS, 140 .index = 0, 141 .length = 0, 142 }; 143 setup_packet.value = 5; 144 int rc; 126 145 127 size_t i; 128 for (i = 0; i < LOOPS; i++) { 129 usb_transaction_handle_t handle; 130 131 usb_target_t target = { i, 0 }; 132 int rc = usb_hcd_send_data_to_function(hcd_phone, 133 target, USB_TRANSFER_ISOCHRONOUS, 134 data, data_len, 135 &handle); 136 if (rc != EOK) { 137 printf("%s: >> Failed to send data to function over HCD (%d: %s).\n", 138 NAME, rc, str_error(rc)); 139 continue; 140 } 141 142 printf("%s: >> Transaction to function dispatched (handle %d).\n", NAME, handle); 143 144 fibril_sleep(1); 145 146 rc = usb_hcd_prepare_data_reception(hcd_phone, 147 target, USB_TRANSFER_INTERRUPT, 148 MAX_SIZE_RECEIVE, 149 &handle); 150 if (rc != EOK) { 151 printf("%s: << Failed to start transaction for data receivement over HCD (%d: %s).\n", 152 NAME, rc, str_error(rc)); 153 continue; 154 } 155 156 printf("%s: << Transaction from function started (handle %d).\n", NAME, handle); 157 158 fibril_sleep(2); 146 printf("%s: usb_hcd_transfer_control_write_setup(...)\n", NAME); 147 rc = usb_hcd_transfer_control_write_setup(hcd_phone, target, 148 &setup_packet, sizeof(setup_packet), NULL); 149 if (rc != EOK) { 150 printf("%s: failed setting address (%d).\n", NAME, rc); 151 return rc; 159 152 } 160 153 161 printf("%s: Waiting for transactions to be finished...\n", NAME); 162 fibril_sleep(10); 154 printf("%s: usb_hcd_transfer_control_write_status(...)\n", NAME); 155 rc = usb_hcd_transfer_control_write_status(hcd_phone, target, NULL); 156 if (rc != EOK) { 157 printf("%s: failed completing control transfer (%d).\n", NAME, rc); 158 return rc; 159 } 160 161 printf("%s: sleeping for a while...\n", NAME); 162 fibril_sleep(5); 163 163 164 164 printf("%s: exiting.\n", NAME); -
uspace/srv/hw/bus/usb/hcd/virtual/conndev.c
r954ea70 rb8a3cda 51 51 .endpoint = IPC_GET_ARG2(icall) 52 52 }; 53 size_t len = IPC_GET_ARG3(icall); 53 54 54 55 if (!hub_can_device_signal(dev)) { … … 60 61 target.address, target.endpoint); 61 62 62 size_t len; 63 void * buffer; 64 int rc = async_data_write_accept(&buffer, false, 65 1, USB_MAX_PAYLOAD_SIZE, 66 0, &len); 63 int rc; 67 64 68 if (rc != EOK) { 69 ipc_answer_0(iid, rc); 70 return; 65 void * buffer = NULL; 66 if (len > 0) { 67 rc = async_data_write_accept(&buffer, false, 68 1, USB_MAX_PAYLOAD_SIZE, 69 0, &len); 70 71 if (rc != EOK) { 72 ipc_answer_0(iid, rc); 73 return; 74 } 71 75 } 72 76 73 rc = hc_fillin_transaction_from_device( USB_TRANSFER_INTERRUPT,target, buffer, len);77 rc = hc_fillin_transaction_from_device(target, buffer, len); 74 78 75 79 ipc_answer_0(iid, rc); -
uspace/srv/hw/bus/usb/hcd/virtual/connhost.c
r954ea70 rb8a3cda 84 84 &answer_data); 85 85 86 rc = async_data_write_start(trans->phone, buffer, len); 87 if (rc != EOK) { 88 async_wait_for(req, NULL); 89 goto leave; 86 if (len > 0) { 87 rc = async_data_write_start(trans->phone, buffer, len); 88 if (rc != EOK) { 89 async_wait_for(req, NULL); 90 goto leave; 91 } 90 92 } 91 93 … … 98 100 leave: 99 101 free(trans); 100 free(buffer); 102 if (buffer != NULL) { 103 free(buffer); 104 } 101 105 } 102 106 103 107 /** Handle data from host to function. 104 108 */ 105 static void handle_data_to_function(ipc_callid_t iid, ipc_call_t icall, int callback_phone) 106 { 107 usb_transfer_type_t transf_type = IPC_GET_ARG3(icall); 109 static void handle_data_to_function(ipc_callid_t iid, ipc_call_t icall, 110 bool setup_transaction, int callback_phone) 111 { 112 size_t expected_len = IPC_GET_ARG3(icall); 108 113 usb_target_t target = { 109 114 .address = IPC_GET_ARG1(icall), … … 111 116 }; 112 117 113 dprintf("pretending transfer to function (dev=%d:%d, type=%s)", 114 target.address, target.endpoint, 115 usb_str_transfer_type(transf_type)); 118 dprintf("pretending transfer to function (dev=%d:%d)", 119 target.address, target.endpoint); 116 120 117 121 if (callback_phone == -1) { … … 123 127 = create_transaction_handle(callback_phone); 124 128 125 size_t len; 126 void * buffer; 127 int rc = async_data_write_accept(&buffer, false, 128 1, USB_MAX_PAYLOAD_SIZE, 129 0, &len); 130 131 if (rc != EOK) { 132 ipc_answer_0(iid, rc); 133 return; 129 size_t len = 0; 130 void * buffer = NULL; 131 if (expected_len > 0) { 132 int rc = async_data_write_accept(&buffer, false, 133 1, USB_MAX_PAYLOAD_SIZE, 134 0, &len); 135 136 if (rc != EOK) { 137 ipc_answer_0(iid, rc); 138 return; 139 } 134 140 } 135 141 … … 139 145 140 146 dprintf("adding transaction to HC", NAME); 141 hc_add_transaction_to_device( transf_type, target,147 hc_add_transaction_to_device(setup_transaction, target, 142 148 buffer, len, 143 149 out_callback, trans); … … 151 157 static void handle_data_from_function(ipc_callid_t iid, ipc_call_t icall, int callback_phone) 152 158 { 153 usb_transfer_type_t transf_type = IPC_GET_ARG3(icall);154 159 usb_target_t target = { 155 160 .address = IPC_GET_ARG1(icall), 156 161 .endpoint = IPC_GET_ARG2(icall) 157 162 }; 158 size_t len = IPC_GET_ARG4(icall); 159 160 dprintf("pretending transfer from function (dev=%d:%d, type=%s)", 161 target.address, target.endpoint, 162 usb_str_transfer_type(transf_type)); 163 size_t len = IPC_GET_ARG3(icall); 164 165 dprintf("pretending transfer from function (dev=%d:%d)", 166 target.address, target.endpoint); 163 167 164 168 if (callback_phone == -1) { … … 170 174 = create_transaction_handle(callback_phone); 171 175 172 void * buffer = malloc(len); 176 void * buffer = NULL; 177 if (len > 0) { 178 buffer = malloc(len); 179 } 173 180 174 181 transaction_details_t * trans = malloc(sizeof(transaction_details_t)); … … 177 184 178 185 dprintf("adding transaction to HC", NAME); 179 hc_add_transaction_from_device(t ransf_type, target,186 hc_add_transaction_from_device(target, 180 187 buffer, len, 181 188 in_callback, trans); … … 219 226 220 227 case IPC_M_USB_HCD_SEND_DATA: 221 handle_data_to_function(callid, call, host_phone); 228 handle_data_to_function(callid, call, 229 false, host_phone); 222 230 break; 223 231 … … 230 238 break; 231 239 240 241 case IPC_M_USB_HCD_INTERRUPT_OUT: 242 handle_data_to_function(callid, call, 243 false, host_phone); 244 break; 245 246 case IPC_M_USB_HCD_INTERRUPT_IN: 247 handle_data_from_function(callid, call, host_phone); 248 break; 249 250 case IPC_M_USB_HCD_CONTROL_WRITE_SETUP: 251 handle_data_to_function(callid, call, 252 true, host_phone); 253 break; 254 255 case IPC_M_USB_HCD_CONTROL_WRITE_DATA: 256 handle_data_to_function(callid, call, 257 false, host_phone); 258 break; 259 260 case IPC_M_USB_HCD_CONTROL_WRITE_STATUS: 261 handle_data_from_function(callid, call, host_phone); 262 break; 263 264 case IPC_M_USB_HCD_CONTROL_READ_SETUP: 265 handle_data_to_function(callid, call, 266 true, host_phone); 267 break; 268 269 case IPC_M_USB_HCD_CONTROL_READ_DATA: 270 case IPC_M_USB_HCD_CONTROL_READ_STATUS: 271 232 272 default: 233 273 ipc_answer_0(callid, EINVAL); -
uspace/srv/hw/bus/usb/hcd/virtual/devices.c
r954ea70 rb8a3cda 48 48 #include "devices.h" 49 49 #include "hub.h" 50 #include "vhcd.h" 50 51 51 52 #define list_foreach(pos, head) \ … … 124 125 ipcarg_t answer_rc; 125 126 aid_t req; 126 int rc ;127 int rc = EOK; 127 128 128 req = async_send_ 3(dev->phone,129 req = async_send_4(dev->phone, 129 130 IPC_M_USBVIRT_DATA_TO_DEVICE, 130 131 transaction->target.address, 131 132 transaction->target.endpoint, 132 133 transaction->type, 134 transaction->len, 133 135 &answer_data); 134 136 135 rc = async_data_write_start(dev->phone, 136 transaction->buffer, transaction->len); 137 if (transaction->len > 0) { 138 rc = async_data_write_start(dev->phone, 139 transaction->buffer, transaction->len); 140 } 137 141 if (rc != EOK) { 138 142 async_wait_for(req, NULL); -
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
r954ea70 rb8a3cda 51 51 #define USLEEP_BASE (500 * 1000) 52 52 53 #define USLEEP_VAR 1000053 #define USLEEP_VAR 5000 54 54 55 55 #define SHORTENING_VAR 15 … … 68 68 static link_t transaction_from_device_list; 69 69 70 #define TRANSACTION_FORMAT "T[%d:%d %s %s(%d)]"70 #define TRANSACTION_FORMAT "T[%d:%d (%d)]" 71 71 #define TRANSACTION_PRINTF(t) \ 72 72 (t).target.address, (t).target.endpoint, \ 73 usb_str_transfer_type((t).type), \74 ((t).direction == USB_DIRECTION_IN ? "in" : "out"), \75 73 (int)(t).len 76 74 … … 132 130 /** Create new transaction 133 131 */ 134 static transaction_t *transaction_create(usb _transfer_type_t type, usb_target_t target,135 usb_ direction_t direction,132 static transaction_t *transaction_create(usbvirt_transaction_type_t type, 133 usb_target_t target, 136 134 void * buffer, size_t len, 137 135 hc_transaction_done_callback_t callback, void * arg) … … 142 140 transaction->type = type; 143 141 transaction->target = target; 144 transaction->direction = direction;145 142 transaction->buffer = buffer; 146 143 transaction->len = len; … … 153 150 /** Add transaction directioned towards the device. 154 151 */ 155 void hc_add_transaction_to_device( usb_transfer_type_t type, usb_target_t target,152 void hc_add_transaction_to_device(bool setup, usb_target_t target, 156 153 void * buffer, size_t len, 157 154 hc_transaction_done_callback_t callback, void * arg) 158 155 { 159 transaction_t *transaction = transaction_create(type, target, 160 USB_DIRECTION_OUT, buffer, len, callback, arg); 156 transaction_t *transaction = transaction_create( 157 setup ? USBVIRT_TRANSACTION_SETUP : USBVIRT_TRANSACTION_OUT, target, 158 buffer, len, callback, arg); 161 159 list_append(&transaction->link, &transaction_to_device_list); 162 160 } … … 164 162 /** Add transaction directioned from the device. 165 163 */ 166 void hc_add_transaction_from_device(usb_t ransfer_type_t type, usb_target_t target,164 void hc_add_transaction_from_device(usb_target_t target, 167 165 void * buffer, size_t len, 168 166 hc_transaction_done_callback_t callback, void * arg) 169 167 { 170 transaction_t *transaction = transaction_create( type, target,171 USB_DIRECTION_IN, buffer, len, callback, arg);168 transaction_t *transaction = transaction_create(USBVIRT_TRANSACTION_IN, 169 target, buffer, len, callback, arg); 172 170 list_append(&transaction->link, &transaction_from_device_list); 173 171 } … … 175 173 /** Fill data to existing transaction from device. 176 174 */ 177 int hc_fillin_transaction_from_device(usb_t ransfer_type_t type, usb_target_t target,175 int hc_fillin_transaction_from_device(usb_target_t target, 178 176 void * buffer, size_t len) 179 177 { 180 dprintf("finding transaction to fill data in..."); 178 dprintf("finding transaction to fill data in (%d:%d)...", 179 target.address, target.endpoint); 181 180 int rc; 182 181 -
uspace/srv/hw/bus/usb/hcd/virtual/hc.h
r954ea70 rb8a3cda 37 37 38 38 #include <usb/hcd.h> 39 #include <usbvirt/ids.h> 39 40 40 41 /** Callback after transaction is sent to USB. … … 52 53 /** Linked-list link. */ 53 54 link_t link; 55 /** Transaction type. */ 56 usbvirt_transaction_type_t type; 54 57 /** Device address. */ 55 58 usb_target_t target; 56 59 /** Direction of the transaction. */ 57 60 usb_direction_t direction; 58 /** Transfer type. */59 usb_transfer_type_t type;60 61 /** Transaction data buffer. */ 61 62 void * buffer; … … 70 71 void hc_manager(void); 71 72 72 void hc_add_transaction_to_device( usb_transfer_type_t type, usb_target_t target,73 void hc_add_transaction_to_device(bool setup, usb_target_t target, 73 74 void * buffer, size_t len, 74 75 hc_transaction_done_callback_t callback, void * arg); 75 76 76 void hc_add_transaction_from_device(usb_t ransfer_type_t type, usb_target_t target,77 void hc_add_transaction_from_device(usb_target_t target, 77 78 void * buffer, size_t len, 78 79 hc_transaction_done_callback_t callback, void * arg); 79 80 80 int hc_fillin_transaction_from_device(usb_t ransfer_type_t type, usb_target_t target,81 int hc_fillin_transaction_from_device(usb_target_t target, 81 82 void * buffer, size_t len); 82 83 -
uspace/srv/hw/bus/usb/hcd/virtual/hub.c
r954ea70 rb8a3cda 37 37 #include <usbvirt/device.h> 38 38 #include <errno.h> 39 #include <stdlib.h> 39 40 40 41 #include "vhcd.h" … … 143 144 hub_device_t hub_dev; 144 145 146 static int send_data(struct usbvirt_device *dev, 147 usb_endpoint_t endpoint, void *buffer, size_t size) 148 { 149 usb_target_t target = { dev->address, endpoint }; 150 void *my_buffer = NULL; 151 if (size > 0) { 152 my_buffer = malloc(size); 153 memcpy(my_buffer, buffer, size); 154 } 155 hc_fillin_transaction_from_device(target, my_buffer, size); 156 157 return EOK; 158 } 159 145 160 void hub_init(void) 146 161 { … … 155 170 156 171 usbvirt_connect_local(&virthub_dev); 172 virthub_dev.send_data = send_data; 157 173 158 174 printf("%s: virtual hub (%d ports) created.\n", NAME, HUB_PORT_COUNT);
Note:
See TracChangeset
for help on using the changeset viewer.