qf_pool.c

/****************************************************************************** Product: QF/C* Last Updated for Version: 5.2.0* Date of the Last Update: Dec 03, 2013** Q u a n t u m L e a P s* ---------------------------* innovating embedded systems** Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved.** This program is open source software: you can redistribute it and/or* modify it under the terms of the GNU General Public License as published* by the Free Software Foundation, either version 3 of the License, or* (at your option) any later version.** Alternatively, this program may be distributed and modified under the* terms of Quantum Leaps commercial licenses, which expressly supersede* the GNU General Public License and are specifically designed for* licensees interested in retaining the proprietary status of their code.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program. If not, see .** Contact information:* Quantum Leaps Web sites: http://www.quantum-leaps.com* http://www.state-machine.com* e-mail: info@quantum-leaps.com*****************************************************************************/#include "qf_pkg.h"#include "qassert.h"Q_DEFINE_THIS_MODULE("qf_pool")/*** \file* \ingroup qf* \brief QF_pool_[] definition and QF_poolInit() implementation.*//* Package-scope objects ---------------------------------------------------*/QF_EPOOL_TYPE_ QF_pool_[QF_MAX_EPOOL]; /* allocate the event pools */uint_t QF_maxPool_; /* number of initialized event pools *//*..........................................................................*/void QF_poolInit(void * const poolSto, uint_t const poolSize, uint_t const evtSize){ /* cannot exceed the number of available memory pools */ Q_REQUIRE(QF_maxPool_ < (uint_t)Q_DIM(QF_pool_)); /* please initialize event pools in ascending order of evtSize: */ Q_REQUIRE((QF_maxPool_ == (uint_t)0) || (QF_EPOOL_EVENT_SIZE_(QF_pool_[QF_maxPool_ - (uint_t)1]) < evtSize)); /* perfom the platform-dependent initialization of the pool */ QF_EPOOL_INIT_(QF_pool_[QF_maxPool_], poolSto, poolSize, evtSize); ++QF_maxPool_; /* one more pool */}
qp官网下载qpc,移植到stm32f103单片机,在正点原子战舰V3开发板上实验成功 qp搭建步骤重要提示: #define RED_QUEUE_LEN 3 #define BLUE_QUEUE_LEN 3 #define TACKER_EVENT_POOL_LEN (RED_QUEUE_LEN + BLUE_QUEUE_LEN) static QEvt const * l_redQueueSto[RED_QUEUE_LEN]; //事件队列 static QEvt const * l_blueQueueSto[BLUE_QUEUE_LEN]; //事件队列 static LedEvt LedEvtPoolSto[TACKER_EVENT_POOL_LEN]; //事件池 static QSubscrList SubSrcSto[MAX_PUB_SIG]; //订阅列表 typedef struct LedEvtTag LedEvt; //定义事件结构 struct LedEvtTag{ QEvt super_; uint16_t uiParaH; uint16_t uiParaL; }; //定义信号枚举 enum LedSignals{ START_SIG = Q_USER_SIG, KEY0_SIG, KEY1_SIG, KEY2_SIG, KEYUP_SIG, ALL_OFF_SIG, ONLY_BULE_SIG, ONLY_RED_SIG, ALL_ON_SIG, MAX_PUB_SIG }; void PublishLedEvt(uint16_t uiSig, uint16_t uiParaH, uint16_t uiParaL) //发布事件函数 { LedEvt* peTacker; peTacker = Q_NEW(LedEvt, uiSig); peTacker->uiParaH = uiParaH; peTacker->uiParaL = uiParaL; QF_publish_((QEvt*)peTacker); } QF_init(); //时间事件列表、活动对象查找表、优先级集合 QF_psInit(SubSrcSto, Q_DIM(SubSrcSto)); //初始化事件池 QF_poolInit(LedEvtPoolSto,sizeof(LedEvtPoolSto),sizeof(LedEvtPoolSto[0])); RedLed_Start(uiPrio++, l_redQueueSto, Q_DIM(l_redQueueSto), 0, 0); //建立活动对象 BlueLed_Start(uiPrio++, l_blueQueueSto, Q_DIM(l_blueQueueSto), 0, 0); /////////////////////////////////////////////////// typedef struct RedActiveTag RedActive; //构建一个活动对象活动类型 struct RedActiveTag{ QActive super_; volatile uint16_t RedLedStateNow; uint16_t a; uint16_t b; }; extern RedActive RedLed; RedActive RedLed; void RedLed_Start(uint_fast8_t prio, QEvt const *qSto[], uint_fast16_t qLen, void *stkSto, uint_fast16_t stkSize) { RedLed_Ctor(&RedLed;); QActive_start_((QActive*)&RedLed;, prio, qSto, qLen, stkSto, stkSize, (QEvt const *)0); //创立活动对象的线程并提醒 QF 开始管理活动对象 } void RedLed_Ctor(RedActive* me) { QActive_ctor(&me;->super_, (QStateHandler)RedLed_Initial); //初始化状态机基础类(成员 super) me->RedLedStateNow = 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值