| 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
EndpointStream.c
Go to the documentation of this file.
1 /*
2 * @brief Endpoint 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_DEVICE)
36
37 #include "EndpointStream.h"
38
39 #if !defined(CONTROL_ONLY_DEVICE)
40 uint8_t Endpoint_Discard_Stream(uint8_t corenum,
41 uint16_t Length,
42 uint16_t *const BytesProcessed)
43 {
44 uint32_t i;
45 for (i = 0; i < Length; i++)
46 Endpoint_Discard_8(corenum);
47 return ENDPOINT_RWSTREAM_NoError;
48 }
49
50 uint8_t Endpoint_Null_Stream(uint8_t corenum,
51 uint16_t Length,
52 uint16_t *const BytesProcessed)
53 {
54 uint32_t i;
55
56 while ( !Endpoint_IsINReady(corenum) ) { /*-- Wait until ready --*/
57 Delay_MS(2);
58 }
59 for (i = 0; i < Length; i++)
60 Endpoint_Write_8(corenum, 0);
61 return ENDPOINT_RWSTREAM_NoError;
62 }
63
64 uint8_t Endpoint_Write_Stream_LE(uint8_t corenum,
65 const void *const Buffer,
66 uint16_t Length,
67 uint16_t *const BytesProcessed)
68 {
69 uint16_t i;
70
71 while ( !Endpoint_IsINReady(corenum) ) { /*-- Wait until ready --*/
72 Delay_MS(2);
73 }
74 for (i = 0; i < Length; i++)
75 Endpoint_Write_8(corenum, ((uint8_t *) Buffer)[i]);
76
77 return ENDPOINT_RWSTREAM_NoError;
78 }
79
80 uint8_t Endpoint_Write_Stream_BE(uint8_t corenum,
81 const void *const Buffer,
82 uint16_t Length,
83 uint16_t *const BytesProcessed)
84 {
85 uint16_t i;
86
87 for (i = 0; i < Length; i++)
88 Endpoint_Write_8(corenum, ((uint8_t *) Buffer)[Length - 1 - i]);
89 return ENDPOINT_RWSTREAM_NoError;
90 }
91
92 uint8_t Endpoint_Read_Stream_LE(uint8_t corenum,
93 void *const Buffer,
94 uint16_t Length,
95 uint16_t *const BytesProcessed)
96 {
97 uint16_t i;
98 if (endpointselected[corenum] == ENDPOINT_CONTROLEP) {
99 if (usb_data_buffer_size[corenum] == 0) {
100 return ENDPOINT_RWSTREAM_IncompleteTransfer;
101 }
102 }
103 else if (usb_data_buffer_OUT_size[corenum] == 0) {
104 return ENDPOINT_RWSTREAM_IncompleteTransfer;
105 }
106
107 for (i = 0; i < Length; i++) {
108 #if defined(__LPC175X_6X__) || defined(__LPC177X_8X__) || defined(__LPC407X_8X__)
109 if (endpointselected[corenum] != ENDPOINT_CONTROLEP) {
110 while (usb_data_buffer_OUT_size[corenum] == 0) ; /* Current Fix for LPC17xx, havent checked for others */
111 }
112 #endif
113 ((uint8_t *) Buffer)[i] = Endpoint_Read_8(corenum);
114 }
115 return ENDPOINT_RWSTREAM_NoError;
116 }
117
118 uint8_t Endpoint_Read_Stream_BE(void *const Buffer,
119 uint16_t Length,
120 uint16_t *const BytesProcessed)
121 {
122 return ENDPOINT_RWSTREAM_NoError;
123 }
124
125 #endif
126
127 uint8_t Endpoint_Write_Control_Stream_LE(uint8_t corenum, const void *const Buffer,
128 uint16_t Length)
129 {
130 Endpoint_Write_Stream_LE(corenum, (uint8_t *) Buffer, MIN(Length, USB_ControlRequest.wLength), NULL);
131 Endpoint_ClearIN(corenum);
132 // while (!(Endpoint_IsOUTReceived()))
133 // {
134 // }
135 return ENDPOINT_RWCSTREAM_NoError;
136 }
137
138 uint8_t Endpoint_Write_Control_Stream_BE(const void *const Buffer,
139 uint16_t Length)
140 {
141 return ENDPOINT_RWCSTREAM_NoError;
142 }
143
144 uint8_t Endpoint_Read_Control_Stream_LE(uint8_t corenum, void *const Buffer,
145 uint16_t Length)
146 {
147 while (!Endpoint_IsOUTReceived(corenum)) ; // FIXME: this safe checking is fine for LPC18xx
148 Endpoint_Read_Stream_LE(corenum, Buffer, Length, NULL); // but hangs LPC17xx --> comment out
149 Endpoint_ClearOUT(corenum);
150 return ENDPOINT_RWCSTREAM_NoError;
151 }
152
153 uint8_t Endpoint_Read_Control_Stream_BE(void *const Buffer,
154 uint16_t Length)
155 {
156 return ENDPOINT_RWCSTREAM_NoError;
157 }
158
159 #endif