1 // |
|
2 // * Copyright 2004 Neusoft America Inc. |
|
3 // * All rights reserved. |
|
4 // * This component and the accompanying materials are made available |
|
5 // * under the terms of the Eclipse Public License v1.0 |
|
6 // * which accompanies this distribution, and is available |
|
7 // * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // * |
|
9 // * Contributors: |
|
10 // * Keith Collins (Neusoft America Inc.) original software development and additional code and modifications. |
|
11 // * Thomas Gahagen (Neusoft America Inc.) additional code and modifications. |
|
12 // * Zhen Yuan (Neusoft America Inc.) additional code and modifications. |
|
13 // * |
|
14 // * Description: This file contains the implemenation for the CCommFrameWriterAo class. |
|
15 // * This class is used to handle the write operations to the serial port |
|
16 // * logical device driver. |
|
17 // |
|
18 |
|
19 // CommFrameWriterAo.cpp |
|
20 |
|
21 /** @file CommFrameWriterAo.cpp |
|
22 * |
|
23 * This file contains the implemenation for the CCommFrameWriterAo class. |
|
24 * This class is used to handle the write operations to the serial port |
|
25 * logical device driver. |
|
26 */ |
|
27 |
|
28 #include "CommFrameWriterAo.h" |
|
29 #include "CsyMsgBufBPFrame.h" |
|
30 #include "Mux0710Protocol.h" |
|
31 #include "CsyDebugLogger.h" |
|
32 #include "PortC32InterfaceBase.h" |
|
33 |
|
34 CCommFrameWriterAo* CCommFrameWriterAo::NewL(CPortFactory* aParent, CMux0710Protocol* aMux0710Protocol) |
|
35 /** |
|
36 * This method uses two phase construction and the cleanup stack to |
|
37 * create an instance of class CCommFrameWriterAo. |
|
38 * |
|
39 * @param aParent - Pointer to the parent object |
|
40 * @param aMux0710Protocol - Pointer to mux protocol object |
|
41 * @return Pointer to new instance of CCommFrameWriterAo |
|
42 */ |
|
43 { |
|
44 _LOG_L4C1("CCommFrameWriterAo::NewL"); |
|
45 |
|
46 CCommFrameWriterAo* obj = new (ELeave) CCommFrameWriterAo(aParent, aMux0710Protocol); |
|
47 CleanupStack::PushL(obj); |
|
48 obj->ConstructL(); |
|
49 CleanupStack::Pop(); |
|
50 return (obj); |
|
51 } |
|
52 |
|
53 |
|
54 CCommFrameWriterAo::~CCommFrameWriterAo() |
|
55 /** |
|
56 * Destructor. |
|
57 */ |
|
58 { |
|
59 _LOG_L4C1("CCommFrameWriterAo::~CCommFrameWriterAo"); |
|
60 |
|
61 Cancel(); |
|
62 |
|
63 // Remove the frames in Write Buf List |
|
64 CCsyMsgBufBpFrame* frame; |
|
65 iWriteFrameBufIter.SetToFirst(); |
|
66 while ((frame = iWriteFrameBufIter++) != NULL) |
|
67 { |
|
68 iWriteFrameBufList.Remove(*frame); |
|
69 delete frame; |
|
70 } |
|
71 |
|
72 // Remove the frames in waiting list |
|
73 iWaitingForFcOffIter.SetToFirst(); |
|
74 while ((frame = iWaitingForFcOffIter++) != NULL) |
|
75 { |
|
76 iWaitingForFcOffList.Remove(*frame); |
|
77 delete frame; |
|
78 } |
|
79 } |
|
80 |
|
81 CCommFrameWriterAo::CCommFrameWriterAo(CPortFactory* aParent, CMux0710Protocol* aMux0710Protocol) |
|
82 /** |
|
83 * Constructor. |
|
84 * @param aParent - Pointer to the parent object |
|
85 * @param aMux0710Protocol - Pointer to mux protocol object |
|
86 */ |
|
87 : CCommReadWriteBaseAo(aParent, aMux0710Protocol, KFrameWriterAoPriority), |
|
88 iWriteFrameBufList(_FOFF(CCsyMsgBufBpFrame, iMsgLink)), |
|
89 iWriteFrameBufIter(iWriteFrameBufList), |
|
90 iWaitingForFcOffList(_FOFF(CCsyMsgBufBpFrame, iMsgLink)), |
|
91 iWaitingForFcOffIter(iWaitingForFcOffList) |
|
92 {} |
|
93 |
|
94 |
|
95 void CCommFrameWriterAo::ConstructL() |
|
96 /** |
|
97 * Safe constructor |
|
98 */ |
|
99 { |
|
100 _LOG_L4C1("CCommFrameWriterAo::ConstructL"); |
|
101 SetBuffersL(); |
|
102 } |
|
103 |
|
104 void CCommFrameWriterAo::RunL() |
|
105 /** |
|
106 * This method is called when a write to the LDD completes. |
|
107 */ |
|
108 { |
|
109 _LOG_L4C1(" "); |
|
110 _LOG_L4C2(">>CCommFrameWriterAo::RunL [iStatus=%d] - written to LDD", |
|
111 iStatus.Int()); |
|
112 |
|
113 if (iStatus.Int()) |
|
114 { |
|
115 _LOG_L1C2("** Error writing to LDD ** [iStatus=%d]",iStatus.Int()); |
|
116 |
|
117 if (!iCompleteWhenSent) |
|
118 { |
|
119 // The frame being sent was not the last or only one for this dlc, other |
|
120 // frames exist |
|
121 |
|
122 // go through list and remove other frames to send for this dlc |
|
123 RemoveAnyDlcFramesOnWriteList(iDlcNum, EFalse); |
|
124 |
|
125 iCompleteWhenSent = ETrue; |
|
126 } |
|
127 } |
|
128 |
|
129 if (iCompleteWhenSent) |
|
130 { |
|
131 iCompleteWhenSent = EFalse; |
|
132 |
|
133 _LOG_L3C2("Complete write [iDlcNum=%d]",iDlcNum); |
|
134 CompleteWrite(iDlcNum,iStatus.Int()); |
|
135 } |
|
136 |
|
137 // check for another message that needs to be sent to the baseband |
|
138 CCsyMsgBufBpFrame* bpFrame = GetFrameToWrite(); |
|
139 if (bpFrame) |
|
140 { |
|
141 TInt ret = KErrNone; |
|
142 do |
|
143 { |
|
144 ret = WriteFrame(bpFrame); |
|
145 if (ret) |
|
146 { |
|
147 _LOG_L1C2("** Write frame failed [ret=%d] **",ret); |
|
148 if (!iCompleteWhenSent) |
|
149 { |
|
150 // go through list and remove other frames to send for this dlc |
|
151 RemoveAnyDlcFramesOnWriteList(iDlcNum, EFalse); |
|
152 } |
|
153 } |
|
154 |
|
155 // Loop around if there is an error and try and send the next frame |
|
156 } |
|
157 while (ret); |
|
158 } |
|
159 else |
|
160 { |
|
161 _LOG_L3C1("Finished all writes - nothing more to send to LDD"); |
|
162 } |
|
163 |
|
164 _LOG_L4C1("<<CCommFrameWriterAo::RunL"); |
|
165 _LOG_L3C1(" "); // please leave this separator in |
|
166 } |
|
167 |
|
168 void CCommFrameWriterAo::DoCancel() |
|
169 /** |
|
170 * Cancel a pending write |
|
171 */ |
|
172 { |
|
173 _LOG_L4C1("CCommFrameWriterAo::DoCancel - cancelling LDD write"); |
|
174 |
|
175 iCommPort->WriteCancel(); |
|
176 |
|
177 // Remove the frames in Write Buf List |
|
178 CCsyMsgBufBpFrame* frame; |
|
179 iWriteFrameBufIter.SetToFirst(); |
|
180 while ((frame = iWriteFrameBufIter++) != NULL) |
|
181 { |
|
182 iWriteFrameBufList.Remove(*frame); |
|
183 iMux0710Protocol->AddFrameFreeQ(frame); |
|
184 } |
|
185 |
|
186 // Remove the frames in waiting list |
|
187 iWaitingForFcOffIter.SetToFirst(); |
|
188 while ((frame = iWaitingForFcOffIter++) != NULL) |
|
189 { |
|
190 iWaitingForFcOffList.Remove(*frame); |
|
191 iMux0710Protocol->AddFrameFreeQ(frame); |
|
192 } |
|
193 } |
|
194 |
|
195 TInt CCommFrameWriterAo::Write(CCsyMsgBufBpFrame* aBpFrame, |
|
196 TBool aHighPriority) |
|
197 /** |
|
198 * This method is called to transmit a frame to the baseband. |
|
199 * |
|
200 * @param aBpFrame - Pointer to frame |
|
201 * @param aHighPriority - Flag to indicate a high priority frame |
|
202 */ |
|
203 { |
|
204 _LOG_L4C3(">>CCommFrameWriterAo::Write [aBpFrame=0x%x, aHighPriority=%d]", |
|
205 aBpFrame,aHighPriority); |
|
206 |
|
207 TInt ret = KErrNone; |
|
208 |
|
209 // 1st check if we are already transmitting a frame |
|
210 if (!IsActive()) |
|
211 { |
|
212 _LOG_L4C1("Not currently writing a frame"); |
|
213 ret = WriteFrame(aBpFrame); |
|
214 } |
|
215 else |
|
216 { |
|
217 // add frame to the list of frames that need to be sent to the BP |
|
218 _LOG_L2C1("Already writing a frame - add to queue"); |
|
219 AddToWaitingToSendList(aBpFrame, aHighPriority); |
|
220 } |
|
221 |
|
222 _LOG_L4C2("<<CCommFrameWriterAo::Write [ret=%d]",ret); |
|
223 return ret; |
|
224 } |
|
225 |
|
226 TInt CCommFrameWriterAo::WriteFrame(CCsyMsgBufBpFrame* aBpFrame) |
|
227 /** |
|
228 * This method is called to transmit a frame to the baseband. |
|
229 * |
|
230 * @param aBpFrame - Pointer to frame |
|
231 */ |
|
232 { |
|
233 _LOG_L4C2(">>CCommFrameWriterAo::WriteFrame [aBpFrame=0x%x]", |
|
234 aBpFrame); |
|
235 |
|
236 TInt ret = KErrNone; |
|
237 |
|
238 iDlcNum = aBpFrame->MsgDlc(); |
|
239 iCompleteWhenSent = aBpFrame->CompleteWhenSent(); |
|
240 |
|
241 if (iBuf == NULL) |
|
242 { |
|
243 _LOG_L1C1("** Failure to alloc iBuf **"); |
|
244 |
|
245 ret = KErrNoMemory; |
|
246 _LOG_L4C2("<<CCommFrameWriterAo::WriteFrame [ret=%d]",ret); |
|
247 return ret; |
|
248 } |
|
249 |
|
250 //********************************************************* |
|
251 // MAF tidy up |
|
252 #ifdef _DEBUG |
|
253 //log out frame |
|
254 TInt len = aBpFrame->iMsg.Length(); |
|
255 _LOG_L3C3("[0x%02x] Tx Got Start dlc=%d", aBpFrame->iMsg[0], aBpFrame->MsgDlc()); |
|
256 for(TInt k = 1; k < len-1; k++) |
|
257 { |
|
258 _LOG_L3C2("[0x%02x]",aBpFrame->iMsg[k]); |
|
259 } |
|
260 _LOG_L3C2("[0x%02x] Tx Frame End", aBpFrame->iMsg[len-1]); |
|
261 if (iMux0710Protocol->IsMuxModeEnabled()) |
|
262 { |
|
263 if ((aBpFrame->iMsg[2] & 0xEF) == KCsy0710CTLUIH) |
|
264 { |
|
265 #ifdef __DEBUGLOGFILE__ |
|
266 TBuf8<200> tt; |
|
267 #else |
|
268 TBuf16<200> tt; |
|
269 #endif |
|
270 tt.Copy(aBpFrame->iMsg); |
|
271 |
|
272 TInt ttLength = tt.Length(); |
|
273 tt.SetLength(ttLength); |
|
274 #ifdef __LOGDEBUGLEVELMINOR__ |
|
275 _LOG_L3C3("Sent >>>> %d: %S", aBpFrame->iMsg[1] >> 2, &tt); |
|
276 #endif |
|
277 } |
|
278 } |
|
279 #endif |
|
280 //********************************************************* |
|
281 |
|
282 // copy message to local buffer |
|
283 #ifdef _27010ADVANCEOPTION |
|
284 |
|
285 if (iMux0710Protocol->IsMuxModeEnabled()) |
|
286 { |
|
287 TInt length = aBpFrame->iMsg.Length() - 1; |
|
288 TUint8 mask = 1<<5; |
|
289 |
|
290 iBuf->Zero(); |
|
291 |
|
292 // start flag |
|
293 iBuf->Append(aBpFrame->iMsg[0]); |
|
294 |
|
295 // check data for flag or escape character |
|
296 for (TInt i=1; i < length; i++) |
|
297 { |
|
298 TUint8 tmp = aBpFrame->iMsg[i]; |
|
299 if ((tmp == KCsy0710StartEndFlag)||(tmp== KCsy0710EscapeByte)) |
|
300 { |
|
301 _LOG_L3C1("Adding escape byte"); |
|
302 iBuf->Append(KCsy0710EscapeByte); |
|
303 tmp = (TUint8) (tmp^mask); |
|
304 } |
|
305 iBuf->Append(tmp); |
|
306 } |
|
307 |
|
308 //ending flag |
|
309 iBuf->Append(aBpFrame->iMsg[length]); |
|
310 } |
|
311 else |
|
312 iBuf->Copy(aBpFrame->iMsg); |
|
313 |
|
314 #else |
|
315 |
|
316 // Basic option - no escape chars |
|
317 iBuf->Copy(aBpFrame->iMsg); |
|
318 |
|
319 #endif |
|
320 |
|
321 // free the caller's frame buffer |
|
322 iMux0710Protocol->AddFrameFreeQ(aBpFrame); |
|
323 |
|
324 // invoke LDD |
|
325 _LOG_L3C1("Sending to LDD"); |
|
326 iStatus = KRequestPending; //MAF why is this being set to KRequestPending? |
|
327 SetActive(); |
|
328 iCommPort->Write(iStatus, *iBuf, iBuf->Length()); |
|
329 |
|
330 _LOG_L4C2("<<CCommFrameWriterAo::WriteFrame [ret=%d]",ret); |
|
331 return ret; |
|
332 } |
|
333 |
|
334 void CCommFrameWriterAo::WriteCancel() |
|
335 /** |
|
336 * Cancel the current write operation. |
|
337 * @return void |
|
338 */ |
|
339 { |
|
340 _LOG_L4C1("CCommFrameWriterAo::WriteCancel"); |
|
341 Cancel(); |
|
342 } |
|
343 |
|
344 void CCommFrameWriterAo::AddToWaitingToSendList(CCsyMsgBufBpFrame* aBpFrame, TBool aHighPriority) |
|
345 /** |
|
346 * This method is called to by C32 Interface objects to add |
|
347 * the specified frame to the baseband queue. |
|
348 * |
|
349 * @param aBpFrame - Pointer to the frame buffer |
|
350 * @param aHighPriority - Flag to indicate a high priority frame |
|
351 */ |
|
352 { |
|
353 _LOG_L4C3(">>CCommFrameWriterAo::AddToWaitingToSendList [aBpFrame=0x%x,aHighPriority=%d]", |
|
354 aBpFrame, aHighPriority); |
|
355 |
|
356 if (aHighPriority) |
|
357 iWriteFrameBufList.AddFirst(*aBpFrame); |
|
358 else |
|
359 iWriteFrameBufList.AddLast(*aBpFrame); |
|
360 |
|
361 _LOG_L4C1("<<CCommFrameWriterAo::AddToWaitingToSendList"); |
|
362 } |
|
363 |
|
364 CCsyMsgBufBpFrame* CCommFrameWriterAo::GetFrameToWrite() |
|
365 /** |
|
366 * This method checks the queue for a frame that needs to be sent |
|
367 * to the baseband. If there is a message then deque it from the queue and |
|
368 * return a pointer to it, else return NULL. |
|
369 * |
|
370 * @return Pointer to the frame to be written or NULL |
|
371 */ |
|
372 { |
|
373 _LOG_L4C1(">>CCommFrameWriterAo::GetFrameToWrite"); |
|
374 |
|
375 CCsyMsgBufBpFrame* frame = NULL; |
|
376 if (!iWriteFrameBufList.IsEmpty()) |
|
377 { |
|
378 frame = iWriteFrameBufList.First(); |
|
379 if (frame) |
|
380 iWriteFrameBufList.Remove(*frame); |
|
381 } |
|
382 |
|
383 _LOG_L4C2("<<CCommFrameWriterAo::GetFrameToWrite [frame=0x%x]",frame); |
|
384 return frame; |
|
385 } |
|
386 |
|
387 void CCommFrameWriterAo::RemoveAnyDlcFramesOnWriteList(TUint8 aDlcNum, TBool aPlaceOnWaitList) |
|
388 /** |
|
389 * This method transfers any frames on the write list from the dlc specified |
|
390 * to the waiting list. |
|
391 * |
|
392 * @param aDlcNum is the dlc number of the frames to move to the waiting list |
|
393 * @param aPlaceOnWaitList indicates whether to free the frame or place onto the |
|
394 * wait list. |
|
395 */ |
|
396 { |
|
397 _LOG_L4C3(">>CCommFrameWriterAo::RemoveAnyDlcFramesOnWriteList [aDlcNum=%d, aPlaceOnWaitList=%d]", |
|
398 aDlcNum,aPlaceOnWaitList); |
|
399 |
|
400 if (iWriteFrameBufList.IsEmpty()) |
|
401 { |
|
402 // No frames to transfer |
|
403 _LOG_L4C1("No frames on write list"); |
|
404 } |
|
405 else |
|
406 { |
|
407 CCsyMsgBufBpFrame* frame = NULL; |
|
408 iWriteFrameBufIter.SetToFirst(); |
|
409 while ((frame = iWriteFrameBufIter++) != NULL) |
|
410 { |
|
411 if (frame->GetDlcNum() == aDlcNum) |
|
412 { |
|
413 iWriteFrameBufList.Remove(*frame); |
|
414 if (aPlaceOnWaitList) |
|
415 { |
|
416 _LOG_L4C1("Transferring frame to wait list"); |
|
417 iWaitingForFcOffList.AddLast(*frame); |
|
418 } |
|
419 else |
|
420 { |
|
421 // Adding frame to the free list |
|
422 iMux0710Protocol->AddFrameFreeQ(frame); |
|
423 } |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 _LOG_L4C1("<<CCommFrameWriterAo::RemoveAnyDlcFramesOnWriteList"); |
|
429 } |
|
430 |
|
431 void CCommFrameWriterAo::RemoveAnyDlcFramesFromWaitList(TUint8 aDlcNum, TBool aPlaceOnWriteList) |
|
432 /** |
|
433 * This method transfers any frames on the waiting list from the dlc specified |
|
434 * to the write list. |
|
435 * |
|
436 * @param aDlcNum is the dlc number of the frames to move to the write list |
|
437 */ |
|
438 { |
|
439 _LOG_L4C3(">>CCommFrameWriterAo::RemoveAnyDlcFramesFromWaitList [aDlcNum=%d,aPlaceOnWriteList=%d]", |
|
440 aDlcNum,aPlaceOnWriteList); |
|
441 |
|
442 if (iWaitingForFcOffList.IsEmpty()) |
|
443 { |
|
444 // No frames to transfer |
|
445 _LOG_L4C1("No frames on waiting list"); |
|
446 } |
|
447 else |
|
448 { |
|
449 TBool writeQueueWasEmpty = iWriteFrameBufList.IsEmpty(); |
|
450 |
|
451 CCsyMsgBufBpFrame* frame = NULL; |
|
452 iWaitingForFcOffIter.SetToFirst(); |
|
453 while ((frame = iWaitingForFcOffIter++) != NULL) |
|
454 { |
|
455 if (frame->GetDlcNum() == aDlcNum) |
|
456 { |
|
457 iWaitingForFcOffList.Remove(*frame); |
|
458 if (aPlaceOnWriteList) |
|
459 { |
|
460 _LOG_L4C1("Transferring frame to write list"); |
|
461 iWriteFrameBufList.AddLast(*frame); |
|
462 } |
|
463 else |
|
464 { |
|
465 // Adding frame to the free list |
|
466 iMux0710Protocol->AddFrameFreeQ(frame); |
|
467 } |
|
468 } |
|
469 } |
|
470 |
|
471 if ((!iWriteFrameBufList.IsEmpty())&&(writeQueueWasEmpty)&&(!IsActive())) |
|
472 { |
|
473 _LOG_L4C1("Write queue was empty and not active - triggering write"); |
|
474 frame = GetFrameToWrite(); |
|
475 TInt ret = WriteFrame(frame); |
|
476 if (ret) |
|
477 { |
|
478 _LOG_L1C2("Write delayed frame failed [ret=%d]",ret); |
|
479 |
|
480 // Place the failed frame back on the list. |
|
481 iWriteFrameBufList.AddFirst(*frame); |
|
482 } |
|
483 } |
|
484 } |
|
485 |
|
486 _LOG_L4C1("<<CCommFrameWriterAo::RemoveAnyDlcFramesFromWaitList"); |
|
487 } |
|
488 |
|
489 void CCommFrameWriterAo::CompleteWrite(const TUint8 aDlcNum, TInt aStatus) |
|
490 /** |
|
491 * This method calls the DLC port interface to complete the write request. |
|
492 * |
|
493 * @param aDlcNum - DLC number of the port |
|
494 */ |
|
495 { |
|
496 _LOG_L4C3(">>CCommFrameWriterAo::CompleteWrite [aDlcNum=%d,aStatus=%d]", |
|
497 aDlcNum,aStatus); |
|
498 |
|
499 if (aDlcNum) |
|
500 { |
|
501 CPortC32InterfaceBase* port = iParent->FindPortC32Interface(aDlcNum); |
|
502 if (port) |
|
503 port->CompleteWriteRequest(aStatus); |
|
504 else |
|
505 { |
|
506 _LOG_L1C2("** Port does not exist for aDlcNum=%d **", |
|
507 aDlcNum); |
|
508 // MAF __ASSERT_DEBUG(EFalse,PANIC(KPanicIllegalState)); |
|
509 } |
|
510 } |
|
511 else |
|
512 { |
|
513 // MAF tell mux control channel of send result |
|
514 } |
|
515 |
|
516 _LOG_L4C1("<<CCommFrameWriterAo::CompleteWrite"); |
|
517 } |
|
518 |
|