echo_h.c
7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*HEADER*****************************************************************
**************************************************************************
***
*** Copyright (c) 2001-2002 ARC International.
*** All rights reserved
***
*** This software embodies materials and concepts which are
*** confidential to ARC International and is made
*** available solely pursuant to the terms of a written license
*** agreement with ARC International
***
*** $Workfile:echo.c$
*** $Revision: 1.11 $
*** $Date: 2003/08/04 23:30:12 $
***
*** Description:
*** This file contains the host specific code of the echo example.
***
**************************************************************************
*END*********************************************************************/
#include "osint.h"
#include "host.h"
#include "test_h.h"
volatile ECHO_GLOBAL_STRUCT echo_host_struct;
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : echo_host_detach
* Returned Value :
* Comments :
* Callback function to process the device detach event
*
*END*--------------------------------------------------------------------*/
static void
echo_host_detach
(
_usb_host_handle handle,
uint_32 length
)
{
USB_HOST_STATE_STRUCT_PTR hsp = (USB_HOST_STATE_STRUCT_PTR)handle;
HOST_GLOBAL_STRUCT_PTR hgp;
hgp = &host_global_struct[hsp->CTLR_NUM];
PRINTF("echo_host_detach USB%d\n", hsp->CTLR_NUM);
_usb_host_cancel_transfer(handle, hgp->DEFAULT_PIPE);
_usb_host_cancel_transfer(handle, echo_host_struct.PIPE_INT_IN);
_usb_host_cancel_transfer(handle, echo_host_struct.PIPE_INT_OUT);
_usb_host_cancel_transfer(handle, echo_host_struct.PIPE_BULK_IN);
_usb_host_cancel_transfer(handle, echo_host_struct.PIPE_BULK_OUT);
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : echo_host_send_transaction_done
* Returned Value :
* Comments :
* Callback function to process the transaction done event on an
* output data pipe
*
*END*--------------------------------------------------------------------*/
static void
echo_host_send_transaction_done
(
_usb_host_handle handle,
uint_32 length
)
{
USB_HOST_STATE_STRUCT_PTR hsp = (USB_HOST_STATE_STRUCT_PTR)handle;
HOST_GLOBAL_STRUCT_PTR hgp;
hgp = &host_global_struct[hsp->CTLR_NUM];
printf("<<<<echo_host_send_transaction_done, length %d\n", length); /* XXX */
hgp->TRANSACTION_COMPLETE = TRUE;
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : echo_host_recv_transaction_done
* Returned Value :
* Comments :
* Callback function to process the transaction done event on an
* input data pipe
*
*END*--------------------------------------------------------------------*/
static void
echo_host_recv_transaction_done
(
_usb_host_handle handle,
uint_32 length
)
{
USB_HOST_STATE_STRUCT_PTR hsp = (USB_HOST_STATE_STRUCT_PTR)handle;
HOST_GLOBAL_STRUCT_PTR hgp;
hgp = &host_global_struct[hsp->CTLR_NUM];
printf("<<<<echo_host_recv_transaction_done, length %d\n", length); /* XXX */
hgp->TRANSACTION_COMPLETE = TRUE;
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : echo_host_chap9
* Returned Value :
* Comments :
* Device specific chapter 9 processing
*
*END*--------------------------------------------------------------------*/
static void
echo_host_chapter9(_usb_host_handle handle)
{
}
static void
echo_host_open(_usb_host_handle handle)
{
USB_HOST_STATE_STRUCT_PTR hsp = (USB_HOST_STATE_STRUCT_PTR)handle;
HOST_GLOBAL_STRUCT_PTR hgp;
uint_8 error;
hgp = &host_global_struct[hsp->CTLR_NUM];
echo_host_struct.PIPE_INT_OUT = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 2, USB_SEND, 0x00,
USB_INTERRUPT_PIPE, 64, 0, 1);
echo_host_struct.PIPE_INT_IN = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 2, USB_RECV, 0x00,
USB_INTERRUPT_PIPE, 64, 0, 1);
echo_host_struct.PIPE_BULK_OUT = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 1, USB_SEND, 0x00,
USB_BULK_PIPE, 64, 0, 1);
echo_host_struct.PIPE_BULK_IN = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 1, USB_RECV, 0x00,
USB_BULK_PIPE, 64, 0, 1);
error = _usb_host_register_service(handle, echo_host_struct.PIPE_INT_OUT,
echo_host_send_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
error = _usb_host_register_service(handle, echo_host_struct.PIPE_INT_IN,
echo_host_recv_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
error = _usb_host_register_service(handle, echo_host_struct.PIPE_BULK_OUT,
echo_host_send_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
error = _usb_host_register_service(handle, echo_host_struct.PIPE_BULK_IN,
echo_host_recv_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
return;
}
/*
* Hardwire the device descriptor for the echo device
*/
usb_dev_desc echo_dev_desc = {
18,
1,
#ifdef BIG_ENDIAN
0x0110,
#else
0x1001,
#endif
0x00,
0x00,
0x00,
64,
#ifdef BIG_ENDIAN
0x05a3,
0x0001,
0x0002,
#else
0xa305,
0x0100,
0x0200,
#endif
1,
2,
0,
1
};
/*
* Compare Device Descriptor to see if it is the Echo Device
*/
int
echo_host_match(usb_dev_desc *uddp)
{
//printf("<<<<echo_host_match &echo_dev_desc 0x%x, &IDVENDOR 0x%x\n", &echo_dev_desc, &(echo_dev_desc.IDVENDOR));
if (swab16(uddp->IDVENDOR) != echo_dev_desc.IDVENDOR) {
printf("Vendor id 0x%x not echo 0x%x\n", swab16(uddp->IDVENDOR), echo_dev_desc.IDVENDOR);
return(0);
}
if (swab16(uddp->IDPRODUCT) != echo_dev_desc.IDPRODUCT) {
printf("Prod id 0x%x not echo\n", swab16(uddp->IDPRODUCT));
return(0);
}
if (swab16(uddp->BCDDEVICE) != echo_dev_desc.BCDDEVICE) {
printf("Dev version 0x%x not echo\n", swab16(uddp->BCDDEVICE));
return(0);
}
return(1);
}
static void
echo_host_poll(_usb_host_handle handle)
{
return;
}
static void
echo_host_send(_usb_host_handle handle, u8 *buffer, s32 len, u64 offset)
{
printf("---echo_host_send buf 0x%x, len %d, pipe %d\n", buffer, len, echo_host_struct.PIPE_BULK_OUT);
/*
* For Echo device, there is no position, so offset is ignored
*/
_usb_host_send_data(handle, echo_host_struct.PIPE_BULK_OUT,
(uchar_ptr)buffer, len);
return;
}
static void
echo_host_recv(_usb_host_handle handle, u8 *buffer, s32 len, u64 offset)
{
printf("---echo_host_recv buf 0x%x, len %d, pipe %d\n", buffer, len, echo_host_struct.PIPE_BULK_IN);
_usb_host_recv_data(handle, echo_host_struct.PIPE_BULK_IN,
(uchar_ptr)buffer, len);
return;
}
usb_host_driver_funcs echo_host_funcs = {
echo_host_match,
echo_host_open,
echo_host_poll,
echo_host_send,
echo_host_recv,
echo_host_detach,
echo_host_chapter9,
};
usb_host_driver echo_host_driver = {
&echo_dev_desc,
&echo_host_funcs,
"Echo loopback"
};