2 * @brief USB Pipe definitions for the LPC microcontrollers
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\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
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
32 #define __INCLUDE_FROM_USB_DRIVER
\r
33 #include "USBMode.h"
\r
35 #if defined(USB_CAN_BE_HOST)
\r
39 uint8_t pipeselected[MAX_USB_CORE];
\r
40 USB_Pipe_Data_t PipeInfo[MAX_USB_CORE][PIPE_TOTAL_PIPES];
\r
42 HCD_USB_SPEED hostportspeed[MAX_USB_CORE];
\r
43 uint8_t hostselected;
\r
45 bool Pipe_ConfigurePipe(const uint8_t corenum,
\r
46 const uint8_t Number,
\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
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
64 0, /* HSHubDevAddr */
\r
65 0, /* HSHubPortNum */
\r
66 &PipeInfo[corenum][Number].PipeHandle /* PipeHandle */)
\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
83 void Pipe_ClosePipe(const uint8_t corenum, uint8_t pipenum)
\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
94 void Pipe_ClearPipes(void)
\r
97 bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
\r
102 uint8_t Pipe_WaitUntilReady(const uint8_t corenum)
\r
104 /* #if (USB_STREAM_TIMEOUT_MS < 0xFF)
\r
105 uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
\r
107 uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
\r
110 uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();*/
\r
113 if (Pipe_IsReadWriteAllowed(corenum)) {
\r
114 return PIPE_READYWAIT_NoError;
\r
117 if (Pipe_IsStalled(corenum)) {
\r
118 return PIPE_READYWAIT_PipeStalled;
\r
120 else if (USB_HostState[corenum] == HOST_STATE_Unattached) {
\r
121 return PIPE_READYWAIT_DeviceDisconnected;
\r
124 /*TODO no timeout yet */
\r
125 /* uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
\r
127 if (CurrentFrameNumber != PreviousFrameNumber)
\r
129 PreviousFrameNumber = CurrentFrameNumber;
\r
131 if (!(TimeoutMSRem--))
\r
132 return PIPE_READYWAIT_Timeout;
\r
137 bool Pipe_IsINReceived(const uint8_t corenum)
\r
139 if (HCD_STATUS_OK != HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle)) {
\r
143 if (Pipe_BytesInPipe(corenum)) {
\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