Start porting the USB core to the AVR32 UC3B.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Pipe.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 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 /** \ingroup Group_USB
32 * @defgroup Group_PipeManagement Pipe Management
33 *
34 * This module contains functions, macros and enums related to pipe management when in USB Host mode. This
35 * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
36 * for various data types.
37 *
38 * @{
39 */
40
41 /** @defgroup Group_PipeRW Pipe Data Reading and Writing
42 *
43 * Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
44 */
45
46 /** \ingroup Group_PipeRW
47 * @defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types
48 *
49 * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
50 * from and to pipes.
51 */
52
53 /** \ingroup Group_PipeRW
54 * @defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
55 *
56 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
57 * and to pipes.
58 */
59
60 /** @defgroup Group_PipePacketManagement Pipe Packet Management
61 *
62 * Functions, macros, variables, enums and types related to packet management of pipes.
63 */
64
65 /** @defgroup Group_PipeControlReq Pipe Control Request Management
66 *
67 * Module for host mode request processing. This module allows for the transmission of standard, class and
68 * vendor control requests to the default control endpoint of an attached device while in host mode.
69 *
70 * \see Chapter 9 of the USB 2.0 specification.
71 */
72
73 #ifndef __PIPE_H__
74 #define __PIPE_H__
75
76 /* Includes: */
77 #if defined(__AVR32__)
78 #include <avr32/io.h>
79 #include <stdint.h>
80 #include <stdbool.h>
81 #elif defined(__AVR__)
82 #include <avr/io.h>
83 #include <avr/pgmspace.h>
84 #include <avr/eeprom.h>
85 #include <stdbool.h>
86 #endif
87
88 #include "../../../Common/Common.h"
89 #include "../HighLevel/USBTask.h"
90
91 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
92 #include "../HighLevel/StreamCallbacks.h"
93 #endif
94
95 /* Enable C linkage for C++ Compilers: */
96 #if defined(__cplusplus)
97 extern "C" {
98 #endif
99
100 /* Preprocessor Checks: */
101 #if !defined(__INCLUDE_FROM_USB_DRIVER)
102 #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
103 #endif
104
105 /* Public Interface - May be used in end-application: */
106 /* Macros: */
107 /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
108 #define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
109
110 /** Mask for \ref Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data. */
111 #define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
112
113 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
114 #define PIPE_ERRORFLAG_CRC16 (1 << 4)
115
116 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
117 #define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
118
119 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
120 #define PIPE_ERRORFLAG_PID (1 << 2)
121
122 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
123 #define PIPE_ERRORFLAG_DATAPID (1 << 1)
124
125 /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
126 #define PIPE_ERRORFLAG_DATATGL (1 << 0)
127
128 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
129 * which will trigger a control request on the attached device when data is written to the pipe.
130 */
131 #define PIPE_TOKEN_SETUP (0 << PTOKEN0)
132
133 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
134 * indicating that the pipe data will flow from device to host.
135 */
136 #define PIPE_TOKEN_IN (1 << PTOKEN0)
137
138 /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
139 * indicating that the pipe data will flow from host to device.
140 */
141 #define PIPE_TOKEN_OUT (2 << PTOKEN0)
142
143 /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
144 * should have one single bank, which requires less USB FIFO memory but results in slower transfers as
145 * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
146 */
147 #define PIPE_BANK_SINGLE (0 << EPBK0)
148
149 /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
150 * should have two banks, which requires more USB FIFO memory but results in faster transfers as one
151 * USB device (the AVR or the attached device) can access one bank while the other accesses the second
152 * bank.
153 */
154 #define PIPE_BANK_DOUBLE (1 << EPBK0)
155
156 /** Pipe address for the default control pipe, which always resides in address 0. This is
157 * defined for convenience to give more readable code when used with the pipe macros.
158 */
159 #define PIPE_CONTROLPIPE 0
160
161 /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value
162 * in the device descriptor of the attached device.
163 */
164 #define PIPE_CONTROLPIPE_DEFAULT_SIZE 64
165
166 /** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address
167 * in the device.
168 */
169 #define PIPE_PIPENUM_MASK 0x07
170
171 /** Total number of pipes (including the default control pipe at address 0) which may be used in
172 * the device. Different USB AVR models support different amounts of pipes, this value reflects
173 * the maximum number of pipes for the currently selected AVR model.
174 */
175 #define PIPE_TOTAL_PIPES 7
176
177 /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
178 * model supports the largest bank size possible on the device; different pipe numbers support
179 * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
180 * currently selected USB AVR model.
181 */
182 #define PIPE_MAX_SIZE 256
183
184 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
185 * numerical address in the attached device.
186 */
187 #define PIPE_EPNUM_MASK 0x0F
188
189 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
190 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
191 */
192 #define PIPE_EPDIR_MASK 0x80
193
194 /* Pseudo-Function Macros: */
195 #if defined(__DOXYGEN__)
196 /** Indicates the number of bytes currently stored in the current pipes's selected bank.
197 *
198 * \note The return width of this function may differ, depending on the maximum pipe bank size
199 * of the selected AVR model.
200 *
201 * \ingroup Group_PipeRW
202 *
203 * \return Total number of bytes in the currently selected Pipe's FIFO buffer
204 */
205 static inline uint16_t Pipe_BytesInPipe(void);
206
207 /** Returns the pipe address of the currently selected pipe. This is typically used to save the
208 * currently selected pipe number so that it can be restored after another pipe has been manipulated.
209 *
210 * \return Index of the currently selected pipe
211 */
212 static inline uint8_t Pipe_GetCurrentPipe(void);
213
214 /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
215 * indicated will operate on the currently selected pipe.
216 *
217 * \param[in] PipeNumber Index of the pipe to select
218 */
219 static inline void Pipe_SelectPipe(uint8_t PipeNumber);
220
221 /** Resets the desired pipe, including the pipe banks and flags.
222 *
223 * \param[in] PipeNumber Index of the pipe to reset
224 */
225 static inline void Pipe_ResetPipe(uint8_t PipeNumber);
226
227 /** Enables the currently selected pipe so that data can be sent and received through it to and from
228 * an attached device.
229 *
230 * \note Pipes must first be configured properly via \ref Pipe_ConfigurePipe().
231 */
232 static inline void Pipe_EnablePipe(void);
233
234 /** Disables the currently selected pipe so that data cannot be sent and received through it to and
235 * from an attached device.
236 */
237 static inline void Pipe_DisablePipe(void);
238
239 /** Determines if the currently selected pipe is enabled, but not necessarily configured.
240 *
241 * \return Boolean True if the currently selected pipe is enabled, false otherwise
242 */
243 static inline bool Pipe_IsEnabled(void);
244
245 /** Gets the current pipe token, indicating the pipe's data direction and type.
246 *
247 * \return The current pipe token, as a PIPE_TOKEN_* mask
248 */
249 static inline uint8_t Pipe_GetPipeToken(void);
250
251 /** Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_*
252 * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during
253 * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices
254 * which have two endpoints of opposite direction sharing the same endpoint address within the device.
255 *
256 * \param[in] Token New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask
257 */
258 static inline void Pipe_SetPipeToken(uint8_t Token);
259
260 /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
261 static inline void Pipe_SetInfiniteINRequests(void);
262
263 /** Configures the currently selected pipe to only allow the specified number of IN requests to be
264 * accepted by the pipe before it is automatically frozen.
265 *
266 * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing
267 */
268 static inline void Pipe_SetFiniteINRequests(uint8_t TotalINRequests);
269
270 /** Determines if the currently selected pipe is configured.
271 *
272 * \return Boolean true if the selected pipe is configured, false otherwise
273 */
274 static inline bool Pipe_IsConfigured(void);
275
276 /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected
277 * pipe is bound to.
278 *
279 * \return Endpoint number the currently selected pipe is bound to
280 */
281 static inline uint8_t Pipe_BoundEndpointNumber(void);
282
283 /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
284 *
285 * \param[in] Milliseconds Number of milliseconds between each pipe poll
286 */
287 static inline void Pipe_SetInterruptPeriod(uint8_t Milliseconds);
288
289 /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
290 * be serviced.
291 *
292 * \return Mask whose bits indicate which pipes have interrupted
293 */
294 static inline uint8_t Pipe_GetPipeInterrupts(void);
295
296 /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
297 * pipes).
298 *
299 * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested
300 *
301 * \return Boolean true if the specified pipe has interrupted, false otherwise
302 */
303 static inline bool Pipe_HasPipeInterrupted(uint8_t PipeNumber);
304
305 /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
306 static inline void Pipe_Unfreeze(void);
307
308 /** Freezes the selected pipe, preventing it from communicating with an attached device. */
309 static inline void Pipe_Freeze(void);
310
311 /** Determines if the currently selected pipe is frozen, and not able to accept data.
312 *
313 * \return Boolean true if the currently selected pipe is frozen, false otherwise
314 */
315 static inline bool Pipe_IsFrozen(void);
316
317 /** Clears the master pipe error flag. */
318 static inline void Pipe_ClearError(void);
319
320 /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that
321 * some sort of hardware error has occurred on the pipe.
322 *
323 * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
324 *
325 * \return Boolean true if an error has occurred on the selected pipe, false otherwise
326 */
327 static inline bool Pipe_IsError(void);
328
329 /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error
330 * flag for the pipe.
331 */
332 static inline void Pipe_ClearErrorFlags(void);
333
334 /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This
335 * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred.
336 *
337 * \return Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe
338 */
339 static inline uint8_t Pipe_GetErrorFlags(void);
340
341 /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe
342 * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT
343 * direction). This function will return false if an error has occurred in the pipe, or if the pipe
344 * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
345 * direction and the pipe bank is full.
346 *
347 * \note This function is not valid on CONTROL type pipes.
348 *
349 * \ingroup Group_PipePacketManagement
350 *
351 * \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction
352 */
353 static inline bool Pipe_IsReadWriteAllowed(void);
354
355 /** Determines if an IN request has been received on the currently selected pipe.
356 *
357 * \ingroup Group_PipePacketManagement
358 *
359 * \return Boolean true if the current pipe has received an IN packet, false otherwise.
360 */
361 static inline bool Pipe_IsINReceived(void);
362
363 /** Determines if the currently selected pipe is ready to send an OUT request.
364 *
365 * \ingroup Group_PipePacketManagement
366 *
367 * \return Boolean true if the current pipe is ready for an OUT packet, false otherwise.
368 */
369 static inline bool Pipe_IsOUTReady(void);
370
371 /** Determines if no SETUP request is currently being sent to the attached device on the selected
372 * CONTROL type pipe.
373 *
374 * \ingroup Group_PipePacketManagement
375 *
376 * \return Boolean true if the current pipe is ready for a SETUP packet, false otherwise.
377 */
378 static inline bool Pipe_IsSETUPSent(void);
379
380 /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
381 *
382 * \ingroup Group_PipePacketManagement
383 */
384 static inline void Pipe_ClearSETUP(void);
385
386 /** Acknowledges the reception of a setup IN request from the attached device on the currently selected
387 * pipe, freeing the bank ready for the next packet.
388 *
389 * \ingroup Group_PipePacketManagement
390 */
391 static inline void Pipe_ClearIN(void);
392
393 /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
394 * the bank ready for the next packet.
395 *
396 * \ingroup Group_PipePacketManagement
397 */
398 static inline void Pipe_ClearOUT(void);
399
400 /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
401 * the currently selected pipe. This occurs when the host sends a packet to the device, but the device
402 * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
403 * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
404 * can be re-sent.
405 *
406 * \ingroup Group_PipePacketManagement
407 *
408 * \return Boolean true if an NAK has been received on the current pipe, false otherwise
409 */
410 static inline bool Pipe_IsNAKReceived(void);
411
412 /** Clears the NAK condition on the currently selected pipe.
413 *
414 * \ingroup Group_PipePacketManagement
415 *
416 * \see \ref Pipe_IsNAKReceived() for more details.
417 */
418 static inline void Pipe_ClearNAKReceived(void);
419
420 /** Determines if the currently selected pipe has had the STALL condition set by the attached device.
421 *
422 * \ingroup Group_PipePacketManagement
423 *
424 * \return Boolean true if the current pipe has been stalled by the attached device, false otherwise
425 */
426 static inline bool Pipe_IsStalled(void);
427
428 /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the
429 * STALL condition itself (this must be done via a ClearFeature control request to the device).
430 *
431 * \ingroup Group_PipePacketManagement
432 */
433 static inline void Pipe_ClearStall(void);
434 #else
435 #define Pipe_BytesInPipe() UPBCX
436
437 #define Pipe_GetCurrentPipe() (UPNUM & PIPE_PIPENUM_MASK)
438
439 #define Pipe_SelectPipe(pipenum) MACROS{ UPNUM = (pipenum); }MACROE
440
441 #define Pipe_ResetPipe(pipenum) MACROS{ UPRST = (1 << (pipenum)); UPRST = 0; }MACROE
442
443 #define Pipe_EnablePipe() MACROS{ UPCONX |= (1 << PEN); }MACROE
444
445 #define Pipe_DisablePipe() MACROS{ UPCONX &= ~(1 << PEN); }MACROE
446
447 #define Pipe_IsEnabled() ((UPCONX & (1 << PEN)) ? true : false)
448
449 #define Pipe_GetPipeToken() (UPCFG0X & PIPE_TOKEN_MASK)
450
451 #define Pipe_SetPipeToken(token) MACROS{ UPCFG0X = ((UPCFG0X & ~PIPE_TOKEN_MASK) | (token)); }MACROE
452
453 #define Pipe_SetInfiniteINRequests() MACROS{ UPCONX |= (1 << INMODE); }MACROE
454
455 #define Pipe_SetFiniteINRequests(n) MACROS{ UPCONX &= ~(1 << INMODE); UPINRQX = (n); }MACROE
456
457 #define Pipe_IsConfigured() ((UPSTAX & (1 << CFGOK)) ? true : false)
458
459 #define Pipe_BoundEndpointNumber() ((UPCFG0X >> PEPNUM0) & PIPE_EPNUM_MASK)
460
461 #define Pipe_SetInterruptPeriod(ms) MACROS{ UPCFG2X = (ms); }MACROE
462
463 #define Pipe_GetPipeInterrupts() UPINT
464
465 #define Pipe_HasPipeInterrupted(n) ((UPINT & (1 << (n))) ? true : false)
466
467 #define Pipe_Unfreeze() MACROS{ UPCONX &= ~(1 << PFREEZE); }MACROE
468
469 #define Pipe_Freeze() MACROS{ UPCONX |= (1 << PFREEZE); }MACROE
470
471 #define Pipe_IsFrozen() ((UPCONX & (1 << PFREEZE)) ? true : false)
472
473 #define Pipe_ClearError() MACROS{ UPINTX &= ~(1 << PERRI); }MACROE
474
475 #define Pipe_IsError() ((UPINTX & (1 << PERRI)) ? true : false)
476
477 #define Pipe_ClearErrorFlags() MACROS{ UPERRX = 0; }MACROE
478
479 #define Pipe_GetErrorFlags() ((UPERRX & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT | \
480 PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID | \
481 PIPE_ERRORFLAG_DATATGL)) | \
482 (UPSTAX & PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW))
483
484 #define Pipe_IsReadWriteAllowed() ((UPINTX & (1 << RWAL)) ? true : false)
485
486 #define Pipe_IsINReceived() ((UPINTX & (1 << RXINI)) ? true : false)
487
488 #define Pipe_IsOUTReady() ((UPINTX & (1 << TXOUTI)) ? true : false)
489
490 #define Pipe_IsSETUPSent() ((UPINTX & (1 << TXSTPI)) ? true : false)
491
492 #define Pipe_ClearIN() MACROS{ uint8_t Temp = UPINTX; UPINTX = (Temp & ~(1 << RXINI)); \
493 UPINTX = (Temp & ~(1 << FIFOCON)); }MACROE
494
495 #define Pipe_ClearOUT() MACROS{ uint8_t Temp = UPINTX; UPINTX = (Temp & ~(1 << TXOUTI)); \
496 UPINTX = (Temp & ~(1 << FIFOCON)); }MACROE
497
498 #define Pipe_ClearSETUP() MACROS{ uint8_t Temp = UPINTX; UPINTX = (Temp & ~(1 << TXSTPI)); \
499 UPINTX = (Temp & ~(1 << FIFOCON)); }MACROE
500
501 #define Pipe_IsNAKReceived() ((UPINTX & (1 << NAKEDI)) ? true : false)
502
503 #define Pipe_ClearNAKReceived() MACROS{ UPINTX &= ~(1 << NAKEDI); }MACROE
504
505 #define Pipe_IsStalled() ((UPINTX & (1 << RXSTALLI)) ? true : false)
506
507 #define Pipe_ClearStall() MACROS{ UPINTX &= ~(1 << RXSTALLI); }MACROE
508 #endif
509
510 /* Enums: */
511 /** Enum for the possible error return codes of the Pipe_WaitUntilReady function
512 *
513 * \ingroup Group_PipeRW
514 */
515 enum Pipe_WaitUntilReady_ErrorCodes_t
516 {
517 PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error */
518 PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */
519 PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */
520 PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet
521 * within the software timeout period set by the
522 * \ref USB_STREAM_TIMEOUT_MS macro.
523 */
524 };
525
526 /** Enum for the possible error return codes of the Pipe_*_Stream_* functions.
527 *
528 * \ingroup Group_PipeRW
529 */
530 enum Pipe_Stream_RW_ErrorCodes_t
531 {
532 PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
533 PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
534 PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
535 * the transfer.
536 */
537 PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
538 * within the software timeout period set by the
539 * \ref USB_STREAM_TIMEOUT_MS macro.
540 */
541 PIPE_RWSTREAM_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted
542 * the transfer early.
543 */
544 };
545
546 /* Inline Functions: */
547 /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
548 *
549 * \ingroup Group_PipePrimitiveRW
550 *
551 * \return Next byte in the currently selected pipe's FIFO buffer
552 */
553 static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
554 static inline uint8_t Pipe_Read_Byte(void)
555 {
556 #if defined(__AVR32__)
557 return 0; // TODO
558 #elif defined(__AVR__)
559 return UPDATX;
560 #endif
561 }
562
563 /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.
564 *
565 * \ingroup Group_PipePrimitiveRW
566 *
567 * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer
568 */
569 static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
570 static inline void Pipe_Write_Byte(const uint8_t Byte)
571 {
572 #if defined(__AVR32__)
573 // TODO
574 #elif defined(__AVR__)
575 UPDATX = Byte;
576 #endif
577 }
578
579 /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
580 *
581 * \ingroup Group_PipePrimitiveRW
582 */
583 static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;
584 static inline void Pipe_Discard_Byte(void)
585 {
586 uint8_t Dummy;
587
588 #if defined(__AVR32__)
589 // TODO
590 #elif defined(__AVR__)
591 Dummy = UPDATX;
592 #endif
593 }
594
595 /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT
596 * direction pipes.
597 *
598 * \ingroup Group_PipePrimitiveRW
599 *
600 * \return Next word in the currently selected pipe's FIFO buffer
601 */
602 static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
603 static inline uint16_t Pipe_Read_Word_LE(void)
604 {
605 union
606 {
607 uint16_t Word;
608 uint8_t Bytes[2];
609 } Data;
610
611 #if defined(__AVR32__)
612 // TODO
613 #elif defined(__AVR__)
614 Data.Bytes[0] = UPDATX;
615 Data.Bytes[1] = UPDATX;
616 #endif
617
618 return Data.Word;
619 }
620
621 /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
622 * direction pipes.
623 *
624 * \ingroup Group_PipePrimitiveRW
625 *
626 * \return Next word in the currently selected pipe's FIFO buffer
627 */
628 static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
629 static inline uint16_t Pipe_Read_Word_BE(void)
630 {
631 union
632 {
633 uint16_t Word;
634 uint8_t Bytes[2];
635 } Data;
636
637 #if defined(__AVR32__)
638 // TODO
639 #elif defined(__AVR__)
640 Data.Bytes[1] = UPDATX;
641 Data.Bytes[0] = UPDATX;
642 #endif
643
644 return Data.Word;
645 }
646
647 /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN
648 * direction pipes.
649 *
650 * \ingroup Group_PipePrimitiveRW
651 *
652 * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
653 */
654 static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
655 static inline void Pipe_Write_Word_LE(const uint16_t Word)
656 {
657 #if defined(__AVR32__)
658 // TODO
659 #elif defined(__AVR__)
660 UPDATX = (Word & 0xFF);
661 UPDATX = (Word >> 8);
662 #endif
663 }
664
665 /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
666 * direction pipes.
667 *
668 * \ingroup Group_PipePrimitiveRW
669 *
670 * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
671 */
672 static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
673 static inline void Pipe_Write_Word_BE(const uint16_t Word)
674 {
675 #if defined(__AVR32__)
676 // TODO
677 #elif defined(__AVR__)
678 UPDATX = (Word >> 8);
679 UPDATX = (Word & 0xFF);
680 #endif
681 }
682
683 /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
684 *
685 * \ingroup Group_PipePrimitiveRW
686 */
687 static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;
688 static inline void Pipe_Discard_Word(void)
689 {
690 uint8_t Dummy;
691
692 #if defined(__AVR32__)
693 // TODO
694 #elif defined(__AVR__)
695 Dummy = UPDATX;
696 Dummy = UPDATX;
697 #endif
698 }
699
700 /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
701 * direction pipes.
702 *
703 * \ingroup Group_PipePrimitiveRW
704 *
705 * \return Next double word in the currently selected pipe's FIFO buffer
706 */
707 static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
708 static inline uint32_t Pipe_Read_DWord_LE(void)
709 {
710 union
711 {
712 uint32_t DWord;
713 uint8_t Bytes[4];
714 } Data;
715
716 #if defined(__AVR32__)
717 // TODO
718 #elif defined(__AVR__)
719 Data.Bytes[0] = UPDATX;
720 Data.Bytes[1] = UPDATX;
721 Data.Bytes[2] = UPDATX;
722 Data.Bytes[3] = UPDATX;
723 #endif
724
725 return Data.DWord;
726 }
727
728 /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
729 * direction pipes.
730 *
731 * \ingroup Group_PipePrimitiveRW
732 *
733 * \return Next double word in the currently selected pipe's FIFO buffer
734 */
735 static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
736 static inline uint32_t Pipe_Read_DWord_BE(void)
737 {
738 union
739 {
740 uint32_t DWord;
741 uint8_t Bytes[4];
742 } Data;
743
744 #if defined(__AVR32__)
745 // TODO
746 #elif defined(__AVR__)
747 Data.Bytes[3] = UPDATX;
748 Data.Bytes[2] = UPDATX;
749 Data.Bytes[1] = UPDATX;
750 Data.Bytes[0] = UPDATX;
751
752 return Data.DWord;
753 }
754
755 /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
756 * direction pipes.
757 *
758 * \ingroup Group_PipePrimitiveRW
759 *
760 * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
761 */
762 static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
763 static inline void Pipe_Write_DWord_LE(const uint32_t DWord)
764 {
765 #if defined(__AVR32__)
766 // TODO
767 #elif defined(__AVR__)
768 UPDATX = (DWord & 0xFF);
769 UPDATX = (DWord >> 8);
770 UPDATX = (DWord >> 16);
771 UPDATX = (DWord >> 24);
772 #endif
773 }
774
775 /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
776 * direction pipes.
777 *
778 * \ingroup Group_PipePrimitiveRW
779 *
780 * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
781 */
782 static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
783 static inline void Pipe_Write_DWord_BE(const uint32_t DWord)
784 {
785 #if defined(__AVR32__)
786 // TODO
787 #elif defined(__AVR__)
788 UPDATX = (DWord >> 24);
789 UPDATX = (DWord >> 16);
790 UPDATX = (DWord >> 8);
791 UPDATX = (DWord & 0xFF);
792 #endif
793 }
794
795 /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
796 *
797 * \ingroup Group_PipePrimitiveRW
798 */
799 static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;
800 static inline void Pipe_Discard_DWord(void)
801 {
802 uint8_t Dummy;
803
804 #if defined(__AVR32__)
805 // TODO
806 #elif defined(__AVR__)
807 Dummy = UPDATX;
808 Dummy = UPDATX;
809 Dummy = UPDATX;
810 Dummy = UPDATX;
811 #endif
812 }
813
814 /* External Variables: */
815 /** Global indicating the maximum packet size of the default control pipe located at address
816 * 0 in the device. This value is set to the value indicated in the attached device's device
817 * descriptor once the USB interface is initialized into host mode and a device is attached
818 * to the USB bus.
819 *
820 * \note This variable should be treated as read-only in the user application, and never manually
821 * changed in value.
822 */
823 extern uint8_t USB_ControlPipeSize;
824
825 /* Function Prototypes: */
826 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
827 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
828 #else
829 #define __CALLBACK_PARAM
830 #endif
831
832 /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
833 * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their
834 * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on) to prevent fragmentation
835 * of the USB FIFO memory.
836 *
837 * The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the
838 * PIPE_TOKEN_* masks.
839 *
840 * The bank size must indicate the maximum packet size that the pipe can handle. Different pipe
841 * numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to
842 * determine the maximum bank size for each pipe.
843 *
844 * The banking mode may be either \ref PIPE_BANK_SINGLE or \ref PIPE_BANK_DOUBLE.
845 *
846 * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
847 * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
848 * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
849 * numbers of IN requests without automatic freezing - this can be overridden by a call to
850 * \ref Pipe_SetFiniteINRequests().
851 *
852 * \note The default control pipe does not have to be manually configured, as it is automatically
853 * configured by the library internally.
854 *
855 * \note This routine will select the specified pipe, and the pipe will remain selected once the
856 * routine completes regardless of if the pipe configuration succeeds.
857 *
858 * \return Boolean true if the configuration is successful, false otherwise
859 */
860 bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
861 const uint16_t Size, const uint8_t Banks);
862
863 /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read
864 * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
865 *
866 * \ingroup Group_PipeRW
867 *
868 * \return A value from the Pipe_WaitUntilReady_ErrorCodes_t enum.
869 */
870 uint8_t Pipe_WaitUntilReady(void);
871
872 /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given
873 * endpoint is found, it is automatically selected.
874 *
875 * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check
876 *
877 * \return Boolean true if a pipe bound to the given endpoint address of the specified direction is found, false
878 * otherwise
879 */
880 bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);
881
882 /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
883 * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
884 * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
885 * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready,
886 * allowing for early aborts of stream transfers.
887 *
888 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
889 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
890 * disabled and this function has the Callback parameter omitted.
891 *
892 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
893 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
894 *
895 * \ingroup Group_PipeStreamRW
896 *
897 * \param[in] Length Number of bytes to send via the currently selected pipe.
898 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
899 *
900 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
901 */
902 uint8_t Pipe_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
903
904 /** Writes the given number of bytes to the pipe from the given buffer in little endian,
905 * sending full packets to the device as needed. The last packet filled is not automatically sent;
906 * the user is responsible for manually sending the last written packet to the host via the
907 * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
908 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
909 *
910 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
911 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
912 * disabled and this function has the Callback parameter omitted.
913 *
914 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
915 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
916 *
917 * \ingroup Group_PipeStreamRW
918 *
919 * \param[in] Buffer Pointer to the source data buffer to read from.
920 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
921 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
922 *
923 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
924 */
925 uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
926
927 /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
928 *
929 * \ingroup Group_PipeStreamRW
930 *
931 * \param[in] Buffer Pointer to the source data buffer to read from.
932 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
933 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
934 *
935 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
936 */
937 uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
938
939 /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
940 *
941 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
942 *
943 * \ingroup Group_PipeStreamRW
944 *
945 * \param[in] Buffer Pointer to the source data buffer to read from.
946 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
947 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
948 *
949 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
950 */
951 uint8_t Pipe_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
952
953 /** Writes the given number of bytes to the pipe from the given buffer in big endian,
954 * sending full packets to the device as needed. The last packet filled is not automatically sent;
955 * the user is responsible for manually sending the last written packet to the host via the
956 * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
957 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
958 *
959 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
960 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
961 * disabled and this function has the Callback parameter omitted.
962 *
963 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
964 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
965 *
966 * \ingroup Group_PipeStreamRW
967 *
968 * \param[in] Buffer Pointer to the source data buffer to read from.
969 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
970 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
971 *
972 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
973 */
974 uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
975
976 /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
977 *
978 * \ingroup Group_PipeStreamRW
979 *
980 * \param[in] Buffer Pointer to the source data buffer to read from.
981 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
982 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
983 *
984 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
985 */
986 uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
987
988 /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
989 *
990 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
991 *
992 * \ingroup Group_PipeStreamRW
993 *
994 * \param[in] Buffer Pointer to the source data buffer to read from.
995 * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
996 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
997 *
998 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
999 */
1000 uint8_t Pipe_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1001
1002 /** Reads the given number of bytes from the pipe into the given buffer in little endian,
1003 * sending full packets to the device as needed. The last packet filled is not automatically sent;
1004 * the user is responsible for manually sending the last written packet to the host via the
1005 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
1006 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
1007 *
1008 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1009 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1010 * disabled and this function has the Callback parameter omitted.
1011 *
1012 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
1013 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
1014 *
1015 * \ingroup Group_PipeStreamRW
1016 *
1017 * \param[out] Buffer Pointer to the source data buffer to write to.
1018 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1019 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
1020 *
1021 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1022 */
1023 uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1024
1025 /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
1026 *
1027 * \ingroup Group_PipeStreamRW
1028 *
1029 * \param[out] Buffer Pointer to the source data buffer to write to.
1030 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1031 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
1032 *
1033 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1034 */
1035 uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1036
1037 /** Reads the given number of bytes from the pipe into the given buffer in big endian,
1038 * sending full packets to the device as needed. The last packet filled is not automatically sent;
1039 * the user is responsible for manually sending the last written packet to the host via the
1040 * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
1041 * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
1042 *
1043 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1044 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1045 * disabled and this function has the Callback parameter omitted.
1046 *
1047 * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
1048 * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
1049 *
1050 * \ingroup Group_PipeStreamRW
1051 *
1052 * \param[out] Buffer Pointer to the source data buffer to write to.
1053 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1054 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
1055 *
1056 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1057 */
1058 uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1059
1060 /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
1061 *
1062 * \ingroup Group_PipeStreamRW
1063 *
1064 * \param[out] Buffer Pointer to the source data buffer to write to.
1065 * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
1066 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
1067 *
1068 * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
1069 */
1070 uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
1071
1072 /* Private Interface - For use in library only: */
1073 #if !defined(__DOXYGEN__)
1074 /* Macros: */
1075 #define PIPE_TOKEN_MASK (0x03 << PTOKEN0)
1076
1077 #if !defined(ENDPOINT_CONTROLEP)
1078 #define ENDPOINT_CONTROLEP 0
1079 #endif
1080
1081 #define Pipe_AllocateMemory() MACROS{ UPCFG1X |= (1 << ALLOC); }MACROE
1082 #define Pipe_DeallocateMemory() MACROS{ UPCFG1X &= ~(1 << ALLOC); }MACROE
1083
1084 /* Function Prototypes: */
1085 void Pipe_ClearPipes(void);
1086
1087 /* Inline Functions: */
1088 static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
1089 static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)
1090 {
1091 if (Bytes <= 8)
1092 return (0 << EPSIZE0);
1093 else if (Bytes <= 16)
1094 return (1 << EPSIZE0);
1095 else if (Bytes <= 32)
1096 return (2 << EPSIZE0);
1097 else if (Bytes <= 64)
1098 return (3 << EPSIZE0);
1099 else if (Bytes <= 128)
1100 return (4 << EPSIZE0);
1101 else
1102 return (5 << EPSIZE0);
1103 }
1104
1105 #endif
1106
1107 /* Disable C linkage for C++ Compilers: */
1108 #if defined(__cplusplus)
1109 }
1110 #endif
1111
1112 #endif
1113
1114 /** @} */