⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdma.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
      {        if( to_vme )        {          pattern_addr = local_addr;          dest_addr = vme_addr;        }        else        {          pattern_addr = vme_addr;          dest_addr = local_addr;        }        if( verifyDmaPattern( pattern_addr, dest_addr, size ) != OK )          fprintf(stdout, "DMA pattern verification failed: ERROR.\n" );        else          fprintf(stdout, "DMA pattern verified OK.\n" );      } /* do_verify */    } /* copied OK */  } /* pattern created OK */  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void  testAsyncDmaCopy(                   char * local_addr, /* relative to PPC */                   char * vme_addr,   /* relative to PPC */                   UINT32 size,                   BOOL   to_vme,                   int    pattern_type,                   BOOL   do_verify )/*  Description : * Attempts to create and copy a block of memory to/from * VME over the DMA. The target block is then verified * against original pattern. * *   Return Value : *       None. * *   Comments: *       Function will fail if twice the memory required by *       the size parameter can be allocated. * **END HEADER**********************************************/{  BOOL   originalDebugState;  char  *pattern_addr, *dest_addr;#if 0  char  *universe_local_addr = local_addr+UNIVERSE_LOCAL_ADDR_OFFSET;  char  *universe_vme_addr = vme_addr+UNIVERSE_VME_ADDR_OFFSET;#endif  char  *universe_local_addr = local_addr;  char  *universe_vme_addr = vme_addr;  fprintf(stdout, "++++++++++++++++++++++++++++++++\n" );  fprintf(stdout, "Test Asynchronous DMA copy function\n" );  /* Get original state of debug value and set state of debug value   * to TRUE to get display out of this function.   */  originalDebugState = sysVmeDmaGetDebugState ();#ifdef CHANGE_DEBUG_STATE  sysVmeDmaSetDebugState( DEFAULT_DEBUG_STATE );#endif  /* Display the DMA copy we are starting.   */  fprintf(stdout, "================================\n" );  fprintf(stdout, "Local address       : 0x%08X (local_addr)\n", (UINT32)local_addr );  fprintf(stdout, "Universe local addr : 0x%08X\n", (UINT32)universe_local_addr );  fprintf(stdout, "Local VME address   : 0x%08X (vme_addr)\n", (UINT32)vme_addr );  fprintf(stdout, "Universe VME addr   : 0x%08X\n", (UINT32)universe_vme_addr );  fprintf(stdout, "Transfer size       : 0x%08X (%0d)\n", size, size );  if( to_vme )    fprintf(stdout, "Direction (to VME)  : TRUE\n" );  else    fprintf(stdout, "Direction (to VME)  : FALSE\n" );  fprintf(stdout, "Pattern type        : %s (%0d)\n",          sys_vme_dma_pattern_type[pattern_type].name, pattern_type );  if( do_verify )    fprintf(stdout, "Verify result       : TRUE\n" );  else    fprintf(stdout, "Verify result       : FALSE\n" );  /* Set the pattern location according to the to_vme flag.   */  if( to_vme )  {    pattern_addr = local_addr;    dest_addr    = vme_addr;  }  else  {    pattern_addr = vme_addr;    dest_addr    = local_addr;  }  /* Clear the RAM on the target to ensure that the DMA copy is real.   */  clearTargetRam( dest_addr, size );  /* Create the pattern.   */  if( createDmaPattern( pattern_addr, size, pattern_type ) != OK )    fprintf(stdout, "Unable to create pattern: FAILED\n" );  else  {    fprintf(stdout, "Pattern created OK\n" );    /*     * Set up the copy routine and call it.     */    if( async_sysVmeDmaCopy( universe_local_addr,                             universe_vme_addr, size, to_vme ) != OK )        {        fprintf(stdout, "DMA copy failed: ERROR.\n" );        }    else        {        fprintf(stdout, "DMA copy returned OK.\n" );	/* LONG PAUSE or gobs of other code....... */	taskDelay(1);	/*	 * Poll to see if the DMA is finished.	 */	if( sysVmeDmaIsAsyncDone( 0 ) == ERROR )	  {	    printf( "Async DMA not done yet.\n" );	    /*	     * Check to see if the DMA is finished.	     */	    if( sysVmeDmaIsAsyncDone( 4 ) == ERROR )	      {		printf( "Oops! Async DMA probably timed out.\n" );	      }	  }	else	  {	  printf( "Async DMA done.\n" );	  }	/*	 * Wait about one more second for good measure.	 */	taskDelay(sysClkRateGet());      /* Verify the pattern if requested.       */      if( do_verify )      {        if( to_vme )        {          pattern_addr = local_addr;          dest_addr = vme_addr;        }        else        {          pattern_addr = vme_addr;          dest_addr = local_addr;        }        if( verifyDmaPattern( pattern_addr, dest_addr, size ) != OK )          fprintf(stdout, "DMA pattern verification failed: ERROR.\n" );        else          fprintf(stdout, "DMA pattern verified OK.\n" );      } /* do_verify */    } /* copied OK */  } /* pattern created OK */  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void  testDmaGet( void )/*  Description : * Attempts to * *   Return Value : *       None. * *   Comments: * **END HEADER**********************************************/{  STATUS  ret_val;  int     i;  UINT32  gotten_val;  BOOL    originalDebugState;  fprintf(stdout, "++++++++++++++++++++++++++++++++\n" );  fprintf(stdout, "Tests and interprets sysVmeDmaGet function\n" );  /* Get original state of debug value and set state of debug value   * to TRUE to get display out of this function.   */  originalDebugState = sysVmeDmaGetDebugState ();#ifdef CHANGE_DEBUG_STATE  sysVmeDmaSetDebugState( DEFAULT_DEBUG_STATE );#endif  /* Do normal types that should generate no errors. */  for( i = 0;       i < (sizeof( sysVmeDmaGetSetType )/sizeof( sysVmeDmaGetSetType[0] )) - 1;       i++ )  {    fprintf(stdout, "\nGetting value of %s\n", sysVmeDmaGetSetType[i].name );    if( (ret_val = sysVmeDmaGet( sysVmeDmaGetSetType[i].type, &gotten_val ))        == OK )      fprintf(stdout, "Function returned OK. Value is %08X\n", gotten_val );    else      fprintf(stdout, "Function returned ERROR.\n" );  }  /* Do deliberate error type . */  fprintf(stdout, "\nAttempting to get value of %s\n", sysVmeDmaGetSetType[i].name );    if( (ret_val = sysVmeDmaGet( sysVmeDmaGetSetType[i].type, &gotten_val ))        == OK )      fprintf(stdout, "Oops! Function returned OK. Value is %08X\n", gotten_val );    else      fprintf(stdout, "OK: Function returned ERROR as expected.\n" );  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void  testDmaSet( void )/*  Description : * Attempts to * *   Return Value : *       None. * *   Comments: * **END HEADER**********************************************/{  STATUS  ret_val;  int     i;  UINT32  gotten_val;  BOOL   originalDebugState;  fprintf(stdout, "++++++++++++++++++++++++++++++++\n" );  fprintf(stdout, "Tests and interprets sysVmeDmaGet function\n" );  /* Get original state of debug value and set state of debug value   * to TRUE to get display out of this function.   */  originalDebugState = sysVmeDmaGetDebugState ();#ifdef CHANGE_DEBUG_STATE  sysVmeDmaSetDebugState( DEFAULT_DEBUG_STATE );#endif  /* Do normal types that should generate no errors. */  for( i = 0;       i < (sizeof( sysVmeDmaGetSetType )/sizeof( sysVmeDmaGetSetType[0] )) - 1;       i++ )  {    fprintf(stdout, "\nGetting value of %s\n", sysVmeDmaGetSetType[i].name );    if( (ret_val = sysVmeDmaGet( sysVmeDmaGetSetType[i].type, &gotten_val ))        == OK )      fprintf(stdout, "Function returned OK. Value is %08X\n", gotten_val );    else      fprintf(stdout, "Function returned ERROR.\n" );  }  /* Do deliberate error type . */  fprintf(stdout, "\nAttempting to get value of %s\n", sysVmeDmaGetSetType[i].name );    if( (ret_val = sysVmeDmaGet( sysVmeDmaGetSetType[i].type, &gotten_val ))        == OK )      fprintf(stdout, "Oops! Function returned OK. Value is %08X\n", gotten_val );    else      fprintf(stdout, "OK: Function returned ERROR as expected.\n" );  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/STATUS createDmaPattern( char * addr,                         UINT32 size,                         int pattern_type )/*  Description : * Attempts to create a pattern of the type specified in * the location specified. * *   Return Value : *       Status (OK or ERROR). * *   Comments: * **END HEADER**********************************************/{  UINT32    i;  char      temp = 0;  fprintf( stdout, "Pattern being created at address 0x%08X\n", (UINT32)addr );  for( i = 0; i < size; i++ )  {    switch( pattern_type )    {      case DMA_PAT_ALL_ZEROS: temp = 0x00; break;      case DMA_PAT_ALL_ONES:  temp = 0xFF; break;      case DMA_PAT_55:        temp = 0x55; break;      case DMA_PAT_AA:        temp = 0xAA; break;      case DMA_PAT_INC:       temp++;      break;      case DMA_PAT_DEC:       temp--;      break;      case DMA_PAT_RANDOM:    temp = ( rand() && 0xFF ); break;      default: return ERROR;    }    *(addr+i) = temp;  }  return OK;}/*HEADER***************************************************/STATUS clearTargetRam( char * addr,                       UINT32 size )/*  Description : * Clears RAM block at specified address. * *   Return Value : *       Status (OK) or (ERROR) if it is unable to clear this region. * *   Comments: * **END HEADER**********************************************/{  UINT32    i;  fprintf( stdout, "Clearing target RAM at address 0x%08X\n", (UINT32)addr );  for( i = 0; i < size; i++ )  {    *(addr+i) = 0;    if( *(addr+i) != 0 )      /* Verification to know if clear is OK */      {        fprintf( stdout, "Unable to clear target RAM at address 0x%08X\n", (UINT32)(addr+i) );        return ERROR;      }  }  return OK;}/*HEADER***************************************************/STATUS verifyDmaPattern( char * pattern_addr,                         char * dest_addr,                         UINT32 size )/*  Description : * Scans the original pattern and the copied pattern looking for * a mismatch. Scan is performed on bytes (not too fast!!). * *   Return Value : *       Status (OK or ERROR). * *   Comments: * **END HEADER**********************************************/{  UINT32  i, mismatches = 0;  char   *org_addr, *copy_addr;  STATUS  ret_val;  /* Create local copies of the pattern and destination addresses.   */  org_addr = pattern_addr;  copy_addr = dest_addr;  fprintf(stdout, "Verifying pattern in buffers\n");  fprintf(stdout, " Original pattern addr     : 0x%08X\n", (UINT32)pattern_addr );  fprintf(stdout, " Copy (DMA'd) pattern addr : 0x%08X\n", (UINT32)dest_addr );  fprintf(stdout, " Pattern size              : 0x%08X (%0d)\n", size, size );  /* Scan through memory blocks checking for mismatches. On first   * one found, display locations and contents and increment   * mismatch counter. On subsequent mismatches, just increment   * counter.   */  for( i = 0; i < size; i++ )  {    if( *org_addr != *copy_addr )    {      if( mismatches == 0 )      {        fprintf(stdout, "Found first mismatch  at byte # %0d: ", i );        fprintf(stdout, "org(0x%08X) = 0x%02X, copy(0x%08X) = 0x%02X\n",                        (UINT32)org_addr, *org_addr,                        (UINT32)copy_addr, *copy_addr );      }      mismatches++;    }    org_addr++;    copy_addr++;  }  /* Display how many mismatches were found.   */  fprintf(stdout, "Total mismatches found = %0d\n", mismatches );  /* Set flag to ERROR if not 0.   */  if( mismatches != 0 )    ret_val = ERROR;  else    ret_val = OK;  return ret_val;}/*HEADER***************************************************/void testSync( void )/*  Description : *    Sets up DMA copy * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  testDmaCopy( my_local_addr,               my_vme_addr,               my_size,               my_to_vme,               my_pattern_type,               my_do_verify );}/*HEADER***************************************************/void testVarsShow( void )/*  Description : *    Show local address. * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  fprintf(stdout, "++++++++++++++++++++++++++++++++\n" );  fprintf(stdout, "Local address        : 0x%08X (my_local_addr)\n", (UINT32)my_local_addr );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -