//----------------------------------------------------------- //计数任务处理 //----------------------------------------------------------- #ifndef __TriggleH #define __TriggleH
#include "..libRain_M128.h"
#include "....WorkTable.h" #include "..DriverUmIo.h" #include "..ProtocolProtocol.h" #include "..CounterCounter.h"
#ifndef _TriggleH //-------------------------------------------------- //初始化 //-------------------------------------------------- extern void Triggle_Init(void);
//-------------------------------------------------- //析构 //-------------------------------------------------- #define Triggle_Destory() do{ Counter_Destory();}while(0)
//------------------------------------------------------------- //循环 //20ms //------------------------------------------------------------- extern void Triggle_Loop( void );
#define Triggle_MainLoop() do{ if( sSysTimer.bSysTouch){ Triggle_Loop(); }; Counter_MainLoop(); }while(0) #endif #endif
//----------------------------------------------------------- //触发任务处理 //管理触发模式 //管理触发计数 //执行触发功能(自动和手动) //使用虚拟DA通道 0:触发计数 1:触发频率 //使用虚拟AD通道 3:触发计数 4:触发频率 //结果保存在UmIo的AD、DA缓冲区中 //----------------------------------------------------------- #include "Triggle.h"
#define TRIGVALIDTIME 2 #define OUT_TRIGGLE 20
struct InTriggle { U8 mNovalidTime; //触发失效效的时间间隔设置。=0无。单位:20MS U8 mTrigModeTemp; //0=停止,1=手动,2=自动,3=ECG,临时 U8 mTask; U8 mTimer; //工作用的计时器 }; struct InTriggle sInTriggle; #define this sInTriggle
enum TrigMode { eStop, eManual, eAuto, eEcg, eNoValid, };
//------------------------------------------------------------- //消息处理 //------------------------------------------------------------- void InTriggle_MsgProc( void ) { switch( Msg_Pop() ) { case Msg_Trig_SetupFreq: //触发频率设定 //计算触发脉冲失效时间 this.mNovalidTime = ((60/20)*1000) / sUmIo.aDaBuf[ eDa_TrigFreq ] - TRIGVALIDTIME; //1分钟->20ms倍数 break; case Msg_Trig_ModeECG: //心电同步 this.mTrigModeTemp = eEcg; break; case Msg_Trig_ModeContinuous: //连续触发 this.mTrigModeTemp = eAuto; break; case Msg_Trig_ModeManual: //手动停止 if( this.mTrigModeTemp == eStop ) { //单次触发 this.mTrigModeTemp = eManual; } else { //停止 this.mTrigModeTemp = eStop; } break; } }
//------------------------------------------------------------- //触发计数及控制 //------------------------------------------------------------- void InTrig_Valid( void ) { //触发的计数控制 if( Counter_IsEnable() ) { if( sUmIo.aDaBuf[ eAd_TrigCounter ] < sUmIo.aDaBuf[ eDa_TrigCounter ] ) { //计数-1 Counter_Dec(); sUmIo.aDaBuf[ eAd_TrigCounter ]++; if( UmIo_Out( OUT_TRIGGLE, 0, false ) ) { //发生变化,向所有串口发送 Package_SendU16( psUart_Pc, eProto_IoOutChange, OUT_TRIGGLE ); Package_SendU16( psUart_Hand, eProto_IoOutChange, OUT_TRIGGLE ); } //向PC、HAND发送AD信息 Package_SendU16( psUart_Pc, eProto_ADChange, sUmIo.aAdBuf[ eAd_TrigCounter ] ); Package_SendU16( psUart_Hand, eProto_ADChange, sUmIo.aAdBuf[ eAd_TrigCounter ] ); } } }
//------------------------------------------------------------- //触发失效 //------------------------------------------------------------- void InTrig_NoValid( void ) { if( UmIo_Out( OUT_TRIGGLE, 0, false ) ) { //发生变化,向所有串口发送 Package_SendU16( psUart_Pc, eProto_IoOutChange, OUT_TRIGGLE | (1<<8) ); Package_SendU16( psUart_Hand, eProto_IoOutChange, OUT_TRIGGLE | (1<<8) ); } }
//-------------------------------------------------- //初始化 //-------------------------------------------------- void Triggle_Init(void) { Memory_Memset( (U8 *)&this, 0, sizeof( struct InTriggle ) );
//消息注册 Msg_Register( InTriggle_MsgProc, Msg_Trig_SetupFreq, Msg_Trig_ModeManual ); Counter_Init(); }
//------------------------------------------------------------- //循环 //20ms //------------------------------------------------------------- void Triggle_Loop( void ) { if( this.mTimer ) { if( --this.mTimer == 0 ) { switch( this.mTask ) { case eStop: //进入失效 InTrig_NoValid(); //触发失效 break;
case eManual: InTrig_NoValid(); //触发失效 this.mTask = eNoValid; this.mTimer = this.mNovalidTime; break; case eAuto: InTrig_NoValid(); //触发失效 this.mTask = eNoValid; this.mTimer = this.mNovalidTime; break; case eEcg: InTrig_NoValid(); //触发失效 this.mTask = eNoValid; this.mTimer = this.mNovalidTime; break; case eNoValid: this.mTask = eStop; break; } } } else { //判断是否加载 if( sUmIo.aMessage[eMessage_TriggleMode] != this.mTrigModeTemp ) { //设置发生改变 sUmIo.aMessage[eMessage_TriggleMode] = this.mTrigModeTemp; //发生变化,向所有串口发送 Package_SendU8( psUart_Pc, eProto_ControlStat, sUmIo.aMessage[eMessage_TriggleMode] ); Package_SendU8( psUart_Hand, eProto_ControlStat, sUmIo.aMessage[eMessage_TriggleMode] ); switch( sUmIo.aMessage[eMessage_TriggleMode] ) { case eStop: break;
case eManual: InTrig_Valid(); //触发有效 this.mTask = eManual; this.mTimer = TRIGVALIDTIME; break; case eAuto: InTrig_Valid(); //触发有效 this.mTask = eAuto; this.mTimer = TRIGVALIDTIME; break; case eEcg: break; } } else { //检测自动、ECG switch( sUmIo.aMessage[eMessage_TriggleMode] ) { case eStop: break;
case eManual: break; case eAuto: InTrig_Valid(); //触发有效 this.mTask = eAuto; this.mTimer = TRIGVALIDTIME; break; case eEcg: //检测ECG输入触发 break; } } } }
基本没停顿,只在状态改变时发生了事件才去处理,所以效率极其高。换51都可以运行过来。 |