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.
180 lines
4.3 KiB
180 lines
4.3 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"
|
|
#include "board.h"
|
|
|
|
//extern bool g_bIsVortex;
|
|
|
|
#ifdef WATCHDOG_ENABLED
|
|
|
|
#include "hardware.h"
|
|
|
|
CWatchDog::CWatchDog(){
|
|
m_bInitiated = false;
|
|
m_dwTime = 0;
|
|
m_eType = BT_UNKNOWN;
|
|
}
|
|
|
|
CWatchDog::~CWatchDog(){
|
|
Destroy();
|
|
}
|
|
|
|
|
|
|
|
bool CWatchDog::Create(){
|
|
if( m_bInitiated ) return true;
|
|
CBoard *pTBoard = CBoard::getInstance();
|
|
if( pTBoard == NULL ) return false;
|
|
// determine PC104 type
|
|
m_eType = pTBoard->getBoardType();
|
|
// init watchdog
|
|
switch( m_eType ){
|
|
default:
|
|
case BT_UNKNOWN:
|
|
return true;
|
|
|
|
case BT_COREMODULE_4DXE:
|
|
break;
|
|
|
|
case BT_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
|
|
uint8_t JAJA = 0xEF & ZFLReadb( 0x10 ); // Watchdog Control Low
|
|
ZFLWriteb( 0x10, JAJA );
|
|
JAJA |= 0x10;
|
|
ZFLWriteb( 0x10, JAJA );
|
|
/*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 BT_VORTEX_SX:
|
|
case BT_VORTEX_DX:
|
|
case BT_VORTEX_MX:
|
|
unsigned char valb;
|
|
unsigned long lTime;
|
|
outp(0x22, 0x13); // lock register
|
|
outp(0x23, 0xc5); // unlock config
|
|
#ifdef BOARD_LAZY_INIT
|
|
lTime=0x20L*15000L; // 15 sec
|
|
#else
|
|
lTime=0x20L*5000L; // 5 sec
|
|
#endif
|
|
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 BT_UNKNOWN:
|
|
break;
|
|
|
|
case BT_COREMODULE_4DXE:
|
|
// stop watch dog
|
|
/* asm
|
|
{
|
|
mov ah, 0xC3
|
|
mov al, 0 // disable
|
|
mov bx, 0
|
|
int 0x15
|
|
} */
|
|
__dpmi_regs cr;
|
|
memset( &cr, 0, sizeof( __dpmi_regs ));
|
|
cr.h.ah = 0xC3;
|
|
cr.x.bx = 0;
|
|
__dpmi_int( 0x15, &cr );
|
|
|
|
break;
|
|
|
|
case BT_TRI_M:{
|
|
// stop watchdog (disable all watchdog timers)
|
|
uint8_t JAJA = 0xFE & ZFLReadb( 0x10 ); // Watchdog Control Low
|
|
ZFLWriteb( 0x10, JAJA );
|
|
/*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 BT_VORTEX_SX:
|
|
case BT_VORTEX_DX:
|
|
case BT_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 = BT_UNKNOWN;
|
|
m_bInitiated = false;
|
|
};
|
|
|
|
#endif // WATCHDOG_ENABLED
|