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