Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

94 lines
1.4 KiB

#include "StdAfx.h"
#include <stdio.h>
#include "areset.h"
static DWORD far* g_Timer = (DWORD far*)0x46CL;
#ifdef INCLUDE_WINDOWS_DEFINITIONS
#define TIMER() *g_Timer
#define MS_TO_TIME(t) (t*182L/10000L)
#else
#define TIMER() GetTickCount()
#define MS_TO_TIME(t) (t)
#endif
CAutoReset::CAutoReset()
{
}
CAutoReset::~CAutoReset()
{
}
BOOL CAutoReset::Create( AUTO_RESET* pAutoReset )
{
m_bFirst = TRUE;
m_dwFirstTime = 0;
m_dwLastTime = 0;
m_bPerformReset= FALSE;
m_bEnabled = pAutoReset->bEnabled;
m_dwInterleave = MS_TO_TIME( pAutoReset->dwInterleave );
m_dwTimeout = MS_TO_TIME( pAutoReset->dwTimeout );
return TRUE;
}
void CAutoReset::Destroy()
{
}
void CAutoReset::OnTarget( INT, INT )
{
OnAlarm();
}
void CAutoReset::OnError()
{
OnAlarm();
}
void CAutoReset::OnAlarm()
{
if( !m_bEnabled )
return;
DWORD dwTime = TIMER();
if( m_bFirst )
{
m_bFirst = FALSE;
m_dwFirstTime = dwTime;
}
else
if( dwTime - m_dwLastTime < m_dwInterleave )
{
if( dwTime - m_dwFirstTime > m_dwTimeout )
m_bPerformReset = TRUE;
}
else
m_dwFirstTime = dwTime;
m_dwLastTime = dwTime;
}
BOOL CAutoReset::IsNeedToReset()
{
if( !m_bEnabled )
return FALSE;
if( m_bPerformReset )
return TRUE;
if( m_bFirst )
return FALSE;
if( TIMER() - m_dwLastTime < m_dwInterleave )
return FALSE;
m_bFirst = TRUE;
return FALSE;
}