/* * ===================================================================== * hit buffer vme functions author F.Spinella 6-7-1996 * 22 April 1999: modify for Hit Buffer V2.0 by S.Belforte * added calls for DipSwitches, FreezeVME, CDF_Error * 13 Nov 1999: Empty Flag for Fifo Reads is bit 31 ! S.B. * 14 Nov 1999: better aaling and fix bug in reading Fifo. S.B. * ===================================================================== */ /* global var */ /* include files */ #include "hit_buffer_def.h" #include "hit_buffer_tools.h" /* * functions returns: vmeAccess functions use return errors code as defined * in unix standard file errno.h, which defines error codes from 1 to 90. 0 * signify success. we use the following rules: 1) 0 : generic * success 2) -1 to -90 : return errors as defined in vmeAccess routines with * inverted sign 3) -100 to -infinity : internal errors of this routines * * Positive numbers returned signify success & number returned has something * related to the function, for example in reading fifos it could be the * number of words read before receiving fifo empty bit */ /* * ======================================================== * --------------------- functions declarations ----------- * ======================================================== */ int HIT_BUFFER_DEFINE(VISION_SLAVE * hit_buffer, int slot, char *crate_name); int HIT_BUFFER_DEFINE_N(VISION_SLAVE * hit_buffer, int slot,char *crate_name); int HIT_BUFFER_CLOSE(VISION_SLAVE hit_buffer); int hit_buffer_ErrorFlagStatus(VISION_SLAVE hit_buffer, unsigned long *ErrorFlag); int hit_buffer_ErrorFlagReset(VISION_SLAVE hit_buffer); int hit_buffer_Init(VISION_SLAVE hit_buffer); int hit_buffer_TmodeEnable(VISION_SLAVE hit_buffer); int hit_buffer_TmodeStatus(VISION_SLAVE hit_buffer, unsigned long *Tmode); int hit_buffer_HitFifoStatus(VISION_SLAVE hit_buffer, unsigned long *hitFifo); int hit_buffer_RoadFifoStatus(VISION_SLAVE hit_buffer, unsigned long *roadFifo); int hit_buffer_OutputHoldStatus(VISION_SLAVE hit_buffer, unsigned long *Hold); int hit_buffer_FSMStatus(VISION_SLAVE hit_buffer, unsigned long *FSM); int hit_buffer_FSMHStatus(VISION_SLAVE hit_buffer, unsigned long *FSMH); int hit_buffer_FSMRStatus(VISION_SLAVE hit_buffer, unsigned long *FSMR); int hit_buffer_OutputRegisterRead(VISION_SLAVE hit_buffer, unsigned long *outreg); int hit_buffer_OutputRegisterWriteNoHoldSens(VISION_SLAVE hit_buffer, unsigned long *outreg); int hit_buffer_OutputRegisterWriteHOldSens(VISION_SLAVE hit_buffer, unsigned long *outreg); int hit_buffer_OutputSend(VISION_SLAVE hit_buffer, unsigned long *Output, int num_word); int hit_buffer_OutputSendFile(VISION_SLAVE hit_buffer, char *OutFile); int hit_buffer_HitSpyRegisterStatus(VISION_SLAVE hit_buffer, unsigned long *HitSpyregister); int hit_buffer_HitSpyPointerStatus(VISION_SLAVE hit_buffer, unsigned long *HitSpypointer); int hit_buffer_HitSpyOverflowStatus(VISION_SLAVE hit_buffer, unsigned long *HitSpyoverflow); int hit_buffer_HitSpyStatus(VISION_SLAVE hit_buffer, unsigned long *HitSpystatus); int hit_buffer_HitSpyRegisterReset(VISION_SLAVE hit_buffer); int hit_buffer_RoadSpyRegisterStatus(VISION_SLAVE hit_buffer, unsigned long *RoadSpyregister); int hit_buffer_RoadSpyPointerStatus(VISION_SLAVE hit_buffer, unsigned long *RoadSpypointer); int hit_buffer_RoadSpyOverflowStatus(VISION_SLAVE hit_buffer, unsigned long *RoadSpyoverflow); int hit_buffer_RoadSpyStatus(VISION_SLAVE hit_buffer, unsigned long *RoadSpystatus); int hit_buffer_RoadSpyRegisterReset(VISION_SLAVE hit_buffer); int hit_buffer_OutSpyRegisterStatus(VISION_SLAVE hit_buffer, unsigned long *OutSpyregister); int hit_buffer_OutSpyPointerStatus(VISION_SLAVE hit_buffer, unsigned long *OutSpypointer); int hit_buffer_OutSpyOverflowStatus(VISION_SLAVE hit_buffer, unsigned long *OutSpyoverflow); int hit_buffer_OutSpyStatus(VISION_SLAVE hit_buffer, unsigned long *OutSpystatus); int hit_buffer_OutSpyRegisterReset(VISION_SLAVE hit_buffer); int hit_buffer_ErrorEnableStatus(VISION_SLAVE hit_buffer, unsigned long *ErrorEnable); int hit_buffer_FreezeVMEStatus(VISION_SLAVE hit_buffer, unsigned long *FreezeVME); int hit_buffer_FreezeVMESet(VISION_SLAVE hit_buffer, unsigned long *FreezeVME); int hit_buffer_CdfErrEnStatus(VISION_SLAVE hit_buffer, unsigned long *CdfErrorEnable); int hit_buffer_CdfErrEnSet(VISION_SLAVE hit_buffer, unsigned long *CdfErrorEnable); int hit_buffer_CdfErrorStatus(VISION_SLAVE hit_buffer, unsigned long *CdfError); int hit_buffer_DipSwitchStatus(VISION_SLAVE hit_buffer, unsigned long *DipSwitch); int hit_buffer_ErrorEnableSet(VISION_SLAVE hit_buffer, unsigned long *ErrorEnable); int hit_buffer_IdPromRead(VISION_SLAVE hit_buffer, unsigned long *idPROM, int num_word, unsigned long offset); int hit_buffer_HitFifoRead(VISION_SLAVE hit_buffer, unsigned long *HitFifo, int num_word); int hit_buffer_RoadFifoRead(VISION_SLAVE hit_buffer, unsigned long *RoadFifo, int num_word); int hit_buffer_HitSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *HitSpyBuffer, int num_word); int hit_buffer_HitSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *HitSpyBuffer, int num_word, unsigned long offset); int hit_buffer_RoadSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *RoadSpyBuffer, int num_word); int hit_buffer_RoadSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *RoadSpyBuffer, int num_word, unsigned long offset); int hit_buffer_OutputSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *OutSpyBuffer, int num_word); int hit_buffer_OutputSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *OutSpyBuffer, int num_word, unsigned long offset); int hit_buffer_SSmapWrite(VISION_SLAVE hit_buffer, unsigned long *SSMap, unsigned long num_word, unsigned long offset); int hit_buffer_AMmapWrite(VISION_SLAVE hit_buffer, unsigned long *AMMap, unsigned long num_word, unsigned long offset); int hit_buffer_SSmapCheck(VISION_SLAVE hit_buffer, unsigned long *SSMap, unsigned long num_word, unsigned long offset); int hit_buffer_AMmapCheck(VISION_SLAVE hit_buffer, unsigned long *AMMap, unsigned long num_word, unsigned long offset); int hit_buffer_SSmapRead(VISION_SLAVE hit_buffer, unsigned long *SSMap, unsigned long num_word, unsigned long offset); int hit_buffer_AMmapRead(VISION_SLAVE hit_buffer, unsigned long *AMMap, unsigned long num_word, unsigned long offset); int hit_buffer_CheckRegistersStatus(VISION_SLAVE hit_buffer, unsigned long *regs_values); int hit_buffer_LoadMaps(VISION_SLAVE hit_buffer, char *SSfile, char *AMfile); int hit_buffer_HitSpyBufferCheck(VISION_SLAVE hit_buffer, char *HitFile); int hit_buffer_RoadSpyBufferCheck(VISION_SLAVE hit_buffer, char *RoadFile); int hit_buffer_OutSpyBufferCheck(VISION_SLAVE hit_buffer, char *OutFile); int hit_buffer_HitFifoCheck(VISION_SLAVE hit_buffer, char *HitFile); int hit_buffer_RoadFifoCheck(VISION_SLAVE hit_buffer, char *RoadFile); int hit_buffer_MapsCheck(VISION_SLAVE hit_buffer, char *SSfile, char *AMfile); int hit_buffer_Random_write(VISION_SLAVE hit_buffer, unsigned long *SSMap, int num_word, unsigned long offset); int hit_buffer_Random_read(VISION_SLAVE hit_buffer, unsigned long *SSMap, int num_word, unsigned long offset); /* * ======================================================== * --------------------- functions body ------- ----------- * ======================================================== */ /* * =========================================================================== * ================= */ int HIT_BUFFER_DEFINE(VISION_SLAVE * hit_buffer, int slot, char *crate_name) { HIT_BUFFER_DEFINE_N(hit_buffer, slot, crate_name); } /* char name[32]; int threshold; int FIFO_value; sprintf(name, "geo32:/slot=%d", slot); status = VISIONopen(hit_buffer, name, net_name); if (status != 0) { printf("error opening hit buffer in slot %d !!!\n", slot); return (-status); } status = VISIONconfig(*hit_buffer, "transferProtocol", (void *) "auto", strlen("auto")); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } FIFO_value = 0; status = VISIONconfig(*hit_buffer, "FIFO", &FIFO_value, sizeof(FIFO_value)); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } threshold = HIT_BUFFER_THRESHOLD; status = VISIONconfig(*hit_buffer, "autoThreshold", &threshold, sizeof(int)); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } return status; } */ /* * =========================================================================== * ================= */ int HIT_BUFFER_DEFINE_N(VISION_SLAVE * hit_buffer, int slot,char *crate_name) { /* * hit buffers transfers: transfers of 4 or less bytes are in single * word (as reg reading/writing) others are all in block transfer */ char name[32]; int threshold; int FIFO_value; sprintf(name, "geo32:/slot=%d", slot); status = VISIONopen(hit_buffer, name,crate_name); if (status != 0) { printf("error opening hit buffer in slot %d crate %s ! \n", slot, crate_name); return (-status); } status = VISIONconfig(*hit_buffer, "transferProtocol", (void *) "auto", strlen("auto")); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } FIFO_value = 0; status = VISIONconfig(*hit_buffer, "FIFO", &FIFO_value, sizeof(FIFO_value)); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } threshold = HIT_BUFFER_THRESHOLD; status = VISIONconfig(*hit_buffer, "autoThreshold", &threshold, sizeof(int)); if (status != 0) { printf("error configuring hit_buffer in slot %d !!!\n", slot); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int HIT_BUFFER_CLOSE(VISION_SLAVE hit_buffer) { status = VISIONinfo(hit_buffer, "name", (void *) info, 20); status = VISIONclose(hit_buffer); if (status != 0) { printf("error %d closing hit_buffer opened as %s ! \n", status, info); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_ErrorFlagStatus(VISION_SLAVE hit_buffer, unsigned long *ErrorFlag) { status = VISIONread(hit_buffer, (unsigned long) hb_error_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) ErrorFlag); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer error register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_ErrorFlagReset(VISION_SLAVE hit_buffer) { status = VISIONwrite(hit_buffer, (unsigned long) hb_error_reg, sizeof(write_word), &real_bytes, &write_word); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer error register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_Init(VISION_SLAVE hit_buffer) { status = VISIONwrite(hit_buffer, (unsigned long) hb_init_reg, sizeof(write_word), &real_bytes, &write_word); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer init register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_TmodeEnable(VISION_SLAVE hit_buffer) { status = VISIONwrite(hit_buffer, (unsigned long) hb_tmod_reg, sizeof(write_word), &real_bytes, &write_word); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer TMODE register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_TmodeStatus(VISION_SLAVE hit_buffer, unsigned long *Tmode) { status = VISIONread(hit_buffer, (unsigned long) hb_tmod_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) Tmode); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer TMODE register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_HitFifoStatus(VISION_SLAVE hit_buffer, unsigned long *hitFifo) { status = VISIONread(hit_buffer, (unsigned long) hb_hit_fifo_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) hitFifo); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer hitFIFO register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_RoadFifoStatus(VISION_SLAVE hit_buffer, unsigned long *roadFifo) { status = VISIONread(hit_buffer, (unsigned long) hb_road_fifo_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) roadFifo); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer roadFIFO register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_OutputHoldStatus(VISION_SLAVE hit_buffer, unsigned long *Hold) { status = VISIONread(hit_buffer, (unsigned long) hb_hold_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) Hold); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer output state register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_FSMStatus(VISION_SLAVE hit_buffer, unsigned long *FSM) { status = VISIONread(hit_buffer, (unsigned long) hb_fsm_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) FSM); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer FSM register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_FSMHStatus(VISION_SLAVE hit_buffer, unsigned long *FSMH) { status = VISIONread(hit_buffer, (unsigned long) hb_fsmh_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) FSMH); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer FSMH register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_FSMRStatus(VISION_SLAVE hit_buffer, unsigned long *FSMR) { status = VISIONread(hit_buffer, (unsigned long) hb_fsmr_reg, (unsigned int) sizeof(unsigned long), &real_bytes, (void *) FSMR); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer FSMR register, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_OutputRegisterWriteNoHoldSens(VISION_SLAVE hit_buffer, unsigned long *outreg) { int result; status = VISIONwrite(hit_buffer, (unsigned long) hb_output_reg, sizeof(*outreg), &real_bytes, outreg); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer output register, opened as %s \n", info); printf("status = %d\n", status); result=(-status); } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_OutputSend(VISION_SLAVE hit_buffer, unsigned long *Output, int num_words) { int i, result; int FIFO_mode; unsigned long *DataBuffPtr; VISIONinfo(hit_buffer, "name", (void *) info, 20); if (num_words > 0) { status = VISIONconfig(hit_buffer, "transferType", (void *) "pio", strlen("pio")); if (status != 0) { printf("error configuring transferType pio for hit_buf opened as %s \n", info); printf("status = %d\n", status); return (-status); } status = VISIONconfig(hit_buffer, "transferProtocol", (void *) "single", strlen("single")); if (status != 0) { printf("error configuring transferProtocol single for hit_buf opened as %s \n", info); printf("status = %d\n", status); return (-status); } FIFO_mode = 1; status = VISIONconfig(hit_buffer, "FIFO", &FIFO_mode, sizeof(FIFO_mode)); if (status != 0) { printf("error configuring FIFO mode 1 for hit_buff opened as %s\n", info); printf("status = %d\n", status); return (-status); } status = VISIONwrite (hit_buffer, (unsigned long) hb_output_reg, sizeof (unsigned long) * num_words, &real_bytes, Output); if (status != 0) { printf("error writing %d dec word in out from hit_buff opened as %s!\n", num_words, info); printf("status = %d\n", status); return (-status); } result = num_words; FIFO_mode = 0; status = VISIONconfig(hit_buffer, "FIFO", &FIFO_mode, sizeof(FIFO_mode)); if (status != 0) { printf("error configuring FIFO mode 0 for hit_buff opened as %s!\n", info); printf("status = %d\n", status); return (-status); } status = VISIONconfig(hit_buffer, "transferType", (void *) "best", strlen("auto")); if (status != 0) { printf("error configuring transferType best for hit_buf opened as %s \n", info); printf("status = %d\n", status); return (-status); } status = VISIONconfig(hit_buffer, "transferProtocol", (void *) "auto", strlen("auto")); if (status != 0) { printf("error configuring transferProtocol auto for hit_buf opened as %s \n", info); printf("status = %d\n", status); return (-status); } } else { printf("Request for sending negative num_words from hit buffer opened as %s \n", info); result= GENERIC_VMESVT_ERROR; } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_OutputSendFile(VISION_SLAVE hit_buffer, char *OutFile) { int i, result; int out_words; int FIFO_mode; unsigned long *DataBuffPtr; VISIONinfo(hit_buffer, "name", (void *) info, 20); out_words = load_file_hex(OutFile, &DataBuffPtr); if (out_words > 0) { /* for (i=0;i (hb_id_prom_end+1)) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("too many words required reading IDprom in hit_buffer opened as %s \n", info); return PARAM_ERROR; } status = VISIONread(hit_buffer, (unsigned long) hb_id_prom + 4*offset, (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) idPROM); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer IDprom, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* * =========================================================================== * ================= */ int hit_buffer_HitFifoRead(VISION_SLAVE hit_buffer, unsigned long *HitFifo, int num_word) { /* * assume hit buffer FIFOs work as merger FIFO: when we are reading * the last word in FIFO, bit 31 is set to 0, so to distinguish case * of only one word in FIFO fro case with FIFO empty, we have to look * first to the Hit-FIFO status */ /* * just to minimize time, FIFO is read in packets of words. This * interactive use is not allowed in verilog simulation, so num_word * input is always converted from NULL to all if global var vmetype * is equal to "verilog" * * * if num_word = NULL this function try to read all data in FIFO, with * the following rules : * * 1) reads reg0 and checks if FIFO is empty => exit 2) if not empty * reads MERGER_PACKET_DIM words for each transfer, if the last * word has the empty bit low reads in decreasing order all words * until the last is found All fake words are fulfilled with zeros. * if the last word doesn't have the empty bit low, reads * MERGER_PACKET_DIM more words * * Function returns the number of read words before receiving fifo empty * flag or error code. */ extern char vmetype[15]; unsigned long fifo_status; unsigned long data0; unsigned long data1; int packet; int result; int stop; int j = 0; int ReadWords; stop = 0; packet = 0; ReadWords = 0; if ((!strcmp(vmetype, "verilog")) && (num_word == NULL)) { num_word = HIT_BUFFER_FIFODEPTH; printf("Improper use of hit_buffer_HitFifoRead in verilog \n"); printf("Converting NULL to HIT_BUFFER_FIFODEPTH \n"); } if (num_word == NULL) { hit_buffer_HitFifoStatus(hit_buffer, &fifo_status); if (fifo_status & HIT_BUFFER_FIFO_NOEMPTY) { do { status = VISIONread(hit_buffer, (unsigned long)(hb_hit_fifo + (packet * HIT_BUFFER_PACKET_DIM)), (unsigned int)(sizeof(unsigned long) * HIT_BUFFER_PACKET_DIM), &real_bytes, (void *)(HitFifo + (packet * HIT_BUFFER_PACKET_DIM))); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer HIT_FIFO, opened as %s \n", info); printf("status = %d\n", status); return (-status); } if (!(HitFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM)] & (1 << 31))) { /* * last word in packet has fifo bit low */ stop = 1; do { data0 = HitFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j]; data1 = HitFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j - 1]; if (((!(data0 & (1<<31))) && (!(data1 & (1<<31)))) && (j != HIT_BUFFER_PACKET_DIM - 1)) { HitFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j] = 0; } j++; } while (((!(data0 & (1<<31))) && (!(data1 & (1<<31)))) && (j != HIT_BUFFER_PACKET_DIM)); } packet++; } while ((stop != 1) && (packet <= ((HIT_BUFFER_FIFODEPTH / HIT_BUFFER_PACKET_DIM)))); if(stop==0) ReadWords= packet * HIT_BUFFER_PACKET_DIM; else ReadWords=(packet * HIT_BUFFER_PACKET_DIM) -j + 1; return ReadWords; } else { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Hit Buffer Hit FIFO empty !!!, opened as %s \n", info); return FIFO_EMPTY; } } /* * if num_word != NULL, tries to read num_word words from the FIFO, * without doing any check */ else if ((num_word != NULL) && (num_word > 0) && (num_word <= HIT_BUFFER_FIFODEPTH)) { status = VISIONread(hit_buffer, (unsigned long) hb_hit_fifo, (unsigned int)num_word*sizeof(unsigned long), &real_bytes, (void *)HitFifo); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading Hit Buffer Hit FIFO, opened as %s\n", info); return (-status); } return (real_bytes / sizeof(unsigned long)); } else { printf("Error defining Hit Buffer Hit FIFO reading parameters, opened as %s \n",info); return PARAM_ERROR; } } /* * =========================================================================== * ================= */ int hit_buffer_RoadFifoRead(VISION_SLAVE hit_buffer, unsigned long *RoadFifo, int num_word) { /* * assume hit buffer FIFOs work as merger FIFO: when we are reading * the last word in FIFO, bit 31 is set to 0, so to distinguish case * of only one word in FIFO from case with FIFO empty, we have to * look first to the Hit-FIFO status */ /* * just to minimize time, FIFO is read in packets of words. This * interactive use is not allowed in verilog simulation, so num_word * input is always converted from NULL to all if global var vmetype * is equal to "verilog" * * * if num_word = NULL this function try to read all data in FIFO, with * the following rules : * * 1) reads reg0 and checks if FIFO is empty => exit 2) if not empty * reads MERGER_PACKET_DIM words for each transfer, if the last * word has the empty bit low reads in decreasing order all words * until the last is found All fake words are fulfilled with zeros. * if the last word doesn't have the empty bit low, reads * MERGER_PACKET_DIM more words * * Function returns the number of read words before receiving fifo empty * flag or error code. */ extern char vmetype[15]; unsigned long fifo_status; unsigned long data0; unsigned long data1; int packet; int result; int stop; int j = 0; int ReadWords; stop = 0; packet = 0; ReadWords = 0; if ((!strcmp(vmetype, "verilog")) && (num_word == NULL)) { num_word = HIT_BUFFER_FIFODEPTH; printf("Improper use of hit_buffer_RoadFifoRead in verilog \n"); printf("Converting NULL to HIT_BUFFER_FIFODEPTH \n"); } if (num_word == NULL) { hit_buffer_RoadFifoStatus(hit_buffer, &fifo_status); if (fifo_status & HIT_BUFFER_FIFO_NOEMPTY) { do { status = VISIONread(hit_buffer, (unsigned long) (hb_road_fifo + (packet * HIT_BUFFER_PACKET_DIM)), (unsigned int)(sizeof(unsigned long) * HIT_BUFFER_PACKET_DIM), &real_bytes, (void *) (RoadFifo + (packet * HIT_BUFFER_PACKET_DIM))); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer ROAD_FIFO, opened as %s \n", info); printf("status = %d\n", status); result=-status; } if (!(RoadFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM)] & (1 << 31))) { /* * last word in packet has fifo bit low */ stop = 1; do { data0 = RoadFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j]; data1 = RoadFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j - 1]; if (((!(data0 & (1 << 31))) && (!(data1 & (1 << 31)))) && (j != HIT_BUFFER_PACKET_DIM - 1)) { RoadFifo[(HIT_BUFFER_PACKET_DIM - 1) + (packet * HIT_BUFFER_PACKET_DIM) - j] = 0; } j++; } while (((!(data0 & (1 << 31))) && (!(data1 & (1 << 31)))) && (j != HIT_BUFFER_PACKET_DIM)); } packet++; } while ((stop != 1) && (packet <= ((HIT_BUFFER_FIFODEPTH / HIT_BUFFER_PACKET_DIM)))); if(stop==0) ReadWords= packet * HIT_BUFFER_PACKET_DIM; else ReadWords=(packet * HIT_BUFFER_PACKET_DIM) -j + 1; return ReadWords; } else { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Hit Buffer Road FIFO empty !!!, opened as %s \n", info); result=FIFO_EMPTY; } } /* * if num_word != NULL, tries to read num_word words from the FIFO, * without doing any check */ else if ((num_word != NULL) && (num_word > 0) && (num_word <= HIT_BUFFER_FIFODEPTH)) { status = VISIONread(hit_buffer, (unsigned long) hb_road_fifo, (unsigned int)num_word*sizeof(unsigned long), &real_bytes, (void *)RoadFifo); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading Hit Buffer Road FIFO, opened as %s\n", info); result=(-status); } result=(real_bytes / sizeof(unsigned long)); } else { printf("Error defining Hit Buffer Road FIFO reading parameters, opened as %s \n",info); result=PARAM_ERROR; } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_HitSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *HitSpyBuffer, int num_word) { /* * hit buffers are circular memories. Pointer points to the location * where will be written next data. This function works in the * following way: * * check num_word, if num_word = NULL I) reads all spy buffer memory * from beginning II) reads pointer and overflow III) overflow is * initially set to NO_OVERFLOW, so , in verilog simulation, it * remains in this situation, so doesn't try to reorder data IIII) * if overlow, reorder data * * if num_word != 0 I) reads spy buffer from beginning to num_word, * without reordering * * * returns num_word if successfull, or negative if error */ unsigned long pointer; unsigned long overflow = HIT_BUFFER_NOOVERFLOW; unsigned long *tmp_buffer; int i; int result; if ((num_word > 0) && (num_word <= HIT_BUFFER_SPYBUFFER_LENGHT)) { status = VISIONread(hit_buffer, (unsigned long) hb_hit_spy, (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) HitSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer hit Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word == NULL) { /* allocates a temporary buffer */ if (!(tmp_buffer = malloc(HIT_BUFFER_SPYBUFFER_LENGHT * sizeof(unsigned long)))) { printf("Out of memory, cannot allocate enough memory !!! \n"); result=NO_MEMORY; } /* reads all spy buffer content */ status = VISIONread(hit_buffer, (unsigned long) hb_hit_spy, (unsigned int) (sizeof(unsigned long) * HIT_BUFFER_SPYBUFFER_LENGHT), &real_bytes, (void *) tmp_buffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer hit Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads pointer value */ status = hit_buffer_HitSpyPointerStatus(hit_buffer, &pointer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer hit Spy pointer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads overflow status */ status = hit_buffer_HitSpyOverflowStatus(hit_buffer, &overflow); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer hit Spy overflow , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } if (overflow == HIT_BUFFER_NOOVERFLOW) { for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { HitSpyBuffer[i] = tmp_buffer[i]; } result=HIT_BUFFER_SPYBUFFER_LENGHT; } else if (overflow == HIT_BUFFER_OVERFLOW) { /* reordering data */ for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { HitSpyBuffer[i - pointer] = tmp_buffer[i]; } for (i = 0; i < pointer; i++) { HitSpyBuffer[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i] = tmp_buffer[i]; } free(tmp_buffer); result=HIT_BUFFER_SPYBUFFER_LENGHT; } else { printf("Error in hit buffer overflow status, opened as %s \n", info); result=GENERIC_VMESVT_ERROR; } } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_RoadSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *RoadSpyBuffer, int num_word) { /* * hit buffers are circular memories. Pointer points to the location * where will be written next data. This function works in the * following way: * * check num_word, if num_word = NULL I) reads all spy buffer memory * from beginning II) reads pointer and overflow III) overflow is * initially set to NO_OVERFLOW, so , in verilog simulation, it * remains in this situation, so doesn't try to reorder data IIII) * if overlow, reorder data * * if num_word != 0 I) reads spy buffer from beginning to num_word, * without reordering * * * returns num_word if successfull, or negative if error */ unsigned long pointer; unsigned long overflow = HIT_BUFFER_NOOVERFLOW; unsigned long *tmp_buffer; int i; int result; if ((num_word > 0) && (num_word <= HIT_BUFFER_SPYBUFFER_LENGHT)) { status = VISIONread(hit_buffer, (unsigned long) hb_road_spy, (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) RoadSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer roads Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word == NULL) { /* allocates a temporary buffer */ if (!(tmp_buffer = malloc(HIT_BUFFER_SPYBUFFER_LENGHT * sizeof(unsigned long)))) { printf("Out of memory, cannot allocate enough memory !!! \n"); result=NO_MEMORY; } /* reads all spy buffer content */ status = VISIONread(hit_buffer, (unsigned long) hb_road_spy, (unsigned int) (sizeof(unsigned long) * HIT_BUFFER_SPYBUFFER_LENGHT), &real_bytes, (void *) tmp_buffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer road Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads pointer value */ status = hit_buffer_RoadSpyPointerStatus(hit_buffer, &pointer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer road Spy pointer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads overflow status */ status = hit_buffer_RoadSpyOverflowStatus(hit_buffer, &overflow); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer road Spy overflow , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } if (overflow == HIT_BUFFER_NOOVERFLOW) { for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { RoadSpyBuffer[i] = tmp_buffer[i]; } result=HIT_BUFFER_SPYBUFFER_LENGHT; } else if (overflow == HIT_BUFFER_OVERFLOW) { /* reordering data */ for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { RoadSpyBuffer[i - pointer] = tmp_buffer[i]; } for (i = 0; i < pointer; i++) { RoadSpyBuffer[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i] = tmp_buffer[i]; } free(tmp_buffer); result=HIT_BUFFER_SPYBUFFER_LENGHT; } else { printf("Error in hit buffer overflow status, opened as %s \n", info); result=GENERIC_VMESVT_ERROR; } } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_OutputSpyBufferRead(VISION_SLAVE hit_buffer, unsigned long *OutSpyBuffer, int num_word) { /* * hit buffers are circular memories. Pointer points to the location * where will be written next data. This function works in the * following way: * * check num_word, if num_word = NULL I) reads all spy buffer memory * from beginning II) reads pointer and overflow III) overflow is * initially set to NO_OVERFLOW, so , in verilog simulation, it * remains in this situation, so doesn't try to reorder data IIII) * if overlow, reorder data * * if num_word != 0 I) reads spy buffer from beginning to num_word, * without reordering * * * returns num_word if successfull, or negative if error */ unsigned long pointer; unsigned long overflow = HIT_BUFFER_NOOVERFLOW; unsigned long *tmp_buffer; int i; int result; if ((num_word > 0) && (num_word <= HIT_BUFFER_SPYBUFFER_LENGHT)) { status = VISIONread(hit_buffer, (unsigned long) hb_out_spy, (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) OutSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer out Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word == NULL) { /* allocates a temporary buffer */ if (!(tmp_buffer = malloc(HIT_BUFFER_SPYBUFFER_LENGHT * sizeof(unsigned long)))) { printf("Out of memory, cannot allocate enough memory !!! \n"); result=NO_MEMORY; } /* reads all spy buffer content */ status = VISIONread(hit_buffer, (unsigned long) hb_out_spy, (unsigned int) (sizeof(unsigned long) * HIT_BUFFER_SPYBUFFER_LENGHT), &real_bytes, (void *) tmp_buffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer out Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads pointer value */ status = hit_buffer_OutSpyPointerStatus(hit_buffer, &pointer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer out Spy pointer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } /* reads overflow status */ status = hit_buffer_OutSpyOverflowStatus(hit_buffer, &overflow); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer out Spy overflow , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } if (overflow == HIT_BUFFER_NOOVERFLOW) { for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { OutSpyBuffer[i] = tmp_buffer[i]; } result=HIT_BUFFER_SPYBUFFER_LENGHT; } else if (overflow == HIT_BUFFER_OVERFLOW) { /* reordering data */ for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { OutSpyBuffer[i - pointer] = tmp_buffer[i]; } for (i = 0; i < pointer; i++) { OutSpyBuffer[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i] = tmp_buffer[i]; } free(tmp_buffer); result=HIT_BUFFER_SPYBUFFER_LENGHT; } else { printf("Error in hit buffer overflow status, opened as %s \n", info); result=GENERIC_VMESVT_ERROR; } } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_HitSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *HitSpyBuffer, int num_word, unsigned long offset) { int result; if ((num_word > 0) && ((num_word+offset <= HIT_BUFFER_SPYBUFFER_LENGHT))) { status = VISIONread(hit_buffer, (unsigned long) hb_hit_spy + (offset*4), (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) HitSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading HitBuffer hit Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word ) { printf("error, hit_buffer_HitSpyBufferOffset called with bad num_word arrgument"); result=GENERIC_VMESVT_ERROR; } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_RoadSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *RoadSpyBuffer, int num_word, unsigned long offset) { int result; if ((num_word > 0) && ((num_word+offset <= HIT_BUFFER_SPYBUFFER_LENGHT))) { status = VISIONread(hit_buffer, (unsigned long) hb_road_spy + (offset*4), (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) RoadSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading HitBuffer Road Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word ) { printf("error, hit_buffer_RoadSpyBufferOffset called with bad num_word arrgument"); result=GENERIC_VMESVT_ERROR; } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_OutputSpyBufferReadOffset(VISION_SLAVE hit_buffer, unsigned long *OutSpyBuffer, int num_word, unsigned long offset) { int result; if ((num_word > 0) && ((num_word+offset <= HIT_BUFFER_SPYBUFFER_LENGHT))) { status = VISIONread(hit_buffer, (unsigned long) hb_out_spy + (offset*4), (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) OutSpyBuffer); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading HitBuffer out Spy Buffer , opened as %s \n", info); printf("status = %d\n", status); result=(-status); } result=num_word; } else if (num_word ) { printf("error, hit_buffer_OutSpyBufferOffset called with bad num_word arrgument"); result=GENERIC_VMESVT_ERROR; } return(result); } /* * =========================================================================== * ================= */ int hit_buffer_SSmapWrite(VISION_SLAVE hit_buffer, unsigned long *SSMap, unsigned long num_word, unsigned long offset) { /* * this function writes num_word words in SSmap , or, if num_word eq * NULL, writes a number of words as defined in * HITBUFFER_SSMAP_LENGHT returns number of words transferred or * negative if error occurred */ int debug_mode = 0; if (offset >= HIT_BUFFER_SSMAP_LENGHT) offset = (HIT_BUFFER_SSMAP_LENGHT - 1); if (num_word == NULL) { num_word = HIT_BUFFER_SSMAP_LENGHT; } if ((hb_ss_map + (sizeof(unsigned long) * num_word)) > (hb_ss_map_end + 1)) { VISIONinfo(hit_buffer, "name", (void *) info, 20); if (debug_mode) printf("hit_buffer_SSmapWrite: required memory size = 0x%x,maximum allowed = 0x%x \n", (hb_ss_map + (sizeof(unsigned long) * num_word)), (hb_ss_map_end + 1)); printf("too much words writing SSmap in hit_buffer opened as %s \n", info); return PARAM_ERROR; } status = VISIONwrite(hit_buffer, (unsigned long) (hb_ss_map + offset*4), num_word * sizeof(unsigned long), &real_bytes, SSMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer SSmap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } if (debug_mode) printf("hit_buffer_SSmapWrite: SS written \n"); return (real_bytes / 4); } /* * =========================================================================== * ================= */ int hit_buffer_AMmapWrite(VISION_SLAVE hit_buffer, unsigned long *AMMap, unsigned long num_word, unsigned long offset) { /* * this function writes num_word words in AMmap , or, if num_word eq * NULL, writes a number of words as defined in * HITBUFFER_AMMAP_LENGHT returns number of words transferred or * negative if error occurred SVT lab mvme162 has few memory, so the * transfer of data from slave to master is fragmented in two parts */ int debug_mode = 1; unsigned long num_word1; unsigned long num_word2; unsigned int real_bytes1; unsigned int real_bytes2; int i; if (num_word == NULL) { num_word = HIT_BUFFER_AMMAP_LENGHT; } if ((hb_am_map + 4*offset + (sizeof(unsigned long) * num_word)) > (hb_am_map_end + 1)) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("too much words writing AMmap in hit_buffer opened as %s \n", info); return PARAM_ERROR; } if (num_word <= (HIT_BUFFER_AMMAP_LENGHT / 2)) { status = VISIONwrite(hit_buffer, (unsigned long) (hb_am_map + 4*offset), num_word * sizeof(unsigned long), &real_bytes, AMMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing hit buffer AMmap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return (real_bytes / 4); } else { num_word1 = num_word/16; for (i=0;i<16;i++) { status = VISIONwrite(hit_buffer, (unsigned long) (hb_am_map + 4*i*num_word1), num_word1 * sizeof(unsigned long), &real_bytes1, (AMMap+i*num_word1)); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing first part of hit buffer AMmap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } } return num_word; /* * num_word1 = num_word - (HIT_BUFFER_AMMAP_LENGHT / 2); * num_word2 = num_word - num_word1; * * if (debug_mode){ * printf("AM MAP LENGHT = %d\n",HIT_BUFFER_AMMAP_LENGHT); * printf("numword = %d \n",num_word); * printf("num_word1 = %d \n",num_word1); * printf("num_word2 = %d \n",num_word2); } * status = VISIONwrite(hit_buffer, (unsigned long) (hb_am_map + 4*offset), num_word1 * sizeof(unsigned long), &real_bytes1, AMMap); * if (status != 0) { * VISIONinfo(hit_buffer, "name", (void *) info, 20); * printf("error writing first part of hit buffer AMmap, opened as %s \n", info); * printf("status = %d\n", status); * return (-status); * } * if (debug_mode) printf("hit_buffer_AMmapWrite: I part of AM loaded \n"); * status = VISIONwrite(hit_buffer, (unsigned long)(hb_am_map + 4*offset+num_word1 * sizeof(unsigned long)), * num_word2 * sizeof(unsigned long), &real_bytes2, (AMMap + num_word1)); * if (status != 0) { * VISIONinfo(hit_buffer, "name", (void *) info, 20); * printf("error writing second part of hit buffer AMmap, opened as %s \n", info); * printf("status = %d\n", status); * return (-status); * } * if (debug_mode) printf("hit_buffer_AMmapWrite: II part of AM loaded \n"); * return ((real_bytes1 + real_bytes2) / 4); */ } } /* * =========================================================================== * ================= */ int hit_buffer_SSmapRead(VISION_SLAVE hit_buffer, unsigned long *SSMap, unsigned long num_word, unsigned long offset) { /* * this function reads HIT_BUFFER_SSMAP_LENGHT words from SSMap is * up to the user to check if data buffer is enough large to keep all * read data */ int debug_mode = 0; if (num_word == NULL) { num_word = HIT_BUFFER_SSMAP_LENGHT; } if (offset >= HIT_BUFFER_SSMAP_LENGHT) offset = (HIT_BUFFER_SSMAP_LENGHT - 1); if (((hb_ss_map + (offset * 4)) + (sizeof(unsigned long) * num_word)) > (hb_ss_map_end + 1)) { VISIONinfo(hit_buffer, "name", (void *) info, 20); if (debug_mode) printf("hit_buffer_SSmapRead: required memory size = 0x%x,maximum allowed = 0x%x \n", (hb_ss_map + (sizeof(unsigned long) * num_word)), (hb_ss_map_end + 1)); printf("too much words writing SSmap in hb opened as %s \n", info); return PARAM_ERROR; } status = VISIONread(hit_buffer, (unsigned long) (hb_ss_map+ (offset * 4)), (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) SSMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer SSMap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } if (debug_mode) printf("hit_buffer_SSmapRead: SS read \n"); return (real_bytes/4); } /* * =========================================================================== * ================= */ int hit_buffer_AMmapRead(VISION_SLAVE hit_buffer, unsigned long *AMMap, unsigned long num_word, unsigned long offset) { /* * this function reads HIT_BUFFER_AMMAP_LENGHT words from AMMap is * up to the user to check if the slave has enough data buffer to keep all * read data * svt vme cpu mvme162 hasn't enough memory to store all data, so it is necessary, * if all the memory has to be read, to split the reading in two shots. */ int i; int debug_mode = 0; unsigned long num_word1; unsigned long num_word2; unsigned int real_bytes1; unsigned int real_bytes2; if (num_word == NULL) num_word = HIT_BUFFER_AMMAP_LENGHT; if ((hb_am_map + 4*offset+ (sizeof(unsigned long) * num_word)) > (hb_am_map_end + 1)) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("too much words reading AMmap in hit_buffer opened as %s \n", info); return PARAM_ERROR; } if (num_word <= (HIT_BUFFER_AMMAP_LENGHT / 2)) { status = VISIONread(hit_buffer, (unsigned long) (hb_am_map + 4*offset), (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) AMMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit buffer AMMap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return (real_bytes/4); } else { num_word1 = num_word/16; for (i=0;i<16;i++) { status = VISIONread(hit_buffer, (unsigned long) (hb_am_map + 4*i*num_word1), num_word1 * sizeof(unsigned long), &real_bytes1, (AMMap+i*num_word1)); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing first part of hit buffer AMmap, opened as %s \n", info); printf("status = %d\n", status); return (-status); } } return num_word; /* * num_word1 = num_word - (HIT_BUFFER_AMMAP_LENGHT / 2); * num_word2 = num_word - num_word1; * * if (debug_mode){ * printf("AM MAP LENGHT = %d\n",HIT_BUFFER_AMMAP_LENGHT); * printf("numword = %d \n",num_word); * printf("num_word1 = %d \n",num_word1); * printf("num_word2 = %d \n",num_word2); } * status = VISIONread(hit_buffer, (unsigned long) (hb_am_map + 4*offset), * (unsigned int)(num_word1 * sizeof(unsigned long)), &real_bytes1,(void *) AMMap); * if (status != 0) { * VISIONinfo(hit_buffer, "name", (void *) info, 20); * printf("error reading first part of hit buffer AMmap, opened as %s \n", info); * printf("status = %d\n", status); * return (-status); * } * if (debug_mode) printf("hit_buffer_AMmapRead: I part of AM read \n"); * status = VISIONread(hit_buffer, (unsigned long)(hb_am_map + 4*offset + num_word1 * sizeof(unsigned long)), * (unsigned int) (num_word2 * sizeof(unsigned long)), &real_bytes2, (void *)(AMMap + num_word1)); * if (status != 0) { * VISIONinfo(hit_buffer, "name", (void *) info, 20); * printf("error reading second part of hit buffer AMmap, opened as %s \n", info); * printf("status = %d\n", status); * return (-status); * } * if (debug_mode) printf("hit_buffer_AMmapRead: II part of AM read \n"); * * return ((real_bytes1 + real_bytes2) / 4); */ } } /* * =========================================================================== * ================= */ int hit_buffer_CheckRegistersStatus(VISION_SLAVE hit_buffer, unsigned long *regs_values) { /* * II level function this function checks all status registers of hit * buffer board. regs_values should be filled with expected data. * */ int debug_mode = 0; int i; unsigned long internal_values[HIT_BUFFER_REGISTER_NUMBER]; int error_flag = 0; VISIONinfo(hit_buffer, "name", (void *) info, 20); for (i = 0; i < HIT_BUFFER_REGISTER_NUMBER; i++) { if (debug_mode) printf("i = %d , regs_values = %d \n", i, regs_values[i]); internal_values[i] = regs_values[i]; } hit_buffer_ErrorFlagStatus(hit_buffer, &internal_values[0]); if (internal_values[0] != regs_values[0]) { printf("ERROR in hb status reg: expected value %x, read value %x (open : %x) \n", regs_values[0], internal_values[0],info); error_flag = 1; } hit_buffer_TmodeStatus(hit_buffer, &internal_values[1]); if (internal_values[1] != regs_values[1]) { printf("ERROR in hb Tmode reg: expected value %x, read value %x (open : %x) \n", regs_values[1], internal_values[1],info); error_flag = 1; } hit_buffer_HitFifoStatus(hit_buffer, &internal_values[2]); if (internal_values[2] != regs_values[2]) { printf("ERROR in hb HFIFO reg: expected value %x, read value %x (open : %x) \n", regs_values[2], internal_values[2],info); error_flag = 1; } hit_buffer_RoadFifoStatus(hit_buffer, &internal_values[3]); if (internal_values[3] != regs_values[3]) { printf("ERROR in hb RFIFO reg: expected value %x, read value %x (open : %x) \n", regs_values[3], internal_values[3],info); error_flag = 1; } hit_buffer_OutputHoldStatus(hit_buffer, &internal_values[4]); if (internal_values[4] != regs_values[4]) { printf("ERROR in hb OUTHOLD reg: expected value %x, read value %x (open : %x) \n", regs_values[4], internal_values[4],info); error_flag = 1; } hit_buffer_FSMStatus(hit_buffer, &internal_values[5]); if (internal_values[5] != regs_values[5]) { printf("ERROR in hb FSM reg: expected value %x, read value %x (open : %x) \n", regs_values[5], internal_values[5],info); error_flag = 1; } hit_buffer_FSMHStatus(hit_buffer, &internal_values[6]); if (internal_values[6] != regs_values[6]) { printf("ERROR in hb FSMH reg: expected value %x, read value %x (open : %x) \n", regs_values[6], internal_values[6],info); error_flag = 1; } hit_buffer_FSMRStatus(hit_buffer, &internal_values[7]); if (internal_values[7] != regs_values[7]) { printf("ERROR in hb FSMR reg: expected value %x, read value %x (open : %x) \n", regs_values[7], internal_values[7],info); error_flag = 1; } hit_buffer_HitSpyRegisterStatus(hit_buffer, &internal_values[8]); if (internal_values[8] != regs_values[8]) { printf("ERROR in hb HSPY reg: expected value %x, read value %x (open : %x) \n", regs_values[8], internal_values[8],info); error_flag = 1; } hit_buffer_RoadSpyRegisterStatus(hit_buffer, &internal_values[9]); if (internal_values[9] != regs_values[9]) { printf("ERROR in hb RSPY reg: expected value %x, read value %x (open : %x) \n", regs_values[9], internal_values[9],info); error_flag = 1; } hit_buffer_OutSpyRegisterStatus(hit_buffer, &internal_values[10]); if (internal_values[10] != regs_values[10]) { printf("ERROR in hb OSPY reg: expected value %x, read value %x (open : %x) \n", regs_values[10], internal_values[10],info); error_flag = 1; } hit_buffer_ErrorEnableStatus(hit_buffer, &internal_values[11]); if (internal_values[11] != regs_values[11]) { printf("ERROR in hb ErrEn reg: expected value %x, read value %x (open : %x) \n", regs_values[11], internal_values[11],info); error_flag = 1; } if (error_flag == 0) return OK; else { return UNEXPECTED_REGISTER_VALUE; } } /* * =========================================================================== * ================= */ int hit_buffer_LoadMaps(VISION_SLAVE hit_buffer, char *SSfile, char *AMfile) { /* * II level function sets hb in tmode loads data structures from * files, and after transfers data to hit buffer maps returns number * of word transferred, summed for the 2 maps, or negative if errors * occurs */ int debug_mode = 0; unsigned long *SSpoint; unsigned long *AMpoint; unsigned long SSrealwords; unsigned long AMrealwords; int SSwords = 0; int AMwords = 0; VISIONinfo(hit_buffer, "name", (void *) info, 20); status = hit_buffer_TmodeEnable(hit_buffer); if (status != 0) { printf("Error in hit_buffer_LoadMaps, in hit buffer opened as %s \n", info); return GENERIC_VMESVT_ERROR; } SSwords = load_file_hex(SSfile, &SSpoint); if (SSwords < 0) { printf("Error occurred filling SSmap data structure, in hit buffer opened as %s \n", info); return SSwords; } if (debug_mode) printf("LoadMaps,Number of words in SSmap = %d, in hit buffer opened as %s \n", SSwords, info); AMwords = load_file_hex(AMfile, &AMpoint); if (AMwords < 0) { printf("Error occurred filling AMmap data structure, in hit buffer opened as %s \n", info); return SSwords; } if (debug_mode) printf("LoadMaps,Number of words in AMmap = %d, in hit buffer opened as %s \n", AMwords, info); SSrealwords = hit_buffer_SSmapWrite(hit_buffer, SSpoint, SSwords,0); if (SSrealwords != SSwords) { printf("Error occurred writing SSmap, in hit buffer opened as %s \n", info); return UNEXPECTED_NUMBER_OF_TRANSFERRED_BYTES; } if (debug_mode) printf("hit_buffer_LoadMaps: SSmap loaded \n"); AMrealwords = hit_buffer_AMmapWrite(hit_buffer, AMpoint, AMwords,0); if (AMrealwords != AMwords) { printf("Error occurred writing AMmap, in hit buffer opened as %s \n", info); return UNEXPECTED_NUMBER_OF_TRANSFERRED_BYTES; } if (debug_mode) printf("hit_buffer_LoadMaps: AMmap loaded \n"); free(SSpoint); free(AMpoint); return (AMwords + SSwords); } /* * =========================================================================== * ================= */ int hit_buffer_HitSpyBufferCheck(VISION_SLAVE hit_buffer, char *HitFile) { /* * this function checks hit spy buffer. Just to mantain verilog * compatibily, assume this function is called only after an init * operation, and data from HitFile are loaded in hit spy buffer. * * This function works in the following way: * * * 1) define 2 structures of lenght HIT_BUFFER_SPYBUFFER_LENGHT 2) * calculate Hit_File lenght 3) calculate pointer and overflow 4) put * last HIT_BUFFER_SPYBUFFER_LENGHT data in the two structures. 5) * reads hit spy register 5) check if register value is equal * to calculated value, if not print values 6) reads hit spy buffer * in the second structure, only interesting part 7) compare data in * the 2 structures, print result 9) reset hit spy register 10) * check new value of the register 11) free structures * * * return OK or (- diff_number) * */ int debug_mode = 1; unsigned long hitspyregcmp; unsigned long hitspyregread; long data_number; unsigned long *hitspyread; unsigned long *hitspycmp; unsigned long pointer; unsigned long overflow; int i; int diff_number = 0; VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer Hit Spy buffer, opened as %s \n", info); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &hitspyread); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &hitspycmp); data_number = file_lenght(HitFile); if (debug_mode) printf("HITFILE lenght = %d \n", data_number); if (data_number <= HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_NOOVERFLOW; if (data_number != HIT_BUFFER_SPYBUFFER_LENGHT) pointer = data_number; else if (data_number == HIT_BUFFER_SPYBUFFER_LENGHT) pointer = 0; } if (data_number > HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_OVERFLOW; /* * pointer eq. remains from data_number and * HIT_BUFFER_SPYBUFFER_LENGHT */ pointer = (data_number - ((int) floor(data_number / HIT_BUFFER_SPYBUFFER_LENGHT) * HIT_BUFFER_SPYBUFFER_LENGHT)); } /* assume spy buffer FREEZED, if not doesn't read spy buffer and returns error */ hitspyregcmp = ((pow(2, 17) * overflow) + pointer); /*hitspyregread = hitspyregcmp;*/ if (overflow == HIT_BUFFER_NOOVERFLOW) { load_struct_hex(HitFile, hitspyread); load_struct_hex(HitFile, hitspycmp); /* read spy buffer content */ if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } hit_buffer_HitSpyRegisterStatus(hit_buffer, &hitspyregread); if ( (hitspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Hit Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_HitSpyBufferRead(hit_buffer, hitspyread, pointer); if (debug_mode) save_struct("HITPROVA", hitspyread, pointer); if (debug_mode) printf("hit spy register expected = 0x%x\n", hitspyregcmp); if (debug_mode) printf("hit spy register read = 0x%x\n", hitspyregread); if (hitspyregcmp == hitspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference in register from read and expected value \n"); printf("hit spy register expected = 0x%x\n", hitspyregcmp); printf("hit spy register read = 0x%x\n", hitspyregread); diff_number++; } if (debug_mode) printf("Difference in hit spy buffers from read to expected : \n"); for (i = 0; i <= (pointer - 1); i++) { if (hitspyread[i] != hitspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, hitspycmp[i], hitspyread[i]); } } } if (overflow == HIT_BUFFER_OVERFLOW) { /* * copy last HIT_BUFFER_SPYBUFFER_LENGHT data in HitFile in * structure pointed from hitspyread, reorder copying in * structure pointed from hitspycmp, copy again structure * pointed from hitspycmp in structure pointed from * hitspyread */ load_struct_hex_offset(HitFile, hitspyread, data_number - HIT_BUFFER_SPYBUFFER_LENGHT + 1); /* * if data_number is a multiple of * HIT_BUFFER_SPYBUFFER_LENGHT */ if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } for (i = 0; i < pointer; i++) { hitspycmp[i] = hitspyread[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i]; } for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { hitspycmp[i] = hitspyread[i - pointer]; } for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { hitspyread[i] = hitspycmp[i]; } hit_buffer_HitSpyRegisterStatus(hit_buffer, &hitspyregread); if ( (hitspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Hit Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_HitSpyBufferRead(hit_buffer, hitspyread, HIT_BUFFER_SPYBUFFER_LENGHT); if (hitspyregcmp == hitspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference in register from read and expected value \n"); diff_number++; } if (debug_mode) printf("Difference in hit spy buffers from read to expected : \n"); for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { if (hitspyread[i] != hitspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, hitspycmp[i], hitspyread[i]); } } } hit_buffer_HitSpyRegisterReset(hit_buffer); hitspyregread = 0; hit_buffer_HitSpyRegisterStatus(hit_buffer, &hitspyregread); if ( (hitspyregread & (~0x40000) ) == 0) { if (debug_mode) printf("hit spy register value OK after reset ! \n"); } else { printf("Error: difference from read and expected value of hit spy register after reset \n"); printf("Expected value = %x, read value = %x\n",0x40000,hitspyregread); diff_number++; } free(hitspyread); free(hitspycmp); if (debug_mode) { if (diff_number == 0) { printf("Test OK \n"); } } if (debug_mode) printf("End of hit spy buffer check \n"); return diff_number; } /* * =========================================================================== * ================= */ int hit_buffer_RoadSpyBufferCheck(VISION_SLAVE hit_buffer, char *RoadFile) { /* * this function checks road spy buffer. Just to mantain verilog * compatibily, assume this function is called only after an init * operation, and data from RoadFile are loaded in road spy buffer. * * This function works in the following way: * * * 1) define 2 structures of lenght HIT_BUFFER_SPYBUFFER_LENGHT 2) * calculate Road_File lenght 3) calculate pointer and overflow 4) * put last HIT_BUFFER_SPYBUFFER_LENGHT data in the two structures. * 5) reads road spy register 5) check if register value is * equal to calcualted value, if not print values 6) reads road spy * buffer in the second structure, only interesting part 7) compare * data in the 2 structures, print result 9) reset road spy * register 10) check new value of the register 11) free structures * * * return OK or (- diff_number) * */ int debug_mode = 0; unsigned long roadspyregcmp; unsigned long roadspyregread; long data_number; unsigned long *roadspyread; unsigned long *roadspycmp; unsigned long pointer; unsigned long overflow; int i; int diff_number = 0; VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer Road Spy buffer, opened as %s \n", info); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &roadspyread); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &roadspycmp); data_number = file_lenght(RoadFile); if (debug_mode) printf("ROADFILE lenght = %d \n", data_number); if (data_number <= HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_NOOVERFLOW; if (data_number != HIT_BUFFER_SPYBUFFER_LENGHT) pointer = data_number; else if (data_number == HIT_BUFFER_SPYBUFFER_LENGHT) pointer = 0; } if (data_number > HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_OVERFLOW; /* * pointer eq. remains from data_number and * HIT_BUFFER_SPYBUFFER_LENGHT */ pointer = (data_number - ((int) floor(data_number / HIT_BUFFER_SPYBUFFER_LENGHT) * HIT_BUFFER_SPYBUFFER_LENGHT)); } /* assume spy buffer FREEZED */ roadspyregcmp = ((pow(2, 17) * overflow) + pointer); roadspyregread = roadspyregcmp; if (overflow == HIT_BUFFER_NOOVERFLOW) { load_struct_hex(RoadFile, roadspyread); load_struct_hex(RoadFile, roadspycmp); /* read spy buffer content */ if (debug_mode) save_struct("ROADPROVA", roadspyread, pointer); if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } hit_buffer_RoadSpyRegisterStatus(hit_buffer, &roadspyregread); if ( (roadspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Road Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_RoadSpyBufferRead(hit_buffer, roadspyread, pointer); if (debug_mode) printf("road spy register expected = 0x%x\n", roadspyregcmp); if (debug_mode) printf("road spy register read = 0x%x\n", roadspyregread); if (roadspyregcmp == roadspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference in value register from read and expected value \n"); printf("road spy register expected = 0x%x\n", roadspyregcmp); printf("road spy register read = 0x%x\n", roadspyregread); diff_number++; } if (debug_mode) printf("Difference in road spy buffers from read to expected : \n"); for (i = 0; i <= (pointer - 1); i++) { if (roadspyread[i] != roadspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, roadspycmp[i], roadspyread[i]); } } } if (overflow == HIT_BUFFER_OVERFLOW) { /* * copy last HIT_BUFFER_SPYBUFFER_LENGHT data in RoadFile in * structure pointed from roadspyread, reorder copying in * structure pointed from roadspycmp, copy again structure * pointed from roadspycmp in structure pointed from * roadspyread */ load_struct_hex_offset(RoadFile, roadspyread, data_number - HIT_BUFFER_SPYBUFFER_LENGHT + 1); /* * if data_number is a multiple of * HIT_BUFFER_SPYBUFFER_LENGHT */ if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } for (i = 0; i < pointer; i++) { roadspycmp[i] = roadspyread[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i]; } for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { roadspycmp[i] = roadspyread[i - pointer]; } for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { roadspyread[i] = roadspycmp[i]; } hit_buffer_RoadSpyRegisterStatus(hit_buffer, &roadspyregread); if ( (roadspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Road Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_RoadSpyBufferRead(hit_buffer, roadspyread, HIT_BUFFER_SPYBUFFER_LENGHT); if (roadspyregcmp == roadspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference in register from read and expected value \n"); printf("road spy register expected = 0x%x\n", roadspyregcmp); printf("road spy register read = 0x%x\n", roadspyregread); diff_number++; } if (debug_mode) printf("Difference in road spy buffers from read to expected : \n"); for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { if (roadspyread[i] != roadspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, roadspycmp[i], roadspyread[i]); } } } hit_buffer_RoadSpyRegisterReset(hit_buffer); roadspyregread = 0; hit_buffer_RoadSpyRegisterStatus(hit_buffer, &roadspyregread); if ( (roadspyregread & (~0x40000) ) == 0) { if (debug_mode) printf("road spy register value OK after reset ! \n"); } else { printf("Error: difference from read and expected value of road spy register afte reset \n"); printf("Expected value = %x, read value = %x\n",0x40000,roadspyregread); diff_number++; } free(roadspyread); free(roadspycmp); if (debug_mode) printf("End of road spy buffer check \n"); if (debug_mode) { if (diff_number == 0) { printf("Test OK \n"); } } return diff_number; } /* * =========================================================================== * ================= */ int hit_buffer_OutSpyBufferCheck(VISION_SLAVE hit_buffer, char *OutFile) { /* * this function checks out spy buffer. Just to mantain verilog * compatibily, assume this function is called only after an init * operation, and data from OutFile are loaded in out spy buffer. * * This function works in the following way: * * * 1) define 2 structures of lenght HIT_BUFFER_SPYBUFFER_LENGHT 2) * calculate Out_File lenght 3) calculate pointer and overflow 4) put * last HIT_BUFFER_SPYBUFFER_LENGHT data in the two structures. 5) * reads out spy register 5) check if register value is equal * to calcualted value, if not print values 6) reads out spy buffer * in the second structure, only interesting part 7) compare data in * the 2 structures, print result 9) reset out spy register 10) * check new value of the register 11) free structures * * * return OK or (- diff_number) * */ int debug_mode = 0; unsigned long outspyregcmp; unsigned long outspyregread; long data_number; unsigned long *outspyread; unsigned long *outspycmp; unsigned long pointer; unsigned long overflow; int i; int diff_number = 0; VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer Out Spy buffer, opened as %s \n", info); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &outspyread); def_struct(HIT_BUFFER_SPYBUFFER_LENGHT - 1, &outspycmp); data_number = file_lenght(OutFile); if (data_number <= HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_NOOVERFLOW; if (data_number != HIT_BUFFER_SPYBUFFER_LENGHT) pointer = data_number; else if (data_number == HIT_BUFFER_SPYBUFFER_LENGHT) pointer = 0; } if (data_number > HIT_BUFFER_SPYBUFFER_LENGHT) { overflow = HIT_BUFFER_OVERFLOW; /* * pointer eq. remains from data_number and * HIT_BUFFER_SPYBUFFER_LENGHT */ pointer = (data_number - ((int) floor(data_number / HIT_BUFFER_SPYBUFFER_LENGHT) * HIT_BUFFER_SPYBUFFER_LENGHT)); } /* assume spy buffer FREEZED */ outspyregcmp = ((pow(2, 17) * overflow) + pointer); /*outspyregread = outspyregcmp;*/ if (overflow == HIT_BUFFER_NOOVERFLOW) { load_struct_hex(OutFile, outspyread); load_struct_hex(OutFile, outspycmp); /* read spy buffer content */ if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } hit_buffer_OutSpyRegisterStatus(hit_buffer, &outspyregread); if ( (outspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Out Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_OutputSpyBufferRead(hit_buffer, outspyread, pointer); if (debug_mode) printf("out spy register expected = 0x%x\n", outspyregcmp); if (debug_mode) printf("out spy register read = 0x%x\n", outspyregread); if (outspyregcmp == outspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference from read and expected valuein register value \n"); printf("out spy register expected = 0x%x\n", outspyregcmp); printf("out spy register read = 0x%x\n", outspyregread); diff_number++; } if (debug_mode) printf("Difference in out spy buffers from read to expected : \n"); for (i = 0; i <= (pointer - 1); i++) { if (outspyread[i] != outspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, outspycmp[i], outspyread[i]); } } } if (overflow == HIT_BUFFER_OVERFLOW) { /* * copy last HIT_BUFFER_SPYBUFFER_LENGHT data in OutFile in * structure pointed from outspyread, reorder copying in * structure pointed from outspycmp, copy again structure * pointed from outspycmp in structure pointed from * outspyread */ load_struct_hex_offset(OutFile, outspyread, data_number - HIT_BUFFER_SPYBUFFER_LENGHT + 1); /* * if data_number is a multiple of * HIT_BUFFER_SPYBUFFER_LENGHT */ if (pointer == 0) { pointer = HIT_BUFFER_SPYBUFFER_LENGHT; } for (i = 0; i < pointer; i++) { outspycmp[i] = outspyread[HIT_BUFFER_SPYBUFFER_LENGHT - pointer + i]; } for (i = pointer; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { outspycmp[i] = outspyread[i - pointer]; } for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { outspyread[i] = outspycmp[i]; } hit_buffer_OutSpyRegisterStatus(hit_buffer, &outspyregread); if ( (outspyregread & 0x40000) == 0x40000) { printf("WARNING: SPY = 1, Out Spy buffer not available for reading\n"); return SPY_BUFFERS_NOT_FREEZED;} hit_buffer_OutputSpyBufferRead(hit_buffer, outspyread, HIT_BUFFER_SPYBUFFER_LENGHT); if (outspyregcmp == outspyregread) { if (debug_mode) printf("register compare OK ! \n"); } else { printf("Error: difference in register value from read and expected value \n"); printf("out spy register expected = 0x%x\n", outspyregcmp); printf("out spy register read = 0x%x\n", outspyregread); diff_number++; } if (debug_mode) printf("Difference in out spy buffers from read to expected : \n"); for (i = 0; i < HIT_BUFFER_SPYBUFFER_LENGHT; i++) { if (outspyread[i] != outspycmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x \n", i, outspycmp[i], outspyread[i]); } } } hit_buffer_OutSpyRegisterReset(hit_buffer); outspyregread = 0; hit_buffer_OutSpyRegisterStatus(hit_buffer, &outspyregread); if ( (outspyregread & (~0x40000) ) == 0) { if (debug_mode) printf("out spy register value OK after reset ! \n"); } else { printf("Error: difference from read and expected value of out spy register afte reset \n"); printf("Expected value = %x, read value = %x\n",0x40000,outspyregread); diff_number++; } free(outspyread); free(outspycmp); if (debug_mode) { if (diff_number == 0) { printf("Test OK \n"); } } return diff_number; } /* * =========================================================================== * ================= */ int hit_buffer_HitFifoCheck(VISION_SLAVE hit_buffer, char *HitFile) { /* * check Hit Buffer Hit FIFO This function assume to be called just * after init operation, and that data in HitFile are completely * contained in FIFO. * * This function works in the following way: * * 1) put hit buffer in Tmode 2) put data in HitFile in a structure , * returns if data are more than HIT_BUFFER_FIFODEPTH 3) check fifo * register 4) define a new structures to contain data from FIFO, of * the same depth of previuos 5) data from previuos structure are * copied in the new one, for verilog simulation 6) reads data from * FIFO, only required number 7) check for eventual difference, print * them on screen 8) check again fifo register * * returns number of difference found or OK */ int debug_mode = 0; unsigned long *hitfiforead; unsigned long *hitfifocmp; long data_number; int i; int diff_number = 0; unsigned long fiforegread; unsigned long fiforegcmp; long strip; /* modified by Alex was unsigned long */ VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer Hit Fifo, opened as %s \n", info); hit_buffer_TmodeEnable(hit_buffer); fiforegcmp = 7; fiforegread = 7; hit_buffer_HitFifoStatus(hit_buffer, &fiforegread); if (debug_mode) printf("Hitfifo register: expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); if (fiforegcmp == fiforegread) { if (debug_mode) printf("Hit Fifo register OK \n"); } else { printf("Expected value differs from read value for Hit FIFO register \n"); printf("Hitfifo register: expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); } data_number = load_file_hex(HitFile, &hitfifocmp); if (data_number > HIT_BUFFER_FIFODEPTH) { printf("Too much data in HitFile, to check Hit Fifo of Hit Buffer opened as %s", info); return EXCEED_FIFO_LENGHT; } def_struct(data_number, &hitfiforead); for (i = 0; i < data_number; i++) { hitfiforead[i] = hitfifocmp[i]; } hit_buffer_HitFifoRead(hit_buffer, hitfiforead, data_number); if (debug_mode) printf("Difference in hit fifo from read to expected: \n"); for (i = 0; i < data_number; i++) { if (i != data_number-1) { if ( (strip = hitfiforead[i] - 0x80000000) < 0) printf("Data at line %d hasn't empty_ flag set\n",i);} else strip = hitfiforead[i]; if (strip != hitfifocmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x,stripped value = 0x%x \n", i, hitfifocmp[i], hitfiforead[i],strip); } } if (diff_number != 0) { printf("differences found !!! \n"); } fiforegcmp = 6; fiforegread = 6; hit_buffer_HitFifoStatus(hit_buffer, &fiforegread); if (debug_mode) printf("Hitfifo register after reading FIFO : expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); if (fiforegcmp == fiforegread) { if (debug_mode) printf("Hit Fifo register OK \n"); } else { printf("Expected value of FIFO register differs from read value after reading \n"); printf("Hitfifo register after reading FIFO : expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); } free(hitfiforead); free(hitfifocmp); if (debug_mode) printf("End of hit fifo check \n"); return diff_number; } /* * =========================================================================== * ================= */ int hit_buffer_RoadFifoCheck(VISION_SLAVE hit_buffer, char *RoadFile) { /* * check Hit Buffer Road FIFO This function assume to be called just * after init operation, and that data in RoadFile are completely * contained in FIFO. * * This function works in the following way: * * 1) put hit buffer in Tmode 2) put data in RoadFile in a structure , * returns if data are more than HIT_BUFFER_FIFODEPTH 3) check fifo * register 4) define a new structures to contain data from FIFO, of * the same depth of previuos 5) data from previuos structure are * copied in the new one, for verilog simulation 6) reads data from * FIFO, only required number 7) check for eventual difference, print * them on screen 8) check again fifo register * * returns number of difference found or OK */ int debug_mode = 0; unsigned long *roadfiforead; unsigned long *roadfifocmp; long data_number; int i; int diff_number = 0; unsigned long fiforegread; unsigned long fiforegcmp; long strip; /* modified by alex, was unsigned long */ VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer Road Fifo, opened as %s \n", info); hit_buffer_TmodeEnable(hit_buffer); fiforegcmp = 7; fiforegread = 7; hit_buffer_RoadFifoStatus(hit_buffer, &fiforegread); if (debug_mode) printf("Roadfifo register: expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); if (fiforegcmp == fiforegread) { if (debug_mode) printf("Road Fifo register OK \n"); } else { printf("Expected value differs from read value \n"); printf("Roadfifo register: expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); } data_number = load_file_hex(RoadFile, &roadfifocmp); if (data_number > HIT_BUFFER_FIFODEPTH) { printf("Too much data in RoadFile, to check Road Fifo of Hit Buffer opened as %s", info); return EXCEED_FIFO_LENGHT; } def_struct(data_number, &roadfiforead); for (i = 0; i < data_number; i++) { roadfiforead[i] = roadfifocmp[i]; } hit_buffer_RoadFifoRead(hit_buffer, roadfiforead, data_number); if (debug_mode) printf("Difference in road fifo from read to expected: \n"); for (i = 0; i < data_number; i++) { if (i != data_number-1) { if ( (strip = roadfiforead[i] - 0x80000000) < 0) printf("Data at line %d hasn't empty_ flag set\n",i);} else strip = roadfiforead[i]; if (strip != roadfifocmp[i]) { diff_number++; printf("line number = %d, expected value = 0x%x, read value = 0x%x, stripped value = 0x%x \n", i, roadfifocmp[i], roadfiforead[i],strip); } } if (diff_number != 0) { printf("Differences found \n"); } fiforegcmp = 6; fiforegread = 6; hit_buffer_RoadFifoStatus(hit_buffer, &fiforegread); if (debug_mode) printf("Roadfifo register after reading FIFO : expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); if (fiforegcmp == fiforegread) { if (debug_mode) printf("Road Fifo register OK \n"); } else { printf("Expected value fot FIFO register differs from read value after reading \n"); printf("Roadfifo register after reading FIFO : expected value = 0x%x, read value = 0x%x \n", fiforegcmp, fiforegread); } free(roadfiforead); free(roadfifocmp); if (debug_mode) printf("End of road fifo check \n"); return diff_number; } /* * =========================================================================== * ================= */ int hit_buffer_MapsCheck(VISION_SLAVE hit_buffer, char *SSfile, char *AMfile) { /* * II level function. This function works in the following way: * * 1) sets hb in tmode 2) loads data structures from files, and after * transfers data to hit buffer maps 3) reads maps from hit buffer * in two other structures 4) check if structures contents is the * same,prints differences * * returns OK , or -(number of difference, summed over the two maps) */ int debug_mode = 1; unsigned long *SSpointread; unsigned long *AMpointread; unsigned long *SSpointcmp; unsigned long *AMpointcmp; unsigned long SSrealwords; unsigned long AMrealwords; int SSwords = 0; int AMwords = 0; int SSdiff_number = 0; int AMdiff_number = 0; int i; VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("Check of hit buffer maps, in hit buffer opened as %s \n", info); status = hit_buffer_TmodeEnable(hit_buffer); if (status != 0) { printf("Error in hit_buffer_CheckMaps, in hit buffer opened as %s \n", info); return GENERIC_VMESVT_ERROR; } SSwords = load_file_hex(SSfile, &SSpointcmp); if (SSwords < 0) { printf("Error occurred filling SSmap data structure, in hit buffer opened as %s \n", info); return SSwords; } if (debug_mode) printf("CheckMaps,Number of words in SSmap = %d, in hit buffer opened as %s \n", SSwords, info); AMwords = load_file_hex(AMfile, &AMpointcmp); if (AMwords < 0) { printf("Error occurred filling AMmap data structure, in hit buffer opened as %s \n", info); return AMwords; } if (debug_mode) printf("CheckMaps,Number of words in AMmap = %d, in hit buffer opened as %s \n", AMwords, info); SSrealwords = hit_buffer_SSmapWrite(hit_buffer, SSpointcmp, SSwords,0); if (debug_mode) printf("hit_buffer_MapsCheck: written SSmap \n"); if (SSrealwords != SSwords) { printf("Error occurred writing SSmap, in hit buffer opened as %s \n", info); return UNEXPECTED_NUMBER_OF_TRANSFERRED_BYTES; } AMrealwords = hit_buffer_AMmapWrite(hit_buffer, AMpointcmp, AMwords,0); if (debug_mode) printf("hit_buffer_MapsCheck: written AMmap \n"); if (AMrealwords != AMwords) { printf("Error occurred writing AMmap, in hit buffer opened as %s \n", info); return UNEXPECTED_NUMBER_OF_TRANSFERRED_BYTES; } def_struct(SSwords, &SSpointread); def_struct(AMwords, &AMpointread); /* copy ...cmp in ...read for Verilog simulation */ /* * for (i = 0; i < SSwords; i++) { * SSpointread[i] = SSpointcmp[i]; * } * for (i = 0; i < AMwords; i++) { * AMpointread[i] = AMpointcmp[i]; * } */ hit_buffer_SSmapRead(hit_buffer, SSpointread,NULL,0); if (debug_mode) printf("hit_buffer_MapsCheck: read SSmap \n"); hit_buffer_AMmapRead(hit_buffer, AMpointread,NULL,0); if (debug_mode) printf("hit_buffer_MapsCheck: read AMmap \n"); for (i = 0; i < SSwords; i++) { if (SSpointread[i] != SSpointcmp[i]) { SSdiff_number++; if (SSdiff_number == 1) { printf("Check SSmap,differences from read to write : \n"); } if (SSdiff_number<100) printf("line number = %x, expected value = 0x%x, read value = 0x%x \n", i, SSpointcmp[i], SSpointread[i]); } } for (i = 0; i < AMwords; i++) { if (AMpointread[i] != AMpointcmp[i]) { AMdiff_number++; if (AMdiff_number == 1) { printf("Check AMmap,differences from read to write : \n"); } if (AMdiff_number<100) printf("line number = %x, expected value = 0x%x, read value = 0x%x \n", i, AMpointcmp[i], AMpointread[i]); } } free(SSpointcmp); free(AMpointcmp); free(SSpointread); free(AMpointread); return (AMdiff_number + SSdiff_number); } /* * =========================================================================== * ================= */ /* * =========================================================================== */ int hit_buffer_Random_write(VISION_SLAVE hit_buffer, unsigned long *dataMap, int num_word, unsigned long offset) { /* * this function writes num_word words anywhere on the hit_buffer board * returns number of words transferred or * negative if error occurred * It is up to the user to check EVERYTHING */ int debug_mode = 0; status = VISIONwrite(hit_buffer, (unsigned long) offset, num_word * sizeof(unsigned long), &real_bytes, dataMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error writing on the hit_buffer board, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return (real_bytes / 4); } /* hit_buffer_Random_write */ /* =========================================================================== */ int hit_buffer_Random_read(VISION_SLAVE hit_buffer, unsigned long *dataMap, int num_word, unsigned long offset) { /* * this function reads num_word words from the hit_buffer board * up to the user to check if data buffer is enough large to keep all * read data * It is up to the user to check EVERYTHING */ status = VISIONread(hit_buffer, (unsigned long) offset, (unsigned int) (sizeof(unsigned long) * num_word), &real_bytes, (void *) dataMap); if (status != 0) { VISIONinfo(hit_buffer, "name", (void *) info, 20); printf("error reading hit_buffer board, opened as %s \n", info); printf("status = %d\n", status); return (-status); } return status; } /* hit_buffer_Random_read */ /* * =========================================================================== */