meta-digi-dey: dey-examples-rtc: added argument for selecting device node

Signed-off-by: Jose Diaz de Grenu de Pedro <Jose.DiazdeGrenudePedro@digi.com>
https://jira.digi.com/browse/DEL-1701
This commit is contained in:
Jose Diaz de Grenu de Pedro 2015-09-16 13:30:23 +02:00
parent 7d8955430a
commit 323de7c1b6
1 changed files with 12 additions and 7 deletions

View File

@ -24,9 +24,9 @@
#include <string.h>
#define PROGRAM "rtc_test"
#define VERSION "3.0"
#define VERSION "3.1"
#define RTC_DEVICE_FILE "/dev/rtc"
#define DEFAULT_RTC_DEVICE_FILE "/dev/rtc"
/* test options */
#define RTC_TEST_RD_TIME (1<<0)
@ -38,7 +38,7 @@
#define RTC_DEFAULT_TEST_OPS 0 /* None, pass it through the command line */
#define rtc_test_usage \
"[-abcdehms]\n"
"[-abcdefhms]\n"
#define rtc_test_full_usage \
"rtc_test [options]\n\n" \
"Tests the real time clock driver\n" \
@ -48,6 +48,7 @@
" -c : Read the alarm programed value\n" \
" -d : Set the alarm to trigger in the specified seconds\n" \
" -e : Test the alarm interrupt with the specified seconds\n" \
" -f : Use specified device (default is /dev/rtc)\n" \
" -h : Help\n" \
" -m : Alarm has minutes resolution. (seconds by default)." \
" In this mode the alarm triggers on the minutes register and the" \
@ -118,12 +119,13 @@ int main(int argc, char *argv[])
unsigned int test_results = 0;
struct rtc_time rtc_tm;
struct rtc_wkalrm wkalrm;
const char rtc_device_file[10] = DEFAULT_RTC_DEVICE_FILE;
memset(&rtc_tm, 0, sizeof(struct rtc_time));
memset(&wkalrm, 0, sizeof(struct rtc_wkalrm));
if (argc > 1) {
while ((opt = getopt(argc, argv, "abcdehms:")) > 0) {
while ((opt = getopt(argc, argv, "abcdef:hms:")) > 0) {
switch (opt) {
case 'a':
test_ops |= RTC_TEST_RD_TIME;
@ -140,6 +142,9 @@ int main(int argc, char *argv[])
case 'e':
test_ops |= RTC_TEST_ALARM_IRQ;
break;
case 'f':
strncpy(rtc_device_file,optarg,10);
break;
case 'm':
minutes_res = 1;
break;
@ -162,9 +167,9 @@ int main(int argc, char *argv[])
rtc_test_banner();
rtc_fd = open(RTC_DEVICE_FILE, O_RDONLY);
rtc_fd = open(rtc_device_file, O_RDONLY);
if (rtc_fd < 0) {
perror(RTC_DEVICE_FILE);
perror(rtc_device_file);
exit(EXIT_FAILURE);
}