@@ -62,10 +62,6 @@ static int rtc_numaker_set_time(const struct device *dev, const struct rtc_time
62
62
struct rtc_numaker_time curr_time ;
63
63
struct rtc_numaker_data * data = dev -> data ;
64
64
uint32_t real_year = timeptr -> tm_year + TM_YEAR_REF ;
65
- #ifdef CONFIG_RTC_ALARM
66
- const struct rtc_numaker_config * config = dev -> config ;
67
- RTC_T * rtc_base = config -> rtc_base ;
68
- #endif
69
65
70
66
if (real_year < NVT_RTC_YEAR_MIN || real_year > NVT_RTC_YEAR_MAX ) {
71
67
/* RTC can't support years out of 2000 ~ 2099 */
@@ -88,12 +84,6 @@ static int rtc_numaker_set_time(const struct device *dev, const struct rtc_time
88
84
k_spinlock_key_t key = k_spin_lock (& data -> lock );
89
85
90
86
RTC_SetDateAndTime ((S_RTC_TIME_DATA_T * )& curr_time );
91
-
92
- #ifdef CONFIG_RTC_ALARM
93
- /* Restore RTC alarm mask */
94
- rtc_base -> CAMSK = rtc_base -> SPR [1 ];
95
- rtc_base -> TAMSK = rtc_base -> SPR [2 ];
96
- #endif
97
87
k_spin_unlock (& data -> lock , key );
98
88
99
89
return 0 ;
@@ -149,8 +139,6 @@ static void rtc_numaker_isr(const struct device *dev)
149
139
150
140
/* Clear RTC Alarm interrupt flag */
151
141
rtc_base -> INTSTS = RTC_INTSTS_ALMIF_Msk ;
152
- rtc_base -> CAMSK = 0x00 ;
153
- rtc_base -> TAMSK = 0x00 ;
154
142
callback = data -> alarm_callback ;
155
143
user_data = data -> alarm_user_data ;
156
144
data -> alarm_pending = callback ? false : true;
@@ -211,13 +199,10 @@ static int rtc_numaker_alarm_set_time(const struct device *dev, uint16_t id, uin
211
199
irq_disable (DT_INST_IRQN (0 ));
212
200
if ((mask == 0 ) || (timeptr == NULL )) {
213
201
/* Disable the alarm */
214
- rtc_base -> SPR [0 ] = mask ;
215
- rtc_base -> SPR [1 ] = 0x00 ;
216
- rtc_base -> SPR [2 ] = 0x00 ;
217
202
irq_enable (DT_INST_IRQN (0 ));
218
203
k_spin_unlock (& data -> lock , key );
219
- rtc_base -> CAMSK = rtc_base -> SPR [ 1 ] ;
220
- rtc_base -> TAMSK = rtc_base -> SPR [ 2 ] ;
204
+ rtc_base -> CAMSK = 0x00 ;
205
+ rtc_base -> TAMSK = 0x00 ;
221
206
/* Disable RTC Alarm Interrupt */
222
207
RTC_DisableInt (RTC_INTEN_ALMIEN_Msk );
223
208
return 0 ;
@@ -265,12 +250,8 @@ static int rtc_numaker_alarm_set_time(const struct device *dev, uint16_t id, uin
265
250
/* Clear RTC alarm interrupt flag */
266
251
RTC_CLEAR_ALARM_INT_FLAG ();
267
252
268
- rtc_base -> SPR [0 ] = mask ;
269
- rtc_base -> SPR [1 ] = camsk ;
270
- rtc_base -> SPR [2 ] = tamsk ;
271
-
272
- rtc_base -> CAMSK = rtc_base -> SPR [1 ];
273
- rtc_base -> TAMSK = rtc_base -> SPR [2 ];
253
+ rtc_base -> CAMSK = camsk ;
254
+ rtc_base -> TAMSK = tamsk ;
274
255
275
256
k_spin_unlock (& data -> lock , key );
276
257
irq_enable (DT_INST_IRQN (0 ));
@@ -281,6 +262,33 @@ static int rtc_numaker_alarm_set_time(const struct device *dev, uint16_t id, uin
281
262
return 0 ;
282
263
}
283
264
265
+ static uint16_t rtc_numaker_get_mask (uint32_t camsk , uint32_t tamsk )
266
+ {
267
+ uint16_t mask = 0x00 ;
268
+
269
+ /* Set H/W care to match bits */
270
+ if (!((camsk >> RTC_CAMSK_MYEAR_Pos ) & NVT_ALARM_UNIT_MSK )) {
271
+ mask |= RTC_ALARM_TIME_MASK_YEAR ;
272
+ }
273
+ if (!((camsk >> RTC_CAMSK_MMON_Pos ) & NVT_ALARM_UNIT_MSK )) {
274
+ mask |= RTC_ALARM_TIME_MASK_MONTH ;
275
+ }
276
+ if (!((camsk >> RTC_CAMSK_MDAY_Pos ) & NVT_ALARM_UNIT_MSK )) {
277
+ mask |= RTC_ALARM_TIME_MASK_MONTHDAY ;
278
+ }
279
+ if (!((tamsk >> RTC_TAMSK_MHR_Pos ) & NVT_ALARM_UNIT_MSK )) {
280
+ mask |= RTC_ALARM_TIME_MASK_HOUR ;
281
+ }
282
+ if (!((tamsk >> RTC_TAMSK_MMIN_Pos ) & NVT_ALARM_UNIT_MSK )) {
283
+ mask |= RTC_ALARM_TIME_MASK_MINUTE ;
284
+ }
285
+ if (!((tamsk >> RTC_TAMSK_MSEC_Pos ) & NVT_ALARM_UNIT_MSK )) {
286
+ mask |= RTC_ALARM_TIME_MASK_SECOND ;
287
+ }
288
+
289
+ return mask ;
290
+ }
291
+
284
292
static int rtc_numaker_alarm_get_time (const struct device * dev , uint16_t id , uint16_t * mask ,
285
293
struct rtc_time * timeptr )
286
294
{
@@ -299,7 +307,7 @@ static int rtc_numaker_alarm_get_time(const struct device *dev, uint16_t id, uin
299
307
RTC_GetAlarmDateAndTime ((S_RTC_TIME_DATA_T * )& alarm_time );
300
308
}
301
309
302
- * mask = rtc_base -> SPR [ 0 ] ;
310
+ * mask = rtc_numaker_get_mask ( rtc_base -> CAMSK , rtc_base -> TAMSK ) ;
303
311
if (* mask & RTC_ALARM_TIME_MASK_YEAR ) {
304
312
timeptr -> tm_year = alarm_time .year - TM_YEAR_REF ;
305
313
}
@@ -379,7 +387,6 @@ static int rtc_numaker_init(const struct device *dev)
379
387
{
380
388
const struct rtc_numaker_config * cfg = dev -> config ;
381
389
struct numaker_scc_subsys scc_subsys ;
382
- RTC_T * rtc_base = cfg -> rtc_base ;
383
390
int err ;
384
391
385
392
/* CLK controller */
@@ -396,8 +403,6 @@ static int rtc_numaker_init(const struct device *dev)
396
403
}
397
404
398
405
RTC_SetClockSource (cfg -> oscillator );
399
- /* Enable spare registers */
400
- rtc_base -> SPRCTL = RTC_SPRCTL_SPRRWEN_Msk ;
401
406
402
407
irq_disable (DT_INST_IRQN (0 ));
403
408
0 commit comments