diff options
Diffstat (limited to 'firmware/usbstack/usb_benchmark.c')
-rw-r--r-- | firmware/usbstack/usb_benchmark.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/firmware/usbstack/usb_benchmark.c b/firmware/usbstack/usb_benchmark.c deleted file mode 100644 index 7cd5a3e987..0000000000 --- a/firmware/usbstack/usb_benchmark.c +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Björn Stenberg | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "system.h" | ||
20 | #include "usb_core.h" | ||
21 | #include "usb_drv.h" | ||
22 | //#define LOGF_ENABLE | ||
23 | #include "logf.h" | ||
24 | |||
25 | #ifdef USB_BENCHMARK | ||
26 | |||
27 | static int current_length; | ||
28 | |||
29 | static unsigned char _input_buffer[16384]; | ||
30 | static unsigned char* input_buffer = USB_IRAM_ORIGIN + 1024; | ||
31 | |||
32 | static void ack_control(struct usb_ctrlrequest* req); | ||
33 | |||
34 | static enum { | ||
35 | IDLE, | ||
36 | SENDING, | ||
37 | RECEIVING | ||
38 | } state = IDLE; | ||
39 | |||
40 | |||
41 | void usb_benchmark_init(void) | ||
42 | { | ||
43 | int i; | ||
44 | for (i=0; i<128; i++) | ||
45 | input_buffer[i] = i; | ||
46 | } | ||
47 | |||
48 | void usb_benchmark_control_request(struct usb_ctrlrequest* req) | ||
49 | { | ||
50 | int todo; | ||
51 | //usb_max_pkt_size = sizeof _input_buffer; | ||
52 | usb_max_pkt_size = 64; | ||
53 | |||
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; | ||
65 | |||
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; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | void usb_benchmark_transfer_complete(bool in) | ||
78 | { | ||
79 | (void)in; | ||
80 | |||
81 | /* see what remains to transfer */ | ||
82 | if (current_length == 0) { | ||
83 | logf("we're done"); | ||
84 | state = IDLE; | ||
85 | return; /* we're done */ | ||
86 | } | ||
87 | |||
88 | switch (state) | ||
89 | { | ||
90 | case SENDING: { | ||
91 | int todo = MIN(usb_max_pkt_size, current_length); | ||
92 | if (in == false) { | ||
93 | logf("unexpected ep_rx"); | ||
94 | break; | ||
95 | } | ||
96 | |||
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; | ||
102 | } | ||
103 | |||
104 | case RECEIVING: | ||
105 | if (in == true) { | ||
106 | logf("unexpected ep_tx"); | ||
107 | break; | ||
108 | } | ||
109 | |||
110 | /* re-prime endpoint */ | ||
111 | usb_drv_recv(EP_BENCHMARK, &input_buffer, sizeof _input_buffer); | ||
112 | input_buffer[0]++; | ||
113 | break; | ||
114 | |||
115 | default: | ||
116 | break; | ||
117 | |||
118 | } | ||
119 | } | ||
120 | |||
121 | static void ack_control(struct usb_ctrlrequest* req) | ||
122 | { | ||
123 | if (req->bRequestType & 0x80) | ||
124 | usb_drv_recv(EP_CONTROL, NULL, 0); | ||
125 | else | ||
126 | usb_drv_send(EP_CONTROL, NULL, 0); | ||
127 | } | ||
128 | #endif /*USB_BENCHMARK*/ | ||