LPCOpen Platform  v1.03
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.h"
42 #include <string.h>
43 #include <stdio.h>
44 
47 #define HCD_ENDPOINT_MAXPACKET_XFER_LEN 0xFFEEFFEE
48 
51 #define YES 1
52 
55 #define NO 0
56 
59 #define HCD_MAX_ENDPOINT 8
60 
63 #define HC_RESET_TIMEOUT 10
64 
67 #define TRANSFER_TIMEOUT_MS 1000
68 
71 #define PORT_RESET_PERIOD_MS 100
72 
73 /* Control / Bulk transfer is always enabled */
77 #define INTERRUPT_LIST_ENABLE YES
78 
82 #define ISO_LIST_ENABLE YES
83 
86 typedef enum {
92 
95 typedef enum {
100 
103 typedef enum {
107 } HCD_USB_SPEED;
108 
111 typedef enum {
152 } HCD_STATUS;
153 
160 HCD_STATUS HcdInitDriver (uint8_t HostID);
161 
168 HCD_STATUS HcdDeInitDriver(uint8_t HostID);
169 
177 void HcdIrqHandler(uint8_t HostID);
178 
185 HCD_STATUS HcdRhPortReset(uint8_t HostID);
186 
193 HCD_STATUS HcdRhPortEnable(uint8_t HostID);
194 
201 HCD_STATUS HcdRhPortDisable(uint8_t HostID);
202 
210 HCD_STATUS HcdGetDeviceSpeed(uint8_t HostID, HCD_USB_SPEED *DeviceSpeed);
211 
218 uint32_t HcdGetFrameNumber(uint8_t HostID);
219 
237 HCD_STATUS HcdOpenPipe(uint8_t HostID,
238  uint8_t DeviceAddr,
239  HCD_USB_SPEED DeviceSpeed,
240  uint8_t EndpointNo,
241  HCD_TRANSFER_TYPE TransferType,
242  HCD_TRANSFER_DIR TransferDir,
243  uint16_t MaxPacketSize,
244  uint8_t Interval,
245  uint8_t Mult,
246  uint8_t HSHubDevAddr,
247  uint8_t HSHubPortNum,
248  uint32_t *const PipeHandle);
249 
256 HCD_STATUS HcdClosePipe(uint32_t PipeHandle);
257 
265 
273 
283  const USB_Request_Header_t *const pDeviceRequest,
284  uint8_t *const buffer);
285 
296  uint8_t *const buffer,
297  uint32_t const length,
298  uint16_t *const pActualTransferred);
299 
307 
315 void HcdSetStreamPacketSize(uint32_t PipeHandle, uint16_t packetsize);
316 
317 #ifdef LPCUSBlib_DEBUG
318  #define hcd_printf printf
320  char const *mess,
321  char const *func,
322  char const *file,
323  uint32_t const line);
324 
325 #else
326  #define hcd_printf(...)
327  #define assert_status_ok_message(...)
328 #endif
329 
330 #define ASSERT_STATUS_OK_MESSAGE(sts, message) \
331  do { \
332  HCD_STATUS status = (sts); \
333  assert_status_ok_message(status, message, __func__, __FILE__, __LINE__); \
334  if (HCD_STATUS_OK != status) { \
335  return status; \
336  } \
337  } while (0)
338 
339 #define ASSERT_STATUS_OK(sts) ASSERT_STATUS_OK_MESSAGE(sts, NULL)
340 
341 #if defined(__LPC_OHCI_C__) || defined(__LPC_EHCI_C__)
342 
343 void HcdDelayUS (uint32_t delay);
344 
345 void HcdDelayMS (uint32_t delay);
346 
362  uint8_t DeviceAddr,
363  HCD_USB_SPEED DeviceSpeed,
364  uint8_t EndpointNumber,
365  HCD_TRANSFER_TYPE TransferType,
366  HCD_TRANSFER_DIR TransferDir,
367  uint16_t MaxPacketSize,
368  uint8_t Interval,
369  uint8_t Mult);
370 
377 static INLINE uint32_t Align32(uint32_t Value)
378 {
379  return Value & 0xFFFFFFE0UL; /* Bit 31 .. 5 */
380 }
381 
389 static INLINE uint32_t Aligned(uint32_t alignment, uint32_t Value)
390 {
391  return Value & (~(alignment - 1));
392 }
393 
400 static INLINE uint32_t Align4k(uint32_t Value)
401 {
402  return Value & 0xFFFFF000; /* Bit 31 .. 5 */
403 }
404 
411 static INLINE uint32_t Offset4k(uint32_t Value)
412 {
413  return Value & 0xFFF;
414 }
415 
416 #endif
417 
418 #endif
419