]> git.sur5r.net Git - freertos/blob
4c529a78a1a651370ed1edf6c3042238de60a3d2
[freertos] /
1 /*\r
2  * @brief USB Pipe definitions for the LPC microcontrollers\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 #define  __INCLUDE_FROM_USB_DRIVER\r
33 #include "USBMode.h"\r
34 \r
35 #if defined(USB_CAN_BE_HOST)\r
36 \r
37 #include "Pipe.h"\r
38 \r
39 uint8_t pipeselected[MAX_USB_CORE];\r
40 USB_Pipe_Data_t PipeInfo[MAX_USB_CORE][PIPE_TOTAL_PIPES];\r
41 \r
42 HCD_USB_SPEED hostportspeed[MAX_USB_CORE];\r
43 uint8_t hostselected;\r
44 \r
45 bool Pipe_ConfigurePipe(const uint8_t corenum,\r
46                                                 const uint8_t Number,\r
47                                                 const uint8_t Type,\r
48                                                 const uint8_t Token,\r
49                                                 const uint8_t EndpointNumber,\r
50                                                 const uint16_t Size,\r
51                                                 const uint8_t Banks)\r
52 {\r
53         if ( HCD_STATUS_OK == HcdOpenPipe(corenum,                              /* HostID */\r
54                                                                           (( Type == EP_TYPE_CONTROL) &&\r
55                                                                            ( USB_HostState[corenum] <\r
56                                                                                  HOST_STATE_Default_PostAddressSet) ) ? 0 : USB_HOST_DEVICEADDRESS,                                                                                                                     /* FIXME DeviceAddr */\r
57                                                                           hostportspeed[corenum],       /* DeviceSpeed */\r
58                                                                           EndpointNumber,                               /* EndpointNo */\r
59                                                                           (HCD_TRANSFER_TYPE) Type,             /* TransferType */\r
60                                                                           (HCD_TRANSFER_DIR) Token,             /* TransferDir */\r
61                                                                           Size,                                                 /* MaxPacketSize */\r
62                                                                           1,                                                    /* Interval */\r
63                                                                           1,                                                    /* Mult */\r
64                                                                           0,                                                    /* HSHubDevAddr */\r
65                                                                           0,                                                    /* HSHubPortNum */\r
66                                                                           &PipeInfo[corenum][Number].PipeHandle                   /* PipeHandle */)\r
67                  ) {\r
68                 PipeInfo[corenum][Number].ByteTransfered = PipeInfo[corenum][Number].StartIdx = 0;\r
69                 PipeInfo[corenum][Number].BufferSize = (Type == EP_TYPE_BULK || Type == EP_TYPE_CONTROL) ? PIPE_MAX_SIZE : Size;/* XXX Some devices could have configuration descriptor > 235 bytes (eps speaker, webcame). If not deal with those, not need to have such large pipe size for control */\r
70                 PipeInfo[corenum][Number].Buffer = USB_Memory_Alloc(PipeInfo[corenum][Number].BufferSize,0);\r
71                 PipeInfo[corenum][Number].EndponitAddress = EndpointNumber;\r
72                 if (PipeInfo[corenum][Number].Buffer == NULL) {\r
73                         return false;\r
74                 }\r
75 \r
76                 return true;\r
77         }\r
78         else {\r
79                 return false;\r
80         }\r
81 }\r
82 \r
83 void Pipe_ClosePipe(const uint8_t corenum, uint8_t pipenum)\r
84 {\r
85         if (pipenum < PIPE_TOTAL_PIPES) {\r
86                 HcdClosePipe(PipeInfo[corenum][pipenum].PipeHandle);\r
87                 PipeInfo[corenum][pipenum].PipeHandle = 0;\r
88                 USB_Memory_Free(PipeInfo[corenum][pipenum].Buffer);\r
89                 PipeInfo[corenum][pipenum].Buffer = NULL;\r
90                 PipeInfo[corenum][pipenum].BufferSize = 0;\r
91         }\r
92 }\r
93 \r
94 void Pipe_ClearPipes(void)\r
95 {}\r
96 \r
97 bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)\r
98 {\r
99         return false;\r
100 }\r
101 \r
102 uint8_t Pipe_WaitUntilReady(const uint8_t corenum)\r
103 {\r
104         /*      #if (USB_STREAM_TIMEOUT_MS < 0xFF)\r
105             uint8_t  TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
106            #else\r
107             uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
108            #endif\r
109 \r
110             uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();*/\r
111 \r
112         for (;; ) {\r
113                 if (Pipe_IsReadWriteAllowed(corenum)) {\r
114                         return PIPE_READYWAIT_NoError;\r
115                 }\r
116 \r
117                 if (Pipe_IsStalled(corenum)) {\r
118                         return PIPE_READYWAIT_PipeStalled;\r
119                 }\r
120                 else if (USB_HostState[corenum] == HOST_STATE_Unattached) {\r
121                         return PIPE_READYWAIT_DeviceDisconnected;\r
122                 }\r
123 \r
124                 /*TODO no timeout yet */\r
125                 /* uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();\r
126 \r
127                    if (CurrentFrameNumber != PreviousFrameNumber)\r
128                    {\r
129                     PreviousFrameNumber = CurrentFrameNumber;\r
130 \r
131                     if (!(TimeoutMSRem--))\r
132                       return PIPE_READYWAIT_Timeout;\r
133                    }*/\r
134         }\r
135 }\r
136 \r
137 bool Pipe_IsINReceived(const uint8_t corenum)\r
138 {\r
139         if (HCD_STATUS_OK != HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle)) {\r
140                 return false;\r
141         }\r
142 \r
143         if (Pipe_BytesInPipe(corenum)) {\r
144                 return true;\r
145         }\r
146         else {  /* Empty Pipe */\r
147                 HcdDataTransfer(PipeInfo[corenum][pipeselected[corenum]].PipeHandle,\r
148                                                 PipeInfo[corenum][pipeselected[corenum]].Buffer,\r
149                                                 HCD_ENDPOINT_MAXPACKET_XFER_LEN,\r
150                                                 &PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);\r
151                 return false;\r
152         }\r
153 }\r
154 \r
155 #endif\r