LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HCD.h
Go to the documentation of this file.
1 /*
2  * @brief Host Controller Driver functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
36 #ifndef __LPC_HCD_H__
37 #define __LPC_HCD_H__
38 
39 #include "../../../../../Common/Common.h"
40 #include "../../StdRequestType.h" // FIXME should be USBTask.h instead
41 #include "../HAL/HAL_LPC.h"
42 #include <string.h>
43 #include <stdio.h>
44 
45 #define HCD_ENDPOINT_MAXPACKET_XFER_LEN 0xFFEEFFEE
46 
47 /*=======================================================================*/
48 /* HCD C O N F I G U R A T I O N */
49 /*=======================================================================*/
50 #define YES 1
51 #define NO 0
52 
53 #define HCD_MAX_ENDPOINT 8 /* Maximum number of endpoints */
54 
55 #define HC_RESET_TIMEOUT 10 /* in microseconds */
56 #define TRANSFER_TIMEOUT_MS 1000
57 #define PORT_RESET_PERIOD_MS 100
58 
59 /* Control / Bulk transfer is always enabled */
60 #define INTERRUPT_LIST_ENABLE YES /* Int transfer enable */
61 #define ISO_LIST_ENABLE YES /* ISO transfer enable */
62 
63 /*=======================================================================*/
64 /* HCD T Y P E S */
65 /*=======================================================================*/
66 typedef enum {
72 
73 typedef enum {
78 
79 typedef enum {
84 
85 typedef enum {
86  /* TD Completion Code, Corresponding to OHCI Completion Code */
88 
94 
100 
106  /* End Completion Code OHCI 0-15 */
107 
108  /*-- 16-20 Data Structure Status --*/
114 
115  /*---------- 21-25 Memory Code ----------*/
121 
122  /* 26-30 */
128 
129  /* 31-35 */
132 } HCD_STATUS;
133 
134 // ////////////////////////////////////////////////////////////////////////
135 HCD_STATUS HcdInitDriver (uint8_t HostID);
136 
137 HCD_STATUS HcdDeInitDriver(uint8_t HostID);
138 
139 void HcdIrqHandler(uint8_t HostID);
140 
141 /************************************************************************/
142 /* Port API */
143 /************************************************************************/
144 HCD_STATUS HcdRhPortReset(uint8_t HostID, uint8_t PortNum);
145 
146 HCD_STATUS HcdRhPortEnable(uint8_t HostID, uint8_t PortNum);
147 
148 HCD_STATUS HcdRhPortDisable(uint8_t HostID, uint8_t PortNum);
149 
150 HCD_STATUS HcdGetDeviceSpeed(uint8_t HostID, uint8_t PortNum, HCD_USB_SPEED *DeviceSpeed);
151 
152 uint32_t HcdGetFrameNumber(uint8_t HostID);
153 
154 /************************************************************************/
155 /* Pipe API */
156 /************************************************************************/
157 HCD_STATUS HcdOpenPipe(uint8_t HostID,
158  uint8_t DeviceAddr,
159  HCD_USB_SPEED DeviceSpeed,
160  uint8_t EndpointNo,
161  HCD_TRANSFER_TYPE TransferType,
162  HCD_TRANSFER_DIR TransferDir,
163  uint16_t MaxPacketSize,
164  uint8_t Interval,
165  uint8_t Mult,
166  uint8_t HSHubDevAddr,
167  uint8_t HSHubPortNum,
168  uint32_t *const PipeHandle);
169 
170 HCD_STATUS HcdClosePipe(uint32_t PipeHandle);
171 
173 
175 
176 /************************************************************************/
177 /* Transfer API */
178 /************************************************************************/
180  const USB_Request_Header_t *const pDeviceRequest,
181  uint8_t *const buffer);
182 
184  uint8_t *const buffer,
185  uint32_t const length,
186  uint16_t *const pActualTransferred);
187 
189 
190 #ifdef LPCUSBlib_DEBUG
191  #define hcd_printf printf
193  char const *mess,
194  char const *func,
195  char const *file,
196  uint32_t const line);
197 
198 #else
199  #define hcd_printf(...)
200  #define assert_status_ok_message(...)
201 #endif
202 
203 #define ASSERT_STATUS_OK_MESSAGE(sts, message) \
204  do { \
205  HCD_STATUS status = (sts); \
206  assert_status_ok_message(status, message, __func__, __FILE__, __LINE__); \
207  if (HCD_STATUS_OK != status) { \
208  return status; \
209  } \
210  } while (0)
211 
212 #define ASSERT_STATUS_OK(sts) ASSERT_STATUS_OK_MESSAGE(sts, NULL)
213 
214 #if defined(__LPC_OHCI_C__) || defined(__LPC_EHCI_C__)
215 
216 void HcdDelayUS (uint32_t delay); // TODO use unify delay
217 
218 void HcdDelayMS (uint32_t delay);
219 
221  uint8_t DeviceAddr,
222  HCD_USB_SPEED DeviceSpeed,
223  uint8_t EndpointNumber,
224  HCD_TRANSFER_TYPE TransferType,
225  HCD_TRANSFER_DIR TransferDir,
226  uint16_t MaxPacketSize,
227  uint8_t Interval,
228  uint8_t Mult);
229 
230 static INLINE uint32_t Align32(uint32_t Value)
231 {
232  return Value & 0xFFFFFFE0UL; /* Bit 31 .. 5 */
233 }
234 
235 static INLINE uint32_t Aligned(uint32_t alignment, uint32_t Value)
236 {
237  return Value & (~(alignment - 1));
238 }
239 
240 static INLINE uint32_t Align4k(uint32_t Value)
241 {
242  return Value & 0xFFFFF000; /* Bit 31 .. 5 */
243 }
244 
245 static INLINE uint32_t Offset4k(uint32_t Value)
246 {
247  return Value & 0xFFF;
248 }
249 
250 #endif
251 
252 #endif
253