00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <sys/ioctl.h>
00025 #include <unistd.h>
00026 #include <sys/types.h>
00027 #include <asm/types.h>
00028 #include <sys/stat.h>
00029 #include <fcntl.h>
00030 #include <signal.h>
00031 #include <sched.h>
00032 #include <sys/resource.h>
00033 #include <sys/io.h>
00034 #include <E12user.h>
00035 #include <packet.h>
00036 #include <coprocessor.h>
00037 #include <counter.h>
00038 #include <curses.h>
00039
00040 #define COUNTERRESPONSE BITMASK(COUNTER)
00041 #define RPCOUNT 10 //ncurses rows per counter
00042
00043
00044 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00045
00046 static int help(void)
00047 {
00048 const char *help_table = "*******************************************************
00049 *E12count *
00050 *Nathan Z. Gustavson *
00051 *Emac.inc *
00052 *"__DATE__" *
00053 *usage: *
00054 *E12count device command mask (trigger) (thresh) (flags) *
00055 * *
00056 *triggers *
00057 *r - rising *
00058 *f - falling *
00059 *b - both *
00060 *commands *
00061 *d - display *
00062 *r - run *
00063 *h - halt *
00064 *c - config accepts the trigger,thresh&flags arguements *
00065 *s - zero signal notification on *
00066 *o - zero signal notification off *
00067 *flags *
00068 *s - autostop *
00069 *l - autoload *
00070 *n - notify at zero *
00071 * *
00072 *examples: *
00073 *E12Count /dev/37e12 c 0xff r 0x100 l n *
00074 *E12Count /dev/37e12 r 0xff *
00075 *E12Count /dev/37e12 d 0xff *
00076 ****************************************************************\n";
00077
00078
00079
00080 printf("%s",help_table);
00081
00082
00083 return 0;
00084 }
00085
00086 #define ARGCHECK(num){if(argc<num){printf("invalid number of arguements\n");help();return -1;}}
00087
00088
00089 static int onescount(__u8 mask)
00090 {
00091 int ones=0;
00092 int count;
00093
00094 for(count=0;count<=7;count++)
00095 {
00096 ones += mask&0x01;
00097 mask >>= 1;
00098 }
00099
00100 return ones;
00101 }
00102
00103
00104
00105 static int InitWindow(WINDOW *wmain,int mask)
00106 {
00107 char counterstring[50];
00108 int countnum = onescount(mask);
00109 int counter;
00110
00111 wmain = initscr();
00112 start_color();
00113 cbreak();
00114
00115 wmain = newwin((RPCOUNT*countnum),50, 0 , 0);
00116
00117 init_pair(1, COLOR_BLACK, COLOR_GREEN);
00118 wattrset(wmain,COLOR_PAIR(1));
00119 wbkgd(wmain,COLOR_PAIR(1));
00120 werase(wmain);
00121 box(wmain, ACS_VLINE, ACS_HLINE);
00122
00123
00124 for(counter=0;counter<=7;counter++)
00125 {
00126 if(mask&BITMASK(counter))
00127 {
00128 sprintf(counterstring,"counter %u",counter);
00129 mvwaddstr(wmain, RPCOUNT*counter, 3, counterstring);
00130 }
00131 }
00132
00133 wrefresh(wmain);
00134 nodelay(wmain,TRUE);
00135
00136 return 0;
00137 }
00138
00139 static int DestroyWindow(WINDOW *win)
00140 {
00141 delwin(win);
00142 endwin();
00143 return 0;
00144 }
00145
00146
00147
00148 static void DisplayCounters(int fd,__u8 mask)
00149 {
00150 Cop_Data *Cop = CopDeviceCreate(0);
00151 int rxnum;
00152 __u32 typemask;
00153 WINDOW *winmain = NULL;
00154 int counter;
00155 __u8 buffer[100];
00156
00157 InitWindow(winmain,mask);
00158
00159 while((getch())!=0x1b)
00160 {
00161 for(counter=0;counter<=7;counter++)
00162 {
00163 if(mask&BITMASK(counter))
00164 E12_CounterReadRQ(fd, counter);
00165 }
00166
00167
00168
00169 rxnum = read(fd,buffer,sizeof(buffer));
00170 typemask = E12_Packet_Route(Cop, buffer, rxnum);
00171
00172
00173 for(counter=0;counter<=7;counter++)
00174 {
00175 if(Cop->parsemask.counter&BITMASK(counter))
00176 mvwprintw(winmain, RPCOUNT*counter, 20, "[%x]",Cop->counter[counter]);
00177 }
00178 }
00179 DestroyWindow(winmain);
00180 }
00181
00182
00183
00184 int main(int argc,char **argv)
00185 {
00186 int counter=0;
00187 int trigger,flags,flagnum;
00188 int thresh=0;
00189 __u8 mask;
00190 char command;
00191 char *device;
00192 __u16 threshold;
00193 int fd;
00194
00195 printf("argc=%u\n",argc);
00196
00197 ARGCHECK(4);
00198 device = argv[1];
00199 OPENDEV(fd,device);
00200
00201 command = *argv[2];
00202 mask =(__u8)strtoul(argv[3],NULL,0);
00203
00204 switch(command)
00205 {
00206 case 'd':
00207 DisplayCounters(fd,mask);
00208 close(fd);
00209 return 0;
00210
00211
00212 case 'c':
00213 ARGCHECK(6);
00214 printf("configuration command\n");
00215
00216 trigger = NOE;
00217
00218 switch(*argv[4])
00219 {
00220 case 'r':
00221 trigger = RISEE;
00222 break;
00223 case 'f':
00224 trigger = FALLE;
00225 break;
00226 case 'b':
00227 trigger = ANYE;
00228 break;
00229 }
00230
00231
00232 threshold=strtoul(argv[5],NULL,0);
00233
00234 printf("threshold = %x\n",threshold);
00235
00236 flags = 0;
00237
00238 printf("flags=%u, parsing for flag args\n",flags);
00239 for(flagnum=0;(flagnum<(argc-6));flagnum++)
00240 {
00241 printf("parsing flag %u\n",flagnum);
00242 switch(*argv[flagnum+6])
00243 {
00244 case 's':
00245 flags|=AUTOSTOP;
00246 break;
00247
00248 case 'l':
00249 flags|=AUTOLOAD;
00250 break;
00251
00252 case 'n':
00253 flags|=ANOTE;
00254 break;
00255
00256 }
00257 }
00258
00259 printf("flags = %x\n",flags);
00260
00261 for(counter=0;counter<=7;counter++)
00262 {
00263 if(mask&BITMASK(counter))
00264 {
00265 printf("configuring counter %u\n",counter);
00266 E12_CountConfig(fd, counter, trigger, thresh,flags);
00267 }
00268 }
00269
00270 printf("counters configured");
00271 close(fd);
00272 return 0;
00273
00274
00275 case 'r':
00276 E12_CountCommand(fd,ICSTART);
00277 close(fd);
00278 return 0;
00279
00280
00281 case 'h':
00282 E12_CountCommand(fd,ICSTOP);
00283 close(fd);
00284 return 0;
00285
00286 case 's':
00287 E12_CountCommand(fd,ICNOTIFYON);
00288 close(fd);
00289 return 0;
00290
00291
00292 case 'o':
00293 E12_CountCommand(fd,ICNOTIFYOFF);
00294 close(fd);
00295 return 0;
00296 }
00297
00298
00299 printf("invalid command\n");
00300 help();
00301 close(fd);
00302 return 0;
00303 }
00304
00305
00306
00307
00308
00309
00310