LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Pipe_LPC.c
Go to the documentation of this file.
1 /*
2  * @brief USB Pipe definitions 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 "../Pipe.h"
38 
39 uint8_t pipeselected[MAX_USB_CORE];
41 
43 uint8_t hostselected;
44 
45 bool Pipe_ConfigurePipe(const uint8_t corenum,
46  const uint8_t Number,
47  const uint8_t Type,
48  const uint8_t Token,
49  const uint8_t EndpointNumber,
50  const uint16_t Size,
51  const uint8_t Banks)
52 {
53  if ( HCD_STATUS_OK == HcdOpenPipe(corenum, /* HostID */
54  (( Type == EP_TYPE_CONTROL) &&
55  ( USB_HostState[corenum] <
56  HOST_STATE_Default_PostAddressSet) ) ? 0 : USB_HOST_DEVICEADDRESS, /* FIXME DeviceAddr */
57  hostportspeed[corenum], /* DeviceSpeed */
58  EndpointNumber, /* EndpointNo */
59  (HCD_TRANSFER_TYPE) Type, /* TransferType */
60  (HCD_TRANSFER_DIR) Token, /* TransferDir */
61  Size, /* MaxPacketSize */
62  1, /* Interval */
63  1, /* Mult */
64  0, /* HSHubDevAddr */
65  0, /* HSHubPortNum */
66  &PipeInfo[corenum][Number].PipeHandle /* PipeHandle */)
67  ) {
68  PipeInfo[corenum][Number].ByteTransfered = PipeInfo[corenum][Number].StartIdx = 0;
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 */
70  PipeInfo[corenum][Number].Buffer = USB_Memory_Alloc(PipeInfo[corenum][Number].BufferSize);
71  PipeInfo[corenum][Number].EndponitAddress = EndpointNumber;
72  if (PipeInfo[corenum][Number].Buffer == NULL) {
73  return false;
74  }
75 
76  return true;
77  }
78  else {
79  return false;
80  }
81 }
82 
83 void Pipe_ClosePipe(const uint8_t corenum, uint8_t pipenum)
84 {
85  if (pipenum < PIPE_TOTAL_PIPES) {
86  HcdClosePipe(PipeInfo[corenum][pipenum].PipeHandle);
87  PipeInfo[corenum][pipenum].PipeHandle = 0;
88  USB_Memory_Free(PipeInfo[corenum][pipenum].Buffer);
89  PipeInfo[corenum][pipenum].Buffer = NULL;
90  PipeInfo[corenum][pipenum].BufferSize = 0;
91  }
92 }
93 
94 void Pipe_ClearPipes(void)
95 {}
96 
98 {
99  return false;
100 }
101 
102 uint8_t Pipe_WaitUntilReady(const uint8_t corenum)
103 {
104  /* #if (USB_STREAM_TIMEOUT_MS < 0xFF)
105  uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
106  #else
107  uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
108  #endif
109 
110  uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();*/
111 
112  for (;; ) {
113  if (Pipe_IsReadWriteAllowed(corenum)) {
114  return PIPE_READYWAIT_NoError;
115  }
116 
117  if (Pipe_IsStalled(corenum)) {
119  }
120  else if (USB_HostState[corenum] == HOST_STATE_Unattached) {
122  }
123 
124  /*TODO no timeout yet */
125  /* uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
126 
127  if (CurrentFrameNumber != PreviousFrameNumber)
128  {
129  PreviousFrameNumber = CurrentFrameNumber;
130 
131  if (!(TimeoutMSRem--))
132  return PIPE_READYWAIT_Timeout;
133  }*/
134  }
135 }
136 
137 bool Pipe_IsINReceived(const uint8_t corenum)
138 {
139  if (HCD_STATUS_OK != HcdGetPipeStatus(PipeInfo[corenum][pipeselected[corenum]].PipeHandle)) {
140  return false;
141  }
142 
143  if (Pipe_BytesInPipe(corenum)) {
144  return true;
145  }
146  else { /* Empty Pipe */
147  HcdDataTransfer(PipeInfo[corenum][pipeselected[corenum]].PipeHandle,
148  PipeInfo[corenum][pipeselected[corenum]].Buffer,
150  &PipeInfo[corenum][pipeselected[corenum]].ByteTransfered);
151  return false;
152  }
153 }
154 
155 #endif