Merge pull request #14733 from benpicco/cpu/lpc23xx/rtc_cleanup

cpu/lpc23xx: RTC: cleanup
This commit is contained in:
Marian Buschsieweke 2020-08-17 20:34:30 +02:00 committed by GitHub
commit 90c59b1c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,7 +95,10 @@ int rtc_set_time(struct tm *localt)
int rtc_get_time(struct tm *localt)
{
if (localt != NULL) {
if (localt == NULL) {
return -1;
}
localt->tm_sec = RTC_SEC;
localt->tm_min = RTC_MIN;
localt->tm_hour = RTC_HOUR;
@ -105,15 +108,15 @@ int rtc_get_time(struct tm *localt)
localt->tm_mon = RTC_MONTH - 1;
localt->tm_year = RTC_YEAR;
localt->tm_isdst = -1; /* not available */
return 0;
}
return -1;
}
int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
{
if (localt != NULL) {
/* normalize input */
rtc_tm_normalize(localt);
@ -128,22 +131,22 @@ int rtc_set_alarm(struct tm *localt, rtc_alarm_cb_t cb, void *arg)
RTC_AMR = 0; /* set which alarm fields to check */
DEBUG("alarm set %2lu.%2lu.%4lu %2lu:%2lu:%2lu\n",
RTC_ALDOM, RTC_ALMON, RTC_ALYEAR, RTC_ALHOUR, RTC_ALMIN, RTC_ALSEC);
}
if (cb) {
_cb = cb;
_cb_arg = arg;
return 0;
}
else if (cb == NULL) {
return -1;
}
RTC_AMR = 0xff;
return -2;
return 0;
}
int rtc_get_alarm(struct tm *localt)
{
if (localt != NULL) {
if (localt == NULL) {
return -1;
}
localt->tm_sec = RTC_ALSEC;
localt->tm_min = RTC_ALMIN;
localt->tm_hour = RTC_ALHOUR;
@ -157,9 +160,6 @@ int rtc_get_alarm(struct tm *localt)
return 0;
}
return -1;
}
void rtc_clear_alarm(void)
{
RTC_AMR = 0xff;
@ -177,20 +177,13 @@ void rtc_poweroff(void)
{
RTC_CCR &= ~CCR_CLKEN; /* disable clock */
install_irq(RTC_INT, NULL, 0);
RTC_ILR = 0;
PCONP &= ~BIT9;
}
void RTC_IRQHandler(void)
{
if (RTC_ILR & ILR_RTSSF) {
/* sub second interrupt (does not need flag-clearing) */
}
else if (RTC_ILR & ILR_RTCCIF) {
/* counter increase interrupt */
}
else if (RTC_ILR & ILR_RTCALF) {
RTC_ILR |= ILR_RTCALF;
if (RTC_ILR & ILR_RTCALF) {
RTC_ILR = ILR_RTCALF;
RTC_AMR = 0xff; /* disable alarm irq */
if (_cb) {
_cb(_cb_arg);