Beispiel #1
0
int main(int argc, char *argv[])
{
	long actualFrequency = 0;
	long requestedFrequency = 1e9 / MainClockPeriod;

	PaxosIndication indication(IfcNames_PaxosIndicationH2S);
	echoRequestProxy = new PaxosRequestProxy(IfcNames_PaxosRequestS2H);

	int status = setClockFrequency(0, requestedFrequency, &actualFrequency);
	fprintf(stderr, "Requested main clock frequency %5.2f, actual clock frequency \
					%5.2f  MHz. status=%d, errno=%d\n",
			(double)requestedFrequency * 1.0e-6,
			(double)actualFrequency * 1.0e-6,
			status, errno);

	uint32_t ballot  = 1;
	send1Amessage(ballot);
	send1Bmessage(ballot, 0, 0, 1);
	send1Bmessage(ballot, 0, 0, 2);
	send2Bmessage(ballot, 42, 0);
	send2Bmessage(ballot, 42, 0);
	send2Bmessage(ballot, 42, 1);

	return 0;
}
Beispiel #2
0
int main(int argc, const char **argv)
{
  PortalPoller *poller = new PortalPoller();
  AuroraIndication *indication = new AuroraIndication(IfcNames_AuroraIndication);
  AuroraRequestProxy *device = new AuroraRequestProxy(IfcNames_AuroraRequest, poller);

  long freq = 0;
  setClockFrequency(0, 200000000, &freq);

  fprintf(stderr, "Main::calling say1(%d)\n", 0);
  device->send(0);

  fprintf(stderr, "Main::about to go to sleep\n");
  int count = 0;
  while(true){
    device->debug();
    device->userClkElapsedCycles(1000);
    device->mgtRefClkElapsedCycles(1000);
    device->qpllReset(count < 2);
    device->pma_init(count < 2);
    device->loopback(1);
    if (count < 0x14) {
      fprintf(stderr, "Reading drp reg %x\n", count+0x30);
      device->drpRequest(count+0x30, 0, 0);
    }
    count++;
    sleep(1);
  }
}
Beispiel #3
0
int main(int argc, const char **argv)
{
	char hostname[32];
	
	//Getting my ID
	if (argc >= 3) {
		strncpy(hostname, argv[1], 32);
		myid = atoi(argv[1]);
	} else {
		gethostname(hostname, 32);
		if ( strstr(hostname, "nohost") != NULL ) {
			myid = atoi(hostname+strlen("nohost"));
		} else if( strstr(hostname, "bdbm") != NULL ) {
			myid = atoi(hostname+strlen("bdbm"));
		} else {
			myid = 1;
		}
	}

	fprintf(stderr, "Main: hostname=%s myid=%d\n", hostname, myid);

	init_dma();


	long actualFrequency=0;
	long requestedFrequency=1e9/MainClockPeriod;
	int status = setClockFrequency(0, requestedFrequency, &actualFrequency);
	fprintf(stderr, "Requested Freq: %5.2f, Actual Freq: %5.2f, status=%d\n"
			,(double)requestedFrequency*1.0e-6
			,(double)actualFrequency*1.0e-6,status);

	//Start ext aurora
	auroraifc_start(myid);

	device->start(0);
	device->setDebugVals(0,0); //flag, delay

	device->debugDumpReq(0);
	sleep(1);
	device->debugDumpReq(0);
	sleep(1);

	//void local_test(bool check, int read_repeat, int debug_lvl )
//	local_test(true, 1, 5);
//	LOG(0, "Press any key to continue..\n");
	//gets(str);

	//void one_to_many_test(bool check, int read_repeat, int debug_lvl, int accessNode)
	one_to_many_test(true, 1, 5, 1);
	LOG(0, "Press any key to continue..\n");
//	gets(str);
	
	//void many_to_many_test(bool check, int test_repeat, int read_repeat, int debug_lvl)
//	many_to_many_test(true, 1, 10, 5);


}
Beispiel #4
0
void
ReSID::loadFromBuffer(uint8_t **buffer)
{
	debug(2, "  Loading ReSID state...\n");

    setChipModel((chip_model)read8(buffer));
    setAudioFilter((bool)read8(buffer));
    setSamplingMethod((sampling_method)read8(buffer));
    setSampleRate(read32(buffer));
    setClockFrequency(read32(buffer));
}
Beispiel #5
0
int main(int argc, const char **argv)
{
  MaxSonarCtrlIndication *ind = new MaxSonarCtrlIndication(IfcNames_MaxSonarCtrlIndicationH2S);
  MaxSonarCtrlRequestProxy *device = new MaxSonarCtrlRequestProxy(IfcNames_MaxSonarCtrlRequestS2H);
  long req_freq = 100000000; // 100 mHz
  long freq = 0;
  setClockFrequency(0, req_freq, &freq);
  fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq);
  device->range_ctrl(1);

  while(true){
    usleep(50000);
    device->pulse_width();
    sem_wait(&(ind->pulse_width_sem));
    float distance = ((float)ind->useconds)/147.0;
    fprintf(stderr, "(%8d microseconds == %8f inches)\n", ind->useconds, distance);
  }
}
Beispiel #6
0
int main(int argc, const char **argv)
{
    int mismatch = 0;
    uint32_t sg = 0;
    int max_error = 10;

    if (sem_init(&test_sem, 1, 0)) {
        fprintf(stderr, "error: failed to init test_sem\n");
        exit(1);
    }
    fprintf(stderr, "testmemwrite: start %s %s\n", __DATE__, __TIME__);
    DmaManager *dma = platformInit();
    MemwriteRequestProxy *device = new MemwriteRequestProxy(IfcNames_MemwriteRequestS2H);
    MemwriteIndication deviceIndication(IfcNames_MemwriteIndicationH2S);

    fprintf(stderr, "main::allocating memory...\n");
    int dstAlloc = portalAlloc(alloc_sz, 0);
    unsigned int *dstBuffer = (unsigned int *)portalMmap(dstAlloc, alloc_sz);
#ifdef FPGA0_CLOCK_FREQ
    long req_freq = FPGA0_CLOCK_FREQ, freq = 0;
    setClockFrequency(0, req_freq, &freq);
    fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq);
