| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HCD.c
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
32 #define __INCLUDE_FROM_USB_DRIVER
33 #include "../USBMode.h"
34
35 #ifdef USB_CAN_BE_HOST
36
37 #if !defined(__LPC_OHCI__) && !defined(__LPC_EHCI__)
38 #error "Either __LPC_OHCI__ or __LPC_EHCI__ must be defined"
39 #endif
40
41 #include "../USBTask.h"
42
43
44 #ifdef LPCUSBlib_DEBUG
45 void assert_status_ok_message(HCD_STATUS status,
46 char const *mess,
47 char const *func,
48 char const *file,
49 uint32_t const line)
50 {
51 if (HCD_STATUS_OK != status) {
52 hcd_printf("%s\r\n", func);
53 hcd_printf("\t%s: %d\r\n", file, line);
54 hcd_printf("\tEvaluated HCD_STATUS = %d\r\n", (uint32_t) status);
55 if (mess != NULL) {
56 hcd_printf("\t%s\r\n", mess);
57 }
58 }
59 }
60
61 #endif
62
63 void HcdDelayUS(uint32_t delay)
64 {
65 volatile uint32_t i;
66
67 for (i = 0; i < (4 * delay); i++) /* This logic was tested. It gives app. 1 micro sec delay */
68 ;
69 }
70
71 void HcdDelayMS(uint32_t delay)
72 {
73 volatile uint32_t i;
74
75 for (i = 0; i < delay; i++)
76 HcdDelayUS(1000);
77 }
78
79 HCD_STATUS OpenPipe_VerifyParameters(uint8_t HostID,
80 uint8_t DeviceAddr,
81 HCD_USB_SPEED DeviceSpeed,
82 uint8_t EndpointNumber,
83 HCD_TRANSFER_TYPE TransferType,
84 HCD_TRANSFER_DIR TransferDir,
85 uint16_t MaxPacketSize,
86 uint8_t Interval,
87 uint8_t Mult)
88 {
89 if ((HostID >= MAX_USB_CORE) ||
90 ( DeviceAddr > 127) ||
91 ( DeviceSpeed > HIGH_SPEED) ||
92 (EndpointNumber & 0x70) ||
93 ( TransferType > INTERRUPT_TRANSFER) ||
94 ( TransferDir > OUT_TRANSFER) ) {
95 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
96 }
97
98 /* XXX by USB specs Low speed device should not have packet size > 8, but many market devices does */
99 if ((DeviceSpeed == LOW_SPEED) && ((TransferType == BULK_TRANSFER) || (TransferType == ISOCHRONOUS_TRANSFER)) ) {
100 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
101 }
102
103 switch (TransferType) {
104 case CONTROL_TRANSFER:
105 if (MaxPacketSize > 64) {
106 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
107 }
108 break;
109
110 case BULK_TRANSFER:
111 if (((DeviceSpeed == FULL_SPEED) && (MaxPacketSize > 64)) ||
112 ((DeviceSpeed == HIGH_SPEED) && (MaxPacketSize > 512)) ) {
113 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
114 }
115 break;
116
117 case INTERRUPT_TRANSFER:
118 if ((Interval == 0) ||
119 ((DeviceSpeed == FULL_SPEED) && (MaxPacketSize > 64)) ||
120 ((DeviceSpeed == HIGH_SPEED) && ((MaxPacketSize > 1024) || (Interval > 16) || (Mult == 0))) ) {
121 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
122 }
123 break;
124
125 case ISOCHRONOUS_TRANSFER:
126 if ((Interval == 0) || (Interval > 16) ||
127 ((DeviceSpeed == FULL_SPEED) && (MaxPacketSize > 1023)) ||
128 ((DeviceSpeed == HIGH_SPEED) && ((MaxPacketSize > 1024) || (Mult == 0))) ) {
129 ASSERT_STATUS_OK(HCD_STATUS_PARAMETER_INVALID);
130 }
131 break;
132 }
133 return HCD_STATUS_OK;
134 }
135
136 #endif