1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
27 static int current_length
;
29 static unsigned char _input_buffer
[16384];
30 static unsigned char* input_buffer
= USB_IRAM_ORIGIN
+ 1024;
32 static void ack_control(struct usb_ctrlrequest
* req
);
41 void usb_benchmark_init(void)
48 void usb_benchmark_control_request(struct usb_ctrlrequest
* req
)
51 //usb_max_pkt_size = sizeof _input_buffer;
52 usb_max_pkt_size
= 64;
54 switch (req
->bRequest
) {
57 current_length
= req
->wValue
* req
->wIndex
;
58 logf("bench: read %d", current_length
);
59 todo
= MIN(usb_max_pkt_size
, current_length
);
61 usb_drv_reset_endpoint(EP_BENCHMARK
, true);
62 usb_drv_send(EP_BENCHMARK
, &input_buffer
, todo
);
63 current_length
-= todo
;
68 current_length
= req
->wValue
* req
->wIndex
;
69 logf("bench: write %d", current_length
);
71 usb_drv_reset_endpoint(EP_BENCHMARK
, false);
72 usb_drv_recv(EP_BENCHMARK
, &input_buffer
, sizeof _input_buffer
);
77 void usb_benchmark_transfer_complete(bool in
)
81 /* see what remains to transfer */
82 if (current_length
== 0) {
85 return; /* we're done */
91 int todo
= MIN(usb_max_pkt_size
, current_length
);
93 logf("unexpected ep_rx");
97 logf("bench: %d more tx", current_length
);
98 usb_drv_send(EP_BENCHMARK
, &input_buffer
, todo
);
99 current_length
-= todo
;
106 logf("unexpected ep_tx");
110 /* re-prime endpoint */
111 usb_drv_recv(EP_BENCHMARK
, &input_buffer
, sizeof _input_buffer
);
121 static void ack_control(struct usb_ctrlrequest
* req
)
123 if (req
->bRequestType
& 0x80)
124 usb_drv_recv(EP_CONTROL
, NULL
, 0);
126 usb_drv_send(EP_CONTROL
, NULL
, 0);
128 #endif /*USB_BENCHMARK*/