Skip to content

Commit f702948

Browse files
prepare for QP v8.x.x
1 parent 6906d66 commit f702948

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

cpputest-for-qpcpp-lib/src/cpputest_qf_port.cpp

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
/// @endcond
77
///
88

9-
#define QP_IMPL // this is QP implementation
10-
#include "qp_port.hpp" // QF port
11-
#include "qp_pkg.hpp" // QF package-scope interface
12-
#include "qsafe.h" // QP embedded systems-friendly assertions
13-
#ifdef Q_SPY // QS software tracing enabled?
9+
#define QP_IMPL // this is QP implementation
10+
#include "qp_port.hpp" // QF port
11+
#include "qp_pkg.hpp" // QF package-scope interface
12+
#include "qsafe.h" // QP embedded systems-friendly assertions
13+
#ifdef Q_SPY // QS software tracing enabled?
1414
#error "Q_SPY not supported in the cpputest port"
1515
#else
1616
#include "qs_dummy.hpp" // disable the QS software tracing
@@ -39,25 +39,42 @@ int_t QF::run()
3939
}
4040
#endif
4141

42+
/**
43+
* Fake cpputest event loop for QActive. Only loops
44+
* until queue is empty, then removes it from the
45+
* ready set.
46+
* @param act an active object to run an event loop upon.
47+
*/
48+
void QActive::evtLoop_(QActive* act)
49+
{
50+
while (!act->m_eQueue.isEmpty()) {
51+
QEvt const* e = act->get_();
52+
act->dispatch(e, act->m_prio);
53+
QF::gc(e);
54+
}
55+
56+
if (act->m_eQueue.isEmpty()) {
57+
cpputest_readySet_.remove(act->m_prio);
58+
}
59+
}
60+
4261
void RunUntilNoReadyActiveObjects()
4362
{
4463
while (cpputest_readySet_.notEmpty()) {
4564
std::uint_fast8_t p = cpputest_readySet_.findMax();
65+
#if QP_VERSION > 800
66+
QActive* a = QP::QActive::fromRegistry(p);
67+
#elif QP_VERSION > 700
4668
QActive* a = QP::QActive::registry_[p];
69+
#else
70+
#error "unsupported QP version"
71+
#endif
4772

4873
// the active object 'a' must still be registered in QF
4974
// (e.g., it must not be stopped)
5075
Q_ASSERT_ID(320, a != nullptr);
5176

52-
while (!a->getEQueue().isEmpty()) {
53-
const auto e = a->get_();
54-
a->dispatch(e, 0);
55-
QF::gc(e);
56-
}
57-
58-
if (a->getEQueue().isEmpty()) { /* empty queue? */
59-
cpputest_readySet_.remove(p);
60-
}
77+
QActive::evtLoop_(a);
6178
}
6279
}
6380

@@ -68,23 +85,22 @@ void QF::stop()
6885
}
6986

7087
//****************************************************************************
71-
void QActive::start( QPrioSpec const prioSpec,
72-
QEvt const * * const qSto, std::uint_fast16_t const qLen,
73-
void * const stkSto, std::uint_fast16_t const stkSize,
74-
void const * const par)
88+
void QActive::start(QPrioSpec const prioSpec, QEvt const** const qSto,
89+
std::uint_fast16_t const qLen, void* const stkSto,
90+
std::uint_fast16_t const stkSize, void const* const par)
7591
{
7692
// unused parameters in the cpputest port
7793
Q_UNUSED_PAR(stkSto);
7894
Q_UNUSED_PAR(stkSize);
7995

80-
m_prio = static_cast<std::uint8_t>(prioSpec & 0xFFU); // QF-priority
81-
m_pthre = static_cast<std::uint8_t>(prioSpec >> 8U); // preemption-thre.
82-
register_(); // make QF aware of this AO
96+
m_prio = static_cast<std::uint8_t>(prioSpec & 0xFFU); // QF-priority
97+
m_pthre = static_cast<std::uint8_t>(prioSpec >> 8U); // preemption-thre.
98+
register_(); // make QF aware of this AO
8399

84100
m_eQueue.init(qSto, qLen);
85101

86-
this->init(par, m_prio); // execute initial transition (virtual call)
87-
QS_FLUSH(); // flush the QS trace buffer to the host
102+
this->init(par, m_prio); // execute initial transition (virtual call)
103+
QS_FLUSH(); // flush the QS trace buffer to the host
88104
}
89105

90106
//............................................................................

0 commit comments

Comments
 (0)