Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Related Pages  

PWMcontrol.c

00001 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <sys/ioctl.h>
00012 #include <unistd.h>
00013 #include <sys/types.h>
00014 #include <asm/types.h>
00015 #include <sys/stat.h>
00016 #include <fcntl.h>
00017 #include <signal.h>
00018 #include <sched.h>
00019 #include <sys/resource.h>
00020 #include <sys/io.h>
00021 #include <E12user.h>
00022 #include <packet.h>
00023 #include <coprocessor.h>
00024 
00025 
00026 
00027 #define ARGCHECK(num1,num2){if((argc!=num1)&&(argc!=num2)){printf("invalid number of arguements\n");help();return -1;}}
00028 
00029 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00030 
00031 static int help(void)
00032 {
00033 const char *help_table = "**********************************************
00034 *PWMcontrol                                  *
00035 *Nathan Z. Gustavson                         *
00036 *Emac.inc                                    * 
00037 *"__DATE__"                                 *   
00038 *usage:                                      *   
00039 *PWMcontrol device pwm freq duty             *
00040 *ex:                                         *
00041 *version /dev/37e12 0 1000 50                *
00042 *Sets pwm 0 to 1000kHz at 50% duty cycle     *
00043 *Or                                          *
00044 *PWMcontrol device 0xff                      *
00045 *to display current PWM configurations       *
00046 **********************************************\n";
00047 printf("%s",help_table);
00048 return 0;
00049 }
00050 
00051 static int displayPWMs(Cop_Data *Cop)
00052 {
00053 int pwm;
00054   printf("pwm\tfreq\tduty\t\n");
00055 for(pwm=0;pwm<PWMNUM;pwm++)
00056   printf("%u\t%u\t%u\t\n",Cop->PWM_config[pwm].pwm,Cop->PWM_config[pwm].frequency,Cop->PWM_config[pwm].duty);
00057 
00058 return 0;
00059 }
00060 
00061 int main(int argc, char **argv)
00062 {
00063 int fd;
00064 int pwm,freq,duty;
00065 Cop_Data *Cop = CopDeviceCreate(0);
00066 
00067 ARGCHECK(5,3);
00068 OPENDEV(fd,argv[1]);
00069 
00070 pwm = strtoul(argv[2],NULL,0);
00071 
00072 if(pwm==0xff)
00073   {
00074     UpdatetHardwarePWMInfo(fd, Cop);//read current PWM configuration from the hardware and copy it into Cop
00075     displayPWMs(Cop);//display PWM configuration
00076   }
00077 else
00078   {//set PWM configuration
00079     freq = strtoul(argv[3],NULL,0);
00080     duty = strtoul(argv[4],NULL,0);
00081     E12_PWMControl(fd,pwm, freq, duty, Cop);
00082   }
00083 
00084 close(fd);
00085 CopDeviceDestroy(Cop);
00086 
00087 return 0;
00088 }
00089 
00090 

Generated on Thu Jan 8 09:51:00 2004 for PCM-37e12 by doxygen1.2.15