コード例 #1
0
ファイル: qf_main.c プロジェクト: KnightSch/qpc
int main(void) {
    static QEvt const *l_tableQueueSto[N_PHILO];
    static QEvt const *l_philoQueueSto[N_PHILO][N_PHILO];
    static QSubscrList l_subscrSto[MAX_PUB_SIG];

    /* storage for event pools... */
    static QF_MPOOL_EL(TableEvt) l_smlPoolSto[2*N_PHILO]; /* small pool */

    uint8_t n;

    Philo_ctor(); /* instantiate all Philosopher active objects */
    Table_ctor(); /* instantiate the Table active object */

    QF_init();  /* initialize the framework and the underlying RT kernel */
    BSP_init(); /* initialize the BSP */

    /* send object dictionaries for event pools... */
    QS_OBJ_DICTIONARY(l_smlPoolSto);

   /* init publish-subscribe... */
    QF_psInit(l_subscrSto, Q_DIM(l_subscrSto));

    /* initialize event pools... */
    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));

    /* start the active objects... */
    for (n = 0; n < N_PHILO; ++n) {
        QACTIVE_START(AO_Philo[n], (uint8_t)(n + 1),
                      l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
                      (void *)0, 0U, (QEvt *)0);
    }
    QACTIVE_START(AO_Table, (uint8_t)(N_PHILO + 1),
                  l_tableQueueSto, Q_DIM(l_tableQueueSto),
                  (void *)0, 0U, (QEvt *)0);

    return QF_run(); /* run the QF application, QF_run() does not return  */
}
コード例 #2
0
/* Common Gateway Iinterface (CG) handler ..................................*/
static char const *cgi_display(int index, int numParams,
                               char const *param[],
                               char const *value[])
{
    int i;
    for (i = 0; i < numParams; ++i) {
        if (strstr(param[i], "text") != (char *)0) {   /* param text found? */
            TextEvt *te = Q_NEW(TextEvt, DISPLAY_CGI_SIG);
            strncpy(te->text, value[i], Q_DIM(te->text));
            QF_PUBLISH((QEvt *)te, AO_LwIPMgr);
            return "/thank_you.htm";
        }
    }
    return (char *)0;/*no URI, HTTPD will send 404 error page to the browser*/
}
コード例 #3
0
ファイル: qf_pool.c プロジェクト: christation/STM32491_CPLR
/**
* \description
* This function initializes one event pool at a time and must be called
* exactly once for each event pool before the pool can be used.
*
* \arguments
* \arg[in] \c poolSto  pointer to the storage for the event pool
* \arg[in] \c poolSize size of the storage for the pool in bytes
* \arg[in] \c evtSize  the block-size of the pool in bytes, which determines
*             the maximum size of events that can be allocated from the pool.
*
* \note
* You might initialize many event pools by making many consecutive calls
* to the QF_poolInit() function. However, for the simplicity of the internal
* implementation, you must initialize event pools in the ascending order of
* the event size.
*
* Many RTOSes provide fixed block-size heaps, a.k.a. memory pools that can
* be adapted for QF event pools. In case such support is missing, QF provides
* a native QF event pool implementation. The macro #QF_EPOOL_TYPE_ determines
* the type of event pool used by a particular QF port. See structure ::QMPool
* for more information.
*
* \note The actual number of events available in the pool might be actually
* less than (\a poolSize / \a evtSize) due to the internal alignment
* of the blocks that the pool might perform. You can always check the
* capacity of the pool by calling QF_getPoolMin().
*
* \note The dynamic allocation of events is optional, meaning that you
* might choose not to use dynamic events. In that case calling QF_poolInit()
* and using up memory for the memory blocks is unnecessary.
*
* \sa QF initialization example for QF_init()
*/
void QF_poolInit(void * const poolSto, uint_fast16_t const poolSize,
                 uint_fast16_t const evtSize)
{
    /** \pre cannot exceed the number of available memory pools */
    Q_REQUIRE_ID(100, QF_maxPool_ < (uint_fast8_t)Q_DIM(QF_pool_));
    /** \pre please initialize event pools in ascending order of evtSize: */
    Q_REQUIRE_ID(101, (QF_maxPool_ == (uint_fast8_t)0)
        || (QF_EPOOL_EVENT_SIZE_(QF_pool_[QF_maxPool_ - (uint_fast8_t)1])
            < evtSize));

    /* perform the platform-dependent initialization of the pool */
    QF_EPOOL_INIT_(QF_pool_[QF_maxPool_],
                   poolSto, poolSize, evtSize);
    ++QF_maxPool_; /* one more pool */
}
コード例 #4
0
ファイル: main.cpp プロジェクト: alisonjoe/qpcpp
int main() {
    static QEvt const *blinkyQSto[10]; // Event queue storage for Blinky

    BSP_init(); // initialize the Board Support Package
    QF::init(); // initialize the framework and the underlying RT kernel

    // publish-subscribe not used, no call to QF::psInit()
    // dynamic event allocation not used, no call to QF::poolInit()

    // instantiate and start the active objects...
    AO_Blinky->start(1U,                            // priority
                     blinkyQSto, Q_DIM(blinkyQSto), // event queue
                     (void *)0, 0U);                // stack (unused)

    return QF::run(); // run the QF application
}
コード例 #5
0
ファイル: main.c プロジェクト: henrychoi/realtime
int main(void)
{
    Ble_ctor();
    Array_ctor();

    QF_init(Q_DIM(QF_active)); /* initialize the QF-nano framework */
    void BSP_init(); BSP_init(); /* initialize the Board Support Package */

    /* dictionaries... */
    QS_USR_DICTIONARY(TRACE_SDK_EVT);
    QS_USR_DICTIONARY(TRACE_PEER_EVT);
    QS_USR_DICTIONARY(TRACE_ADV_EVT);
    QS_USR_DICTIONARY(TRACE_BLE_EVT);
    QS_USR_DICTIONARY(TRACE_DM_EVT);
    QS_USR_DICTIONARY(TRACE_ANCS_EVT);

    return QF_run(); /* run the QF application */
}
コード例 #6
0
/*..........................................................................*/
struct pbuf *PbufQueue::get(void) {
    struct pbuf *pBuf;

    if (isEmpty()) {
        /* Return a NULL pointer if the queue is empty. */
        pBuf = (struct pbuf *)0;
    }
    else {
        /*
        * The queue is not empty so return the next frame from it
        * and adjust the read pointer accordingly.
        */
        pBuf = m_ring[m_qread];
        if ((++m_qread) == Q_DIM(m_ring)) {
            m_qread = 0;
        }
    }
    return pBuf;
}
コード例 #7
0
ファイル: reminder2.c プロジェクト: christation/STM32491_CPLR
/*..........................................................................*/
int main(int argc, char *argv[]) {
    printf("Reminder state pattern\nQEP version: %s\nQF  version: %s\n"
           "Press 'e' to echo the current value...\n"
           "Press ESC to quit...\n",
           QEP_getVersion(), QF_getVersion());

    Cruncher_ctor(&l_cruncher);

    BSP_init(argc, argv);                             /* initialize the BSP */

    QF_init();     /* initialize the framework and the underlying RT kernel */

    /* publish-subscribe not used, no call to QF_psInit() */

    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));

                             /* instantiate and start the active objects... */
    QACTIVE_START((QActive *)&l_cruncher, 1,
                  l_cruncherQSto, Q_DIM(l_cruncherQSto),
                  (void *)0, 1024, (QEvt *)0);

    return QF_run();                              /* run the QF application */
}
コード例 #8
0
ファイル: hc.c プロジェクト: russells/hc2
#include "serial.h"


