/************************************************************************************ * initialize.c: initialization routines. * * Damon Fasching, UW Madison fasching@wisconsin.cern.ch * Douglas Ferguson, UW Madison (510) 486-5230 dpferguson@lbl.gov ************************************************************************************/ #include "resources.h" #if defined(I_AM_MASTER_DSP) #include "rodConfiguration.h" #endif extern TIMER_Handle timer1; /* general purpose timer, started in main() */ #pragma CODE_SECTION(initialize, "xcode"); #pragma CODE_SECTION(checkDspStructSize, "xcode"); INT32 checkDspStructSize(void); /************************************************************************************ * initialize * * synopsis: Master initialization routine; executed once on startup. * author: Damon Fasching * * modifications/bugs * - Commented out initRrif & removed code from project-- no longer * needed (the RRIF is initialized correctly now, in hardware) 20.03.02 dpsf * - Removed MEM_TEST_MODE #ifdefs (no longer used). 03.06.02 dpsf * - Added initialization of the task manager, and the histogram * control structure for slave DSPs. 08.06.02 dpsf * - removed slvAppInit; the slave application routines have been * replaced by the task manager. 10.06.02 dpsf * - Replaced addError sections with macros 01.07.04 dpsf ************************************************************************************/ INT32 initialize(void) { INT32 status, returnCode= SUCCESS; #if defined(I_AM_MASTER_DSP) UINT32 slvIdx; #endif status= checkMemBound(); addErrFatalM(&returnCode, status, "initialize", "checkMemBound"); status= checkDspStructSize(); addErrFatalM(&returnCode, status, "initialize", "checkDspStructSize"); initCommRegs(); initPrimListStructs(); initPrimParams(); initSendTxtBuffSM(); status= initTaskManager(); addErrFatalM(&returnCode, status, "initialize", "initTaskManager"); initSerialPorts(); /************************************************************************************/ #if defined(I_AM_MASTER_DSP) status= initRegisterArray(); addErrFatalM(&returnCode, status, "initialize", "initRegisterArray"); for (slvIdx = 0; slvIdx < N_SDSP; ++slvIdx) { initGetSlvTxtBuffSM(slvIdx); initHostListToSlaveSM(slvIdx); } initCmdBuffer(SP_BOTH); //Give ROD controller FPGA ~1 sec to set the ROD busy signal (SP1 DRSTAT) #ifndef SIM delay(20000000); #endif /* Wait for the ROD controller to signal that it is done with its own initialization */ status= waitRodBusy(); addErrFatalM(&returnCode, status, "initialize", "waitRodBusy"); /* The frequently used SDSP communication register routines are initialized by calling the initSlvRegAddr routine: */ initSdspRegAddr(); initRodConfig(); #elif defined(I_AM_SLAVE_DSP) status= initHistos(); addErrFatalM(&returnCode, status, "initialize", "initHistos"); initRodConfig(); initExtPinGpio(); status= initEvtMgrStructs(); addErrFatalM(&returnCode, status, "initialize", "initEvtMgrStructs"); #endif return returnCode; } /************************************************************************************ * checkDspStructSize * synopsis: Checks to make sure all major DSP structures conform to word * boundaries; this ensures that they can be re-initialized by the * setMem routine if needed. ************************************************************************************/ INT32 checkDspStructSize(void) { INT32 returnCode= SUCCESS; UINT32 sCheck= 0; sCheck|= ((sizeof(TaskMgrCtrl) & 3) != 0)<<1; sCheck|= ((sizeof(TaskInput) & 3) != 0)<<2; sCheck|= ((sizeof(TaskData) & 3) != 0)<<3; sCheck|= ((sizeof(TaskOutput) & 3) != 0)<<4; #if defined(I_AM_MASTER_DSP) #elif defined(I_AM_SLAVE_DSP) sCheck|= ((sizeof(HistoCtrl) & 3) != 0)<<5; sCheck|= ((sizeof(BinCtr) & 3) != 0)<<6; sCheck|= ((sizeof(struct EvtMgrCtrl) & 3) != 0)<<7; sCheck|= ((sizeof(struct EventData) & 3) != 0)<<8; sCheck|= ((sizeof(struct EventQueue) & 3) != 0)<<9; #endif if (sCheck) { newErrM(NON_WORD_BOUNDARY, FATAL_ERR, "checkDspStructSize", "A DSP structure does not conform to word boundary.\n"); } return returnCode; }