Merge pull request #16421 from benpicco/cpu/sam0_common-rtc_reorder

cpu/sam0_common: only include RTC/RTT symbols if module is used
This commit is contained in:
Dylan Laduranty 2021-05-03 22:07:09 +02:00 committed by GitHub
commit efbd867484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,6 +84,7 @@ static void _wait_syncbusy(void)
} }
} }
#if defined(MODULE_PERIPH_RTC) || defined(MODULE_PERIPH_RTT)
static void _read_req(void) static void _read_req(void)
{ {
#ifdef RTC_READREQ_RREQ #ifdef RTC_READREQ_RREQ
@ -91,6 +92,7 @@ static void _read_req(void)
_wait_syncbusy(); _wait_syncbusy();
#endif #endif
} }
#endif
static void _poweron(void) static void _poweron(void)
{ {
@ -111,6 +113,7 @@ static bool _power_is_on(void)
#endif #endif
} }
__attribute__((unused))
static void _poweroff(void) static void _poweroff(void)
{ {
#ifdef MCLK #ifdef MCLK
@ -142,6 +145,7 @@ static inline void _rtt_reset(void)
} }
#ifdef CPU_COMMON_SAMD21 #ifdef CPU_COMMON_SAMD21
#ifdef MODULE_PERIPH_RTC
static void _rtc_clock_setup(void) static void _rtc_clock_setup(void)
{ {
/* Use 1024 Hz GCLK */ /* Use 1024 Hz GCLK */
@ -150,7 +154,9 @@ static void _rtc_clock_setup(void)
| GCLK_CLKCTRL_ID_RTC; | GCLK_CLKCTRL_ID_RTC;
while (GCLK->STATUS.bit.SYNCBUSY) {} while (GCLK->STATUS.bit.SYNCBUSY) {}
} }
#endif /* MODULE_PERIPH_RTC */
#ifdef MODULE_PERIPH_RTT
static void _rtt_clock_setup(void) static void _rtt_clock_setup(void)
{ {
/* Use 32 kHz GCLK */ /* Use 32 kHz GCLK */
@ -159,9 +165,11 @@ static void _rtt_clock_setup(void)
| GCLK_CLKCTRL_ID_RTC; | GCLK_CLKCTRL_ID_RTC;
while (GCLK->STATUS.bit.SYNCBUSY) {} while (GCLK->STATUS.bit.SYNCBUSY) {}
} }
#endif /* MODULE_PERIPH_RTT */
#else /* CPU_COMMON_SAMD21 - Clock Setup */ #else /* CPU_COMMON_SAMD21 - Clock Setup */
#ifdef MODULE_PERIPH_RTC
static void _rtc_clock_setup(void) static void _rtc_clock_setup(void)
{ {
/* RTC source clock is external oscillator at 1kHz */ /* RTC source clock is external oscillator at 1kHz */
@ -182,7 +190,9 @@ static void _rtc_clock_setup(void)
#error "No clock source for RTC selected. " #error "No clock source for RTC selected. "
#endif #endif
} }
#endif /* MODULE_PERIPH_RTC */
#if defined(MODULE_PERIPH_RTT) || RTC_NUM_OF_TAMPERS
static void _rtt_clock_setup(void) static void _rtt_clock_setup(void)
{ {
/* RTC source clock is external oscillator at 32kHz */ /* RTC source clock is external oscillator at 32kHz */
@ -202,8 +212,10 @@ static void _rtt_clock_setup(void)
#error "No clock source for RTT selected. " #error "No clock source for RTT selected. "
#endif #endif
} }
#endif /* MODULE_PERIPH_RTT */
#endif /* !CPU_COMMON_SAMD21 - Clock Setup */ #endif /* !CPU_COMMON_SAMD21 - Clock Setup */
#ifdef MODULE_PERIPH_RTC
static void _rtc_init(void) static void _rtc_init(void)
{ {
#ifdef REG_RTC_MODE2_CTRLA #ifdef REG_RTC_MODE2_CTRLA
@ -251,7 +263,9 @@ void rtc_init(void)
NVIC_EnableIRQ(RTC_IRQn); NVIC_EnableIRQ(RTC_IRQn);
} }
#endif /* MODULE_PERIPH_RTC */
#ifdef MODULE_PERIPH_RTT
void rtt_init(void) void rtt_init(void)
{ {
_rtt_clock_setup(); _rtt_clock_setup();
@ -277,6 +291,7 @@ void rtt_init(void)
NVIC_EnableIRQ(RTC_IRQn); NVIC_EnableIRQ(RTC_IRQn);
} }
#endif /* MODULE_PERIPH_RTT */
#if RTC_NUM_OF_TAMPERS #if RTC_NUM_OF_TAMPERS
@ -406,43 +421,7 @@ uint8_t rtc_tamper_pin_mask(gpio_t pin)
} }
#endif /* RTC_NUM_OF_TAMPERS */ #endif /* RTC_NUM_OF_TAMPERS */
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg) #ifdef MODULE_PERIPH_RTC
{
/* clear overflow cb to avoid race while assigning */
rtt_clear_overflow_cb();
/* set callback variables */
overflow_cb.cb = cb;
overflow_cb.arg = arg;
/* enable overflow interrupt */
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_OVF;
}
void rtt_clear_overflow_cb(void)
{
/* disable overflow interrupt */
RTC->MODE0.INTENCLR.reg = RTC_MODE0_INTENCLR_OVF;
}
uint32_t rtt_get_counter(void)
{
_wait_syncbusy();
_read_req();
return RTC->MODE0.COUNT.reg;
}
void rtt_set_counter(uint32_t count)
{
RTC->MODE0.COUNT.reg = count;
_wait_syncbusy();
}
uint32_t rtt_get_alarm(void)
{
_wait_syncbusy();
return RTC->MODE0.COMP[0].reg;
}
int rtc_get_alarm(struct tm *time) int rtc_get_alarm(struct tm *time)
{ {
RTC_MODE2_ALARM_Type alarm; RTC_MODE2_ALARM_Type alarm;
@ -545,6 +524,61 @@ int rtc_set_time(struct tm *time)
return 0; return 0;
} }
void rtc_clear_alarm(void)
{
/* disable alarm interrupt */
RTC->MODE2.INTENCLR.reg = RTC_MODE2_INTENCLR_ALARM0;
}
void rtc_poweron(void)
{
_poweron();
}
void rtc_poweroff(void)
{
_poweroff();
}
#endif /* MODULE_PERIPH_RTC */
#ifdef MODULE_PERIPH_RTT
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
{
/* clear overflow cb to avoid race while assigning */
rtt_clear_overflow_cb();
/* set callback variables */
overflow_cb.cb = cb;
overflow_cb.arg = arg;
/* enable overflow interrupt */
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_OVF;
}
void rtt_clear_overflow_cb(void)
{
/* disable overflow interrupt */
RTC->MODE0.INTENCLR.reg = RTC_MODE0_INTENCLR_OVF;
}
uint32_t rtt_get_counter(void)
{
_wait_syncbusy();
_read_req();
return RTC->MODE0.COUNT.reg;
}
void rtt_set_counter(uint32_t count)
{
RTC->MODE0.COUNT.reg = count;
_wait_syncbusy();
}
uint32_t rtt_get_alarm(void)
{
_wait_syncbusy();
return RTC->MODE0.COMP[0].reg;
}
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg) void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
{ {
/* disable interrupt to avoid race */ /* disable interrupt to avoid race */
@ -563,37 +597,22 @@ void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_CMP0; RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_CMP0;
} }
void rtc_clear_alarm(void)
{
/* disable alarm interrupt */
RTC->MODE2.INTENCLR.reg = RTC_MODE2_INTENCLR_ALARM0;
}
void rtt_clear_alarm(void) void rtt_clear_alarm(void)
{ {
/* disable compare interrupt */ /* disable compare interrupt */
RTC->MODE0.INTENCLR.reg = RTC_MODE0_INTENCLR_CMP0; RTC->MODE0.INTENCLR.reg = RTC_MODE0_INTENCLR_CMP0;
} }
void rtc_poweron(void)
{
_poweron();
}
void rtt_poweron(void) void rtt_poweron(void)
{ {
_poweron(); _poweron();
} }
void rtc_poweroff(void)
{
_poweroff();
}
void rtt_poweroff(void) void rtt_poweroff(void)
{ {
_poweroff(); _poweroff();
} }
#endif /* MODULE_PERIPH_RTT */
static void _isr_rtc(void) static void _isr_rtc(void)
{ {