Changeset b8a3cda in mainline for uspace/app/usb/example.c
- 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
- File:
-
- 1 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);
Note:
See TracChangeset
for help on using the changeset viewer.