| M480 BSP V3.05.001 The Board Support Package for M480 Series

ehci.h
Go to the documentation of this file.
1 /**************************************************************************/
10 #ifndef _USBH_EHCI_H_
11 #define _USBH_EHCI_H_
12
14
15 struct utr_t;
16 struct udev_t;
17 struct qh_t;
18 struct iso_ep_t;
19 struct ep_info_t;
20
21 /*----------------------------------------------------------------------------------------*/
22 /* Periodic Frame List Size (256, 512, or 1024) */
23 /*----------------------------------------------------------------------------------------*/
24 #define FL_SIZE 1024 /* frame list size can be 256, 512, or 1024 */
25 #define NUM_IQH 11 /* depends on FL_SIZE, 256:9, 512:10, 1024:11 */
26
27
28 /*----------------------------------------------------------------------------------------*/
29 /* Interrupt Threshold Control (1, 2, 4, 6, .. 64) */
30 /*----------------------------------------------------------------------------------------*/
31 #define UCMDR_INT_THR_CTRL (0x1<<HSUSBH_UCMDR_ITC_Pos) /* 1 micro-frames */
32
33
34 /*----------------------------------------------------------------------------------------*/
35 /* Queue Element Transfer Descriptor (qTD) */
36 /*----------------------------------------------------------------------------------------*/
37 typedef struct qTD_t
38 {
39 uint32_t Next_qTD; /* Next qTD Pointer */
40 uint32_t Alt_Next_qTD; /* Alternate Next qTD Pointer */
41 uint32_t Token; /* qTD Token */
42 uint32_t Bptr[5]; /* qTD Buffer Page Pointer List */
43 /*
44 * The following members are used by USB Host libary.
45 */
46 struct utr_t *utr; /* associated UTR */
47 uint32_t xfer_len; /* assigned transfer transfer length */
48 struct qh_t *qh; /* The QH that this qTD belong to. */
49 struct qTD_t *next; /* link for <qtd_list> of QH */
50 } qTD_T;
51
52
53 #define QTD_LIST_END 0x1 /* Indicate the terminate of qTD list. */
54 #define QTD_PTR(x) ((qTD_T *)((uint32_t)(x) & ~0x1F))
55
56 /*
57 * Status: qTD Token[7:0]
58 */
59 #define QTD_STS_PS_OUT (0<<0) /* directs the HC to issue an OUT PID */
60 #define QTD_STS_PS_PING (1<<0) /* directs the HC to issue an PING PID */
61 #define QTD_STS_SPLIT_STRAT (0<<1) /* directs the HC to issue an Start split */
62 #define QTD_STS_SPLIT_COMPLETE (1<<1) /* directs the HC to issue an Complete split */
63 #define QTD_STS_MISS_MF (1<<2) /* miss a required complete-split transaction */
64 #define QTD_STS_XactErr (1<<3) /* Transaction Error occurred */
65 #define QTD_STS_BABBLE (1<<4) /* Babble Detected */
66 #define QTD_STS_DATA_BUFF_ERR (1<<5) /* Data Buffer Error */
67 #define QTD_STS_HALT (1<<6) /* Halted */
68 #define QTD_STS_ACTIVE (1<<7) /* Active */
69
70 /*
71 * PID: qTD Token[9:8]
72 */
73 #define QTD_PID_Msk (0x3<<8)
74 #define QTD_PID_OUT (0<<8) /* generates token (E1H) */
75 #define QTD_PID_IN (1<<8) /* generates token (69H) */
76 #define QTD_PID_SETUP (2<<8) /* generates token (2DH) */
77
78 #define QTD_ERR_COUNTER (3<<10) /* Token[11:10] */
79 #define QTD_IOC (1<<15) /* Token[15] - Interrupt On Complete */
80 #define QTD_TODO_LEN_Pos 16 /* Token[31:16] - Total Bytes to Transfer */
81 #define QTD_TODO_LEN(x) (((x)>>16) & 0x7FFF)
82 #define QTD_DT (1UL<<31) /* Token[31] - Data Toggle */
83
84 /*----------------------------------------------------------------------------------------*/
85 /* Queue Head (QH) */
86 /*----------------------------------------------------------------------------------------*/
87 typedef struct qh_t
88 {
89 /* OHCI spec. Endpoint descriptor */
90 uint32_t HLink; /* Queue Head Horizontal Link Pointer */
91 uint32_t Chrst; /* Endpoint Characteristics: QH DWord 1 */
92 uint32_t Cap; /* Endpoint Capabilities: QH DWord 2 */
93 uint32_t Curr_qTD; /* Current qTD Pointer */
94 /*
95 * The followings are qTD Transfer Overlay
96 */
97 uint32_t OL_Next_qTD; /* Next qTD Pointer */
98 uint32_t OL_Alt_Next_qTD; /* Alternate Next qTD Pointer */
99 uint32_t OL_Token; /* qTD Token */
100 uint32_t OL_Bptr[5]; /* qTD Buffer Page Pointer List */
101 /*
102 * The following members are used by USB Host libary.
103 */
104 qTD_T *dummy; /* point to the inactive dummy qTD */
105 qTD_T *qtd_list; /* currently linked qTD transfers */
106 qTD_T *done_list; /* currently linked qTD transfers */
107 struct qh_t *next; /* point to the next QH in remove list */
108 } QH_T;
109
110 /* HLink[0] T field of "Queue Head Horizontal Link Pointer" */
111 #define QH_HLNK_END 0x1
112
113 /*
114 * HLink[2:1] Typ field of "Queue Head Horizontal Link Pointer"
115 */
116 #define QH_HLNK_ITD(x) (((uint32_t)(x) & ~0x1F) | 0x0)
117 #define QH_HLNK_QH(x) (((uint32_t)(x) & ~0x1F) | 0x2)
118 #define QH_HLNK_SITD(x) (((uint32_t)(x) & ~0x1F) | 0x4)
119 #define QH_HLNK_FSTN(x) (((uint32_t)(x) & ~0x1F) | 0x6)
120 #define QH_PTR(x) ((QH_T *)((uint32_t)(x) & ~0x1F))
121
122 /*
123 * Bit fields of "Endpoint Characteristics"
124 */
125 #define QH_NAK_RL (4L<<28) /* Chrst[31:28] - NAK Count Reload */
126 #define QH_CTRL_EP_FLAG (1<<27) /* Chrst[27] - Control Endpoint Flag */
127 #define QH_RCLM_LIST_HEAD (1<<15) /* Chrst[15] - Head of Reclamation List Flag */
128 #define QH_DTC (1<<14) /* Chrst[14] - Data Toggle Control */
129 #define QH_EPS_FULL (0<<12) /* Chrst[13:12] - Endpoint Speed (Full) */
130 #define QH_EPS_LOW (1<<12) /* Chrst[13:12] - Endpoint Speed (Low) */
131 #define QH_EPS_HIGH (2<<12) /* Chrst[13:12] - Endpoint Speed (High) */
132 #define QH_I_NEXT (1<<7) /* Chrst[7] - Inactivate on Next Transaction */
133
134 /*
135 * Bit fields of "Endpoint Capabilities"
136 */
137 #define QH_MULT_Pos 30 /* Cap[31:30] - High-Bandwidth Pipe Multiplier */
138 #define QH_HUB_PORT_Pos 23 /* Cap[29:23] - Hub Port Number */
139 #define QH_HUB_ADDR_Pos 16 /* Cap[22:16] - Hub Addr */
140 #define QH_C_MASK_Msk 0xFF00 /* Cap[15:8] - uFrame C-mask */
141 #define QH_S_MASK_Msk 0x00FF /* Cap[7:0] - uFrame S-mask */
142
143
144 /*----------------------------------------------------------------------------------------*/
145 /* Isochronous (High-Speed) Transfer Descriptor (iTD) */
146 /*----------------------------------------------------------------------------------------*/
147 typedef struct itd_t
148 {
149 uint32_t Next_Link; /* Next Link Pointer */
150 uint32_t Transaction[8]; /* Transaction Status and Control */
151 uint32_t Bptr[7]; /* Buffer Page Pointer List */
152 /*
153 * The following members are used by USB Host libary.
154 */
155 struct iso_ep_t *iso_ep; /* associated isochronous information block */
156 struct utr_t *utr; /* associated UTR */
157 uint32_t buff_base; /* buffer base address */
158 uint8_t fidx; /* iTD's first index to UTR iso frames */
159 uint8_t trans_mask; /* mask of activated transactions in iTD */
160 uint32_t sched_frnidx; /* scheduled frame index */
161 struct itd_t *next; /* used by software to maintain iTD list */
162 } iTD_T;
163
164 /*
165 * Next_Link[2:1] Typ field of "Next Schedule Element Pointer" Typ field
166 */
167 #define ITD_HLNK_ITD(x) (((uint32_t)(x) & ~0x1F) | 0x0)
168 #define ITD_HLNK_QH(x) (((uint32_t)(x) & ~0x1F) | 0x2)
169 #define ITD_HLNK_SITD(x) (((uint32_t)(x) & ~0x1F) | 0x4)
170 #define ITD_HLNK_FSTN(x) (((uint32_t)(x) & ~0x1F) | 0x6)
171 #define ITD_PTR(x) ((iTD_T *)((uint32_t)(x) & ~0x1F))
172
173 /*
174 * Transaction[8]
175 */
176 #define ITD_STATUS(x) (((x)>>28)&0xF)
177 #define ITD_STATUS_ACTIVE (0x80000000UL) /* Active */
178 #define ITD_STATUS_BUFF_ERR (0x40000000UL) /* Data Buffer Error */
179 #define ITD_STATUS_BABBLE (0x20000000UL) /* Babble Detected */
180 #define ITD_STATUS_XACT_ERR (0x10000000UL) /* Transcation Error */
181
182 #define ITD_XLEN_Pos 16
183 #define ITD_XFER_LEN(x) (((x)>>16)&0xFFF)
184 #define ITD_IOC (1<<15)
185 #define ITD_PG_Pos 12
186 #define ITD_XFER_OFF_Msk 0xFFF
187
188 /*
189 * Bptr[7]
190 */
191 #define ITD_BUFF_PAGE_Pos 12
192 /* Bptr[0] */
193 #define ITD_EP_NUM_Pos 8
194 #define ITD_EP_NUM(itd) (((itd)->Bptr[0]>>8)&0xF)
195 #define ITD_DEV_ADDR_Pos 0
196 #define ITD_DEV_ADDR(itd) ((itd)->Bptr[0]&0x7F)
197 /* Bptr[1] */
198 #define ITD_DIR_IN (1<<11)
199 #define ITD_DIR_OUT (0<<11)
200 #define ITD_MAX_PKTSZ_Pos 0
201 #define ITD_MAX_PKTSZ(itd) ((itd)->Bptr[1]&0x7FF)
202
203 /*----------------------------------------------------------------------------------------*/
204 /* Split Isochronous (Full-Speed) Transfer Descriptor (siTD) */
205 /*----------------------------------------------------------------------------------------*/
206 typedef struct sitd_t
207 {
208 uint32_t Next_Link; /* Next Link Pointer */
209 uint32_t Chrst; /* Endpoint and Transaction Translator Characteristics */
210 uint32_t Sched; /* Micro-frame Schedule Control */
211 uint32_t StsCtrl; /* siTD Transfer Status and Control */
212 uint32_t Bptr[2]; /* Buffer Page Pointer List */
213 uint32_t BackLink; /* siTD Back Link Pointer */
214 /*
215 * The following members are used by USB Host libary.
216 */
217 struct iso_ep_t *iso_ep; /* associated isochronous information block */
218 struct utr_t *utr; /* associated UTR */
219 uint8_t fidx; /* iTD's first index to UTR iso frames */
220 uint32_t sched_frnidx; /* scheduled frame index */
221 struct sitd_t *next; /* used by software to maintain siTD list */
222 } siTD_T;
223
224 #define SITD_LIST_END 0x1 /* Indicate the terminate of siTD list. */
225
226 #define SITD_XFER_IO_Msk (1UL<<31)
227 #define SITD_XFER_IN (1UL<<31)
228 #define SITD_XFER_OUT (0UL<<31)
229
230 #define SITD_PORT_NUM_Pos 24
231 #define SITD_HUB_ADDR_Pos 16
232 #define SITD_EP_NUM_Pos 8
233 #define SITD_DEV_ADDR_Pos 0
234
235 #define SITD_IOC (1UL<<31)
236 #define SITD_XFER_CNT_Pos 16
237 #define SITD_XFER_CNT_Msk (0x3FF<<SITD_XFER_CNT_Pos)
238
239 #define SITD_STATUS(x) ((x)&0xFC)
240 #define SITD_STATUS_ACTIVE 0x80
241 #define SITD_STATUS_ERR 0x40
242 #define SITD_STATUS_BUFF_ERR 0x20
243 #define SITD_BABBLE_DETECTED 0x10
244 #define SITD_STATUS_XFER_ERR 0x08
245 #define SITD_STATUS_MISSED_MF 0x04
246 #define SITD_STATUS_ERROR_MASK 0x78
247
248
249 /*
250 * Next_Link[2:1] Typ field of "Next Schedule Element Pointer" Typ field
251 */
252 #define SITD_HLNK_ITD(x) (((uint32_t)(x) & ~0x1F) | 0x0)
253 #define SITD_HLNK_QH(x) (((uint32_t)(x) & ~0x1F) | 0x2)
254 #define SITD_HLNK_SITD(x) (((uint32_t)(x) & ~0x1F) | 0x4)
255 #define SITD_HLNK_FSTN(x) (((uint32_t)(x) & ~0x1F) | 0x6)
256 #define SITD_PTR(x) ((siTD_T *)((uint32_t)(x) & ~0x1F))
257
258 #define HLINK_IS_TERMINATED(x) (((uint32_t)(x) & 0x1) ? 1 : 0)
259 #define HLINK_IS_SITD(x) ((((uint32_t)(x) & 0x6) == 0x4) ? 1 : 0)
260
261 /*----------------------------------------------------------------------------------------*/
262 /* Isochronous endpoint transfer information block. (Software only) */
263 /*----------------------------------------------------------------------------------------*/
264 typedef struct iso_ep_t
265 {
266 struct ep_info_t *ep;
267 uint32_t next_frame; /* frame number of next scheduling */
268 iTD_T *itd_list; /* Reference to a list of installed iTDs */
269 iTD_T *itd_done_list; /* Reference to a list of completed iTDs */
270 siTD_T *sitd_list; /* Reference to a list of installed siTDs */
271 siTD_T *sitd_done_list; /* Reference to a list of completed siTDs */
272 struct iso_ep_t *next; /* used by software to maintain ISO EP list */
273 } ISO_EP_T;
274
275 extern void scan_isochronous_list(void);
276
278
279 #endif /* _USBH_EHCI_H_ */
280