118 lines
4.0 KiB
C
Raw Normal View History

2014-10-02 10:39:09 -04:00
/*****************************************************************************
2015-04-28 13:45:35 -04:00
* Product: DPP example
2016-09-29 18:08:33 -04:00
* Last Updated for Version: 5.7.2
* Date of the Last Update: 2016-09-27
2014-10-02 10:39:09 -04:00
*
* Q u a n t u m L e a P s
* ---------------------------
* innovating embedded systems
*
2015-04-28 13:45:35 -04:00
* Copyright (C) Quantum Leaps, LLC. All rights reserved.
2014-10-02 10:39:09 -04:00
*
* This program is open source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alternatively, this program may be distributed and modified under the
* terms of Quantum Leaps commercial licenses, which expressly supersede
* the GNU General Public License and are specifically designed for
* licensees interested in retaining the proprietary status of their code.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact information:
2015-12-24 14:33:20 -05:00
* http://www.state-machine.com
* mailto:info@state-machine.com
2014-10-02 10:39:09 -04:00
*****************************************************************************/
2015-12-24 14:33:20 -05:00
#include "qpc.h"
#include "dpp.h"
#include "bsp.h"
2014-10-02 10:39:09 -04:00
2015-12-24 14:33:20 -05:00
/* local "naked" thread object .............................................*/
2016-09-23 12:08:21 -04:00
static QXThread l_test1;
static QXThread l_test2;
static QXMutex l_mutex;
static QXSemaphore l_sema;
2014-10-02 10:39:09 -04:00
2015-12-24 14:33:20 -05:00
/* global pointer to the test thread .......................................*/
2016-09-23 12:08:21 -04:00
QXThread * const XT_Test1 = &l_test1;
QXThread * const XT_Test2 = &l_test2;
2014-10-02 10:39:09 -04:00
2015-12-24 14:33:20 -05:00
/*..........................................................................*/
2016-09-23 12:08:21 -04:00
static void Thread1_run(QXThread * const me) {
2015-12-24 14:33:20 -05:00
2016-09-23 12:08:21 -04:00
QXMutex_init(&l_mutex, 3U);
2015-12-24 14:33:20 -05:00
2016-09-23 12:08:21 -04:00
(void)me;
2015-12-24 14:33:20 -05:00
for (;;) {
2016-09-23 12:08:21 -04:00
float volatile x;
2015-12-24 14:33:20 -05:00
2016-09-29 18:08:33 -04:00
/* wait on a semaphore (BLOCK with timeout) */
(void)QXSemaphore_wait(&l_sema, BSP_TICKS_PER_SEC, 0U);
2015-12-24 14:33:20 -05:00
BSP_ledOn();
2016-09-29 18:08:33 -04:00
QXMutex_lock(&l_mutex); /* exercise the mutex */
2016-09-23 12:08:21 -04:00
/* some flating point code to exercise the VFP... */
x = 1.4142135F;
x = x * 1.4142135F;
QXMutex_unlock(&l_mutex);
2016-09-29 18:08:33 -04:00
QXThread_delay(BSP_TICKS_PER_SEC/7, 0U); /* BLOCK */
2016-09-23 12:08:21 -04:00
/* publish to thread2 */
QF_PUBLISH(Q_NEW(QEvt, TEST_SIG), &l_test1);
}
}
/*..........................................................................*/
void Test1_ctor(void) {
QXThread_ctor(&l_test1, Q_XTHREAD_CAST(&Thread1_run), 0U);
}
/*..........................................................................*/
static void Thread2_run(QXThread * const me) {
/* subscribe to the test signal */
QActive_subscribe(&me->super, TEST_SIG);
/* initialize the semaphore before using it
* NOTE: the semaphore is initialized in the highest-priority thread
* that uses it. Alternatively, the semaphore can be initialized
* before any thread runs.
*/
QXSemaphore_init(&l_sema, 0U); /* start with zero count */
for (;;) {
QEvt const *e;
/* some flating point code to exercise the VFP... */
2016-09-29 18:08:33 -04:00
float volatile x;
2016-09-23 12:08:21 -04:00
x = 1.4142135F;
x = x * 1.4142135F;
2016-09-29 18:08:33 -04:00
/* wait on the internal event queue (BLOCK) with timeout */
e = QXThread_queueGet(BSP_TICKS_PER_SEC/2, 0U);
2015-12-24 14:33:20 -05:00
BSP_ledOff();
2016-09-23 12:08:21 -04:00
2016-09-29 18:08:33 -04:00
if (e != (QEvt *)0) { /* event actually delivered? */
QF_gc(e); /* recycle the event manually! */
}
else {
QXThread_delay(BSP_TICKS_PER_SEC/2, 0U); /* wait more (BLOCK) */
QXSemaphore_signal(&l_sema); /* signal Thread1 */
}
2015-12-24 14:33:20 -05:00
}
}
/*..........................................................................*/
2016-09-23 12:08:21 -04:00
void Test2_ctor(void) {
QXThread_ctor(&l_test2, Q_XTHREAD_CAST(&Thread2_run), 0U);
2015-12-24 14:33:20 -05:00
}