vusbo11.c
8.74 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
/*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:vusbo11.c$
*** $Revision: 1.1 $
*** $Date: 2003/02/17 20:49:01 $
***
*** Description:
*** This file contains the low-level VUSB32 On-The-Go routines.
***
**************************************************************************
*END*********************************************************************/
#ifndef __USB_OS_MQX__
#include "types.h"
#include "hostapi.h"
#include "devapi.h"
#include "otgapi.h"
#include "usb.h"
#include "vusb11.h"
#include "usbprv.h"
#include "usbdprv.h"
#include "usbhprv.h"
#include "usboprv.h"
#else
#include "mqx.h"
#include "bsp.h"
#include "otgapi.h"
#include "vusb11.h"
#include "usbprv.h"
#include "usbdprv.h"
#include "usbhprv.h"
#include "usboprv.h"
#endif
#ifndef __USB_OS_MQX__
USB_OTG_STATE_STRUCT_PTR otg_handle;
extern USB_DEV_STATE_STRUCT_PTR global_usb_device_state_struct_ptr;
#ifndef PERIPHERAL_ONLY
extern USB_HOST_STATE_STRUCT_PTR usb_host_state_struct_ptr;
#endif
#endif
#ifndef __USB_OS_MQX__
extern volatile boolean IN_ISR;
#endif
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_otg_vusb11_init
* Returned Value : USB_OK or error code
* Comments :
* Initialises the OTG Hardware.
*
*END*--------------------------------------------------------------------*/
uint_8 _usb_otg_vusb11_init
(
/* [IN] handle to the usb otg */
_usb_otg_handle handle
)
{ /* Body */
USB_OTG_STATE_STRUCT_PTR usb_otg_ptr;
usb_otg_ptr = (USB_OTG_STATE_STRUCT_PTR)handle;
usb_otg_ptr->USB_REG_PTR = (USB_STRUCT_PTR)
(_bsp_get_usb_base(usb_otg_ptr->DEV_NUM));
usb_otg_ptr->OTG_REG_PTR = (OTG_STRUCT_PTR)((uint_32)usb_otg_ptr->USB_REG_PTR
- BSP_VUSB11_OTG_USB_OFFSET);
/* mask all OTG interupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_ENABLE = 0x0;
/* Clear all OTG interrupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_STAT = 0xFF;
/* Turn off all the signals;
** The following are initial condition for A-device and B-device.
** !drv_vbus; !charg_vbus; !loc_conn; loc_sof
*/
usb_otg_ptr->OTG_REG_PTR->OTG_CTL = OTG_CTL_OTG_ENABLE;
#ifdef __USB_OS_MQX__
if (!(USB_install_isr(_bsp_get_usb_vector(usb_otg_ptr->DEV_NUM),
_usb_otg_vusb11_isr, (pointer)usb_otg_ptr))
{
return USBERR_INSTALL_ISR;
} /* Endbody */
#else
USB_install_isr(_bsp_get_usb_vector(usb_otg_ptr->DEV_NUM),
_usb_otg_vusb11_isr, (pointer)usb_otg_ptr);
#endif
#ifdef PERIPHERAL_ONLY
usb_otg_ptr->STATE_STRUCT.STATE = B_IDLE;
#else
/*
** The identification (id) input is FALSE when a Mini-A plug is inserted
** in the device’s Mini-AB receptacle. Otherwise, this input is TRUE.
*/
if (ID_FALSE(usb_otg_ptr->OTG_REG_PTR)) {
usb_otg_ptr->STATE_STRUCT.STATE = A_IDLE;
} else {
usb_otg_ptr->STATE_STRUCT.STATE = OTG_START;
} /* Endif */
#endif
/* Enable the OTG specific interrupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_ENABLE = OTG_INT_ENABLE_A_VBUS |
OTG_INT_ENABLE_B_SESS|
OTG_CTL_OTG_ENABLE |
OTG_INT_ENABLE_SESS_VLD|
OTG_INT_ENABLE_ID;
#ifndef __USB_OS_MQX__
/* keep a global copy of the handle */
otg_handle = (USB_OTG_STATE_STRUCT_PTR)handle;
#endif
/* start the state machine once to keep going */
_usb_otg_state_machine((pointer)usb_otg_ptr);
return USB_OK;
} /* Endbody */
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_otg_vusb11_shutdown
* Returned Value : None
* Comments :
* Shutdown the otg device.
*
*END*--------------------------------------------------------------------*/
void _usb_otg_vusb11_shutdown
(
/* [IN] Handle to the USB otg */
_usb_otg_handle handle
)
{ /* Body */
USB_OTG_STATE_STRUCT_PTR usb_otg_ptr;
usb_otg_ptr = (USB_OTG_STATE_STRUCT_PTR)handle;
/* mask all OTG interupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_ENABLE = 0x0;
/* Clear all OTG interrupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_STAT = 0xFF;
/* Turn off all the OTG signals */
usb_otg_ptr->OTG_REG_PTR->OTG_CTL = 0x0;
} /* EndBody */
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_otg_vusb11_isr
* Returned Value : None
* Comments :
* Service all OTG and VUSB32 interrupts.
*
*END*--------------------------------------------------------------------*/
#ifndef __USB_OS_MQX__
OTG_INTERRUPT_ROUTINE_KEYWORD void _usb_otg_vusb11_isr
(
void
)
#else
void _usb_otg_vusb11_isr
(
_usb_otg_handle handle
)
#endif
{ /* Body */
USB_OTG_STATE_STRUCT_PTR usb_otg_ptr;
uint_32 otg_status;
OTG_STATE_MACHINE_STRUCT_PTR s_ptr;
#ifndef __USB_OS_MQX__
usb_otg_ptr = (USB_OTG_STATE_STRUCT_PTR)otg_handle;
IN_ISR = TRUE;
#else
usb_otg_ptr = (USB_OTG_STATE_STRUCT_PTR)handle;
#endif
s_ptr = &usb_otg_ptr->STATE_STRUCT;
otg_status = (usb_otg_ptr->OTG_REG_PTR->OTG_INT_STAT &
usb_otg_ptr->OTG_REG_PTR->OTG_INT_ENABLE);
do {
/* Clear all enabled interrupts */
usb_otg_ptr->OTG_REG_PTR->OTG_INT_STAT = otg_status;
/* If we have OTG interrupt call the state machine */
if (otg_status) {
s_ptr->OTG_INT_STATUS = otg_status;
/*
** If any timers expired it will process the event and
** any other signals at that time. We don't need to call
** the state machine if this is the case.
*/
if (!_usb_otg_process_timers((pointer)usb_otg_ptr)) {
/* clear timer interrupt */
otg_status &= ~OTG_INT_ENABLE_1_MSEC ;
if (otg_status) {
_usb_otg_state_machine((pointer)usb_otg_ptr);
} /* Endif */
} /* Endif */
s_ptr->OTG_INT_STATUS = 0;
} /* Endif */
#ifndef PERIPHERAL_ONLY
/* A_DEVICE */
if (s_ptr->HOST_UP) {
/* Check data line pulsing by B device */
if ((s_ptr->STATE == A_IDLE) &&
(!s_ptr->A_BUS_REQ) &&
(usb_otg_ptr->USB_REG_PTR->INTSTATUS & VUSB_INT_STAT_ATTACH) &&
(s_ptr->A_SRP_TMR == -1))
{
s_ptr->A_DATA_PULSE_DET = TRUE;
return ;
} /* Endif */
if (s_ptr->A_SRP_TMR == -1) {
if ((s_ptr->STATE == B_WAIT_ACON) &&
(usb_otg_ptr->USB_REG_PTR->INTSTATUS & VUSB_INT_STAT_ATTACH))
{
s_ptr->JSTATE_COUNT++;
/* Clear the Attach interrupt 10 times and assert JSTATE
** to TRUE on 11th time.
*/
usb_otg_ptr->USB_REG_PTR->INTSTATUS = VUSB_INT_STAT_ATTACH;
if (s_ptr->JSTATE_COUNT == 10) {
s_ptr->JSTATE = TRUE;
s_ptr->JSTATE_COUNT = 0;
} /* Endif */
} /* Endif */
#ifndef __USB_OS_MQX__
_usb_hci_vusb11_isr();
#else
_usb_hci_vusb11_isr((pointer)usb_host_state_struct_ptr);
#endif
} /* Endif */
}/* Endif */
#endif
/* B_DEVICE */
if (s_ptr->DEVICE_UP){
if ((s_ptr->STATE == B_IDLE) &&
(usb_otg_ptr->USB_REG_PTR->INTSTATUS & VUSB_INT_STAT_RESET))
{
return;
} /* Endif */
#ifndef __USB_OS_MQX__
_usb_dci_vusb11_isr();
#else
_usb_dci_vusb11_isr((pointer)global_usb_device_state_struct_ptr);
#endif
}/* Endif */
/* check the interrupt again */
otg_status = (usb_otg_ptr->OTG_REG_PTR->OTG_INT_STAT &
usb_otg_ptr->OTG_REG_PTR->OTG_INT_ENABLE);
} while(otg_status);
#ifndef __USB_OS_MQX__
IN_ISR = FALSE;
#endif
} /* Endbody */
/* EOF */