/****************************************************************************** * * Title : rodInit.c * Version 0.0 * * Description: rod initialization routine. * Related files: * * Changes: March 7, 2002 - stop/resume CommunicationLoop added. * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "errorHandler.h" #include "vmeHpiUtility.h" #include "rodInit.h" #include "hostUtility.h" #include "comRegDfns.h" #include "threadUtility.h" #include "globalDefinitions.h" #include "uirUtility.h" #include "mainUir.h" #include "vmeAddressMap.h" #include "commandListExecution.h" #define I_AM_MASTER_DSP #undef IDREGS_BASE #include "memoryPartitions.h" //dspf: MDSP_PRM_BFR_SZ, MDSP_REP_BFR_SZ => use memory map. #undef I_AM_MASTER_DSP /****************************************************************************** * Definitions * ******************************************************************************/ /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * rodInit() *============================================================================= * * * */ ERROR_ID rodInit(struct HOST *host){ unsigned int i; char errorMessage[200]; ERROR_ID errorId=SUCCESS; UINT32 statRegValue; UINT32 hpic; UINT32 hpicVmeAddr=BASE_ADDRESS(host->slotNumber)+HPIC_REL_ADDR; int status; UINT32 data; void *buffer; unsigned int value; char string[300]; /* reset board */ /* value=0; SET_BIT(value, 6); errorId=vmeWriteElement(value, BASE_ADDRESS(host->slotNumber)+FPGA_CONTROL_2_REL_ADDR, sizeof(UINT32)); ERROR_CHECK(errorId, vmeWriteElement()); */ Sleep(1000); host->rodStatusReg[0]=0; /* clear local copies of registers */ host->rodStatusReg[1]=0; /* HPI INITIALIZATION - little endian */ errorId=setHpicMaster(host->slotNumber); ERROR_CHECK(errorId, setHpic()); if(errorId!=SUCCESS) { host->option.rodEnabled=FALSE; SetCtrlVal(host->panel.parent, ROD_HOST_RUNNING, 0); return(errorId); } // get ROD serial number errorId=vmeReadElement(BASE_ADDRESS(host->slotNumber)+FPGA_STATUS_6_REL_ADDR, &value, sizeof(UINT32)); HOST_ERROR_CHECK(errorId, host, vmeReadBlock(ROD serial number)); SetCtrlVal(host->panel.parent, ROD_ROD_SN, value&0x1FF); SetCtrlVal(host->panel.parent, ROD_ROD_REV, (value&0xFF0000)/0x10000); SetCtrlVal(host->panel.parent, ROD_MEMORY, (value&0x200)/0x200); /* 10th bit */ errorId=refreshFpgaStatus(host); HOST_ERROR_CHECK(errorId, host, refreshFpgaStatus()); /* wait for MasterDSP init bit (RodStatusReg0) */ for(i=0; ; ++i) { /* read RodStatusReg0and1 and save to local variables */ errorId=readRodStatusRegs(host->slotNumber, host->rodStatusReg); if(errorId!=SUCCESS){ hostError(__FILE__,__LINE__, VME_ERROR, host, "readRodStatusRegs(rodStatusReg)"); return(errorId); } if(READ_BIT(host->rodStatusReg[0], SR_RUNNING)) { break; } if(i>((int)(global.rodInitTimeout*10))){ /* timeout error */ host->option.rodEnabled=FALSE; SetCtrlVal(host->panel.parent, ROD_HOST_RUNNING, 0); sprintf(errorMessage, "ERROR - ROD slot#%d NOT initialized!\n", host->slotNumber); errorId=FATAL_ERROR; hostError(__FILE__, __LINE__, errorId, host, errorMessage); return(errorId); } Sleep(50); } /* read text buffs info struct addresses from REP_BUFF and store into local variables */ errorId=RWmaster(READ, host->slotNumber, REP_BUFF_BASE, host->txtBuffStructHpiAddr, N_TXT_BUFFS, HPIA_AUTOINCREMENT, 0); ERROR_CHECK(errorId, RWmaster()); if(errorId!=SUCCESS) return(errorId); host->rodInitialized=TRUE; //execute init command list (e.g. load slave code etc.) strcpy(string, global.mainDir); strcat(string, "Rcc\\DefaultLists\\rodInit.cl"); errorId=executeCommandListFile(host->slotNumber, string, 0, IF_ERROR_DEFAULT); HOST_ERROR_CHECK(errorId, host, executePrimListFile()); return(errorId); } /******************************************************************************/