QP/C++
qte_arm.cpp
Go to the documentation of this file.
00001 
00002 // Product: QF/C++
00003 // Last Updated for Version: 4.4.00
00004 // Date of the Last Update:  Mar 28, 2012
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
00011 //
00012 // This program is open source software: you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as published
00014 // by the Free Software Foundation, either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // Alternatively, this program may be distributed and modified under the
00018 // terms of Quantum Leaps commercial licenses, which expressly supersede
00019 // the GNU General Public License and are specifically designed for
00020 // licensees interested in retaining the proprietary status of their code.
00021 //
00022 // This program is distributed in the hope that it will be useful,
00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00025 // GNU General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with this program. If not, see <http://www.gnu.org/licenses/>.
00029 //
00030 // Contact information:
00031 // Quantum Leaps Web sites: http://www.quantum-leaps.com
00032 //                          http://www.state-machine.com
00033 // e-mail:                  info@quantum-leaps.com
00035 #include "qf_pkg.h"
00036 #include "qassert.h"
00037 
00041 
00042 QP_BEGIN_
00043 
00044 Q_DEFINE_THIS_MODULE("qte_arm")
00045 
00046 // Package-scope objects -----------------------------------------------------
00047 QTimeEvt *QF_timeEvtListHead_;           // head of linked list of time events
00048 
00049 //............................................................................
00050 bool QF::noTimeEvtsActive(void) {
00051     return QF_timeEvtListHead_ == null_tevt;
00052 }
00053 //............................................................................
00054 void QTimeEvt::arm_(QActive * const act, QTimeEvtCtr const nTicks) {
00055     Q_REQUIRE((nTicks > tc_0)                    /* cannot arm with 0 ticks */
00056               && (static_cast<enum_t>(sig) >= Q_USER_SIG)   /* valid signal */
00057               && (m_prev == null_tevt)       /* time event must NOT be used */
00058               && (act != null_act));         // Active object must be provided
00059     m_ctr  = nTicks;
00060     m_prev = this;                                   // mark the timer in use
00061     m_act  = act;
00062     QF_CRIT_STAT_
00063     QF_CRIT_ENTRY_();
00064 
00065     QS_BEGIN_NOCRIT_(QS_QF_TIMEEVT_ARM, QS::teObj_, this)
00066         QS_TIME_();                                               // timestamp
00067         QS_OBJ_(this);                               // this time event object
00068         QS_OBJ_(act);                                     // the active object
00069         QS_TEC_(nTicks);                                // the number of ticks
00070         QS_TEC_(m_interval);                                   // the interval
00071     QS_END_NOCRIT_()
00072 
00073     m_next = QF_timeEvtListHead_;
00074     if (QF_timeEvtListHead_ != null_tevt) {
00075         QF_timeEvtListHead_->m_prev = this;
00076     }
00077     QF_timeEvtListHead_ = this;
00078     QF_CRIT_EXIT_();
00079 }
00080 
00081 QP_END_
00082