#include "v1495.h" /* In the functions below base address is the VME base address of the board */ /* not the local address. The driver takes care of determining the address */ /* for the VME controller */ /* A function to return the geographical address of the board */ epicsInt8 v1495_get_geo_address( char* baseAddr, epicsUInt16* val ) { V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { *val = vmeRead16( &(v1495_regs->geo_addr) ); return v1495_OK; } return v1495_ERROR; } /* A function to return the firmware version of the board */ epicsInt8 v1495_get_fw_revision( char* baseAddr, epicsUInt16* val ) { V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { *val = vmeRead16( &(v1495_regs->fw_revision) ); // printf("Getting Firmware from 0x%x, got 0x%x \n", &(v1495_regs->fw_revision), *val ); return v1495_OK; } return v1495_ERROR; } /* A function to return the scratch16 register on the board */ epicsInt8 v1495_get_scratch16( char* baseAddr, epicsUInt16* val ) { V1495_REGS* v1495_regs; // printf("In v1495_get_scratch16 \n"); if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { *val = vmeRead16( &(v1495_regs->scratch_16) ); // printf("Getting Scratch16 from 0x%x, got 0x%x \n", &(v1495_regs->scratch_16), *val ); return v1495_OK; } return v1495_ERROR; } /* A function to return the scratch32 register on the board */ epicsInt8 v1495_get_scratch32( char* baseAddr, epicsUInt32* val ) { V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { *val = vmeRead32( &(v1495_regs->scratch_32) ); return v1495_OK; } return v1495_ERROR; } /* A function to reset the board */ epicsInt8 v1495_reset_module( char* baseAddr ) { V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { vmeWrite16( &(v1495_regs->module_reset), 1 ); return v1495_OK; } return v1495_ERROR; } /* A function to set scratch16 register */ epicsInt8 v1495_set_scratch16 ( char* baseAddr, epicsUInt16 val ){ V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { vmeWrite16( &(v1495_regs->scratch_16), val ); printf("Wrote Scratch16 to 0x%x value of 0x%x \n", (unsigned)&(v1495_regs->scratch_16), val ); return v1495_OK; } return v1495_ERROR; } /* A function to set scratch32 register */ epicsInt8 v1495_set_scratch32 ( char* baseAddr, epicsUInt32 val ) { V1495_REGS* v1495_regs; if( v1495_get_regs( baseAddr, &v1495_regs ) == v1495_OK ) { vmeWrite32( &(v1495_regs->scratch_32), val ); printf("Wrote Scratch32 to 0x%x value of 0x%x \n", (unsigned)&(v1495_regs->scratch_16), val ); epicsUInt32 tmpVal = vmeRead32( &(v1495_regs->scratch_32) ); printf( "Checking by reading back scratch32: read back 0x%x from 0x%x \n", tmpVal, (unsigned)&(v1495_regs->scratch_16) ); return v1495_OK; } return v1495_ERROR; } /* Return the address for V1495 registers */ epicsInt8 v1495_get_regs( char* baseAddr, V1495_REGS** regs ) { char* localAddr; #if defined VXWORKS // printf("Will use VxWorks address mapping functions \n"); if( devBusToLocalAddr( V1495_ADDRESS_TYPE, baseAddr, &localAddr ) == S_dev_success ) { #elif defined Linux_vme // printf("Will use Linux address mapping functions \n"); if( vmeBusToLocalAdrs( V1495_ADDRESS_TYPE, baseAddr, &localAddr ) == OK ) { #else if( sysBusToLocalAdrs( V1495_ADDRESS_TYPE, baseAddr, &localAddr ) == OK ) { #endif // printf( "The local address for base address 0x%x is 0x%x \n", baseAddr, localAddr ); /* Get the address of the board registers */ // printf( "Local address is 0x%x\n", localAddr ); *regs = (V1495_REGS*)localAddr; return v1495_OK; } else { printf( "Cannot get local address for base address 0x%x\n", (unsigned)baseAddr ); return v1495_ERROR; } } /* Below are the definitions of the functions for register IO for CAEN V1495 board */ #define EIEIO __asm__ volatile ("eieio") #define SYNC __asm__ volatile ("sync") /* read 16-bit register of a CAEN V1495 board */ epicsUInt16 v1495_read_reg16( volatile unsigned int* addr ) { unsigned int rval; #ifdef VXWORKS EIEIO; SYNC; #endif rval = *addr; #ifndef VXWORKS rval = SSWAP(rval); #endif return rval; } /* write to 16-bit register of a CAEN V1495 board */ void v1495_write_reg16( volatile unsigned int* addr, epicsUInt16 val ) { #ifdef VXWORKS EIEIO; SYNC; #endif #ifndef VXWORKS val = SSWAP(val); #endif *addr = val; return; } /* read 32-bit register of a CAEN V1495 board */ epicsUInt32 v1495_read_reg32( volatile unsigned int* addr ) { unsigned int rval; #ifdef VXWORKS EIEIO; SYNC; #endif rval = *addr; #ifndef VXWORKS rval = LSWAP(rval); #endif return rval; } /* write to 32-bit register of a CAEN V1495 board */ void v1495_write_reg32( volatile unsigned int* addr, epicsUInt32 val ) { #ifdef VXWORKS EIEIO; SYNC; #endif #ifndef VXWORKS val = LSWAP(val); #endif *addr = val; return; }