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

📄 test.c

📁 rt 7520采集卡 linux驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*	FILE NAME: test.c	FILE DESCRIPTION:		Test driver and library functionality.		Nothing should be connected to the board connectors during this		test.	PROJECT NAME: Linux DM7520 Driver, Library, and Example Programs	PROJECT VERSION: (Defined in README.TXT)	Copyright 2004 RTD Embedded Technologies, Inc.  All Rights Reserved.*/#include <stdio.h>	//printf#include <unistd.h>	//sleep#include <stdlib.h>	//exit#include <errno.h>	//errno#include <slang/slang.h>  //for anykey//#include "dm7520.h"#include "dm7520_library.h"//-----------------------------------------------------------------// prototipesint test_defaults(int board_idx);int anykey(void);int atest_timers (int board);int atest_timers_registers (int board_idx);int atest_timers_utc (int board_idx);int atest_dio (int board);int atest_dio_registers (int board_idx);int atest_din (int board_idx);int atest_hdin_fifo (int board_idx);int atest_dout (int board_idx);int atest_da ();int atest_ad (void);//-----------------------------------------------------------------// Timer/Counters#define cnt8254MODES 6#define cntTIMERS    12#define cntUTCS      3#define FALSE        0// Timer/Counter Nameschar *szTimer[cntTIMERS] =   {      "Pacer Clock 1",      "Pacer Clock 2",      "Burst Clock",      "ADC Sample Counter",      "DAC1 Update Counter",      "DAC2 Update Counter",      "Delay Counter",      "About Counter",      "DAC Clock",      "User TC 0",      "User TC 1",      "User TC 2"   };// 8254 Operation Mode Nameschar *sz8254Mode[cnt8254MODES] =   {      "Event Counter",      "Programmable One-Shot",      "Rate Generator",      "Square Wave Generator",      "Software Triggered Strobe",      "Hardware Triggered Strobe"   };int hb=0;FILE * infile;int cntError = 0;int fifohalf;int fifosize;char buf[128];int board_idx;int main(int argc, char * argv[]){ int devno;		//device handler int ret = 0;  if (argc<2) {fprintf(stderr,"Usage: %s <device> \n",argv[0]);exit(1);} if (NULL==(infile=fopen(argv[1],"r")))   {    fprintf(stderr,"Cannot open file, errno=%d\n",errno);    perror("Error is");    exit(2);   }  devno = fileno(infile);  board_idx = devno;   ret = dm7520_getFifoSize(devno, &fifosize);  if (0!=ret) {    printf ("Error executing dm7520_getFifoSize ret=%d\n",ret);    return 0;  }  fifohalf = fifosize/2; test_defaults(devno);  atest_timers(devno); atest_dio(devno); atest_da(); atest_ad ();  printf("\n\nAll tests are done. Number of errors = %d\n", cntError); return 0;}int test_defaults(int board_idx) { int dir;  int mask;  int mode; int cmp;  int clk; int irq; int itstatus; uint16_t timers; int chk; uint16_t fifos; int msk; uint8_t dio; uint16_t its; uint8_t	port1_dir;   printf("===============================================================\n");   printf("Defaults Test \n");   printf("===============================================================\n");   //atest_debug();   //   // Reset board   //   InitBoard7520(board_idx);      ClearAllIO7520(board_idx);   ClearADFifo7520(board_idx);   ClearDAC1Fifo7520(0);   ClearDAC2Fifo7520(1);   ClearDinFifo7520(board_idx);   ClearCGT7520(board_idx);//   ClearITMask7520(board_idx,0xFFFF);//   ClearITOverrun7520(board_idx);   ClearDIO7520(board_idx);   ClearDIO0IrqStatus7520(board_idx);   PollDIO07520(board_idx, &dir, &mask, &mode, &cmp, &clk, &irq, &itstatus );   //   // Digital Port 0 direction   //   printf("  %-42s","Digital Port 0 direction");   if ( 0 != dir )   {      cntError++;      printf("***FAILED (direction = %X)\n",dir);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 mask   //   printf("  %-42s","Digital Port 0 mask");   if ( 0 != mask )   {      cntError++;      printf("***FAILED (mask = %X)\n",mask);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 mode   //   printf("  %-42s","Digital Port 0 mode");   if ( 0 != mode )   {      cntError++;      printf("***FAILED (mode = %X)\n",mode);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 pattern   //   printf("  %-42s","Digital Port 0 pattern");   if ( 0 != cmp )   {      cntError++;      printf("***FAILED (pattern = %X)\n",cmp);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 clock   //   printf("  %-42s","Digital Port 0 clock");   if ( 0 != clk )   {      cntError++;      printf("***FAILED (clock = %X)\n",clk);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 interrupt enable   //   printf("  %-42s","Digital Port 0 interrupt enable");   if ( 0 != irq )   {      cntError++;      printf("***FAILED (enable = %X)\n",irq);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 0 interrupt status   //   printf("  %-42s","Digital Port 0 interrupt status");   if ( 0 != itstatus )   {      cntError++;      printf("***FAILED (status = %X)\n",itstatus);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital Port 1 direction   //   printf("  %-42s","Digital Port 1 direction");   GetDIO1Direction7520(board_idx, &port1_dir);   if ( 0 != port1_dir )   {      cntError++;      printf("***FAILED (direction = %X)\n",port1_dir);	  anykey();   } else {      printf("   Passed\n");   }   //   // Timer Gates   //   printf("  %-42s","Timer Gates");   GetTimerStatus7520(board_idx, &timers);   chk = ( TS_PCLK_GATE | TS_BCLK_GATE |           TS_DCNT_GATE | TS_ACNT_GATE | TS_PCLK_RUN);   if ( 0 != (chk & timers) )   {      cntError++;      printf("***FAILED (status = %X)\n",chk & timers);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital I/O Status   //   printf("  %-42s","FIFO Status");   GetFifoStatus7520(board_idx, &fifos);   msk = FS_DAC1_EMPTY | FS_DAC2_EMPTY | FS_ADC_EMPTY | FS_DIN_EMPTY;   if ( (0x7777 & ~msk) != (0x7777 & fifos) )   {      cntError++;      printf("***FAILED (status = %X)\n",fifos);	  anykey();   } else {      printf("   Passed\n");   }   //   // Digital I/O Status   //   printf("  %-42s","Digital I/O Status");   GetDIOStatus7520(board_idx, &dio);   if ( 3 != dio )   {      cntError++;      printf("***FAILED (status = %X)\n",dio);	  anykey();   } else {      printf("   Passed\n");   }   //   // Interrupt Status   //   printf("  %-42s","Interrupt Status");   GetITStatus7520(board_idx, &its);   if ( 0 != its )   {      cntError++;      printf("***FAILED (status = %X)\n",its);	  anykey();   } else {      printf("   Passed\n");   }   return cntError;} // atest_defaults//suggests to press any key and returns number of key pressedint anykey(void) {    int x;    printf("\nPress any key to continue\n");	    SLang_init_tty(-1, 1, 1);    x = SLang_getkey();    SLang_reset_tty();        return x;}int atest_timers (int board) {   printf("===============================================================\n");   printf("Timer Test\n");   printf("==============================================================\n");   atest_timers_registers(board);   atest_timers_utc(board);   return cntError;} // atest_timers/****************************************************************************@func This function tests if Timer/Counter registers are accesible.@rdesc Returns number of failed tests.****************************************************************************/int atest_timers_registers (int board_idx){   int ti, mi;   //   // Write each 8254 mode, read back, compare   //   printf("  --------------------------------------------------------------\n");   printf("  Timer/Counter Register I/O Test\n");   printf("  --------------------------------------------------------------\n");   for (ti=TC_UTC0;ti<cntTIMERS;ti++)   {      printf("    %s (write & read Mode Register)\n",szTimer[ti]);      for (mi=0;mi<cnt8254MODES;mi++)      {	 uint8_t	mode;         printf("      MODE: %-32s",sz8254Mode[mi]);         Set8254Mode7520(board_idx,ti,mi);	 Get8254Mode7520(board_idx,ti,&mode);         if ( mi != mode )         {            cntError++;            printf("***FAILED\n");            anykey();         } else {            printf("   Passed\n");         }      } // for mi   } // for ti   //   // Restore defaults   //   InitBoard7520(board_idx);   return cntError;} // atest_timers_registers/****************************************************************************@func This function tests the 3 User Timer/Counters.@rdesc Returns number of failed tests.****************************************************************************/int atest_timers_utc (int board_idx){   int i;   uint16_t cnt1, cnt2;   int diff;   uint8_t status;   int modeTC0 =-1;
   uint16_t  countTC0=0;
      //   // Setup user counter to 200 Hz, not gated   // read count, wait 3 msec, read count again ==> should have changed   //   printf("  --------------------------------------------------------------\n");   printf("  User Timer/Counter Test\n");   printf("  --------------------------------------------------------------\n");   //   // User TC 0   //   printf("    %s Gate Test\n",szTimer[TC_UTC0]);   printf("      %-38s","Not Gated                   [running]");   SetUtc0Clock7520(board_idx,CUTC0_8MHZ);   SetUtc0Gate7520(board_idx,GUTC0_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC0,M8254_RATE_GENERATOR,40000);   Get8254Status7520(board_idx, TC_UTC0,&status);   if (status!=0xB4) {      cntError++;      printf("wrong 8254 status=%X  (B4 expected)\n",status);      anykey();    }            Get8254Count7520(board_idx,TC_UTC0,&cnt1);   Get8254Count7520(board_idx,TC_UTC0,&cnt2);   if ( cnt1 == cnt2 )   {      cntError++;      printf("***FAILED (not running)\n");      anykey();   } else {      printf("   Passed \n");   }   //   // Make user counter gated, read count several times   // ==> must not change   //   printf("      %-38s","Gated                   [not running]");   SetUtc0Clock7520(board_idx,CUTC0_8MHZ);   SetUtc0Gate7520(board_idx,GUTC0_GATED);   SetupTimerCounter7520(board_idx,TC_UTC0,M8254_RATE_GENERATOR,40000);   Get8254Count7520(board_idx,TC_UTC0,&cnt1);   for (i=0;i<100;i++)   {      Get8254Count7520(board_idx,TC_UTC0,&cnt2);      if ( cnt1 != cnt2 )      {         cntError++;         printf("***FAILED (%u != %u)\n",cnt2,cnt1);         anykey();         break;      }   } // for i

   ReadTimerCounter7520(board_idx, TC_UTC0, &modeTC0, &countTC0);
   
   if ((modeTC0==M8254_RATE_GENERATOR)&&(countTC0==cnt1)&&(cnt1 == cnt2 ))   {      printf("   Passed\n");   }
   else {
         cntError++;
         printf("***FAILED TC0 mode=%d (expected=%d), countTC0=%d (40000), cnt1=%d (40000), cnt2=%d (40000)\n",
			 modeTC0,M8254_RATE_GENERATOR,countTC0,cnt1,cnt2);
         anykey();
   }   //   // User TC 1   //   printf("    %s Gate Test\n",szTimer[TC_UTC1]);   printf("      %-38s","Not Gated                   [running]");   SetUtc1Clock7520(board_idx,CUTC1_8MHZ);   SetUtc1Gate7520(board_idx,GUTC1_NOT_GATED);   SetupTimerCounter7520(board_idx,TC_UTC1,M8254_RATE_GENERATOR,40000);     Get8254Count7520(board_idx,TC_UTC1,&cnt1);   Get8254Count7520(board_idx,TC_UTC1,&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]");   SetUtc1Clock7520(board_idx,CUTC1_8MHZ);

⌨️ 快捷键说明

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