| 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
PipeStream.c
Go to the documentation of this file.
1 /*
2 * @brief Pipe data stream transmission and reception management for the LPC microcontrollers
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #define __INCLUDE_FROM_USB_DRIVER
33 #include "USBMode.h"
34
35 #if defined(USB_CAN_BE_HOST)
36
37 #include "PipeStream.h"
38
39 uint8_t Pipe_Discard_Stream(const uint8_t corenum,
40 uint16_t Length,
41 uint16_t *const BytesProcessed)
42 {
43 uint8_t ErrorCode;
44 uint16_t BytesInTransfer = 0;
45
46 // Pipe_SetPipeToken(PIPE_TOKEN_IN);
47 ErrorCode = Pipe_WaitUntilReady(corenum);
48 if (ErrorCode) {
49 return ErrorCode;
50 }
51
52 if (BytesProcessed != NULL) {
53 Length -= *BytesProcessed;
54 }
55
56 while (Length) {
57 if (!(Pipe_IsReadWriteAllowed(corenum))) {
58 Pipe_ClearIN(corenum);
59
60 if (BytesProcessed != NULL) {
61 *BytesProcessed += BytesInTransfer;
62 return PIPE_RWSTREAM_IncompleteTransfer;
63 }
64 ErrorCode = Pipe_WaitUntilReady(corenum);
65 if (ErrorCode) {
66 return ErrorCode;
67 }
68 }
69 else {
70 Pipe_Discard_8();
71
72 Length--;
73 BytesInTransfer++;
74 }
75 }
76
77 return PIPE_RWSTREAM_NoError;
78 }
79
80 uint8_t Pipe_Null_Stream(const uint8_t corenum,
81 uint16_t Length,
82 uint16_t *const BytesProcessed)
83 {
84 if (BytesProcessed != NULL) {
85 Length -= *BytesProcessed;
86 }
87
88 while (Length) {
89 Pipe_Write_8(corenum, 0);
90 Length--;
91 }
92
93 return PIPE_RWSTREAM_NoError;
94 }
95
96 uint8_t Pipe_Write_Stream_LE(const uint8_t corenum,
97 const void *const Buffer,
98 uint16_t Length,
99 uint16_t *const BytesProcessed)
100 {
101 uint8_t *DataStream = (uint8_t *) Buffer;
102 if (BytesProcessed != NULL) {
103 Length -= *BytesProcessed;
104 DataStream += *BytesProcessed;
105 }
106
107 while (Length) {
108 Pipe_Write_8(corenum, *DataStream);
109 DataStream++;
110 Length--;
111 }
112
113 return PIPE_RWSTREAM_NoError;
114 }
115
116 uint8_t Pipe_Read_Stream_LE(const uint8_t corenum,
117 void *const Buffer,
118 uint16_t Length,
119 uint16_t *const BytesProcessed) /* TODO Blocking due to Pipe_WaitUntilReady */
120 {
121 uint8_t *DataStream = (uint8_t *) Buffer;
122 uint8_t ErrorCode;
123
124 ErrorCode = Pipe_WaitUntilReady(corenum);
125 if (ErrorCode) {
126 return ErrorCode;
127 }
128
129 if (BytesProcessed != NULL) {
130 Length -= *BytesProcessed;
131 DataStream += *BytesProcessed;
132 }
133
134 while (Length) {
135 if (Pipe_IsReadWriteAllowed(corenum)) {
136 *DataStream = Pipe_Read_8(corenum);
137 DataStream++;
138 Length--;
139 }
140 else {
141 Pipe_ClearIN(corenum);
142 HcdDataTransfer(PipeInfo[corenum][pipeselected[corenum]].PipeHandle,
143 PipeInfo[corenum][pipeselected[corenum]].Buffer,
144 MIN(Length, PipeInfo[corenum][pipeselected[corenum]].BufferSize),
145 &PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);
146 ErrorCode = Pipe_WaitUntilReady(corenum);
147 if (ErrorCode) {
148 return ErrorCode;
149 }
150 }
151 }
152
153 return PIPE_RWSTREAM_NoError;
154 }
155
156 uint8_t Pipe_Write_Stream_BE(const void *const Buffer,
157 uint16_t Length,
158 uint16_t *const BytesProcessed)
159 {
160 return PIPE_RWSTREAM_NoError;
161 }
162
163 uint8_t Pipe_Read_Stream_BE(void *const Buffer,
164 uint16_t Length,
165 uint16_t *const BytesProcessed)
166 {
167 return PIPE_RWSTREAM_NoError;
168 }
169
170 uint8_t Pipe_Write_PStream_LE(const void *const Buffer,
171 uint16_t Length,
172 uint16_t *const BytesProcessed)
173 {
174 return PIPE_RWSTREAM_NoError;
175 }
176
177 uint8_t Pipe_Write_PStream_BE(const void *const Buffer,
178 uint16_t Length,
179 uint16_t *const BytesProcessed)
180 {
181 return PIPE_RWSTREAM_NoError;
182 }
183
184 uint8_t Pipe_Write_EStream_LE(const void *const Buffer,
185 uint16_t Length,
186 uint16_t *const BytesProcessed)
187 {
188 return PIPE_RWSTREAM_NoError;
189 }
190
191 uint8_t Pipe_Write_EStream_BE(const void *const Buffer,
192 uint16_t Length,
193 uint16_t *const BytesProcessed)
194 {
195 return PIPE_RWSTREAM_NoError;
196 }
197
198 uint8_t Pipe_Read_EStream_LE(void *const Buffer,
199 uint16_t Length,
200 uint16_t *const BytesProcessed)
201 {
202 return PIPE_RWSTREAM_NoError;
203 }
204
205 uint8_t Pipe_Read_EStream_BE(void *const Buffer,
206 uint16_t Length,
207 uint16_t *const BytesProcessed)
208 {
209 return PIPE_RWSTREAM_NoError;
210 }
211
212 uint8_t Pipe_Streaming(uint8_t corenum, uint8_t* const buffer, uint32_t const transferlength, uint16_t const packetsize)
213 {
214 uint32_t pipehdl = PipeInfo[corenum][pipeselected[corenum]].PipeHandle;
215 if (HCD_STATUS_OK == HcdGetPipeStatus(pipehdl))
216 {
217 HcdSetStreamPacketSize(pipehdl,packetsize);
218 HcdDataTransfer(pipehdl,buffer,transferlength,&PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);
219 return PIPE_RWSTREAM_NoError;
220 }
221 else return PIPE_RWSTREAM_IncompleteTransfer;
222 }
223
224 #endif