usbTask.c
3.34 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
#include "os_config.h"
#include "c_def.h"
#include "debug.h"
#include "oem.h"
#include "regmap.h"
#ifdef USB_HOST_ENABLE
#include "mem_reloc.h"
#include "app_timer.h"
#include "tools.h"
#include "IRP.h"
#include "usbd.h"
#include "message.h"
#ifdef USB_DEV_ENABLE
#include "usb.h"
#endif
#include "otg.h"
#include "interrupt.h"
void task_usbotg(void *pvParameters) __INTERNAL_RAM_TEXT;
//extern TX_THREAD thread_usbotg;
extern int dstk_IRPprocess( IRP *irp );
int AOAstack_irpProcess( IRP *irp );
extern int iap2stk_IRPprocess( IRP *irp );
#ifdef SYSTEM_CRASH_CHECK_ENABLE
volatile U8 task_usbotg_check_cnt;
#endif
void task_usbotg(void *pvParameters)
{
UINT ret;
U32 data[WIDTH_OF_USBMSG_QUEUE];
IRP * irp = (IRP *)data;
#ifdef USB_INT_CHANGEs_TO_LEVEL1
SOFT5_INT_ENABLE;
#endif
/*
#ifdef USB_DEV_ENABLE
usbd_init();
hstk_init();
hcd_init();
otg_init();
daudio_init();
denum_init();
dstk_init();
dcd_init();
#else
#if 0
usbd_init();
usbd_open();
hstk_init();
hcd_init();
otg_init();
otg_open();
#endif
#endif
*/
//debug
//hid_test();
while(1)
{
#ifdef SYSTEM_CRASH_CHECK_ENABLE
task_usbotg_check_cnt = 1;
#endif
//ret = tx_queue_receive( &gUsbQueue, (void *)msg, TX_WAIT_FOREVER );
ret = QUEUE_USB_RECEIVE;
DBG_assert( TX_SUCCESS == ret );
switch( irp->target )
{
case enIRP_USB_OPEN:
#if 0
usbd_init();
usbd_open();
hstk_init();
hcd_init();
otg_init();
otg_open();
#endif
#ifndef OTG_FORCE_FULL_SPEED
usb_highspeed_flag = TRUE;
#endif
irp->target = enIRPT_USBD;
irp->type = enIRP_USBHOST_START;
usbd_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
case enIRP_USB_CLOSE:
irp->target = enIRPT_USBD;
irp->type = enIRP_USBHOST_STOP;
usbd_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
#if 0
//usbd_fini();
//usbd_clsoe();
//hstk_fini();
hcd_close();
//otg_fini();
otg_close();
#endif
break;
case enIRPT_USBD:
//DBG_Printf("enIRPT_USBD\n");
#ifndef OTG_FORCE_FULL_SPEED
usb_highspeed_flag = TRUE;
#endif
usbd_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
case enIRPT_MSC_CLASS:
mscClass_IRPprocess( irp );
if( irp->complete != NULL ) {
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
#if 0
case enIRPT_HUB:
hub_IRPprocess( irp );
break;
#endif
#ifdef PTP_MTP_CLASS
case enIRPT_MTP:
mtpClass_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
#endif
#ifdef USB_DEV_ENABLE
case enIRPT_DEV_STACK:
#ifndef OTG_FORCE_FULL_SPEED
usb_highspeed_flag = TRUE;
#endif
dstk_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
#endif
#ifdef APPLE_IAP2_STACK
case enIRPT_IAP2:
iap2stk_IRPprocess( irp );
if( irp->complete != NULL )
{
(*irp->complete) ( irp->result, irp->actualLen );
}
break;
#endif
default:
HALT;
break;
}
//if( irp->complete != NULL )
//{
// (*irp->complete) ( irp->result, irp->actualLen );
//}
#ifdef SYSTEM_CRASH_CHECK_ENABLE
task_usbotg_check_cnt = 2;
#endif
}
}
#endif //USB_HOST_ENABLE