3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
32 * \brief Pipe data stream transmission and reception management for the AVR32 UC3 microcontrollers.
33 * \copydetails Group_PipeStreamRW_UC3
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.
39 /** \ingroup Group_PipeStreamRW
40 * \defgroup Group_PipeStreamRW_UC3 Read/Write of Multi-Byte Streams (UC3)
41 * \brief Pipe data stream transmission and reception management for the Atmel AVR32 UC3 architecture.
43 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
49 #ifndef __PIPE_STREAM_UC3_H__
50 #define __PIPE_STREAM_UC3_H__
53 #include "../../../../Common/Common.h"
54 #include "../USBMode.h"
56 /* Enable C linkage for C++ Compilers: */
57 #if defined(__cplusplus)
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.
66 /* Public Interface - May be used in end-application: */
67 /* Function Prototypes: */
68 /** \name Stream functions for null data */
71 /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
72 * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
73 * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
75 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
76 * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
77 * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
78 * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
79 * the total number of bytes processed in the stream, and the function will exit with an error code of
80 * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
81 * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
82 * value reaches the total transfer length.
84 * <b>Single Stream Transfer Example:</b>
88 * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
90 * // Stream failed to complete - check ErrorCode here
94 * <b>Partial Stream Transfers Example:</b>
97 * uint16_t BytesProcessed;
100 * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
102 * // Stream not yet complete - do other actions here, abort if required
105 * if (ErrorCode != PIPE_RWSTREAM_NoError)
107 * // Stream failed to complete - check ErrorCode here
111 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
112 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
114 * \param[in] Length Number of bytes to discard via the currently selected pipe.
115 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
116 * updated, \c NULL if the entire stream should be processed at once.
118 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
120 uint8_t Pipe_Discard_Stream(uint16_t Length
,
121 uint16_t* const BytesProcessed
);
123 /** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
124 * as needed. The last packet is not automatically sent once the remaining bytes has been written; the
125 * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.
127 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
128 * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
129 * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
130 * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
131 * updated with the total number of bytes processed in the stream, and the function will exit with an error code of
132 * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
133 * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
134 * value reaches the total transfer length.
136 * <b>Single Stream Transfer Example:</b>
140 * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
142 * // Stream failed to complete - check ErrorCode here
146 * <b>Partial Stream Transfers Example:</b>
149 * uint16_t BytesProcessed;
151 * BytesProcessed = 0;
152 * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
154 * // Stream not yet complete - do other actions here, abort if required
157 * if (ErrorCode != PIPE_RWSTREAM_NoError)
159 * // Stream failed to complete - check ErrorCode here
163 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
164 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
166 * \param[in] Length Number of zero bytes to write via the currently selected pipe.
167 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
168 * updated, \c NULL if the entire stream should be processed at once.
170 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
172 uint8_t Pipe_Null_Stream(uint16_t Length
,
173 uint16_t* const BytesProcessed
);
177 /** \name Stream functions for RAM source/destination data */
180 /** Writes the given number of bytes to the pipe from the given buffer in little endian,
181 * sending full packets to the device as needed. The last packet filled is not automatically sent;
182 * the user is responsible for manually sending the last written packet to the host via the
183 * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
184 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
186 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
187 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
188 * storage location, the transfer will instead be performed as a series of chunks. Each time
189 * the pipe bank becomes full while there is still data to process (and after the current
190 * packet transmission has been initiated) the BytesProcessed location will be updated with the
191 * total number of bytes processed in the stream, and the function will exit with an error code of
192 * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
193 * in the user code - to continue the transfer, call the function again with identical parameters
194 * and it will resume until the BytesProcessed value reaches the total transfer length.
196 * <b>Single Stream Transfer Example:</b>
198 * uint8_t DataStream[512];
201 * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
202 * NULL)) != PIPE_RWSTREAM_NoError)
204 * // Stream failed to complete - check ErrorCode here
208 * <b>Partial Stream Transfers Example:</b>
210 * uint8_t DataStream[512];
212 * uint16_t BytesProcessed;
214 * BytesProcessed = 0;
215 * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
216 * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
218 * // Stream not yet complete - do other actions here, abort if required
221 * if (ErrorCode != PIPE_RWSTREAM_NoError)
223 * // Stream failed to complete - check ErrorCode here
227 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
228 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
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 pipe into the buffer.
232 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
233 * updated, \c NULL if the entire stream should be written at once.
235 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
237 uint8_t Pipe_Write_Stream_LE(const void* const Buffer
,
239 uint16_t* const BytesProcessed
) ATTR_NON_NULL_PTR_ARG(1);
241 /** Writes the given number of bytes to the pipe from the given buffer in big endian,
242 * sending full packets to the device 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 Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
245 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
247 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
248 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
250 * \param[in] Buffer Pointer to the source data buffer to read from.
251 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
252 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
253 * updated, \c NULL if the entire stream should be written at once.
255 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
257 uint8_t Pipe_Write_Stream_BE(const void* const Buffer
,
259 uint16_t* const BytesProcessed
) ATTR_NON_NULL_PTR_ARG(1);
261 /** Reads the given number of bytes from the pipe into the given buffer in little endian,
262 * sending full packets to the device as needed. The last packet filled is not automatically sent;
263 * the user is responsible for manually sending the last written packet to the host via the
264 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
265 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
267 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
268 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
269 * storage location, the transfer will instead be performed as a series of chunks. Each time
270 * the pipe bank becomes empty while there is still data to process (and after the current
271 * packet has been acknowledged) the BytesProcessed location will be updated with the total number
272 * of bytes processed in the stream, and the function will exit with an error code of
273 * \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
274 * in the user code - to continue the transfer, call the function again with identical parameters
275 * and it will resume until the BytesProcessed value reaches the total transfer length.
277 * <b>Single Stream Transfer Example:</b>
279 * uint8_t DataStream[512];
282 * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
283 * NULL)) != PIPE_RWSTREAM_NoError)
285 * // Stream failed to complete - check ErrorCode here
289 * <b>Partial Stream Transfers Example:</b>
291 * uint8_t DataStream[512];
293 * uint16_t BytesProcessed;
295 * BytesProcessed = 0;
296 * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
297 * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
299 * // Stream not yet complete - do other actions here, abort if required
302 * if (ErrorCode != PIPE_RWSTREAM_NoError)
304 * // Stream failed to complete - check ErrorCode here
308 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
309 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
311 * \param[out] Buffer Pointer to the source data buffer to write to.
312 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
313 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
314 * updated, \c NULL if the entire stream should be read at once.
316 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
318 uint8_t Pipe_Read_Stream_LE(void* const Buffer
,
320 uint16_t* const BytesProcessed
) ATTR_NON_NULL_PTR_ARG(1);
322 /** Reads the given number of bytes from the pipe into the given buffer in big endian,
323 * sending full packets to the device as needed. The last packet filled is not automatically sent;
324 * the user is responsible for manually sending the last written packet to the host via the
325 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
326 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
328 * \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
329 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
331 * \param[out] Buffer Pointer to the source data buffer to write to.
332 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
333 * \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
334 * updated, \c NULL if the entire stream should be read at once.
336 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
338 uint8_t Pipe_Read_Stream_BE(void* const Buffer
,
340 uint16_t* const BytesProcessed
) ATTR_NON_NULL_PTR_ARG(1);
343 /* Disable C linkage for C++ Compilers: */
344 #if defined(__cplusplus)