Q_DEFINE_THIS_FILE;


static QEvent rtcQueue[4];
static QEvent recorderQueue[4];
/** The size of buttonsQueue[] is embarrassing, and reveals a flaw in the
    current code.  It will go away completely in a later iteration. */
static QEvent buttonsQueue[18];
static QEvent uiQueue[8];

QActiveCB const Q_ROM Q_ROM_VAR QF_active[] = {
	{ (QActive*)0            , (QEvent*)0   , 0                   },
	{ (QActive *) (&recorder), recorderQueue, Q_DIM(recorderQueue)},
	{ (QActive *) (&buttons) , buttonsQueue , Q_DIM(buttonsQueue) },
	{ (QActive *) (&ui)      , uiQueue      , Q_DIM(uiQueue)      },
	{ (QActive *) (&rtc)     , rtcQueue     , Q_DIM(rtcQueue)     },
};
Q_ASSERT_COMPILE( QF_MAX_ACTIVE == Q_DIM(QF_active) - 1 );


int main(void)
{
	/**
	 * Reserve this space for recording assertions.  We don't touch this
	 * memory here, and assume that it will be in the same place on every
	 * run, and that it isn't cleared by hardware or by startup code.  If
	 * those are true, then after a reset caused by an assertion, it will
	 * contain the values as filled in by QF_onAssert() at the end of the
コード例 #9
0
ファイル: main.c プロジェクト: henrychoi/realtime
#include "qpn.h"
#include "qs_trace.h"
#include "appsig.h"

static QEvt l_arrayQueue[2];//Array event queue
void Array_ctor(); //and its ctor
extern struct Apa102Array l_Array;

static QEvt l_bleQueue[2];//Ble event queue
void Ble_ctor(); //and its ctor
extern struct BlePeripheral l_Ble;

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,           (QEvt *)0,        0U                    },
    { (QActive *)&l_Ble,      l_bleQueue,       Q_DIM(l_bleQueue)     },
    { (QActive *)&l_Array,    l_arrayQueue,     Q_DIM(l_arrayQueue)   }
};

int main(void)
{
    Ble_ctor();
    Array_ctor();

    QF_init(Q_DIM(QF_active)); /* initialize the QF-nano framework */
    void BSP_init(); BSP_init(); /* initialize the Board Support Package */

    /* dictionaries... */
    QS_USR_DICTIONARY(TRACE_SDK_EVT);
    QS_USR_DICTIONARY(TRACE_PEER_EVT);
    QS_USR_DICTIONARY(TRACE_ADV_EVT);
コード例 #10
0
ファイル: main.c プロジェクト: chalot/BWRecorder
/*..........................................................................*/
int main(void) {

	/**初始化BSP*/
	BSP_init();

//	/**载入系统参数,如失败系统停止运行*/
//	if(!Load_Parameters())
//	{
//		//系统参数初始化失败,程序终止
//		return -1;
//	}

	/**初始化QP框架*/
	QF_init();

	/** 初始化事件池,用了小尺寸事件池和中尺寸事件池,未用大尺寸事件池,因为并没有字节数特别多的事件 */
	QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
	QF_poolInit(l_medPoolSto, sizeof(l_medPoolSto), sizeof(l_medPoolSto[0]));
//	QF_poolInit(l_largePoolSto, sizeof(l_largePoolSto), sizeof(l_largePoolSto[0]));

	/**初始化publish-subscribe缓区*/
	QF_psInit(l_subscrSto, Q_DIM(l_subscrSto));

	/**创建内存池,预分配一个块。只能调用一次*/
	if (MP_Create() < 0) {
		/**内存池创建失败,程序终止*/
		return -1;
	}

#ifdef GPRS
	/**GPRS状态机初始化*/
	QGprs_ctor();

	/**启动GPRS状态机*/
	QActive_start(AO_Gprs, AO_PRIO_GPRS, l_GPRSQueueSto, Q_DIM(l_GPRSQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef GPS
	/**GPS状态机初始化*/
	QGps_ctor();

	/**启动状态机*/
	QActive_start(AO_Gps, AO_PRIO_GPS, l_GPSQueueSto, Q_DIM(l_GPSQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef ACCDET
	/**ACC检测状态机初始化*/
	QACCDetector_ctor();

	/**启动ACC检测状态机*/
	QActive_start(AO_ACCDetector, AO_PRIO_ACCDET, l_ACCQueueSto,
			Q_DIM(l_ACCQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef CAN
	/**CAN状态机初始化*/
	QCAN_ctor();

	/**启动CAN状态机*/
	QActive_start(AO_Can, AO_PRIO_CAN, l_CANQueueSto, Q_DIM(l_CANQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef LCD
	/**LCD屏状态机初始化 */
	QLCD_ctor();

	/**启动状态机*/
	QActive_start(AO_LCD, AO_PRIO_LCD, l_LCDQueueSto, Q_DIM(l_LCDQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef SENSOR
	/**LCD屏状态机初始化 */
	Q3DSensor_ctor();

	/**启动状态机*/
	QActive_start(AO_3DSensor, AO_PRIO_SENSOR, l_SENSORQueueSto,
			Q_DIM(l_SENSORQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef VIDEO
	/**摄像头状态机初始化 */
	QVideo_ctor();

	/**启动状态机*/
	QActive_start(AO_Video, AO_PRIO_VIDEO, l_VIDEOQueueSto,
			Q_DIM(l_VIDEOQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef TTS
	/**TTS状态机初始化 */
	QTTS_ctor();

	/**启动状态机*/
	QActive_start(AO_TTS, AO_PRIO_TTS, l_TTSQueueSto, Q_DIM(l_TTSQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef RECORDER
	/**TTS状态机初始化 */
	QRecorder_ctor();

	/**启动状态机*/
	QActive_start(AO_Recorder, AO_PRIO_RECORDER, l_RECORDQueueSto,
			Q_DIM(l_RECORDQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef ICCARD
	/**IC卡状态机初始化 */
	QICcard_ctor();

	/**启动状态机*/
	QActive_start(AO_ICCard, AO_PRIO_IC, l_ICCARDQueueSto,
			Q_DIM(l_ICCARDQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef PRINTER
	/**IC卡状态机初始化 */
	QPrinter_ctor();

	/**启动状态机*/
	QActive_start(AO_Printer, AO_PRIO_PRINTER, l_PRINTERQueueSto,
			Q_DIM(l_PRINTERQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef IR
	/**IC卡状态机初始化 */
	QIR_ctor();

	/**启动状态机*/
	QActive_start(AO_IR, AO_PRIO_IR, l_IRQueueSto, Q_DIM(l_IRQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef USB
	/**IC卡状态机初始化 */
	QUSB_ctor();

	/**启动状态机*/
	QActive_start(AO_USB, AO_PRIO_USB, l_USBQueueSto, Q_DIM(l_USBQueueSto),
			(void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef AUDIO
	/**IC卡状态机初始化 */
	QAudio_ctor();

	/**启动状态机*/
	QActive_start(AO_Audio, AO_PRIO_AUDIO, l_AUDIOQueueSto,
			Q_DIM(l_AUDIOQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

#ifdef UPGRADE
	/**SD卡升级状态机初始化*/
	QUpgrade_ctor();

	/**启动升级状态机*/
	QActive_start(AO_Upgrade, AO_PRIO_UPGRADE, l_UPGRADEQueueSto,
			Q_DIM(l_UPGRADEQueueSto), (void *) 0, 0U, (QEvt *) 0);
#endif

	/**系统时间状态机初始化*/
	QSystick_ctor();

	/**启动系统时钟状态机*/
	QActive_start(AO_Systick, AO_PRIO_SYSTICK, l_SYSTICKQueueSto,
			Q_DIM(l_SYSTICKQueueSto), (void *) 0, 0U, (QEvt *) 0);

	/**载入系统参数,如失败系统停止运行*/
//	if (!Load_Parameters()) {
//		/**系统参数初始化失败,程序终止*/
//		return -1;
//	}

	/**嵌套中断向量初始化*/
	NVIC_Configuration();

	/**启动QP框架,程序开始运行*/
	return QF_run();
}
コード例 #11
0
*
* Contact information:
* Quantum Leaps Web sites: http://www.quantum-leaps.com
*                          http://www.state-machine.com
* e-mail:                  [email protected]
*****************************************************************************/
#include "qpn_port.h"                                       /* QP-nano port */
#include "bsp.h"                             /* Board Support Package (BSP) */
#include "pelican.h"                               /* application interface */

/*..........................................................................*/
static QEvt  l_pelicanQueue[3];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,           (QEvt *)0,      0U                    },
    { (QActive *)&AO_Pelican, l_pelicanQueue, Q_DIM(l_pelicanQueue) }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
int main (void) {
    Pelican_ctor();                          /* instantiate the  Pelican AO */

    BSP_init();                                     /* initialize the board */

    return QF_run();                         /* transfer control to QF-nano */
}
コード例 #12
0
ファイル: bsp.cpp プロジェクト: dongkc/rtu_drv
//............................................................................
void BSP_displayPaused(uint8_t paused) {
    char buf[16];
    LoadString(l_hInst,
        (paused != 0U) ? IDS_PAUSED : IDS_RUNNING, buf, Q_DIM(buf));
    SetDlgItemText(l_hWnd, IDC_PAUSED, buf);
}
コード例 #13
0
ファイル: main.c プロジェクト: SmartCocktailFactory/SCF_MCU
/*..........................................................................*/
int main(void) {

    Table_ctor();               /* instantiate the Table active object */
    LwIPMgr_ctor();             /* instantiate all LwIP-Manager active object */
    MgtProtocolHandler_ctor();  /* instantiate the MgtProtocolHandler active object */
    IceMgr_ctor();              /* instantiate the IceMgr active object */
    ModIo2Mgr_ctor();           /* instantiate the ModIo2Mgr active object */
    IceDetectionMgr_ctor();     /* instantiate the IceDetectionMgr active object */

    BSP_init();                 /* initialize the Board Support Package */

    QF_init();                  /* initialize the framework and the underlying RT kernel */

    /*
    ModLED8x8_init();
    while (1) {
      ModLED8x8_scrollString("*** RES Smart Cocktail Factory ***", SCROLL_RIGHT);
      delayMs(500);
      ModLED8x8_scrollString("*** RES Smart Cocktail Factory ***", SCROLL_LEFT);
      delayMs(500);
    }
    */

    /* object dictionaries... */
    QS_OBJ_DICTIONARY(l_smlPoolSto);
    QS_OBJ_DICTIONARY(l_medPoolSto);
    QS_OBJ_DICTIONARY(l_lwIPMgrQueueSto);
    QS_OBJ_DICTIONARY(l_tableQueueSto);
    QS_OBJ_DICTIONARY(l_mgtProtocolHandlerSto);
    QS_OBJ_DICTIONARY(l_iceMgrSto);
    QS_OBJ_DICTIONARY(l_modIo2MgrSto);
    QS_OBJ_DICTIONARY(l_iceDetectionMgrSto);

    /* init publish-subscribe */
    QF_psInit(l_subscrSto, Q_DIM(l_subscrSto));

    /* initialize event pools... */
    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
    QF_poolInit(l_medPoolSto, sizeof(l_medPoolSto), sizeof(l_medPoolSto[0]));

    /* start active objects */
    QActive_start(AO_LwIPMgr, 1,
                  l_lwIPMgrQueueSto, Q_DIM(l_lwIPMgrQueueSto),
                  (void *)0, 0, (QEvent *)0);

    QActive_start(AO_Table, 3,
                  l_tableQueueSto, Q_DIM(l_tableQueueSto),
                  (void *)0, 0, (QEvent *)0);

    QActive_start(AO_MgtProtocolHandler, 5,
                  l_mgtProtocolHandlerSto, Q_DIM(l_mgtProtocolHandlerSto),
                  (void *)0, 0, (QEvent *)0);

    QActive_start(AO_IceMgr, 7,
                  l_iceMgrSto, Q_DIM(l_iceMgrSto),
                  (void *)0, 0, (QEvent *)0);

    QActive_start(AO_ModIo2Mgr, 9,
                  l_modIo2MgrSto, Q_DIM(l_modIo2MgrSto),
                  (void *)0, 0, (QEvent *)0);

    QActive_start(AO_IceDetectionMgr, 11,
                  l_iceDetectionMgrSto, Q_DIM(l_iceDetectionMgrSto),
                  (void *)0, 0, (QEvent *)0);

    /* run the QF application */
    QF_run();

    return 1;
}
コード例 #14
0
/*..........................................................................*/
QState UI_num_sd_handler(UI_num_sd *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            uint8_t c;
            static char const * const help_sd[] = {
                "Standard Deviation:         ",
                "Find the mean value and the ",
                " root-mean-square (RMS)     ",
                "deviation of n data samples ",
                "xi, where i = 1..n.         ",
                "Mean value <x> is calculated",
                "as follows:                 ",
                "<x> = Sum(xi)/n;            ",
                "Two RMS estimatators are    ",
                "provided:                   ",
                "sig(n) =                    ",
                "   sqrt(Sum(xi-<x>)**2 / n);",
                "sig(n-1) =                  ",
                "sqrt(Sum(xi-<x>)**2 / (n-1))"
            };
                                     /* instantiate the state-local objects */
            me->super.super.help_text = help_sd;
            me->super.super.help_len  = Q_DIM(help_sd);
            me->n      = 0.0;
            me->sum    = 0.0;
            me->sum_sq = 0.0;

            Video_printStrAt(2, 10, VIDEO_FGND_BLACK,
                "Screen 1: Standard Deviation     ");
            Video_clearRect( 0, 11, 35, 23, VIDEO_BGND_BLUE);
            Video_clearRect(35, 11, 80, 23, VIDEO_BGND_BLACK);

            c = VIDEO_FGND_LIGHT_GRAY;
            Video_printStrAt(36, 12, c,
                "Press '-'        to enter a negative number");
            Video_printStrAt(36, 13, c,
                "Press '0' .. '9' to enter a digit");
            Video_printStrAt(36, 14, c,
                "Press '.'        to enter the decimal point");
            Video_printStrAt(36, 15, c,
                "Press <Enter>    to enter the data sample");
            Video_printStrAt(36, 16, c,
                "Press 'e' or 'E' to Cancel last entry");
            Video_printStrAt(36, 17, c,
                "Press 'c' or 'C' to Cancel the data set");

            c = VIDEO_FGND_WHITE;
            Video_printStrAt(36, 20, c,
                "Press UP-arrow   for previous screen");
            Video_printStrAt(36, 21, c,
                "Press DOWN-arrow for next screen");
            Video_printStrAt(36, 22, c,
                "Press F1         for help");

            Video_clearRect(NUM_ENTRY_X, NUM_ENTRY_Y,
                NUM_ENTRY_X + NUM_STR_WIDTH, NUM_ENTRY_Y + 1,
                VIDEO_BGND_BLACK);
            Video_drawRect(NUM_ENTRY_X - 1, NUM_ENTRY_Y - 1,
                NUM_ENTRY_X + NUM_STR_WIDTH + 1, NUM_ENTRY_Y + 2,
                VIDEO_FGND_WHITE, 2);

            NumEntry_config(&me->super.num_entry, NUM_ENTRY_X, NUM_ENTRY_Y,
                            NUM_ENTRY_COLOR);
            QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt);

            c = VIDEO_FGND_WHITE;                                 /* labels */
            Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 4, c,
                 "n        =");
            Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 5, c,
                 "<x>      =");
            Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 6, c,
                "sig(n)   =");
            Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 7, c,
                "sig(n-1) =");

            c = VIDEO_FGND_YELLOW;                                /* values */
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 4, c,
                "0           ");
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 5, c,
                "N/A         ");
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 6, c,
                "N/A         ");
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 7, c,
                "N/A         ");

            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
                                      /* destroy the state-local objects... */
            /* noting to destroy */
            return Q_HANDLED();
        }
        case C_SIG: {
            return Q_TRAN(&UI_num_sd_handler);        /* transition-to-self */
        }
        case CE_SIG: {
            QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt);
            return Q_HANDLED();
        }
        case UP_SIG: {
            return Q_TRAN(&UI_num_lr_handler);   /* Liner Regression screen */
        }
        case DOWN_SIG: {
            return Q_TRAN(&UI_num_lr_handler);   /* Liner Regression screen */
        }
        case NEG_SIG:
        case DIGIT_0_SIG:
        case DIGIT_1_9_SIG:
        case POINT_SIG: {
            QHsm_dispatch((QHsm *)&me->super.num_entry, e);
            return Q_HANDLED();
        }
        case ENTER_SIG: {
            double tmp = NumEntry_get(&me->super.num_entry);
            char buf[14];

            me->n      += 1.0;
            me->sum    += tmp;
            me->sum_sq += tmp*tmp;

            sprintf(buf, "%-12.6g", me->n);
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 4,
                              VIDEO_FGND_YELLOW, buf);

            tmp = me->sum / me->n;                                   /* <x> */
            sprintf(buf, "%-12.6g", tmp);
            Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 5,
                              VIDEO_FGND_YELLOW, buf);

            tmp = me->sum_sq / me->n - tmp*tmp;
            if (tmp >= 0.0) {                                   /* sigma(n) */
                tmp = sqrt(tmp);
                sprintf(buf, "%-12.6g", tmp);
                Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 6,
                                  VIDEO_FGND_YELLOW, buf);
                if (me->n > 1.0) {                            /* sigma(n-1) */
                     tmp *= sqrt(me->n/(me->n - 1.0));
                     sprintf(buf, "%-12.6g", tmp);
                     Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 7,
                                       VIDEO_FGND_YELLOW, buf);
                }
            }
            QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt);
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&UI_num_handler);
}
コード例 #15
0
ファイル: main.c プロジェクト: KnightSch/qpc
/*..........................................................................*/
int main() {
    static QEvt const *tableQueueSto[N_PHILO];
    static QEvt const *philoQueueSto[N_PHILO][N_PHILO];

    static OS_STK philoStk[N_PHILO][128]; /* stacks for the Philosophers */
    static OS_STK tableStk[256];          /* stack for the Table */

    static QSubscrList subscrSto[MAX_PUB_SIG];
    static TableEvt smlPoolSto[2*N_PHILO]; /* storage for small event pool */
    uint8_t n;

    /* in C you need to explicitly instantiate all AOs...  */
    Philo_ctor();
    Table_ctor();

    QF_init();  /* initialize the framework and the underlying RT kernel */
    BSP_init(); /* initialize the Board Support Package */

    /* object dictionaries... */
    QS_OBJ_DICTIONARY(smlPoolSto);
    QS_OBJ_DICTIONARY(tableQueueSto);
    QS_OBJ_DICTIONARY(philoQueueSto[0]);
    QS_OBJ_DICTIONARY(philoQueueSto[1]);
    QS_OBJ_DICTIONARY(philoQueueSto[2]);
    QS_OBJ_DICTIONARY(philoQueueSto[3]);
    QS_OBJ_DICTIONARY(philoQueueSto[4]);

    /* init publish-subscribe */
    QF_psInit(subscrSto, Q_DIM(subscrSto));

    /* initialize event pools... */
    QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));

    /* start the active objects... */
    /* CAUTION:
    * Make sure to configure **SUFFICIENT** number of uC/OS-II tasks and
    * message queues in "os_cfg.h" for all your active objects!!!
    */
    for (n = 0U; n < N_PHILO; ++n) {
        /* NOTE: provide uC/OS-II task attributes for the AO's task */
        QF_setUCosTaskAttr(AO_Philo[n], OS_TASK_OPT_STK_CHK);
        QACTIVE_START(AO_Philo[n],
                      (uint_fast8_t)(n + 1), /* QP priority */
                      philoQueueSto[n],      /* storage for the AO's queue */
                      Q_DIM(philoQueueSto[n]), /* queue's length [entries] */
                      philoStk[n],           /* stack storage */
                      sizeof(philoStk[n]),   /* sack size [bytes] */
                      (QEvt const *)0);      /* initialization event */
    }

    /* NOTE: provide uC/OS-II task attributes for the AO's task */
    QF_setUCosTaskAttr(AO_Table, OS_TASK_OPT_STK_CHK);
    QACTIVE_START(AO_Table,
                  (uint_fast8_t)(N_PHILO + 1), /* QP priority */
                  tableQueueSto,  /* storage for the AO's queue */
                  Q_DIM(tableQueueSto), /* queue's length [entries] */
                  tableStk,             /* stack storage */
                  sizeof(tableStk),     /* sack size [bytes] */
                  (QEvt const *)0);     /* initialization event */

    return QF_run(); /* run the QF application */
}
コード例 #16
0
ファイル: main.c プロジェクト: KnightSch/qpc
/*..........................................................................*/
int main() {
    static QEvt const *tableQueueSto[N_PHILO];
    static uint64_t tableStackSto[64];
    static QEvt const *philoQueueSto[N_PHILO][N_PHILO];
    static uint64_t philoStackSto[N_PHILO][64];

    static QSubscrList subscrSto[MAX_PUB_SIG];
    static QF_MPOOL_EL(TableEvt) smlPoolSto[2*N_PHILO]; /* small pool */

    /* stack for the "naked" test thread */
    static void const *testQueueSto[5];
    static uint64_t testStackSto[64];

    /* stack for the QXK's idle thread */
    static uint64_t idleStackSto[32];

    uint8_t n;

    Philo_ctor(); /* instantiate all Philosopher active objects */
    Table_ctor(); /* instantiate the Table active object */
    Test_ctor();  /* instantiate the Test "naked" thread */

    QF_init();    /* initialize the framework */
    BSP_init();   /* initialize the Board Support Package */

    /* object dictionaries... */
    QS_OBJ_DICTIONARY(smlPoolSto);
    QS_OBJ_DICTIONARY(tableQueueSto);
    QS_OBJ_DICTIONARY(philoQueueSto[0]);
    QS_OBJ_DICTIONARY(philoQueueSto[1]);
    QS_OBJ_DICTIONARY(philoQueueSto[2]);
    QS_OBJ_DICTIONARY(philoQueueSto[3]);
    QS_OBJ_DICTIONARY(philoQueueSto[4]);

    /* initialize QXK... */
    QXK_init(idleStackSto, sizeof(idleStackSto));

    /* initialize publish-subscribe... */
    QF_psInit(subscrSto, Q_DIM(subscrSto));

    /* initialize event pools... */
    QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));

    /* start the active objects... */
    for (n = 0U; n < N_PHILO; ++n) {
        QACTIVE_START(AO_Philo[n],           /* AO to start */
                  (uint_fast8_t)(n + 1),     /* QP priority of the AO */
                  philoQueueSto[n],          /* event queue storage */
                  Q_DIM(philoQueueSto[n]),   /* queue length [events] */
                  philoStackSto[n],          /* stack storage */
                  sizeof(philoStackSto[n]),  /* stack size [bytes] */
                  (QEvt *)0);                /* initialization event */
    }
    QACTIVE_START(AO_Table,                  /* AO to start */
                  (uint_fast8_t)(N_PHILO + 1), /* QP priority of the AO */
                  tableQueueSto,             /* event queue storage */
                  Q_DIM(tableQueueSto),      /* queue length [events] */
                  tableStackSto,             /* stack storage */
                  sizeof(tableStackSto),     /* stack size [bytes] */
                  (QEvt *)0);                /* initialization event */

    /* start the "naked" thread */
    QXTHREAD_START(&XT_Test->super,          /* Thread to start */
                  (uint_fast8_t)10U,         /* QP priority of the thread */
                  testQueueSto,              /* message queue storage */
                  Q_DIM(testQueueSto),       /* message length [events] */
                  testStackSto,              /* stack storage */
                  sizeof(testStackSto),      /* stack size [bytes] */
                  (QEvt *)0);                /* initialization event */

    return QF_run(); /* run the QF application */
}
コード例 #17
0
*                          http://www.state-machine.com
* e-mail:                  [email protected]
*****************************************************************************/
#include "qpn_port.h"                                       /* QP-nano port */
#include "bsp.h"                             /* Board Support Package (BSP) */
#include "game.h"                                  /* application interface */

/*..........................................................................*/
static QEvt l_tunnelQueue[GAME_MINES_MAX + 4];
static QEvt l_shipQueue[3];
static QEvt l_missileQueue[3];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,           (QEvt *)0,      0U                    },
    { (QActive *)&AO_Tunnel,  l_tunnelQueue,  Q_DIM(l_tunnelQueue)  },
    { (QActive *)&AO_Ship,    l_shipQueue,    Q_DIM(l_shipQueue)    },
    { (QActive *)&AO_Missile, l_missileQueue, Q_DIM(l_missileQueue) }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
int main (void) {
    Tunnel_ctor();
    Ship_ctor();
    Missile_ctor(GAME_MISSILE_SPEED_X);

    BSP_init();                                     /* initialize the board */
コード例 #18
0
ファイル: main.c プロジェクト: henrychoi/realtime
#include "qpn_port.h"   /* QP-nano port */
#include "bsp.h"        /* Board Support Package (BSP) */
#include "excitation.h"

/*..........................................................................*/
static QEvt l_excitationQ[4];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM Q_ROM_VAR QF_active[] = {
    { (QActive*)0, (QEvt*)0, 0U }
    , { (QActive*)&AO_excitation, l_excitationQ, Q_DIM(l_excitationQ) }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
int main (void) {
    Excitation_init();
    BSP_init();                                     /* initialize the board */
    return QF_run();                         /* transfer control to QF-nano */
}
コード例 #19
0
ファイル: defer.c プロジェクト: westlicht/camcontrol
        me->deferredRequest.sig = 0;          /* request no longer deferred */
    }
    else {
        printf("No requests to recall\n");
    }
}

/* test harness ============================================================*/

/* Local-scope objects -----------------------------------------------------*/
static QEvent l_serverQueue[1];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM Q_ROM_VAR QF_active[] = {
    { (QActive *)0,           (QEvent *)0,   0                    },
    { (QActive *)&AO_TServer, l_serverQueue, Q_DIM(l_serverQueue) }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
void main (void) {
    TServer_ctor();

    BSP_init();                                     /* initialize the board */

    QF_run();                                /* transfer control to QF-nano */
}
/*..........................................................................*/
void onConsoleInput(uint8_t key) {
コード例 #20
0
/*..........................................................................*/
QState LwIPMgr_running(LwIPMgr *me, QEvent const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            QTimeEvt_postEvery(&me->te_LWIP_SLOW_TICK, (QActive *)me,
                (LWIP_SLOW_TICK_MS * BSP_TICKS_PER_SEC) / 1000);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->te_LWIP_SLOW_TICK);
            return Q_HANDLED();
        }

        case SEND_UDP_SIG: {
            if (me->upcb->remote_port != (uint16_t)0) {
                struct pbuf *p = pbuf_new((u8_t *)((TextEvt const *)e)->text,
                                      strlen(((TextEvt const *)e)->text) + 1);
                if (p != (struct pbuf *)0) {
                    udp_send(me->upcb, p);
                    printf("Sent: %s\n", ((TextEvt const *)e)->text);
                    pbuf_free(p);                   /* don't leak the pbuf! */
                }
            }
            return Q_HANDLED();
        }

        case LWIP_RX_READY_SIG: {
            eth_driver_read();
            return Q_HANDLED();
        }
        case LWIP_TX_READY_SIG: {
            eth_driver_write();
            return Q_HANDLED();
        }
        case LWIP_SLOW_TICK_SIG: {
                                                 /* has IP address changed? */
            if (me->ip_addr != me->netif->ip_addr.addr) {
                TextEvt *te;
                uint32_t ip_net;    /* IP address in the network byte order */

                me->ip_addr = me->netif->ip_addr.addr; /* save the IP addr. */
                ip_net  = ntohl(me->ip_addr);
                    /* publish the text event to display the new IP address */
                te = Q_NEW(TextEvt, DISPLAY_IPADDR_SIG);
                snprintf(te->text, Q_DIM(te->text), "%d.%d.%d.%d",
                         ((ip_net) >> 24) & 0xFF,
                         ((ip_net) >> 16) & 0xFF,
                         ((ip_net) >> 8)  & 0xFF,
                         ip_net           & 0xFF);
                QF_PUBLISH((QEvent *)te, me);
            }

#if LWIP_TCP
            me->tcp_tmr += LWIP_SLOW_TICK_MS;
            if (me->tcp_tmr >= TCP_TMR_INTERVAL) {
                me->tcp_tmr = 0;
                tcp_tmr();
            }
#endif
#if LWIP_ARP
            me->arp_tmr += LWIP_SLOW_TICK_MS;
            if (me->arp_tmr >= ARP_TMR_INTERVAL) {
                me->arp_tmr = 0;
                etharp_tmr();
            }
#endif
#if LWIP_DHCP
            me->dhcp_fine_tmr += LWIP_SLOW_TICK_MS;
            if (me->dhcp_fine_tmr >= DHCP_FINE_TIMER_MSECS) {
                me->dhcp_fine_tmr = 0;
                dhcp_fine_tmr();
            }
            me->dhcp_coarse_tmr += LWIP_SLOW_TICK_MS;
            if (me->dhcp_coarse_tmr >= DHCP_COARSE_TIMER_MSECS) {
                me->dhcp_coarse_tmr = 0;
                dhcp_coarse_tmr();
            }
#endif
#if LWIP_AUTOIP
            me->auto_ip_tmr += LWIP_SLOW_TICK_MS;
            if (me->auto_ip_tmr >= AUTOIP_TMR_INTERVAL) {
                me->auto_ip_tmr = 0;
                autoip_tmr();
            }
#endif
            return Q_HANDLED();
        }
        case LWIP_RX_OVERRUN_SIG: {
            LINK_STATS_INC(link.err);
            return Q_HANDLED();
        }
    }
コード例 #21
0
ファイル: main.cpp プロジェクト: QuantumLeaps/qpcpp
//............................................................................
int main() {
    static QP::QEvt const *tableQueueSto[N_PHILO];
    static QP::QEvt const *philoQueueSto[N_PHILO][N_PHILO];

    static QP::QSubscrList subscrSto[DPP::MAX_PUB_SIG];
    static QF_MPOOL_EL(DPP::TableEvt) smlPoolSto[2*N_PHILO]; // small pool

    // stacks and queues for the extended test threads
    static QP::QEvt const *test1QueueSto[5];
    static uint64_t test1StackSto[64];
    static QP::QEvt const *test2QueueSto[5];
    static uint64_t test2StackSto[64];

    QP::QF::init();  // initialize the framework and the underlying RT kernel
    DPP::BSP::init(); // initialize the BSP

    // object dictionaries...
    QS_OBJ_DICTIONARY(DPP::AO_Table);
    QS_OBJ_DICTIONARY(DPP::AO_Philo[0]);
    QS_OBJ_DICTIONARY(DPP::AO_Philo[1]);
    QS_OBJ_DICTIONARY(DPP::AO_Philo[2]);
    QS_OBJ_DICTIONARY(DPP::AO_Philo[3]);
    QS_OBJ_DICTIONARY(DPP::AO_Philo[4]);

    // init publish-subscribe
    QP::QF::psInit(subscrSto, Q_DIM(subscrSto));

    // initialize event pools...
    QP::QF::poolInit(smlPoolSto,
                     sizeof(smlPoolSto), sizeof(smlPoolSto[0]));

    // start the extended Test1 thread
    DPP::XT_Test1->start(
            static_cast<uint_fast8_t>(1), // QP prio of the thread
            test1QueueSto,           // event queue storage
            Q_DIM(test1QueueSto),    // queue length [events]
            test1StackSto,           // stack storage
            sizeof(test1StackSto),   // stack size [bytes]
            static_cast<QP::QEvt *>(0)); // initialization event

    // NOTE: leave priority 2 free for a mutex

    // start the Philo active objects...
    for (uint8_t n = 0U; n < N_PHILO; ++n) {
        DPP::AO_Philo[n]->start(
            static_cast<uint_fast8_t>(n + 3), // QP priority of the AO
            philoQueueSto[n],          // event queue storage
            Q_DIM(philoQueueSto[n]),   // queue length [events]
            static_cast<void *>(0),    // no stack storage
            static_cast<uint_fast16_t>(0), // stack size [bytes]
            static_cast<QP::QEvt *>(0));   // initialization event
    }

    // example of prioritizing the Ticker0 active object
    DPP::the_Ticker0->start((uint_fast8_t)(N_PHILO + 3), // priority
                            0, 0,
                            0, 0);

    // NOTE: leave priority (N_PHILO + 4) free for mutex

    // start the extended Test2 thread
    DPP::XT_Test2->start(
            static_cast<uint_fast8_t>(N_PHILO + 5), // QP prio of the thread
            test2QueueSto,           // event queue storage
            Q_DIM(test2QueueSto),    // queue length [events]
            test2StackSto,           // stack storage
            sizeof(test2StackSto),   // stack size [bytes]
            static_cast<QP::QEvt *>(0)); // initialization event

    // NOTE: leave priority (N_PHILO + 6) free for mutex

    DPP::AO_Table->start(
            static_cast<uint_fast8_t>(N_PHILO + 7), // QP priority of the AO
            tableQueueSto,           // event queue storage
            Q_DIM(tableQueueSto),    // queue length [events]
            static_cast<void *>(0),  // no stack storage
            static_cast<uint_fast16_t>(0), // stack size [bytes]
            static_cast<QP::QEvt *>(0));   // initialization event

    return QP::QF::run(); // run the QF application
}
コード例 #22
0
ファイル: main.c プロジェクト: JPLOpenSource/SCA
int main(int argc, char* argv[])
{
    char cmdBuf[SOCK_BUFF_SIZE];

    printf("Quantum Test\nQEP %s\nQF  %s, QF/Linux port %s\n",
           QEP_getVersion(),
           QF_getVersion(), QF_getPortVersion());

    QF_init();
	QF_psInit(subscrSto, Q_DIM(subscrSto));
	QF_poolInit(poolArray, sizeof(poolArray), sizeof(GenEvt));
	
    applicationStart(QSIZE);

    for (;;)
    {
      // Get the incoming string command from the dmsTerminal or the GUI
      receiveCmd(cmdBuf);


	  // Attempt to parse the command string for IMPL or ACTIVE calls
	   char tmpBuf[USER_ENTRY_SIZE];
	   char smName[USER_ENTRY_SIZE];
	   char attrName[USER_ENTRY_SIZE];
	   char valStr[USER_ENTRY_SIZE];
	   // scan for IMPL['SM'].set("attr", True/False), allowing blanks
	   // IMPL['trans'].set('guard', False)
	   int cnt = sscanf(strcpy(tmpBuf, cmdBuf),
			   "IMPL[%*['\"]%[^'\"]%*['\"]].set(%*['\"]%[^'\"]%*['\"],%[^)])",
			   smName, attrName, valStr);
	   if (cnt > 0) {  // found an IMPL attribute setter!
		   setGuardAttribute(smName, attrName, valStr);
		   continue;
	   }

      char *word;
      word = strtok(cmdBuf, " ");

      // We assume the first word contains the signal that is to be published,
      // and the remaining words are data to be used to populate the event.
      GenEvt *event;
      int signal = strtoul(word, NULL, 10);
      if (signal == DURING)
      {
        QF_tick();
        QF_publish( Q_NEW(QEvent, DURING) );
      }
      else
      {
        event = Q_NEW(GenEvt, signal);
        // Loop through the remaining words and populate the event
        int i = 0;
        do
        {
           word = strtok('\0', " ");
           if (word)
           {
             Q_ASSERT(i<EVENT_SIZE);
             event->data[i] = strtoul(word, NULL, 16);
           }
           i = i + 1;
        } while (word);
        QF_publish((QEvent *)event);
      }
      QF_run();
    }
}
コード例 #23
0
ファイル: main.c プロジェクト: christation/STM32491_CPLR
/*............................................................................*/
int main(void)
{
   /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/
       startup_stm32f429_439xx.s/startup_stm32f401xx.s) before to branch to
       application main. To reconfigure the default setting of SystemInit()
       function, refer to system_stm32f4xx.c file
    */

   /* Enable debugging for select modules - Note: this has no effect in rel
    * builds since all DBG level logging is disabled and only LOG and up msgs
    * will get printed. */
   DBG_setDefaults();

   /* initialize the Board Support Package */
   BSP_init();

   dbg_slow_printf("Initialized BSP\n");
   log_slow_printf("Starting Bootloader version %s built on %s\n", FW_VER, BUILD_DATE);

   /* Instantiate the Active objects by calling their "constructors"         */
   dbg_slow_printf("Initializing AO constructors\n");

   /* Make sure the comm interfaces are up first */
   SerialMgr_ctor();
   LWIPMgr_ctor();

   /* Iterate though the available I2C busses on the system and call the ctor()
    * for each instance of the I2CBusMgr AO for each bus. */
   for( uint8_t i = 0; i < MAX_I2C_BUS; ++i ) {
      I2CBusMgr_ctor( i );      /* Start this instance of AO for this bus. */
   }

   I2C1DevMgr_ctor();
   CommMgr_ctor();
   FlashMgr_ctor();
   SysMgr_ctor();

   dbg_slow_printf("Initializing QF\n");
   QF_init();       /* initialize the framework and the underlying RT kernel */

   /* object dictionaries... */
   dbg_slow_printf("Initializing object dictionaries for QSPY\n");
   QS_OBJ_DICTIONARY(l_smlPoolSto);
   QS_OBJ_DICTIONARY(l_medPoolSto);
   QS_OBJ_DICTIONARY(l_lrgPoolSto);
   QS_OBJ_DICTIONARY(l_SerialMgrQueueSto);
   QS_OBJ_DICTIONARY(l_LWIPMgrQueueSto);
   QS_OBJ_DICTIONARY(l_I2CBusMgrQueueSto);
   QS_OBJ_DICTIONARY(l_I2C1DevMgrQueueSto);
   QS_OBJ_DICTIONARY(l_CommMgrQueueSto);
   QS_OBJ_DICTIONARY(l_FlashMgrQueueSto);
   QS_OBJ_DICTIONARY(l_SysMgrQueueSto);

   QF_psInit(l_subscrSto, Q_DIM(l_subscrSto));     /* init publish-subscribe */

   /* initialize the general memory pool */
   dbg_slow_printf("Initializing general purpose memory pool in CCMRAM\n");
   QMPool_init(
         p_glbMemPool,
         l_memPoolSto,
         sizeof(l_memPoolSto),
         DC3_MAX_MEM_BLK_SIZE
   );

   /* initialize event pools... */
   dbg_slow_printf("Initializing small event storage pool\n");
   QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
   dbg_slow_printf("Initializing medium event storage pool\n");
   QF_poolInit(l_medPoolSto, sizeof(l_medPoolSto), sizeof(l_medPoolSto[0]));
   dbg_slow_printf("Initializing large event storage pool\n");
   QF_poolInit(l_lrgPoolSto, sizeof(l_lrgPoolSto), sizeof(l_lrgPoolSto[0]));

   /* Start Active objects */
   dbg_slow_printf("Starting Active Objects\n");

   QACTIVE_START(AO_SerialMgr,
         SERIAL_MGR_PRIORITY,                                    /* priority */
         l_SerialMgrQueueSto, Q_DIM(l_SerialMgrQueueSto),       /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "SerialMgr"                                     /* Name of the task */
   );

   QACTIVE_START(AO_LWIPMgr,
         ETH_PRIORITY,                                           /* priority */
         l_LWIPMgrQueueSto, Q_DIM(l_LWIPMgrQueueSto),           /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "LWIPMgr"                                       /* Name of the task */
   );

   /* Iterate though the available I2C busses on the system and start an
    * instance of the I2CBusMgr AO for each bus.
    * WARNING!!!: make sure that the priorities for them are all together since
    * this loop will iterates through them and will take another AO's priority.
    * You will end up with clashing priorities for your AOs.*/
   for( uint8_t i = 0; i < MAX_I2C_BUS; ++i ) {
      QACTIVE_START(AO_I2CBusMgr[i],
            I2CBUS1MGR_PRIORITY + i,                                /* priority */
            l_I2CBusMgrQueueSto[i], Q_DIM(l_I2CBusMgrQueueSto[i]), /* evt queue */
            (void *)0, 0,                              /* per-thread stack size */
            (QEvt *)0,                               /* no initialization event */
            "I2CBusMgr"                                     /* Name of the task */
      );
   }

   QACTIVE_START(AO_I2C1DevMgr,
         I2C1DEVMGR_PRIORITY,                                    /* priority */
         l_I2C1DevMgrQueueSto, Q_DIM(l_I2C1DevMgrQueueSto),     /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "I2CDevMgr"                                     /* Name of the task */
   );

   QACTIVE_START(AO_CommMgr,
         COMM_MGR_PRIORITY,                                      /* priority */
         l_CommMgrQueueSto, Q_DIM(l_CommMgrQueueSto),           /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "CommMgr"                                       /* Name of the task */
   );

   QACTIVE_START(AO_FlashMgr,
         FLASH_MGR_PRIORITY,                                     /* priority */
         l_FlashMgrQueueSto, Q_DIM(l_FlashMgrQueueSto),         /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "FlashMgr"                                      /* Name of the task */
   );

   QACTIVE_START(AO_SysMgr,
         SYS_MGR_PRIORITY,                                       /* priority */
         l_SysMgrQueueSto, Q_DIM(l_SysMgrQueueSto),             /* evt queue */
         (void *)0, 0,                              /* per-thread stack size */
         (QEvt *)0,                               /* no initialization event */
         "SysMgr"                                        /* Name of the task */
   );
   log_slow_printf("Starting QPC. All logging from here on out shouldn't show 'SLOW'!!!\n\n");
   QF_run();                                       /* run the QF application */

   return(0);
}
コード例 #24
0
ファイル: qfn_main.c プロジェクト: QuantumLeaps/qpn
#include "qpn.h"     /* QP-nano API */
#include "bsp.h"     /* Board Support Package (BSP) */
#include "pelican.h" /* Application interface */

/*..........................................................................*/
static QEvt l_pelicanQueue[2];
static QEvt l_pedQueue[1];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,           (QEvt *)0,      0                     },
    { (QActive *)&AO_Pelican, l_pelicanQueue, Q_DIM(l_pelicanQueue) },
    { (QActive *)&AO_Ped,     l_pedQueue,     Q_DIM(l_pedQueue)     }
};

/*..........................................................................*/
int_t main (void) {
    Pelican_ctor();  /* instantiate the  Pelican AO */
    Ped_ctor();      /* instantiate the  Ped     AO */

    QF_init(Q_DIM(QF_active)); /* initialize the QF-nano framework */
    BSP_init();      /* initialize the Board Support Package */

    return QF_run(); /* transfer control to QF-nano */
}
コード例 #25
0
ファイル: blinky.c プロジェクト: QuantumLeaps/qpn
/* protected: */
static QState Blinky_initial(Blinky * const me);
static QState Blinky_off(Blinky * const me);
static QState Blinky_on(Blinky * const me);
/*$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

/* the single instance of the Blinky active object -------------------------*/
Blinky AO_Blinky;

/* Local-scope objects -----------------------------------------------------*/
static QEvt l_blinkyQSto[10]; /* Event queue storage for Blinky */

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,           (QEvt *)0,        0U                      },
    { (QActive *)&AO_Blinky,  l_blinkyQSto,     Q_DIM(l_blinkyQSto)     }
};

/* the main function -------------------------------------------------------*/
int main(void) {
    QF_init(Q_DIM(QF_active)); /* initialize the QF-nano framework */
    BSP_init(); /* initialize the Board Support Package */

    Blinky_ctor(); /* in C you must explicitly call the Blinky constructor */
    return QF_run(); /* transfer control to QF-nano */
}

/* ask QM to define the Blinky class ---------------------------------------*/
/*$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/* Check for the minimum required QP version */
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
コード例 #26
0
            Alarm_dispatch(&me->alarm);
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&AlarmClock_timekeeping);
}

