drivers: rtc: smartbond: Update RTC driver
This commit should fix the followings: 1. When an alarm event is initialized, the driver should only consume the valid alarm fields, based on the given mask. Otherwise, the driver should use default valid subfield values. 2. Setting an alarm event should not return with error code if the timer and/or calendar counters have yet to be initialized, explicitly. Instead, a log warning should be issued. Signed-off-by: Ioannis Karachalios <ioannis.karachalios.px@renesas.com>
This commit is contained in:
parent
b8836ab94a
commit
6f0476eb77
1 changed files with 31 additions and 9 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <DA1469xAB.h>
|
||||
#include <da1469x_config.h>
|
||||
#include <da1469x_pdc.h>
|
||||
#include "rtc_utils.h"
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(rtc_smartbond, CONFIG_RTC_LOG_LEVEL);
|
||||
|
@ -266,8 +267,7 @@ static int rtc_smartbond_get_time(const struct device *dev, struct rtc_time *tim
|
|||
}
|
||||
|
||||
if (!data->is_rtc_configured) {
|
||||
LOG_ERR("RTC is not initialized yet");
|
||||
return -ENODATA;
|
||||
LOG_WRN("RTC is not initialized yet");
|
||||
}
|
||||
|
||||
k_mutex_lock(&data->lock, K_FOREVER);
|
||||
|
@ -286,7 +286,10 @@ static int rtc_smartbond_get_time(const struct device *dev, struct rtc_time *tim
|
|||
#if defined(CONFIG_RTC_ALARM)
|
||||
BUILD_ASSERT(RTC_ALARMS_COUNT, "At least one alarm event should be supported");
|
||||
|
||||
/* Define a valid calendar value as a zero sub-field is not valid for the alarm calendar value */
|
||||
/*
|
||||
* Parse only the alarm fields indicated by the mask. Default valid values should be assigned
|
||||
* to unused fields as it might happen that application has provided with invalid values.
|
||||
*/
|
||||
static uint32_t alarm_calendar_to_bcd(const struct rtc_time *timeptr, uint16_t mask)
|
||||
{
|
||||
uint32_t rtc_calendar_alarm_reg = 0x0108;
|
||||
|
@ -304,14 +307,28 @@ static uint32_t alarm_calendar_to_bcd(const struct rtc_time *timeptr, uint16_t m
|
|||
return rtc_calendar_alarm_reg;
|
||||
}
|
||||
|
||||
/* No need to parse the alarm mask as a zero sub-field is valid for the alarm time counter. */
|
||||
static inline uint32_t alarm_time_to_bcd(const struct rtc_time *timeptr)
|
||||
/*
|
||||
* Parse only the alarm fields indicated by the mask. Default valid values should be assigned
|
||||
* to unused fields as it might happen that application has provided with invalid values.
|
||||
*/
|
||||
static inline uint32_t alarm_time_to_bcd(const struct rtc_time *timeptr, uint16_t mask)
|
||||
{
|
||||
uint32_t rtc_time_alarm_reg = 0;
|
||||
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(S, rtc_time_alarm_reg, bin2bcd(timeptr->tm_sec)); /*[0, 59]*/
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(M, rtc_time_alarm_reg, bin2bcd(timeptr->tm_min)); /*[0, 59]*/
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(HR, rtc_time_alarm_reg, bin2bcd(timeptr->tm_hour)); /*[0, 23]*/
|
||||
if (mask & RTC_ALARM_TIME_MASK_SECOND) {
|
||||
/*[0, 59]*/
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(S, rtc_time_alarm_reg, bin2bcd(timeptr->tm_sec));
|
||||
}
|
||||
|
||||
if (mask & RTC_ALARM_TIME_MASK_MINUTE) {
|
||||
/*[0, 59]*/
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(M, rtc_time_alarm_reg, bin2bcd(timeptr->tm_min));
|
||||
}
|
||||
|
||||
if (mask & RTC_ALARM_TIME_MASK_HOUR) {
|
||||
/*[0, 23]*/
|
||||
RTC_TIME_ALARM_REG_SET_FIELD(HR, rtc_time_alarm_reg, bin2bcd(timeptr->tm_hour));
|
||||
}
|
||||
|
||||
return rtc_time_alarm_reg;
|
||||
}
|
||||
|
@ -408,6 +425,11 @@ static int rtc_smartbond_alarm_set_time(const struct device *dev, uint16_t id, u
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!rtc_utils_validate_rtc_time(timeptr, mask)) {
|
||||
LOG_ERR("Invalid alarm fields values");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!data->is_rtc_configured) {
|
||||
LOG_WRN("RTC is not initialized yet");
|
||||
}
|
||||
|
@ -425,7 +447,7 @@ static int rtc_smartbond_alarm_set_time(const struct device *dev, uint16_t id, u
|
|||
rtc_time_alarm_reg = RTC->RTC_TIME_ALARM_REG;
|
||||
rtc_calendar_alarm_reg = RTC->RTC_CALENDAR_ALARM_REG;
|
||||
|
||||
RTC->RTC_TIME_ALARM_REG = alarm_time_to_bcd(timeptr);
|
||||
RTC->RTC_TIME_ALARM_REG = alarm_time_to_bcd(timeptr, mask);
|
||||
RTC->RTC_CALENDAR_ALARM_REG = alarm_calendar_to_bcd(timeptr, mask);
|
||||
|
||||
rtc_status_reg = RTC->RTC_STATUS_REG;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue