Commit 73914923 authored by Miguel Jimenez Lopez's avatar Miguel Jimenez Lopez

sw: Improve user command line arguments for irq-demo

parent 2dba3f53
......@@ -80,7 +80,7 @@ int add_usr_timestamp_to_stats_engine(stats_engine engine, struct timespec *ts)
return 0;
}
int run_stats_engine(stats_engine engine)
int run_stats_engine(stats_engine engine, int verbose)
{
struct timespec ts;
int neg;
......@@ -100,7 +100,7 @@ int run_stats_engine(stats_engine engine)
engine->stats.ts_per_second = count_ts;
engine->stats.ts_total++;
log_stats_engine(engine, 0);
log_stats_engine(engine, verbose);
update_index_stats_engine(&engine->current_ts);
......
......@@ -27,7 +27,7 @@ int enable_log_for_stats_engine(stats_engine engine);
int disable_log_for_stats_engine(stats_engine engine);
int add_usr_timestamp_to_stats_engine(stats_engine engine,
struct timespec *ts);
int run_stats_engine(stats_engine engine);
int run_stats_engine(stats_engine engine, int verbose);
void destroy_stats_engine(stats_engine engine);
#endif
......@@ -22,6 +22,7 @@
struct _user_args {
char *fmc_dev_path;
unsigned int irq_period;
int verbose;
};
typedef struct _user_args * user_args;
......
......@@ -29,6 +29,8 @@
/* Static data for signal handlers */
static fmc_dio_device global_fmc_dev = NULL;
/* Global verbose control */
static int verbose_mode = 0;
/*
* irq-demo /dev/<fmc-device-file> [<irq period>]
......@@ -75,11 +77,13 @@ int main(int argc, char *argv[])
user_arguments = create_user_arguments();
if(parse_user_arguments(argc, argv, user_arguments)) {
/* In case of failure, show the help message and exit */
show_help();
ret = 1;
goto out_log;
}
/* Set verbose mode from user command line */
verbose_mode = user_arguments->verbose;
/* Create stats engine to compute timestamps metrics (difference, mean, stdev) */
sengine = create_stats_engine();
if(check_stats_engine(sengine)) {
......@@ -176,7 +180,7 @@ static void process_timestamps_to_engine(stats_engine engine, struct timespec *t
/* Pass a timestamp to stats engine */
add_usr_timestamp_to_stats_engine(engine, &ts[i]);
/* Compute stats taking into consideration all the timestamps inside the engine */
run_stats_engine(engine);
run_stats_engine(engine, verbose_mode);
}
/* Finally, free memory for timestamps (reserved by FMC DIO device) */
......@@ -194,15 +198,28 @@ static user_args create_user_arguments(void)
static int parse_user_arguments(int argc, char *argv[], user_args parsed_args)
{
if(argc != 2 && argc != 3)
return 1;
parsed_args->fmc_dev_path = argv[1];
if(argc == 3)
sscanf(argv[2], "%d", &parsed_args->irq_period);
else
parsed_args->irq_period = TEST_FMC_DIO_PERIOD;
int opt;
parsed_args->irq_period = TEST_FMC_DIO_PERIOD;
parsed_args->verbose = 0;
while((opt = getopt(argc, argv, "hvf:p:")) != -1) {
switch(opt) {
case 'f':
parsed_args->fmc_dev_path = optarg;
break;
case 'p':
sscanf(optarg, "%d", &parsed_args->irq_period);
break;
case 'v':
parsed_args->verbose = 1;
break;
case 'h':
default:
show_help();
return 1;
}
}
return 0;
}
......@@ -216,7 +233,11 @@ static void destroy_user_arguments(user_args args)
static void show_help(void)
{
printf("usage: %s <FMC device path> [<irq period (ns)>]\n", PROG_NAME);
printf("%s -f <FMC DIO device path> [options]\n", PROG_NAME);
printf("\t -f <path> \tSet FMC DIO device path\n");
printf("\t -p <period> \tSet IRQ period (in nanoseconds)\n");
printf("\t -v \t\tEnable verbose mode\n");
printf("\t -h \t\tShow this help message\n");
}
static unsigned int check_user_stop(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment