#ifndef SPINCORE_PULSEBLASTER_H #define SPINCORE_PULSEBLASTER_H #include #include #include #include #include #include #include #include #ifndef SP_DEBUG # define SP_DEBUG 1 #endif class SpinCorePulseBlaster_error: public pulse_exception { public: explicit SpinCorePulseBlaster_error(const std::string& msg) throw (): pulse_exception(msg) {} explicit SpinCorePulseBlaster_error(const char* msg) throw (): pulse_exception(msg) {} virtual ~SpinCorePulseBlaster_error() throw () {} protected: virtual const std::string prefix() const { return "ERROR (SpinCorePulseBlaster_error): "; } }; #if !( defined(__linux__)||defined(__CYGWIN__)) # error "Sorry, we are not prepared for this target!" #endif #ifdef __linux__ # include # include # include # include # include # include "pulseblaster.h" #endif #ifdef __CYGWIN__ # include #endif class SpinCorePulseBlasterLowlevel { protected: # ifdef __linux__ /** device file handle */ int device_file_descriptor; # endif # ifdef __CYGWIN__ /** the loaded dll */ HINSTANCE PBP_DLL; /** the pulseblaster communication function sp_outp \param address address register in board's internal memory \param value value to store */ __attribute__((stdcall)) int (*sp_outp)(unsigned short address, int value); /** the pulseblaster communication function sp_inp \param address addres register in board's internal memory */ __attribute__((stdcall)) int (*sp_inp)(unsigned short address); /** initialisation of the Pulseblaster board */ __attribute__((stdcall)) int (*sp_Init)(); /** close access to Pulseblaster board */ __attribute__((stdcall)) int (*sp_Close)(); #endif SpinCorePulseBlasterLowlevel(); #ifdef __linux__ inline int write_register(int reg, int data) { int result=ioctl(device_file_descriptor,IOCTL_OUTB,(reg&0xff)<<8|(data&0xff)); if (result==-1) throw SpinCorePulseBlaster_error(std::string("write_register: ioctl error \"")+strerror(errno)+"\""); if (result!=0) { char errorno[256]; snprintf(errorno, 256, "%d",result); throw SpinCorePulseBlaster_error(std::string("write_register: ioctl returned nonzero value = ")+errorno); } return result; } /** writes data to pulseblaster device care about buffer length and write in chunks to avoid freeze of user space */ int write_data(const unsigned char* data, size_t size); inline int read_register(int reg) { int result=ioctl(device_file_descriptor,IOCTL_INB, reg&0xff); if (result==-1) throw SpinCorePulseBlaster_error(std::string("write_register: ioctl error \"")+strerror(errno)+"\""); if (result<0) throw SpinCorePulseBlaster_error("read_register: ioctl returned nonzero value"); return result; } #endif #ifdef __CYGWIN__ inline int write_register(unsigned int reg, unsigned int data) { int result=sp_outp(reg,data); #if SP_DEBUG fprintf(stderr, "sp_outp(0x%02x,0x%02x)\n",reg,data); #endif if (result!=0) throw SpinCorePulseBlaster_error("write_register returned nonzero value"); return result; } inline int write_data(const unsigned char* data, size_t size) { int result=0; size_t i; for (i=0; i