Changeset 56cb9bd in mainline
- Timestamp:
- 2010-10-26T13:49:50Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fa2a361
- Parents:
- 2185776
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usb/example.c
r2185776 r56cb9bd 60 60 (printf("%s: %s" fmt "\n", NAME, _QUOTEME(cmd), __VA_ARGS__), cmd(__VA_ARGS__)) 61 61 62 #define EXEC2(cmd, fmt, ...) \ 63 do { \ 64 printf("%s: " fmt " = ", NAME, __VA_ARGS__); \ 65 fflush(stdout); \ 66 int _rc = cmd; \ 67 if (_rc != EOK) { \ 68 printf("E%d\n", _rc); \ 69 printf("%s: ... aborting.\n", NAME); \ 70 exit(_rc); \ 71 } \ 72 printf("EOK\n"); \ 73 } while (false) 74 #define EXEC(cmd, fmt, ...) \ 75 EXEC2(cmd(__VA_ARGS__), _QUOTEME(cmd) fmt, __VA_ARGS__) 76 62 77 static void fibril_sleep(size_t sec) 63 78 { … … 70 85 { 71 86 ipc_answer_0(iid, EOK); 72 printf("%s: client connection()\n", NAME);87 //printf("%s: client connection()\n", NAME); 73 88 74 89 while (true) { … … 114 129 115 130 case IPC_M_PHONE_HUNGUP: 116 printf("%s: hang-up.\n", NAME);131 //printf("%s: hang-up.\n", NAME); 117 132 return; 118 133 … … 125 140 } 126 141 142 static void data_dump(uint8_t *data, size_t len) 143 { 144 size_t i; 145 for (i = 0; i < len; i++) { 146 printf(" 0x%02X", data[i]); 147 if (((i > 0) && (((i+1) % 10) == 0)) 148 || (i + 1 == len)) { 149 printf("\n"); 150 } 151 } 152 } 153 127 154 int main(int argc, char * argv[]) 128 155 { … … 134 161 } 135 162 163 printf("%s: example communication with HCD\n", NAME); 164 136 165 usb_target_t target = {0, 0}; 166 usb_handle_t handle; 167 168 169 137 170 usb_device_request_setup_packet_t setup_packet = { 138 171 .request_type = 0, … … 142 175 }; 143 176 setup_packet.value = 5; 177 178 printf("\n%s: === setting device address to %d ===\n", NAME, 179 (int)setup_packet.value); 180 EXEC2(usb_hcd_async_transfer_control_write_setup(hcd_phone, target, 181 &setup_packet, sizeof(setup_packet), &handle), 182 "usb_hcd_async_transfer_control_write_setup(%d, {%d:%d}, &data, %u, &h)", 183 hcd_phone, target.address, target.endpoint, sizeof(setup_packet)); 184 185 EXEC(usb_hcd_async_wait_for, "(h=%x)", handle); 186 187 EXEC2(usb_hcd_async_transfer_control_write_status(hcd_phone, target, 188 &handle), 189 "usb_hcd_async_transfer_control_write_status(%d, {%d:%d}, &h)", 190 hcd_phone, target.address, target.endpoint); 191 192 EXEC(usb_hcd_async_wait_for, "(h=%x)", handle); 193 194 target.address = setup_packet.value; 195 196 197 printf("\n%s: === getting standard device descriptor ===\n", NAME); 198 usb_device_request_setup_packet_t get_descriptor = { 199 .request_type = 128, 200 .request = USB_DEVREQ_GET_DESCRIPTOR, 201 .index = 0, 202 .length = MAX_SIZE_RECEIVE, 203 }; 204 get_descriptor.value_low = 0; 205 get_descriptor.value_high = 1; 206 207 uint8_t descriptor[MAX_SIZE_RECEIVE]; 208 size_t descriptor_length; 209 210 EXEC2(usb_hcd_async_transfer_control_read_setup(hcd_phone, target, 211 &get_descriptor, sizeof(get_descriptor), &handle), 212 "usb_hcd_async_transfer_control_read_setup(%d, {%d:%d}, &data, %u, &h)", 213 hcd_phone, target.address, target.endpoint, sizeof(get_descriptor)); 214 215 EXEC(usb_hcd_async_wait_for, "(h=%x)", handle); 216 217 usb_handle_t data_handle; 218 EXEC2(usb_hcd_async_transfer_control_read_data(hcd_phone, target, 219 descriptor, MAX_SIZE_RECEIVE, &descriptor_length, &data_handle), 220 "usb_hcd_async_transfer_control_read_data(%d, {%d:%d}, &data, %u, &len, &h2)", 221 hcd_phone, target.address, target.endpoint, MAX_SIZE_RECEIVE); 222 223 EXEC2(usb_hcd_async_transfer_control_read_status(hcd_phone, target, 224 &handle), 225 "usb_hcd_async_transfer_control_read_status(%d, {%d:%d}, &h)", 226 hcd_phone, target.address, target.endpoint); 227 228 EXEC(usb_hcd_async_wait_for, "(h=%x)", handle); 229 EXEC(usb_hcd_async_wait_for, "(h2=%x)", data_handle); 230 231 printf("%s: standard device descriptor dump (%dB):\n", NAME, descriptor_length); 232 data_dump(descriptor, descriptor_length); 233 234 fibril_sleep(1); 235 236 #if 0 144 237 int rc; 145 238 … … 161 254 printf("%s: sleeping for a while...\n", NAME); 162 255 fibril_sleep(5); 163 256 #endif 257 164 258 printf("%s: exiting.\n", NAME); 165 259
Note:
See TracChangeset
for help on using the changeset viewer.