|
QP/C
|
00001 /***************************************************************************** 00002 * Product: QF/C platform-independent public interface 00003 * Last Updated for Version: 4.4.00 00004 * Date of the Last Update: Jan 17, 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 software may be distributed and modified under the terms of the GNU 00013 * General Public License version 2 (GPL) as published by the Free Software 00014 * Foundation and appearing in the file GPL.TXT included in the packaging of 00015 * this file. Please note that GPL Section 2[b] requires that all works based 00016 * on this software must also be made publicly available under the terms of 00017 * the GPL ("Copyleft"). 00018 * 00019 * Alternatively, this software may be distributed and modified under the 00020 * terms of Quantum Leaps commercial licenses, which expressly supersede 00021 * the GPL and are specifically designed for licensees interested in 00022 * retaining the proprietary status of their code. 00023 * 00024 * Contact information: 00025 * Quantum Leaps Web site: http://www.quantum-leaps.com 00026 * e-mail: info@quantum-leaps.com 00027 *****************************************************************************/ 00028 #ifndef qf_h 00029 #define qf_h 00030 00040 /****************************************************************************/ 00041 #if (QF_MAX_ACTIVE < 1) || (63 < QF_MAX_ACTIVE) 00042 #error "QF_MAX_ACTIVE not defined or out of range. Valid range is 1..63" 00043 #endif 00044 00045 /****************************************************************************/ 00046 #ifndef QF_EVENT_SIZ_SIZE 00047 00049 #define QF_EVENT_SIZ_SIZE 2 00050 #endif 00051 #if (QF_EVENT_SIZ_SIZE == 1) 00052 00058 typedef uint8_t QEventSize; 00059 #elif (QF_EVENT_SIZ_SIZE == 2) 00060 typedef uint16_t QEventSize; 00061 #elif (QF_EVENT_SIZ_SIZE == 4) 00062 typedef uint32_t QEventSize; 00063 #else 00064 #error "QF_EVENT_SIZ_SIZE defined incorrectly, expected 1, 2, or 4" 00065 #endif 00066 00067 /****************************************************************************/ 00068 #ifndef QF_MAX_EPOOL 00069 00071 #define QF_MAX_EPOOL 3 00072 #endif 00073 00074 /****************************************************************************/ 00075 #ifndef QF_ACTIVE_SUPER_ 00076 00094 #define QF_ACTIVE_SUPER_ QHsm 00095 00099 #define QF_ACTIVE_CTOR_(me_, initial_) QHsm_ctor((me_), (initial_)) 00100 00104 #define QF_ACTIVE_INIT_(me_, e_) QHsm_init((me_), (e_)) 00105 00109 #define QF_ACTIVE_DISPATCH_(me_, e_) QHsm_dispatch((me_), (e_)) 00110 00113 #define QF_ACTIVE_STATE_ QStateHandler 00114 00115 #endif 00116 00117 struct QEQueueTag; /* forward declaration */ 00118 00119 /****************************************************************************/ 00140 typedef struct QActiveTag { 00144 QF_ACTIVE_SUPER_ super; 00145 00156 QF_EQUEUE_TYPE eQueue; 00157 00158 #ifdef QF_OS_OBJECT_TYPE 00159 00166 QF_OS_OBJECT_TYPE osObject; 00167 #endif 00168 00169 #ifdef QF_THREAD_TYPE 00170 00176 QF_THREAD_TYPE thread; 00177 #endif 00178 00182 uint8_t prio; 00183 00193 uint8_t running; 00194 } QActive; 00195 00196 /* public functions */ 00224 void QActive_start(QActive *me, uint8_t prio, 00225 QEvent const *qSto[], uint32_t qLen, 00226 void *stkSto, uint32_t stkSize, 00227 QEvent const *ie); 00228 00229 #ifdef Q_SPY 00230 00251 void QActive_postFIFO(QActive *me, QEvent const *e, 00252 void const *sender); 00253 00254 00275 #define QACTIVE_POST(me_, e_, sender_) \ 00276 QActive_postFIFO((me_), (e_), (sender_)) 00277 00278 #else 00279 00280 void QActive_postFIFO(QActive *me, QEvent const *e); 00281 #define QACTIVE_POST(me_, e_, dummy_) QActive_postFIFO((me_), (e_)) 00282 00283 #endif 00284 00293 void QActive_postLIFO(QActive *me, QEvent const *e); 00294 00295 /* protected functions ...*/ 00296 00313 #define QActive_ctor(me_, initial_) QF_ACTIVE_CTOR_(&(me_)->super, (initial_)) 00314 00328 void QActive_stop(QActive *me); 00329 00344 void QActive_subscribe(QActive const *me, QSignal sig); 00345 00365 void QActive_unsubscribe(QActive const *me, QSignal sig); 00366 00386 void QActive_unsubscribeAll(QActive const *me); 00387 00388 00403 void QActive_defer(QActive *me, QEQueue *eq, QEvent const *e); 00404 00421 uint8_t QActive_recall(QActive *me, QEQueue *eq); 00422 00433 QEvent const *QActive_get_(QActive *me); 00434 /* friend class QF; */ 00435 /* friend class QTimeEvt; */ 00436 00437 /****************************************************************************/ 00438 #ifndef QF_TIMEEVT_CTR_SIZE 00439 00442 #define QF_TIMEEVT_CTR_SIZE 2 00443 #endif 00444 #if (QF_TIMEEVT_CTR_SIZE == 1) 00445 00455 typedef uint8_t QTimeEvtCtr; 00456 #elif (QF_TIMEEVT_CTR_SIZE == 2) 00457 typedef uint16_t QTimeEvtCtr; 00458 #elif (QF_TIMEEVT_CTR_SIZE == 4) 00459 typedef uint32_t QTimeEvtCtr; 00460 #else 00461 #error "QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1, 2, or 4" 00462 #endif 00463 00497 typedef struct QTimeEvtTag { 00501 QEvent super; 00502 00505 struct QTimeEvtTag *prev; 00506 00509 struct QTimeEvtTag *next; 00510 00513 QActive *act; 00514 00519 QTimeEvtCtr ctr; 00520 00526 QTimeEvtCtr interval; 00527 } QTimeEvt; 00528 00529 /* public functions */ 00530 00544 void QTimeEvt_ctor(QTimeEvt *me, QSignal sig); 00545 00564 #define QTimeEvt_postIn(me_, act_, nTicks_) do { \ 00565 (me_)->interval = (QTimeEvtCtr)0; \ 00566 QTimeEvt_arm_((me_), (act_), (nTicks_)); \ 00567 } while (0) 00568 00590 #define QTimeEvt_postEvery(me_, act_, nTicks_) do { \ 00591 (me_)->interval = (nTicks_); \ 00592 QTimeEvt_arm_((me_), (act_), (nTicks_)); \ 00593 } while (0) 00594 00606 uint8_t QTimeEvt_disarm(QTimeEvt *me); 00607 00625 uint8_t QTimeEvt_rearm(QTimeEvt *me, QTimeEvtCtr nTicks); 00626 00635 QTimeEvtCtr QTimeEvt_ctr(QTimeEvt const *me); 00636 00637 /* private functions */ 00638 00644 void QTimeEvt_arm_(QTimeEvt *me, QActive *act, QTimeEvtCtr nTicks); 00645 00646 /* friend class QF; */ 00647 00648 /***************************************************************************** 00649 * QF facilities 00650 */ 00651 00660 typedef struct QSubscrListTag { 00661 00671 uint8_t bits[((QF_MAX_ACTIVE - 1) / 8) + 1]; 00672 } QSubscrList; 00673 00674 /* public functions */ 00675 00681 void QF_init(void); 00682 00707 void QF_psInit(QSubscrList *subscrSto, QSignal maxSignal); 00708 00740 void QF_poolInit(void *poolSto, uint32_t poolSize, QEventSize evtSize); 00741 00762 void QF_run(void); 00763 00782 void QF_stop(void); 00783 00790 void QF_onStartup(void); 00791 00805 void QF_onCleanup(void); 00806 00830 void QF_onIdle(void); 00831 00832 #ifdef Q_SPY 00833 00848 void QF_publish(QEvent const *e, void const *sender); 00849 00869 #define QF_PUBLISH(e_, sender_) QF_publish((e_), (sender_)) 00870 00871 #else 00872 00873 void QF_publish(QEvent const *e); 00874 #define QF_PUBLISH(e_, dummy_) QF_publish(e_) 00875 00876 #endif 00877 00878 #ifdef Q_SPY 00879 00894 void QF_tick(void const *sender); 00895 00915 #define QF_TICK(sender_) QF_tick(sender_) 00916 00917 #else 00918 00919 void QF_tick(void); 00920 #define QF_TICK(dummy_) QF_tick() 00921 00922 #endif 00923 00924 /* functions used in the QF ports only -------------------------------------*/ 00925 00937 void QF_add_(QActive *a); 00938 00951 void QF_remove_(QActive const *a); 00952 00963 char_t const Q_ROM * Q_ROM_VAR QF_getVersion(void); 00964 00974 char_t const Q_ROM * Q_ROM_VAR QF_getPortVersion(void); 00975 00988 uint32_t QF_getPoolMargin(uint8_t poolId); 00989 01002 uint32_t QF_getQueueMargin(uint8_t prio); 01003 01009 QEvent *QF_new_(QEventSize evtSize, QSignal sig); 01010 01024 #define Q_NEW(evtT_, sig_) \ 01025 ((evtT_ *)QF_new_((QEventSize)sizeof(evtT_), (QSignal)(sig_))) 01026 01048 void QF_gc(QEvent const *e); 01049 01058 extern uint8_t const Q_ROM Q_ROM_VAR QF_log2Lkup[256]; 01059 01065 extern uint8_t const Q_ROM Q_ROM_VAR QF_pwr2Lkup[65]; 01066 01072 extern uint8_t const Q_ROM Q_ROM_VAR QF_invPwr2Lkup[65]; 01073 01078 extern uint8_t const Q_ROM Q_ROM_VAR QF_div8Lkup[65]; 01079 01080 01085 extern QActive *QF_active_[]; 01086 01087 #endif /* qf_h */
1.7.6.1