Fix incorrect macro guard in the UC3 EndpointStream header file.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / UC3 / EndpointStream_UC3.h
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 /** \file
32 * \brief Endpoint data stream transmission and reception management for the AVR32 UC3 microcontrollers.
33 * \copydetails Group_EndpointStreamRW_UC3
34 *
35 * \note This file should not be included directly. It is automatically included as needed by the USB driver
36 * dispatch header located in LUFA/Drivers/USB/USB.h.
37 */
38
39 /** \ingroup Group_EndpointStreamRW
40 * \defgroup Group_EndpointStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)
41 * \brief Endpoint data stream transmission and reception management for the Atmel AVR32 UC3 architecture.
42 *
43 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
44 * and to endpoints.
45 *
46 * @{
47 */
48
49 #ifndef __ENDPOINT_STREAM_UC3_H__
50 #define __ENDPOINT_STREAM_UC3_H__
51
52 /* Includes: */
53 #include "../../../../Common/Common.h"
54 #include "../USBMode.h"
55
56 /* Enable C linkage for C++ Compilers: */
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60
61 /* Preprocessor Checks: */
62 #if !defined(__INCLUDE_FROM_USB_DRIVER)
63 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
64 #endif
65
66 /* Public Interface - May be used in end-application: */
67 /* Function Prototypes: */
68 /** \name Stream functions for null data */
69 //@{
70
71 /** Reads and discards the given number of bytes from the currently selected endpoint's bank,
72 * discarding fully read packets from the host as needed. The last packet is not automatically
73 * discarded once the remaining bytes has been read; the user is responsible for manually
74 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
75 *
76 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
77 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
78 * storage location, the transfer will instead be performed as a series of chunks. Each time
79 * the endpoint bank becomes empty while there is still data to process (and after the current
80 * packet has been acknowledged) the BytesProcessed location will be updated with the total number
81 * of bytes processed in the stream, and the function will exit with an error code of
82 * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
83 * in the user code - to continue the transfer, call the function again with identical parameters
84 * and it will resume until the BytesProcessed value reaches the total transfer length.
85 *
86 * <b>Single Stream Transfer Example:</b>
87 * \code
88 * uint8_t ErrorCode;
89 *
90 * if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
91 * {
92 * // Stream failed to complete - check ErrorCode here
93 * }
94 * \endcode
95 *
96 * <b>Partial Stream Transfers Example:</b>
97 * \code
98 * uint8_t ErrorCode;
99 * uint16_t BytesProcessed;
100 *
101 * BytesProcessed = 0;
102 * while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
103 * {
104 * // Stream not yet complete - do other actions here, abort if required
105 * }
106 *
107 * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
108 * {
109 * // Stream failed to complete - check ErrorCode here
110 * }
111 * \endcode
112 *
113 * \note This routine should not be used on CONTROL type endpoints.
114 *
115 * \param[in] Length Number of bytes to discard via the currently selected endpoint.
116 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
117 * transaction should be updated, \c NULL if the entire stream should be read at once.
118 *
119 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
120 */
121 uint8_t Endpoint_Discard_Stream(uint16_t Length,
122 uint16_t* const BytesProcessed);
123
124 /** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending
125 * full packets to the host as needed. The last packet is not automatically sent once the
126 * remaining bytes have been written; the user is responsible for manually sending the last
127 * packet to the host via the \ref Endpoint_ClearIN() macro.
128 *
129 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
130 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
131 * storage location, the transfer will instead be performed as a series of chunks. Each time
132 * the endpoint bank becomes full while there is still data to process (and after the current
133 * packet transmission has been initiated) the BytesProcessed location will be updated with the
134 * total number of bytes processed in the stream, and the function will exit with an error code of
135 * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
136 * in the user code - to continue the transfer, call the function again with identical parameters
137 * and it will resume until the BytesProcessed value reaches the total transfer length.
138 *
139 * <b>Single Stream Transfer Example:</b>
140 * \code
141 * uint8_t ErrorCode;
142 *
143 * if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
144 * {
145 * // Stream failed to complete - check ErrorCode here
146 * }
147 * \endcode
148 *
149 * <b>Partial Stream Transfers Example:</b>
150 * \code
151 * uint8_t ErrorCode;
152 * uint16_t BytesProcessed;
153 *
154 * BytesProcessed = 0;
155 * while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
156 * {
157 * // Stream not yet complete - do other actions here, abort if required
158 * }
159 *
160 * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
161 * {
162 * // Stream failed to complete - check ErrorCode here
163 * }
164 * \endcode
165 *
166 * \note This routine should not be used on CONTROL type endpoints.
167 *
168 * \param[in] Length Number of zero bytes to send via the currently selected endpoint.
169 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
170 * transaction should be updated, \c NULL if the entire stream should be read at once.
171 *
172 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
173 */
174 uint8_t Endpoint_Null_Stream(uint16_t Length,
175 uint16_t* const BytesProcessed);
176
177 //@}
178
179 /** \name Stream functions for RAM source/destination data */
180 //@{
181
182 /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
183 * sending full packets to the host as needed. The last packet filled is not automatically sent;
184 * the user is responsible for manually sending the last written packet to the host via the
185 * \ref Endpoint_ClearIN() macro.
186 *
187 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
188 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
189 * storage location, the transfer will instead be performed as a series of chunks. Each time
190 * the endpoint bank becomes full while there is still data to process (and after the current
191 * packet transmission has been initiated) the BytesProcessed location will be updated with the
192 * total number of bytes processed in the stream, and the function will exit with an error code of
193 * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
194 * in the user code - to continue the transfer, call the function again with identical parameters
195 * and it will resume until the BytesProcessed value reaches the total transfer length.
196 *
197 * <b>Single Stream Transfer Example:</b>
198 * \code
199 * uint8_t DataStream[512];
200 * uint8_t ErrorCode;
201 *
202 * if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
203 * NULL)) != ENDPOINT_RWSTREAM_NoError)
204 * {
205 * // Stream failed to complete - check ErrorCode here
206 * }
207 * \endcode
208 *
209 * <b>Partial Stream Transfers Example:</b>
210 * \code
211 * uint8_t DataStream[512];
212 * uint8_t ErrorCode;
213 * uint16_t BytesProcessed;
214 *
215 * BytesProcessed = 0;
216 * while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
217 * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
218 * {
219 * // Stream not yet complete - do other actions here, abort if required
220 * }
221 *
222 * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
223 * {
224 * // Stream failed to complete - check ErrorCode here
225 * }
226 * \endcode
227 *
228 * \note This routine should not be used on CONTROL type endpoints.
229 *
230 * \param[in] Buffer Pointer to the source data buffer to read from.
231 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
232 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
233 * transaction should be updated, \c NULL if the entire stream should be written at once.
234 *
235 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
236 */
237 uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,
238 uint16_t Length,
239 uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
240
241 /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
242 * sending full packets to the host as needed. The last packet filled is not automatically sent;
243 * the user is responsible for manually sending the last written packet to the host via the
244 * \ref Endpoint_ClearIN() macro.
245 *
246 * \note This routine should not be used on CONTROL type endpoints.
247 *
248 * \param[in] Buffer Pointer to the source data buffer to read from.
249 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
250 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
251 * transaction should be updated, \c NULL if the entire stream should be written at once.
252 *
253 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
254 */
255 uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
256 uint16_t Length,
257 uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
258
259 /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
260 * discarding fully read packets from the host as needed. The last packet is not automatically
261 * discarded once the remaining bytes has been read; the user is responsible for manually
262 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
263 *
264 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
265 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
266 * storage location, the transfer will instead be performed as a series of chunks. Each time
267 * the endpoint bank becomes empty while there is still data to process (and after the current
268 * packet has been acknowledged) the BytesProcessed location will be updated with the total number
269 * of bytes processed in the stream, and the function will exit with an error code of
270 * \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
271 * in the user code - to continue the transfer, call the function again with identical parameters
272 * and it will resume until the BytesProcessed value reaches the total transfer length.
273 *
274 * <b>Single Stream Transfer Example:</b>
275 * \code
276 * uint8_t DataStream[512];
277 * uint8_t ErrorCode;
278 *
279 * if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
280 * NULL)) != ENDPOINT_RWSTREAM_NoError)
281 * {
282 * // Stream failed to complete - check ErrorCode here
283 * }
284 * \endcode
285 *
286 * <b>Partial Stream Transfers Example:</b>
287 * \code
288 * uint8_t DataStream[512];
289 * uint8_t ErrorCode;
290 * uint16_t BytesProcessed;
291 *
292 * BytesProcessed = 0;
293 * while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
294 * &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
295 * {
296 * // Stream not yet complete - do other actions here, abort if required
297 * }
298 *
299 * if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
300 * {
301 * // Stream failed to complete - check ErrorCode here
302 * }
303 * \endcode
304 *
305 * \note This routine should not be used on CONTROL type endpoints.
306 *
307 * \param[out] Buffer Pointer to the destination data buffer to write to.
308 * \param[in] Length Number of bytes to send via the currently selected endpoint.
309 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
310 * transaction should be updated, \c NULL if the entire stream should be read at once.
311 *
312 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
313 */
314 uint8_t Endpoint_Read_Stream_LE(void* const Buffer,
315 uint16_t Length,
316 uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
317
318 /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
319 * discarding fully read packets from the host as needed. The last packet is not automatically
320 * discarded once the remaining bytes has been read; the user is responsible for manually
321 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
322 *
323 * \note This routine should not be used on CONTROL type endpoints.
324 *
325 * \param[out] Buffer Pointer to the destination data buffer to write to.
326 * \param[in] Length Number of bytes to send via the currently selected endpoint.
327 * \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
328 * transaction should be updated, \c NULL if the entire stream should be read at once.
329 *
330 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
331 */
332 uint8_t Endpoint_Read_Stream_BE(void* const Buffer,
333 uint16_t Length,
334 uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
335
336 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
337 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
338 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
339 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
340 *
341 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
342 * to clear the status stage when using this routine in a control transaction.
343 * \n\n
344 *
345 * \note This routine should only be used on CONTROL type endpoints.
346 *
347 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
348 * together; i.e. the entire stream data must be read or written at the one time.
349 *
350 * \param[in] Buffer Pointer to the source data buffer to read from.
351 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
352 *
353 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
354 */
355 uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,
356 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
357
358 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
359 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
360 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
361 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
362 *
363 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
364 * to clear the status stage when using this routine in a control transaction.
365 * \n\n
366 *
367 * \note This routine should only be used on CONTROL type endpoints.
368 *
369 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
370 * together; i.e. the entire stream data must be read or written at the one time.
371 *
372 * \param[in] Buffer Pointer to the source data buffer to read from.
373 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
374 *
375 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
376 */
377 uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,
378 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
379
380 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
381 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
382 * automatically sent after success or failure states; the user is responsible for manually sending the
383 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
384 *
385 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
386 * to clear the status stage when using this routine in a control transaction.
387 * \n\n
388 *
389 * \note This routine should only be used on CONTROL type endpoints.
390 *
391 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
392 * together; i.e. the entire stream data must be read or written at the one time.
393 *
394 * \param[out] Buffer Pointer to the destination data buffer to write to.
395 * \param[in] Length Number of bytes to send via the currently selected endpoint.
396 *
397 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
398 */
399 uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,
400 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
401
402 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
403 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
404 * automatically sent after success or failure states; the user is responsible for manually sending the
405 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
406 *
407 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
408 * to clear the status stage when using this routine in a control transaction.
409 * \n\n
410 *
411 * \note This routine should only be used on CONTROL type endpoints.
412 *
413 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
414 * together; i.e. the entire stream data must be read or written at the one time.
415 *
416 * \param[out] Buffer Pointer to the destination data buffer to write to.
417 * \param[in] Length Number of bytes to send via the currently selected endpoint.
418 *
419 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
420 */
421 uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,
422 uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
423 //@}
424
425 /* Disable C linkage for C++ Compilers: */
426 #if defined(__cplusplus)
427 }
428 #endif
429
430 #endif
431
432 /** @} */
433