📄 libvme.cpp
字号:
// Inputs : // int addr - VME byte Address to Read the long word from// Outputs : the value of the long word// Description: Read a long from the VME Bus// Remarks : Will throw a BusError execption if there is an error// History ://-----------------------------------------------------------------------------unsigned int VMEBus::ReadLong(int addr){ int c; unsigned int v; lseek(vme_handle, addr, SEEK_SET); c = read(vme_handle,&v,4);#ifdef DEBUG printf("<libvme:Readlong> addr=%08X v=%02X s=%01X\n", addr, v, c);#endif if (c != 4) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_READ); } else lasterror = 0; if (iSwapEndian) return SwapEndian(v); else return v; }//-----------------------------------------------------------------------------// Function : WriteByte// Inputs : // int addr - VME byte Address to write the byte to// uchar v - the byte to write// Outputs :// Description: Write a Byte to the VME Bus// Remarks : Will throw a BusError execption if there is an error// History ://-----------------------------------------------------------------------------void VMEBus::WriteByte(int addr,unsigned char v){ int c; lseek(vme_handle, addr, SEEK_SET); c = write(vme_handle,&v,1);#ifdef DEBUG printf("<libvme:WriteByte> addr=%08X v=%02X s=%01X\n", addr, v, c);#endif if (c != 1) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_WRITE); } else lasterror = 0;}//-----------------------------------------------------------------------------// Function : WriteWord// Inputs : // int addr - VME byte Address to write the word to// ushort v - the word to write// Outputs :// Description: Write a word to the VME Bus// Remarks : Will throw a BusError execption if there is an error// History ://-----------------------------------------------------------------------------void VMEBus::WriteWord(int addr, unsigned short v){ int c; unsigned short result; if (iSwapEndian) result = SwapEndian(v); else result = v; lseek(vme_handle,addr,SEEK_SET); c = write(vme_handle,&result,2);#ifdef DEBUG printf("<libvme:WriteWord> addr=%08X v=%02X s=%01X\n", addr, result, c);#endif if (c != 2) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_WRITE); } else lasterror = 0;}//-----------------------------------------------------------------------------// Function : WriteLong// Inputs : // int addr - VME byte Address to write the long word to// uint v - the long word to write// Outputs :// Description: Write a long word to the VME Bus// Remarks : Will throw a BusError execption if there is an error// History :// 99/Apr/9 Fixed unsigned short result to unsigned long result// This would not write a long correctly before this fix.//----------------------------------------------------------------------------void VMEBus::WriteLong(int addr,unsigned int v){ int c; unsigned long result; if (iSwapEndian) result = SwapEndian(v); else result = v; lseek(vme_handle,addr,SEEK_SET); c = write(vme_handle,&result,4);#ifdef DEBUG printf("<libvme:WriteLong> addr=%08X v=%08lX s=%01X\n", addr, result, c);#endif if (c != 4) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_WRITE); } else lasterror = 0;}//-----------------------------------------------------------------------------// Function : VMEerror// Inputs :// Outputs : the value of the last error that happened// Description: Return lasterror// Remarks :// This is not really used anymore, we now throw execptions, but it is left// in for older programs. Please don't use it anymore// History ://-----------------------------------------------------------------------------int VMEBus::VMEerror(){ return lasterror;}//-----------------------------------------------------------------------------// Function : ReadWord_wa// Inputs :// int addr - the Word Address of the word to read// Outputs : the word that was read from the VME bus// Description: This function uses word addressing insted of byte addressing// Remarks :// This function is used when the native register map for a board is in words// History ://-----------------------------------------------------------------------------unsigned short VMEBus::ReadWord_wa(int addr){ return ReadWord(addr * 2);}//-----------------------------------------------------------------------------// Function : WriteWord_wa// Inputs :// int addr - the Word Address of the word to write// ushort v - the word to write// Outputs : // Description: This function uses word addressing insted of byte addressing// Remarks :// This function is used when the native register map for a board is in words// History ://-----------------------------------------------------------------------------void VMEBus::WriteWord_wa(int addr,unsigned short v){ WriteWord(addr * 2,v);}//-----------------------------------------------------------------------------// Function : ReadLong_la// Inputs :// int addr - the long word Address of the long word to read// Outputs : the long word that was read from the VME bus// Description: This function uses long word addressing insted of byte // addressing// Remarks :// This function is used when the native register map for a board is in // long words// History ://-----------------------------------------------------------------------------unsigned long VMEBus::ReadLong_la(int addr){ return ReadLong(addr * 4);}//-----------------------------------------------------------------------------// Function : WriteLong_la// Inputs :// int addr - the long word Address of the long word to write to// uint v - the long word to write// Outputs : // Description: This function uses long word addressing insted of byte // addressing// Remarks :// This function is used when the native register map for a board is in // long words// History ://-----------------------------------------------------------------------------void VMEBus::WriteLong_la(int addr,unsigned long v){ WriteLong(addr * 4,v);}//-----------------------------------------------------------------------------// Function : ReadBlock// Inputs :// int addr - VME Byte address to read from// int count - The number of BYTES to read// uchar*buff - Pointer to place data into (the user must provide enough room)// Outputs : The number of Byte read// Description:// Remarks : Will throw a BusError execption if there is an error. This // function can be used to do DMA transfers if DMA mode is enabled.// History ://-----------------------------------------------------------------------------int VMEBus::ReadBlock(int addr, int count, unsigned char *buff){ int c; lseek(vme_handle,addr,SEEK_SET); c = read(vme_handle,buff,count); if (c != count) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_READ); } else lasterror = 0; return c;}//-----------------------------------------------------------------------------// Function : WriteBlock// Inputs :// int addr - VME Byte address to read from// int count - The number of BYTES to write// uchar*buff - Pointer to data // Outputs : The number of Byte written// Description:// Remarks : Will throw a BusError execption if there is an error. This // function can be used to do DMA transfers if DMA mode is enabled.// History ://-----------------------------------------------------------------------------int VMEBus::WriteBlock(int addr, int count, unsigned char *buff){ int c; lseek(vme_handle,addr,SEEK_SET); c = write(vme_handle,buff,count); if (c != count) { lasterror = -1; throw VME_BusError(addr + c, c, VME_TYPE_WRITE); } else lasterror = 0; return c;}//-----------------------------------------------------------------------------// Function : SwapEndianOff// Inputs :// Outputs : returns the value of iSwapEndian// Description: Use this function to disable the Endian Swapping that this// library will do on word and long word accesses// Remarks :// History ://-----------------------------------------------------------------------------int VMEBus::SwapEndianOff(void){ iSwapEndian = 0; return (iSwapEndian);}//-----------------------------------------------------------------------------// Function : SwapEndianOn// Inputs :// Outputs : returns the value of iSwapEndian// Description: Use this function to enable the Endian Swapping that this// library will do on word and long word accesses// Remarks :// History ://-----------------------------------------------------------------------------int VMEBus::SwapEndianOn(void){ iSwapEndian = 1; return (iSwapEndian);}//-----------------------------------------------------------------------------// Function : Mode_DMA// Inputs :// Outputs :// Description: Turn on DMA mode transfers// Remarks :// History ://-----------------------------------------------------------------------------void VMEBus::Mode_DMA(void){ ioctl(vme_handle,IOCTL_SET_MODE,MODE_DMA);}//-----------------------------------------------------------------------------// Function : Mode_Programmed// Inputs :// Outputs :// Description: Turn off DMA mode transfers// Remarks :// History ://-----------------------------------------------------------------------------void VMEBus::Mode_Programmed(void){ ioctl(vme_handle,IOCTL_SET_MODE,MODE_PROGRAMMED);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -