]> git.sur5r.net Git - freertos/blob
d4b490dd7783c7a2a68dd3a983f31f875cc3efc8
[freertos] /
1 /*\r
2  * @brief Pipe data stream transmission and reception management 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 "PipeStream.h"\r
38 \r
39 uint8_t Pipe_Discard_Stream(const uint8_t corenum,\r
40                                                         uint16_t Length,\r
41                                                         uint16_t *const BytesProcessed)\r
42 {\r
43         uint8_t  ErrorCode;\r
44         uint16_t BytesInTransfer = 0;\r
45 \r
46         //      Pipe_SetPipeToken(PIPE_TOKEN_IN);\r
47         ErrorCode = Pipe_WaitUntilReady(corenum);\r
48         if (ErrorCode) {\r
49                 return ErrorCode;\r
50         }\r
51 \r
52         if (BytesProcessed != NULL) {\r
53                 Length -= *BytesProcessed;\r
54         }\r
55 \r
56         while (Length) {\r
57                 if (!(Pipe_IsReadWriteAllowed(corenum))) {\r
58                         Pipe_ClearIN(corenum);\r
59 \r
60                         if (BytesProcessed != NULL) {\r
61                                 *BytesProcessed += BytesInTransfer;\r
62                                 return PIPE_RWSTREAM_IncompleteTransfer;\r
63                         }\r
64                         ErrorCode = Pipe_WaitUntilReady(corenum);\r
65                         if (ErrorCode) {\r
66                                 return ErrorCode;\r
67                         }\r
68                 }\r
69                 else {\r
70                         Pipe_Discard_8();\r
71 \r
72                         Length--;\r
73                         BytesInTransfer++;\r
74                 }\r
75         }\r
76 \r
77         return PIPE_RWSTREAM_NoError;\r
78 }\r
79 \r
80 uint8_t Pipe_Null_Stream(const uint8_t corenum,\r
81                                                  uint16_t Length,\r
82                                                  uint16_t *const BytesProcessed)\r
83 {\r
84         if (BytesProcessed != NULL) {\r
85                 Length -= *BytesProcessed;\r
86         }\r
87 \r
88         while (Length) {\r
89                 Pipe_Write_8(corenum, 0);\r
90                 Length--;\r
91         }\r
92 \r
93         return PIPE_RWSTREAM_NoError;\r
94 }\r
95 \r
96 uint8_t Pipe_Write_Stream_LE(const uint8_t corenum,\r
97                                                          const void *const Buffer,\r
98                                                          uint16_t Length,\r
99                                                          uint16_t *const BytesProcessed)\r
100 {\r
101         uint8_t *DataStream = (uint8_t *) Buffer;\r
102         if (BytesProcessed != NULL) {\r
103                 Length -= *BytesProcessed;\r
104                 DataStream += *BytesProcessed;\r
105         }\r
106 \r
107         while (Length) {\r
108                 Pipe_Write_8(corenum, *DataStream);\r
109                 DataStream++;\r
110                 Length--;\r
111         }\r
112 \r
113         return PIPE_RWSTREAM_NoError;\r
114 }\r
115 \r
116 uint8_t Pipe_Read_Stream_LE(const uint8_t corenum,\r
117                                                         void *const Buffer,\r
118                                                         uint16_t Length,\r
119                                                         uint16_t *const BytesProcessed) /* TODO Blocking due to Pipe_WaitUntilReady */\r
120 {\r
121         uint8_t *DataStream = (uint8_t *) Buffer;\r
122         uint8_t ErrorCode;\r
123 \r
124         ErrorCode = Pipe_WaitUntilReady(corenum);\r
125         if (ErrorCode) {\r
126                 return ErrorCode;\r
127         }\r
128 \r
129         if (BytesProcessed != NULL) {\r
130                 Length -= *BytesProcessed;\r
131                 DataStream += *BytesProcessed;\r
132         }\r
133 \r
134         while (Length) {\r
135                 if (Pipe_IsReadWriteAllowed(corenum)) {\r
136                         *DataStream = Pipe_Read_8(corenum);\r
137                         DataStream++;\r
138                         Length--;\r
139                 }\r
140                 else {\r
141                         Pipe_ClearIN(corenum);\r
142                         HcdDataTransfer(PipeInfo[corenum][pipeselected[corenum]].PipeHandle,\r
143                                                         PipeInfo[corenum][pipeselected[corenum]].Buffer,\r
144                                                         MIN(Length, PipeInfo[corenum][pipeselected[corenum]].BufferSize),\r
145                                                         &PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);\r
146                         ErrorCode = Pipe_WaitUntilReady(corenum);\r
147                         if (ErrorCode) {\r
148                                 return ErrorCode;\r
149                         }\r
150                 }\r
151         }\r
152 \r
153         return PIPE_RWSTREAM_NoError;\r
154 }\r
155 \r
156 uint8_t Pipe_Write_Stream_BE(const void *const Buffer,\r
157                                                          uint16_t Length,\r
158                                                          uint16_t *const BytesProcessed)\r
159 {\r
160         return PIPE_RWSTREAM_NoError;\r
161 }\r
162 \r
163 uint8_t Pipe_Read_Stream_BE(void *const Buffer,\r
164                                                         uint16_t Length,\r
165                                                         uint16_t *const BytesProcessed)\r
166 {\r
167         return PIPE_RWSTREAM_NoError;\r
168 }\r
169 \r
170 uint8_t Pipe_Write_PStream_LE(const void *const Buffer,\r
171                                                           uint16_t Length,\r
172                                                           uint16_t *const BytesProcessed)\r
173 {\r
174         return PIPE_RWSTREAM_NoError;\r
175 }\r
176 \r
177 uint8_t Pipe_Write_PStream_BE(const void *const Buffer,\r
178                                                           uint16_t Length,\r
179                                                           uint16_t *const BytesProcessed)\r
180 {\r
181         return PIPE_RWSTREAM_NoError;\r
182 }\r
183 \r
184 uint8_t Pipe_Write_EStream_LE(const void *const Buffer,\r
185                                                           uint16_t Length,\r
186                                                           uint16_t *const BytesProcessed)\r
187 {\r
188         return PIPE_RWSTREAM_NoError;\r
189 }\r
190 \r
191 uint8_t Pipe_Write_EStream_BE(const void *const Buffer,\r
192                                                           uint16_t Length,\r
193                                                           uint16_t *const BytesProcessed)\r
194 {\r
195         return PIPE_RWSTREAM_NoError;\r
196 }\r
197 \r
198 uint8_t Pipe_Read_EStream_LE(void *const Buffer,\r
199                                                          uint16_t Length,\r
200                                                          uint16_t *const BytesProcessed)\r
201 {\r
202         return PIPE_RWSTREAM_NoError;\r
203 }\r
204 \r
205 uint8_t Pipe_Read_EStream_BE(void *const Buffer,\r
206                                                          uint16_t Length,\r
207                                                          uint16_t *const BytesProcessed)\r
208 {\r
209         return PIPE_RWSTREAM_NoError;\r
210 }\r
211 \r
212 uint8_t Pipe_Streaming(uint8_t corenum, uint8_t* const buffer, uint32_t const transferlength, uint16_t const packetsize)\r
213 {\r
214         uint32_t pipehdl = PipeInfo[corenum][pipeselected[corenum]].PipeHandle;\r
215         if (HCD_STATUS_OK == HcdGetPipeStatus(pipehdl))\r
216         {\r
217                 HcdSetStreamPacketSize(pipehdl,packetsize);\r
218                 HcdDataTransfer(pipehdl,buffer,transferlength,&PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);\r
219                 return PIPE_RWSTREAM_NoError;\r
220         }\r
221         else return PIPE_RWSTREAM_IncompleteTransfer;\r
222 }\r
223 \r
224 #endif\r