Lines Matching +full:time +full:- +full:out
4 * SPDX-License-Identifier: Apache-2.0
22 /* Time indices in RTC RAM */
40 /* Alarm time indices in RTC RAM */
45 /* Registers A-D indeces in RTC RAM */
70 /* Update-ended Interrupt Enable bit in REG_B */
91 /* Update-end Flag bit in REG_C */
100 /* Maximum and Minimum values of time */
113 #define MIN_YEAR_DIFF 0 /* YEAR - 1900 */
114 #define MAX_YEAR_DIFF 99 /* YEAR - 1999 */
148 if (timeptr->tm_sec < MIN_SEC || timeptr->tm_sec > MAX_SEC) { in rtc_mc146818_validate_time()
151 if (timeptr->tm_min < MIN_MIN || timeptr->tm_min > MAX_MIN) { in rtc_mc146818_validate_time()
154 if (timeptr->tm_hour < MIN_HOUR || timeptr->tm_hour > MAX_HOUR) { in rtc_mc146818_validate_time()
157 if (timeptr->tm_wday + 1 < MIN_WDAY || timeptr->tm_wday + 1 > MAX_WDAY) { in rtc_mc146818_validate_time()
160 if (timeptr->tm_mday < MIN_MDAY || timeptr->tm_mday > MAX_MDAY) { in rtc_mc146818_validate_time()
163 if (timeptr->tm_mon + 1 < MIN_MON || timeptr->tm_mon + 1 > MAX_MON) { in rtc_mc146818_validate_time()
166 if (timeptr->tm_year - 70 < MIN_YEAR_DIFF || timeptr->tm_year - 70 > MAX_YEAR_DIFF) { in rtc_mc146818_validate_time()
174 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_set_time()
180 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_set_time()
183 ret = -EINVAL; in rtc_mc146818_set_time()
184 goto out; in rtc_mc146818_set_time()
187 /* Check time valid */ in rtc_mc146818_set_time()
189 ret = -EINVAL; in rtc_mc146818_set_time()
190 goto out; in rtc_mc146818_set_time()
196 year = (1900 + timeptr->tm_year) % 100; in rtc_mc146818_set_time()
197 cent = (1900 + timeptr->tm_year) / 100; in rtc_mc146818_set_time()
199 rtc_write(RTC_SEC, (uint8_t)timeptr->tm_sec); in rtc_mc146818_set_time()
200 rtc_write(RTC_MIN, (uint8_t)timeptr->tm_min); in rtc_mc146818_set_time()
201 rtc_write(RTC_HOUR, (uint8_t)timeptr->tm_hour); in rtc_mc146818_set_time()
202 rtc_write(RTC_WDAY, (uint8_t)timeptr->tm_wday); in rtc_mc146818_set_time()
203 rtc_write(RTC_MDAY, (uint8_t)timeptr->tm_mday); in rtc_mc146818_set_time()
204 rtc_write(RTC_MONTH, (uint8_t)timeptr->tm_mon + 1); in rtc_mc146818_set_time()
211 out: in rtc_mc146818_set_time()
212 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_set_time()
218 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_get_time()
224 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_get_time()
228 ret = -EINVAL; in rtc_mc146818_get_time()
229 goto out; in rtc_mc146818_get_time()
233 ret = -ENODATA; in rtc_mc146818_get_time()
234 goto out; in rtc_mc146818_get_time()
243 timeptr->tm_mon = rtc_read(RTC_MONTH) - 1; in rtc_mc146818_get_time()
244 timeptr->tm_mday = rtc_read(RTC_MDAY); in rtc_mc146818_get_time()
245 timeptr->tm_wday = rtc_read(RTC_WDAY) - 1; in rtc_mc146818_get_time()
246 timeptr->tm_hour = rtc_read(RTC_HOUR); in rtc_mc146818_get_time()
247 timeptr->tm_min = rtc_read(RTC_MIN); in rtc_mc146818_get_time()
248 timeptr->tm_sec = rtc_read(RTC_SEC); in rtc_mc146818_get_time()
250 timeptr->tm_year = 100 * (int)cent + year - 1900; in rtc_mc146818_get_time()
252 timeptr->tm_nsec = 0; in rtc_mc146818_get_time()
253 timeptr->tm_yday = 0; in rtc_mc146818_get_time()
256 /* Check time valid */ in rtc_mc146818_get_time()
258 ret = -ENODATA; in rtc_mc146818_get_time()
259 goto out; in rtc_mc146818_get_time()
262 out: in rtc_mc146818_get_time()
263 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_get_time()
271 (timeptr->tm_sec < MIN_SEC || timeptr->tm_sec > MAX_SEC)) { in rtc_mc146818_validate_alarm()
276 (timeptr->tm_min < MIN_MIN || timeptr->tm_min > MAX_MIN)) { in rtc_mc146818_validate_alarm()
281 (timeptr->tm_hour < MIN_HOUR || timeptr->tm_hour > MAX_HOUR)) { in rtc_mc146818_validate_alarm()
294 return -EINVAL; in rtc_mc146818_alarm_get_supported_fields()
307 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_alarm_set_time()
310 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_alarm_set_time()
313 ret = -EINVAL; in rtc_mc146818_alarm_set_time()
314 goto out; in rtc_mc146818_alarm_set_time()
318 ret = -EINVAL; in rtc_mc146818_alarm_set_time()
319 goto out; in rtc_mc146818_alarm_set_time()
322 /* Check time valid */ in rtc_mc146818_alarm_set_time()
324 ret = -EINVAL; in rtc_mc146818_alarm_set_time()
325 goto out; in rtc_mc146818_alarm_set_time()
329 rtc_write(RTC_ALARM_SEC, timeptr->tm_sec); in rtc_mc146818_alarm_set_time()
335 rtc_write(RTC_ALARM_MIN, timeptr->tm_min); in rtc_mc146818_alarm_set_time()
340 rtc_write(RTC_ALARM_HOUR, timeptr->tm_hour); in rtc_mc146818_alarm_set_time()
347 out: in rtc_mc146818_alarm_set_time()
348 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_alarm_set_time()
355 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_alarm_get_time()
359 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_alarm_get_time()
362 ret = -EINVAL; in rtc_mc146818_alarm_get_time()
363 goto out; in rtc_mc146818_alarm_get_time()
367 ret = -EINVAL; in rtc_mc146818_alarm_get_time()
368 goto out; in rtc_mc146818_alarm_get_time()
375 timeptr->tm_sec = value; in rtc_mc146818_alarm_get_time()
381 timeptr->tm_min = value; in rtc_mc146818_alarm_get_time()
387 timeptr->tm_hour = value; in rtc_mc146818_alarm_get_time()
392 out: in rtc_mc146818_alarm_get_time()
393 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_alarm_get_time()
400 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_alarm_set_callback()
403 return -EINVAL; in rtc_mc146818_alarm_set_callback()
406 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_alarm_set_callback()
408 dev_data->cb = callback; in rtc_mc146818_alarm_set_callback()
409 dev_data->cb_data = user_data; in rtc_mc146818_alarm_set_callback()
419 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_alarm_set_callback()
425 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_alarm_is_pending()
429 return -EINVAL; in rtc_mc146818_alarm_is_pending()
432 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_alarm_is_pending()
434 ret = dev_data->alarm_pending ? 1 : 0; in rtc_mc146818_alarm_is_pending()
435 dev_data->alarm_pending = false; in rtc_mc146818_alarm_is_pending()
437 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_alarm_is_pending()
446 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_update_set_callback()
448 k_spinlock_key_t key = k_spin_lock(&dev_data->lock); in rtc_mc146818_update_set_callback()
450 dev_data->update_cb = callback; in rtc_mc146818_update_set_callback()
451 dev_data->update_cb_data = user_data; in rtc_mc146818_update_set_callback()
462 k_spin_unlock(&dev_data->lock, key); in rtc_mc146818_update_set_callback()
470 struct rtc_mc146818_data * const dev_data = dev->data; in rtc_mc146818_isr()
480 if (dev_data->cb) { in rtc_mc146818_isr()
481 dev_data->cb(dev, 0, dev_data->cb_data); in rtc_mc146818_isr()
482 dev_data->alarm_pending = false; in rtc_mc146818_isr()
484 dev_data->alarm_pending = true; in rtc_mc146818_isr()
491 if (dev_data->update_cb) { in rtc_mc146818_isr()
492 dev_data->update_cb(dev, dev_data->update_cb_data); in rtc_mc146818_isr()