| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Pipe.h
Go to the documentation of this file.
1 /*
2 * @brief Common USB Pipe definitions for all architectures
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * Copyright(C) Dean Camera, 2011, 2012
7 * All rights reserved.
8 *
9 * @par
10 * Software that is described herein is for illustrative purposes only
11 * which provides customers with programming information regarding the
12 * LPC products. This software is supplied "AS IS" without any warranties of
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
14 * all warranties, express or implied, including all implied warranties of
15 * merchantability, fitness for a particular purpose and non-infringement of
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
17 * or liability for the use of the software, conveys no license or rights under any
18 * patent, copyright, mask work right, or any other intellectual property rights in
19 * or to any products. NXP Semiconductors reserves the right to make changes
20 * in the software without notification. NXP Semiconductors also makes no
21 * representation or warranty that such application will be suitable for the
22 * specified use without further testing or modification.
23 *
24 * @par
25 * Permission to use, copy, modify, and distribute this software and its
26 * documentation is hereby granted, under NXP Semiconductors' and its
27 * licensor's relevant copyrights in the software, without fee, provided that it
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
29 * copyright, permission, and disclaimer notice must appear in all copies of
30 * this code.
31 */
32
76 #ifndef __PIPE_H__
77 #define __PIPE_H__
78
79 /* Includes: */
80 #include "../../../Common/Common.h"
81 #include "USBMode.h"
82
83 /* Enable C linkage for C++ Compilers: */
84 #if defined(__cplusplus)
85 extern "C" {
86 #endif
87
88 /* Preprocessor Checks: */
89 #if !defined(__INCLUDE_FROM_USB_DRIVER)
90 #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
91 #endif
92
93 /* Public Interface - May be used in end-application: */
94 /* Macros: */
98 #define PIPE_CONTROLPIPE 0
99
103 #define PIPE_PIPENUM_MASK 0x0F
104
108 #define PIPE_EPNUM_MASK 0x0F
109
113 #define PIPE_EPDIR_MASK 0x80
114
115 #include "USBTask.h"
116 #include "HCD/HCD.h"
117 #include "USBMemory.h" // FIXME move later
118 #include <stdbool.h>
119
120 /* Macros: */
122 // @{
124 #define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
125
127 #define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
128
130 #define PIPE_ERRORFLAG_CRC16 (1 << 4)
131
133 #define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
134
136 #define PIPE_ERRORFLAG_PID (1 << 2)
137
139 #define PIPE_ERRORFLAG_DATAPID (1 << 1)
140
142 #define PIPE_ERRORFLAG_DATATGL (1 << 0)
143
144
150 #define PIPE_TOKEN_SETUP (0)
151
155 #define PIPE_TOKEN_IN (1)
156
160 #define PIPE_TOKEN_OUT (2)
161
162
169 #define PIPE_BANK_SINGLE (0 << 1)
170
176 #define PIPE_BANK_DOUBLE (1 << 1)
177
178
182 #define PIPE_CONTROLPIPE_DEFAULT_SIZE 8
183
188 #define PIPE_TOTAL_PIPES HCD_MAX_ENDPOINT
189
195 #define PIPE_MAX_SIZE 512
196
197 /* Enums: */
202 enum Pipe_WaitUntilReady_ErrorCodes_t {
203 PIPE_READYWAIT_NoError = 0,
204 PIPE_READYWAIT_PipeStalled = 1,
205 PIPE_READYWAIT_DeviceDisconnected = 2,
206 PIPE_READYWAIT_Timeout = 3,
210 };
211
214 typedef struct {
215 uint32_t PipeHandle;
216 uint8_t *Buffer;
217 uint16_t BufferSize;
218 uint16_t StartIdx;
219 uint16_t ByteTransfered;
220 uint8_t EndponitAddress;
221 } USB_Pipe_Data_t;
222
225 extern uint8_t hostselected;
226
229 extern HCD_USB_SPEED hostportspeed[];
230
233 extern uint8_t pipeselected[MAX_USB_CORE];
234
237 extern USB_Pipe_Data_t PipeInfo[MAX_USB_CORE][PIPE_TOTAL_PIPES];
238
239 /* Inline Functions: */
251 static inline uint16_t Pipe_BytesInPipe(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
252
253 static inline uint16_t Pipe_BytesInPipe(const uint8_t corenum)
254 {
255 return PipeInfo[corenum][pipeselected[corenum]].ByteTransfered - PipeInfo[corenum][pipeselected[corenum]].StartIdx;
256 }
257
265 static inline uint8_t Pipe_GetCurrentPipe(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
266
267 static inline uint8_t Pipe_GetCurrentPipe(const uint8_t corenum)
268 {
269 return pipeselected[corenum];
270 }
271
280 static inline void Pipe_SelectPipe(const uint8_t corenum, const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
281
282 static inline void Pipe_SelectPipe(const uint8_t corenum, const uint8_t PipeNumber)
283 {
284 pipeselected[corenum] = PipeNumber;
285 }
286
293 static inline void Pipe_ResetPipe(const uint8_t corenum, const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
294
295 static inline void Pipe_ResetPipe(const uint8_t corenum, const uint8_t PipeNumber)
296 {
297 PipeInfo[corenum][pipeselected[corenum]].StartIdx = PipeInfo[corenum][pipeselected[corenum]].ByteTransfered = 0;
298 }
299
305 static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;
306
307 static inline void Pipe_EnablePipe(void)
308 {
309 // TODO implement later
310 }
311
315 static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;
316
317 static inline void Pipe_DisablePipe(void)
318 {
319 // TODO implement later
320 }
321
326 static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
327
328 static inline bool Pipe_IsEnabled(void)
329 {
330 // TODO implement later
331 return true;
332 }
333
339 static inline uint8_t Pipe_GetPipeToken(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
340
341 static inline uint8_t Pipe_GetPipeToken(const uint8_t corenum)
342 {
343 return (PipeInfo[corenum][pipeselected[corenum]].EndponitAddress &
344 PIPE_EPDIR_MASK) ? PIPE_TOKEN_IN : PIPE_TOKEN_OUT;
345 }
346
356 static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_DEPRECATED ATTR_ALWAYS_INLINE;
357
358 static inline void Pipe_SetPipeToken(const uint8_t Token)
359 {}
360
362 static inline void Pipe_SetInfiniteINRequests(void) ATTR_DEPRECATED ATTR_ALWAYS_INLINE;
363
364 static inline void Pipe_SetInfiniteINRequests(void)
365 {}
366
374 static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_DEPRECATED ATTR_ALWAYS_INLINE;
375
376 static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)
377 {}
378
384 static inline bool Pipe_IsConfigured(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
385
386 static inline bool Pipe_IsConfigured(const uint8_t corenum)
387 {
388 return PipeInfo[corenum][pipeselected[corenum]].Buffer != NULL; // TODO implement using status later
389 }
390
398 static inline uint8_t Pipe_GetBoundEndpointAddress(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
399
400 static inline uint8_t Pipe_GetBoundEndpointAddress(const uint8_t corenum)
401 {
402 return PipeInfo[corenum][pipeselected[corenum]].EndponitAddress;
403 }
404
410 static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;
411
412 static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)
413 {
414 // TODO implement later
415 }
416
422 static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
423
424 static inline uint8_t Pipe_GetPipeInterrupts(void)
425 {
426 return 0; // TODO implement later
427 }
428
436 static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
437
438 static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber)
439 {
440 return false; // TODO implement later
441 }
442
444 static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;
445
446 static inline void Pipe_Unfreeze(void)
447 {
448 // TODO implement later
449 }
450
452 static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;
453
454 static inline void Pipe_Freeze(void)
455 {
456 // TODO implement later
457 }
458
463 static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
464
465 static inline bool Pipe_IsFrozen(void)
466 {
467 return false; // TODO implement later
468 }
469
471 static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;
472
473 static inline void Pipe_ClearError(void)
474 {
475 // TODO implement later
476 }
477
486 static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
487
488 static inline bool Pipe_IsError(void)
489 {
490 return false; // TODO implement later
491 }
492
499 static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
500
501 static inline uint8_t Pipe_GetErrorFlags(void)
502 {
503 return 0; // TODO implement later
504 }
505
515 static inline uint8_t Pipe_GetBusyBanks(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
516
517 static inline uint8_t Pipe_GetBusyBanks(void)
518 {
519 return 0; // TODO implement later
520 }
521
530 // static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
531 bool Pipe_IsINReceived(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT;
532
541 static inline bool Pipe_IsOUTReady(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
542
543 static inline bool Pipe_IsOUTReady(const uint8_t corenum)
544 {
545 return (HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle) == HCD_STATUS_OK)
546 && (PipeInfo[corenum][pipeselected[corenum]].ByteTransfered <
547 PipeInfo[corenum][pipeselected[corenum]].BufferSize);
548 }
549
565 static inline bool Pipe_IsReadWriteAllowed(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
566
567 static inline bool Pipe_IsReadWriteAllowed(const uint8_t corenum)
568 {
569 if (Pipe_GetPipeToken(corenum) == PIPE_TOKEN_IN) {
570 return (HCD_STATUS_OK == HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle)) &&
571 Pipe_BytesInPipe(corenum);
572 }
573 else {
574 return Pipe_IsOUTReady(corenum);
575 }
576 }
577
585 static inline bool Pipe_IsStatusOK(uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
586 static inline bool Pipe_IsStatusOK(uint8_t corenum)
587 {
588 return (HCD_STATUS_OK == HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle));
589 }
590
599 static inline bool Pipe_IsSETUPSent(void) ATTR_DEPRECATED ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
600
601 static inline bool Pipe_IsSETUPSent(void)
602 {
603 return true;
604 }
605
610 static inline void Pipe_ClearSETUP(void) ATTR_DEPRECATED ATTR_ALWAYS_INLINE;
611
612 static inline void Pipe_ClearSETUP(void)
613 {}
614
621 static inline void Pipe_ClearIN(const uint8_t corenum) ATTR_ALWAYS_INLINE;
622
623 static inline void Pipe_ClearIN(const uint8_t corenum)
624 {
625 PipeInfo[corenum][pipeselected[corenum]].StartIdx = PipeInfo[corenum][pipeselected[corenum]].ByteTransfered = 0;
626 }
627
634 static inline void Pipe_ClearOUT(const uint8_t corenum) ATTR_ALWAYS_INLINE;
635
636 static inline void Pipe_ClearOUT(const uint8_t corenum)
637 {
638 HcdDataTransfer(PipeInfo[corenum][pipeselected[corenum]].PipeHandle,
639 PipeInfo[corenum][pipeselected[corenum]].Buffer,
640 PipeInfo[corenum][pipeselected[corenum]].ByteTransfered,
641 NULL /* FIXME &PipeInfo[pipeselected].ByteTransfered*/);
642 PipeInfo[corenum][pipeselected[corenum]].StartIdx = PipeInfo[corenum][pipeselected[corenum]].ByteTransfered = 0;
643 }
644
656 static inline bool Pipe_IsNAKReceived(void) ATTR_DEPRECATED ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
657
658 static inline bool Pipe_IsNAKReceived(void)
659 {
660 return false;
661 }
662
669 static inline void Pipe_ClearNAKReceived(void) ATTR_DEPRECATED ATTR_ALWAYS_INLINE;
670
671 static inline void Pipe_ClearNAKReceived(void)
672 {}
673
682 static inline bool Pipe_IsStalled(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
683
684 static inline bool Pipe_IsStalled(const uint8_t corenum)
685 {
686 return HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle) == HCD_STATUS_TRANSFER_Stall;
687 }
688
695 static inline void Pipe_ClearStall(const uint8_t corenum) ATTR_ALWAYS_INLINE;
696
697 static inline void Pipe_ClearStall(const uint8_t corenum)
698 {
699 HcdClearEndpointHalt(PipeInfo[corenum][pipeselected[corenum]].PipeHandle);
700 }
701
710 static inline uint8_t Pipe_Read_8(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
711
712 static inline uint8_t Pipe_Read_8(const uint8_t corenum)
713 {
714 if (PipeInfo[corenum][pipeselected[corenum]].StartIdx < PipeInfo[corenum][pipeselected[corenum]].ByteTransfered ) {
715 uint8_t temp =
716 PipeInfo[corenum][pipeselected[corenum]].Buffer[PipeInfo[corenum][pipeselected[corenum]].StartIdx];
717 PipeInfo[corenum][pipeselected[corenum]].StartIdx++;
718 return temp;
719 }
720 else {
721 return 0;
722 }
723 }
724
734 static inline void Pipe_Write_8(const uint8_t corenum, const uint8_t Data) ATTR_ALWAYS_INLINE;
735
736 static inline void Pipe_Write_8(const uint8_t corenum, const uint8_t Data)
737 {
738 if (PipeInfo[corenum][pipeselected[corenum]].ByteTransfered <
739 PipeInfo[corenum][pipeselected[corenum]].BufferSize) {
740 PipeInfo[corenum][pipeselected[corenum]].Buffer[PipeInfo[corenum][pipeselected[corenum]].ByteTransfered] = Data;
741 PipeInfo[corenum][pipeselected[corenum]].ByteTransfered++;
742 }
743 }
744
749 static inline void Pipe_Discard_8(void) ATTR_ALWAYS_INLINE;
750
751 static inline void Pipe_Discard_8(void)
752 {}
753
763 static inline uint16_t Pipe_Read_16_LE(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
764
765 static inline uint16_t Pipe_Read_16_LE(const uint8_t corenum)
766 {
767 uint16_t tem = 0;
768 uint8_t tem1, tem2;
769
770 tem1 = Pipe_Read_8(corenum);
771 tem2 = Pipe_Read_8(corenum);
772 tem = (tem2 << 8) | tem1;
773 return tem;
774 }
775
785 static inline uint16_t Pipe_Read_16_BE(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
786
787 static inline uint16_t Pipe_Read_16_BE(const uint8_t corenum)
788 {
789 uint16_t tem = 0;
790 uint8_t tem1, tem2;
791
792 tem1 = Pipe_Read_8(corenum);
793 tem2 = Pipe_Read_8(corenum);
794 tem = (tem1 << 8) | tem2;
795 return tem;
796 }
797
808 static inline void Pipe_Write_16_LE(const uint8_t corenum, const uint16_t Data) ATTR_ALWAYS_INLINE;
809
810 static inline void Pipe_Write_16_LE(const uint8_t corenum, const uint16_t Data)
811 {
812 Pipe_Write_8(corenum, Data & 0xFF);
813 Pipe_Write_8(corenum, (Data >> 8) & 0xFF);
814 }
815
826 static inline void Pipe_Write_16_BE(const uint8_t corenum, const uint16_t Data) ATTR_ALWAYS_INLINE;
827
828 static inline void Pipe_Write_16_BE(const uint8_t corenum, const uint16_t Data)
829 {
830 Pipe_Write_8(corenum, (Data >> 8) & 0xFF);
831 Pipe_Write_8(corenum, Data & 0xFF);
832 }
833
838 static inline void Pipe_Discard_16(void) ATTR_ALWAYS_INLINE;
839
840 static inline void Pipe_Discard_16(void)
841 {}
842
852 static inline uint32_t Pipe_Read_32_LE(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
853
854 static inline uint32_t Pipe_Read_32_LE(const uint8_t corenum)
855 {
856 uint32_t tem = 0;
857 uint8_t tem1, tem2, tem3, tem4;
858
859 tem1 = Pipe_Read_8(corenum);
860 tem2 = Pipe_Read_8(corenum);
861 tem3 = Pipe_Read_8(corenum);
862 tem4 = Pipe_Read_8(corenum);
863 tem = (tem4 << 24) | (tem3 << 16) | (tem2 << 8) | tem1;
864 return tem;
865 }
866
876 static inline uint32_t Pipe_Read_32_BE(const uint8_t corenum) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
877
878 static inline uint32_t Pipe_Read_32_BE(const uint8_t corenum)
879 {
880 uint32_t tem = 0;
881 uint8_t tem1, tem2, tem3, tem4;
882
883 tem1 = Pipe_Read_8(corenum);
884 tem2 = Pipe_Read_8(corenum);
885 tem3 = Pipe_Read_8(corenum);
886 tem4 = Pipe_Read_8(corenum);
887 tem = (tem1 << 24) | (tem2 << 16) | (tem3 << 8) | tem4;
888 return tem;
889 }
890
901 static inline void Pipe_Write_32_LE(const uint8_t corenum, const uint32_t Data) ATTR_ALWAYS_INLINE;
902
903 static inline void Pipe_Write_32_LE(const uint8_t corenum, const uint32_t Data)
904 {
905 Pipe_Write_8(corenum, Data & 0xFF);
906 Pipe_Write_8(corenum, (Data >> 8) & 0xFF);
907 Pipe_Write_8(corenum, (Data >> 16) & 0xFF);
908 Pipe_Write_8(corenum, (Data >> 24) & 0xFF);
909 }
910
921 static inline void Pipe_Write_32_BE(const uint8_t corenum, const uint32_t Data) ATTR_ALWAYS_INLINE;
922
923 static inline void Pipe_Write_32_BE(const uint8_t corenum, const uint32_t Data)
924 {
925 Pipe_Write_8(corenum, (Data >> 24) & 0xFF);
926 Pipe_Write_8(corenum, (Data >> 16) & 0xFF);
927 Pipe_Write_8(corenum, (Data >> 8) & 0xFF);
928 Pipe_Write_8(corenum, Data & 0xFF);
929 }
930
935 static inline void Pipe_Discard_32(void) ATTR_ALWAYS_INLINE;
936
937 static inline void Pipe_Discard_32(void)
938 {}
939
940 /* External Variables: */
950 /* Function Prototypes: */
992 bool Pipe_ConfigurePipe(const uint8_t corenum,
993 const uint8_t Number,
994 const uint8_t Type,
995 const uint8_t Token,
996 const uint8_t EndpointNumber,
997 const uint16_t Size,
998 const uint8_t Banks);
999
1000 void Pipe_ClosePipe(const uint8_t corenum, uint8_t pipenum);
1001
1010 uint8_t Pipe_WaitUntilReady(const uint8_t corenum);
1011
1020 bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) ATTR_WARN_UNUSED_RESULT;
1021
1022 /* Private Interface - For use in library only: */
1023 #if !defined(__DOXYGEN__)
1024 /* Macros: */
1025 #if !defined(ENDPOINT_CONTROLEP)
1026 #define ENDPOINT_CONTROLEP 0
1027 #endif
1028
1029 /* Inline Functions: */
1030 static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
1031 ATTR_ALWAYS_INLINE;
1032
1033 static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)
1034 {
1035 return 0; // implement later
1036 }
1037
1038 /* Function Prototypes: */
1039 void Pipe_ClearPipes(void);
1040
1041 #endif
1042
1043 /* Disable C linkage for C++ Compilers: */
1044 #if defined(__cplusplus)
1045 }
1046 #endif
1047
1048 #endif
1049