2013-10-10 20:01:51 -04:00
|
|
|
//****************************************************************************
|
|
|
|
// Product: BSP for DPP-GUI example with Qt5
|
2015-09-29 11:34:38 -04:00
|
|
|
// Last Updated for Version: QP/C++ 5.5.0/Qt 5.x
|
|
|
|
// Last updated on 2015-09-26
|
2012-08-14 18:00:48 -04:00
|
|
|
//
|
|
|
|
// Q u a n t u m L e a P s
|
|
|
|
// ---------------------------
|
|
|
|
// innovating embedded systems
|
|
|
|
//
|
2015-09-29 11:34:38 -04:00
|
|
|
// Copyright (C) Quantum Leaps, LLC. All rights reserved.
|
2012-08-14 18:00:48 -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
|
2013-10-16 16:46:00 -04:00
|
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
2012-08-14 18:00:48 -04:00
|
|
|
// (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-09-29 11:34:38 -04:00
|
|
|
// http://www.state-machine.com
|
|
|
|
// mailto:info@state-machine.com
|
2013-10-10 20:01:51 -04:00
|
|
|
//****************************************************************************
|
|
|
|
#include <QtWidgets>
|
2012-08-14 18:00:48 -04:00
|
|
|
#include "gui.h"
|
|
|
|
//-----------------
|
2015-09-29 11:34:38 -04:00
|
|
|
#include "qpcpp.h"
|
2012-08-14 18:00:48 -04:00
|
|
|
#include "dpp.h"
|
|
|
|
#include "bsp.h"
|
|
|
|
|
2013-10-10 20:01:51 -04:00
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
|
2012-08-14 18:00:48 -04:00
|
|
|
#ifdef Q_SPY
|
|
|
|
enum {
|
|
|
|
PHILO_STAT = QP::QS_USER
|
|
|
|
};
|
2015-05-14 16:05:04 -04:00
|
|
|
static uint8_t const l_time_tick = 0U; // for QS
|
2012-08-14 18:00:48 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//............................................................................
|
2015-05-14 16:05:04 -04:00
|
|
|
static uint32_t l_rnd; // random seed
|
2012-08-14 18:00:48 -04:00
|
|
|
|
|
|
|
//............................................................................
|
2013-10-10 20:01:51 -04:00
|
|
|
void QP::QF_onClockTick(void) {
|
|
|
|
QP::QF::TICK_X(0U, &l_time_tick);
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void QP::QF::onStartup(void) {
|
|
|
|
QP::QF_setTickRate(BSP_TICKS_PER_SEC);
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void QP::QF::onCleanup(void) {
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void BSP_init(void) {
|
|
|
|
Q_ALLEGE(QS_INIT((char *)0));
|
2014-04-21 21:48:04 -04:00
|
|
|
QS_RESET();
|
2012-08-14 18:00:48 -04:00
|
|
|
QS_OBJ_DICTIONARY(&l_time_tick);
|
|
|
|
QS_USR_DICTIONARY(PHILO_STAT);
|
|
|
|
|
|
|
|
BSP_randomSeed(1234U);
|
|
|
|
}
|
|
|
|
//............................................................................
|
2013-10-10 20:01:51 -04:00
|
|
|
void BSP_terminate(int) {
|
2012-08-14 18:00:48 -04:00
|
|
|
qDebug("terminate");
|
2015-05-14 16:05:04 -04:00
|
|
|
QP::QF::stop(); // stop the QF::run() thread
|
|
|
|
qApp->quit(); // quit the Qt application *after* the QF_run() has stopped
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void BSP_displayPhilStat(uint8_t n, char_t const *stat) {
|
|
|
|
|
|
|
|
static QLabel * const philoLabel[] = {
|
|
|
|
Gui::instance()->m_philoLabel_0,
|
|
|
|
Gui::instance()->m_philoLabel_1,
|
|
|
|
Gui::instance()->m_philoLabel_2,
|
|
|
|
Gui::instance()->m_philoLabel_3,
|
|
|
|
Gui::instance()->m_philoLabel_4
|
|
|
|
};
|
|
|
|
static QPixmap thinking(":/res/thinking.png");
|
|
|
|
static QPixmap hungry (":/res/hungry.png");
|
|
|
|
static QPixmap eating (":/res/eating.png");
|
|
|
|
|
|
|
|
Q_REQUIRE(n < Q_DIM(philoLabel));
|
|
|
|
|
|
|
|
switch (stat[0]) {
|
|
|
|
case 't':
|
|
|
|
philoLabel[n]->setPixmap(thinking);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
philoLabel[n]->setPixmap(hungry);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
philoLabel[n]->setPixmap(eating);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("philo[%d] is %s", n, stat);
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void BSP_displayPaused(uint8_t paused) {
|
|
|
|
if (paused != 0U) {
|
|
|
|
qDebug("PAUSED");
|
|
|
|
Gui::instance()->m_pauseButton->setText("PAUSED");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug("SERVING");
|
|
|
|
Gui::instance()->m_pauseButton->setText("SERVING");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
uint32_t BSP_random(void) { // a very cheap pseudo-random-number generator
|
|
|
|
// "Super-Duper" Linear Congruential Generator (LCG)
|
|
|
|
// LCG(2^32, 3*7*11*13*23, 0, seed)
|
|
|
|
l_rnd = l_rnd * (3*7*11*13*23);
|
|
|
|
return l_rnd >> 8;
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void BSP_randomSeed(uint32_t seed) {
|
|
|
|
l_rnd = seed;
|
|
|
|
}
|
|
|
|
//............................................................................
|
2015-09-29 11:34:38 -04:00
|
|
|
void Q_onAssert(char_t const * const module, int_t loc) {
|
2012-08-14 18:00:48 -04:00
|
|
|
QMessageBox::critical(0, "PROBLEM",
|
|
|
|
QString("<p>Assertion failed in module <b>%1</b>,"
|
2015-09-29 11:34:38 -04:00
|
|
|
"location <b>%2</b></p>")
|
|
|
|
.arg(module)
|
|
|
|
.arg(loc));
|
|
|
|
QS_ASSERTION(module, loc, 10000); // send assertion info to the QS trace
|
|
|
|
qFatal("Assertion failed in module %s, location %d", module, loc);
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
|
2013-10-10 20:01:51 -04:00
|
|
|
//****************************************************************************
|
2012-08-14 18:00:48 -04:00
|
|
|
#ifdef Q_SPY
|
|
|
|
|
|
|
|
#include "qspy.h"
|
|
|
|
|
|
|
|
static QTime l_time;
|
|
|
|
|
|
|
|
//............................................................................
|
|
|
|
static int custParserFun(QSpyRecord * const qrec) {
|
2015-05-14 16:05:04 -04:00
|
|
|
int ret = 1; // perform standard QSPY parsing
|
2012-08-14 18:00:48 -04:00
|
|
|
switch (qrec->rec) {
|
2015-05-14 16:05:04 -04:00
|
|
|
case QP::QS_QF_MPOOL_GET: { // example record to parse
|
2012-08-14 18:00:48 -04:00
|
|
|
int nFree;
|
|
|
|
(void)QSpyRecord_getUint32(qrec, QS_TIME_SIZE);
|
|
|
|
(void)QSpyRecord_getUint64(qrec, QS_OBJ_PTR_SIZE);
|
|
|
|
nFree = (int)QSpyRecord_getUint32(qrec, QF_MPOOL_CTR_SIZE);
|
2015-05-14 16:05:04 -04:00
|
|
|
(void)QSpyRecord_getUint32(qrec, QF_MPOOL_CTR_SIZE); // nMin
|
2012-08-14 18:00:48 -04:00
|
|
|
if (QSpyRecord_OK(qrec)) {
|
|
|
|
Gui::instance()->m_epoolLabel->setText(QString::number(nFree));
|
2015-05-14 16:05:04 -04:00
|
|
|
ret = 0; // don't perform standard QSPY parsing
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
//............................................................................
|
2013-10-10 20:01:51 -04:00
|
|
|
bool QP::QS::onStartup(void const *) {
|
2015-05-14 16:05:04 -04:00
|
|
|
static uint8_t qsBuf[4*1024]; // 4K buffer for Quantum Spy
|
2012-08-14 18:00:48 -04:00
|
|
|
initBuf(qsBuf, sizeof(qsBuf));
|
|
|
|
|
2013-10-10 20:01:51 -04:00
|
|
|
QSPY_config(QP_VERSION, // version
|
2012-08-14 18:00:48 -04:00
|
|
|
QS_OBJ_PTR_SIZE, // objPtrSize
|
|
|
|
QS_FUN_PTR_SIZE, // funPtrSize
|
|
|
|
QS_TIME_SIZE, // tstampSize
|
|
|
|
Q_SIGNAL_SIZE, // sigSize,
|
|
|
|
QF_EVENT_SIZ_SIZE, // evtSize
|
|
|
|
QF_EQUEUE_CTR_SIZE, // queueCtrSize
|
|
|
|
QF_MPOOL_CTR_SIZE, // poolCtrSize
|
|
|
|
QF_MPOOL_SIZ_SIZE, // poolBlkSize
|
|
|
|
QF_TIMEEVT_CTR_SIZE,// tevtCtrSize
|
|
|
|
(void *)0, // matFile,
|
|
|
|
(void *)0,
|
|
|
|
&custParserFun); // customized parser function
|
|
|
|
|
|
|
|
l_time.start(); // start the time stamp
|
|
|
|
|
2015-05-14 16:05:04 -04:00
|
|
|
// set up the QS filters...
|
|
|
|
QS_FILTER_ON(QS_QF_MPOOL_GET);
|
|
|
|
|
|
|
|
return true; // success
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void QP::QS::onCleanup(void) {
|
|
|
|
QSPY_stop();
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
void QP::QS::onFlush(void) {
|
|
|
|
uint16_t nBytes = 1024U;
|
|
|
|
uint8_t const *block;
|
2015-05-14 16:05:04 -04:00
|
|
|
while ((block = getBlock(&nBytes)) != static_cast<uint8_t *>(0)) {
|
2012-08-14 18:00:48 -04:00
|
|
|
QSPY_parse(block, nBytes);
|
|
|
|
nBytes = 1024U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
QP::QSTimeCtr QP::QS::onGetTime(void) {
|
2015-05-14 16:05:04 -04:00
|
|
|
return static_cast<QSTimeCtr>(l_time.elapsed());
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
2015-09-29 11:34:38 -04:00
|
|
|
//............................................................................
|
|
|
|
//! callback function to reset the target (to be implemented in the BSP)
|
|
|
|
void QP::QS::onReset(void) {
|
|
|
|
//TBD
|
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
//! callback function to execute a uesr command (to be implemented in BSP)
|
|
|
|
void QP::QS::onCommand(uint8_t cmdId, uint32_t param) {
|
|
|
|
(void)cmdId;
|
|
|
|
(void)param;
|
|
|
|
//TBD
|
|
|
|
}
|
2012-08-14 18:00:48 -04:00
|
|
|
|
|
|
|
//............................................................................
|
|
|
|
void QP::QS_onEvent(void) {
|
2013-10-10 20:01:51 -04:00
|
|
|
uint16_t nBytes = 1024;
|
2012-08-14 18:00:48 -04:00
|
|
|
uint8_t const *block;
|
|
|
|
QF_CRIT_ENTRY(dummy);
|
2015-05-14 16:05:04 -04:00
|
|
|
if ((block = QS::getBlock(&nBytes)) != static_cast<uint8_t *>(0)) {
|
2012-08-14 18:00:48 -04:00
|
|
|
QF_CRIT_EXIT(dummy);
|
|
|
|
QSPY_parse(block, nBytes);
|
|
|
|
}
|
2013-10-10 20:01:51 -04:00
|
|
|
else {
|
|
|
|
QF_CRIT_EXIT(dummy);
|
|
|
|
}
|
2012-08-14 18:00:48 -04:00
|
|
|
}
|
|
|
|
//............................................................................
|
|
|
|
extern "C" void QSPY_onPrintLn(void) {
|
|
|
|
qDebug(QSPY_line);
|
|
|
|
}
|
|
|
|
|
2015-05-14 16:05:04 -04:00
|
|
|
#endif // Q_SPY
|