// // file: gstm.cpp // purpose: Control the GSTM module // written for the AlphaPC164 // // #include #include #include "l2pci/PCIDev.hpp" #include "l2mbus/DMADev.hpp" #include "l2mbus/TSIDev.hpp" #include "l2mbus/PIODev.hpp" #include // setup for VME: #include "l2vme/UIIDev.hpp" #include "l2pci/MemMap.hpp" #include "l2vme/LocalVmeMaster.hpp" // include file containing GSTM defines #include "gstm_define.h" #include "gstm_masks.h" using namespace l2vme; using namespace l2mbus; uint32 swap(uint32 data) { return(((data&0xff000000)>>24) | ((data&0x00ff0000)>> 8) | ((data&0x0000ff00)<< 8) | ((data&0x000000ff)<<24) ); } void rsleep(uint32 i) { // sleep in microseconds for(uint32 k=0;k1\n"); scanf("%d",&data_nexp); for (k=0;k1) value=1; // create a bit pattern with a single 0 uint32 mask0=~(0x1<read32(offset)); uint32 cmd=setBit(mask0,bit%0x20,1); pvme->write32(offset,swap(cmd)); } inline void enableBit(uint32 offset_bit, LocalVmeMaster *pvme) { uint32 offset=offset_bit/0x100; uint32 bit=offset_bit%0x100; enableBit(offset,bit,pvme); } // set a single bit in a register to 0 void disableBit(uint32 offset,uint32 bit, LocalVmeMaster *pvme) { uint32 mask0=swap(pvme->read32(offset)); uint32 cmd=setBit(mask0,bit%0x20,0); pvme->write32(offset,swap(cmd)); } inline void disableBit(uint32 offset_bit, LocalVmeMaster *pvme) { uint32 offset=offset_bit/0x100; uint32 bit=offset_bit%0x100; disableBit(offset,bit,pvme); } // get the register content uint32 getRegister(uint32 offset, LocalVmeMaster *pvme) { return(swap(pvme->read32(offset))); } // set a register inline void setRegister(uint32 offset,uint32 cmd, LocalVmeMaster *pvme) { pvme->write32(offset,swap(cmd)); } //Reset inline void reset(LocalVmeMaster *pvme) { uint32 offset,cmd; // start by writing 0 to the control and mode registers. offset=GSTM_CTRL; cmd=0x0; pvme->write32(offset,swap(cmd)); offset=GSTM_MODE; cmd=0x0; pvme->write32(offset,swap(cmd)); // reset the module, which requires //several writes, all of them are sticky. offset=GSTM_CTRL; uint32 mask0=swap(pvme->read32(offset)); // global reset: cmd=setBit(mask0,CTRL_RESET,1); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); // wait a little while rsleep(500); cmd=setBit(mask0,CTRL_RESET,0); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); // reset the error status bit cmd=setBit(mask0,CTRL_CLR_ERROR,1); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); cmd=setBit(mask0,CTRL_CLR_ERROR,0); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); // Clear the FIFOs cmd=setBit(mask0,CTRL_CLR_FIFO,1); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); cmd=setBit(mask0,CTRL_CLR_FIFO,0); pvme->write32(offset,swap(cmd)); mask0=swap(pvme->read32(offset)); }