Skip to content

Commit 15ffad4

Browse files
committed
cpu/sam0_common: clear tamper wake on gpio_irq_disable()
1 parent 5d26414 commit 15ffad4

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

cpu/sam0_common/include/periph_cpu_common.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,10 +1353,26 @@ void rtc_tamper_init(void);
13531353
* @param pin The GPIO pin to be used for tamper detection
13541354
* @param flank The Flank to trigger the even
13551355
*
1356-
* @return 0 on success, -1 if pin is not RTC pin
1356+
* @return 0 on success, -1 if pin is not an RTC pin
13571357
*/
13581358
int rtc_tamper_register(gpio_t pin, gpio_flank_t flank);
13591359

1360+
/**
1361+
* @brief (Re-)Enable Tamper Detection pin
1362+
*
1363+
* @param pin The GPIO pin to be used for tamper detection
1364+
*
1365+
* @return 0 on success, -1 if pin is not an RTC pin
1366+
*/
1367+
int rtc_tamper_pin_enable(gpio_t pin);
1368+
1369+
/**
1370+
* @brief Disable Tamper Detection pin
1371+
*
1372+
* @param pin The GPIO pin to no longer be used for tamper detection
1373+
*/
1374+
void rtc_tamper_pin_disable(gpio_t pin);
1375+
13601376
/**
13611377
* @brief Enable Tamper Detection IRQs
13621378
*/

cpu/sam0_common/periph/gpio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ void gpio_irq_enable(gpio_t pin)
481481

482482
/* enable wake from deep sleep */
483483
_set_extwake(pin, true);
484+
485+
if (IS_ACTIVE(MODULE_PERIPH_GPIO_TAMPER_WAKE)) {
486+
rtc_tamper_pin_enable(pin);
487+
}
484488
}
485489

486490
void gpio_irq_disable(gpio_t pin)
@@ -502,6 +506,10 @@ void gpio_irq_disable(gpio_t pin)
502506

503507
/* disable wake from deep sleep */
504508
_set_extwake(pin, false);
509+
510+
if (IS_ACTIVE(MODULE_PERIPH_GPIO_TAMPER_WAKE)) {
511+
rtc_tamper_pin_disable(pin);
512+
}
505513
}
506514

507515
#if defined(CPU_COMMON_SAML1X)

cpu/sam0_common/periph/rtc_rtt.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdint.h>
2828
#include <string.h>
2929

30+
#include "atomic_utils.h"
3031
#include "pm_layered.h"
3132
#include "periph/rtc.h"
3233
#include "periph/rtt.h"
@@ -503,6 +504,30 @@ int rtc_tamper_register(gpio_t pin, gpio_flank_t flank)
503504
return 0;
504505
}
505506

507+
int rtc_tamper_pin_enable(gpio_t pin)
508+
{
509+
int in = _rtc_pin(pin);
510+
511+
if (in < 0) {
512+
return -1;
513+
}
514+
515+
atomic_set_bit_u32(atomic_bit_u32(&tampctr, 2 * in));
516+
517+
return 0;
518+
}
519+
520+
void rtc_tamper_pin_disable(gpio_t pin)
521+
{
522+
int in = _rtc_pin(pin);
523+
524+
if (in < 0) {
525+
return;
526+
}
527+
528+
atomic_clear_bit_u32(atomic_bit_u32(&tampctr, 2 * in));
529+
}
530+
506531
void rtc_tamper_enable(void)
507532
{
508533
DEBUG("enable tamper\n");

0 commit comments

Comments
 (0)