Lines Matching +full:wakeup +full:- +full:line
4 * SPDX-License-Identifier: Apache-2.0
114 struct rtc_smartbond_data *data = dev->data; in smartbond_rtc_isr()
115 /* Exercise which events asserted the RTC IRQ line. Register is cleared upon read. */ in smartbond_rtc_isr()
116 uint32_t rtc_event_flags_reg = RTC->RTC_EVENT_FLAGS_REG; in smartbond_rtc_isr()
118 uint32_t rtc_interrupt_mask_reg = RTC->RTC_INTERRUPT_MASK_REG; in smartbond_rtc_isr()
123 if (data->alarm_cb) { in smartbond_rtc_isr()
124 data->alarm_cb(dev, 0, data->alarm_user_data); in smartbond_rtc_isr()
125 data->is_alarm_pending = false; in smartbond_rtc_isr()
127 data->is_alarm_pending = true; in smartbond_rtc_isr()
135 if (data->update_cb) { in smartbond_rtc_isr()
136 data->update_cb(dev, data->update_user_data); in smartbond_rtc_isr()
146 CRG_TOP->CLK_RTCDIV_REG |= CRG_TOP_CLK_RTCDIV_REG_RTC_DIV_ENABLE_Msk; in rtc_smartbond_set_status()
147 RTC->RTC_CONTROL_REG = 0; in rtc_smartbond_set_status()
149 RTC->RTC_CONTROL_REG = (RTC_RTC_CONTROL_REG_RTC_CAL_DISABLE_Msk | in rtc_smartbond_set_status()
151 CRG_TOP->CLK_RTCDIV_REG &= ~CRG_TOP_CLK_RTCDIV_REG_RTC_DIV_ENABLE_Msk; in rtc_smartbond_set_status()
159 RTC_TIME_REG_SET_FIELD(S, rtc_time_reg, bin2bcd(timeptr->tm_sec)); /*[0, 59]*/ in rtc_time_to_bcd()
160 RTC_TIME_REG_SET_FIELD(M, rtc_time_reg, bin2bcd(timeptr->tm_min)); /*[0, 59]*/ in rtc_time_to_bcd()
161 RTC_TIME_REG_SET_FIELD(HR, rtc_time_reg, bin2bcd(timeptr->tm_hour)); /*[0, 23]*/ in rtc_time_to_bcd()
170 RTC_CALENDAR_REG_SET_FIELD(D, rtc_calendar_reg, bin2bcd(timeptr->tm_mday)); /*[1, 31]*/ in rtc_calendar_to_bcd()
172 bin2bcd((timeptr->tm_year + TM_YEAR_REF) % 100)); /*[year - 1900]*/ in rtc_calendar_to_bcd()
174 bin2bcd((timeptr->tm_year + TM_YEAR_REF) / 100)); in rtc_calendar_to_bcd()
175 RTC_CALENDAR_REG_SET_FIELD(M, rtc_calendar_reg, bin2bcd(timeptr->tm_mon + 1)); /*[0, 11]*/ in rtc_calendar_to_bcd()
177 if (timeptr->tm_wday != -1) { in rtc_calendar_to_bcd()
178 rtc_calendar_reg |= ((timeptr->tm_wday + 1) & in rtc_calendar_to_bcd()
187 uint32_t rtc_time_reg = RTC->RTC_TIME_REG; in bcd_to_rtc_time()
189 timeptr->tm_sec = bcd2bin(RTC_TIME_REG_GET_FIELD(S, rtc_time_reg)); in bcd_to_rtc_time()
190 timeptr->tm_min = bcd2bin(RTC_TIME_REG_GET_FIELD(M, rtc_time_reg)); in bcd_to_rtc_time()
191 timeptr->tm_hour = bcd2bin(RTC_TIME_REG_GET_FIELD(HR, rtc_time_reg)); in bcd_to_rtc_time()
193 timeptr->tm_nsec = 0; /*Unknown*/ in bcd_to_rtc_time()
198 uint32_t rtc_calendar_reg = RTC->RTC_CALENDAR_REG; in bcd_to_rtc_calendar()
200 timeptr->tm_mday = bcd2bin(RTC_CALENDAR_REG_GET_FIELD(D, rtc_calendar_reg)); in bcd_to_rtc_calendar()
201 timeptr->tm_mon = bcd2bin(RTC_CALENDAR_REG_GET_FIELD(M, rtc_calendar_reg)) - 1; in bcd_to_rtc_calendar()
202 timeptr->tm_year = bcd2bin(RTC_CALENDAR_REG_GET_FIELD(Y, rtc_calendar_reg)) + in bcd_to_rtc_calendar()
203 (bcd2bin(RTC_CALENDAR_REG_GET_FIELD(C, rtc_calendar_reg)) * 100) - TM_YEAR_REF; in bcd_to_rtc_calendar()
204 timeptr->tm_wday = (rtc_calendar_reg & RTC_RTC_CALENDAR_REG_RTC_DAY_Msk) - 1; in bcd_to_rtc_calendar()
206 timeptr->tm_yday = timeptr->tm_isdst = -1; /*Unknown*/ in bcd_to_rtc_calendar()
211 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_set_time()
217 return -EINVAL; in rtc_smartbond_set_time()
220 if (timeptr->tm_year + TM_YEAR_REF < TM_YEAR_REF) { in rtc_smartbond_set_time()
222 return -EINVAL; in rtc_smartbond_set_time()
225 if ((timeptr->tm_yday != -1) || (timeptr->tm_isdst != -1) || (timeptr->tm_nsec != 0)) { in rtc_smartbond_set_time()
226 LOG_WRN("Unsupported RTC sub-values"); in rtc_smartbond_set_time()
229 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_set_time()
233 rtc_time_reg = RTC->RTC_TIME_REG; in rtc_smartbond_set_time()
234 rtc_calendar_reg = RTC->RTC_CALENDAR_REG; in rtc_smartbond_set_time()
236 RTC->RTC_TIME_REG = rtc_time_to_bcd(timeptr); in rtc_smartbond_set_time()
237 RTC->RTC_CALENDAR_REG = rtc_calendar_to_bcd(timeptr); in rtc_smartbond_set_time()
240 rtc_status_reg = RTC->RTC_STATUS_REG; in rtc_smartbond_set_time()
243 RTC->RTC_TIME_REG = rtc_time_reg; in rtc_smartbond_set_time()
244 RTC->RTC_CALENDAR_REG = rtc_calendar_reg; in rtc_smartbond_set_time()
245 ret = -EINVAL; in rtc_smartbond_set_time()
249 if (!data->is_rtc_configured && (ret == 0)) { in rtc_smartbond_set_time()
250 data->is_rtc_configured = true; in rtc_smartbond_set_time()
255 k_mutex_unlock(&data->lock); in rtc_smartbond_set_time()
262 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_get_time()
266 return -EINVAL; in rtc_smartbond_get_time()
269 if (!data->is_rtc_configured) { in rtc_smartbond_get_time()
273 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_get_time()
281 k_mutex_unlock(&data->lock); in rtc_smartbond_get_time()
299 bin2bcd(timeptr->tm_mday)); in alarm_calendar_to_bcd()
304 bin2bcd(timeptr->tm_mon + 1)); in alarm_calendar_to_bcd()
320 RTC_TIME_ALARM_REG_SET_FIELD(S, rtc_time_alarm_reg, bin2bcd(timeptr->tm_sec)); in alarm_time_to_bcd()
325 RTC_TIME_ALARM_REG_SET_FIELD(M, rtc_time_alarm_reg, bin2bcd(timeptr->tm_min)); in alarm_time_to_bcd()
330 RTC_TIME_ALARM_REG_SET_FIELD(HR, rtc_time_alarm_reg, bin2bcd(timeptr->tm_hour)); in alarm_time_to_bcd()
338 uint32_t rtc_calendar_alarm_reg = RTC->RTC_CALENDAR_ALARM_REG; in bcd_to_alarm_calendar()
340 timeptr->tm_mday = bcd2bin(RTC_CALENDAR_ALARM_REG_GET_FIELD(D, rtc_calendar_alarm_reg)); in bcd_to_alarm_calendar()
341 timeptr->tm_mon = bcd2bin(RTC_CALENDAR_ALARM_REG_GET_FIELD(M, rtc_calendar_alarm_reg)) - 1; in bcd_to_alarm_calendar()
343 timeptr->tm_yday = timeptr->tm_wday = timeptr->tm_isdst = timeptr->tm_year = -1; in bcd_to_alarm_calendar()
348 uint32_t rtc_time_alarm_reg = RTC->RTC_TIME_ALARM_REG; in bcd_to_alarm_time()
350 timeptr->tm_sec = bcd2bin(RTC_TIME_ALARM_REG_GET_FIELD(S, rtc_time_alarm_reg)); in bcd_to_alarm_time()
351 timeptr->tm_min = bcd2bin(RTC_TIME_ALARM_REG_GET_FIELD(M, rtc_time_alarm_reg)); in bcd_to_alarm_time()
352 timeptr->tm_hour = bcd2bin(RTC_TIME_ALARM_REG_GET_FIELD(HR, rtc_time_alarm_reg)); in bcd_to_alarm_time()
354 timeptr->tm_nsec = 0; in bcd_to_alarm_time()
407 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_alarm_set_time()
415 return -EINVAL; in rtc_smartbond_alarm_set_time()
420 return -EINVAL; in rtc_smartbond_alarm_set_time()
425 return -EINVAL; in rtc_smartbond_alarm_set_time()
430 return -EINVAL; in rtc_smartbond_alarm_set_time()
433 if (!data->is_rtc_configured) { in rtc_smartbond_alarm_set_time()
437 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_alarm_set_time()
439 rtc_alarm_enable_reg = RTC->RTC_ALARM_ENABLE_REG; in rtc_smartbond_alarm_set_time()
442 RTC->RTC_ALARM_ENABLE_REG = 0; in rtc_smartbond_alarm_set_time()
443 RTC->RTC_INTERRUPT_DISABLE_REG = RTC_RTC_INTERRUPT_DISABLE_REG_RTC_ALRM_INT_DIS_Msk; in rtc_smartbond_alarm_set_time()
447 rtc_time_alarm_reg = RTC->RTC_TIME_ALARM_REG; in rtc_smartbond_alarm_set_time()
448 rtc_calendar_alarm_reg = RTC->RTC_CALENDAR_ALARM_REG; in rtc_smartbond_alarm_set_time()
450 RTC->RTC_TIME_ALARM_REG = alarm_time_to_bcd(timeptr, mask); in rtc_smartbond_alarm_set_time()
451 RTC->RTC_CALENDAR_ALARM_REG = alarm_calendar_to_bcd(timeptr, mask); in rtc_smartbond_alarm_set_time()
453 rtc_status_reg = RTC->RTC_STATUS_REG; in rtc_smartbond_alarm_set_time()
456 RTC->RTC_TIME_ALARM_REG = rtc_time_alarm_reg; in rtc_smartbond_alarm_set_time()
457 RTC->RTC_CALENDAR_ALARM_REG = rtc_calendar_alarm_reg; in rtc_smartbond_alarm_set_time()
458 RTC->RTC_ALARM_ENABLE_REG = rtc_alarm_enable_reg; in rtc_smartbond_alarm_set_time()
459 ret = -EINVAL; in rtc_smartbond_alarm_set_time()
461 RTC->RTC_ALARM_ENABLE_REG = tm_to_rtc_alarm_mask(mask); in rtc_smartbond_alarm_set_time()
464 RTC->RTC_INTERRUPT_ENABLE_REG = RTC_RTC_INTERRUPT_ENABLE_REG_RTC_ALRM_INT_EN_Msk; in rtc_smartbond_alarm_set_time()
467 k_mutex_unlock(&data->lock); in rtc_smartbond_alarm_set_time()
475 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_alarm_get_time()
479 return -EINVAL; in rtc_smartbond_alarm_get_time()
484 return -EINVAL; in rtc_smartbond_alarm_get_time()
487 if (!data->is_rtc_configured) { in rtc_smartbond_alarm_get_time()
491 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_alarm_get_time()
495 *mask = rtc_to_tm_alarm_mask(RTC->RTC_ALARM_ENABLE_REG); in rtc_smartbond_alarm_get_time()
497 k_mutex_unlock(&data->lock); in rtc_smartbond_alarm_get_time()
506 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_alarm_is_pending()
510 return -EINVAL; in rtc_smartbond_alarm_is_pending()
515 status = data->is_alarm_pending; in rtc_smartbond_alarm_is_pending()
517 data->is_alarm_pending = 0; in rtc_smartbond_alarm_is_pending()
526 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_alarm_set_callback()
530 return -EINVAL; in rtc_smartbond_alarm_set_callback()
533 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_alarm_set_callback()
535 data->alarm_cb = callback; in rtc_smartbond_alarm_set_callback()
536 data->alarm_user_data = user_data; in rtc_smartbond_alarm_set_callback()
538 k_mutex_unlock(&data->lock); in rtc_smartbond_alarm_set_callback()
548 return -EINVAL; in rtc_smartbond_alarm_get_supported_fields()
553 return -EINVAL; in rtc_smartbond_alarm_get_supported_fields()
566 struct rtc_smartbond_data *data = dev->data; in rtc_smartbond_update_set_callback()
568 k_mutex_lock(&data->lock, K_FOREVER); in rtc_smartbond_update_set_callback()
570 data->update_cb = callback; in rtc_smartbond_update_set_callback()
571 data->update_user_data = user_data; in rtc_smartbond_update_set_callback()
573 if (data->update_cb) { in rtc_smartbond_update_set_callback()
574 /* Enable asserting the RTC interrupt line when the second counter rolls over. */ in rtc_smartbond_update_set_callback()
575 RTC->RTC_INTERRUPT_ENABLE_REG = RTC_RTC_INTERRUPT_ENABLE_REG_RTC_SEC_INT_EN_Msk; in rtc_smartbond_update_set_callback()
577 RTC->RTC_INTERRUPT_DISABLE_REG = RTC_RTC_INTERRUPT_DISABLE_REG_RTC_SEC_INT_DIS_Msk; in rtc_smartbond_update_set_callback()
580 k_mutex_unlock(&data->lock); in rtc_smartbond_update_set_callback()
616 clk_rtcdiv_reg = CRG_TOP->CLK_RTCDIV_REG; in rtc_smartbond_100HZ_clock_cfg()
620 CRG_TOP->CLK_RTCDIV_REG = clk_rtcdiv_reg; in rtc_smartbond_100HZ_clock_cfg()
627 /* Wakeup device from RTC events (alarm/roll over) */ in rtc_smartbond_init()
641 RTC->RTC_KEEP_RTC_REG |= RTC_RTC_KEEP_RTC_REG_RTC_KEEP_Msk; in rtc_smartbond_init()