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

divider.c

00001 /***************************************************************************
00002                           divider.c  -  description
00003                              -------------------
00004     begin                : Tue Jan 6 2004
00005     copyright            : (C) 2004 by NZG
00006     email                : ngustavson@emacinc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include <stdlib.h>
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <unistd.h>
00021 #include <sys/types.h>
00022 #include <asm/types.h>
00023 #include <sys/stat.h>
00024 #include <fcntl.h>
00025 #include <E12user.h>
00026 #include <packet.h>
00027 #include <coprocessor.h>
00028 #include <counter.h>
00029 
00030 #define ARGCHECK(num){if(argc!=num){printf("invalid number of arguements\n");help();return -1;}}
00031 
00032 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00033 
00034 static int help(void)
00035 {
00036 const char *help_table = "***************************************************
00037 *divider                                          *
00038 *Nathan Z. Gustavson                              *
00039 *EMAC.Inc                                         *
00040 *"__DATE__"                                      *
00041 *usage:                                           *
00042 *divider device in out divide                     *
00043 *ex:                                              *
00044 *divider /dev/37e12 0 1 100                       *
00045 *divides the input of digital 0 by 100 on digital1*
00046 ***************************************************\n";
00047 printf("%s",help_table);
00048 return 0;
00049 }
00050 
00051 int main(int argc, char **argv)
00052 {
00053 int fd;
00054 int in, out, divide;
00055 unsigned char mask;
00056 int data;
00057 
00058 Cop_Data *Cop;
00059 ARGCHECK(5);
00060 OPENDEV(fd,argv[1]);
00061 in = strtoul(argv[2],NULL,0);
00062 out = strtoul(argv[3],NULL,0);
00063 divide = strtoul(argv[4],NULL,0);
00064 mask = 1<<out;
00065 data = mask;
00066 //configure ports
00067 Cop = CopDeviceCreate(0);
00068 E12_Digital_Cfg(fd, mask,0); //configure output port line to output
00069 E12_CountConfig(fd, in, ANYE, divide,AUTOLOAD|ANOTE,Cop);
00070 E12_CountCommand(fd, in,ICSTART);
00071 while(1)
00072   {
00073     E12_Parse_Until(fd, Cop, NOTIFYRESPONSE);
00074     E12_Digitalout(fd,data,0);
00075     data = ((~data)&(mask));
00076   }
00077 CopDeviceDestroy(Cop);
00078 close(fd);
00079 return 0;
00080 }

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