Lines Matching +full:0 +full:- +full:128
5 * SPDX-License-Identifier: Apache-2.0
22 #define _IFX_CAT1_RTC_STATE_UNINITIALIZED 0
30 #if defined(SRSS_BACKUP_NUM_BREG3) && (SRSS_BACKUP_NUM_BREG3 > 0)
31 #define _IFX_CAT1_RTC_BREG (BACKUP->BREG_SET3[SRSS_BACKUP_NUM_BREG3 - 1])
32 #elif defined(SRSS_BACKUP_NUM_BREG2) && (SRSS_BACKUP_NUM_BREG2 > 0)
33 #define _IFX_CAT1_RTC_BREG (BACKUP->BREG_SET2[SRSS_BACKUP_NUM_BREG2 - 1])
34 #elif defined(SRSS_BACKUP_NUM_BREG1) && (SRSS_BACKUP_NUM_BREG1 > 0)
35 #define _IFX_CAT1_RTC_BREG (BACKUP->BREG_SET1[SRSS_BACKUP_NUM_BREG1 - 1])
36 #elif defined(SRSS_BACKUP_NUM_BREG0) && (SRSS_BACKUP_NUM_BREG0 > 0)
37 #define _IFX_CAT1_RTC_BREG (BACKUP->BREG_SET0[SRSS_BACKUP_NUM_BREG0 - 1])
41 #define _IFX_CAT1_RTC_BREG_CENTURY_Pos 0UL
42 #define _IFX_CAT1_RTC_BREG_CENTURY_Msk 0x0000FFFFUL
44 #define _IFX_CAT1_RTC_BREG_STATE_Msk 0xFFFF0000UL
73 /* Convert parts per billion to groupings of 128 ticks added or removed from one hour of clock
76 * ROUND_DOWN(ppb * 32768Hz * 60min * 60sec / 1000000000, 128) / 128
77 * ROUND_DOWN(ppb * 117964800 / 1000000000, 128) / 128
78 * ROUND_DOWN(ppb * 9216 / 78125, 128) / 128
80 #define PPB_TO_WCO_PULSE_SETS(ppb) ((ROUND_DOWN((ppb * 9216 / 78125), 128)) / 128)
82 /* Convert groupings of 128 ticks added or removed from one hour of clock cycles at
85 * wps * 128 * 1000000000 / 32768Hz * 60min * 60sec
123 z_time->tm_sec = (int)pdlTime->sec; in _ifx_cat1_rtc_from_pdl_time()
124 z_time->tm_min = (int)pdlTime->min; in _ifx_cat1_rtc_from_pdl_time()
125 z_time->tm_hour = (int)pdlTime->hour; in _ifx_cat1_rtc_from_pdl_time()
126 z_time->tm_mday = (int)pdlTime->date; in _ifx_cat1_rtc_from_pdl_time()
127 z_time->tm_year = (int)(year - _IFX_CAT1_RTC_TM_YEAR_BASE); in _ifx_cat1_rtc_from_pdl_time()
132 z_time->tm_mon = (int)(pdlTime->month - 1u); in _ifx_cat1_rtc_from_pdl_time()
133 z_time->tm_wday = (int)(pdlTime->dayOfWeek - 1u); in _ifx_cat1_rtc_from_pdl_time()
136 z_time->tm_yday = -1; in _ifx_cat1_rtc_from_pdl_time()
139 z_time->tm_isdst = -1; in _ifx_cat1_rtc_from_pdl_time()
142 z_time->tm_nsec = 0; in _ifx_cat1_rtc_from_pdl_time()
155 * i.e. 1999->2000 in _ifx_cat1_rtc_century_interrupt()
178 rslt = -EINVAL; in ifx_cat1_rtc_init()
193 IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), _ifx_cat1_rtc_isr_handler, in ifx_cat1_rtc_init()
194 DEVICE_DT_INST_GET(0), 0); in ifx_cat1_rtc_init()
195 irq_enable(DT_INST_IRQN(0)); in ifx_cat1_rtc_init()
202 struct ifx_cat1_rtc_data *data = dev->data; in ifx_cat1_rtc_set_time()
204 uint32_t sec = timeptr->tm_sec; in ifx_cat1_rtc_set_time()
205 uint32_t min = timeptr->tm_min; in ifx_cat1_rtc_set_time()
206 uint32_t hour = timeptr->tm_hour; in ifx_cat1_rtc_set_time()
207 uint32_t day = timeptr->tm_mday; in ifx_cat1_rtc_set_time()
211 uint32_t mon = timeptr->tm_mon + 1; in ifx_cat1_rtc_set_time()
212 uint32_t year = timeptr->tm_year + _IFX_CAT1_RTC_TM_YEAR_BASE; in ifx_cat1_rtc_set_time()
216 uint32_t retry = 0; in ifx_cat1_rtc_set_time()
222 return -EINVAL; in ifx_cat1_rtc_set_time()
225 if (retry != 0) { in ifx_cat1_rtc_set_time()
229 k_spinlock_key_t key = k_spin_lock(&data->lock); in ifx_cat1_rtc_set_time()
233 _ifx_cat1_rtc_set_century((uint16_t)(year) - (uint16_t)(year2digit)); in ifx_cat1_rtc_set_time()
236 k_spin_unlock(&data->lock, key); in ifx_cat1_rtc_set_time()
240 retry = 0; in ifx_cat1_rtc_set_time()
248 return 0; in ifx_cat1_rtc_set_time()
250 return -EINVAL; in ifx_cat1_rtc_set_time()
256 struct ifx_cat1_rtc_data *data = dev->data; in ifx_cat1_rtc_get_time()
262 return -ENODATA; in ifx_cat1_rtc_get_time()
265 k_spinlock_key_t key = k_spin_lock(&data->lock); in ifx_cat1_rtc_get_time()
270 k_spin_unlock(&data->lock, key); in ifx_cat1_rtc_get_time()
285 if (calibration >= 0) { in ifx_cat1_set_calibration()
294 /* Maximum calibration value on cat1b of 60 128 tick groupings */ in ifx_cat1_set_calibration()
297 return -EINVAL; in ifx_cat1_set_calibration()
303 return -EINVAL; in ifx_cat1_set_calibration()
306 return 0; in ifx_cat1_set_calibration()
320 *calibration = WCO_PULSE_SETS_TO_PPB(hw_calibration) * -1; in ifx_cat1_get_calibration()
323 return 0; in ifx_cat1_get_calibration()