LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HAL_LPC17xx.h
Go to the documentation of this file.
1 /*
2  * @brief HAL USB functions for the LPC17xx microcontrollers
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 #ifndef __HAL_LPC17XX_H__
33 #define __HAL_LPC17XX_H__
34 
35 #if defined(__LPC17XX__)
36 #include "LPC17xx.h"
37 #elif defined(__LPC177X_8X__)
38 #include "LPC177x_8x.h"
39 #endif
40 #include "lpc_types.h"
41 #define __INCLUDE_FROM_USB_DRIVER
42 #include "../../../USBMode.h"
43 
44 #define USBRAM_SECTION RAM2
45 
46 #if defined(__LPC177X_8X__)
47 
48 #if defined(__CC_ARM)
49  #undef __DATA(x)
50  #define __DATA(x) __attribute__ ((section("usbram")))
51 #endif
52 #endif
53 #if defined(__ICCARM__)
54  #define __DATA(x) @ "USB_DMA_RAM"
55 #endif
56 
57 extern void HcdIrqHandler(uint8_t HostID);
58 
59 #ifdef USB_CAN_BE_DEVICE
60 
61 #define FRAME_INT 0x00000001
62 #define EP_FAST_INT 0x00000002
63 #define EP_SLOW_INT 0x00000004
64 #define DEV_STAT_INT 0x00000008
65 #define CCEMTY_INT 0x00000010
66 #define CDFULL_INT 0x00000020
67 #define RxENDPKT_INT 0x00000040
68 #define TxENDPKT_INT 0x00000080
69 #define EP_RLZED_INT 0x00000100
70 #define ERR_INT 0x00000200
71 
72 #define PKT_LNGTH_MASK 0x000003FF
73 #define PKT_DV 0x00000400
74 #define PKT_RDY 0x00000800
75 
76 #define CTRL_RD_EN 0x00000001
77 #define CTRL_WR_EN 0x00000002
78 
79 #define CMD_SET_ADDR 0x00D00500
80 #define CMD_CFG_DEV 0x00D80500
81 #define CMD_SET_MODE 0x00F30500
82 #define CMD_RD_FRAME 0x00F50500
83 #define DAT_RD_FRAME 0x00F50200
84 #define CMD_RD_TEST 0x00FD0500
85 #define DAT_RD_TEST 0x00FD0200
86 #define CMD_SET_DEV_STAT 0x00FE0500
87 #define CMD_GET_DEV_STAT 0x00FE0500
88 #define DAT_GET_DEV_STAT 0x00FE0200
89 #define CMD_GET_ERR_CODE 0x00FF0500
90 #define DAT_GET_ERR_CODE 0x00FF0200
91 #define CMD_RD_ERR_STAT 0x00FB0500
92 #define DAT_RD_ERR_STAT 0x00FB0200
93 #define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16))
94 #define CMD_SEL_EP(x) (0x00000500 | ((x) << 16))
95 #define DAT_SEL_EP(x) (0x00000200 | ((x) << 16))
96 #define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16))
97 #define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16))
98 #define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16))
99 #define CMD_CLR_BUF 0x00F20500
100 #define DAT_CLR_BUF 0x00F20200
101 #define CMD_VALID_BUF 0x00FA0500
102 
103 #define DEV_ADDR_MASK 0x7F
104 #define DEV_EN 0x80
105 
106 #define CONF_DVICE 0x01
107 
108 #define AP_CLK 0x01
109 #define INAK_CI 0x02
110 #define INAK_CO 0x04
111 #define INAK_II 0x08
112 #define INAK_IO 0x10
113 #define INAK_BI 0x20
114 #define INAK_BO 0x40
115 
116 #define DEV_CON 0x01
117 #define DEV_CON_CH 0x02
118 #define DEV_SUS 0x04
119 #define DEV_SUS_CH 0x08
120 #define DEV_RST 0x10
121 
122 #define ERR_EC_MASK 0x0F
123 #define ERR_EA 0x10
124 
125 #define ERR_PID 0x01
126 #define ERR_UEPKT 0x02
127 #define ERR_DCRC 0x04
128 #define ERR_TIMOUT 0x08
129 #define ERR_EOP 0x10
130 #define ERR_B_OVRN 0x20
131 #define ERR_BTSTF 0x40
132 #define ERR_TGL 0x80
133 
134 #define EP_SEL_F 0x01
135 #define EP_SEL_ST 0x02
136 #define EP_SEL_STP 0x04
137 #define EP_SEL_PO 0x08
138 #define EP_SEL_EPN 0x10
139 #define EP_SEL_B_1_FULL 0x20
140 #define EP_SEL_B_2_FULL 0x40
141 
142 #define EP_STAT_ST 0x01
143 #define EP_STAT_DA 0x20
144 #define EP_STAT_RF_MO 0x40
145 #define EP_STAT_CND_ST 0x80
146 
147 #define CLR_BUF_PO 0x01
148 
149 #define EOT_INT 0x01
150 #define NDD_REQ_INT 0x02
151 #define SYS_ERR_INT 0x04
152 
153 void HAL_Reset (void);
154 
155 void HAL_SetDeviceAddress (uint8_t Address);
156 
157 void HAL17XX_USBConnect (uint32_t con);
158 
159 uint32_t SIE_ReadCommandData (uint32_t cmd);/* Device_LPC17xx */
160 
161 typedef struct {
162  /*---------- Word 0 ----------*/
164 
165  /*---------- Word 1 ----------*/
166  /* 1st half word */
167  uint16_t Mode : 2;
168  uint16_t NextDDValid : 1;
169  uint16_t : 1;
170  uint16_t Isochronous : 1;
171  uint16_t MaxPacketSize : 11;
172  /* 2nd half word */
173  __IO uint16_t BufferLength;
174 
175  /*---------- Word 2 ----------*/
176  __IO uint8_t *BufferStartAddr;
177 
178  /*---------- Word 3 ----------*/
179  /* 1st half word */
180  __IO uint16_t Retired : 1;
181  uint16_t Status : 4;
182  uint16_t IsoPacketValid : 1;
183  uint16_t LSByteExtracted : 1; /* ATLE mode */
184  uint16_t MSByteExtracted : 1; /* ATLE mode */
185  uint16_t MessageLengthPosition : 6;
186  uint16_t : 2;
187  /* 2st half word */
188  uint16_t PresentCount;
189 
190  /*---------- Word 4 ----------*/
191  uint32_t IsoBufferAddr; /* Iso transfer exclusive */
193 #endif
194 
195 #endif // __HAL_LPC17XX_H__