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

e12digitalGP.c

00001 /*
00002 e12digitalGP.c
00003 reads/writes/configures the coprocessors general purpose port zero
00004 7/24/03
00005 Nathan Z. Gustavson ngustavson@emacinc.com
00006 Emac.inc
00007 www.emacinc.com
00008 */
00009 
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 #include <sys/ioctl.h>
00019 #include <unistd.h>
00020 #include <sys/types.h>
00021 #include <asm/types.h>
00022 #include <sys/stat.h>
00023 #include <fcntl.h>
00024 #include <signal.h>
00025 #include <sched.h>
00026 #include <sys/resource.h>
00027 #include <sys/io.h>
00028 #include <E12user.h>
00029 #include <packet.h>
00030 #include <coprocessor.h>
00031 
00032 #define DIGRESPONSE BITMASK(PRTIN0)
00033 
00034 #define ARGCHECK(num){if(argc<=num){printf("invalid number of arguements\n");help();return -1;}}
00035 
00036 
00037 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00038 
00039 
00040 static int help(void)
00041 {
00042 const char *help_table = "**********************************************
00043 *e12digitalGP                                *
00044 *Nathan Z. Gustavson                         *
00045 *Emac.inc                                    * 
00046 *"__DATE__"                                 *
00047 *usage:                                      *   
00048 *e12digitalGP device port command (data/mask)*
00049 *commands                                    *
00050 *                                            *
00051 *I/O mask  - i mask is input/output bitmask  *
00052 *1 = output 0 = input                        *
00053 *                                            *
00054 *read      - r (mask/data) unused            *
00055 *returns current state of the pins           * 
00056 *                                            *
00057 *write     - w data                          *
00058 *drive output pins with data                 *
00059 **********************************************\n";
00060 printf("%s",help_table);
00061 return 0;
00062 }
00063 
00064 
00065 
00066 
00067 int main(int argc,char **argv)
00068 {
00069 int fd,rxnum;
00070 __u8 mask;
00071 Cop_Data *Cop = CopDeviceCreate(0);
00072 __u32 typemask=0;
00073 __u8 buffer[100];
00074 int port;
00075 
00076 ARGCHECK(3);
00077 
00078 OPENDEV(fd,argv[1]);
00079 
00080 port = strtoul(argv[2],NULL,0);
00081 
00082 if((port>1)||(port<0))
00083     {
00084       printf("invalid port %u\n",port);
00085       help();
00086       return 0;
00087     }
00088 
00089 switch(*argv[3])//switch command
00090   {
00091   case 'i':
00092     ARGCHECK(4);    
00093     mask = strtoul(argv[4],NULL,0);
00094     E12_Digital_Cfg(fd, mask,port);
00095     break;
00096 
00097   case 'r':
00098   ARGCHECK(3); 
00099   E12_Digital_Req(fd);
00100   while(!(typemask&DIGRESPONSE))
00101     {//disregard any other data
00102       rxnum =read(fd,buffer,sizeof(buffer));
00103       typemask = E12_Packet_Route(Cop,buffer, rxnum);
00104     }
00105   printf("%x\n",Cop->Digital[port]);
00106   break;
00107 
00108   case 'w':
00109     ARGCHECK(4);
00110     mask = (unsigned char)strtoul(argv[4],NULL,0);
00111     E12_Digitalout(fd,mask,port);
00112     break;
00113 
00114   default:
00115     printf("invalid command\n");
00116     help();
00117   }
00118 
00119 return 0;
00120 
00121 }
00122 
00123 

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