📄 ped.c
字号:
/****************************************************************************** PELICAN crossing example* Last Updated for Version: 1.5.00* Date of the Last Update: Sep 17, 2006** Copyright (C) 2002-2006 Quantum Leaps, LLC. All rights reserved.** This software may be distributed and modified under the terms of the GNU* General Public License version 2 (GPL) as published by the Free Software* Foundation and appearing in the file GPL.TXT included in the packaging of* this file. Please note that GPL Section 2[b] requires that all works based* on this software must also be made publicly available under the terms of* the GPL ("Copyleft").** Alternatively, this software may be distributed and modified under the* terms of Quantum Leaps commercial licenses, which expressly allow the* licensees to retain the proprietary status of their code. The licensees* who use this software under one of Quantum Leaps commercial licenses do* not use this software under the GPL and therefore are not subject to any* of its terms.** Contact information:* Quantum Leaps Web site: http://www.quantum-leaps.com* Quantum Leaps licensing: http://www.quantum-leaps.com/licensing* Quantum Leaps products: http://www.quantum-leaps.com/products* e-mail: sales@quantum-leaps.com*****************************************************************************/#include "qpn_port.h"#include "qassert.h"#include "bsp.h"#include "pelican.h"/*--------------------------------------------------------------------------*/static QSTATE Ped_initial(Ped *me);static QSTATE Ped_on(Ped *me);static QSTATE Ped_wait(Ped *me);static QSTATE Ped_off(Ped *me);/*--------------------------------------------------------------------------*/enum PedTimeouts { /* various timeouts in ticks */ ON_TOUT = BSP_TICKS_PER_SEC * 4, /* wait time after posting ON_SIG */ WAIT_TOUT = BSP_TICKS_PER_SEC * 3, /* wait between posting PED_WAITING */ OFF_TOUT = BSP_TICKS_PER_SEC * 8 /* wait time after posting OFF_SIG */};/*..........................................................................*/void Ped_ctor(Ped *me, uint8_t retry) { QActive_ctor(me, &Ped_initial); me->retry__ = retry; /* the number of retries */}/* HSM definition ----------------------------------------------------------*/QSTATE Ped_initial(Ped *me) { switch (Q_SIG(me)) { case Q_TOP_INIT_SIG: { Q_TRAN(&Ped_on); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE Ped_on(Ped *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { BSP_showState(PED_PRIO, "on"); QActive_arm((QActive *)me, ON_TOUT); return (QSTATE)0; } case Q_TIMEOUT_SIG: { me->retryCtr__ = me->retry__; Q_TRAN(&Ped_wait); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE Ped_wait(Ped *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { BSP_showState(PED_PRIO, "wait"); QActive_arm((QActive *)me, WAIT_TOUT); QF_post(PELICAN_PRIO, PEDS_WAITING_SIG, 0); return (QSTATE)0; } case Q_TIMEOUT_SIG: { if ((me->retryCtr__--) != 0) { Q_TRAN(&Ped_wait); /* transition-to-self */ } else { Q_TRAN(&Ped_off); } return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE Ped_off(Ped *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { BSP_showState(PED_PRIO, "off"); QActive_arm((QActive *)me, OFF_TOUT); QF_post(PELICAN_PRIO, OFF_SIG, 0); return (QSTATE)0; } case Q_EXIT_SIG: { QF_post(PELICAN_PRIO, ON_SIG, 0); return (QSTATE)0; } case Q_TIMEOUT_SIG: { Q_TRAN(&Ped_on); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -