- some SCSI/UMS fixes
[Rockbox.git] / firmware / usbstack / usb_benchmark.c
blob7cd5a3e987a2b8b96bd3a5f669ed016240c89295
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
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 ****************************************************************************/
19 #include "system.h"
20 #include "usb_core.h"
21 #include "usb_drv.h"
22 //#define LOGF_ENABLE
23 #include "logf.h"
25 #ifdef USB_BENCHMARK
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);
34 static enum {
35 IDLE,
36 SENDING,
37 RECEIVING
38 } state = IDLE;
41 void usb_benchmark_init(void)
43 int i;
44 for (i=0; i<128; i++)
45 input_buffer[i] = i;
48 void usb_benchmark_control_request(struct usb_ctrlrequest* req)
50 int todo;
51 //usb_max_pkt_size = sizeof _input_buffer;
52 usb_max_pkt_size = 64;
54 switch (req->bRequest) {
55 case 1: /* read */
56 ack_control(req);
57 current_length = req->wValue * req->wIndex;
58 logf("bench: read %d", current_length);
59 todo = MIN(usb_max_pkt_size, current_length);
60 state = SENDING;
61 usb_drv_reset_endpoint(EP_BENCHMARK, true);
62 usb_drv_send(EP_BENCHMARK, &input_buffer, todo);
63 current_length -= todo;
64 break;
66 case 2: /* write */
67 ack_control(req);
68 current_length = req->wValue * req->wIndex;
69 logf("bench: write %d", current_length);
70 state = RECEIVING;
71 usb_drv_reset_endpoint(EP_BENCHMARK, false);
72 usb_drv_recv(EP_BENCHMARK, &input_buffer, sizeof _input_buffer);
73 break;
77 void usb_benchmark_transfer_complete(bool in)
79 (void)in;
81 /* see what remains to transfer */
82 if (current_length == 0) {
83 logf("we're done");
84 state = IDLE;
85 return; /* we're done */
88 switch (state)
90 case SENDING: {
91 int todo = MIN(usb_max_pkt_size, current_length);
92 if (in == false) {
93 logf("unexpected ep_rx");
94 break;
97 logf("bench: %d more tx", current_length);
98 usb_drv_send(EP_BENCHMARK, &input_buffer, todo);
99 current_length -= todo;
100 input_buffer[0]++;
101 break;
104 case RECEIVING:
105 if (in == true) {
106 logf("unexpected ep_tx");
107 break;
110 /* re-prime endpoint */
111 usb_drv_recv(EP_BENCHMARK, &input_buffer, sizeof _input_buffer);
112 input_buffer[0]++;
113 break;
115 default:
116 break;
121 static void ack_control(struct usb_ctrlrequest* req)
123 if (req->bRequestType & 0x80)
124 usb_drv_recv(EP_CONTROL, NULL, 0);
125 else
126 usb_drv_send(EP_CONTROL, NULL, 0);
128 #endif /*USB_BENCHMARK*/