27 #include "cusbpnusbsenderTraces.h" |
27 #include "cusbpnusbsenderTraces.h" |
28 #endif |
28 #endif |
29 |
29 |
30 #include <d32usbc.h> // RDevUsbcClient |
30 #include <d32usbc.h> // RDevUsbcClient |
31 |
31 |
32 // EXTERNAL DATA STRUCTURES |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 // CONSTANTS |
|
35 // MACROS |
|
36 // LOCAL CONSTANTS AND MACROS |
32 // LOCAL CONSTANTS AND MACROS |
37 // MODULE DATA STRUCTURES |
33 const TInt KTotalUsbPacketCount( KPnUsbPacketCount + 1 ); |
38 // LOCAL FUNCTION PROTOTYPES |
34 |
39 // FORWARD DECLARATIONS |
|
40 |
|
41 // ============================= LOCAL FUNCTIONS =============================== |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
35 // ============================ MEMBER FUNCTIONS =============================== |
43 |
36 |
44 // ----------------------------------------------------------------------------- |
37 // ----------------------------------------------------------------------------- |
45 // CUsbPnUsbSender::CUsbPnUsbSender |
38 // CUsbPnUsbSender::CUsbPnUsbSender |
46 // C++ default constructor can NOT contain any code, that |
39 // C++ default constructor can NOT contain any code, that |
47 // might leave. |
40 // might leave. |
48 // ----------------------------------------------------------------------------- |
41 // ----------------------------------------------------------------------------- |
49 // |
42 // |
50 CUsbPnUsbSender::CUsbPnUsbSender( MUsbPnBufferListener& aListener, RDevUsbcClient& aLdd ) |
43 CUsbPnUsbSender::CUsbPnUsbSender( MUsbPnBufferListener& aListener, |
|
44 RDevUsbcClient& aLdd ) |
51 :CActive( 100 ) //ECommTransmitPriority=100 in es_prot.h |
45 :CActive( 100 ) //ECommTransmitPriority=100 in es_prot.h |
52 ,iBufferListener( aListener ) |
46 ,iBufferListener( aListener ) |
53 ,iLdd( aLdd ) |
47 ,iLdd( aLdd ) |
54 ,iPacketCount( 0 ) |
48 ,iPacketCount( NULL ) |
55 ,iPacket( NULL ) |
49 ,iPacket( NULL ) |
56 { |
50 { |
57 OstTraceExt2( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_ENTRY, "CUsbPnUsbSender::CUsbPnUsbSender;aListener=%x;aLdd=%x", ( TUint )&( aListener ), ( TUint )&( aLdd ) ); |
51 OstTraceExt2( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_ENTRY, "CUsbPnUsbSender::CUsbPnUsbSender;aListener=%x;aLdd=%x", ( TUint )&( aListener ), ( TUint )&( aLdd ) ); |
58 C_TRACE( ( _T( "CUsbPnUsbSender::CUsbPnUsbSender( aListener:0x%x, aLdd:0x%x )" ), &aListener, &aLdd ) ); |
52 C_TRACE( ( _T( "CUsbPnUsbSender::CUsbPnUsbSender( aListener:0x%x, aLdd:0x%x )" ), &aListener, &aLdd ) ); |
59 |
53 |
111 { |
105 { |
112 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_ENTRY, "CUsbPnUsbSender::~CUsbPnUsbSender" ); |
106 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_ENTRY, "CUsbPnUsbSender::~CUsbPnUsbSender" ); |
113 C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender()" ) ) ); |
107 C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender()" ) ) ); |
114 |
108 |
115 Cancel(); |
109 Cancel(); |
116 |
110 DeletePackets(); |
117 // Delete circular buffer objects |
111 |
118 CUsbPnPacket* packet; |
112 iCurrentPacket = NULL; |
|
113 iPacket = NULL; |
|
114 |
|
115 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_EXIT, "CUsbPnUsbSender::~CUsbPnUsbSender - return" ); |
|
116 C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender() - return" ) ) ); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CUsbPnUsbSender::DeletePackets |
|
121 // ----------------------------------------------------------------------------- |
|
122 void CUsbPnUsbSender::DeletePackets( ) |
|
123 { |
|
124 OstTrace0( TRACE_API, CUSBPNUSBSENDER_DELETEPACKETS_ENTRY, "CUsbPnUsbSender::DeletePackets" ); |
|
125 A_TRACE( ( _T( "CUsbPnUsbSender::DeletePackets()" ) ) ); |
|
126 CUsbPnPacket* packet = NULL; |
119 while(iPacketCount > 0) |
127 while(iPacketCount > 0) |
120 { |
128 { |
121 iPacketCount--; |
129 iPacketCount--; |
122 packet = &iPacket->NextPacket(); |
130 packet = &iPacket->NextPacket(); |
123 delete iPacket; |
131 delete iPacket; |
124 iPacket = packet; |
132 iPacket = packet; |
125 } |
133 } |
126 iCurrentPacket = NULL; |
134 OstTrace0( TRACE_API, CUSBPNUSBSENDER_DELETEPACKETS_EXIT, "CUsbPnUsbSender::DeletePackets - return void" ); |
127 iPacket = NULL; |
135 A_TRACE( ( _T( "CUsbPnUsbSender::DeletePackets() - return void" ) ) ); |
128 |
136 } |
129 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_EXIT, "CUsbPnUsbSender::~CUsbPnUsbSender - return" ); |
|
130 C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender() - return" ) ) ); |
|
131 } |
|
132 |
137 |
133 // ----------------------------------------------------------------------------- |
138 // ----------------------------------------------------------------------------- |
134 // CUsbPnUsbSender::AddPacketBufferL |
139 // CUsbPnUsbSender::AddPacketBufferL |
135 // ----------------------------------------------------------------------------- |
140 // ----------------------------------------------------------------------------- |
136 void CUsbPnUsbSender::AddPacketBufferL( TInt aIndex ) |
141 void CUsbPnUsbSender::AddPacketBufferL( const TInt aIndex ) |
137 { |
142 { |
138 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_ENTRY, "CUsbPnUsbSender::AddPacketBufferL" ); |
143 OstTrace1( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_ENTRY, "CUsbPnUsbSender::AddPacketBufferL aIndex %d", aIndex ); |
139 C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer()"))); |
144 C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer() aIndex %d"), aIndex)); |
140 |
145 |
141 iPacketCount++; |
146 if( aIndex <= KTotalUsbPacketCount ) |
142 iPacket = CUsbPnPacket::NewL( iPacket, aIndex ); |
147 { |
|
148 iPacketCount++; |
|
149 iPacket = CUsbPnPacket::NewL( iPacket, aIndex ); |
|
150 } |
|
151 else |
|
152 { |
|
153 TRACE_ASSERT_ALWAYS; |
|
154 } |
143 |
155 |
144 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_EXIT, "CUsbPnUsbSender::AddPacketBufferL - return void" ); |
156 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_EXIT, "CUsbPnUsbSender::AddPacketBufferL - return void" ); |
145 C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer - return void"))); |
157 C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer - return void"))); |
146 } |
158 } |
147 |
159 |
148 // ----------------------------------------------------------------------------- |
160 // ----------------------------------------------------------------------------- |
149 // CUsbPnUsbSender::PacketL |
161 // CUsbPnUsbSender::GetNextPacketL |
150 // ----------------------------------------------------------------------------- |
162 // ----------------------------------------------------------------------------- |
151 CUsbPnPacket& CUsbPnUsbSender::PacketL() |
163 CUsbPnPacket& CUsbPnUsbSender::GetNextPacketL() |
152 { |
164 { |
153 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_PACKETL_ENTRY, "CUsbPnUsbSender::PacketL" ); |
165 OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_GETNEXTPACKETL_ENTRY, "CUsbPnUsbSender::GetNextPacketL" ); |
154 C_TRACE((_T("CUsbPnUsbSender::PacketL()"))); |
166 C_TRACE((_T("CUsbPnUsbSender::PacketL()"))); |
155 |
167 |
156 CUsbPnPacket& packet( iPacket->NextPacket() ); |
168 CUsbPnPacket& nextPacket( iPacket->NextPacket() ); |
157 TBool err = packet.PacketInUse(); |
169 TBool err = nextPacket.PacketInUse(); |
158 if (EFalse != err) |
170 if (EFalse != err) |
159 { |
171 { |
160 User::Leave( err ); |
172 User::Leave( err ); |
161 } |
173 } |
162 |
174 OstTrace1( TRACE_NORMAL, CUSBPNUSBSENDER_GETNEXTPACKETL_EXIT, "CUsbPnUsbSender::GetNextPacketL - return;packet=%d", nextPacket.PacketNumber() ); |
163 OstTrace1( TRACE_NORMAL, CUSBPNUSBSENDER_PACKETL_EXIT, "CUsbPnUsbSender::PacketL - return;packet=%d", packet.PacketNumber() ); |
175 C_TRACE((_T("CUsbPnUsbSender::GetNextPacketL() - return packet:%d"), nextPacket.PacketNumber())); |
164 C_TRACE((_T("CUsbPnUsbSender::PacketL() - return packet:%d"), packet.PacketNumber())); |
176 |
165 |
177 return nextPacket; |
166 return packet; |
178 } |
167 } |
179 |
168 |
180 // ----------------------------------------------------------------------------- |
169 // ----------------------------------------------------------------------------- |
181 // CUsbPnUsbSender::AddPacketToSendingQueue |
170 // CUsbPnUsbSender::Send |
182 // ----------------------------------------------------------------------------- |
171 // ?implementation_description |
183 // |
172 // (other items were commented in a header). |
184 void CUsbPnUsbSender::AddPacketToSendingQueue( CUsbPnPacket& aPacket ) |
173 // ----------------------------------------------------------------------------- |
185 { |
174 // |
186 ASSERT( &aPacket ); |
175 void CUsbPnUsbSender::Send( CUsbPnPacket& aPacket ) |
187 OstTrace0( TRACE_API, CUSBPNUSBSENDER_ADDPACKETTOSENDINGQUEUE_ENTRY, "CUsbPnUsbSender::AddPacketToSendingQueue" ); |
176 { |
|
177 OstTrace0( TRACE_API, CUSBPNUSBSENDER_SEND_ENTRY, "CUsbPnUsbSender::Send" ); |
|
178 A_TRACE( ( _T( "CUsbPnUsbSender::Send()" ) ) ); |
188 A_TRACE( ( _T( "CUsbPnUsbSender::Send()" ) ) ); |
179 |
189 |
180 iPacket = &iPacket->NextPacket(); |
190 iPacket = &iPacket->NextPacket(); |
181 OstTrace1( TRACE_DETAILED, CUSBPNUSBSENDER_SEND, "CUsbPnUsbSender::Send;packet number:%d", iPacket->PacketNumber() ); |
191 OstTrace1( TRACE_DETAILED, CUSBPNUSBSENDER_ADDPACKETTOSENDINGQUEUE, "CUsbPnUsbSender::AddPacketToSendingQueue;packet number:%d", iPacket->PacketNumber() ); |
182 E_TRACE( ( _T( "CUsbPnUsbSender::Send() - packet number:%d" ), iPacket->PacketNumber() ) ); |
192 E_TRACE( ( _T( "CUsbPnUsbSender::AddPacketToSendingQueue() - packet number:%d" ), iPacket->PacketNumber() ) ); |
183 |
193 |
184 TryToSendPacket( *iPacket ); |
194 TryToSendPacket( *iPacket ); |
185 |
195 |
186 OstTrace0( TRACE_API, CUSBPNUSBSENDER_SEND_EXIT, "CUsbPnUsbSender::Send - return void" ); |
196 OstTrace0( TRACE_API, CUSBPNUSBSENDER_ADDPACKETTOSENDINGQUEUE_EXIT, "CUsbPnUsbSender::AddPacketToSendingQueue - return void" ); |
187 A_TRACE( ( _T( "CUsbPnUsbSender::Send() - return void" ) ) ); |
197 A_TRACE( ( _T( "CUsbPnUsbSender::AddPacketToSendingQueue() - return void" ) ) ); |
188 } |
198 } |
189 |
199 |
190 // ----------------------------------------------------------------------------- |
200 // ----------------------------------------------------------------------------- |
191 // CUsbPnUsbSender::TryToSendPacket |
201 // CUsbPnUsbSender::TryToSendPacket |
192 // ?implementation_description |
|
193 // (other items were commented in a header). |
|
194 // ----------------------------------------------------------------------------- |
202 // ----------------------------------------------------------------------------- |
195 // |
203 // |
196 void CUsbPnUsbSender::TryToSendPacket( const CUsbPnPacket& aPacket ) |
204 void CUsbPnUsbSender::TryToSendPacket( const CUsbPnPacket& aPacket ) |
197 { |
205 { |
198 OstTraceExt2( TRACE_API, CUSBPNUSBSENDER_TRYTOSENDPACKET_ENTRY, "CUsbPnUsbSender::TryToSendPacket;aPacket=%d;iCurrentPacket=%d", aPacket.PacketNumber(), iCurrentPacket->PacketNumber() ); |
206 ASSERT( &aPacket ); |
199 A_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket( aPacketNumber:%d, iCurrentPacket:%d )" ), aPacket.PacketNumber(), iCurrentPacket->PacketNumber( ) )); |
207 OstTraceExt2( TRACE_API, CUSBPNUSBSENDER_TRYTOSENDPACKET_ENTRY, "CUsbPnUsbSender::TryToSendPacket;aPacket=0x%x;iCurrentPacket=%d", ( TUint )&( aPacket ), iCurrentPacket->PacketNumber() ); |
|
208 A_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket( aPacketNumber:0x%x, iCurrentPacket:%d )" ), &aPacket, iCurrentPacket->PacketNumber( ) )); |
200 |
209 |
201 // Write message to USB |
210 // Write message to USB |
202 if(!IsActive()) |
211 if(!IsActive()) |
203 { |
212 { |
204 if( &aPacket == &iCurrentPacket->NextPacket() || &aPacket == iCurrentPacket ) |
213 if( &aPacket == ( &iCurrentPacket->NextPacket() ) |
|
214 || &aPacket == iCurrentPacket ) |
205 { |
215 { |
206 OstTrace0( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET, "CUsbPnUsbSender::TryToSendPacket - Write to socket" ); |
216 OstTrace0( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET, "CUsbPnUsbSender::TryToSendPacket - Write to socket" ); |
207 E_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket() - Write to socket"))); |
217 E_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket() - Write to socket"))); |
208 |
218 |
209 HBufC8& data(aPacket.Buffer()); |
219 HBufC8& data(aPacket.Buffer()); |
210 TInt length( data.Length() ); |
220 TInt length( data.Length() ); |
211 #ifdef EXTENDED_TRACE_FLAG |
221 #ifdef EXTENDED_TRACE_FLAG |
212 TInt i(0); |
222 for(TInt i = 0; i < length; i++) |
213 |
|
214 while(i < length ) |
|
215 { |
223 { |
216 OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET_DUP1, "CUsbPnUsbSender::Send( [%d] = %x )", i, data[i] ); |
224 OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET_DUP1, "CUsbPnUsbSender::Send( [%d] = %x )", i, data[i] ); |
217 E_TRACE( ( _T( "CUsbPnUsbSender::Send([%d] = %x )" ), i, data[i] ) ); |
225 E_TRACE( ( _T( "CUsbPnUsbSender::Send([%d] = %x )" ), i, data[i] ) ); |
218 i++; |
226 i++; |
219 } |
227 } |
220 #endif |
228 #endif |
221 |
229 |
222 // ZLP flag setting is optional. Could be always true as driver checks against max packet size |
230 // ZLP flag setting is optional. Could be always true as driver checks against max packet size |
223 TBool zlp( ( length != 0 ) && ( length % KPnPacketSize ) == 0 ); |
231 TBool zlp( ETrue ); |
224 |
232 if( length != 0 ) |
|
233 { |
|
234 zlp = ( ( length != 0 ) && |
|
235 ( length % KPnPacketSize ) == 0 ); |
|
236 } |
|
237 |
225 iLdd.Write( iStatus, EEndpoint1, data, length, zlp ); |
238 iLdd.Write( iStatus, EEndpoint1, data, length, zlp ); |
226 SetActive(); |
239 SetActive(); |
227 } |
240 } |
228 else |
241 else |
229 { |
242 { |
272 iBufferListener.Receive( ETrue ); |
281 iBufferListener.Receive( ETrue ); |
273 iCurrentPacket = &iCurrentPacket->NextPacket(); |
282 iCurrentPacket = &iCurrentPacket->NextPacket(); |
274 |
283 |
275 if(iCurrentPacket != iPacket) |
284 if(iCurrentPacket != iPacket) |
276 { |
285 { |
277 // Continue write |
|
278 OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_RUNL, "CUsbPnUsbSender::RunL - Write next in queue;tail=%d;head=%d", iCurrentPacket->PacketNumber(), iPacket->PacketNumber() ); |
286 OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_RUNL, "CUsbPnUsbSender::RunL - Write next in queue;tail=%d;head=%d", iCurrentPacket->PacketNumber(), iPacket->PacketNumber() ); |
279 E_TRACE( ( _T( "CUsbPnUsbSender::RunL() - Write next in queue tail:%d,head:%d " ), iCurrentPacket->PacketNumber(), iPacket->PacketNumber())); |
287 E_TRACE( ( _T( "CUsbPnUsbSender::RunL() - Write next in queue tail:%d,head:%d " ), iCurrentPacket->PacketNumber(), iPacket->PacketNumber())); |
280 TryToSendPacket( iCurrentPacket->NextPacket() ); |
288 TryToSendPacket( iCurrentPacket->NextPacket() ); |
281 } |
289 } |
282 |
|
283 OstTrace0( TRACE_API, CUSBPNUSBSENDER_RUNL_EXIT, "CUsbPnUsbSender::RunL - return void" ); |
290 OstTrace0( TRACE_API, CUSBPNUSBSENDER_RUNL_EXIT, "CUsbPnUsbSender::RunL - return void" ); |
284 A_TRACE( ( _T( "CUsbPnUsbSender::RunL() - return void" ) ) ); |
291 A_TRACE( ( _T( "CUsbPnUsbSender::RunL() - return void" ) ) ); |
285 } |
292 } |
286 |
293 |
287 // ----------------------------------------------------------------------------- |
294 // ----------------------------------------------------------------------------- |
288 // CUsbPnUsbSender::RunError |
295 // CUsbPnUsbSender::RunError |
289 // ?implementation_description |
|
290 // (other items were commented in a header). |
|
291 // ----------------------------------------------------------------------------- |
296 // ----------------------------------------------------------------------------- |
292 // |
297 // |
293 TInt CUsbPnUsbSender::RunError( TInt aError ) |
298 TInt CUsbPnUsbSender::RunError( TInt aError ) |
294 { |
299 { |
295 OstTrace1( TRACE_API, CUSBPNUSBSENDER_RUNERROR_ENTRY, "CUsbPnUsbSender::RunError;aError=%d", aError ); |
300 OstTrace1( TRACE_API, CUSBPNUSBSENDER_RUNERROR_ENTRY, "CUsbPnUsbSender::RunError;aError=%d", aError ); |