From: <ro...@us...> - 2008-10-07 14:31:00
|
Revision: 1998 http://nscldaq.svn.sourceforge.net/nscldaq/?rev=1998&view=rev Author: ron-fox Date: 2008-10-07 14:29:59 +0000 (Tue, 07 Oct 2008) Log Message: ----------- - Build the NSCL CVMEInterface class. - add tclpackage directory. (need to stock it etc)> Modified Paths: -------------- trunk/nextgen/configure.ac trunk/nextgen/sbs/Makefile.am Added Paths: ----------- trunk/nextgen/sbs/nsclapi/ trunk/nextgen/sbs/nsclapi/CVMEInterface.h trunk/nextgen/sbs/nsclapi/Locking.cpp trunk/nextgen/sbs/nsclapi/Makefile.am trunk/nextgen/sbs/nsclapi/SBSBIT3API.cpp trunk/nextgen/sbs/nsclapi/SBSBit3API.h trunk/nextgen/sbs/tclpackage/ Modified: trunk/nextgen/configure.ac =================================================================== --- trunk/nextgen/configure.ac 2008-10-07 13:41:24 UTC (rev 1997) +++ trunk/nextgen/configure.ac 2008-10-07 14:29:59 UTC (rev 1998) @@ -443,6 +443,7 @@ sbs/driver/src/Makefile sbs/driver/include/Makefile sbs/driver/dd/GNUmakefile + sbs/nsclapi/Makefile docbuild/Makefile docconfig/Makefile]) Modified: trunk/nextgen/sbs/Makefile.am =================================================================== --- trunk/nextgen/sbs/Makefile.am 2008-10-07 13:41:24 UTC (rev 1997) +++ trunk/nextgen/sbs/Makefile.am 2008-10-07 14:29:59 UTC (rev 1998) @@ -1 +1 @@ -SUBDIRS = driver \ No newline at end of file +SUBDIRS = driver nsclapi Added: trunk/nextgen/sbs/nsclapi/CVMEInterface.h =================================================================== --- trunk/nextgen/sbs/nsclapi/CVMEInterface.h (rev 0) +++ trunk/nextgen/sbs/nsclapi/CVMEInterface.h 2008-10-07 14:29:59 UTC (rev 1998) @@ -0,0 +1,107 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +/*! + Provides device/driver independent interfaces to the VME bus. + This is implemented as a class with wholey static members for the following + reasons: + - Class provides a namespace context to prevent global namespace polution. + - Class allows for future optimizations that support 'sharing' address space + mappings. + + The basic functions we support are: + - Map an address space. + - Unmap an address space. + - Do a block read + - Do a block write. + + The address modes supported are: + A16/D32 - Short I/O space. + A24/D32 - Standard memory. + A32/D32 - Extended memory. + GEO/D32 - Geographical addressing. + MCST/D32 - Multicast control register access. + CBLT/D32 - Chained block transfer. + + \note Assumptions: + - The goal is simplicity. + - There is only one driver on each system. + - All address spaces are open read/write. + - The goal is simplicity! + + +*/ + +#ifndef __VMEINTERFACE_H +#define __VMEINTERFACE_H + + +class CVMEInterface +{ + public: + // Type definitions: + + typedef enum { // Addressing modes: + A16, + A24, + A32, + GEO, + MCST, + CBLT, + LAST, + ShortIO = A16, + Standard = A24, + Extended = A32, + Geographical = GEO, + Multicast = MCST, + ChainedBlock = CBLT +#ifdef HAVE_WIENERUSBVME_INTERFACE + , + A24SuperBLT, + A24UserBLT, + A32SuperBLT, + A32UserBLT, + +#endif + } AddressMode; + + static const char* m_szDriverName; // Name of driver (e.g. NSCLBiT3). + + static void* Open(AddressMode nMode, + unsigned short crate = 0); //!< Open a logical device. + static void Close(void* pDeviceHandle); //!< Close the logical device. + static void* Map(void* pDeviceHandle, + unsigned long nBase, + unsigned long nBytes); //!< Map a chunk of the bus to pva. + static void Unmap(void* pDeviceHandle, + void* pBase, + unsigned long lBytes); //!< Unmap a previously mapped section. + + static int Read(void* pDeviceHandle, + unsigned long nOffset, + void* pBuffer, + unsigned long nBytes); //!< Block read from VME. + static int Write(void* pDeviceHandle, + unsigned long nOffset, + void* pBuffer, + unsigned long nBytes); //!< Block write to vme. + static void Lock(); + static void Unlock(); + +}; + + +#endif Property changes on: trunk/nextgen/sbs/nsclapi/CVMEInterface.h ___________________________________________________________________ Added: svn:executable + * Added: trunk/nextgen/sbs/nsclapi/Locking.cpp =================================================================== --- trunk/nextgen/sbs/nsclapi/Locking.cpp (rev 0) +++ trunk/nextgen/sbs/nsclapi/Locking.cpp 2008-10-07 14:29:59 UTC (rev 1998) @@ -0,0 +1,179 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +#include <config.h> + +#include <CVMEInterface.h> +#include <ErrnoException.h> +#include <unistd.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> +#include <assert.h> +#include <string> + +using namespace std; + +// In some cases we need to define the semun union: + +#if defined(__GNU_LIBRARY__) && !(defined(_SEM_SEMUN_UNDEFINED)) +#else +union semun { + int val; // SETVAL value. + struct semid_ds *buf; // IPC_STAT, IPC_SET buffer. + unsigned short int *array; // Array for GETALL/SETALL + struct seminfo* _buf; // Buffer for IPC_INFO +}; +#endif + + +/*! + This file implements coarse grained VME locking. + If applications use this, the entire VME subsystem will be controlled + by a single lock. +*/ + +static int semid = -1; // This will be the id of the locking semaphore +static int semkey= 0x564d4520; // "VME " :-). + +/*! + This internal function is used to establish the semaphore: + - If the semaphore exists, it's id is just stored in semid. + - If the semaphore does not exist we try to create it O_EXCL + this is an attempt to deal with any timing holes that may + occur when two programs simultaneously attemp to create the semaphore. + - If the O_EXCL creation succeeds (semaphore does not exist), it is + given in initial value of 1 so that a single process can pass the lock + gate. + - If the O_EXCL creation fails, the process backs off for a while and + then does a semget for an existing semaphore again assuming that on the + second try, all initialization has been complete. + + \throw CErrnoException + If an error occured on any of the system calls. + +*/ +static void +AttachSemaphore() +{ + // Retry loop in case anybody makes and then kills it: + + while(1) { + // Try to get the id of an existing semaphore: + + semid = semget(semkey, 0, 0777); // Try to map: + if(semid >= 0) break; // Previously existing!! + if(errno != ENOENT) { + throw + CErrnoException("AttachSemaphore - semget error unexpected"); + } + // Sempahore does not exist. Try to be the only guy to + // create it: + + semid = semget(semkey, 1, 0777 | IPC_CREAT | IPC_EXCL); + if(semid >= 0) { + // We're the creator... initialize the sempahore, and return. + + union semun data; + data.val = 1; + + int istat = semctl(semid, 0, SETVAL, data); // Allow 1 holder + if(istat < 0) { + throw CErrnoException("AttachSemaphore - semctl error unexpected"); + } + + break; + } + if(errno != EEXIST) { + throw + CErrnoException("AttachSemaphore - semget error unexpected"); + } + // The semaphore popped into being between the initial try + // to just attach it and our try to create it. + // The next semget should work, but we want to give + // the creator a chance to initialize the semaphore so + // we don't try to take out a lock on the semaphore before + // it is completely initialized: + + sleep(1); + } + return; +} +/*! + Lock the semaphore. If the semid is -1, the + semaphore is created first. + + \throw CErrnoException + - Really from AttachSemaphore + - From failures in semop. +*/ +void +CVMEInterface::Lock() +{ + // If necessary, get the semaphore id.. + + if (semid == -1) AttachSemaphore(); + assert(semid >= 0); // Otherwise attach.. throws. + + struct sembuf buf; + buf.sem_num = 0; // Only one semaphore. + buf.sem_op = -1; // Want to take the semaphore. + buf.sem_flg = SEM_UNDO; // For process exit. + + while (1) { // In case of signal... + int stat = semop(semid, &buf, 1); + + if(stat == 0) break; + + if(errno != EINTR) { // Bad errno: + throw CErrnoException("CVMEInterface::Lock semop gave bad status"); + } + // On EINTR try again. + } + return; +} +/*! + Unlock the semaphore. It is a crime to unlock the semaphore if it doesn + not yet exist, since that would be unlocking a semaphore that is not yet + locked. + + \throw CErrnoException + If the semop operation produced an error. + \throw string + If the semaphore did not yet exist. +*/ +void +CVMEInterface::Unlock() +{ + if(semid == -1) { + throw string("Attempt to unlock the semaphore before it was created"); + } + struct sembuf buf; + buf.sem_num = 0; + buf.sem_op = 1; + buf.sem_flg= SEM_UNDO; // Undoes the locking undo. + + while(1) { // IN case of signal though not likely. + int stat = semop(semid, &buf, 1); + if(stat == 0) break; // Got the job done!! + if(errno != EINTR) { + throw CErrnoException("CVMEInterface::Unlock semop gave bad status"); + } + // on EINTR try again. + } + return; +} Added: trunk/nextgen/sbs/nsclapi/Makefile.am =================================================================== --- trunk/nextgen/sbs/nsclapi/Makefile.am (rev 0) +++ trunk/nextgen/sbs/nsclapi/Makefile.am 2008-10-07 14:29:59 UTC (rev 1998) @@ -0,0 +1,21 @@ +lib_LTLIBRARIES = libSBSVmeAPI.la +libSBSVmeAPI_la_SOURCES = SBSBIT3API.cpp Locking.cpp +include_HEADERS = CVMEInterface.h SBSBit3API.h + +# Locking.cpp + + +libSBSVmeAPI_la_LDFLAGS = -version-info 1:0:0 \ + -Wl"-rpath=$(libdir)" + +libSBSVmeAPI_la_LIBADD = @top_srcdir@/base/exception/libException.la \ + @top_srcdir@/sbs/driver/src/libbtp.la + + +INCLUDES = -I@top_srcdir@/base/headers -I@top_srcdir@/base/exception \ + -I@top_srcdir@/sbs/driver/include + +LDFLAGS = -lpthread + + + Property changes on: trunk/nextgen/sbs/nsclapi/Makefile.am ___________________________________________________________________ Added: svn:executable + * Added: trunk/nextgen/sbs/nsclapi/SBSBIT3API.cpp =================================================================== --- trunk/nextgen/sbs/nsclapi/SBSBIT3API.cpp (rev 0) +++ trunk/nextgen/sbs/nsclapi/SBSBIT3API.cpp 2008-10-07 14:29:59 UTC (rev 1998) @@ -0,0 +1,1013 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + + +static const char* Copyright= "(C) Copyright Michigan State University 2002, All rights reserved"; + + +#include <config.h> + +#include "CVMEInterface.h" +#include "SBSBit3API.h" // Device specific api. + +#ifndef BT1003 +#define BT1003 +#endif +extern "C" { +#include <btapi.h> +#include <btngpci.h> +} +#include <string> +#include <string.h> + + +using namespace std; + + +const char* CVMEInterface::m_szDriverName="SBSBIT3"; + +/* + Local data structures. + */ + +// Translating address spaces to logical device specifiers: + +struct DeviceEntry { + CVMEInterface::AddressMode s_eModeId; + bt_dev_t s_eLogicalDevice; +}; + +static const DeviceEntry kaDeviceTable[] = { + {CVMEInterface::A16, BT_DEV_IO }, + {CVMEInterface::A24, BT_DEV_A24 }, + {CVMEInterface::A32, BT_DEV_A32 }, + {CVMEInterface::GEO, BT_DEV_GEO }, + {CVMEInterface::MCST, BT_DEV_MCCTL }, + {CVMEInterface::CBLT, BT_DEV_CBLT } +}; + +static const unsigned int knDeviceTableSize = sizeof(kaDeviceTable)/ + sizeof(DeviceEntry); + +static const unsigned int BTERRORLENGTH(100); // Length of an error string. + +// Local private 'static' functions. + +/*! + Translate an address space selector into a logical device + selector. + +Parameters: + +\param eAmode CVMEInterface::AddressMode [in] Addressing mode to + translate. + +Returns: +\return bt_dev_t Logical device specifier for bit 3. + +Exceptions: +\throw string describing why the lookup failed. + +*/ + +static bt_dev_t +AddressModeToDevice(CVMEInterface::AddressMode eMode) +{ + for(int i = 0; i < knDeviceTableSize; i++) { + if(kaDeviceTable[i].s_eModeId == eMode) { + return kaDeviceTable[i].s_eLogicalDevice; + } + } + throw string("[SBSBit3]AddressModeToDevice-no such address mode"); +} + +/*! + If necessary throw an error from the return code generated by a + Bt interface library function. + \param pDevice [bt_desc_t* in]: Pointer to device unit open on b3. + \param nReturnCode [bt_error_t in]: A return code from the bit 3 interface + library. + \param pContextString [const char* in]: A string describing the context + of the potential error condition. + + \return - does if nReturnCode == BT_SUCCESS, otherwise, formats and + throws a string exception. + \throw string if nReturnCode != BT_SUCCESS. + +*/ +static void +CheckError(bt_desc_t* pDevice, + bt_error_t nReturnCode, + const char* pContextString) +{ + if(nReturnCode != BT_SUCCESS) { + int nContextLen = strlen(pContextString); + char ErrorMessage[nContextLen + BTERRORLENGTH]; + bt_strerror(*pDevice, nReturnCode, pContextString, + ErrorMessage, sizeof(ErrorMessage)); + throw string(ErrorMessage); + } +} + +/*! + Open the a device and returns a handle to it: + - The Address space selector is translated to a device name. + - a bt_desc_t is allocated. + - bt_open is called to fill in the handle. + - A Pointer to the handle is returned to the user. + +Parameters: +\param eMode CVMEInterface::AddressMode [in] Specifies the + address mode desired for the device. +\param nCrate Number of the crate to open. This can be a value from 0-15. + +Throws: + \throw string - Text string describing the error. + +\note The assumption is that both read and write access are desired. +\note We assume there's only one VME crate attached to the system. +*/ +void* +CVMEInterface::Open(AddressMode eMode, + unsigned short nCrate) +{ + bt_desc_t* pDevice = new bt_desc_t; + + // Validate the crate number. + + if(nCrate > BT_MAX_UNITS) { + throw string("CVMEInterface::[SBS]Open - vme crate number > BT_MAX_UNITS"); + } + + try { + char Device[BT_MAX_DEV_NAME]; + + bt_dev_t LogicalDevice = AddressModeToDevice(eMode); + if(!bt_gen_name(nCrate, LogicalDevice, Device, sizeof(Device))) { + throw + string("CVMEInterface[SBSBit3]::Open - bt_gen_name failed"); + } + + bt_error_t err = bt_open(pDevice, Device, BT_RDWR); + CheckError(pDevice, err, "CVMEInterface[SBSBit3]::Open - Open failed "); + + // Set the appropriate byte swap mode for block transfers. + + CSBSBit3VmeInterface::SetSwapMode(pDevice, BT_SWAP_NONE); + + } + catch(...) { + delete pDevice; + throw; + } + + return (void*)pDevice; +} +/*! + Closes a previously opened device. Note that the device handle + is a pointer to a bt_desc_t that will be deleted. + +Parameters: + +\param pDevice - void* [modified] Pointer to the device dependent + handle. In our case that represents a bt_desc_t. + +Exceptions: +\throw string - Describing any errors. +*/ +void +CVMEInterface::Close(void* pDeviceHandle) +{ + bt_desc_t *p = (bt_desc_t*)pDeviceHandle; + + bt_error_t err = bt_close(*p); + + CheckError(p, err, "CVMEInterface[SBSBit3]::Close - bt_close failed:"); + delete p; // It's not safe to delete on throw. + + +} + +/*! + Map a region of VME address space into process virtual address + space. Once mapped, accesses to the process adress space will + be modifying or reading the VME addreess space without any driver + intervention. + +Parameters: +\param pDeviceHandle - void* [in] Device dependent handle open on + the VME interface device (bt_desc_t*). + +\param lOffset - unsigned long [in] - base address of the first + VME location to map. + +\param lBytes - unsigned long [in] - Number of bytes of VME space + desired. + +Returns: +\return void* Pointer to the address space mapped. + +\note Additional space may be mapped before and after the requested + range in order to acocmodate the memory mapping granularity + of the underlying operating system. This additional mapping + is transparent to the user software. + +Exceptions: +\throw string - Explains any errors. + +*/ +void* +CVMEInterface::Map(void* pDeviceHandle, + unsigned long nBase, + unsigned long nBytes) +{ + bt_desc_t* p = (bt_desc_t*)pDeviceHandle; + void* pSpace; + + bt_error_t err = bt_mmap(*p, + &pSpace, nBase, nBytes, + BT_RDWR, BT_SWAP_NONE); + CheckError(p, err, "CVMEInterface[SBSBit3]::Map - bt_mmap failed : "); + return pSpace; +} +/*! + Unmap an existing address map from process virtual addres space to + VME address space. Once the unmap is done, accesses to that + virtual address window will fail with a SEGFLT or BUSERR + (OS dependent). + +Parameters: +\param pDeviceHandle - void* [in] Device handle pointer. In our + case, this points to a bt_desc_t. + +\param pBase - void* [i] Points to the base of the map. + lBytes pointed to by this pointer will become + inaccessible to the calling process as a result + of this call. +\param lBytes - unsigned long [in] Number of bytes in the region. + +Exceptions: +\throw - string - describing errors from bt_unmap. + +*/ +void +CVMEInterface::Unmap(void* pDeviceHandle, + void* pBase, + unsigned long lBytes) +{ + bt_desc_t* p = (bt_desc_t*)pDeviceHandle; + + bt_error_t err = bt_unmmap(*p, pBase, lBytes); + + CheckError(p, err, "CVMEInterface[SBSBit3]::Unmap - bt_mmap failed : "); + +} +/*! + Performs a block transfer of data from the VME bus to a local + buffer. This function does not require a map to operate. + +Parameters: +\param pDeviceHandle - void* [in] Pointer to the device handle + open on a PCI<-->VME bus interface. In our case + the handle is a bt_desc_t* + +\param nOffset - unsigned long [in] Address in VME space from which + the transfer will start. + +\param pBuffer - void* [out] Pointer to the buffer into which data + will be transferred. + +\param nBytes - unsigned long [in] Number of bytes to transfer. + +Returns: +\return int - Number of bytes transferred. + +Exceptions: +\throw string - Descriptive error text if there was a problem. +*/ + +int +CVMEInterface::Read(void* pDeviceHandle, + unsigned long nOffset, + void* pBuffer, + unsigned long nBytes) +{ + bt_desc_t* p = (bt_desc_t*)pDeviceHandle; + size_t nTransferred; + + bt_error_t err = bt_read(*p, pBuffer, nOffset, nBytes, + &nTransferred); + + CheckError(p, err, "CVMEInterface[SBSBit3]::Read - bt_read failed : "); + return nTransferred; + + +} +/*! + Write a block of data from a user buffer to addresses on the VME +bus. + +Parameters: +\param pDeviceHandle void* [in] Pointer to the device specific + handle. In our case this is realy a bt_desc_t* + +\param lOffset unsigned long [in] Base address in the VME for the + transfer. + +\param pBuffer void * [in] Pointer to the buffer from which + the data comes. + +\param lBytes unsigned long [in] Number of bytes to write. + +Returns: +\return int - Number of bytes transferred. + +Exceptions: +\throw string - Descriptive error text if there was a problem. +*/ +int +CVMEInterface::Write(void* pDeviceHandle, + unsigned long nOffset, + void* pBuffer, + unsigned long nBytes) +{ + bt_desc_t* p = (bt_desc_t*)pDeviceHandle; + size_t nTransferred; + + bt_error_t err = bt_write(*p, pBuffer, nOffset, nBytes, + &nTransferred); + CheckError(p, err, "CVMEInterface[SBSBit3]::Write - bt_read failed : "); + + return nTransferred; + + +} +// The functions following this comment are all SBSBit3 API specific. +// The header for them is in SBSBit3API.h Users call these functions at +// their peril as they bind them to a specific piece of hardware. +// + +/*! + Set the dma transfer mode to use VME block transfer. VME Block transfer + allows the device to do away with additional address cycles after a single + initial address cycle establishes the transfer base address, and the DS's + establish the transfer width. Subsequent data transfers assume an + appropriate increment in address.. This allows data transfer to be + significantly faster for blocks of contiguous data. + + Older slave interfaces may not implement DMA transfer however. + + \param pHandle (void* [in]): pointer to the device handle gotten via + CVMEInterface::Open. + \param enable (bool [in]): true if block transfer mode is desired, + false otherwise. + +*/ +void +CSBSBit3VmeInterface::SetDMABlockTransfer(void* pHandle, bool enable) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + + bt_error_t err = bt_set_info(*p, BT_INFO_BLOCK, (bt_devdata_t)enable); + CheckError(p, err, "CSBSBit3VmeInterface::SetDMABlockTransfer failed"); +} +/*! + Set the DMA transfer mode to 'pause'. In pause, mode, the device + re-arbitrates the bus more often than required by the block mode + transfer specification. While this allows other bus masters a better + bus access latency in the presence of DMA transfers, it also reduces + the DMA throughput. + + \param pDevice (void* [in]): Pointer to device handle returned from + VMEInterface::Open(). + \param enable (bool [in]): State desired: + - true - turns on pause mode. + - false - turns off pause mode. +*/ +void +CSBSBit3VmeInterface::SetDMAPauseMode(void* pHandle, bool enable) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_PAUSE, (bt_devdata_t)enable); + CheckError(p, err, "CSBSBit3VmeInterface::SetDMAPauseMode failed"); +} +/*! + Set the maximum transfer width of the interface. Valid values of the + bt_width_t parameter can be any of: + - BT_WIDTH_D8 8 bit maximum transfer width + - BT_WIDTH_D16 16 bit maximum transfer width + - BT_WIDTH_D32 32 bit maximum transfer width + - BT_WIDTH_D64 64 bit maximum transfer width + - BT_WIDTH_ANY Let the driver choose the best setting. + + By default, after power up, the driver is set at BT_WIDTH_D32 since + most P's don't support D6 transfers (according to the Bit3 manual, while this + has changed with PCI-64, the SBS/Bit3 -620 is a 32 bit wide PCI module. + + \param pHandle (void* [in]): Handle open on the device, gotten via + a successful call to CVMEInterface::Open + \param width (bt_data_width_t [in]): Requested width. See above for legal + values. +*/ +void +CSBSBit3VmeInterface::SetMaxTransferWidth(void* pHandle, bt_width_t eWidth) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_DATAWIDTH, eWidth); + CheckError(p, err, "CSBSBit3VmeInterface::SetMaxTransferWidth failed"); +} +/*! + Set the DMA address modifier code. It is important that this be selected + from one of the block transfer modes if DMA block mode is on else DMA + with slaves may not work + correctly. The default DMA transfer mode is supervisory d32 block transfer. + + \param pHandle (void* [in]): Handle returned from CVMEInterface::Open. + \param nModifier (int [in]): Address modifier. Symbolic definitions + of these are as follows: + - BT_AMOD_A32_SB (0x0F) A32 Extended Supervisory Block transfer. + - BT_AMOD_A32_SP (0x0E) A32 Extended Supervisory Program. + - BT_AMOD_A32_SD (0x0D) A32 Extended Supervisory Data Access. + - BT_AMOD_A32_NB (0x0B) A32 Extended Non-Privileged Block transfer. + - BT_AMOD_A32_NP (0x0A) A32 Extended Non-Privileged Program. + - BT_AMOD_A32_ND (0x09) A32 Extended Non-Privileged Data. + - BT_AMOD_A32_SMBLT (0x0C) A32 Multiplexed Block Transfer (D64) priv. + - BT_AMOD_A32_NMBLT (0x08) A32 Multiplexed Block Transfer (D64) nonpriv + - BT_AMOD_A32 see BT_AMOD_A32_SD + - BT_AMOD_A32_D64 see BT_AMOD_A32_SMBLT + - BT_AMOD_A24_SB (0x3F) A24 Standard Supervisory Block + - BT_AMOD_A24_SP (0x3E) A24 Standard Supervisory Program + - BT_AMOD_A24_SD (0x3D) A24 Standard Supervisory Data Access + - BT_AMOD_A24_NB (0x3B) A24 Standard Non-Privileged Block + - BT_AMOD_A24_NP (0x3A) A24 Standard Non-Privileged Program + - BT_AMOD_A24_ND (0x39) A24 Standard Non-Privileged Data + - BT_AMOD_A24_SMBLT (0x3C) A24 Multiplexed Block Transfer (D64) privileged + - BT_AMOD_A24_NMBLT (0x38) A24 Multiplexed Block Transfer (D64) nonpriv. + - BT_AMOD_A24 see BT_AMOD_A24_SD + - BT_AMOD_A24_D64 see BT_AMOD_A24_SMBLT + - BT_AMOD_A16_SD (0x2D) A16 Short Supervisory Data Access + - BT_AMOD_A16_ND (0x29) A16 Short Non-Privileged Data Access + - BT_AMOD_A16 see BT_AMOD_A16_SD + - BT_AMOD_GEO (0x2F) Geographical addressing + - BT_AMOD_MCCTL (0X09) Multicast control register writes (CAEN ADCS). + - BT_AMOD_CBLT (0x0B) Chained block transfer (CAEN adcs). + +*/ +void +CSBSBit3VmeInterface::SetDMAAddressModifier(void* pHandle, int Modifier) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_DMA_AMOD, Modifier); + CheckError(p, err, "CSBSBit3VmeInterface::SetDMAAddressModifier failed"); +} +/*! + SetMMAPAddress modifier sets the address modifier used for the mmap call. + note that this is somewhat dangerous. The devices themselves have a + default address modifier. Use that whenever possible, as this setting + does not revert to default on close !!!! + + \param pHandle (void* [in]): Device handle returned from CVMEInterface::Open + \param Modifier (int [in]): Requested address modifier. Legal values are: + - BT_AMOD_A32_SB (0x0F) A32 Extended Supervisory Block transfer. + - BT_AMOD_A32_SP (0x0E) A32 Extended Supervisory Program. + - BT_AMOD_A32_SD (0x0D) A32 Extended Supervisory Data Access. + - BT_AMOD_A32_NB (0x0B) A32 Extended Non-Privileged Block transfer. + - BT_AMOD_A32_NP (0x0A) A32 Extended Non-Privileged Program. + - BT_AMOD_A32_ND (0x09) A32 Extended Non-Privileged Data. + - BT_AMOD_A32_SMBLT (0x0C) A32 Multiplexed Block Transfer (D64) priv. + - BT_AMOD_A32_NMBLT (0x08) A32 Multiplexed Block Transfer (D64) nonpriv + - BT_AMOD_A32 see BT_AMOD_A32_SD + - BT_AMOD_A32_D64 see BT_AMOD_A32_SMBLT + - BT_AMOD_A24_SB (0x3F) A24 Standard Supervisory Block + - BT_AMOD_A24_SP (0x3E) A24 Standard Supervisory Program + - BT_AMOD_A24_SD (0x3D) A24 Standard Supervisory Data Access + - BT_AMOD_A24_NB (0x3B) A24 Standard Non-Privileged Block + - BT_AMOD_A24_NP (0x3A) A24 Standard Non-Privileged Program + - BT_AMOD_A24_ND (0x39) A24 Standard Non-Privileged Data + - BT_AMOD_A24_SMBLT (0x3C) A24 Multiplexed Block Transfer (D64) privileged + - BT_AMOD_A24_NMBLT (0x38) A24 Multiplexed Block Transfer (D64) nonpriv. + - BT_AMOD_A24 see BT_AMOD_A24_SD + - BT_AMOD_A24_D64 see BT_AMOD_A24_SMBLT + - BT_AMOD_A16_SD (0x2D) A16 Short Supervisory Data Access + - BT_AMOD_A16_ND (0x29) A16 Short Non-Privileged Data Access + - BT_AMOD_A16 see BT_AMOD_A16_SD + - BT_AMOD_GEO (0x2F) Geographical addressing + - BT_AMOD_MCCTL (0X09) Multicast control register writes (CAEN ADCS). + - BT_AMOD_CBLT (0x0B) Chained block transfer (CAEN adcs). +*/ +void +CSBSBit3VmeInterface::SetMMAPAddressModifier(void* pHandle, int Modifier) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_MMAP_AMOD, Modifier); + CheckError(p, err, "CSBSBit3VmeInterface::SetMMAPAddressModifier failed"); +} +/*! + Set the data swap mode. The SBS/Bit3 interface has byte swapping hardware + that can be set as needed to acommodate differences in byte order between + the host (linux system ), and slave interface (VME board). + \param pHandle (void* [in]): Handle received from a successful call to + CVMEInterface::Open. + \param SwapMode (bt_swap_t [in]) Swap mode, can be one of the follwoing: + - BT_SWAP_NONE No swapping + - BT_SWAP_BSNBD Byte swap, non byte data + - BT_SWAP_WS Word swap + - BT_SWAP_WS_BSNBD Word swap and byte swap non btye data + - BT_SWAP_BSBD Byte swap btye data + - BT_SWAP_BSBD_BSNBD Btye swap byte data and byte swap non byte data + - BT_SWAP_BSBD_WS Byte swap byte data and word swap + - BT_SWAP_BSBD_WS_BSNBD All possible swapping + - BT_SWAP_DEFAULT Driver default swapping + + BT_SWAP_DEFAULT is set to transparently swap bytes in VME byte order (big + endian) to PC byte ordering (little endian). + Note that this setting only affects DMA transfers. At present, you have no + control over the swap mode for memory mapping, and it is BT_SWAP_DEFAULT. + +*/ +void +CSBSBit3VmeInterface::SetSwapMode(void* pHandle, bt_swap_t SwapMode) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_SWAP, SwapMode); + CheckError(p, err, "CSBSBit3VmeInterface::SetSwapMode failed"); +} +/*! + Sets the dma threshold. The dma theshold defines the minimum length + transfer in CVMEInterface::Read or CVMEInterface::Write that will turn on + the bit3's dma engine. If a Read/Write is issued for a transfer smaller than + the threshold, the driver will perform PIO to satisfy it, otherwise it will + perform the transfer via DMA. + + This is a trade off between the high speed transfer + of the dma engine against the longer setup time requirement compared to + PIO transfers. If a Read/Write is issued for a transfer smaller than + + \param pHandle (void* [in]): Device handle returned from CVMEInterface::Open + \param nTransfers (int [in]): The new threshold. + +*/ +void +CSBSBit3VmeInterface::SetDMAThreshold(void* pHandle, int nTransfers) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_DMA_THRESHOLD, nTransfers); + CheckError(p, err, "CSBSBit3VmeInterface::SetDMAThreshold failed"); +} +/*! + Sets the DMA polling ceiling. This determines how many transfers are + required before the driver decides to use interrupts as opposed to polling + to determine that a DMA transfer has completed. + + This value represents a trade-off between operation completion latency + (better for polling), and overall linux system responsiveness (better + for interrupts). Since any polling will be done in the device driver, + the linux system will be almost completely unresponsive for the duration + of a DMA that polls for completion. + + \param pHandle (void* [in]): Handle on the device from CVMEInterface::Open. + \param nTransfers (int [in]): The new ceiling value. +*/ +void +CSBSBit3VmeInterface::SetDMAPollCeiling(void* pHandle, int nTransfers) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_DMA_POLL_CEILING, nTransfers); + CheckError(p, err, "CSBSBit3VmeInterface::SetDMAPollCeiling failed"); +} +/*! + Sets the trace mask. The trace mask determines how much inforation the + driver logs to the /var/log files. The less information logged, the better + the performance, however the more information logged, the easier + it is to troubleshoot problems. + \param pHandle (void * [in]): The handle returned from CVMEInterface::Open + \param nMask A bitwise or of any of the following bits: + - BT_TRC_ERROR Fatal system errors, shouldn't happen + - BT_TRC_WARN driver errors that may happen due to external conditions + - BT_TRC_INFO Messages for errors returned to the user + - BT_TRC_CFG driver configuration and initialization + - BT_TRC_RD_WR generic read/write (outside of DMA & PIO) + - BT_TRC_MMAP memory mapping and related code/ + - BT_TRC_BIND bt_bind() and related code + - BT_TRC_CTRL All ioctl() functions + - BT_TRC_OPEN Driver open and close + - BT_TRC_ISR Interrupt Service Routine + - BT_TRC_IRQ_DISP Interrupt Request Processing/Dispatch + - BT_TRC_ICBR user ICBR and the vector returned by applicable kernel + interrupt handlers. + - BT_TRC_ISR_ERR ISR errors only + - BT_TRC_DMA DMA, each transfer + - BT_TRC_PIO PIO, each transfer + - BT_TRC_FUNC function entry and exit + - BT_TRC_ALLOC Allocation/release of resources + - BT_TRC_LOCK all locks (user & driver internal) + - BT_TRC_MAPREG details of each map register load + - BT_TRC_RAWIO Raw I/O register access + - BT_TRC_KLIB Misc. shared kernel routines + - BT_TRC_KDDI All 3rd party driver rouitnes KDDI + - BT_TRC_LIO Low level I/O register rd/wr + - BT_TRC_PROFILE enable H/W timing marks for profiling + - BT_TRC_DETAIL Detailed trace of enabled function + - BT_TRC_HW_DEBUG enable HW trace messages instead of console + - BT_TRC_ERROR Fatal system errors, shouldn't happen + - BT_TRC_WARN driver errors that may happen due to external conditions + - BT_TRC_INFO Messages for errors returned to the user + - BT_TRC_CFG driver configuration and initialization + - BT_TRC_RD_WR generic read/write (outside of DMA & PIO) + - BT_TRC_MMAP memory mapping and related code/ + - BT_TRC_BIND bt_bind() and related code + - BT_TRC_CTRL All ioctl() functions + - BT_TRC_OPEN Driver open and close + - BT_TRC_ISR Interrupt Service Routine + - BT_TRC_IRQ_DISP Interrupt Request Processing/Dispatch + - BT_TRC_ICBR user ICBR and the vector returned by applicable kernel + interrupt handlers. + - BT_TRC_ISR_ERR ISR errors only + - BT_TRC_DMA DMA, each transfer + - BT_TRC_PIO PIO, each transfer + - BT_TRC_FUNC function entry and exit + - BT_TRC_ALLOC Allocation/release of resources + - BT_TRC_LOCK all locks (user & driver internal) + - BT_TRC_MAPREG details of each map register load + - BT_TRC_RAWIO Raw I/O register access + - BT_TRC_KLIB Misc. shared kernel routines + - BT_TRC_KDDI All 3rd party driver rouitnes KDDI + - BT_TRC_LIO Low level I/O register rd/wr + - BT_TRC_PROFILE enable H/W timing marks for profiling + - BT_TRC_DETAIL Detailed trace of enabled function + - BT_TRC_HW_DEBUG enable HW trace messages instead of console + + Note that the default, power up state is BT_TRC_ERROR | BT_TRC_WARN. +*/ +void +CSBSBit3VmeInterface::SetTraceMask(void* pHandle, int nMask) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_set_info(*p, BT_INFO_TRACE, nMask); + CheckError(p, err, "CSBSBit3VmeInterface::SetTraceMask failed"); +} + +// Information retrieval functions: +// Retrieve read-only parameters of the driver. +// +/*! + Retrieve the SBS part number of the PCI component of the bus interface. + + \param pHandle (void* [in]): The handle returned from CVMEInterface::Open. + \return part number as an integer. +*/ +int +CSBSBit3VmeInterface::GetLocalCardPartNumber(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_LOC_PN, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetLocalPartNumber failed"); + return Result; +} +/*! + Retrieve the SBS part number of the VME component of the bus bridge. + \param pHandle (void* [in]): The handle returned from CVMEInterface::Open. + \return part number as an integer. +*/ +int +CSBSBit3VmeInterface::GetRemoteCardPartNumber(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_REM_PN, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetRemotePartNumber failed"); + return Result; +} +/*! + Returns the number of bytes of local memory on any daughter board in + the VME interface. Presumably this will be 0 if no memory daughter board + is installed. + \param pHandle (void* [in]): The handle returned from CVMEInterface::Open. + \return memory size as unsigned int. +*/ +unsigned int +CSBSBit3VmeInterface::GetLocalMemorySize(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_LM_SIZE, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetLocalMemorySize failed"); + return Result; +} +/*! + + Returns a bool indicating whether or not the DMA block mode transfer + is enabled. For more information about this see, + CSBSBit3VmeInterface::SetDMABlockTransfer. + + \param pHandle (void* [in]): handle returned from CVMEInterface::Open. + \return true if dma on this unit will be done in block transfer mode. + +*/ +bool +CSBSBit3VmeInterface::IsDMABlockTransfer(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_BLOCK, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::IsDMABlockTransfer failed"); + return Result; +} +/*! + Returns a bool that indicates whether or not DMA block transfers are done + in pause mode. For more information about pause mode, see: + CSBSBit3VmeInterface::SetDMAPauseMode. + \param pHandle (void* [in]) Handle returned from CVMEInterface::Open + \return true if dma will be done in pause mode. +*/ +bool +CSBSBit3VmeInterface::IsDMAPauseMode(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_PAUSE, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::IsDMAPauseMode failed"); + return Result; +} +/*! + Returns the Maximum transfer width. + \param pHandle (void* [in]) Device handle gotten from CVMEInterface::Open. + \return The return value will be one of: + - BT_WIDTH_D8 8 bits. + - BT_WIDTH_D16 16 bits. + - BT_WIDTH_D32 32 bits. + - BT_WIDTH_D64 64 bits. +*/ +bt_width_t +CSBSBit3VmeInterface::GetMaxTransferWidth(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_DATAWIDTH, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetMaxTransferWidth failed"); + return Result; +} +/*! + Return the current dma address modifier. + \param pHandle (void* [in]) Device handle gotten from CVMEInterface::Open. + \return The return value will be one of + - BT_AMOD_A32_SB (0x0F) A32 Extended Supervisory Block transfer. + - BT_AMOD_A32_SP (0x0E) A32 Extended Supervisory Program. + - BT_AMOD_A32_SD (0x0D) A32 Extended Supervisory Data Access. + - BT_AMOD_A32_NB (0x0B) A32 Extended Non-Privileged Block transfer. + - BT_AMOD_A32_NP (0x0A) A32 Extended Non-Privileged Program. + - BT_AMOD_A32_ND (0x09) A32 Extended Non-Privileged Data. + - BT_AMOD_A32_SMBLT (0x0C) A32 Multiplexed Block Transfer (D64) priv. + - BT_AMOD_A32_NMBLT (0x08) A32 Multiplexed Block Transfer (D64) nonpriv + - BT_AMOD_A32 see BT_AMOD_A32_SD + - BT_AMOD_A32_D64 see BT_AMOD_A32_SMBLT + - BT_AMOD_A24_SB (0x3F) A24 Standard Supervisory Block + - BT_AMOD_A24_SP (0x3E) A24 Standard Supervisory Program + - BT_AMOD_A24_SD (0x3D) A24 Standard Supervisory Data Access + - BT_AMOD_A24_NB (0x3B) A24 Standard Non-Privileged Block + - BT_AMOD_A24_NP (0x3A) A24 Standard Non-Privileged Program + - BT_AMOD_A24_ND (0x39) A24 Standard Non-Privileged Data + - BT_AMOD_A24_SMBLT (0x3C) A24 Multiplexed Block Transfer (D64) privileged + - BT_AMOD_A24_NMBLT (0x38) A24 Multiplexed Block Transfer (D64) nonpriv. + - BT_AMOD_A24 see BT_AMOD_A24_SD + - BT_AMOD_A24_D64 see BT_AMOD_A24_SMBLT + - BT_AMOD_A16_SD (0x2D) A16 Short Supervisory Data Access + - BT_AMOD_A16_ND (0x29) A16 Short Non-Privileged Data Access + - BT_AMOD_A16 see BT_AMOD_A16_SD + - BT_AMOD_GEO (0x2F) Geographical addressing + - BT_AMOD_MCCTL (0X09) Multicast control register writes (CAEN ADCS). + - BT_AMOD_CBLT (0x0B) Chained block transfer (CAEN adcs). +*/ +int +CSBSBit3VmeInterface::GetDMAAddressModifier(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_DMA_AMOD, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetDMAAddressModifier failed"); + return Result; +} +/*! + Get the address modifier that will be applied to the mmap function. + \param pHandle (void* [in]) Device handle gotten from CVMEInterface::Open. + \return The return value will be one of + - BT_AMOD_A32_SB (0x0F) A32 Extended Supervisory Block transfer. + - BT_AMOD_A32_SP (0x0E) A32 Extended Supervisory Program. + - BT_AMOD_A32_SD (0x0D) A32 Extended Supervisory Data Access. + - BT_AMOD_A32_NB (0x0B) A32 Extended Non-Privileged Block transfer. + - BT_AMOD_A32_NP (0x0A) A32 Extended Non-Privileged Program. + - BT_AMOD_A32_ND (0x09) A32 Extended Non-Privileged Data. + - BT_AMOD_A32_SMBLT (0x0C) A32 Multiplexed Block Transfer (D64) priv. + - BT_AMOD_A32_NMBLT (0x08) A32 Multiplexed Block Transfer (D64) nonpriv + - BT_AMOD_A32 see BT_AMOD_A32_SD + - BT_AMOD_A32_D64 see BT_AMOD_A32_SMBLT + - BT_AMOD_A24_SB (0x3F) A24 Standard Supervisory Block + - BT_AMOD_A24_SP (0x3E) A24 Standard Supervisory Program + - BT_AMOD_A24_SD (0x3D) A24 Standard Supervisory Data Access + - BT_AMOD_A24_NB (0x3B) A24 Standard Non-Privileged Block + - BT_AMOD_A24_NP (0x3A) A24 Standard Non-Privileged Program + - BT_AMOD_A24_ND (0x39) A24 Standard Non-Privileged Data + - BT_AMOD_A24_SMBLT (0x3C) A24 Multiplexed Block Transfer (D64) privileged + - BT_AMOD_A24_NMBLT (0x38) A24 Multiplexed Block Transfer (D64) nonpriv. + - BT_AMOD_A24 see BT_AMOD_A24_SD + - BT_AMOD_A24_D64 see BT_AMOD_A24_SMBLT + - BT_AMOD_A16_SD (0x2D) A16 Short Supervisory Data Access + - BT_AMOD_A16_ND (0x29) A16 Short Non-Privileged Data Access + - BT_AMOD_A16 see BT_AMOD_A16_SD + - BT_AMOD_GEO (0x2F) Geographical addressing + - BT_AMOD_MCCTL (0X09) Multicast control register writes (CAEN ADCS). + - BT_AMOD_CBLT (0x0B) Chained block transfer (CAEN adcs). + +*/ +int +CSBSBit3VmeInterface::GetMMAPAddressModifier(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_PIO_AMOD, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetMMAPAddressModifier failed"); + return Result; +} +/*! + The SBS/Bit3 interface has hardware support for byte swapping. Ordinarily, + the interface is set up to transparently swap between the VME standard + byte ordering (big endian), and PC (little endian) byte ordering. This + function returns the current byte swapping selection. + \param pHandle (void* [in]): Handle received from a successful call to + CVMEInterface::Open. + \return SwapMode (bt_swap_t [in]) Swap mode, can be one of the follwoing: + - BT_SWAP_NONE No swapping + - BT_SWAP_BSNBD Byte swap, non byte data + - BT_SWAP_WS Word swap + - BT_SWAP_WS_BSNBD Word swap and byte swap non btye data + - BT_SWAP_BSBD Byte swap btye data + - BT_SWAP_BSBD_BSNBD Btye swap byte data and byte swap non byte data + - BT_SWAP_BSBD_WS Byte swap byte data and word swap + - BT_SWAP_BSBD_WS_BSNBD All possible swapping + - BT_SWAP_DEFAULT Driver default swapping + + BT_SWAP_DEFAULT is set to transparently swap bytes in VME byte order (big + endian) to PC byte ordering (little endian). + Note that this setting only affects DMA transfers. At present, you have no + control over the swap mode for memory mapping, and it is BT_SWAP_DEFAULT. + +*/ +int +CSBSBit3VmeInterface::GetSwapMode(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_SWAP, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetSwapMode failed"); + return Result; +} +/*! + Return the current dma threshold. CVMEInterface::Read or + CVMEInterface::Write calls that cause more than this threshold number of + bus transfers will engage the DMA engine on the SBS/Bit3 interface. Fewer + transactions will result in a programmed I/O transfer in the driver. + + Control over this setting allows control over the trade-off between the + higher transfer rates of the DMA engine vs. programmed contrrol against + the higher overhead required to setup a DMA transfer. + + \param pHandle (void* [in]): Handle returned from CVMEInterface::Open + \return The threshold value. +*/ +int +CSBSBit3VmeInterface::GetDMAThreshold(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_DMA_THRESHOLD, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetDMAThreshold failed"); + return Result; +} +/*! + Return the DMA Poll ceiling. This value determines the number of + transfers performed by a CVMEInterface::Read or CVMEInterface::Write + operation before using interrupts to synchronize completion. This + value represents a trade-off between the improved latency of polling for + completion and the worsened system response of doing so. + + \param pHandle (void* [in]): Handle returned from CVMEInterface::Open + \return The threshold value. +*/ +int +CSBSBit3VmeInterface::GetDMAPollCeiling(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_DMA_POLL_CEILING, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetDMAPollCeiling failed"); + return Result; +} +/*! + Gets the current debugging trace mask for the device driver. + The driver is extensively instrumented with debugging trace code. + The amount of information traced to the system log files is controled + by a trace mask. This function returns the current value of that mask. + Bits in this mask represent a trade off between the extent of debug + support and the driver overhead required to provide it. + \param pHandle (void* [in]): Handle returned from CVMEInterface::Open + \return The value of the trace mask. This is a bit mask make up of the + logical or of the following bits: + - BT_TRC_ERROR Fatal system errors, shouldn't happen + - BT_TRC_WARN driver errors that may happen due to external conditions + - BT_TRC_INFO Messages for errors returned to the user + - BT_TRC_CFG driver configuration and initialization + - BT_TRC_RD_WR generic read/write (outside of DMA & PIO) + - BT_TRC_MMAP memory mapping and related code/ + - BT_TRC_BIND bt_bind() and related code + - BT_TRC_CTRL All ioctl() functions + - BT_TRC_OPEN Driver open and close + - BT_TRC_ISR Interrupt Service Routine + - BT_TRC_IRQ_DISP Interrupt Request Processing/Dispatch + - BT_TRC_ICBR user ICBR and the vector returned by applicable kernel + interrupt handlers. + - BT_TRC_ISR_ERR ISR errors only + - BT_TRC_DMA DMA, each transfer + - BT_TRC_PIO PIO, each transfer + - BT_TRC_FUNC function entry and exit + - BT_TRC_ALLOC Allocation/release of resources + - BT_TRC_LOCK all locks (user & driver internal) + - BT_TRC_MAPREG details of each map register load + - BT_TRC_RAWIO Raw I/O register access + - BT_TRC_KLIB Misc. shared kernel routines + - BT_TRC_KDDI All 3rd party driver rouitnes KDDI + - BT_TRC_LIO Low level I/O register rd/wr + - BT_TRC_PROFILE enable H/W timing marks for profiling + - BT_TRC_DETAIL Detailed trace of enabled function + - BT_TRC_HW_DEBUG enable HW trace messages instead of console +*/ +int +CSBSBit3VmeInterface::GetTraceMask(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_devdata_t Result; + bt_error_t err = bt_get_info(*p, BT_INFO_TRACE, &Result); + CheckError(p, err, "CSBSBit3VmeInterface::GetTraceMask Failed"); + return Result; +} +/*! + + Does a sysreset on the VME bus. This can be done to return devices + on the VME bus to a known state. Note that this function has \em very + global effect and should be used with caution. + \param pHandle (void* [in]): Handle returned from CVMEInterface::Open. + +*/ +void +CSBSBit3VmeInterface::ResetVme(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + bt_error_t err = bt_reset(*p); + CheckError(p, err ,"CSBSBit3VmeInterface::ResetVme failed"); +} + +/*! + Check for errors on the Bit3 device. Errors must be reset with a call + to CheckErrors. + + \return bt_error_t + \retval BT_SUCCESS - no errors. + \retval BT_ESTATUS - There are status errors. + \retval BT_ENOPWR - VME crate is off. + \retval BT_EPWRCYC - Power just turned on. + \retval BT_IO - driver could not be queried. + +*/ +bt_error_t +CSBSBit3VmeInterface::CheckErrors(void* pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + return bt_chkerr(*p); +} +/*! + Reset errors on the interface. + \return bt_error_t + \retval BT_SUCCESS - success. + \retval BT_ESTATUS - Status errors persist. + \retval BT_ENOPWR - Power is still off. + \retval BT_IO - I/O failure. + */ +bt_error_t +CSBSBit3VmeInterface::ClearErrors(void*pHandle) +{ + bt_desc_t* p = (bt_desc_t*)pHandle; + return bt_clrerr(*p); +} Property changes on: trunk/nextgen/sbs/nsclapi/SBSBIT3API.cpp ___________________________________________________________________ Added: svn:executable + * Added: trunk/nextgen/sbs/nsclapi/SBSBit3API.h =================================================================== --- trunk/nextgen/sbs/nsclapi/SBSBit3API.h (rev 0) +++ trunk/nextgen/sbs/nsclapi/SBSBit3API.h 2008-10-07 14:29:59 UTC (rev 1998) @@ -0,0 +1,98 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2005. + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +/*! + Device specific extensions to CVMEInterface for SBS's driver for + the SBS/Bit3 PCI - VME bus bridge. Use of these functions will + make your software device specific!!!!!! + + Note as well that the + modifications you make will be global to all users of the same + device (address space), and will not be reset when you close/extit. + So if you change a VMEA32/D32 device into a shortio device you've changed + it for everyone!!!! +*/ + +#ifndef __SBSBIT3API_H +#define __SBSBIT3API_H + +#ifndef BT1003 +#define BT1003 +#endif + +extern "C" { + + +#ifndef __SBS_BTDEF_H +#include <btdef.h> +#define __SBS_BTDEF_H +#endif + +#ifndef __SBS_BTPDEF_H +#include <btpdef.h> +#define __SBS_BTPDEF_H +#endif + +#ifndef __SBS_BTNGPCI_H +#include <btngpci.h> +#define __SBS_BTNGPCI_H +#endif +} +class CSBSBit3VmeInterface { +public: + + // Set parameters... + + static void SetDMABlockTransfer(void* pHandle, bool enable); + static void SetDMAPauseMode(void* pHandle, bool enable); + static void SetMaxTransferWidth(void* pHandle, bt_width_t width); + static void SetDMAAddressModifier(void* pHandle, int Modifier); + static void SetMMAPAddressModifier(void* pHandle, int Modifier); + static void SetSwapMode(void* pHandle, bt_swap_t SwapMode); + static void SetDMAThreshold(void* pHandle, int nTransfers); + static void SetDMAPollCeiling(void* pHandle, int nTransfers); + static void SetTraceMask(void* pHandle, int nMask); + + // Get current value of parameters: + + // Readonly parameters first: + + static int GetLocalCardPartNumber(void* pHandle); + static int GetRemoteCardPartNumber(void* pHandle); + static unsigned int GetLocalMemorySize(void* pHandle); + + static bool IsDMABlockTransfer(void* pHandle); + static bool IsDMAPauseMode(void* pHandle); + static bt_width_t GetMaxTransferWidth(void* pHandle); + static int GetDMAAddressModifier(void* pHandle); + static int GetMMAPAddressModifier(void* pHandle); + static int GetSwapMode(void* pHandle); + static int GetDMAThreshold(void* pHandle); + static int GetDMAPollCeiling(void* pHandle); + static int GetTraceMask(void* pHandle); + + // Direct interfaces to the bt interface: + + static void ResetVme(void* pHandle); //!< Reset VME bus. + + // Get/clear error status: + + static bt_error_t CheckErrors(void* pHandle); + static bt_error_t ClearErrors(void* pHandle); +}; + + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |