From f94e601981410c1b03d0d9706ddbc51a69fd6248 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 Feb 2015 08:04:25 -0600 Subject: [PATCH] Add an IOCTL method to the RTC interface --- arch/arm/src/stm32/stm32_rtc_lowerhalf.c | 1 + drivers/timers/rtc.c | 12 +++++++++++- include/nuttx/rtc.h | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c index 1a7c1e27d3..7c4aaf221b 100644 --- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c @@ -118,6 +118,7 @@ static const struct rtc_ops_s g_rtc_ops = .rdwkalm = NULL, .setwkalm = NULL, #endif + .ioctl = NULL, .destroy = NULL, }; diff --git a/drivers/timers/rtc.c b/drivers/timers/rtc.c index 1d4a0c8278..f3231ded11 100644 --- a/drivers/timers/rtc.c +++ b/drivers/timers/rtc.c @@ -502,8 +502,18 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; #endif /* CONFIG_RTC_ALARM */ + /* Forward any unrecognized IOCTLs to the lower half driver... they + * may represent some architecture-specific command. + */ + default: - ret = -ENOTTY; + { + ret = -ENOTTY; + if (ops->ioctl) + { + ret = ops->ioctl(upper->lower, cmd, arg); + } + } break; } diff --git a/include/nuttx/rtc.h b/include/nuttx/rtc.h index a84eaf7b89..d9a4e45d7d 100644 --- a/include/nuttx/rtc.h +++ b/include/nuttx/rtc.h @@ -261,6 +261,16 @@ #define RTC_WKALM_SET _RTCIOC(0x0010) +/* Architecture-specific RTC IOCTLS should begin at RTC_USER_IOCBASE. For + * example: + * + * #define MY_RTC_IOCTL1 _RTCIOC(RTC_USER_IOCBASE); + * #define MY_RTC_IOCTL2 _RTCIOC(RTC_USER_IOCBASE + 1); + * etc. + */ + +#define RTC_USER_IOCBASE 0x0011 + /**************************************************************************** * Public Types ****************************************************************************/ @@ -406,6 +416,11 @@ struct rtc_ops_s FAR const struct rtc_wkalrm *wkalrm); #endif + /* Support for architecture-specific RTC operations */ + + CODE int (*ioctl)(FAR struct rtc_lowerhalf_s *lower, int cmd, + unsigned long arg); + /* The driver has been unlinked and there are no further open references * to the driver. */