/* test harness ============================================================*/

/* Local-scope objects -----------------------------------------------------*/
static QEvt l_clockQueue[3];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,              (QEvt *)0,    0U                  },
    { (QActive *)&AO_AlarmClock, l_clockQueue, Q_DIM(l_clockQueue) }
};
uint8_t const Q_ROM QF_activeNum = Q_DIM(QF_active) - 1;

/*..........................................................................*/
int main (void) {
    AlarmClock_ctor();

    printf("Orthogonal Component state pattern\nQP-nano version: %s\n"
           "Press 'o' to turn the Alarm ON\n"
           "Press 'f' to turn the Alarm OFF\n"
           "Press '0'..'9' to set the Alarm time\n"
           "Press 'A' to set the Clock in 12-hour mode\n"
           "Press 'B' to set the Clock in 24-hour mode\n"
           "Press ESC to quit...\n",
           QP_getVersion());
コード例 #27
0
ファイル: dclock.c プロジェクト: russells/dclock
   are any queued events for higher priority AOs, they get dispatched first,
   and lower priority AOs don't have their events dispatched until the higher
   priority AOs event queues are empty.

   In our case, the most important relative priority here is that alarm must be
   higher priority than timekeeper.  When the alarm is turned off, both alarm
   and timekeeper have events dispatched for that.  But timekeeper asks alarm
   its alarm state before writing to the RTC, and if alarm's event has not been
   processed yet it will get the wrong answer.  So make sure alarm's queue is
   processed before timekeeper's.

   Yes, this is weird and fragile, and should be fixed.
 */
QActiveCB const Q_ROM Q_ROM_VAR QF_active[] = {
	{ (QActive *)0              , (QEvent *)0      , 0                        },
	{ (QActive *)(&twi)         , twiQueue         , Q_DIM(twiQueue)          },
	{ (QActive *)(&timedisplay) , timedisplayQueue , Q_DIM(timedisplayQueue)  },
	{ (QActive *)(&buttons)     , buttonsQueue     , Q_DIM(buttonsQueue)      },
	{ (QActive *)(&timekeeper)  , timekeeperQueue  , Q_DIM(timekeeperQueue)   },
	{ (QActive *)(&alarm)       , alarmQueue       , Q_DIM(alarmQueue)        },
	{ (QActive *)(&timesetter)  , timesetterQueue  , Q_DIM(timesetterQueue)   },
};
/* If QF_MAX_ACTIVE is incorrectly defined, the compiler says something like:
   lapclock.c:68: error: size of array ‘Q_assert_compile’ is negative
 */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);


