示例#1
0
文件: main.c 项目: sndae/b3r1
int main (void)
{
    Initialization();

    show_mhz();				// Display CPU speed
    TimerWait(1000);		// Wait 1 second

    while(1)
    {
        printLCD("Show ADC");			// Display the text in quotes on the LCD
        while (!KEY_VALID);				// Wait for joystick to be moved or pressed.
        if (getkey() == 1)				// If enter was pressed then do what is in the braces, just skip over it.
        {
            TimerWait(500);				// debounce joystick button
            showADC();
            printLCD("Back ADCs");
            TimerWait(2000);
        }

        printLCD("Balance");			// Display the text in quotes on the LCD
        while (!KEY_VALID);				// Wait for joystick to be moved or pressed.
        if (getkey() == 1)				// If enter was pressed then do what is in the braces, else just continue.
        {
            TimerWait(500);				// debounce joystick button
            balance();
            printLCD("Back Balance");
            TimerWait(2000);
        }

        printLCD("rprintf");			// Display the text in quotes on the LCD
        while (!KEY_VALID);				// Wait for joystick to be moved or pressed.
        if (getkey() == 1)				// If enter was pressed then do what is in the braces, else just continue.
        {
            TimerWait(500);				// debounce joystick button
            rprintf_test();
            printLCD("Back rprintf");
            TimerWait(2000);
        }

        printLCD("PWM Test");			// Display the text in quotes on the LCD
        while (!KEY_VALID);				// Wait for joystick to be moved or pressed.
        if (getkey() == 1)				// If enter was pressed then do what is in the braces, else just continue.
        {
            TimerWait(500);				// debounce joystick button
            PWM_Test();
            printLCD("Back PWM Test");
            TimerWait(3000);
        }
    }
}
示例#2
0
int main(int argc, char *argv[])
{
   struct timespec ts,ts1;
   int i,ncpu;
   int idcpu;
   unsigned long freq[8];
   XEvent event;
   char gov[20];
   char drv[20],*ptr,*endptr;
   char prg[LN_PATH];
   ts.tv_sec=0;
   ts.tv_nsec=DELAY;
   prg[0]=0;
   idcpu=0;

   for(i=0;i<MAX_CPU;i++)
     freq[i]=0;
   if(argc >1)
     {
	for (i=1; i<=argc; i++)
	  {
	     if (!strcmp(argv[i], "-v"))
	       {
		  printf(WMCPUFREQ_VERSION);
		  exit(0);
	       }
	     if (!strcmp(argv[i], "-exe"))
	       {
		  if(strlen(argv[i+1]) < LN_PATH )
		    strcpy(prg,argv[i+1]);
		  break;
	       }
	     if (!strcmp(argv[i], "-cpuid"))
	       {
		 if(strlen(argv[i+1]) < LN_PATH )
		   idcpu=strtol(argv[i+1],&endptr,0);
		 printf("cpuid= %d \n",idcpu);
		 break;
	       }
	     printf("only -v, -exe, -cpuid supported \n");
	     exit(0);
	  }
     }

   /* basic checks */
   if ( idcpu < 0 )
     {
       printf("cpuid < 0 \n");
       exit(-1);
     }

   /* get driver name (guess all cpu have the same driver) */
   ptr=cpufreq_get_driver(cpu);
   if(!ptr)
     {
	printf("no driver found \n");
	exit(-1);
     }
   strcpy(drv,ptr);
   cpufreq_put_driver(ptr);


   /* get number of cpu (0=cpu0, 1=cpu1 ...) */

   ncpu=-1;

   for(i=0;i<MAX_CPU;i++)
     {
       if( cpufreq_cpu_exists(idcpu+i) ==0)
	 {
	   printf("cpuid %d found\n",idcpu+i);
	   ncpu=i;
	 }
     }

   switch ( ncpu ) {
   case -1:
     printf("no cpuid found \n");
     exit(-1);
   case 0:
     wm_xpm=wmcpufreq_master_xpm_1;
     wm_bits=wmcpufreq_mask_bits_1;
     break;
   case 1:
     wm_xpm=wmcpufreq_master_xpm_2;
     wm_bits=wmcpufreq_mask_bits_2;
     break;
   case 2:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   case 3:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   default:
     printf("no yet implemented: cpuid %d \n",ncpu);
     exit(-1);
     break;
   }

   /* guess every cpu has the same limits */
   if(cpufreq_get_hardware_limits(cpu, &f_min, &f_max))
     {
	printf("can't determine hardware limits \n");
	exit(-1);
     }
   openXwindow(argc,argv,
	       wm_xpm,
	       (char*)wm_bits,
	       wmcpufreq_mask_width,
               wmcpufreq_mask_height);
   while(1)
     {
	/* Process any pending X events */
	while(XPending(display))
	  {
	     XNextEvent(display, &event);
	     switch(event.type)
	       {
		case Expose:
		  RedrawWindow();
		  break;
		case ButtonPress:
		  if(strlen(prg))
		    execCommand(prg);
		  break;
		case ButtonRelease:
		  break;
	       }
	  }
	RedrawWindow();
	/* get info */
	for(i=0;i<=ncpu;i++)
	  freq[i]=cpufreq_get_freq_kernel(i+idcpu);
	policy=cpufreq_get_policy(cpu);
	strcpy(gov,policy->governor);
	max=policy->max;
	min=policy->min;
	cpufreq_put_policy(policy);
	/* show info */
	show_mhz(freq,ncpu);
	if (ncpu==0)
	  show_driver(drv);
	show_governor(gov);
	/* delay */
	nanosleep(&ts,&ts1);
     }
}