/* --------------------------------------------------------------------------- * Functions mapping to VME using the CERN RCC library * * Author : J.B.Lane UCL October 2002 rcc.c * --------------------------------------------------------------------------- */ #include #include "rcc_error/rcc_error.h" #include "vme_rcc/vme_rcc.h" #include "ask.h" /* prototypes */ int handle; int ret; void signal_handler (int sig) { static VME_BusErrorInfo_t info; ret = VME_BusErrorInfoGet (&info); if (ret != 0) VME_ErrorPrint (ret); VME_ErrorPrint (VME_BUSERROR); printf ("\nBUS ERROR at address %08X, am = %02X, multiple = %x\n", info.vmebus_address, info.address_modifier, info.multiple); } unsigned short* vme_get_window (const int vme_size, const int vme_addr, const int mode) { VME_MasterMap_t master_map = {0x0, 0x1000, VME_A32, 0}; /* base size amod */ //VME_ErrorCode_t error_code; const int vme_mode[] = { VME_A32, VME_A24 }; static int open_device = 1; unsigned int value; /* UINT32 */ unsigned short* memory_ptr = NULL; if (open_device) { open_device = 0; ret = VME_Open (); if (ret != 0) printf ("VME_Open error %d\n", ret); VME_ErrorPrint (ret); } master_map.vmebus_address = vme_addr; master_map.window_size = vme_size; master_map.address_modifier = vme_mode[mode]; ret = VME_MasterMap (&master_map, &handle); VME_ErrorPrint (ret); ret = VME_MasterMapVirtualAddress (handle, &value); VME_ErrorPrint (ret); memory_ptr = (unsigned short*) value; if (signal(SIGBUS, signal_handler) == SIG_ERR) printf ("signal error\n"); ret = VME_BusErrorRegisterSignal (SIGBUS); VME_ErrorPrint (ret); if (ret != 0) printf ("VME window create error %d\n", ret); if (ret != 0) memory_ptr = NULL; else /* Try to recognize an MXI bus fault (eg VXIinit or VXIedit required)... * D32 read should give VME bus error and data 0xFFFFFFFF on a D16 module * but TIM now responses to D32 */ { printf ("Checking VME access\n"); VME_ReadFastUInt (handle, 0, &value); if ((value & 0xFF000000) != 0xFF000000) { printf ( "\nERROR: address %p value %x D32 read expected data FFxxxxxx\n", memory_ptr, value); printf ("Try running Resman\n\n"); } } printf (" mapped address = %p\n", memory_ptr); return memory_ptr; } void vme_end (void) { ret = VME_BusErrorRegisterSignal (0); VME_ErrorPrint (ret); ret = VME_MasterUnmap (handle); VME_ErrorPrint (ret); ret = VME_Close (); VME_ErrorPrint (ret); printf ("RCC done.\n"); }