From 0723226bdad20721b658e8552b2833e0bf5f78e5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 2 Apr 2016 13:55:58 -0600 Subject: [PATCH] RTC: Further simplications of the RTC driver interface; Add sample implem. --- arch | 2 +- drivers/timers/rtc.c | 47 +++++--------------------------------- include/nuttx/timers/rtc.h | 21 ++++------------- 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/arch b/arch index 97812e3a3e1..fcd1c6ab800 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 97812e3a3e124c579a66b07a79a5595c84123d5d +Subproject commit fcd1c6ab800ebf8ac14e00cea9ab62c23c3df457 diff --git a/drivers/timers/rtc.c b/drivers/timers/rtc.c index 9f9915a8e3a..a659b69ea9b 100644 --- a/drivers/timers/rtc.c +++ b/drivers/timers/rtc.c @@ -349,43 +349,6 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; #ifdef CONFIG_RTC_ALARM - /* RTC_RD_ALARM reads the alarm time - * - * Argument: A writeable reference to struct rtc_rdalarm_s to receive the - * current alarm settings. - */ - - case RTC_RD_ALARM: - { - FAR struct rtc_rdalarm_s *alarminfo = - (FAR struct rtc_rdalarm_s *)((uintptr_t)arg); - int alarmid; - - DEBUGASSERT(alarminfo != NULL); - alarmid = alarminfo->id; - DEBUGASSERT(alarmid >= 0 && alarmid < RTC_NALARMS); - - /* Is the alarm active? */ - - if (upper->alarminfo[alarmid].active) - { - /* Yes, read the alarm */ - - if (ops->rdalarm) - { - ret = ops->rdalarm(upper->lower, alarminfo); - } - } - else - { - /* No.. decline the request to return the time. */ - - alarminfo->active = false; - ret = OK; - } - } - break; - /* RTC_SET_ALARM sets the alarm time. * * Argument: A read-only reference to a struct rtc_time containing the @@ -413,17 +376,19 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (ops->cancelalarm) { - ret = ops->cancelalarm(upper->lower, alarmid); + (void)ops->cancelalarm(upper->lower, alarmid); } + + upperinfo->active = false; } - upperinfo->active = false; if (ops->setalarm) { /* Save the signal info to be used to notify the caller when the * alarm expires. */ + upperinfo->active = true; upperinfo->signo = alarminfo->signo; upperinfo->pid = alarminfo->pid; upperinfo->sigvalue = alarminfo->sigvalue; @@ -438,9 +403,9 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Then set the alarm */ ret = ops->setalarm(upper->lower, &lowerinfo); - if (ret >= 0) + if (ret < 0) { - upperinfo->active = true; + upperinfo->active = false; } } } diff --git a/include/nuttx/timers/rtc.h b/include/nuttx/timers/rtc.h index ce4a2e251a9..bd7fa8c8361 100644 --- a/include/nuttx/timers/rtc.h +++ b/include/nuttx/timers/rtc.h @@ -143,28 +143,20 @@ #define RTC_SET_TIME _RTCIOC(0x0002) -/* RTC_RD_ALARM reads the alarm time (for RTCs that support alarms) - * - * Argument: A writeable reference to a struct rtc_rdalarm_s to receive the RTC's - * alarm time. - */ - -#define RTC_RD_ALARM _RTCIOC(0x0003) - /* RTC_SET_ALARM sets the alarm time (for RTCs that support alarms). * * Argument: A read-only reference to a struct rtc_setalarm_s containing the * new alarm time to be set. */ -#define RTC_SET_ALARM _RTCIOC(0x0004) +#define RTC_SET_ALARM _RTCIOC(0x0003) /* RTC_WKALRM_CANCEL cancel the alarm. * * Argument: An ALARM ID value that indicates which alarm should be canceled. */ -#define RTC_CANCEL_ALARM _RTCIOC(0x005) +#define RTC_CANCEL_ALARM _RTCIOC(0x004) /* Architecture-specific RTC IOCTLS should begin at RTC_USER_IOCBASE. For * example: @@ -174,7 +166,7 @@ * etc. */ -#define RTC_USER_IOCBASE 0x0006 +#define RTC_USER_IOCBASE 0x0005 /**************************************************************************** * Public Types @@ -269,17 +261,12 @@ struct rtc_ops_s FAR const struct rtc_time *rtctime); #ifdef CONFIG_RTC_ALARM - /* rdalarm reads the current alarm time */ - - CODE int (*rdalarm)(FAR struct rtc_lowerhalf_s *lower, - FAR struct rtc_rdalarm_s *alarminfo); - /* setalarm sets up a new alarm. */ CODE int (*setalarm)(FAR struct rtc_lowerhalf_s *lower, FAR const struct lower_setalarm_s *alarminfo); - /* cancelalarm cancels the alarm. */ + /* cancelalarm cancels the current alarm. */ CODE int (*cancelalarm)(FAR struct rtc_lowerhalf_s *lower, int alarmid); #endif