Commit 2ad892cd authored by Philippe Gerum's avatar Philippe Gerum Committed by Jan Kiszka
Browse files

testsuite/gpiotest: enable timestamping on 'timestamp' argument


Signed-off-by: Philippe Gerum's avatarPhilippe Gerum <rpm@xenomai.org>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent d35f3e41
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <smokey/smokey.h> #include <smokey/smokey.h>
#include <rtdm/gpio.h> #include <rtdm/gpio.h>
#include <boilerplate/time.h>
smokey_test_plugin(interrupt, smokey_test_plugin(interrupt,
SMOKEY_ARGLIST( SMOKEY_ARGLIST(
...@@ -39,6 +40,7 @@ smokey_test_plugin(interrupt, ...@@ -39,6 +40,7 @@ smokey_test_plugin(interrupt,
"\tdevice=<device-path>\n" "\tdevice=<device-path>\n"
"\trigger={edge[-rising/falling/both], level[-low/high]}\n" "\trigger={edge[-rising/falling/both], level[-low/high]}\n"
"\tselect, wait on select(2)." "\tselect, wait on select(2)."
"\ttimestamp, enable timestamping."
); );
smokey_test_plugin(read_value, smokey_test_plugin(read_value,
...@@ -72,8 +74,10 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[]) ...@@ -72,8 +74,10 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[])
{ .name = "level-high", .flag = GPIO_TRIGGER_LEVEL_HIGH }, { .name = "level-high", .flag = GPIO_TRIGGER_LEVEL_HIGH },
{ NULL, 0 }, { NULL, 0 },
}; };
int do_select = 0, fd, ret, trigger, n, value; int do_select = 0, fd, ret, trigger, n, value, do_timestamp = 0;
const char *device = NULL, *trigname; const char *device = NULL, *trigname;
struct rtdm_gpio_readout rdo;
struct timespec now;
fd_set set; fd_set set;
smokey_parse_args(t, argc, argv); smokey_parse_args(t, argc, argv);
...@@ -95,6 +99,9 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[]) ...@@ -95,6 +99,9 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[])
if (SMOKEY_ARG_ISSET(interrupt, select)) if (SMOKEY_ARG_ISSET(interrupt, select))
do_select = SMOKEY_ARG_BOOL(interrupt, select); do_select = SMOKEY_ARG_BOOL(interrupt, select);
if (SMOKEY_ARG_ISSET(interrupt, timestamp))
do_timestamp = SMOKEY_ARG_BOOL(interrupt, timestamp);
trigger = GPIO_TRIGGER_NONE; trigger = GPIO_TRIGGER_NONE;
if (SMOKEY_ARG_ISSET(interrupt, trigger)) { if (SMOKEY_ARG_ISSET(interrupt, trigger)) {
trigname = SMOKEY_ARG_STRING(interrupt, trigger); trigname = SMOKEY_ARG_STRING(interrupt, trigger);
...@@ -131,6 +138,19 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[]) ...@@ -131,6 +138,19 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[])
return ret; return ret;
} }
} }
if (do_timestamp) {
ret = read(fd, &rdo, sizeof(rdo));
if (ret < 0) {
ret = -errno;
warning("failed reading from %s [%s]",
device, symerror(ret));
return ret;
}
clock_gettime(CLOCK_MONOTONIC, &now);
printf("received irq %llu us from now, GPIO state=%d\n",
(timespec_scalar(&now) - rdo.timestamp) / 1000ULL,
rdo.value);
} else {
ret = read(fd, &value, sizeof(value)); ret = read(fd, &value, sizeof(value));
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
...@@ -140,6 +160,7 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[]) ...@@ -140,6 +160,7 @@ static int run_interrupt(struct smokey_test *t, int argc, char *const argv[])
} }
printf("received irq, GPIO state=%d\n", value); printf("received irq, GPIO state=%d\n", value);
} }
}
close(fd); close(fd);
......
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