For DOS Protected Mode version of sensor core software
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.
 
 
 
 

252 lines
4.5 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: watchdo_.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of watchdo_.cpp
//----------------------------------------------------------------------------
#include <stdio.h>
#include <dos.h>
#include "StdAfx.h"
#include "WatchDog.h"
extern BOOL g_bIsVortex;
#ifdef WATCHDOG_ENABLED
CWatchDog::CWatchDog()
{
m_bInitiated = FALSE;
m_dwTime = 0;
m_eType = WT_UNKNOWN;
}
CWatchDog::~CWatchDog()
{
Destroy();
}
void ZFLWriteb( BYTE index, BYTE value )
{
asm
{
mov AL,index
mov DX,ZFLINDEX
out DX,AL
mov DX,ZFLDATA8
mov AL,value
out DX,AL
}
}
void ZFLWritew( BYTE index, WORD value )
{
asm
{
mov AL,index
mov DX,ZFLINDEX
out DX,AL
mov DX,ZFLDATA16
mov AX,value
out DX,AX
}
}
BYTE ZFLReadb( BYTE index )
{
asm
{
mov AL,index
mov DX,ZFLINDEX
out DX,AL
mov DX,ZFLDATA8
in AL,DX
}
return _AL;
}
void ZFLOrb( BYTE index, BYTE mask )
{
asm
{
mov AL,index
mov DX,ZFLINDEX
out DX,AL
mov DX,ZFLDATA8
in AL,DX
or AL,mask
out DX,AL
}
}
BOOL CWatchDog::Create()
{
if( m_bInitiated )
return TRUE;
// determine PC104 type
m_eType = WT_UNKNOWN;
// check for CoreModule
if( m_eType == WT_UNKNOWN )
{
char far *pCoreModule4DXeStr = "CM/4DXi";
if( !_fmemcmp( (void far*)0xF0000101UL, pCoreModule4DXeStr, 7 ) &&
!_fmemcmp( (void far*)0xF0002B6DUL, pCoreModule4DXeStr, 7 ) )
m_eType = WT_COREMODULE_4DXE;
}
// check for VortexSX
if( m_eType == WT_UNKNOWN )
{
if ( g_bIsVortex ) m_eType = WT_VORTEX_SX;
}
// check for TRI-M
if( m_eType == WT_UNKNOWN )
{
asm
{
mov AL,0x02 // Index
mov DX,ZFLINDEX // Index Address
out DX,AL // Set Index
mov DX,ZFLDATA16 // read value:
in AX,DX // AX=1234H
}
if( _AX == 0x1234 )
m_eType = WT_TRI_M;
}
// init watchdog
switch( m_eType )
{
default:
case WT_UNKNOWN:
return TRUE;
case WT_COREMODULE_4DXE:
break;
case WT_TRI_M:
// set WD1 counter to maximal value (~2sec)
ZFLWritew( 0x0C, 0xFFFF );
// clear status registers
ZFLWriteb( 0x12, 0 );
// program WD events: enable WD1 generated RESET
ZFLWriteb( 0x11, 0x08 ); // Watchdog control high
// program reset pulse length. Pulse length is expressed in 32kHz clock periods.
ZFLWriteb( 0x0F, 0x10 ); // Watchdog generated pulse length
// reset counters
_AL = ZFLReadb( 0x10 ); // Watchdog Control Low
asm
{
and AL,0xEF // clear WD1 reload bit
out DX,AL // write back register value
or AL,0x10 // set WD1 and WD2 reload bit
out DX,AL // make 0->1 transition
}
// enable WD1
ZFLOrb( 0x10, 0x01 ); // WatchDog Control Low
break;
case WT_VORTEX_SX:
case WT_VORTEX_DX:
case WT_VORTEX_MX:
unsigned char valb;
unsigned long lTime;
outp(0x22, 0x13); // lock register
outp(0x23, 0xc5); // unlock config
lTime=0x20L*60000L; // 60 sec
outp(0x22,0x3b);
outp(0x23,(lTime>>16)&0xff); // counter msb
outp(0x22,0x3a);
outp(0x23,(lTime>>8)&0xff);
outp(0x22,0x39);
outp(0x33,lTime & 0xff ); // counter lsb
outp(0x22,0x38);
valb = inp(0x23);
outp(0x22,0x38);
outp( 0x23, (valb & 0x0f) | 0xD0); //sys reset
outp(0x22,0x37);
valb = inp(0x23);
outp(0x22,0x37);
outp( 0x23, valb | 0x40); // enable wdt
outp(0x22,0x13); //Lock reg
outp(0x22,0x00); // Lock config
break;
}
m_bInitiated = TRUE;
// force watchdog initialization
Update( 20 );
return TRUE;
}
void CWatchDog::Destroy()
{
if( !m_bInitiated )
return;
switch( m_eType )
{
default:
case WT_UNKNOWN:
break;
case WT_COREMODULE_4DXE:
// stop watch dog
asm
{
mov ah, 0xC3
mov al, 0 // disable
mov bx, 0
int 0x15
}
break;
case WT_TRI_M:
// stop watchdog (disable all watchdog timers)
asm
{
mov AL,0x10
mov DX,ZFLINDEX
out DX,AL
mov DX,ZFLDATA8 // read port 0x10
in AL,DX
and AL,0xFE // clear WD1 enable bit
out DX,AL // write back register value
}
break;
case WT_VORTEX_SX:
case WT_VORTEX_DX:
case WT_VORTEX_MX:
unsigned char valb;
outp(0x22, 0x13); // lock register
outp(0x23, 0xc5); // unlock config
outp(0x22, 0x37);
valb = inp(0x23);
outp(0x22, 0x37);
outp( 0x23, valb & 0xBF);
outp(0x22,0x13); //Lock reg
outp(0x22,0x00); // Lock config
break;
}
m_dwTime = 0;
m_eType = WT_UNKNOWN;
m_bInitiated = FALSE;
}
#endif // WATCHDOG_ENABLED