Update Webserver project to remove DHCP IP configuration status notification.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / EndpointStream.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #define __INCLUDE_FROM_USB_DRIVER
32 #include "USBMode.h"
33
34 #if defined(USB_CAN_BE_DEVICE)
35
36 #include "EndpointStream.h"
37
38 #if !defined(CONTROL_ONLY_DEVICE)
39 uint8_t Endpoint_Discard_Stream(uint16_t Length,
40 uint16_t* const BytesProcessed)
41 {
42 uint8_t ErrorCode;
43 uint16_t BytesInTransfer = 0;
44
45 if ((ErrorCode = Endpoint_WaitUntilReady()))
46 return ErrorCode;
47
48 if (BytesProcessed != NULL)
49 Length -= *BytesProcessed;
50
51 while (Length)
52 {
53 if (!(Endpoint_IsReadWriteAllowed()))
54 {
55 Endpoint_ClearOUT();
56
57 if (BytesProcessed != NULL)
58 {
59 *BytesProcessed += BytesInTransfer;
60 return ENDPOINT_RWSTREAM_IncompleteTransfer;
61 }
62
63 if ((ErrorCode = Endpoint_WaitUntilReady()))
64 return ErrorCode;
65 }
66 else
67 {
68 Endpoint_Discard_8();
69
70 Length--;
71 BytesInTransfer++;
72 }
73 }
74
75 return ENDPOINT_RWSTREAM_NoError;
76 }
77
78 uint8_t Endpoint_Null_Stream(uint16_t Length,
79 uint16_t* const BytesProcessed)
80 {
81 uint8_t ErrorCode;
82 uint16_t BytesInTransfer = 0;
83
84 if ((ErrorCode = Endpoint_WaitUntilReady()))
85 return ErrorCode;
86
87 if (BytesProcessed != NULL)
88 Length -= *BytesProcessed;
89
90 while (Length)
91 {
92 if (!(Endpoint_IsReadWriteAllowed()))
93 {
94 Endpoint_ClearIN();
95
96 if (BytesProcessed != NULL)
97 {
98 *BytesProcessed += BytesInTransfer;
99 return ENDPOINT_RWSTREAM_IncompleteTransfer;
100 }
101
102 if ((ErrorCode = Endpoint_WaitUntilReady()))
103 return ErrorCode;
104 }
105 else
106 {
107 Endpoint_Write_8(0);
108
109 Length--;
110 BytesInTransfer++;
111 }
112 }
113
114 return ENDPOINT_RWSTREAM_NoError;
115 }
116
117 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
118 #define TEMPLATE_BUFFER_TYPE const void*
119 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
120 #define TEMPLATE_BUFFER_OFFSET(Length) 0
121 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
122 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
123 #include "Template/Template_Endpoint_RW.c"
124
125 #define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
126 #define TEMPLATE_BUFFER_TYPE const void*
127 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
128 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
129 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
130 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
131 #include "Template/Template_Endpoint_RW.c"
132
133 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
134 #define TEMPLATE_BUFFER_TYPE void*
135 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
136 #define TEMPLATE_BUFFER_OFFSET(Length) 0
137 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
138 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
139 #include "Template/Template_Endpoint_RW.c"
140
141 #define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
142 #define TEMPLATE_BUFFER_TYPE void*
143 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
144 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
145 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
146 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
147 #include "Template/Template_Endpoint_RW.c"
148
149 #if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
150 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
151 #define TEMPLATE_BUFFER_TYPE const void*
152 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
153 #define TEMPLATE_BUFFER_OFFSET(Length) 0
154 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
155 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
156 #include "Template/Template_Endpoint_RW.c"
157
158 #define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
159 #define TEMPLATE_BUFFER_TYPE const void*
160 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
161 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
162 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
163 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
164 #include "Template/Template_Endpoint_RW.c"
165 #endif
166
167 #if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
168 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
169 #define TEMPLATE_BUFFER_TYPE const void*
170 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
171 #define TEMPLATE_BUFFER_OFFSET(Length) 0
172 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
173 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
174 #include "Template/Template_Endpoint_RW.c"
175
176 #define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
177 #define TEMPLATE_BUFFER_TYPE const void*
178 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
179 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
180 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
181 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
182 #include "Template/Template_Endpoint_RW.c"
183
184 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
185 #define TEMPLATE_BUFFER_TYPE void*
186 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
187 #define TEMPLATE_BUFFER_OFFSET(Length) 0
188 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
189 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
190 #include "Template/Template_Endpoint_RW.c"
191
192 #define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
193 #define TEMPLATE_BUFFER_TYPE void*
194 #define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
195 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
196 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
197 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
198 #include "Template/Template_Endpoint_RW.c"
199 #endif
200
201 #endif
202
203 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
204 #define TEMPLATE_BUFFER_OFFSET(Length) 0
205 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
206 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
207 #include "Template/Template_Endpoint_Control_W.c"
208
209 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
210 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
211 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
212 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
213 #include "Template/Template_Endpoint_Control_W.c"
214
215 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
216 #define TEMPLATE_BUFFER_OFFSET(Length) 0
217 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
218 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
219 #include "Template/Template_Endpoint_Control_R.c"
220
221 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
222 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
223 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
224 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
225 #include "Template/Template_Endpoint_Control_R.c"
226
227 #if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
228 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
229 #define TEMPLATE_BUFFER_OFFSET(Length) 0
230 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
231 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
232 #include "Template/Template_Endpoint_Control_W.c"
233
234 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
235 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
236 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
237 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
238 #include "Template/Template_Endpoint_Control_W.c"
239 #endif
240
241 #if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
242 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
243 #define TEMPLATE_BUFFER_OFFSET(Length) 0
244 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
245 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
246 #include "Template/Template_Endpoint_Control_W.c"
247
248 #define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
249 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
250 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
251 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
252 #include "Template/Template_Endpoint_Control_W.c"
253
254 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
255 #define TEMPLATE_BUFFER_OFFSET(Length) 0
256 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
257 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
258 #include "Template/Template_Endpoint_Control_R.c"
259
260 #define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
261 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
262 #define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
263 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
264 #include "Template/Template_Endpoint_Control_R.c"
265 #endif
266
267 #endif