Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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;
}