2 * @brief Pipe data stream transmission and reception management
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 /** @ingroup Group_PipeRW
\r
34 * @defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
\r
35 * @brief Pipe data stream transmission and reception management.
\r
37 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
\r
43 #ifndef __PIPE_STREAM_H__
\r
44 #define __PIPE_STREAM_H__
\r
47 #include "../../../Common/Common.h"
\r
48 #include "USBMode.h"
\r
50 /* Enable C linkage for C++ Compilers: */
\r
51 #if defined(__cplusplus)
\r
55 /* Preprocessor Checks: */
\r
56 #if !defined(__INCLUDE_FROM_USB_DRIVER)
\r
57 #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
\r
60 /* Public Interface - May be used in end-application: */
\r
62 /** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */
\r
63 enum Pipe_Stream_RW_ErrorCodes_t
\r
65 PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
\r
66 PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
\r
67 PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
\r
70 PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
\r
71 * within the software timeout period set by the
\r
72 * @ref USB_STREAM_TIMEOUT_MS macro.
\r
74 PIPE_RWSTREAM_IncompleteTransfer = 4, /**< Indicates that the pipe bank became full/empty before the
\r
75 * complete contents of the stream could be transferred.
\r
79 #include "USBTask.h"
\r
80 /* Function Prototypes: */
\r
81 /** \name Stream functions for null data */
\r
84 * @brief Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
\r
85 * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
\r
86 * user is responsible for manually discarding the last packet from the device via the @ref Pipe_ClearIN() macro.
\r
88 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
\r
89 * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
\r
90 * will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
\r
91 * to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
\r
92 * the total number of bytes processed in the stream, and the function will exit with an error code of
\r
93 * @ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
\r
94 * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
\r
95 * value reaches the total transfer length.
\r
97 * <b>Single Stream Transfer Example:</b>
\r
99 * uint8_t ErrorCode;
\r
101 * if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
\r
103 * // Stream failed to complete - check ErrorCode here
\r
107 * <b>Partial Stream Transfers Example:</b>
\r
109 * uint8_t ErrorCode;
\r
110 * uint16_t BytesProcessed;
\r
112 * BytesProcessed = 0;
\r
113 * while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
\r
115 * // Stream not yet complete - do other actions here, abort if required
\r
118 * if (ErrorCode != PIPE_RWSTREAM_NoError)
\r
120 * // Stream failed to complete - check ErrorCode here
\r
124 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
125 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
127 * @param corenum : USB port number
\r
128 * @param Length : Number of bytes to discard via the currently selected pipe
\r
129 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
130 * updated, \c NULL if the entire stream should be processed at once.
\r
131 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
134 uint8_t Pipe_Discard_Stream(const uint8_t corenum,
\r
136 uint16_t *const BytesProcessed) /*ATTR_DEPRECATED*/;
\r
139 * @brief Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
\r
140 * as needed. The last packet is not automatically sent once the remaining bytes has been written; the
\r
141 * user is responsible for manually discarding the last packet from the device via the @ref Pipe_ClearOUT() macro.
\r
143 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
\r
144 * succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
\r
145 * will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
\r
146 * to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
\r
147 * updated with the total number of bytes processed in the stream, and the function will exit with an error code of
\r
148 * @ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
\r
149 * continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
\r
150 * value reaches the total transfer length.
\r
152 * <b>Single Stream Transfer Example:</b>
\r
154 * uint8_t ErrorCode;
\r
156 * if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
\r
158 * // Stream failed to complete - check ErrorCode here
\r
162 * <b>Partial Stream Transfers Example:</b>
\r
164 * uint8_t ErrorCode;
\r
165 * uint16_t BytesProcessed;
\r
167 * BytesProcessed = 0;
\r
168 * while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
\r
170 * // Stream not yet complete - do other actions here, abort if required
\r
173 * if (ErrorCode != PIPE_RWSTREAM_NoError)
\r
175 * // Stream failed to complete - check ErrorCode here
\r
179 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
180 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
182 * @param corenum : USB port number
\r
183 * @param Length : Number of zero bytes to write via the currently selected pipe
\r
184 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
185 * updated, \c NULL if the entire stream should be processed at once.
\r
186 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
188 uint8_t Pipe_Null_Stream(const uint8_t corenum,
\r
190 uint16_t *const BytesProcessed);
\r
194 /** \name Stream functions for RAM source/destination data */
\r
197 * @brief Writes the given number of bytes to the pipe from the given buffer in little endian,
\r
198 * sending full packets to the device as needed. The last packet filled is not automatically sent;
\r
199 * the user is responsible for manually sending the last written packet to the host via the
\r
200 * @ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
\r
201 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
\r
203 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
\r
204 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
\r
205 * storage location, the transfer will instead be performed as a series of chunks. Each time
\r
206 * the pipe bank becomes full while there is still data to process (and after the current
\r
207 * packet transmission has been initiated) the BytesProcessed location will be updated with the
\r
208 * total number of bytes processed in the stream, and the function will exit with an error code of
\r
209 * @ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
\r
210 * in the user code - to continue the transfer, call the function again with identical parameters
\r
211 * and it will resume until the BytesProcessed value reaches the total transfer length.
\r
213 * <b>Single Stream Transfer Example:</b>
\r
215 * uint8_t DataStream[512];
\r
216 * uint8_t ErrorCode;
\r
218 * if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
\r
219 * NULL)) != PIPE_RWSTREAM_NoError)
\r
221 * // Stream failed to complete - check ErrorCode here
\r
225 * <b>Partial Stream Transfers Example:</b>
\r
227 * uint8_t DataStream[512];
\r
228 * uint8_t ErrorCode;
\r
229 * uint16_t BytesProcessed;
\r
231 * BytesProcessed = 0;
\r
232 * while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
\r
233 * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
\r
235 * // Stream not yet complete - do other actions here, abort if required
\r
238 * if (ErrorCode != PIPE_RWSTREAM_NoError)
\r
240 * // Stream failed to complete - check ErrorCode here
\r
244 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
245 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
247 * @param corenum : USB port number
\r
248 * @param Buffer : Pointer to the source data buffer to read from
\r
249 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
250 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
251 * updated, \c NULL if the entire stream should be written at once.
\r
252 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
254 uint8_t Pipe_Write_Stream_LE(const uint8_t corenum,
\r
255 const void *const Buffer,
\r
257 uint16_t *const BytesProcessed);
\r
260 * @brief Writes the given number of bytes to the pipe from the given buffer in big endian,
\r
261 * sending full packets to the device as needed. The last packet filled is not automatically sent;
\r
262 * the user is responsible for manually sending the last written packet to the host via the
\r
263 * @ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
\r
264 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
\r
266 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
267 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
269 * @param Buffer : Pointer to the source data buffer to read from
\r
270 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
271 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
272 * updated, \c NULL if the entire stream should be written at once.
\r
273 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
275 uint8_t Pipe_Write_Stream_BE(const void *const Buffer,
\r
277 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
278 "Function is not implemented yet");
\r
281 * @brief Reads the given number of bytes from the pipe into the given buffer in little endian,
\r
282 * sending full packets to the device as needed. The last packet filled is not automatically sent;
\r
283 * the user is responsible for manually sending the last written packet to the host via the
\r
284 * @ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
\r
285 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
\r
287 * If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
\r
288 * failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
\r
289 * storage location, the transfer will instead be performed as a series of chunks. Each time
\r
290 * the pipe bank becomes empty while there is still data to process (and after the current
\r
291 * packet has been acknowledged) the BytesProcessed location will be updated with the total number
\r
292 * of bytes processed in the stream, and the function will exit with an error code of
\r
293 * @ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
\r
294 * in the user code - to continue the transfer, call the function again with identical parameters
\r
295 * and it will resume until the BytesProcessed value reaches the total transfer length.
\r
297 * <b>Single Stream Transfer Example:</b>
\r
299 * uint8_t DataStream[512];
\r
300 * uint8_t ErrorCode;
\r
302 * if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
\r
303 * NULL)) != PIPE_RWSTREAM_NoError)
\r
305 * // Stream failed to complete - check ErrorCode here
\r
309 * <b>Partial Stream Transfers Example:</b>
\r
311 * uint8_t DataStream[512];
\r
312 * uint8_t ErrorCode;
\r
313 * uint16_t BytesProcessed;
\r
315 * BytesProcessed = 0;
\r
316 * while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
\r
317 * &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
\r
319 * // Stream not yet complete - do other actions here, abort if required
\r
322 * if (ErrorCode != PIPE_RWSTREAM_NoError)
\r
324 * // Stream failed to complete - check ErrorCode here
\r
328 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
329 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
331 * @param corenum : USB port number
\r
332 * @param Buffer : Pointer to the source data buffer to write to
\r
333 * @param Length : Number of bytes to read for the currently selected pipe to read from
\r
334 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
335 * updated, \c NULL if the entire stream should be read at once.
\r
336 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
338 uint8_t Pipe_Read_Stream_LE(const uint8_t corenum,
\r
339 void *const Buffer,
\r
341 uint16_t *const BytesProcessed);
\r
344 * @brief Reads the given number of bytes from the pipe into the given buffer in big endian,
\r
345 * sending full packets to the device as needed. The last packet filled is not automatically sent;
\r
346 * the user is responsible for manually sending the last written packet to the host via the
\r
347 * @ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
\r
348 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
\r
350 * @note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
\r
351 * having to explicitly change the data direction with a call to @ref Pipe_SetPipeToken().
\r
353 * @param Buffer : Pointer to the source data buffer to write to
\r
354 * @param Length : Number of bytes to read for the currently selected pipe to read from
\r
355 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
356 * updated, \c NULL if the entire stream should be read at once.
\r
357 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
359 uint8_t Pipe_Read_Stream_BE(void *const Buffer,
\r
361 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
362 "Function is not implemented yet");
\r
365 /** \name Stream functions for EEPROM source/destination data */
\r
368 * @brief Pipe Write EEPROM Stream Little Endian
\r
369 * @param Buffer : Pointer to the source data buffer to read from
\r
370 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
371 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
372 * updated, \c NULL if the entire stream should be written at once.
\r
373 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
375 uint8_t Pipe_Write_EStream_LE(const void *const Buffer,
\r
377 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
378 "Function is not implemented yet");
\r
381 * @brief Pipe Write EEPROM Stream Big Endian
\r
382 * @param Buffer : Pointer to the source data buffer to read from
\r
383 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
384 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
385 * updated, \c NULL if the entire stream should be written at once.
\r
386 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
388 uint8_t Pipe_Write_EStream_BE(const void *const Buffer,
\r
390 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
391 "Function is not implemented yet");
\r
394 * @brief Pipe Read EEPROM Stream Little Endian
\r
395 * @param Buffer : Pointer to the source data buffer to write to
\r
396 * @param Length : Number of bytes to read for the currently selected pipe to read from
\r
397 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
398 * updated, \c NULL if the entire stream should be read at once.
\r
399 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
401 uint8_t Pipe_Read_EStream_LE(void *const Buffer,
\r
403 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
404 "Function is not implemented yet");
\r
407 * @brief Pipe Read EEPROM Stream Big Endian
\r
408 * @param Buffer : Pointer to the source data buffer to write to
\r
409 * @param Length : Number of bytes to read for the currently selected pipe to read from
\r
410 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
411 * updated, \c NULL if the entire stream should be read at once.
\r
412 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
414 uint8_t Pipe_Read_EStream_BE(void *const Buffer,
\r
416 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
417 "Function is not implemented yet");
\r
421 /** \name Stream functions for PROGMEM source/destination data */
\r
424 * @brief Pipe Write FLASH Stream Little Endian
\r
425 * @param Buffer : Pointer to the source data buffer to read from
\r
426 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
427 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
428 * updated, \c NULL if the entire stream should be written at once.
\r
429 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
431 uint8_t Pipe_Write_PStream_LE(const void *const Buffer,
\r
433 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
434 "Function is not implemented yet");
\r
437 * @brief Pipe Write FLASH Stream Big Endian
\r
438 * @param Buffer : Pointer to the source data buffer to read from
\r
439 * @param Length : Number of bytes to read for the currently selected pipe into the buffer
\r
440 * @param BytesProcessed : Pointer to a location where the total number of bytes already processed should
\r
441 * updated, \c NULL if the entire stream should be written at once.
\r
442 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
444 uint8_t Pipe_Write_PStream_BE(const void *const Buffer,
\r
446 uint16_t *const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1) ATTR_ERROR(
\r
447 "Function is not implemented yet");
\r
450 * @brief Transfer a stream of data to/from USB bus
\r
451 * @param corenum : streaming USB core number
\r
452 * @param buffer : Pointer to the data buffer to read from or write to
\r
453 * @param transferlength : Number of bytes to transfer
\r
454 * @param packetsize : Size in byte of each packet in stream
\r
455 * @return A value from the @ref Pipe_Stream_RW_ErrorCodes_t enum
\r
457 uint8_t Pipe_Streaming(uint8_t corenum, uint8_t* const buffer, uint32_t const transferlength, uint16_t const packetsize);
\r
461 /* Disable C linkage for C++ Compilers: */
\r
462 #if defined(__cplusplus)
\r