diff --git a/src/ca/evtime.c b/src/ca/evtime.c new file mode 100644 index 000000000..f058b596e --- /dev/null +++ b/src/ca/evtime.c @@ -0,0 +1,88 @@ + +#include +#include + +void event_handler(struct event_handler_args args); +int main(int argc, char **argv); +int evtime(char *pname); + +static unsigned iteration_count; +static unsigned last_time; +static double rate; + +#ifndef vxWorks +main(int argc, char **argv) +{ + char *pname; + + if(argc == 2){ + pname = argv[1]; + evtime(pname); + } + else{ + printf("usage: %s ", argv[0]); + } +} +#endif + + + + +/* + * evtime() + */ +int evtime(char *pname) +{ + chid chan; + int status; + + status = ca_search(pname, &chan); + SEVCHK(status, NULL); + + status = ca_pend_io(10.0); + if(status != ECA_NORMAL){ + printf("%s not found\n", pname); + return OK; + } + + rate = sysClkRateGet(); + + status = ca_add_event( + DBR_FLOAT, + chan, + event_handler, + NULL, + NULL); + SEVCHK(status, __FILE__); + + status = ca_pend_event(0.0); + SEVCHK(status, NULL); +} + + +/* + * event_handler() + * + */ +void event_handler(struct event_handler_args args) +{ + unsigned current_time; +# define COUNT 0x8000 + double interval; + double delay; + + if(iteration_count%COUNT == 0){ + current_time = tickGet(); + if(last_time != 0){ + interval = current_time - last_time; + delay = interval/(rate*COUNT); + printf("Delay = %f sec for 1 event\n", + delay, + COUNT); + } + last_time = current_time; + } + + iteration_count++; +} +