diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 4172c859df..9953d8aad6 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -1144,6 +1144,15 @@ int rtc_tamper_register(gpio_t pin, gpio_flank_t flank); * @brief Enable Tamper Detection IRQs */ void rtc_tamper_enable(void); + +/** + * @brief Get and clear the RTC tamper event that has woken the CPU + * from Deep Sleep. + * + * @return The set bits in the return value correspond to the tamper + * pin index inside the @ref rtc_tamper_pins array. + */ +uint8_t rtc_get_tamper_event(void); /** @} */ /** diff --git a/cpu/sam0_common/periph/rtc_rtt.c b/cpu/sam0_common/periph/rtc_rtt.c index bbd2541051..7901aeaeec 100644 --- a/cpu/sam0_common/periph/rtc_rtt.c +++ b/cpu/sam0_common/periph/rtc_rtt.c @@ -374,6 +374,16 @@ void rtc_tamper_enable(void) DEBUG("tamper enabled\n"); } +uint8_t rtc_get_tamper_event(void) +{ + uint32_t ret = RTC->MODE0.TAMPID.reg; + + /* clear tamper event */ + RTC->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_TAMPER; + RTC->MODE0.TAMPID.reg = ret; + + return ret & RTC_TAMPID_TAMPID_Msk; +} #endif /* RTC_NUM_OF_TAMPERS */ void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)