Exemplo n.º 1
0
Arquivo: main.c Projeto: wuwx/simba
int test_preemptive(struct harness_t *harness_p)
{
    struct time_t timeout;
    struct time_t start, stop, duration;

    /* Spawn a low priority worker thread. */
    BTASSERT(thrd_spawn(preemptive_main,
                        NULL,
                        20,
                        preemptive_stack,
                        sizeof(preemptive_stack)) != NULL);

    BTASSERT(time_get(&start) == 0);

    /* Suspend this thread to make sure the worker thread is in its
       infinite loop. When the suspend timeout occurs, this thread
       will be scheduled since it has higher priority than the worker
       thread. */
    timeout.seconds = 0;
    timeout.nanoseconds = 10000000;
    BTASSERT(thrd_suspend(&timeout) == -ETIMEDOUT);

    BTASSERT(time_get(&stop) == 0);
    BTASSERT(time_subtract(&duration, &stop, &start) == 0);

    BTASSERT(duration.seconds == 0);
    BTASSERTI(duration.nanoseconds, >=, 10000000);

    return (0);
}
Exemplo n.º 2
0
/*
 * TimerTimeout:  Called from irc_io to help create the timeout
 * part of the call to select.
 */
Timeval	TimerTimeout (void)
{
	Timeval	forever = {9999, 0};
	Timeval right_away = {0, 0};
	Timeval	current;
	Timeval	timeout_in;

	/* This, however, should never happen. */
	if (!PendingTimers)
		return forever;

	get_time(&current);
	timeout_in = time_subtract(current, PendingTimers->time);
	if (time_diff(right_away, timeout_in) < 0)
		timeout_in = right_away;
	return timeout_in;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  int                ret = 0;
  const float        mclk_freq = 33.0f;
  ADMXRC2_STATUS     status;
  ADMXRC2_CARD_INFO  cardInfo;
  ADMXRC2_SPACE_INFO spInfo;
  ADMXRC2_BANK_INFO  bankInfo, bankInfo2;
  const char*        filename;
  Option             options[8];
  Arguments          arguments;
  float              freq, min_freq, max_freq;
  unsigned long      i;
  uint32_t           sizeReg;
  BOOLEAN            dma;
  BOOLEAN            use64bit;
  BOOLEAN            speed;
  unsigned long      nrep;
  BOOLEAN            failed;

  /* Set up expected options */
  options[0].key = "banks";
  options[0].type = Option_hex;
  options[0].def.hexVal = 0xffffffff;
  options[0].meaning = "bitmask of banks to test";
  options[1].key = "card";
  options[1].type = Option_uint;
  options[1].def.uintVal = 0;
  options[1].meaning = "ID of card to use";
  options[2].key = "index";
  options[2].type = Option_uint;
  options[2].def.uintVal = 0;
  options[2].meaning = "index of card to use";
  options[3].key = "lclk";
  options[3].type = Option_float;
  options[3].def.floatVal = 33.0;
  options[3].meaning = "local bus clock speed (MHz)";
  options[4].key = "repeat";
  options[4].type = Option_uint;
  options[4].def.uintVal = 1;
  options[4].meaning = "number of repetitions";
  options[5].key = "speed";
  options[5].type = Option_boolean;
  options[5].def.booleanVal = TRUE;
  options[5].meaning = "TRUE => measure access speed";
  options[6].key = "usedma";
  options[6].type = Option_boolean;
  options[6].def.booleanVal = TRUE;
  options[6].meaning = "TRUE => use DMA transfers";
  options[7].key = "64";
  options[7].type = Option_boolean;
  options[7].def.booleanVal = FALSE;
  options[7].meaning = "TRUE => use 64-bit local bus";
  arguments.nOption = 8;
  arguments.option = options;
  arguments.nParamType = 0;
  arguments.minNParam = 0;
	
  /* Parse command line */
  parse_command_line("memtest", argc, argv, &arguments);
	
  if (options[1].specified && options[2].specified) {
    printf("*** Do not specify both /card and /index\n");
    ret = -1;
    //goto done;
  }
	
  if (!options[2].specified) {
    ADMXRC2_CARDID cardID = options[1].value.uintVal;
		
    status = ADMXRC2_OpenCard(cardID, &card);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to open card with ID %ld: %s\n",
	     (unsigned long) cardID, ADMXRC2_GetStatusString(status));
      ret = -1;
      //goto done;
    }
  } else {
    unsigned int index = options[2].value.uintVal;
		
    status = ADMXRC2_OpenCardByIndex(index, &card);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to open card with index %ld: %s\n",
	     (unsigned long) index, ADMXRC2_GetStatusString(status));
      ret = -1;
     // goto done;
    }
  }
	
  freq = options[3].value.floatVal;
  nrep = options[4].value.uintVal;
  speed = options[5].value.booleanVal;
  dma = options[6].value.booleanVal;
  use64bit = options[7].value.booleanVal;

  /*
  ** Find out if we're running on a big-endian machine
  */
  bBigEndian = (os_cpu_to_le32(0x1U) != 0x1U);

  /* 
  ** Get card information, specifically for device fitted and
  ** number of SSRAM banks
  */
  status = ADMXRC2_GetCardInfo(card, &cardInfo);
  if (status != ADMXRC2_SUCCESS) {
    printf("*** Failed to get card info: %s\n", ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  switch (cardInfo.BoardType) {
  case ADMXRC2_BOARD_ADMXRC:
  case ADMXRC2_BOARD_ADMXRC_P:
  case ADMXRC2_BOARD_ADMXRC2_LITE:
    min_freq = 25.0;
    max_freq = 40.0;
    break;

  case ADMXRC2_BOARD_ADMXRC2:
  case ADMXRC2_BOARD_ADMXRC4LS:
  case ADMXRC2_BOARD_ADMXRC4LX:
  case ADMXRC2_BOARD_ADMXRC4SX:
    min_freq = 24.0;
    max_freq = 66.0;
    break;

  case ADMXRC2_BOARD_ADMXPL:
    min_freq = 24.0;
    max_freq = 80.0;
    break;

  default:
    printf("*** This example must be run on one of the following cards:\n\n");
    printf("\tADM-XRC\n");
    printf("\tADM-XRC-P\n");
    printf("\tADM-XRCII-Lite\n");
    printf("\tADM-XRCII\n");
    printf("\tADM-XPL\n");
    printf("\tADM-XRC4LX\n");
    printf("\tADM-XRC4SX\n");
    ret = -1;
    //goto done;
  }
	
  if (freq > max_freq || freq < min_freq) {
    printf("*** LCLK frequency of %.1f MHz is not supported\n", freq);
    ret = -1;
   // goto done;
  }
	
  if (use64bit && cardInfo.BoardType != ADMXRC2_BOARD_ADMXPL) {
    printf("*** 64-bit local bus is not supported on the specified card.\n");
    ret = -1;
    //goto done;
  }

  /* Get the address of FPGA space */
  status = ADMXRC2_GetSpaceInfo(card, 0, &spInfo);
  if (status != ADMXRC2_SUCCESS) {
    printf("Failed to get space 0 info: %s\n",
	   ADMXRC2_GetStatusString(status));
    return -1;
  }
  fpgaSpace = (volatile uint32_t*) spInfo.VirtualBase;

  fpgaSpace[6] = os_cpu_to_le32(0);
  fpgaSpace[6];
  fpgaSpace[7] = os_cpu_to_le32(0);
  fpgaSpace[7];




 
	
  if (!options[0].specified) {
    bankTestMask = cardInfo.RAMBanksFitted;
  } else {
    bankTestMask = options[0].value.hexVal & cardInfo.RAMBanksFitted;
  }

  /*
  ** Check that the type, size, width etc. of each SSRAM bank
  ** is the same.
  */
  numBank = 0;
  testSize = 0;
  for (i = 0; i < cardInfo.NumRAMBank; i++) {
    status = ADMXRC2_GetBankInfo(card, i, &bankInfo2);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to get bank %ld info: %s\n",
	     (unsigned long) i,
	     ADMXRC2_GetStatusString(status));
      return -1;
    }

    if (!(bankInfo2.Type & (ADMXRC2_RAM_ZBTP | ADMXRC2_RAM_ZBTFT))) {
      /* Ignore any banks that are not ZBT SSRAM */
      continue;
    }

    if (!bankInfo2.Fitted) {
      printf("*** Not all SSRAM banks are fitted - aborting.\n");
      ret = -1;
      //goto done;
    }

    if (cardInfo.BoardType == ADMXRC2_BOARD_ADMXPL && !use64bit) {
      /*
      ** ADM-XPL ZBT bank width is 64 bits but the 32-bit version of design
      ** uses only the lower 32 bits of the ZBT bank.
      */
      bankInfo2.Width = 32;
    }

    if (!numBank) {
      memcpy(&bankInfo, &bankInfo2, sizeof(bankInfo));
      bankSize = (bankInfo.Width / 8) * bankInfo.Size;
    } else {
      if (bankInfo2.Type != bankInfo.Type ||
	  bankInfo2.Width != bankInfo.Width ||
	  bankInfo2.Size != bankInfo.Size) {
	printf("*** Not all SSRAM banks are the same - aborting.\n");
	ret = -1;
	//goto done;
      }
    }

    numBank++;

    if (bankTestMask & (0x1UL << i)) {
      testSize += (bankInfo.Width / 8) * bankInfo.Size;
    }
  }
	
  if (!numBank) {
    printf("*** No SSRAM banks found - aborting.\n");
    ret = -1;
    //goto done;
  }

  /*
  ** Calculate memory size in bytes
  */
  memorySize = numBank * bankSize;
  lastPageSize = memorySize & (pageSize - 1);

  /*
  ** Determine value to program into the SIZE register in the FPGA
  */
  switch (bankInfo.Size) {
  case 128*1024:
    sizeReg = 0;
    break;
  case 256*1024:
    sizeReg = 1;
    break;
  case 512*1024:
    sizeReg = 2;
    break;
  case 1024*1024:
    sizeReg = 3;
    break;
  case 2048*1024:
    sizeReg = 4;
    break;
  default:
    printf("*** SSRAM of %ld words x %ld is not supported by this application\n",
	   (unsigned long) bankInfo.Size, (unsigned long) bankInfo.Width);
    ret = -1;
    //goto done;
  }
	
  ssram = (volatile uint32_t*) (((uint8_t*) fpgaSpace) + ssramOffset);
	
  rambuf = (uint8_t*) ADMXRC2_Malloc(memorySize);
  if (rambuf == NULL) {
    printf("*** Failed to allocate RAM buffer - aborting\n");
    ret = -1;
    //goto done;
  }
  rambuf32 = (uint32_t*) rambuf;

  chkbuf = (uint8_t*) ADMXRC2_Malloc(memorySize);
  if (chkbuf == NULL) {
    printf("*** Failed to allocate RAM readback buffer - aborting\n");
    ret = -1;
    ///goto done;
  }
  chkbuf32 = (uint32_t*) chkbuf;

  status = ADMXRC2_SetClockRate(card, ADMXRC2_CLOCK_LCLK, freq * 1.0e6, NULL);
  if (status != ADMXRC2_SUCCESS) {
    printf("*** Failed to set LCLK to %.1fMHz: %s\n",
	   freq, ADMXRC2_GetStatusString(status));
    ret = -1;
    //goto done;
  }
	
  if (cardInfo.BoardType != ADMXRC2_BOARD_ADMXPL) {
    status = ADMXRC2_SetClockRate(card, 1, mclk_freq * 1.0e6, NULL);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to set clock 1 to %.1fMHz: %s\n",
	     mclk_freq, ADMXRC2_GetStatusString(status));
      return -1;
    }
  }

  filename="/var/www/html/VirtualLabs/experiments/exp_4/bitfiles/user_configuration.bit";
  status = ADMXRC2_ConfigureFromFile(card, filename);
  if (status != ADMXRC2_SUCCESS) {
    printf ("*** Failed to load the bitstream '%s': %s\n",
	    filename, ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  if (use64bit) {
    uint32_t config;
    
    config = ADMXRC2_SPACE_SET_WIDTH | ADMXRC2_SPACE_WIDTH_64;
    status = ADMXRC2_SetSpaceConfig(card, 0, config);
    if (status != ADMXRC2_SUCCESS) {
      printf ("*** Failed to set space configuration: %s\n",
	      ADMXRC2_GetStatusString(status));
      return -1;
    }
  }
  
  status = ADMXRC2_SetupDMA(card,
			    rambuf,
			    memorySize,
			    0,
			    &dmaDesc1);
  if (status != ADMXRC2_SUCCESS) {
    printf ("*** Failed to get a DMA descriptor: %s\n",
	    ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  status = ADMXRC2_SetupDMA(card,
			    chkbuf,
			    memorySize,
			    0,
			    &dmaDesc2);
  if (status != ADMXRC2_SUCCESS) {
    printf ("*** Failed to get a DMA descriptor: %s\n",
	    ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  dmaMode = ADMXRC2_BuildDMAModeWord(cardInfo.BoardType,
				     use64bit ? ADMXRC2_IOWIDTH_64 : ADMXRC2_IOWIDTH_32,
				     0,
				     ADMXRC2_DMAMODE_USEREADY | ADMXRC2_DMAMODE_USEBTERM | ADMXRC2_DMAMODE_BURSTENABLE);
	
  /* Wait for DLLs/DCMs to lock */
  sleep(1);

  /*
  ** Program the number of address bits used by the SSRAMs
  */
  fpgaSpace[ZBT_SIZE_REG] = os_cpu_to_le32(sizeReg);
  fpgaSpace[ZBT_SIZE_REG]; /* make sure it's got there */

  printf("Size reg   = 0x%8.8lx\n", (unsigned long) os_le32_to_cpu(fpgaSpace[ZBT_SIZE_REG]));
  printf("Info reg   = 0x%8.8lx\n", (unsigned long) os_le32_to_cpu(fpgaSpace[ZBT_INFO_REG]));
  printf("Status reg = 0x%8.8lx\n", (unsigned long) os_le32_to_cpu(fpgaSpace[ZBT_STATUS_REG]));
	
  failed = FALSE;
	
 // printf("Performing memory tests using %s\n",
//	 dma ? "DMA" : "programmed I/O");
	
  /* Iterate over flowthrough and pipelined */
  for (i = 0; i < 2; i++) {
    int           nError = 0;
    unsigned long j, k;
    uint32_t      exp, act;
    unsigned long rep;
		
    if (i == 0) {
      if (!(bankInfo.Type & ADMXRC2_RAM_ZBTFT)) {
	continue;
      }
			
      /*
      ** Set the FPGA to flowthrough mode
      */
      fpgaSpace[ZBT_PIPELINE_REG] = os_cpu_to_le32(0x0);
      fpgaSpace[ZBT_PIPELINE_REG]; /* make sure it's got there */
    //  printf("Testing %ld kB in flowthrough mode...\n", testSize / 1024);
    } else {
      if (!(bankInfo.Type & ADMXRC2_RAM_ZBTP)) {
	continue;
      }
			
      /*
      ** Set the FPGA to pipelined mode
      */
      fpgaSpace[ZBT_PIPELINE_REG] = os_cpu_to_le32(0x1);
      fpgaSpace[ZBT_PIPELINE_REG]; /* make sure it's got there */
      printf("Testing %ld kB in pipelined mode...\n", testSize / 1024);
    }
		

}


//////////////////////////////////////////////////////////////////////////////////////////////////////////



	  FILE *fptr;
	  char filen[30];
	  char initial[16];
	  char temp[16];
	argc --;
	if(argc > 0)
	strcpy(filen,*(argv+1));
	else 
	{
	printf(" Image file name not specified \n");
	exit(1);
	}
	
   if(!(fptr = fopen(filen,"r")))
	{
	printf(" Image file does not exist specify some other existing image file  \n");
	exit(1);
	}

    
   int row=0,col=0,count =0,j;
   int header =0;
   char ch;
    while( count!=3)
          {   
              count ++;
              ch=fgetc(fptr);
              initial[header]=ch;
              header++;
              
          } 
    ch=fgetc(fptr);
    initial[header]=ch;

    header++;
    while(ch!=32)
        { 
           col= col*10+ (ch-48) ;
           ch = fgetc(fptr); 
           initial[header]=ch;
          header++;
        }  

    ch= fgetc(fptr);
    initial[header]=ch;

    header++;
    while(ch!=10)
         { 
           row = row*10 + (ch-48);
           ch= fgetc(fptr);
           initial[header]=ch;

           header++; 
         }
    count =0; 
    while( count!=4)
          {
              count ++;
              ch=fgetc(fptr);
              initial[header]=ch;

              header++;
          } 
   initial[header]='\0';
//   printf( "\n  row === %d",row);
 //  printf( "\n  col === %d",col);
   strcpy(temp,initial);
 //  printf( "\n header len  === %d",header);
//  printf( "\n Header   === %s======%s",initial,temp);

 int matrix[row][col];

 for(i=0;i< row;i++)
       {
           for( j= 0;j< col;j++)
                matrix[i][j]=fgetc(fptr);
       }

 fclose(fptr); 

int output[row][col];
int m,n;
count = 0;

for(m=0;m<row;m++)
  {for(n=0;n<col;n++)
      { output[m][n]=0;
	rambuf[count] = matrix[m][n];
	count++;}
  }

count = 0;

for(j=0;j<2;j++)
	{
	status = writeSSRAM(rambuf + j * bankSize, j * bankSize, bankSize, dma);
	if (status != ADMXRC2_SUCCESS) {
	printf("Error: failed to write SSRAM\n");
	failed = TRUE;
	}
	}

fpgaSpace[6] = os_cpu_to_le32(1);
fpgaSpace[6];

while(fpgaSpace[7]!=os_cpu_to_le32(0x31));

fpgaSpace[6] = os_cpu_to_le32(0);
fpgaSpace[6];
sleep(10);

        
if (!failed) {
	  for (j = 0; j < 2; j++) {
	    if (!(bankTestMask & (1U << j))) {
	      continue;
	    }
						
	    status = readSSRAM(chkbuf + j * bankSize, j * bankSize, bankSize, dma);
	    if (status != ADMXRC2_SUCCESS) {
	      printf("Error: failed to read SSRAM\n");
	      failed = TRUE;
	      break;
	    }
	  }
	}
count = 0;
for(m=0;m<row;m++)
  {for(n=0;n<col;n++)
      { output[m][n]=chkbuf[count];
	count++;}
  }

//=========================================== new IMAGE FILE BUILD============================

  char newFile[] = "Converted_Imag";
  char *newfile= strncat(newFile,".pgm",4);
 
   fptr = fopen(newfile,"w");
   count=0;
  // strcpy(initial,temp);
   printf("\n %s..... %s\n",initial,temp);
   while(count!=15)
         {
            fputc(initial[count],fptr);
            count++;
         }
      for(i=0;i< row;i++)
       {
           for( j= 0;j< col;j++)
              fputc(output[i][j],fptr);
       }
   fclose(fptr); 




////////////////////////////////////////////////////////////////////////////////////////////////////////////


  if (speed) {
    /*
    ** Measure the host read and host write speeds of the SSRAM,
    ** using DMA.
    */
    float          bytes, rate;
    double         delta;
    struct timeval start, now, elapsed;
		
    printf("Measuring access speed...\n");
		
    start = get_time();
    bytes = 0.0f;
    do {
      readSSRAM(rambuf, 0, memorySize, dma);
      bytes += (float) memorySize;
      now = get_time();
      elapsed = time_subtract(&now, &start);
      delta = time_to_double(&elapsed);
    } while (delta < 2.0);
		
    rate = bytes / delta;
    printf("SSRAM to host throughput = %.1fMB/s\n", rate / 1048576.0f);
		
    start = get_time();
    bytes = 0.0f;
    do {
      writeSSRAM(rambuf, 0, memorySize, dma);
      bytes += (float) memorySize;
      now = get_time();
      elapsed = time_subtract(&now, &start);
      delta = time_to_double(&elapsed);
    } while (delta < 2.0);
		
    rate = bytes / delta;
    printf("Host to SSRAM throughput = %.1fMB/s\n", rate / 1048576.0f);
  }


 ADMXRC2_Free (rambuf);
  ADMXRC2_Free (chkbuf);
  ADMXRC2_CloseCard (card);
  exit(0);


  return 0;

}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
  int                ret = 0;
  const float        mclk_freq = 33.0f;
  ADMXRC2_STATUS     status;
  ADMXRC2_CARD_INFO  cardInfo;
  ADMXRC2_SPACE_INFO spInfo;
  ADMXRC2_BANK_INFO  bankInfo, bankInfo2;
  const char*        filename;
  Option             options[8];
  Arguments          arguments;
  float              freq, min_freq, max_freq;
  unsigned long      i;
  uint32_t           sizeReg;
  BOOLEAN            dma;
  BOOLEAN            use64bit;
  BOOLEAN            speed;
  unsigned long      nrep;
  BOOLEAN            failed;

  /* Set up expected options */
  options[0].key = "banks";
  options[0].type = Option_hex;
  options[0].def.hexVal = 0xffffffff;
  options[0].meaning = "bitmask of banks to test";
  options[1].key = "card";
  options[1].type = Option_uint;
  options[1].def.uintVal = 0;
  options[1].meaning = "ID of card to use";
  options[2].key = "index";
  options[2].type = Option_uint;
  options[2].def.uintVal = 0;
  options[2].meaning = "index of card to use";
  options[3].key = "lclk";
  options[3].type = Option_float;
  options[3].def.floatVal = 33.0;
  options[3].meaning = "local bus clock speed (MHz)";
  options[4].key = "repeat";
  options[4].type = Option_uint;
  options[4].def.uintVal = 1;
  options[4].meaning = "number of repetitions";
  options[5].key = "speed";
  options[5].type = Option_boolean;
  options[5].def.booleanVal = TRUE;
  options[5].meaning = "TRUE => measure access speed";
  options[6].key = "usedma";
  options[6].type = Option_boolean;
  options[6].def.booleanVal = TRUE;
  options[6].meaning = "TRUE => use 64 bit local bus";
  options[7].key = "64";
  options[7].type = Option_boolean;
  options[7].def.booleanVal = FALSE;
  options[7].meaning = "TRUE => use DMA for test";printf("Writing 0xAAAAAAAA...\n");
  arguments.nOption = 8;
  arguments.option = options;
  arguments.nParamType = 0;
  arguments.minNParam = 0;
	
  /* Parse command line */
  parse_command_line("memtest", argc, argv, &arguments);
	
 	

		
    status = ADMXRC2_OpenCardByIndex(index, &card);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to open card with index %ld: %s\n",
	     (unsigned long) index, ADMXRC2_GetStatusString(status));
      ret = -1;
      goto done;
    }
  
	
  freq = options[3].value.floatVal;
  nrep = options[4].value.uintVal;
  speed = options[5].value.booleanVal;
  dma = options[6].value.booleanVal;
  use64bit = options[7].value.booleanVal;

  /* 
  ** Get card information, specifically for device fitted and
  ** number of SSRAM banks
  */
  status = ADMXRC2_GetCardInfo(card, &cardInfo);
  if (status != ADMXRC2_SUCCESS) {
    printf("*** Failed to get card info: %s\n", ADMXRC2_GetStatusString(status));
    return -1;
  }

  /* Get the address of FPGA space */
  status = ADMXRC2_GetSpaceInfo(card, 0, &spInfo);
  if (status != ADMXRC2_SUCCESS) {
    printf("Failed to get space 0 info: %s\n",
	   ADMXRC2_GetStatusString(status));
    return -1;
  }
  fpgaSpace = (volatile uint32_t*) spInfo.VirtualBase;
	
  if (!options[0].specified) {
    bankTestMask = cardInfo.RAMBanksFitted;
  } else {
    bankTestMask = options[0].value.hexVal & cardInfo.RAMBanksFitted;
  }

  /*
  ** Check that the type, size, width etc. of each SSRAM bank
  ** is the same.
  */
  numBank = 0;
  testSize = 0;
  for (i = 0; i < cardInfo.NumRAMBank; i++) {
    status = ADMXRC2_GetBankInfo(card, i, &bankInfo2);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to get bank %ld info: %s\n",
	     (unsigned long) i,
	     ADMXRC2_GetStatusString(status));
      return -1;
    }

    if (!(bankInfo2.Type & (ADMXRC2_RAM_ZBTP | ADMXRC2_RAM_ZBTFT))) {
      /* Ignore any banks that are not ZBT SSRAM */
      continue;
    }

    if (!bankInfo2.Fitted) {
      printf("*** Not all SSRAM banks are fitted - aborting.\n");
      ret = -1;
      goto done;
    }

    if (!numBank) {
      memcpy(&bankInfo, &bankInfo2, sizeof(bankInfo));
      bankSize = (bankInfo.Width / 8) * bankInfo.Size / 4;
    } else {
      if (bankInfo2.Type != bankInfo.Type ||
	  bankInfo2.Width != bankInfo.Width ||
	  bankInfo2.Size != bankInfo.Size) {
	printf("*** Not all SSRAM banks are the same - aborting.\n");
	ret = -1;
	goto done;
      }
    }

    numBank++;

    if (bankTestMask & (0x1UL << i)) {
      testSize += (bankInfo.Width / 8) * bankInfo.Size / 4;
    }
  }
	
  if (!numBank) {
    printf("*** No SSRAM banks found - aborting.\n");
    ret = -1;
    goto done;
  }

  /*
  ** Calculate memory size in longwords (32-bit words)
  */
  memorySize = numBank * bankSize;
  lastPageSize = memorySize & (pageSize - 1);

  /*
  ** Determine value to program into the SIZE register in the FPGA
  */
  switch (bankInfo.Size) {
  case 128*1024:
    sizeReg = 0;
    break;
  case 256*1024:
    sizeReg = 1;
    break;
  case 512*1024:
    sizeReg = 2;
    break;
  case 1024*1024:
    sizeReg = 3;
    break;
  default:
    printf("*** SSRAM of %ld words x %ld is not supported by this application\n",
	   (unsigned long) bankInfo.Size, (unsigned long) bankInfo.Width);
    ret = -1;
    goto done;
  }
	
  ssram = (volatile uint32_t*) (((uint8_t*) fpgaSpace) + ssramOffset);
	
  rambuf = (uint32_t*) ADMXRC2_Malloc(memorySize * sizeof(uint32_t));
  if (rambuf == NULL) {
    printf("*** Failed to allocate RAM buffer - aborting\n");
    ret = -1;
    goto done;
  }
  
  chkbuf = (uint32_t*) ADMXRC2_Malloc(memorySize * sizeof(uint32_t));
  if (chkbuf == NULL) {
    printf("*** Failed to allocate RAM readback buffer - aborting\n");
    ret = -1;
    goto done;
  }
	
  status = ADMXRC2_SetClockRate(card, ADMXRC2_CLOCK_LCLK, freq * 1.0e6, NULL);
  if (status != ADMXRC2_SUCCESS) {
    printf("*** Failed to set LCLK to %.1fMHz: %s\n",
	   freq, ADMXRC2_GetStatusString(status));
    ret = -1;
    goto done;
  }
	
  if (cardInfo.BoardType != ADMXRC2_BOARD_ADMXRC2_PRO_LITE) {
    status = ADMXRC2_SetClockRate(card, 1, mclk_freq * 1.0e6, NULL);
    if (status != ADMXRC2_SUCCESS) {
      printf("*** Failed to set clock 1 to %.1fMHz: %s\n",
	     mclk_freq, ADMXRC2_GetStatusString(status));
      return -1;
    }
  }
	
  if (use64bit) {
    uint32_t config;
    
    config = ADMXRC2_SPACE_SET_WIDTH | ADMXRC2_SPACE_WIDTH_64;
    status = ADMXRC2_SetSpaceConfig(card, 0, config);
    if (status != ADMXRC2_SUCCESS) {
      printf ("*** Failed to set space configuration: %s\n",
	      ADMXRC2_GetStatusString(status));
      return -1;
    }
  }
  
  status = ADMXRC2_SetupDMA(card,
			    rambuf,
			    memorySize * sizeof(uint32_t),
			    0,
			    &dmaDesc1);
  if (status != ADMXRC2_SUCCESS) {
    printf ("*** Failed to get a DMA descriptor: %s\n",
	    ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  status = ADMXRC2_SetupDMA(card,
			    chkbuf,
			    memorySize * sizeof(uint32_t),
			    0,
			    &dmaDesc2);
  if (status != ADMXRC2_SUCCESS) {
    printf ("*** Failed to get a DMA descriptor: %s\n",
	    ADMXRC2_GetStatusString(status));
    return -1;
  }
	
  dmaMode = ADMXRC2_BuildDMAModeWord(cardInfo.BoardType,
				     use64bit ? ADMXRC2_IOWIDTH_64 : ADMXRC2_IOWIDTH_32,
				     0,
				     ADMXRC2_DMAMODE_USEREADY | ADMXRC2_DMAMODE_USEBTERM | ADMXRC2_DMAMODE_BURSTENABLE);
	
  /* Wait for DLLs/DCMs to lock */
  sleep(1);

  /*
  ** Program the number of address bits used by the SSRAMs
  */
  fpgaSpace[ZBT_SIZE_REG] = sizeReg;
  fpgaSpace[ZBT_SIZE_REG]; /* make sure it's got there */

  printf("Size reg   = 0x%8.8lx\n", (unsigned long) fpgaSpace[ZBT_SIZE_REG]);
  printf("Info reg   = 0x%8.8lx\n", (unsigned long) fpgaSpace[ZBT_INFO_REG]);
  printf("Status reg = 0x%8.8lx\n", (unsigned long) fpgaSpace[ZBT_STATUS_REG]);
	
  failed = FALSE;

  /* Iterate over flowthrough and pipelined */
  for (i = 0; i < 2; i++) {
    int           nError = 0;
    unsigned long j, k;
//char m= 'a';
    uint32_t      exp, act;
    unsigned long rep;
		
    if (i == 0) {
      if (!(bankInfo.Type & ADMXRC2_RAM_ZBTFT)) {
	continue;
      }
			
      /*
      ** Set the FPGA to flowthrough mode
      */
      fpgaSpace[ZBT_PIPELINE_REG] = 0x0;
      fpgaSpace[ZBT_PIPELINE_REG]; /* make sure it's got there */
      printf("Testing %ld kB in flowthrough mode...\n", testSize * 4 / 1024);
    } else {
      if (!(bankInfo.Type & ADMXRC2_RAM_ZBTP)) {
	continue;
      }
			
      /*
      ** Set the FPGA to pipelined mode
      */
      fpgaSpace[ZBT_PIPELINE_REG] = 0x1;
      fpgaSpace[ZBT_PIPELINE_REG]; /* make sure it's got there */
      printf("Testing %ld kB in pipelined mode...\n", testSize * 4 / 1024);
    }
		
    for (rep = 0; rep < nrep; rep++) {
			
      printf("Repetition %ld\n", rep);
			
///////////////////////////////////////////STARTING//////////////////////////////////////

      
      /* Perform 0xAAAAAAA test - look for shorted/stuck data pins */
      if (!failed && nError == 0) {
	
	rambuf_8 = rambuf;

	for (j = 0; j < 50; j++) {
	  rambuf_8[j+12*bankSize] = j;
	}

	for (j = 0; j < 50; j++) {
	  rambuf[j+4*bankSize] = 0;
	}


			
	  status = writeSSRAM(rambuf, 3 * bankSize, bankSize, dma);
	  if (status != ADMXRC2_SUCCESS) {
	    printf("Error: failed to write SSRAM\n");
	    failed = TRUE;
	}
	status = writeSSRAM(rambuf, 4 * bankSize, bankSize, dma);
	  if (status != ADMXRC2_SUCCESS) {
	    printf("Error: failed to write SSRAM\n");
	    failed = TRUE;
	}
		

	fpgaSpace[6] = os_cpu_to_le32(1);
	fpgaSpace[6];

	while(fpgaSpace[7]!=os_cpu_to_le32(0x31));

	fpgaSpace[6] = os_cpu_to_le32(0);
	fpgaSpace[6];


		
	}

for (j = 0; j < numBank; j++) {
for (k = 0; k < bankSize; k++) {
unsigned long idx = j * bankSize + k;
chkbuf[idx] = 0;
}
}


	    status = readSSRAM(chkbuf, 4 * bankSize, bankSize, dma);
	    if (status != ADMXRC2_SUCCESS) {
	      printf("Error: failed to read SSRAM\n");
	      failed = TRUE;
	  }

	    status = readSSRAM(chkbuf, 3 * bankSize, bankSize, dma);
	    if (status != ADMXRC2_SUCCESS) {
	      printf("Error: failed to read SSRAM\n");
	      failed = TRUE;
	  }
			
     for (j = 0;j < 50;j++){
		printf("\n%02d     %08X     %08X   ", j,chkbuf[j+3*bankSize],chkbuf[4*bankSize+j]);

	
	}
			
      if (!failed && nError == 0) {
	printf("PASSED\n");
      } else {
	printf("*** FAILED with %ld error(s)\n", (long) nError);
	break;
      }
    }
		
    if (failed) {
      break;
    }
  }
	
  if (speed) {
    /*
    ** Measure the host read and host write speeds of the SSRAM,
    ** using DMA.
    */
    float          bytes, rate;
    double         delta;
    struct timeval start, now, elapsed;
		
    printf("Measuring access speed...\n");
		
    start = get_time();
    bytes = 0.0f;
    do {
      readSSRAM(rambuf, 0, memorySize, dma);
      bytes += (float) (memorySize * sizeof(uint32_t));
      now = get_time();
      elapsed = time_subtract(&now, &start);
      delta = time_to_double(&elapsed);
    } while (delta < 2.0);
		
    rate = bytes / delta;
    printf("SSRAM to host throughput = %.1fMB/s\n", rate / 1048576.0f);
		
    start = get_time();
    bytes = 0.0f;
    do {
      writeSSRAM(rambuf, 0, memorySize, dma);
      bytes += (float) (memorySize * sizeof(uint32_t));
      now = get_time();
      elapsed = time_subtract(&now, &start);
      delta = time_to_double(&elapsed);
    } while (delta < 2.0);
		
    rate = bytes / delta;
    printf("Host to SSRAM throughput = %.1fMB/s\n", rate / 1048576.0f);
  }
	
 done:
  if (rambuf != NULL) {
    ADMXRC2_Free(rambuf);
  }

  if (chkbuf != NULL) {
    ADMXRC2_Free(chkbuf);
  }

  if (dmaDesc1Valid) {
    ADMXRC2_UnsetupDMA(card, dmaDesc1);
  }

  if (dmaDesc2Valid) {
    ADMXRC2_UnsetupDMA(card, dmaDesc2);
  }

  if (card != ADMXRC2_HANDLE_INVALID_VALUE) {
    ADMXRC2_CloseCard(card);
  }
	
  return ret;
}
Exemplo n.º 5
0
socket_fd TCServerSocketConnect(const socket_address* connectAddress, socket_address_length addressLength, time_delta* initialRTT)
{
    // Attempt to create a UDP socket
    socket_fd newSocket = socket(connectAddress->sa_family, SOCK_DGRAM, 0);
    if (newSocket < 0)
    {
        perror("ERROR: socket creation failed in TCServerSocketConnect()");
        return -1;
    }

    // Make note of the time, for the initial RTT calculation
    time_of_day timeSYNACK;
    if (gettimeofday(&timeSYNACK, NULL) != 0)
    {
        perror("ERROR: cannot get time of SYNACK in TCServerSocketConnect()");
        return -1;
    }

    // Send a reply to the client host's connection request (automatically binds local socket)
    ssize_t bytesWritten = sendto(newSocket, TC_HANDSHAKE_SYNACK_MSG, strlen(TC_HANDSHAKE_SYNACK_MSG), 0, connectAddress, addressLength);
    if (bytesWritten < 0)
    {
        perror("ERROR: sendto failed in TCServerSocketConnect()");
        return -1;
    }
    if (bytesWritten < (ssize_t)strlen(TC_HANDSHAKE_SYNACK_MSG))
    {
        fprintf(stderr, "ERROR: unable to send full SYNACK message in TCServerSocketConnect()\n");
        return -1;
    }

    // Create a read-file-descriptor-set for select()ing on the socket
    fd_set readFDs;
    FD_ZERO(&readFDs);

    // Add the socket to the set
    FD_SET(newSocket, &readFDs);

    // Select on the socket, waiting for the client to ACK the connection
    time_delta timeout = TC_HANDSHAKE_TIMEOUT;
    switch (select(newSocket + 1, &readFDs, NULL, NULL, &timeout))
    {
    case -1:
        perror("ERROR: select failed in TCServerSocketConnect()");
        return -1;

    case 0:
        fprintf(stderr, "ERROR: timed out waiting for ACK in TCServerSocketConnect()\n");
        return -1;

    default:
        if (FD_ISSET(newSocket, &readFDs) != 0)
        {
            // Read the client's message
            char readBuffer[TC_HANDSHAKE_BUFFER_SIZE + 1];
            ssize_t bytesRead = recv(newSocket, readBuffer, TC_HANDSHAKE_BUFFER_SIZE, 0);
            if (bytesRead < 0)
            {
                perror("ERROR: recv failed in TCServerSocketConnect()");
                return -1;
            }

            // Note the time
            time_of_day timeACK;
            if (gettimeofday(&timeACK, NULL) != 0)
            {
                perror("ERROR: cannot get time of ACK in TCServerSocketConnect()");
                return -1;
            }

            // NULL-terminate the message
            readBuffer[bytesRead] = 0;

            // Check that the message is an ACK
            if (strncmp(readBuffer, TC_HANDSHAKE_ACK_MSG, TC_HANDSHAKE_BUFFER_SIZE) != 0)
            {
                // Not an ACK; connection failed
                fprintf(stderr, "ERROR: non-ACK response to handshake in TCServerSocketConnect()\n");
                return -1;
            }

            // connect() the socket, so that we don't have to call sendto() in future
            if (connect(newSocket, connectAddress, addressLength) != 0)
            {
                perror("ERROR: could not connect socket in TCServerSocketConnect()");
                return -1;
            }

            // Calculate the round-trip-time
            time_subtract(initialRTT, &timeACK, &timeSYNACK);
        }
        else
        {
            // Should never happen...
            fprintf(stderr, "ERROR: client socket file descriptor not ready for reading after successful select() operation in TCServerSocketConnect()\n");
            return -1;
        }
        break;
    }

    // Return the connected socket
    return newSocket;
}
Exemplo n.º 6
0
// Return the amount of time to wait between sched_run_callbacks() calls
static struct timeval fuse_serve_timeout(void)
{
	struct timeval tv = { .tv_sec = 0, .tv_usec = 1000000/HZ };
	return tv;
}

struct callback_list {
	unlock_callback_t callback;
	void * data;
	int count;
	struct callback_list * next;
};
static struct callback_list * callbacks;

int fstitchd_unlock_callback(unlock_callback_t callback, void * data)
{
	if(callbacks && callbacks->callback == callback && callbacks->data == data)
		callbacks->count++;
	else
	{
		struct callback_list * list = malloc(sizeof(*list));
		if(!list)
			return -ENOMEM;
		list->callback = callback;
		list->data = data;
		list->count = 1;
		list->next = callbacks;
		callbacks = list;
	}
	return 0;
}

// Adapted from FUSE's lib/fuse_loop.c to support sched callbacks and multiple mounts
int fuse_serve_loop(void)
{
	struct timeval tv;
	mount_t ** mp;
	int r;
	Dprintf("%s()\n", __FUNCTION__);

	if (!root_cfs)
	{
		fprintf(stderr, "%s(): no root cfs was specified; not running.\n", __FUNCTION__);
		return -1;
	}

	if ((r = fuse_serve_mount_load_mounts()) < 0)
	{
		fprintf(stderr, "%s(): fuse_serve_load_mounts: %d\n", __FUNCTION__, r);
		return r;
	}

	serving = 1;
	tv = fuse_serve_timeout();

	while ((mp = fuse_serve_mounts()) && mp && mp[0])
	{
		fd_set rfds;
		int max_fd = 0;
		struct timeval it_start, it_end;

		FD_ZERO(&rfds);

		if (shutdown_pipe[0] != -1)
		{
			FD_SET(shutdown_pipe[0], &rfds);
			if (shutdown_pipe[0] > max_fd)
				max_fd = shutdown_pipe[0];
		}

		FD_SET(remove_activity, &rfds);
		if (remove_activity > max_fd)
			max_fd = remove_activity;

		for (mp = fuse_serve_mounts(); mp && *mp; mp++)
		{
			if ((*mp)->mounted && !fuse_session_exited((*mp)->session))
			{
				//printf("[\"%s\"]", mount->fstitch_path); fflush(stdout); // debug
				int mount_fd = fuse_chan_fd((*mp)->channel);
				FD_SET(mount_fd, &rfds);
				if (mount_fd > max_fd)
					max_fd = mount_fd;
			}
		}

		r = select(max_fd+1, &rfds, NULL, NULL, &tv);

		if (r == 0)
		{
			//printf("."); fflush(stdout); // debugging output
			sched_run_callbacks();
			tv = fuse_serve_timeout();
		}
		else if (r < 0)
		{
			if (errno != EINTR)
				perror("select");
			//printf("!\n"); fflush(stdout); // debugging output
			tv = fuse_serve_timeout(); // tv may have become undefined
		}
		else
		{
			if (gettimeofday(&it_start, NULL) == -1)
			{
				perror("gettimeofday");
				break;
			}

			for (mp = fuse_serve_mounts(); mp && *mp; mp++)
			{
				if ((*mp)->mounted && FD_ISSET((*mp)->channel_fd, &rfds))
				{
					r = fuse_chan_receive((*mp)->channel, channel_buf, channel_buf_len);
					if(r <= 0)
						fprintf(stderr, "fuse_chan_receive() returned %d, ignoring!\n", r);
					//assert(r > 0); // this happens during shutdown on MacFUSE...

					Dprintf("fuse_serve: request for mount \"%s\"\n", (*mp)->fstitch_path);
					fuse_session_process((*mp)->session, channel_buf, r, (*mp)->channel);
					sched_run_cleanup();
				}
			}

			if (shutdown_pipe[0] != -1 && FD_ISSET(shutdown_pipe[0], &rfds))
			{
				// Start unmounting all filesystems
				// Looping will stop once all filesystems are unmounted
				ignore_shutdown_signals();
				if (fuse_serve_mount_start_shutdown() < 0)
				{
					fprintf(stderr, "fuse_serve_mount_start_shutdown() failed, exiting fuse_serve_loop()\n");
					return -1;
				}
			}

			if (FD_ISSET(remove_activity, &rfds))
			{
				if (fuse_serve_mount_step_remove() < 0)
				{
					fprintf(stderr, "fuse_serve_mount_step_remove() failed, exiting fuse_serve_loop()\n");
					return -1;
				}
			}


			if (gettimeofday(&it_end, NULL) == -1)
			{
				perror("gettimeofday");
				break;
			}
			tv = time_subtract(tv, time_elapsed(it_start, it_end));
		}

		while(callbacks)
		{
			struct callback_list * first = callbacks;
			callbacks = first->next;
			first->callback(first->data, first->count);
			free(first);
		}
	}

	serving = 0;

	return 0;
}