QP/C
qa_get_.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product: QF/C
00003 * Last Updated for Version: 4.5.00
00004 * Date of the Last Update:  May 18, 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
00034 *****************************************************************************/
00035 #include "qf_pkg.h"
00036 #include "qassert.h"
00037 
00038 Q_DEFINE_THIS_MODULE("qa_get_")
00039 
00040 
00049 /*..........................................................................*/
00050 QEvt const *QActive_get_(QActive * const me) {
00051     QEvt const *e;
00052     QF_CRIT_STAT_
00053     QF_CRIT_ENTRY_();
00054 
00055     QACTIVE_EQUEUE_WAIT_(me);          /* wait for event to arrive directly */
00056 
00057     e = me->eQueue.frontEvt;
00058 
00059     if (me->eQueue.nFree != me->eQueue.end) {  /* any events in the buffer? */
00060                                               /* remove event from the tail */
00061         me->eQueue.frontEvt = QF_PTR_AT_(me->eQueue.ring, me->eQueue.tail);
00062         if (me->eQueue.tail == (QEQueueCtr)0) {   /* need to wrap the tail? */
00063             me->eQueue.tail = me->eQueue.end;                /* wrap around */
00064         }
00065         --me->eQueue.tail;
00066 
00067         ++me->eQueue.nFree;       /* one more free event in the ring buffer */
00068 
00069         QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_GET, QS_aoObj_, me)
00070             QS_TIME_();                                        /* timestamp */
00071             QS_SIG_(e->sig);                    /* the signal of this event */
00072             QS_OBJ_(me);                              /* this active object */
00073             QS_U8_(QF_EVT_POOL_ID_(e));         /* the pool Id of the event */
00074             QS_U8_(QF_EVT_REF_CTR_(e));       /* the ref count of the event */
00075             QS_EQC_(me->eQueue.nFree);            /* number of free entries */
00076         QS_END_NOCRIT_()
00077     }
00078     else {
00079         me->eQueue.frontEvt = (QEvt const *)0;     /* queue becomes empty */
00080         QACTIVE_EQUEUE_ONEMPTY_(me);
00081 
00082         QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_GET_LAST, QS_aoObj_, me)
00083             QS_TIME_();                                        /* timestamp */
00084             QS_SIG_(e->sig);                    /* the signal of this event */
00085             QS_OBJ_(me);                              /* this active object */
00086             QS_U8_(QF_EVT_POOL_ID_(e));         /* the pool Id of the event */
00087             QS_U8_(QF_EVT_REF_CTR_(e));       /* the ref count of the event */
00088         QS_END_NOCRIT_()
00089     }
00090     QF_CRIT_EXIT_();
00091     return e;
00092 }
00093 /*..........................................................................*/
00094 uint32_t QF_getQueueMargin(uint8_t const prio) {
00095     uint32_t margin;
00096     QF_CRIT_STAT_
00097 
00098     Q_REQUIRE((prio <= (uint8_t)QF_MAX_ACTIVE)
00099               && (QF_active_[prio] != (QActive *)0));
00100 
00101     QF_CRIT_ENTRY_();
00102     margin = (uint32_t)QF_active_[prio]->eQueue.nMin;
00103     QF_CRIT_EXIT_();
00104 
00105     return margin;
00106 }