コード例 #1
0
ファイル: nandsim_manual.c プロジェクト: jameyhicks/connectal
int main(int argc, const char **argv)
{
  int srcAlloc;
  int nandAlloc;
  unsigned int *srcBuffer;
  unsigned int ref_srcAlloc;
  unsigned int ref_nandAlloc;
  int rc = 0, i;
  pthread_t tid = 0;

  init_portal_internal(&intarr[0], IfcNames_DmaIndication, DmaIndication_handleMessage, NULL, NULL, DmaIndication_reqinfo);     // fpga1
  init_portal_internal(&intarr[1], IfcNames_NandSimIndication, NandSimIndication_handleMessage, NULL, NULL, NandSimIndication_reqinfo); // fpga2
  init_portal_internal(&intarr[2], IfcNames_DmaConfig, NULL, NULL, NULL, DmaConfig_reqinfo);         // fpga3
  init_portal_internal(&intarr[3], IfcNames_NandSimRequest, NULL, NULL, NULL, NandSimRequest_reqinfo);    // fpga4

  sem_init(&test_sem, 0, 0);
  DmaManager_init(&priv, &intarr[2]);
  srcAlloc = portalAlloc(alloc_sz, 0);
  if (rc){
    PORTAL_PRINTF("portal alloc failed rc=%d\n", rc);
    return rc;
  }

  PORTAL_PRINTF( "Main: creating exec thread\n");
  if(pthread_create(&tid, NULL, pthread_worker, NULL)){
   PORTAL_PRINTF( "error creating exec thread\n");
   return -1;
  }
  srcBuffer = (unsigned int *)portalMmap(srcAlloc, alloc_sz);

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

  PORTAL_PRINTF("Test 1: check for operations\n");
  portalCacheFlush(srcAlloc, srcBuffer, alloc_sz, 1);
  PORTAL_PRINTF("Main: before DmaManager_reference(%u)\n", srcAlloc);
  ref_srcAlloc = DmaManager_reference(&priv, srcAlloc);


  nandAlloc = portalAlloc (nandBytes, 0);
  ref_nandAlloc = DmaManager_reference(&priv, nandAlloc);
  PORTAL_PRINTF("Main::configure NAND fd=%d ref=%d\n", nandAlloc, ref_nandAlloc);
  NandSimRequest_configureNand (&intarr[3], ref_nandAlloc, nandBytes);
  sem_wait(&test_sem);


  PORTAL_PRINTF( "Main::starting write - begin %08zx\n", numBytes);
  NandSimRequest_startWrite (&intarr[3], ref_srcAlloc, 0, 0, numBytes, 16);
  PORTAL_PRINTF( "Main:: wait for semaphore\n");
  sem_wait(&test_sem);

  for (i = 0; i < numWords; i++) {
    srcBuffer[i] = 0;
  }
  PORTAL_PRINTF( "Main::starting read %08zx\n", numBytes);
  NandSimRequest_startRead (&intarr[3], ref_srcAlloc, 0, 0, numBytes, 16);
  sem_wait(&test_sem);
  PORTAL_PRINTF ("read: %u %u %u %u\n", srcBuffer[0], srcBuffer[1], srcBuffer[2], srcBuffer[3]);

  PORTAL_PRINTF( "Main::starting erase %08zx\n", numBytes);
  NandSimRequest_startErase (&intarr[3], 0, numBytes);
  sem_wait(&test_sem);

  PORTAL_PRINTF( "Main::starting read %08zx\n", numBytes);
  NandSimRequest_startRead (&intarr[3], ref_srcAlloc, 0, 0, numBytes, 16);
  sem_wait(&test_sem);
  PORTAL_PRINTF ("read: %u %u %u %u\n", srcBuffer[0], srcBuffer[1], srcBuffer[2], srcBuffer[3]);


  PORTAL_PRINTF("\n\nTest 2: check for match\n");
  {
  unsigned long loop = 0;
  unsigned long match = 0, mismatch = 0;
  while (loop < nandBytes) {
	  int i;
	  for (i = 0; i < numBytes/sizeof(srcBuffer[0]); i++) {
		  srcBuffer[i] = loop+i;
	  }

	  /*PORTAL_PRINTF("Main::starting write ref=%d, len=%08zx (%lu)\n", ref_srcAlloc, numBytes, loop);*/
  	  NandSimRequest_startWrite (&intarr[3], ref_srcAlloc, 0, loop, numBytes, 16);
      sem_wait(&test_sem);

	  loop+=numBytes;
  }

  loop = 0;
  while (loop < nandBytes) {
	  int i;
	  /*PORTAL_PRINTF("Main::starting read %08zx (%lu)\n", numBytes, loop);*/
	  NandSimRequest_startRead (&intarr[3], ref_srcAlloc, 0, loop, numBytes, 16);
	  sem_wait(&test_sem);

	  for (i = 0; i < numBytes/sizeof(srcBuffer[0]); i++) {
		  if (srcBuffer[i] != loop+i) {
			  PORTAL_PRINTF("Main::mismatch [%08zx] != [%08zx]\n", loop+i, srcBuffer[i]);
			  mismatch++;
		  } else {
			  match++;
		  }
	  }

	  loop+=numBytes;
  }

  PORTAL_PRINTF("Main::Summary: match=%lu mismatch:%lu (%lu) (%f percent)\n", 
		match, mismatch, match+mismatch, (float)mismatch/(float)(match+mismatch)*100.0);
  }

  PORTAL_PRINTF( "Main: all done\n");
#ifdef __KERNEL__
  if (tid && !kthread_stop (tid)) {
    PORTAL_PRINTF ("kthread stops\n");
  }
  wait_for_completion(&worker_completion);
#endif
  PORTAL_PRINTF ("Main: ends\n");
  return 0;
}
コード例 #2
0
int main(int argc, const char **argv)
{
    int srcAlloc;
    unsigned int *srcBuffer;
    unsigned int ref_srcAlloc;
    unsigned int i;
    pthread_t tid = 0;

    init_portal_internal(&intarr[0], IfcNames_MMUIndicationH2S,     0, MMUIndication_handleMessage, &MMUIndication_cbTable, NULL, NULL, MMUIndication_reqinfo);// fpga1
    init_portal_internal(&intarr[1], IfcNames_ReadTestIndicationH2S,0, ReadTestIndication_handleMessage, &ReadTestIndication_cbTable, NULL, NULL, ReadTestIndication_reqinfo); // fpga2
    init_portal_internal(&intarr[2], IfcNames_MMURequestS2H,     0, NULL, NULL, NULL, NULL, MMURequest_reqinfo); // fpga3
    init_portal_internal(&intarr[3], IfcNames_ReadTestRequestS2H,0, NULL, NULL, NULL, NULL, ReadTestRequest_reqinfo);    // fpga4

    sem_init(&test_sem, 0, 0);
    DmaManager_init(&priv, &intarr[2]);
    srcAlloc = portalAlloc(numBytes, 0);
    if (srcAlloc < 0){
        PORTAL_PRINTF("portal alloc failed rc=%d\n", srcAlloc);
        return srcAlloc;
    }
    srcBuffer = (unsigned int *)portalMmap(srcAlloc, numBytes);
    for (i = 0; i < numBytes/sizeof(srcBuffer[0]); i++)
        srcBuffer[i] = i;
    portalCacheFlush(srcAlloc, srcBuffer, numBytes, 1);

    PORTAL_PRINTF( "Main: creating exec thread\n");
    if(pthread_create(&tid, NULL, pthread_worker, NULL)){
       PORTAL_PRINTF( "error creating exec thread\n");
       return -1;
    }

    PORTAL_PRINTF( "Test 1: check for match\n");
    PORTAL_PRINTF( "Main: before DmaManager_reference(%x)\n", srcAlloc);
    ref_srcAlloc = DmaManager_reference(&priv, srcAlloc);
    PORTAL_PRINTF( "Main: starting read %08x\n", numBytes);
    ReadTestRequest_startRead (&intarr[3], ref_srcAlloc, numBytes, burstLen, 1);
    PORTAL_PRINTF( "Main: waiting for semaphore1\n");
    sem_wait(&test_sem);

    PORTAL_PRINTF( "Test 2: check that mismatch is detected\n");
    srcBuffer[0] = -1;
    srcBuffer[numBytes/sizeof(srcBuffer[0])/2] = -1;
    srcBuffer[numBytes/sizeof(srcBuffer[0])-1] = -1;
    portalCacheFlush(srcAlloc, srcBuffer, numBytes, 1);

    ReadTestRequest_startRead (&intarr[3], ref_srcAlloc, numBytes, burstLen, 1);
    PORTAL_PRINTF( "Main: waiting for semaphore2\n");
    sem_wait(&test_sem);

    PORTAL_PRINTF( "Main: all done\n");
#ifdef __KERNEL__
    if (tid && !kthread_stop (tid)) {
        printk("kthread stops");
    }
    wait_for_completion(&worker_completion);
#endif

#ifdef __KERNEL__
    portalmem_dmabuffer_destroy(srcAlloc);
#endif
    return 0;
}
コード例 #3
0
ファイル: nandsim_manual.c プロジェクト: acw1251/connectal
int main(int argc, const char **argv)
{
  int srcAlloc;
  int backAlloc;
  unsigned int *srcBuffer;
  unsigned int ref_srcAlloc;
  unsigned int *backBuffer;
  unsigned int ref_backAlloc;
  int rc = 0, i;
  pthread_t tid = 0;


  init_portal_internal(&intarr[2], IfcNames_BackingStoreMMURequest, NULL, NULL, NULL, NULL, MMURequest_reqinfo);         // fpga3
  init_portal_internal(&intarr[0], IfcNames_BackingStoreMMUIndication, MMUIndication_handleMessage, &MMUIndication_cbTable, NULL, NULL, MMUIndication_reqinfo);     // fpga1
  init_portal_internal(&intarr[3], IfcNames_NandCfgRequest, NULL, NULL, NULL, NULL, NandCfgRequest_reqinfo);    // fpga4
  init_portal_internal(&intarr[1], IfcNames_NandCfgIndication, NandCfgIndication_handleMessage, &NandCfgIndication_cbTable, NULL, NULL, NandCfgIndication_reqinfo); // fpga2

  DmaManager_init(&priv, &intarr[2]);
  sem_init(&test_sem, 0, 0);

  PORTAL_PRINTF( "Main: creating exec thread - %lu\n", sizeof (unsigned int) );
  if(pthread_create(&tid, NULL, pthread_worker, NULL)){
   PORTAL_PRINTF( "error creating exec thread\n");
   return -1;
  }

  backAlloc = portalAlloc (back_sz, 0);
  PORTAL_PRINTF("backAlloc=%d\n", backAlloc);

  ref_backAlloc = DmaManager_reference(&priv, backAlloc);
  PORTAL_PRINTF("ref_backAlloc=%d\n", ref_backAlloc);

  backBuffer = (unsigned int*)portalMmap(backAlloc, back_sz); 
  portalCacheFlush(backAlloc, backBuffer, back_sz, 1);

  NandCfgRequest_configureNand (&intarr[3], ref_backAlloc, back_sz);
  PORTAL_PRINTF("Main::configure NAND fd=%d ref=%d\n", backAlloc, ref_backAlloc);
  sem_wait(&test_sem);

  srcAlloc = portalAlloc(back_sz, 0);
  srcBuffer = (unsigned int *)portalMmap(srcAlloc, back_sz);
  ref_srcAlloc = DmaManager_reference(&priv, srcAlloc);

  PORTAL_PRINTF("about to start write\n");
  //write data to "flash" memory
  strcpy((char*)srcBuffer, "acabcabacababacababababababcacabcabacababacabababc\n012345678912");
  NandCfgRequest_startWrite(&intarr[3], ref_srcAlloc, 0, 0, 1024, 8);
  sem_wait(&test_sem);

  // at this point, if we were synchronizing with the algo_exe, we
  // could tell it that it was OK to start searching
  PORTAL_PRINTF ("initialization of data in \"flash\" memory complete\n");

#ifdef __KERNEL__
  if (tid && !kthread_stop (tid)) {
    PORTAL_PRINTF ("kthread stops\n");
  }
  wait_for_completion(&worker_completion);
  msleep(20000);
#else
  sleep(20);
#endif


#ifdef __KERNEL__
  portalmem_dmabuffer_destroy(backAlloc);
  portalmem_dmabuffer_destroy(srcAlloc);
#endif

  PORTAL_PRINTF ("Main: ends\n");
  return 0;
}