From 9abb28c725f9151d81a0f0a2c17a4fb5e1e18384 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 11:21:47 -0600 Subject: [PATCH] apps/examples/can: Use new IOCTL commands to show the current bit timing values --- examples/can/can_main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index 31ad280fd..d9cb977db 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -138,6 +139,7 @@ int main(int argc, FAR char *argv[]) int can_main(int argc, char *argv[]) #endif { + struct canioc_bittiming_s bt; #ifndef CONFIG_EXAMPLES_CAN_READONLY struct can_msg_s txmsg; #ifdef CONFIG_CAN_EXTID @@ -296,6 +298,24 @@ int can_main(int argc, char *argv[]) goto errout_with_dev; } + /* Show bit timing information .. if provided by the driver. Not all CAN + * drivers will support this IOCTL. + */ + + ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)((uintptr_t)&bt)); + if (ret < 0) + { + printf("Bit timing not available: %d\n", errno); + } + else + { + printf("Bit timing:\n"); + printf(" Baud: %lu\n", (unsigned long)bt.bt_baud); + printf(" TSEG1: %u\n", bt.bt_tseg1); + printf(" TSEG2: %u\n", bt.bt_tseg2); + printf(" SJW: %u\n", bt.bt_sjw); + } + /* Now loop the appropriate number of times, performing one loopback test * on each pass. */