• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision14147 (tree)
Time2021-04-08 06:30:20
Authorcinsights

Log Message

WIP RP RTC alarm

Change Summary

Incremental Difference

--- trunk/os/hal/ports/RP/LLD/RTCv1/hal_rtc_lld.c (revision 14146)
+++ trunk/os/hal/ports/RP/LLD/RTCv1/hal_rtc_lld.c (revision 14147)
@@ -110,6 +110,9 @@
110110 while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE_BITS) != 0)
111111 ;
112112
113+ /* Entering a reentrant critical zone.*/
114+ syssts_t sts = osalSysGetStatusAndLockX();
115+
113116 /* Write setup to pre-load registers. */
114117 rtcp->rtc->SETUP0 =
115118 ((timespec->year + 1980) << RTC_SETUP_0_YEAR_LSB) |
@@ -126,6 +129,10 @@
126129
127130 /* Enable RTC and wait for active. */
128131 rtcp->rtc->CTRL = RTC_CTRL_RTC_ENABLE_BITS;
132+
133+ /* Leaving a reentrant critical zone.*/
134+ osalSysRestoreStatusX(sts);
135+
129136 while ((rtcp->rtc->CTRL & RTC_CTRL_RTC_ACTIVE_BITS) == 0)
130137 ;
131138 }
@@ -141,10 +148,16 @@
141148 */
142149 void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec) {
143150
151+ /* Entering a reentrant critical zone.*/
152+ syssts_t sts = osalSysGetStatusAndLockX();
153+
144154 /* Read RTC0 first then RTC1. */
145155 uint32_t rtc_0 = rtcp->rtc->RTC0;
146156 uint32_t rtc_1 = rtcp->rtc->RTC1;
147157
158+ /* Leaving a reentrant critical zone.*/
159+ osalSysRestoreStatusX(sts);
160+
148161 /* Calculate and set milliseconds since midnight field. */
149162 timespec->millisecond =
150163 ((((rtc_0 & RTC_RTC_0_HOUR_BITS) >> RTC_RTC_0_HOUR_LSB) * 3600)
@@ -179,9 +192,49 @@
179192 rtcalarm_t alarm,
180193 const RTCAlarm *alarmspec) {
181194
182- (void)rtcp;
183195 (void)alarm;
184- (void)alarmspec;
196+ RTCDateTime *t = &alarmspec->alarm;
197+ uint32_t sec = (uint32_t)t->millisecond / 1000;
198+ uint32_t hour = sec / 3600;
199+ sec %= 3600;
200+ uint32_t min = sec / 60;
201+ sec %= 60;
202+
203+ rtc_disable_alarm();
204+
205+ // Only add to setup if it isn't -1
206+ rtcp->rtc->IRQSETUP0 = ((t->year < 0) ? 0 : (((uint)t->year) << RTC_IRQ_SETUP_0_YEAR_LSB )) |
207+ ((t->month < 0) ? 0 : (((uint)t->month) << RTC_IRQ_SETUP_0_MONTH_LSB)) |
208+ ((t->day < 0) ? 0 : (((uint)t->day) << RTC_IRQ_SETUP_0_DAY_LSB ));
209+ rtcp->rtc->IRQSETUP1 = ((t->dotw == 0) ? 0 : (((uint)t->dotw) << RTC_IRQ_SETUP_1_DOTW_LSB)) |
210+ (t->hour << RTC_IRQ_SETUP_1_HOUR_LSB)) |
211+ (t->min << RTC_IRQ_SETUP_1_MIN_LSB )) |
212+ (t->sec << RTC_IRQ_SETUP_1_SEC_LSB ));
213+
214+ // Set the match enable bits for things we care about
215+ if (t->year >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_YEAR_ENA_BITS);
216+ if (t->month >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_MONTH_ENA_BITS);
217+ if (t->day >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_DAY_ENA_BITS);
218+ if (t->dotw >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_DOTW_ENA_BITS);
219+ if (t->hour >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_HOUR_ENA_BITS);
220+ if (t->min >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_MIN_ENA_BITS);
221+ if (t->sec >= 0) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_SEC_ENA_BITS);
222+
223+ // Does it repeat? I.e. do we not match on any of the bits
224+ _alarm_repeats = rtc_alarm_repeats(t);
225+
226+ // Store function pointer we can call later
227+ _callback = user_callback;
228+
229+ irq_set_exclusive_handler(RTC_IRQ, rtc_irq_handler);
230+
231+ // Enable the IRQ at the peri
232+ rtc_hw->inte = RTC_INTE_RTC_BITS;
233+
234+ // Enable the IRQ at the proc
235+ irq_set_enabled(RTC_IRQ, true);
236+
237+ rtc_enable_alarm();
185238 }
186239
187240 /**
--- trunk/os/hal/ports/RP/LLD/RTCv1/hal_rtc_lld.h (revision 14146)
+++ trunk/os/hal/ports/RP/LLD/RTCv1/hal_rtc_lld.h (revision 14147)
@@ -95,7 +95,7 @@
9595 */
9696 typedef struct {
9797 /* End of the mandatory fields.*/
98- uint32_t dummy;
98+ RTCDateTime alarm;
9999 } RTCAlarm;
100100
101101 /**
Show on old repository browser