#endif
    unsigned int ref_dstAlloc = dma->reference(dstAlloc);
    for (int i = 0; i < numWords; i++)
        dstBuffer[i] = 0xDEADBEEF;
    portalCacheFlush(dstAlloc, dstBuffer, alloc_sz, 1);
    fprintf(stderr, "testmemwrite: flush and invalidate complete\n");
    fprintf(stderr, "testmemwrite: starting write %08x\n", numWords);
    portalTimerStart(0);
    device->startWrite(ref_dstAlloc, 0, numWords, burstLen, iterCnt);
    sem_wait(&test_sem);
    for (int i = 0; i < numWords; i++) {
        if (dstBuffer[i] != sg) {
            mismatch++;
            if (max_error-- > 0)
                fprintf(stderr, "testmemwrite: [%d] actual %08x expected %08x\n", i, dstBuffer[i], sg);
        }
        sg++;
    }
    platformStatistics();
    fprintf(stderr, "testmemwrite: mismatch count %d.\n", mismatch);
    exit(mismatch);
}
Beispiel #7
0
/*!
 */
void pDetectorConfiguration::readFromFile(std::string filePath)
{
  *xpollog::kInfo << "Reading configuration from " << filePath <<
    "... " << endline;
  std::ifstream *inputFile = xpolio::kIOManager->openInputFile(filePath);
  xpolio::kIOManager->skipLine(inputFile);
  setReadoutMode(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setBufferMode(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setCalibrationDac(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setPixelAddressX(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setPixelAddressY(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  for (int i = 0; i <  NUM_READOUT_CLUSTERS; i++) {
    setThresholdDac(i, xpolio::kIOManager->readUnsignedShort(inputFile));
  }
  xpolio::kIOManager->skipLine(inputFile);
  //  setTimingCode(xpolio::kIOManager->readUnsignedShort(inputFile));
  setClockFrequency(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setClockShift(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setNumPedSamples(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setPedSampleDelay(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setTrgEnableDelay(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setMinWindowSize(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setMaxWindowSize(xpolio::kIOManager->readUnsignedShort(inputFile));
  xpolio::kIOManager->skipLine(inputFile);
  setWindowMarginHigh(xpolio::kIOManager->readBool(inputFile));
  xpolio::kIOManager->closeInputFile(inputFile);
}
Beispiel #8
0
int runtest(int argc, const char ** argv)
{
  int test_result = 0;
  int srcAlloc;
  unsigned int *srcBuffer = 0;

  fprintf(stderr, "Main::%s %s\n", __DATE__, __TIME__);
  MemreadRequestProxy *device = new MemreadRequestProxy(IfcNames_MemreadRequestS2H);
  MemreadIndication deviceIndication(IfcNames_MemreadIndicationH2S);
  DmaManager *dma = platformInit();

  fprintf(stderr, "Main::allocating memory...\n");
  srcAlloc = portalAlloc(alloc_sz, 0);
  srcBuffer = (unsigned int *)portalMmap(srcAlloc, alloc_sz);

#ifdef FPGA0_CLOCK_FREQ
  long req_freq = FPGA0_CLOCK_FREQ;
  long freq = 0;
  setClockFrequency(0, req_freq, &freq);
  fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq);
#endif

  for (int i = 0; i < numWords; i++){
    srcBuffer[i] = i;
  }

  portalCacheFlush(srcAlloc, srcBuffer, alloc_sz, 1);
  fprintf(stderr, "Main::flush and invalidate complete\n");

  unsigned int ref_srcAlloc = dma->reference(srcAlloc);
  fprintf(stderr, "ref_srcAlloc=%d\n", ref_srcAlloc);

  if(true) {
    fprintf(stderr, "Main::test read %08x\n", numWords);
    // first attempt should get the right answer
    device->startRead(ref_srcAlloc, 0, numWords, burstLen);
    sem_wait(&test_sem);
    if (mismatchCount) {
      fprintf(stderr, "Main::first test failed to match %d.\n", mismatchCount);
      test_result++;     // failed
    }
  }

  int err = 5;
  switch (err){
  case 0:
    {
      fprintf(stderr, "Main: attempt to use a de-referenced sglist\n");
      dma->dereference(ref_srcAlloc);
      device->startRead(ref_srcAlloc, 0, numWords, burstLen);
      break;
    } 
  case 1:
    {
      fprintf(stderr, "Main: attempt to use an out-of-range sglist\n");
      device->startRead(ref_srcAlloc+32, 0, numWords, burstLen);
      break;
    }
  case 2:
    {
      fprintf(stderr, "Main: attempt to use an invalid sglist\n");
      device->startRead(ref_srcAlloc+1, 0, numWords, burstLen);
      break;
    }
  case 3:
    {
      fprintf(stderr, "Main: attempt to use an invalid mmusel\n");
      device->startRead(ref_srcAlloc | (1<<16), 0, numWords, burstLen);
      break;
    }
  case 4:
    {
      fprintf(stderr, "Main: attempt to read off the end of the region\n");
      device->startRead(ref_srcAlloc, numWords<<2, burstLen, burstLen);
      break;
    }
  default:
    {
      device->startRead(ref_srcAlloc, 0, numWords, burstLen);
    }
  }

  sem_wait(&test_sem);
  if (mismatchCount) {
    fprintf(stderr, "Main::first test failed to match %d.\n", mismatchCount);
    test_result++;     // failed
  }
  return test_result;
}
Beispiel #9
0
void
SIDWrapper::setNTSC()
{
    debug(2, "SIDWrapper::setNTSC\n");
    setClockFrequency(NTSC_CYCLES_PER_FRAME * NTSC_REFRESH_RATE);
}
Beispiel #10
0
void
SIDWrapper::setPAL()
{
    debug(2, "SIDWrapper::setPAL\n");
    setClockFrequency(PAL_CYCLES_PER_FRAME * PAL_REFRESH_RATE);
}
Beispiel #11
0
int main(int argc, const char **argv)
{
  fprintf(stderr, "%s %s\n", __DATE__, __TIME__);
  bool sane = 1;
#define LARGE_MAT
#ifdef LARGE_MAT
#ifdef BSIM
  int A = 64;
  int B = 256;
#else
  int A = 256;
  int B = 2048;
#endif
  if (argc > 1) {
    B = strtoul(argv[1], 0, 0);
    A = 2*B;
  }
  srand(A*B);
  cv::Mat m1(A,B,CV_32F);
  cv::Mat m2(B,A,CV_32F);
  for(int a = 0; a < A; a++){
    for(int b = 0; b < B; b++){
      float v = (float)(rand() % 10);
      m2.at<float>(b,a) = (A*B)+v;
      m1.at<float>(a,b) = v;
    }
  }
#else
  cv::Mat m1 = (cv::Mat_<float>(4,8) <<
		11,12,13,14,15,16,17,18,
		21,22,23,24,25,26,27,28,
		31,32,33,34,35,36,37,38,
		41,42,43,44,45,46,47,48
		);
  cv::Mat m2 = (cv::Mat_<float>(8,4) <<
		51,62,53,54,
		55,56,57,58,
		61,62,63,64,
		65,66,67,68,
		71,72,73,74,
		75,76,77,78,
		81,82,83,84,
		85,86,87,88
		);
#endif

#ifndef CUDA_PERF_TEST
#ifdef MATRIX_NT
  mmdevice = new MmRequestNTProxy(IfcNames_MmRequestNTS2H);
#else
#ifdef MATRIX_TN
  mmdevice = new MmRequestTNProxy(IfcNames_MmRequestTNS2H);
#endif
#endif
  MmIndication *mmdeviceIndication = new MmIndication(IfcNames_MmIndicationH2S);
  //TimerRequestProxy *timerdevice = new TimerRequestProxy(IfcNames_TimerRequestPortalS2H);
  TimerIndication timerdeviceIndication(IfcNames_TimerIndicationH2S);
    DmaManager *dma = platformInit();

  if(sem_init(&mul_sem, 1, 0)){
    fprintf(stderr, "failed to init mul_sem\n");
    return -1;
  }

  long req_freq = 100000000;
  long freq = 0;
  setClockFrequency(0, req_freq, &freq);
  fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq);

  matAllocator = new PortalMatAllocator(dma);
  FILE *octave_file = fopen("foo.m", "w");

  fprintf(stderr, "OpenCV matmul\n");
  portalTimerStart(0);
  cv::Mat  m3 = m1 * m2;
  //uint64_t opencv_hw_cycles = portalTimerLap(0);

  PortalMat tm3;
  fprintf(stderr, "Naive matmul\n");
  portalTimerStart(0);
  tm3.naive_mul(m1,m2, octave_file);
  //uint64_t naive_hw_cycles = portalTimerLap(0);

  if (1) {
    fprintf(stderr, "DumpMat\n");
    dumpMatOctave<float>("m1",  "%10.5f", m1,  octave_file);
    dumpMatOctave<float>("m2",  "%10.5f", m2,  octave_file);
    dumpMatOctave<float>("m3",  "%10.5f", m3,  octave_file);
    dumpMatOctave<float>("tm3", "%10.5f", tm3, octave_file);
    fclose(octave_file);
    sane = tm3.compare(m3, 0, 0, 0.0001, 0, false);
    fprintf(stderr, "sane=%d\n", sane);
    fflush(stdout);
  }

#ifdef MATRIX_TN
  fprintf(stderr, "pm1t\n");
  PortalMat pm1t(m1.t());
  fprintf(stderr, "pm2\n");
  PortalMat pm2(m2);
  pm1t.reference();
  pm2.reference();
#else
#ifdef MATRIX_NT
  fprintf(stderr, "pm1\n");
  PortalMat pm1(m1);
  fprintf(stderr, "pm2t\n");
  PortalMat pm2t(m2.t());
  pm1.reference();
  pm2t.reference();
#endif
#endif
  PortalMat pm3;
  pm3.create(m1.rows, m2.cols, CV_32F);
  pm3.reference();

  // we invoke .reference on the matrices in advance 
  // in order to avoid counting the elapsed time for
  // performance analysis.  This is not strictly necessary
  // as all the portalmat methods make sure a valid 
  // reference is available before invoking the hardware

  pthread_t dbgtid;
  fprintf(stderr, "creating debug thread\n");

  if(pthread_create(&dbgtid, NULL,  dbgThread, NULL)){
   fprintf(stderr, "error creating debug thread\n");
   exit(1);
  }

  fprintf(stderr, "HW matmul\n");
  portalTimerStart(0);
#ifdef MATRIX_TN
  pm3.multf(pm1t, pm2, mmdeviceIndication);
#else
#ifdef MATRIX_NT
  pm3.multf(pm1, pm2t, mmdeviceIndication);
#endif
#endif
#if 0
  //uint64_t hw_cycles = portalTimerLap(0); 
  uint64_t read_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Read);
  uint64_t write_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Write);
  float read_util = (float)read_beats/(float)mmdeviceIndication->ccnt;
  float write_util = (float)write_beats/(float)mmdeviceIndication->ccnt;
  float read_bw = read_util * N_VALUE * 4 * (float)freq / 1.0e9;
  float write_bw = write_util * N_VALUE * 4 * (float)freq / 1.0e9;
  float macs = m1.rows * m2.rows * m2.cols;
  fprintf(stderr, "Bus frequency %f MHz\n", (float)freq / 1.0e6);
  fprintf(stderr, "memory read  beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)read_beats, read_util, read_bw);
  fprintf(stderr, "memory write beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)write_beats, write_util, write_bw);
  fprintf(stderr, "Throughput %f macs/cycle %f GFLOP/s\n",
	  (float)macs / (float)mmdeviceIndication->ccnt,
	  2.0 * (float)macs / (float)mmdeviceIndication->ccnt * freq / 1.0e9);
  fprintf(stderr, "Time %f cycles, opencv matmul %f cycles (speedup %f), naive matmul %f cycles (speedup %f)\n",
	  (float)mmdeviceIndication->ccnt,
	  (float)opencv_hw_cycles, (float)opencv_hw_cycles/(float)mmdeviceIndication->ccnt,
	  (float)naive_hw_cycles, (float)naive_hw_cycles/(float)mmdeviceIndication->ccnt);
#endif

  if (0) {
    dumpMat<float>("pm3", "%5.1f", pm3);
    dumpMat<float>(" m3", "%5.1f", m3);
  }
  bool eq = pm3.compare(m3);
#else // CUDA_PERF_TEST
  cv::Mat cm3(m1.rows,m2.cols, CV_32F);
  cuda_mm(m1, m2, cm3);
  cv::Mat  m3 = m1 * m2;
  bool eq = compare(m3, cm3, 0.01);
#endif // CUDA_PERF_TEST
  fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXX eq=%d\n", eq);
  return(!(eq&&sane));
}
Beispiel #12
0
int main(int argc, const char **argv)
{
  int i;
  int srcAlloc;
  int dstAlloc;
  unsigned int *srcBuffer = 0;
  unsigned int *dstBuffer = 0;


  FMComms1RequestProxy *device = 0;
  FMComms1Indication *deviceIndication = 0;
  BlueScopeEventPIORequestProxy *bluescope = 0;
  BlueScopeEventPIOIndication *bluescopeIndication = 0;

  fprintf(stdout, "Main::%s %s\n", __DATE__, __TIME__);

  if(sem_init(&cv_sem, 1, 0)){
    fprintf(stdout, "failed to init cv_sem\n");
    exit(1);
  }

  if(sem_init(&read_sem, 1, 0)){
    fprintf(stdout, "failed to init read_sem\n");
    exit(1);
  }

  if(sem_init(&write_sem, 1, 0)){
    fprintf(stdout, "failed to init write_sem\n");
    exit(1);
  }

  device = new FMComms1RequestProxy(IfcNames_FMComms1Request);
  DmaManager *dma = platformInit();
  deviceIndication = new FMComms1Indication(IfcNames_FMComms1Indication);
  bluescope = new BlueScopeEventPIORequestProxy(IfcNames_BlueScopeEventPIORequest);
  bluescopeIndication = new BlueScopeEventPIOIndication(IfcNames_BlueScopeEventPIOIndication);

  fprintf(stdout, "Main::allocating memory...\n");
  srcAlloc = portalAlloc(alloc_sz, 0);

  srcBuffer = (unsigned int *)portalMmap(srcAlloc, alloc_sz);
  if ((char *) srcBuffer == MAP_FAILED) perror("srcBuffer mmap failed");
  assert ((char *) srcBuffer != MAP_FAILED);

  dstAlloc = portalAlloc(alloc_sz, 0);

  dstBuffer = (unsigned int *)portalMmap(dstAlloc, alloc_sz);
  if ((char *) dstBuffer == MAP_FAILED) perror("dstBuffer mmap failed");
  assert ((char *) dstBuffer != MAP_FAILED);

  int status;
  status = setClockFrequency(0, 100000000, 0);
  /* FMComms1 refclk should be 30 MHz */
  status = setClockFrequency(1,  30000000, 0);
    
  portalCacheFlush(srcAlloc, srcBuffer, alloc_sz, 1);
  portalCacheFlush(dstAlloc, dstBuffer, alloc_sz, 1);
  fprintf(stdout, "Main::flush and invalidate complete\n");

  bluescope->doReset();
  WHERE();
  bluescope->setTriggerMask (0xFFFFFFFF);
  WHERE();
  bluescope->getCounterValue();
  WHERE();
  bluescope->enableIndications(1);
  WHERE();
  sem_wait(&cv_sem);
  fprintf(stdout, "Main::initial BlueScopeEventPIO counterValue: %d\n", counter_value);

  device->getReadStatus();
  device->getWriteStatus();
  sem_wait(&read_sem);
  sem_wait(&write_sem);
  fprintf(stdout, "Main::after getStateDbg\n");

  unsigned int ref_srcAlloc = dma->reference(srcAlloc);
  fprintf(stdout, "ref_srcAlloc=%d\n", ref_srcAlloc);
  unsigned int ref_dstAlloc = dma->reference(dstAlloc);
  fprintf(stdout, "ref_dstAlloc=%d\n", ref_dstAlloc);

  fprintf(stdout, "Main::starting read %08x\n", numWords);

  device->startRead(ref_srcAlloc, numWords, readBurstLen, 1);
  device->startWrite(ref_dstAlloc, numWords, writeBurstLen, 1);
  sem_wait(&read_sem);



   sleep(5);
  device->getReadStatus();
  device->getWriteStatus();
  sem_wait(&read_sem);
  sem_wait(&write_sem);
   sleep(5);
  fprintf(stdout, "Main::stopping reads\n");
  device->startRead(ref_srcAlloc, numWords, readBurstLen, 0);
  fprintf(stdout, "Main::stopping writes\n");
  device->startWrite(ref_dstAlloc, numWords, writeBurstLen, 0);
  device->getReadStatus();
  device->getWriteStatus();
  sem_wait(&read_sem);
  sem_wait(&write_sem);
  testi2c("/dev/i2c-1", 0x58);

  bluescope->getCounterValue();
  fprintf(stdout, "Main::getCounter\n");
 
  sem_wait(&cv_sem);
  
  fprintf(stdout, "Main::final BlueScopeEventPIO counterValue: %d\n", counter_value);
  fprintf(stdout, "received %d events\n", eventcount);
  for (i = 0; i < eventcount; i += 1) {
      fprintf(stdout, "reportEvent(0x%08x, 0x%08x)\n", events[i], timestamps[i]);
  }

  exit(0);
}
Beispiel #13
0
int main(int argc, const char **argv)
{
	testPassed=true;

	fprintf(stderr, "Initializing Connectal & DMA...\n");

	device = new FlashRequestProxy(IfcNames_FlashRequestS2H);
	FlashIndication deviceIndication(IfcNames_FlashIndicationH2S);
    DmaManager *dma = platformInit();

	fprintf(stderr, "Main::allocating memory...\n");
	
	// Memory for DMA
	srcAlloc = portalAlloc(srcAlloc_sz, 0);
	dstAlloc = portalAlloc(dstAlloc_sz, 0);
	srcBuffer = (unsigned int *)portalMmap(srcAlloc, srcAlloc_sz); // Host->Flash Write
	dstBuffer = (unsigned int *)portalMmap(dstAlloc, dstAlloc_sz); // Flash->Host Read

	// Memory for FTL
	blkmapAlloc = portalAlloc(blkmapAlloc_sz * 2, 0);
	char *ftlPtr = (char*)portalMmap(blkmapAlloc, blkmapAlloc_sz * 2);
	blkmap      = (uint16_t(*)[NUM_LOGBLKS]) (ftlPtr);  // blkmap[Seg#][LogBlk#]
	blkmgr      = (uint16_t(*)[NUM_CHIPS][NUM_BLOCKS])  (ftlPtr+blkmapAlloc_sz); // blkmgr[Bus][Chip][Block]

	fprintf(stderr, "dstAlloc = %x\n", dstAlloc); 
	fprintf(stderr, "srcAlloc = %x\n", srcAlloc); 
	fprintf(stderr, "blkmapAlloc = %x\n", blkmapAlloc); 
	
	pthread_mutex_init(&flashReqMutex, NULL);
	pthread_cond_init(&flashFreeTagCond, NULL);

	printf( "Done initializing hw interfaces\n" ); fflush(stdout);

	portalCacheFlush(dstAlloc, dstBuffer, dstAlloc_sz, 1);
	portalCacheFlush(srcAlloc, srcBuffer, srcAlloc_sz, 1);
	portalCacheFlush(blkmapAlloc, blkmap, blkmapAlloc_sz*2, 1);

	ref_dstAlloc = dma->reference(dstAlloc);
	ref_srcAlloc = dma->reference(srcAlloc);
	ref_blkmapAlloc = dma->reference(blkmapAlloc);

	device->setDmaWriteRef(ref_dstAlloc);
	device->setDmaReadRef(ref_srcAlloc);
	device->setDmaMapRef(ref_blkmapAlloc);

	for (int t = 0; t < NUM_TAGS; t++) {
		readTagTable[t].busy = false;
		writeTagTable[t].busy = false;
		eraseTagTable[t].busy = false;

		int byteOffset = t * FPAGE_SIZE;
		readBuffers[t] = dstBuffer + byteOffset/sizeof(unsigned int);
		writeBuffers[t] = srcBuffer + byteOffset/sizeof(unsigned int);
	}

	for (int lpa=0; lpa < NUM_SEGMENTS*NUM_LOGBLKS*NUM_PAGES_PER_BLK; lpa++) {
		flashStatus[lpa] = UNINIT;
	}

	for (int t = 0; t < NUM_TAGS; t++) {
		for ( unsigned int i = 0; i < FPAGE_SIZE/sizeof(unsigned int); i++ ) {
			readBuffers[t][i] = 0xDEADBEEF;
			writeBuffers[t][i] = 0xBEEFDEAD;
		}
	}

	long actualFrequency=0;
	long requestedFrequency=1e9/MainClockPeriod;
	int status = setClockFrequency(0, requestedFrequency, &actualFrequency);
	fprintf(stderr, "Requested Freq: %5.2f, Actual Freq: %5.2f, status=%d\n"
			,(double)requestedFrequency*1.0e-6
			,(double)actualFrequency*1.0e-6,status);

	printf( "Start!\n" ); fflush(stdout);
	device->start(0);
	device->setDebugVals(0,0); //flag, delay

	device->debugDumpReq(0);
	sleep(1);

	printf( "Read initial FTL table from table.dump.0\n" ); fflush(stdout);
	// Read Initial FTL table
	if (readFTLfromFile("table.dump.0", ftlPtr) != 0) {
		fprintf(stderr, "Read Failure\n");
		return -1;
	}
	printf( "Done reading table.dump.0\n" ); fflush(stdout);

	printf( "MAP Upload to HW!\n" ); fflush(stdout);
	device->uploadMap();

	timespec start, now;
	clock_gettime(CLOCK_REALTIME, & start);

	printf( "Test Write!\n" ); fflush(stdout);

	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			int freeTag = waitIdleWriteBuffer();

			// fill write memory
			for (unsigned int w=0; w<FPAGE_SIZE_VALID/sizeof(unsigned int); w++) {
				writeBuffers[freeTag][w] = hashAddrToData(lpa, w);
			}

			writePage(freeTag, lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumWritesInFlight() == 0 ) break;
	}

	// read back Map and Save to table.dump.1
	device->downloadMap(); // read table from FPGA
	if(writeFTLtoFile("table.dump.1", ftlPtr) != 0) {
		fprintf(stderr, "Write Failure\n");
		return -1;
	}

	printf( "Test Read!\n" ); fflush(stdout);
	
	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			readPage(waitIdleReadBuffer(), lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumReadsInFlight() == 0 ) break;
	}

	printf( "Test Erase!\n" ); fflush(stdout);
	for (int logblk = 0; logblk < NUM_LOGBLKS; logblk++){
		// test only 1024 segments due to some bad blocks (cannot allocate full 4096 segments)
		for (int segnum = 0; segnum < 1024; segnum++) {
			// assuming page_ofs = 0
			int lpa = (segnum<<14) + logblk;
			eraseBlock(waitIdleEraseTag(), lpa);
		}
	}

	while (true) {
		usleep(100);
		if ( getNumErasesInFlight() == 0 ) break;
	}

	int elapsed = 0;
	while (true) {
		usleep(100);
		if (elapsed == 0) {
			elapsed=10000;
			device->debugDumpReq(0);
		}
		else {
			elapsed--;
		}
		if ( getNumReadsInFlight() == 0 ) break;
	}
	device->debugDumpReq(0);

	clock_gettime(CLOCK_REALTIME, & now);
	fprintf(stderr, "LOG: finished reading from page! %f\n", timespec_diff_sec(start, now) );

	sleep(2);
}