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

📄 testdma.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
#if 0  fprintf(stdout, "Universe local addr  : 0x%08X \n", (UINT32)(my_local_addr+UNIVERSE_LOCAL_ADDR_OFFSET) );#endif  fprintf(stdout, "Universe local addr  : 0x%08X \n", (UINT32)(my_local_addr) );#if 0  fprintf(stdout, "Universe VME addr    : 0x%08X \n", (UINT32)(my_vme_addr+UNIVERSE_VME_ADDR_OFFSET) );#endif  fprintf(stdout, "Local VME address    : 0x%08X (my_vme_addr)\n", (UINT32)my_vme_addr );  fprintf(stdout, "Universe VME addr    : 0x%08X \n", (UINT32)(my_vme_addr) );  fprintf(stdout, "Transfer size        : 0x%08X (%0d) (my_size)\n", my_size, my_size );  if( my_to_vme )    fprintf(stdout, "Direction (to VME)   : TRUE (my_to_vme)\n" );  else    fprintf(stdout, "Direction (to VME)   : FALSE (my_to_vme)\n" );  fprintf(stdout, "Pattern type         : %s (%0d) (my_pattern_type)\n",          sys_vme_dma_pattern_type[my_pattern_type].name, my_pattern_type );  if( my_do_verify )    fprintf(stdout, "Verify result        : TRUE (my_do_verify)\n" );  else    fprintf(stdout, "Verify result        : FALSE (my_do_verify)\n" );}/*HEADER***************************************************/void showMe ( void )/*  Description : *    Display current parameters. * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  testVarsShow();}/*HEADER***************************************************/void testLockSet ( UINT32    seconds,                   UINT8     type,                   UINT32    value )/*  Description : *    Delay specified number of seconds *    Attempt to lock DMA *       - wait for LOCK_TIMEOUT*100ms for lock *       - timeout if no lock achieved by then *    DO copy using current paremteers * * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  BOOL    timeout = FALSE, waiting_flag = FALSE;  int     i = 0;  STATUS  ret_val;  BOOL    originalDebugState;  /* 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  fprintf(stdout, "++++++++++++++++++++++++++++++++\n" );  fprintf(stdout, "Test DMA lock mechanism using Get (sec = %0d)\n", seconds );  fprintf(stdout, "Delaying %0d seconds before attempting to take lock\n", seconds );  TimeDelay( seconds * 10 );  fprintf(stdout, "Taking the lock (sec = %0d)\n", seconds );#ifdef DEBUG_LOCK  while( !timeout )#else  while( (( ret_val = sysVmeDmaLock()) != OK) && !timeout )#endif  {    if( !waiting_flag )    {#if 0  fprintf(stdout, "Waiting for the lock (sec = %0d, %0d, %0d, %0d)\n", seconds, i, ret_val, timeout );#endif      fprintf(stdout, "Waiting for the lock (sec = %0d)\n", seconds );      waiting_flag = TRUE;    }    TimeDelay( 1 );    i++;    if( i > LOCK_TIMEOUT )      timeout = TRUE;  }  if( timeout )  {    fprintf(stdout, "Timeout occured waiting for the lock (sec = %0d)\n", seconds );    return;  }  fprintf(stdout, "\nSetting value of %s\n", sysVmeDmaGetSetType[i].name );  if( sysVmeDmaSet( type, value ) == OK )    fprintf(stdout, "Function returned OK. \n" );  else    fprintf(stdout, "Function returned ERROR.\n" );#if 0  ret_val = sysVmeDmaUnlock ( DO_NOT_FORCE_UNLOCK );#else  ret_val = sysVmeDmaUnlock ( FORCE_UNLOCK );#endif  fprintf(stdout, "Released the lock (sec = %0d, ret = %0d)\n", seconds, ret_val );  fprintf(stdout, "Lock test done (sec = %0d)\n", seconds );  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void testLockCopy ( UINT32   seconds,                    char   * local_addr,                    char   * vme_addr,                    UINT32   size,                    BOOL     to_vme,                    int      pattern )/*  Description : *    Delay specified number of seconds *    Attempt to lock DMA *       - wait for LOCK_TIMEOUT*100ms for lock *       - timeout if no lock achieved by then *    Do copy using current paremeters * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  BOOL    timeout = FALSE, waiting_flag = FALSE;  int     i = 0;  STATUS  ret_val;  BOOL    originalDebugState;  /* 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  fprintf(stdout, "Test DMA lock mechanism using Copy (%0d)\n", seconds );  fprintf(stdout, "Delaying %0d seconds before attempting to take lock\n", seconds );  TimeDelay( seconds * 10 );  fprintf(stdout, "Taking the lock (%0d)\n", seconds );  while( ((ret_val = sysVmeDmaLock()) != OK) && !timeout )  {    if( !waiting_flag )    {      fprintf(stdout, "Waiting for the lock (%0d)\n", seconds );      waiting_flag = TRUE;    }    TimeDelay( 1 );    i++;    if( i > LOCK_TIMEOUT )      timeout = TRUE;  }  if( timeout )  {    fprintf(stdout, "Timeout occured waiting for the lock (%0d)\n", seconds );    return;  }  testDmaCopy( local_addr,               vme_addr,               size,               to_vme,               pattern,               DO_VERIFIY );#if 0  ret_val = sysVmeDmaUnlock ( DO_NOT_FORCE_UNLOCK );#else  ret_val = sysVmeDmaUnlock ( FORCE_UNLOCK );#endif  fprintf(stdout, "Released the lock (sec = %0d, ret = %0d)\n", seconds, ret_val );  fprintf(stdout, "Lock test done (%0d )\n", seconds );  /* Restore original state of debug value.   */  sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void TimeDelay( UINT32 tenths_of_seconds )/*  Description : *    Delay the number of tenths of seconds specified (max 2000). * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  int   i, j;/*  fprintf(stdout, "TimeDelay called with %0d\n", tenths_of_seconds ); */  if( tenths_of_seconds > 2000 )  {    fprintf(stdout, "TimeDelay called with number greater than 2000*100ms (%0d)\n", tenths_of_seconds );  }  else  {    for( i = 0; i < tenths_of_seconds; i++ )    {      for( j = 0; j < 6; j++ )      {        taskDelay(1);/*        fprintf(stdout, "Inner got here %0d\n", j ); */      }/*      fprintf(stdout, "Outer got here %0d\n", i ); */    }  }}/*HEADER***************************************************/void printfDctlDgcs( void )/*  Description : * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{  printf ("DMA Transfer Control                   :\t0x%08x\n",          (int)LONGSWAP(*UNIVERSE_DCTL));  printf ("DMA General Control and Status         :\t0x%08x\n",          (int)LONGSWAP(*UNIVERSE_DGCS));}/*HEADER***************************************************/void printRegs( void )/*  Description : * *   Return Value : *       void * *   Comments: * **END HEADER**********************************************/{    printf ("DMA Transfer Control                   :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DCTL));    printf ("DMA Transfer Byte Count                :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DTBC));    printf ("DMA PCI bus Address                    :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DLA));    printf ("DMA VMEbus Address                     :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DVA));    printf ("DMA Command Packet Pointer             :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DCPP));    printf ("DMA General Control and Status         :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_DGCS));    printf ("DMA Linked List Update Enable          :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_D_LLUE));    printf ("VMEbus AM Code Error Log               :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_V_AMERR));    printf ("VMEbus Address Error Log               :\t0x%08x\n",            (int)LONGSWAP(*UNIVERSE_VAERR));}void testLock1( void ){  printf( "testLock1: Set, UNIVERSE_VME_DMA_DCAP, UNIVERSE_DCAP_MBLT\n");  printfDctlDgcs();  testLockSet ( 3,                UNIVERSE_VME_DMA_DCAP,                UNIVERSE_DCAP_MBLT );  printfDctlDgcs();}void testLock2( void ){  printf( "testLock2: Set, UNIVERSE_VME_DMA_DCAP, UNIVERSE_DCAP_D64\n");  printfDctlDgcs();  testLockSet ( 6,                UNIVERSE_VME_DMA_DCAP,                UNIVERSE_DCAP_D64 );  printfDctlDgcs();}void testLock3( void ){  printf( "testLock3: Set, UNIVERSE_VME_DMA_DELAY, 3\n");  printfDctlDgcs();  testLockSet ( 9,                UNIVERSE_VME_DMA_DELAY,                3 );  printfDctlDgcs();}void testLock4( void ){  printf( "testLock4: Set, UNIVERSE_VME_DMA_BSIZE, 5\n");  printfDctlDgcs();  testLockSet ( 12,                UNIVERSE_VME_DMA_BSIZE,                5 );  printfDctlDgcs();}void testLock5( void ){  printf( "testLock5: Copy, to VME, 0x60000, size 0x1000, pattern 1 \n");  testLockCopy ( 6,                 (char *)0x60000,                 (char *)0x48060000,  /* Change from D8060000 to 48060000 for SVME-181 mapping */                 0x1000,                 1,                 DMA_PAT_ALL_ONES);}void testLock6( void ){  printf( "testLock6: Copy, from VME, 0x61000, size 0x2000, pattern 2 \n");  testLockCopy ( 7,                 (char *)0x61000,                 (char *)0x48061000,  /* Change from D8062000 to 48061000 for SVME-181 mapping */                 0x2000,                 0,                 DMA_PAT_55 );}void testLock7( void ){  printf( "testLock7: Copy, from VME, 0x63000, size 0x234, pattern 3 \n");  testLockCopy ( 8,                 (char *)0x63000,                 (char *)0x48063000,  /* Change from D8064000 to 48063000 for SVME-181 mapping */                 0x234,                 0,                 DMA_PAT_AA);}void testGetSet( void ){  int   val;  int   should_be;  printf("===============================\n");  printf("Test sysVmeDmaSet/sysVmeDmaSet\n");  should_be = UNIVERSE_DCAP_D8;  printf( "Set DCAP mode to D8    (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val );  should_be = UNIVERSE_DCAP_D16;  printf( "Set DCAP mode to D16   (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val );  should_be = UNIVERSE_DCAP_D32;  printf( "Set DCAP mode to D32   (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val );  should_be = UNIVERSE_DCAP_BLT;  printf( "Set DCAP mode to BLT   (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val );  should_be = UNIVERSE_DCAP_MBLT;  printf( "Set DCAP mode to MBLT  (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val );  should_be = UNIVERSE_DCAP_D64;  printf( "Set DCAP mode to MBLT  (result = %0d)\n", sysVmeDmaSet ( UNIVERSE_VME_DMA_DCAP, should_be ) );  sysVmeDmaGet( UNIVERSE_VME_DMA_DCAP, &val );  printfDctlDgcs();  printf( "Result should be %0d. Actual is %0d\n", should_be, val ); }/****************************************************************/void intrHandler( void ){    UINT32   temp;#ifdef INT_HANDLER_MSG    logMsg( "Asynchronous VMEBus DMA interrupt!\n", 0, 0, 0, 0, 0, 0 );#endif    /*     * We got a DMA interrupt and now we must process the DMA status     * register for the results.     */    temp = LONGSWAP( *UNIVERSE_DGCS );    /*     * See if the DMA DONE bit is set. This indicates that a     * successfull transaction occured.     */    if( (temp & DGCS_DONE) == DGCS_DONE )    {#ifdef INT_HANDLER_MSG      logMsg( "VMEBus DMA termination ok!\n", 0, 0, 0, 0, 0, 0 );#endif      sysVmeDmaSetLastAsyncStatus ( OK );    }    /*     * See if the LERR bit is set indicating a local (PCI) bus error.     */    if( (temp & DGCS_LERR) == DGCS_LERR )    {      logMsg( "VMEBus DMA error on PCI!\n", 0, 0, 0, 0, 0, 0 );      sysVmeDmaSetLastAsyncStatus ( ERROR );    }    /*     * See if the VERR bit is set indicating a VMEbus error.     */    if( (temp & DGCS_VERR) == DGCS_VERR )    {      logMsg( "VMEBus DMA error on VME!\n", 0, 0, 0, 0, 0, 0 );      sysVmeDmaSetLastAsyncStatus ( ERROR );    }    /*     * Check if DMA P_ERR bit is set indicating a ??? error.     */    if( (temp & DGCS_P_ERR) == DGCS_P_ERR )    {      logMsg( "VMEBus DMA error, misaligned transfer!\n",                  0, 0, 0, 0, 0, 0 );      sysVmeDmaSetLastAsyncStatus ( ERROR );    }    return;}/****************************************************************/void testAsync( void ){    /*     * Install our interrupt handler.     */    sysVmeDmaConnect( (FUNCPTR) intrHandler );    printf( "Async DMA interrupt handler installed.\n" );    testAsyncDmaCopy( my_local_addr+my_size,                      my_vme_addr+my_size,                      my_size,                      (my_to_vme ? 0 : 1),                      my_pattern_type-1,                      my_do_verify );

⌨️ 快捷键说明

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