#include #include #include #include #include #include "ti_dsp.h" #include "ROD.h" #define RODID 1 rod_t *pROD; /* defined in ROD.h and used here and in ti_vme_gva.c */ /* Default slot, geographical address, and VME mode */ static int slot=2, mode=3, gaddr=7; /* ---------------------------------------------------------------------- Usage: mV7 ---------------------------------------------------------------------- */ main(int argc, char** argv) { /* The PU descriptor */ ti_dsp_t dsp; unsigned int ist; int inc; int nevt = 10; if (argc > 1) slot = atoi(argv[1]); if (argc > 2) mode = atoi(argv[2]); if (argc > 3) gaddr = atoi(argv[3]); dsp.rodid = RODID; dsp.puid = slot; dsp.nsamp = 5; dsp.ngain = 1; dsp.bootFile = "evtloop.x0"; dsp.calibrationFile = "cc_table.x0"; { extern RODDBG *p_RODDBG; p_RODDBG->vme = 0; p_RODDBG->loc = 0; p_RODDBG->misc = 0; p_RODDBG->util = 0; p_RODDBG->pu = 0; p_RODDBG->ttc = 0; p_RODDBG->oc = 1; } { crate_t *aCrate = ROD_CrateInit(1,0); assert (aCrate != NULL); pROD = aCrate->rod[0]; } ist = ROD_ModuleInit(pROD, gaddr, RODID); assert (ist == 0); /* Configure PUs */ ist = ROD_ConfigPU(pROD, slot, 2); ist = ROD_PModule(pROD); /* Configure mother board components */ ist = ROD_GeneralReset(pROD); ist = ROD_TtcConfig(pROD, mode); /* === Boot the TI processing unit */ ti_boot(&dsp, TI_AUTO); /* === Configure the Output Controller */ ROD_OcResetGen(pROD); /* general reset */ /* Mask all PUs except the one specified by slot */ ROD_OcConfig(pROD, 0x4ff0011 ^ (1 << 15+slot)); ROD_OcRConfig(pROD, &ist); printf("ROD OC Config Register = 0x%08x\n", ist); ROD_OcStatus(pROD, &ist); ROD_OcPStatus(ist); ROD_OcResetEOE(pROD); /* reset EOE flag */ for(inc=0; inc<10; inc++){ printf("Sending %d events\n", nevt); ti_feedevt(&dsp, nevt, 0); /* Lets see what we got */ sleep(1); ti_fpstatus(&dsp); /* Output Controller Status */ ROD_OcStatus(pROD, &ist); ROD_OcPStatus(ist); usleep(10000); { FILE *fd; int nw; unsigned int *data; ist = ROD_OcReadRAM(pROD, &nw, &data, 1); if (ist != SUCCESS) printf("ROD_OcReadRAM() returned %d\n", ist); printf("Read %d words\n", nw); fd = fopen("OCdump.dat", "ab"); fwrite(data, sizeof(int), nw, fd); fclose(fd); free(data); } ROD_OcStatus(pROD, &ist); ROD_OcPStatus(ist); ROD_OcResetEOE(pROD); /* Lets see what we got */ usleep(25000); ist = ti_fpsstatus(&dsp); if (ist & TI_STATUS_NEVT){ puts("Error, there should not be any event in the FIFO"); exit(1); } } /* -- Send serial commands to get the histograms */ ti_syscall(&dsp, 0); ti_fpstatus(&dsp); /* -- Dump the energy histogram FIFO to binary file */ { FILE *fd; int nw; unsigned int data[32768]; nw = ti_hread(&dsp, data, 32768); printf("Read %d words\n", nw); fd = fopen("hist.data", "wb"); fwrite(data, sizeof(int), nw, fd); fclose(fd); } ti_syscall(&dsp, 1); ti_fpstatus(&dsp); /* -- Dump the time histogram FIFO to binary file */ { FILE *fd; int nw; unsigned int data[32768]; nw = ti_hread(&dsp, data, 32768); printf("Read %d words\n", nw); fd = fopen("hist.data", "ab"); fwrite(data, sizeof(int), nw, fd); fclose(fd); } /* -- DSP power down */ ti_syscall(&dsp, 2); ROD_End(pROD); } void ti_utrig(ti_dsp_p dsp, int a, int b, int c) { ROD_TtcEvent(pROD, a, b, c); }