11.07.2015 Views

QP and Win32 - Quantum Leaps

QP and Win32 - Quantum Leaps

QP and Win32 - Quantum Leaps

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Application Note:<strong>QP</strong>/QM <strong>and</strong> <strong>Win32</strong> (Windows)state-machine.com/win32/*..........................................................................*/void QF_init(void) {(2) InitializeCriticalSection(&l_win32CritSect);}/*..........................................................................*/void QF_enterCriticalSection_(void) {(3) EnterCriticalSection(&l_win32CritSect);}/*..........................................................................*/void QF_leaveCriticalSection_(void) {(4) LeaveCriticalSection(&l_win32CritSect);}/*..........................................................................*/void QF_stop(void) {l_running = (uint8_t)0;}/*..........................................................................*/(5) int16_t QF_run(void) {(6) QF_onStartup(); /* startup callback *//* raise the priority of this (main) thread to tick more timely */(7) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);l_running = (uint8_t)1;while (l_running) {(8) Sleep(l_tickMsec); /* wait for the tick interval */(9) QF_onClockTick(); /* clock tick callback (must call QF_TICK()) */}(10) QF_onCleanup(); /* cleanup callback */QS_EXIT(); /* cleanup the QSPY connection *///DeleteCriticalSection(&l_win32CritSect);return (int16_t)0; /* return success */}/*..........................................................................*/void QF_setTickRate(uint32_t ticksPerSec) {l_tickMsec = 1000UL / ticksPerSec;}/*..........................................................................*/(11) void QActive_start(QActive * const me, uint8_t prio,QEvt const *qSto[], uint32_t qLen,void *stkSto, uint32_t stkSize,QEvt const *ie){DWORD threadId;int p;Q_REQUIRE((qSto != (QEvt const **)0) /* queue storage must be provided */&& (stkSto == (void *)0)); /* Windows allocates stack internally */me->prio = prio;QF_add_(me); /* make QF aware of this active object */(12) QEQueue_init(&me->eQueue, qSto, (QEQueueCtr)qLen);(13) me->osObject = CreateEvent(NULL, FALSE, FALSE, NULL);(14) QF_ACTIVE_INIT_(&me->super, ie); /* execute initial transition */Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.16 of 42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!