int main(int argc, char **argv)
{
	uint8_t mcusr;
コード例 #28
0
ファイル: main.c プロジェクト: MCUapps/gpn-gnu
#include "qpn_port.h"                                       /* QP-nano port */
#include "bsp.h"                             /* Board Support Package (BSP) */
#include "project.h"                               /* application interface */

/*..........................................................................*/
static QEvt l_blinkyQueue[4];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM Q_ROM_VAR QF_active[] = {
    { (QActive *)0,           (QEvt *)0,      0U                    },
    { (QActive *)&AO_Blinky,  l_blinkyQueue,  Q_DIM(l_blinkyQueue)  }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
int main() {
    Blinky_ctor();                             /* instantiate the Blinky AO */

    BSP_init();                                     /* initialize the board */

    return QF_run();                         /* transfer control to QF-nano */
}
コード例 #29
0
            }
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&Sensor_processing);
}

/* test harness ============================================================*/

/* Local-scope objects -----------------------------------------------------*/
static QEvt l_sensorQueue[2];

/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
    { (QActive *)0,          (QEvt *)0,     0U                   },
    { (QActive *)&AO_Sensor, l_sensorQueue, Q_DIM(l_sensorQueue) }
};

/* make sure that the QF_active[] array matches QF_MAX_ACTIVE in qpn_port.h */
Q_ASSERT_COMPILE(QF_MAX_ACTIVE == Q_DIM(QF_active) - 1);

