/* hapd.cc tool for hapd module update: 04/05/30 */ #include #include #include #include #include "VMEModuleA16D16.hh" enum { BASE_ADDRESS = 0x6000 }; enum { MODULE_SIZE = 0x20 }; class Hapd { public: enum { DSPINIT_OP, STATUS_OP, COMMAND_OP, WRITE_OP, READ_OP, HITDATA_OP }; enum { ADR_VERSION = 0x00, // check board version; read only ADR_MODE1 = 0x02, // mode set register 1 ADR_MODE2 = 0x04, // mode set register 2 ADR_SPW = 0x06, // strobe pulse width ADR_STATUS = 0x08, // status ADR_RESET = 0x0a, // software reset; write only ADR_IO1L = 0x18, // I/O 1 lower 16 bit ADR_IO1H = 0x1a, // I/O 1 higher 16 bit ADR_IO2L = 0x1c, // I/O 2 lower 16 bit ADR_IO2H = 0x1e, // I/O 2 higher 16 bit }; private: int m_operation; int m_narg; char **m_argument; VMEModuleA16D16 *m_module; public: Hapd( int argc, char *argv[] ); int dispatch_operation( const char *s ); void show_usage(); int go(); private: int command(); int dspinit(); int hitdata(); int read(); int status(); int write(); }; Hapd::Hapd( int argc, char * argv[] ) { if( argc<2 || dispatch_operation(argv[1]) < 0 ) show_usage(); m_narg = argc - 2; m_argument = new char*[m_narg]; for(int k=0;k 0 ) addr = (caddr_t) n; } p = getenv( "MODULE_SIZE" ); if( p!=NULL ) { unsigned long n = strtoul( p, 0, 0 ); if( n > 0 ) size = (size_t) n; } // VMEModuleA16D16 module( addr, size ); // printf( "base address = 0x%x / size = 0x%x\n", (int)addr, (int)size ); m_module = new VMEModuleA16D16( addr, size ); } int Hapd::go() { switch( m_operation ) { case COMMAND_OP: return command(); case DSPINIT_OP: return dspinit(); case HITDATA_OP: return hitdata(); case READ_OP: return read(); case STATUS_OP: return status(); case WRITE_OP: return write(); default: return -1; } } int Hapd::dispatch_operation( const char *s ) { if( !strcmp(s,"c") || !strcmp(s,"command") ) m_operation = COMMAND_OP; else if( !strcmp(s,"d") || !strcmp(s,"dspinit") ) m_operation = DSPINIT_OP; else if( !strcmp(s,"h") || !strcmp(s,"hitdata") ) m_operation = HITDATA_OP; else if( !strcmp(s,"r") || !strcmp(s,"read") ) m_operation = READ_OP; else if( !strcmp(s,"s") || !strcmp(s,"status") ) m_operation = STATUS_OP; else if( !strcmp(s,"w") || !strcmp(s,"write") ) m_operation = WRITE_OP; else return -1; return 0; } int Hapd::command() { if(m_narg<1) show_usage(); unsigned short value = strtoul( m_argument[0], 0, 0 ); m_module->write(ADR_IO2H/2, value); printf( "command 0x%04x\n", value ); return 1; } int Hapd::dspinit() { m_module->write(ADR_RESET/2, 0xffff); // RESET unsigned version = m_module->read(ADR_VERSION/2); m_module->write(ADR_MODE1/2, 0x0808); // DATA0 = input to DSP8230 (read) m_module->write(ADR_MODE2/2, 0x0909); // DATA1 = output from DSP8230 (write) m_module->write(ADR_IO2H/2, 0x10); // send CMD_RESET printf( "dspinit done (module version 0x%04x)\n", version ); return 1; } int Hapd::hitdata() { unsigned hd = m_module->read(ADR_IO1H/2); printf( "read hitdata 0x%04x\n", hd ); return 1; } int Hapd::read() { unsigned md = m_module->read(ADR_IO1L/2); printf( "read miscdata 0x%04x\n", md ); return 1; } int Hapd::status() { unsigned st = m_module->read(ADR_STATUS/2); printf( "read status 0x%04x\n", st ); return 1; } int Hapd::write() { if(m_narg<1) show_usage(); unsigned short value = strtoul( m_argument[0], 0, 0 ); m_module->write(ADR_IO2L/2, value); printf( "write data 0x%04x\n", value ); return 1; } void Hapd::show_usage(){ const char *cmd = "hapd"; printf( "%s operation [arguments]\n", cmd ); printf( " %s c value : command\n", cmd ); printf( " %s d : dspinit\n", cmd ); printf( " %s h : hitdata\n", cmd ); printf( " %s r : read\n", cmd ); printf( " %s s : status\n", cmd ); printf( " %s w value : write\n", cmd ); exit(1); } int main( int argc, char * argv[] ) { Hapd hapd( argc, argv ); hapd.go(); }