Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\personality\example\init.cpp
15 // Test code for example RTOS personality.
19 #include <kernel/kern_priv.h>
20 #include <personality/example/personality.h>
21 #include <personality/example/personality_int.h>
28 #define MSG_ID_RUN_P 3
29 #define MSG_ID_RND_ISR 4
32 #define MSG_ID_FLUSH 7
33 #define MSG_ID_SEM_RPT 8
34 #define MSG_ID_RCV_RPT 9
35 #define MSG_ID_TM_RPT 10
37 typedef struct _random_isr_msg
40 unsigned random_isr_number;
44 typedef struct _data_msg
48 unsigned char checksum;
49 unsigned char data[1];
52 typedef struct _report_msg
61 const TInt KMajorVersionNumber=0;
62 const TInt KMinorVersionNumber=1;
63 const TInt KBuildVersionNumber=1;
65 void RxMsg(TAny* aPtr);
67 TPMsgQ ThePMsgQ(&RxMsg, 0, Kern::DfcQue0(), 7);
69 NONSHARABLE_CLASS(DRtosIfcFactory) : public DLogicalDevice
73 virtual TInt Install(); //overriding pure virtual
74 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
75 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
81 TRxQ(DThread* aThread) : iFirst(0), iLast(0), iStatus(0), iPtr(0), iThread(aThread) {}
82 TInt QueueReq(TRequestStatus* aStatus, TAny* aPtr);
83 void AddMsg(msghdr* aM);
84 inline TBool MsgPresent() {return iFirst!=NULL;}
91 TRequestStatus* iStatus;
96 TInt TRxQ::QueueReq(TRequestStatus* aStatus, TAny* aPtr)
107 void TRxQ::AddMsg(msghdr* aM)
119 void TRxQ::CompleteReq()
130 data_msg* dm = (data_msg*)m;
131 r = Kern::ThreadRawWrite(iThread, iPtr, &dm->length, dm->length + 5, iThread);
138 report_msg* rpt = (report_msg*)m;
139 rpt->pad = m->msg_id;
140 r = Kern::ThreadRawWrite(iThread, iPtr, &rpt->pad, sizeof(SReport), iThread);
147 Kern::RequestComplete(iThread, iStatus, r);
151 void TRxQ::CancelReq()
154 Kern::RequestComplete(iThread, iStatus, KErrCancel);
171 NONSHARABLE_CLASS(DRtosIfc) : public DLogicalChannel
177 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
178 virtual void HandleMsg(TMessageBase* aMsg);
180 TInt DoControl(TInt aFunc, TAny* a1, TAny* a2);
181 TInt DoRequest(TInt aFunc, TRequestStatus* aStatus, TAny* a1, TAny* a2);
182 void DoCancel(TInt aMask);
183 void HandleRtosMsg(msghdr* aMsg);
186 TRequestStatus* iDoneStatus;
191 void RxMsg(TAny* aPtr)
193 msghdr* m = ThePMsgQ.Get();
194 ((DRtosIfc*)aPtr)->HandleRtosMsg(m);
199 TPMsgQ::ThePMsgQ = &::ThePMsgQ;
202 assert(current_task_id() == TASK_ID_UNKNOWN);
204 kprintf("Entry point exit");
211 kprintf("Send init msg");
212 msghdr* m = (msghdr*)alloc_mem_block(sizeof(msghdr));
213 m->msg_id = MSG_ID_INIT;
214 int r = send_msg(OC_TASK, m);
220 msghdr* m = (msghdr*)alloc_mem_block(sizeof(msghdr));
221 m->msg_id = MSG_ID_FLUSH;
222 int r = send_msg(OC_TASK, m);
228 msghdr* m = (msghdr*)alloc_mem_block(sizeof(msghdr));
229 m->msg_id = MSG_ID_DONE;
230 int r = send_msg(OC_TASK, m);
234 DRtosIfcFactory::DRtosIfcFactory()
236 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
237 //iParseMask=0;//No units, no info, no PDD
238 //iUnitsMask=0;//Only one thing
241 TInt DRtosIfcFactory::Create(DLogicalChannelBase*& aChannel)
243 aChannel = new DRtosIfc;
244 return aChannel ? KErrNone : KErrNoMemory;
247 TInt DRtosIfcFactory::Install()
249 TInt r = SetName(&KRtosIfcLddName);
257 void DRtosIfcFactory::GetCaps(TDes8& aDes) const
260 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
261 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
265 : iRxQ(&Kern::CurrentThread()),
266 iRptQ(&Kern::CurrentThread())
268 iThread=&Kern::CurrentThread();
272 DRtosIfc::~DRtosIfc()
276 Kern::SafeClose((DObject*&)iThread, NULL);
279 TInt DRtosIfc::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
285 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
286 return KErrNotSupported;
289 SetDfcQ(Kern::DfcQue0());
291 ThePMsgQ.iPtr = this;
296 void DRtosIfc::HandleMsg(TMessageBase* aMsg)
298 TThreadMessage& m=*(TThreadMessage*)aMsg;
300 if (id==(TInt)ECloseMsg)
302 ThePMsgQ.CancelReceive();
303 ThePMsgQ.iPtr = NULL;
304 m.Complete(KErrNone,EFalse);
305 iMsgQ.CompleteAll(KErrServerTerminated);
308 else if (id==KMaxTInt)
312 m.Complete(KErrNone,ETrue);
319 TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
320 TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
322 Kern::RequestComplete(iThread,pS,r);
323 m.Complete(KErrNone,ETrue);
328 TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
333 TInt DRtosIfc::DoControl(TInt aFunc, TAny* a1, TAny* a2)
340 case RRtosIfc::EControlInit:
343 case RRtosIfc::EControlFlush:
346 case RRtosIfc::EControlFinish:
349 case RRtosIfc::EControlSend:
351 data_msg* dm = (data_msg*)alloc_mem_block(512);
352 TPtr8 lptr(dm->data, 0, 516-sizeof(data_msg));
353 r = Kern::ThreadDesRead(iThread, a1, lptr, 0, 0);
356 dm->header.msg_id = MSG_ID_DATA;
357 dm->length = lptr.Length();
359 send_msg(OC_TASK, &dm->header);
366 r = KErrNotSupported;
372 TInt DRtosIfc::DoRequest(TInt aFunc, TRequestStatus* aStatus, TAny* a1, TAny* a2)
378 case RRtosIfc::ERequestWaitInitialTests:
379 iDoneStatus = aStatus;
381 case RRtosIfc::ERequestReceive:
382 return iRxQ.QueueReq(aStatus, a1);
383 case RRtosIfc::ERequestReport:
384 return iRptQ.QueueReq(aStatus, a1);
386 return KErrNotSupported;
390 void DRtosIfc::DoCancel(TInt aMask)
392 if (aMask & RRtosIfc::ECancelWaitInitialTests)
394 Kern::RequestComplete(iThread, iDoneStatus, KErrCancel), iDoneStatus=NULL;
396 if (aMask & RRtosIfc::ECancelReceive)
398 if (aMask & RRtosIfc::ECancelReport)
402 void DRtosIfc::HandleRtosMsg(msghdr* aM)
408 Kern::RequestComplete(iThread, iDoneStatus, KErrNone), iDoneStatus=NULL;
429 DECLARE_STANDARD_EXTENSION()
434 DECLARE_EXTENSION_LDD()
436 return new DRtosIfcFactory;
439 DECLARE_STANDARD_LDD()
441 return new DRtosIfcFactory;