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

📄 test.c

📁 rt 7520采集卡 linux驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
   SetUtc1Gate7520(board_idx,GUTC1_GATED);   SetupTimerCounter7520(board_idx,TC_UTC1,M8254_RATE_GENERATOR,40000);   Get8254Count7520(board_idx,TC_UTC1,&cnt1);   for (i=0;i<100;i++)   {      Get8254Count7520(board_idx,TC_UTC1,&cnt2);      if ( cnt1 != cnt2 )      {         cntError++;         printf("***FAILED (%u != %u)\n",cnt2,cnt1);         anykey();         break;      }   } // for i   if ( cnt1 == cnt2 )   {      printf("   Passed\n");   }   //   // User TC 2   //   printf("    %s Gate Test\n",szTimer[TC_UTC2]);   printf("      %-38s","Not Gated                   [running]");   SetUtc2Clock7520(board_idx,CUTC2_8MHZ);   SetUtc2Gate7520(board_idx,GUTC2_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC2,M8254_RATE_GENERATOR,40000);      Get8254Count7520(board_idx,TC_UTC2,&cnt1);   Get8254Count7520(board_idx,TC_UTC2,&cnt2);   if ( cnt1 == cnt2 )   {      cntError++;      printf("***FAILED\n");      anykey();   } else {      printf("   Passed\n");      }   //   // Make user counter gated, read count several times   // ==> must not change   //   printf("      %-38s","Gated                   [not running]");   SetUtc2Clock7520(board_idx,CUTC2_8MHZ);   SetUtc2Gate7520(board_idx,GUTC2_GATED);   SetupTimerCounter7520(board_idx,TC_UTC2,M8254_RATE_GENERATOR,40000);   Get8254Count7520(board_idx,TC_UTC2,&cnt1);   for (i=0;i<100;i++)   {      Get8254Count7520(board_idx,TC_UTC2,&cnt2);      if ( cnt1 != cnt2 )      {         cntError++;         printf("***FAILED (%u != %u)\n",cnt2,cnt1);         anykey();         break;      }   } // for i   if ( cnt1 == cnt2 )   {      printf("   Passed\n");   }   //   // Cascaded User TC0-TC1-TC2   //   printf("    %s\n","User TC 0-1-2 Cascaded Test");   printf("      %-38s","Precision (10%)");   SetUtc0Clock7520(board_idx,CUTC0_8MHZ);   SetUtc0Gate7520(board_idx,GUTC0_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC0,M8254_RATE_GENERATOR,8000); // out: 1kHz   SetUtc1Clock7520(board_idx,CUTC1_UTC0_OUT);   SetUtc1Gate7520(board_idx,GUTC1_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC1,M8254_RATE_GENERATOR,100); // out: 10Hz                                                      // counts at 1us   SetUtc2Clock7520(board_idx,CUTC2_UTC1_OUT);   SetUtc2Gate7520(board_idx,GUTC2_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC2,M8254_RATE_GENERATOR,10000); //                                                      // counts at 1s   sleep(1);   printf("\n");   diff = 0;   for (i=0;i<10;i++)   {      Get8254Count7520(board_idx,TC_UTC2,&cnt1);      sleep(1); // 1 s       Get8254Count7520(board_idx,TC_UTC2,&cnt2);         diff = diff + cnt1-cnt2;	       printf("diff=%d (expected 10)\n", cnt1-cnt2);   }   diff/=10;   if ( (diff < 10-1) || (diff > 10+1) )   {      // Must be within 10%      cntError++;      printf("***FAILED diff=%d cnt1=%d cnt2=%d\n", diff,cnt1,cnt2);      anykey();   } else {      printf("   Passed\n");   }   //   // Restore defaults   //   InitBoard7520(board_idx);   return cntError;} // atest_timers_utc/****************************************************************************@func This function tests if the Digital I/O Chip registers are accessible.@rdesc Returns number of failed tests.****************************************************************************/int atest_dio_registers (int board_idx){   unsigned char bData;   uint8_t	direction;   uint8_t	mask;   uint8_t	mode;   uint8_t	source;   printf("  --------------------------------------------------------------------\n");   printf("  Digital I/O Chip Register I/O Test\n");   printf("  --------------------------------------------------------------------\n");   ClearDIO7520(board_idx);   ClearDIO0IrqStatus7520(board_idx);   //   // Port 0 Direction   //   printf("    Port 0\n");   printf("      %-38s","Direction");   SetDIO0Direction7520(board_idx,0x55);   GetDIO0Direction7520(board_idx, &direction);   if ( 0x55 != direction )   {      cntError++;      printf("***FAILED\n");	  anykey();   } else {      printf("   Passed\n");   }   //   // Port 0 Mask   //   printf("      %-38s","Mask");   SetDIO0Mask7520(board_idx,0x55);   GetDIO0Mask7520(board_idx, &mask);   if ( 0x55 != mask )   {      cntError++;      printf("***FAILED\n");	  anykey();   } else {      printf("   Passed\n");   }   //   // Port 0 Mode   //   printf("      %-38s","Mode");   SetDIO0CompareMode7520(board_idx,1);   GetDIO0CompareMode7520(board_idx, &mode);   if ( 1 != mode )   {      cntError++;      printf("***FAILED\n");	  anykey();   } else {      printf("   Passed\n");   }   //   // Port 0 Clock   //   printf("      %-38s","Clock");   SetDIO0Clock7520(board_idx,1);   GetDIO0Clock7520(board_idx,&source);   if ( 1 != source )   {      cntError++;      printf("***FAILED\n");	  anykey();   } else {      printf("   Passed\n");   }   //   // Port 0 Compare Value   //   printf("      %-38s","Compare Value");   EnableDIO0Irq7520(board_idx,1); // can set compare value only if ITs are enabled!   SetDIO0CompareValue7520(board_idx,0xAA);   GetDIO0CompareValue7520(board_idx, &bData);   if ( 0xAA != bData )   {      cntError++;      printf("***FAILED (set:%Xh got:%Xh)\n",0xAA,bData);	  anykey();   } else {      printf("   Passed\n");   }   //   // Port 1 Direction   //   printf("    Port 1\n");   printf("      %-38s","Direction");   SetDIO1Direction7520(board_idx,1);   GetDIO1Direction7520(board_idx,&direction);   if ( 1 != direction )   {      cntError++;      printf("***FAILED\n");	  anykey();   } else {      printf("   Passed\n");   }   //   // Restore defaults   //   InitBoard7520(board_idx);   return cntError;} // atest_dio_registers/****************************************************************************@func Check if DIN FIFO is empty.@rdesc Returns non-zero if FIFO is not-empty, half-full or full.****************************************************************************/int check_din_fifo_empty (int board_idx){   uint8_t	fifo_empty;   uint8_t	fifo_half_full;   uint8_t	fifo_full;   IsDINFifoEmpty7520(board_idx,&fifo_empty);   IsDINFifoHalfFull7520(board_idx,&fifo_half_full);   IsDINFifoFull7520(board_idx,&fifo_full);   if ( !fifo_empty )   {      printf("***FAILED (FIFO not empty)\n");	  anykey();      return 1;   } else   if ( fifo_half_full )   {      printf("***FAILED (FIFO half full)\n");	  anykey();      return 2;   } else   if ( fifo_full )   {      printf("***FAILED (FIFO full)\n");	  anykey();      return 3;   } else {      printf("   Passed\n");   }   return 0;} // check_din_fifo_empty/****************************************************************************@func Check if DIN FIFO is not empty.@rdesc Returns non-zero if FIFO is empty, half-full or full.****************************************************************************/int check_din_fifo_not_empty (int board_idx){   uint8_t	fifo_empty;   uint8_t	fifo_half_full;   uint8_t	fifo_full;   IsDINFifoEmpty7520(board_idx,&fifo_empty);   IsDINFifoHalfFull7520(board_idx,&fifo_half_full);   IsDINFifoFull7520(board_idx,&fifo_full);   if ( fifo_empty )   {      printf("***FAILED (FIFO empty)\n");	  anykey();      return 1;   } else   if ( fifo_half_full )   {      printf("***FAILED (FIFO half full)\n");	  anykey();      return 2;   } else   if ( fifo_full )   {      printf("***FAILED (FIFO full)\n");	  anykey();      return 3;   } else {      printf("   Passed\n");   }   return 0;} // check_din_fifo_not_empty/****************************************************************************@func Check if DIN FIFO is half-full.@rdesc Returns non-zero if FIFO is empty, not half-full or full.****************************************************************************/int check_din_fifo_half_full (int board_idx){   uint8_t	fifo_empty;   uint8_t	fifo_half_full;   uint8_t	fifo_full;   IsDINFifoEmpty7520(board_idx,&fifo_empty);   IsDINFifoHalfFull7520(board_idx,&fifo_half_full);   IsDINFifoFull7520(board_idx,&fifo_full);   if ( fifo_empty )   {      printf("***FAILED (FIFO empty)\n");	  anykey();      return 1;   } else   if ( !fifo_half_full )   {      printf("***FAILED (FIFO not half full)\n");	  anykey();      return 2;   } else   if ( fifo_full )   {      printf("***FAILED (FIFO full)\n");	  anykey();      return 3;   } else {      printf("   Passed\n");   }   return 0;} // check_din_fifo_half_full/****************************************************************************@func Check if DIN FIFO is full.@rdesc Returns non-zero if FIFO is empty, not half-full or not full.****************************************************************************/int check_din_fifo_full (int board_idx){   uint8_t	fifo_empty;   uint8_t	fifo_half_full;   uint8_t	fifo_full;   IsDINFifoEmpty7520(board_idx,&fifo_empty);   IsDINFifoHalfFull7520(board_idx,&fifo_half_full);   IsDINFifoFull7520(board_idx,&fifo_full);   if ( fifo_empty )   {      printf("***FAILED (FIFO empty)\n");	  anykey();      return 1;   } else   if ( !fifo_half_full )   {      printf("***FAILED (FIFO not half full)\n");	  anykey();      return 2;   } else   if ( !fifo_full )   {      printf("***FAILED (FIFO not full)\n");	  anykey();      return 3;   } else {      printf("   Passed\n");   }   return 0;} // check_din_fifo_full/****************************************************************************@func This function tests Digital Input.@rdesc Returns number of failed tests.****************************************************************************/int atest_din (int board_idx){   unsigned char bData;   int i, j;   printf("  --------------------------------------------------------------------\n");   printf("  Software Read/Write Test (Ports must be floating)\n");   printf("  --------------------------------------------------------------------\n");   ClearAllIO7520(board_idx);   //   // Write Port 0 / Read Port 0 back   //   printf("    %-40s","Write/Read Port 0");   for ( j=0; j<10; j++ )   {           unsigned char data = random()*0xFF/RAND_MAX;      unsigned char mask = ( j ? random()*0xFF/RAND_MAX : 0x00 );      //      // Program Port 0 for output and write the random value (no mask)      //      ClearDIO7520(board_idx);      ClearDIO0IrqStatus7520(board_idx);      SetupPort07520(board_idx,0xFF,0x00,0,0x00,0,FALSE);      WriteDIO07520(board_idx,data);      //      // Program Port 0 for input with the random mask      //      SetupPort07520(board_idx,0xFF,mask,0,0x00,0,FALSE);      //      // Write value i (i = 0..255), read back and compare      //      for ( i=0; i<=0xFF; i++ )      {         WriteDIO07520(board_idx,i);         ReadDIO07520(board_idx, &bData);         if ( ((mask & data) | (~mask & i)) != bData )         {            cntError++;            printf("***FAILED (write: %X & %X, read: %X)\n",mask,i,bData);			anykey();            break;         }      } // for i      if ( i < 256 ) break;   } // for j   if ( i > 0xFF )   {      printf("   Passed\n");   }   //   // Write Port 1 / Read Port 1 back   //   printf("    %-40s","Write/Read Port 1");   //   // Program Port 1 for output   //   ClearDIO7520(board_idx);   ClearDIO0IrqStatus7520(board_idx);   SetDIO1Direction7520(board_idx,1);   //   // Write value i (i = 0..255), read back and compare   //   for ( i=0; i<=0xFF; i++ )   {      WriteDIO17520(board_idx,i);      ReadDIO17520(board_idx, &bData);      if ( i != bData )      {         cntError++;         printf("***FAILED (write: %X, read: %X)\n",i,bData);		 anykey();         break;      }   } // for i   if ( i > 0xFF )   {      printf("   Passed\n");   }   //   // Restore defaults   //   InitBoard7520(board_idx);   return cntError;} // atest_din/****************************************************************************@func This function tests Digital Input.@rdesc Returns number of failed tests.****************************************************************************/int atest_hdin_fifo (int board_idx){   uint16_t bData;   int i;   //   // High Speed Digital Input FIFO Test   //   printf("  --------------------------------------------------------------------\n");   printf("  High Speed Digital Input FIFO Test\n");   printf("  --------------------------------------------------------------------\n");   ClearAllIO7520(board_idx);   //   // Set up for software controlled A/D   //   //   // Set up for A/D controlled High-Speed Digital Input   //   SetHdinStart7520(board_idx,HDIN_SOFTWARE);

⌨️ 快捷键说明

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