rdb_host.c
6.86 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
* Host driver for the RDB device
*
* Note that this is just for loopback testing. The real host
* for this device will be a PC not a BB.
*/
#include "osint.h"
#include "host.h"
/*
* State structure for the host rdbs driver. Note that it
* is not possible to have two instances of this on the same BB.
*/
struct {
boolean rdbs_enabled;
int_16 bulkpipein;
int_16 bulkpipeout;
} rdbs_host_state;
/*
* Callback function to process the device detach event
*/
static void
rdbs_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];
_usb_host_cancel_transfer(handle, hgp->DEFAULT_PIPE);
if (rdbs_host_state.rdbs_enabled) {
_usb_host_cancel_transfer(handle, rdbs_host_state.bulkpipein);
_usb_host_cancel_transfer(handle, rdbs_host_state.bulkpipeout);
}
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : rdbs_host_send_transaction_done
* Returned Value :
* Comments :
* Callback function to process the transaction done event on an
* output data pipe
*
*END*--------------------------------------------------------------------*/
static void
rdbs_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("<<<<rdbs_host_send_transaction_done\n"); /* XXX */
hgp->TRANSACTION_COMPLETE = TRUE;
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : rdbs_host_recv_transaction_done
* Returned Value :
* Comments :
* Callback function to process the transaction done event on an
* input data pipe
*
*END*--------------------------------------------------------------------*/
static void
rdbs_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("<<<<rdbs_host_recv_transaction_done\n"); /* XXX */
hgp->TRANSACTION_COMPLETE = TRUE;
return;
}
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : rdbs_host_chap9
* Returned Value :
* Comments :
* Device specific chapter 9 processing
*
*END*--------------------------------------------------------------------*/
static void
rdbs_host_chapter9(_usb_host_handle handle)
{
}
static void
rdbs_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];
rdbs_host_state.bulkpipeout = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 2, USB_SEND, 0x00,
USB_BULK_PIPE, 64, 0, 0);
rdbs_host_state.bulkpipein = _usb_host_open_pipe(handle,
hgp->USB_CURRENT_ADDRESS, 2, USB_RECV, 0x00,
USB_BULK_PIPE, 64, 0, 0);
printf("///rdbs_host_open bulkpipein %d, bulkpipeout %d\n",
rdbs_host_state.bulkpipein, rdbs_host_state.bulkpipeout);
error = _usb_host_register_service(handle, rdbs_host_state.bulkpipeout,
rdbs_host_send_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
error = _usb_host_register_service(handle, rdbs_host_state.bulkpipein,
rdbs_host_recv_transaction_done);
if (error != USB_OK) {
printf("\nUSB Service Registration failed. Error: %x", error);
}
return;
}
/*
* Hardwire the device descriptor for the rdbs device
*/
usb_dev_desc rdbs_dev_desc
__attribute__ ((aligned (16)))
= {
18,
1,
#ifdef BIG_ENDIAN
0x0110,
#else
0x1001,
#endif
0x00,
0x00,
0x00,
62,
#ifdef BIG_ENDIAN
0xBB3D,
0xBBDB,
0x0001,
#else
0x3DBB,
0xDBBB,
0x0100,
#endif
1,
2,
0,
1
};
/*
* Compare Device Descriptor to see if it is the RDBS Device
*/
int
rdbs_host_match(usb_dev_desc *uddp)
{
//printf("<<<<rdbs_host_match &rdbs_dev_desc 0x%x, &IDVENDOR 0x%x\n", &rdbs_dev_desc, &(rdbs_dev_desc.IDVENDOR));
if (swab16(uddp->IDVENDOR) != rdbs_dev_desc.IDVENDOR) {
//printf("Vendor id 0x%x not rdbs 0x%x\n", swab16(uddp->IDVENDOR), rdbs_dev_desc.IDVENDOR);
return(0);
}
if (swab16(uddp->IDPRODUCT) != rdbs_dev_desc.IDPRODUCT) {
//printf("Prod id 0x%x not rdbs\n", swab16(uddp->IDPRODUCT));
return(0);
}
if (swab16(uddp->BCDDEVICE) != rdbs_dev_desc.BCDDEVICE) {
//printf("Dev version 0x%x not rdbs\n", swab16(uddp->BCDDEVICE));
return(0);
}
return(1);
}
static void
rdbs_host_poll(_usb_host_handle handle)
{
return;
}
static char rdbs_send_buf[64];
static void
rdbs_host_send(_usb_host_handle handle, u8 *buffer, s32 len, u64 offset)
{
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];
hgp->TRANSACTION_COMPLETE = FALSE;
printf("--rdbs_host_send buf 0x%x, len %d, pipe %d\n", buffer, len, rdbs_host_state.bulkpipeout);
/*
* For RDB device, there is no position, so offset is ignored
*/
if (len > 62) {
printf("---rdbs_host_send bad len %d\n", len);
len = 62;
}
bzero((void *)rdbs_send_buf, sizeof(rdbs_send_buf));
*(uint_16 *)rdbs_send_buf = len;
bcopy((void *)buffer, (void *)&rdbs_send_buf[2], len);
error = _usb_host_send_data(handle, rdbs_host_state.bulkpipeout, (uchar_ptr)rdbs_send_buf, 64);
if (error != USB_STATUS_TRANSFER_QUEUED) {
printf("---rdbs_host_send: host_send_data err %d\n", error);
}
while (hgp->TRANSACTION_COMPLETE == FALSE) {
if (!hgp->DEVICE_ATTACHED)
return;
osYieldThread();
}
return;
}
static char rdbs_recv_buf[64];
static void
rdbs_host_recv(_usb_host_handle handle, u8 *buffer, s32 len, u64 offset)
{
USB_HOST_STATE_STRUCT_PTR hsp = (USB_HOST_STATE_STRUCT_PTR)handle;
HOST_GLOBAL_STRUCT_PTR hgp;
hgp = &host_global_struct[hsp->CTLR_NUM];
hgp->TRANSACTION_COMPLETE = FALSE;
printf("--rdbs_host_recv buf 0x%x, len %d, pipe %d\n", buffer, len, rdbs_host_state.bulkpipein);
_usb_host_recv_data(handle, rdbs_host_state.bulkpipein, (uchar_ptr)rdbs_recv_buf, 64);
while (hgp->TRANSACTION_COMPLETE == FALSE) {
if (!hgp->DEVICE_ATTACHED)
return;
osYieldThread();
}
len = *(uint_16 *)rdbs_recv_buf;
if (len > 62)
len = 62;
bcopy((void *)&rdbs_recv_buf[2], (void *)buffer, len);
return;
}
usb_host_driver_funcs rdbs_host_funcs = {
rdbs_host_match,
rdbs_host_open,
rdbs_host_poll,
rdbs_host_send,
rdbs_host_recv,
rdbs_host_detach,
rdbs_host_chapter9,
};
usb_host_driver rdbs_host_driver = {
&rdbs_dev_desc,
&rdbs_host_funcs,
"BB RDB host driver"
};