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

📄 testtc.c

📁 AT91RM9200的嵌入式LINUX下GPIO驱动
💻 C
字号:
/* testtc.c* test file for testing AT91RM9200 tc, deals with the Timer/Counter 1*/#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <sched.h>  #include <unistd.h>#include <string.h>#include <errno.h>#include <linux/termios.h>#include <fcntl.h>#include <asm/param.h>#include <asm/arch/hardware.h>  /* get all the AT91 def's */#include <asm/arch/tc.h>  /* get all the tc ioctl def's */int main(int argc, char **argv)  {  unsigned int cntr;  struct at91_tc_ioctl_clock tc_clock;  struct at91_pck_ioctl pmc_pck;  char *filename4 = "/dev/tc1";  int file4;#define AT91C_START_CNT -1  /* almost forever */unsigned int rd_wr_sz = AT91C_START_CNT;  printf ("tc test program\n");  if (argc <= 1)    {    printf("testtc [period] [pin_on_off(1 or 0)] [dev (/dev/tca29]\n");    printf("\t period: period of TIOA1\n");    }  if (argc > 1)  /* how many loops to take */    rd_wr_sz = atoi (argv[1]);  if ((file4 = open(filename4, O_RDWR)) < 0)    {    printf ("open failed %s\n", filename4);    exit(1);    }#define AT91_DAS_FREQ 960  tc_clock.tc_rc = AT91C_TC_TIMER_DIV1_CLK / AT91_DAS_FREQ;  /* set to 960 Hz */  tc_clock.tc_ra = ((AT91C_TC_TIMER_DIV1_CLK / AT91_DAS_FREQ) * 31) / 32;  /* make 1/32 high pulse */  tc_clock.tc_ccr = AT91C_TC_CLKEN | AT91C_TC_SWTRG;  /* Channel Control Register */  tc_clock.tc_cmr = AT91C_TC_ACPA_SET | AT91C_TC_ACPC_CLEAR | AT91C_TC_WAVE |     AT91C_TC_WAVESEL_UP_AUTO | AT91C_TC_TIMER_DIV1_CLOCK;  /* Channel Mode Register */  tc_clock.tcb_bcr = 0;  /* TC Block Control Register */  tc_clock.tcb_bmr = 0;  /* TC Block Mode Register */  tc_clock.p_pio = AT91C_BASE_PIOA;  /* PIO port if any */  tc_clock.pio_asr = 0;  /* ASR for above port if any */  tc_clock.pio_bsr = AT91C_PA19_TIOA1;  /* BSR for above port if any */  if (ioctl(file4, AT91_TC_SET_CLOCK, &tc_clock) != 0)  /* write the data */    {    perror ("AT91_TC_SET_CLOCK failed");    close (file4);    exit (1);    }   /* now program the 288 kHz pin to the power supply 18.432 MHz / 64 */  pmc_pck.pck_no = 0;  /* Select PCK0 */  pmc_pck.pmc_pck = AT91C_PMC_PRES_CLK_64 | AT91C_PMC_CSS_MAIN_CLK;  /* TC Block Mode Register */  pmc_pck.p_pio = AT91C_BASE_PIOB;  /* PIO port if any */  pmc_pck.pio_asr = AT91C_PB27_PCK0;  /* ASR for above port if any */  pmc_pck.pio_bsr = 0;  /* BSR for above port if any */  if (ioctl(file4, AT91_TC_ENABLE_PCK, &pmc_pck) != 0)  /* write the data */    {    perror ("AT91_TC_SET_CLOCK failed");    close (file4);    exit (1);    }   sleep(500);  close (file4);  exit(0);  }

⌨️ 快捷键说明

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