/*..........................................................................*/
int main (void) {
    Sensor_ctor();

    BSP_init();                                     /* initialize the board */

    return QF_run();                         /* transfer control to QF-nano */
}
/*..........................................................................*/
void BSP_onKeyboardInputISR(uint8_t key) {
コード例 #30
0
};

static Note const l_alarm3[] = {                        /* out of air alarm */
    { 0x20, BSP_TICKS_PER_SEC/4 },
    { 0x00, BSP_TICKS_PER_SEC/4 },
    { 0x20, BSP_TICKS_PER_SEC/4 },
    { 0x00, BSP_TICKS_PER_SEC/4 },
    { 0xD0, BSP_TICKS_PER_SEC/4 },
    { 0x00, BSP_TICKS_PER_SEC/4 },
    { 0xD0, BSP_TICKS_PER_SEC/4 },
    { 0x00, BSP_TICKS_PER_SEC/4 }
};

static Alarm const l_alarms[] = {        /* consistent with enum AlarmTypes */
    { (Note *)0, 0               },                           /* ALL_ALARMS */
    { l_alarm1,  Q_DIM(l_alarm1) },                          /* DEPTH_ALARM */
    { l_alarm2,  Q_DIM(l_alarm2) },                    /* ASCENT_RATE_ALARM */
    { l_alarm3,  Q_DIM(l_alarm3) }                      /* OUT_OF_AIR_ALARM */
};


/* helper functions --------------------------------------------------------*/
#define QPSet8_clear(me_) ((me_)->bits = (uint8_t)0)

/* Global-scope objects ----------------------------------------------------*/
QActive * const AO_AlarmMgr = (QActive *)&l_alarmmgr;/* "opaque" AO pointer */

/* local constants ---------------------------------------------------------*/

/*..........................................................................*/
void AlarmMgr_ctor(void) {