2 * @brief HAL USB functions for the LPC17xx microcontrollers
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 /** @ingroup Group_HAL_LPC
\r
33 * @defgroup Group_HAL_LPC17xx Hardware Abstraction Layer LPC17XX
\r
36 #ifndef __HAL_LPC17XX_H__
\r
37 #define __HAL_LPC17XX_H__
\r
41 #define __INCLUDE_FROM_USB_DRIVER
\r
42 #include "../../USBMode.h"
\r
44 #define USBRAM_SECTION RAM2
\r
46 #if defined(__LPC177X_8X__) || defined(__LPC407X_8X__)
\r
47 /** This macro is used to declare a variable in a defined section. */
\r
48 #if defined(__CC_ARM)
\r
49 #define __BSS(x) __attribute__ ((section("usbram")))
\r
51 #if defined(__ICCARM__)
\r
52 #define __BSS(x) @ ".sram"
\r
55 #if defined(__CC_ARM) || defined(__ICCARM__)
\r
60 #define USB_REG(CoreID) LPC_USB
\r
63 * @brief Interrupt Handler (Host side).
\r
64 * This handler is known as interrupt service routine of USB Host.
\r
66 * @param HostID : Host ID
\r
69 extern void HcdIrqHandler(uint8_t HostID);
\r
71 #ifdef USB_CAN_BE_DEVICE
\r
73 /* Device Interrupt Bit Definitions */
\r
74 #define FRAME_INT 0x00000001
\r
75 #define EP_FAST_INT 0x00000002
\r
76 #define EP_SLOW_INT 0x00000004
\r
77 #define DEV_STAT_INT 0x00000008
\r
78 #define CCEMTY_INT 0x00000010
\r
79 #define CDFULL_INT 0x00000020
\r
80 #define RxENDPKT_INT 0x00000040
\r
81 #define TxENDPKT_INT 0x00000080
\r
82 #define EP_RLZED_INT 0x00000100
\r
83 #define ERR_INT 0x00000200
\r
85 /* Rx & Tx Packet Length Definitions */
\r
86 #define PKT_LNGTH_MASK 0x000003FF
\r
87 #define PKT_DV 0x00000400
\r
88 #define PKT_RDY 0x00000800
\r
90 /* USB Control Definitions */
\r
91 #define CTRL_RD_EN 0x00000001
\r
92 #define CTRL_WR_EN 0x00000002
\r
95 #define CMD_SET_ADDR 0x00D00500
\r
96 #define CMD_CFG_DEV 0x00D80500
\r
97 #define CMD_SET_MODE 0x00F30500
\r
98 #define CMD_RD_FRAME 0x00F50500
\r
99 #define DAT_RD_FRAME 0x00F50200
\r
100 #define CMD_RD_TEST 0x00FD0500
\r
101 #define DAT_RD_TEST 0x00FD0200
\r
102 #define CMD_SET_DEV_STAT 0x00FE0500
\r
103 #define CMD_GET_DEV_STAT 0x00FE0500
\r
104 #define DAT_GET_DEV_STAT 0x00FE0200
\r
105 #define CMD_GET_ERR_CODE 0x00FF0500
\r
106 #define DAT_GET_ERR_CODE 0x00FF0200
\r
107 #define CMD_RD_ERR_STAT 0x00FB0500
\r
108 #define DAT_RD_ERR_STAT 0x00FB0200
\r
109 #define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16))
\r
110 #define CMD_SEL_EP(x) (0x00000500 | ((x) << 16))
\r
111 #define DAT_SEL_EP(x) (0x00000200 | ((x) << 16))
\r
112 #define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16))
\r
113 #define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16))
\r
114 #define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16))
\r
115 #define CMD_CLR_BUF 0x00F20500
\r
116 #define DAT_CLR_BUF 0x00F20200
\r
117 #define CMD_VALID_BUF 0x00FA0500
\r
119 /* Device Address Register Definitions */
\r
120 #define DEV_ADDR_MASK 0x7F
\r
121 #define DEV_EN 0x80
\r
123 /* Device Configure Register Definitions */
\r
124 #define CONF_DVICE 0x01
\r
126 /* Device Mode Register Definitions */
\r
127 #define AP_CLK 0x01
\r
128 #define INAK_CI 0x02
\r
129 #define INAK_CO 0x04
\r
130 #define INAK_II 0x08
\r
131 #define INAK_IO 0x10
\r
132 #define INAK_BI 0x20
\r
133 #define INAK_BO 0x40
\r
135 /* Device Status Register Definitions */
\r
136 #define DEV_CON 0x01
\r
137 #define DEV_CON_CH 0x02
\r
138 #define DEV_SUS 0x04
\r
139 #define DEV_SUS_CH 0x08
\r
140 #define DEV_RST 0x10
\r
142 /* Error Code Register Definitions */
\r
143 #define ERR_EC_MASK 0x0F
\r
144 #define ERR_EA 0x10
\r
146 /* Error Status Register Definitions */
\r
147 #define ERR_PID 0x01
\r
148 #define ERR_UEPKT 0x02
\r
149 #define ERR_DCRC 0x04
\r
150 #define ERR_TIMOUT 0x08
\r
151 #define ERR_EOP 0x10
\r
152 #define ERR_B_OVRN 0x20
\r
153 #define ERR_BTSTF 0x40
\r
154 #define ERR_TGL 0x80
\r
156 /* Endpoint Select Register Definitions */
\r
157 #define EP_SEL_F 0x01
\r
158 #define EP_SEL_ST 0x02
\r
159 #define EP_SEL_STP 0x04
\r
160 #define EP_SEL_PO 0x08
\r
161 #define EP_SEL_EPN 0x10
\r
162 #define EP_SEL_B_1_FULL 0x20
\r
163 #define EP_SEL_B_2_FULL 0x40
\r
165 /* Endpoint Status Register Definitions */
\r
166 #define EP_STAT_ST 0x01
\r
167 #define EP_STAT_DA 0x20
\r
168 #define EP_STAT_RF_MO 0x40
\r
169 #define EP_STAT_CND_ST 0x80
\r
171 /* Clear Buffer Register Definitions */
\r
172 #define CLR_BUF_PO 0x01
\r
174 /* DMA Interrupt Bit Definitions */
\r
175 #define EOT_INT 0x01
\r
176 #define NDD_REQ_INT 0x02
\r
177 #define SYS_ERR_INT 0x04
\r
179 void HAL_Reset (uint8_t corenum);
\r
182 * @brief Set device address
\r
183 * @param Address : Address to be set
\r
186 void HAL_SetDeviceAddress (uint8_t Address);
\r
189 * @brief Send connect SIE command
\r
190 * @param con : connect or disconnect status
\r
193 void HAL17XX_USBConnect (uint32_t con);
\r
196 * @brief Read SIE command data
\r
197 * @param cmd : command code
\r
200 uint32_t SIE_ReadCommandData (uint32_t cmd);/* Device_LPC17xx */
\r
202 /*---------- DMA Descriptor ----------*/
\r
204 /*---------- Word 0 ----------*/
\r
207 /*---------- Word 1 ----------*/
\r
208 /* 1st half word */
\r
210 uint16_t NextDDValid : 1;
\r
212 uint16_t Isochronous : 1;
\r
213 uint16_t MaxPacketSize : 11;
\r
214 /* 2nd half word */
\r
215 __IO uint16_t BufferLength;
\r
217 /*---------- Word 2 ----------*/
\r
218 __IO uint8_t *BufferStartAddr;
\r
220 /*---------- Word 3 ----------*/
\r
221 /* 1st half word */
\r
222 __IO uint16_t Retired : 1;
\r
223 uint16_t Status : 4;
\r
224 uint16_t IsoPacketValid : 1;
\r
225 uint16_t LSByteExtracted : 1; /* ATLE mode */
\r
226 uint16_t MSByteExtracted : 1; /* ATLE mode */
\r
227 uint16_t MessageLengthPosition : 6;
\r
229 /* 2st half word */
\r
230 uint16_t PresentCount;
\r
232 /*---------- Word 4 ----------*/
\r
233 uint32_t IsoBufferAddr; /* Iso transfer exclusive */
\r
234 } DMADescriptor, *PDMADescriptor;
\r
237 #endif // __HAL_LPC17XX_H__
\r