|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: board_.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of board_.cpp
//----------------------------------------------------------------------------
#include "board.h"
CBoard::CBoard( PISRPROC pIsrProc ) : CIsr( pIsrProc ){ m_pOldIsrProc = NULL;
m_wTimer = 0;
#ifndef BOARD_DEFFERED_PROCESSING
m_bReady = FALSE; memset( &m_BoardData, 0, sizeof(BOARDDATA) );#endif
// unknown type of board
m_nBoardType = BT_NONE; m_bBoardMCU = FALSE; m_bOutputDirty = FALSE;
#ifdef DEBUG_ENABLE_OLD_BOARD
// used for A/D conversion
s_pDataArray[0] = s_pDataArray[1] = 0;#endif
// reset mask
m_bOutputMask = 0;}
CBoard::~CBoard(){ Destroy();}
#ifdef DEBUG_ENABLE_OLD_BOARD
BOOL CBoard::InitOldBoard(){ // try to initialize old board
static short infoArray[11];// = { 0, 0x300, 5, 3, 12, 20, 0, 0, 0, 0, 0 };
infoArray[0] = 0; // result
infoArray[1] = 0x300; // base address
infoArray[2] = 5; // interrupt level
infoArray[3] = 3; // DMA level
infoArray[4] = 12; // A/D resolution
infoArray[5] = 20; // A/D scan interval
infoArray[6] = 0; // reserved
infoArray[7] = 0; // reserved
infoArray[8] = 0; // reserved
infoArray[9] = 0; // reserved
infoArray[10] = 0; // reserved
// initialize board
SMM( 0, infoArray ); if( infoArray[0] ) return FALSE;
infoArray[1] = 1; // Number of conversions
infoArray[2] = FP_SEG(s_pDataArray); infoArray[3] = FP_OFF(s_pDataArray); infoArray[4] = 1; // Operation type
infoArray[5] = 0; // Gain setting
infoArray[6] = 0; // Low channel
infoArray[7] = 1; // High channel
infoArray[8] = 0; // reserved
infoArray[9] = 0; // reserved
infoArray[10] = 0; // reserved
// Install ISR for Sapphire
SMM(4, infoArray); if( infoArray[0] ) return FALSE;
// fix irq 7
asm { mov AL, 0xDE out 0xF2, AL in AL, 0xF3 and AL, 0xF3 out 0xF3, AL }
// set type of board
m_nBoardType = BT_OLD;
// install interrupt handler
_disable(); m_pOldIsrProc = _dos_getvect( OLD_INTERRUPT_BOARD ); _dos_setvect( OLD_INTERRUPT_BOARD, m_pIsrProc );#ifndef BOARD_BIND_IRQ_TO_SAPHIR
outportb(PICIMR, inportb(PICIMR) & OLD_INTERRUPT_MASK ); inportb( OLD_BASE_ADDRESS ); // Reset interrupt trigger
// outportb( OLD_BASE_ADDRESS, 0x01 );
#endif
_enable();
#ifdef RELAY_ACTIVATE_BY_ZERO
m_bOutputMask = 0x0;#else
m_bOutputMask = 0x0;#endif
// Enable two lasers
outportb( OLD_BASE_ADDRESS, m_bOutputMask |= 0x07 );
return TRUE;}#endif
BOOL CBoard::InitNewBoard(){ // control register 0
// 0 - VREF (0=internal, 1=external)
// 1 - MODE (0-continues conversations, 1-single conversation )
// 2 - POWER_DOWN (0-active, 1-power down)
// 3,4 - CHANAL SELECT
// 5,6 - NUMBER OF DIFFERENTION CHANALS
// 7 - AUTOSCAN ENABLE
// 8,9 - TEST INPUT ENABLE
// control register 1
// 0 - RESET
// 1 - FIFO_RESET
// 2 - FIFO_LEVEL
// 3 - FIFO_LEVEL
// 4 - DATA_AVALIBLE TYPE (pulse = 1, static = 0)
// 5 - DATA_AVALIBLE POLARITY (hi = 1,0 = low)
// 6 - R/W, RD/WR SELECTION
// 7 - BIN/2s DATA FORMAT (binary = 1, 2s = 0 )
// 8 - OFFSET (0=normal, 1=offset calibration)
// 9 - RBACK (0=normal, 1=debug mode)
#ifdef RELAY_ACTIVATE_BY_ZERO
m_bOutputMask = BE_NEW_DC0;#else
m_bOutputMask = 0;#endif
// disable laser devices
outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
// nessesary to make delay
delay(100);
// check if this is a new board
m_bBoardMCU = inportb( NEW_BASE_ADDRESS + 0x05 ) == 0x5A;
BSNLB=0; BSNHB=0;
// if not MCU board
if( m_bBoardMCU ) { BSNLB=inportb( NEW_BASE_ADDRESS + 6 ); BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
outportb( NEW_BASE_ADDRESS + 6, 0xFF ); outportb( NEW_BASE_ADDRESS + 7, 0x11 );
outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF ); outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF ); outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift >> 8 ); // zero offset
outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift & 0xFF );// outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
// outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
} else { // write to CR0
outportb(NEW_BASE_ADDRESS + 1, 0x04); // 1st word
outportb(NEW_BASE_ADDRESS, 0x01);
// write to CR1
outportb(NEW_BASE_ADDRESS + 1, 0x04); // 2nd word
outportb(NEW_BASE_ADDRESS, 0x00);
// write to CR0
outportb(NEW_BASE_ADDRESS + 1, 0x00); // 3th word
outportb(NEW_BASE_ADDRESS, 0x8A); // 10001010
// 10001--- autoscan two single-ended channels,
// -----0-- ADC is active,
// ------1- single conversation mode
// -------0 internal reference
// outportb(BASE_ADDRESS, 0x02); // One channel, internal reference
// write to CR1
outportb(NEW_BASE_ADDRESS + 1, 0x04); // 4th word
#ifdef BOARD_A2D_FOUR_SAMPLES
outportb(NEW_BASE_ADDRESS, 0x8A); //(10011010)
// 1------- output in binary format
// -0------ RD: read input, WR: write input
// --00---- DATA_AV: active low level
// ----10-- trigger level 8
// ------1- FIFO reset
// -------0 no reset
#else
outportb(NEW_BASE_ADDRESS, 0x92); // 10010010
// 1------- output in binary format
// -0------ RD: read input, WR: write input
// --01---- DATA_AV: active low pulse
// ----00-- trigger level 1
// ------1- FIFO reset
// -------0 no reset
#endif
}
// set type of board
m_nBoardType = BT_NEW;
// install handler
m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD ); _disable(); _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc ); outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK ); _enable();
// enable devices
outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask |= BE_NEW_DEVICE0 | BE_NEW_DEVICE1 );
return TRUE;}
BOOL CBoard::Create( BOARD_SETTINGS* pSettings ){ Destroy();
m_Settings = *pSettings;
#ifdef DEBUG_ENABLE_OLD_BOARD
if( InitOldBoard() ) return TRUE;#endif
if( InitNewBoard() ) return TRUE;
return FALSE;}
void CBoard::Destroy(){ if( m_pOldIsrProc ) { if( m_nBoardType == BT_NEW ) { outportb( PICIMR, inportb(PICIMR) | !NEW_INTERRUPT_MASK ); _disable(); _dos_setvect( NEW_INTERRUPT_BOARD, m_pOldIsrProc ); _enable(); }#ifdef DEBUG_ENABLE_OLD_BOARD
else if( m_nBoardType == BT_OLD ) {#ifndef BOARD_BIND_IRQ_TO_SAPHIR
outportb( PICIMR, inportb(PICIMR) | !OLD_INTERRUPT_MASK ); outportb( OLD_BASE_ADDRESS, m_bOutputMask &= ~0x07 ); // Disable interrupt
#endif
_disable(); _dos_setvect( OLD_INTERRUPT_BOARD, m_pOldIsrProc ); _enable(); }#endif
m_pOldIsrProc = NULL;
#ifndef BOARD_DEFFERED_PROCESSING
m_bReady = FALSE; memset( &m_BoardData, 0, sizeof(BOARDDATA) );#endif
}
// unknown type of board
m_nBoardType = BT_NONE;
// used for A/D conversion
#ifdef DEBUG_ENABLE_OLD_BOARD
s_pDataArray[0] = s_pDataArray[1] = 0;#endif
}
|