1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/pir: migrate to ztimer64

This commit is contained in:
Francisco Molina 2021-12-09 12:52:37 +01:00
parent d8126864ea
commit c19a78765a
5 changed files with 10 additions and 8 deletions

View File

@ -12,7 +12,7 @@ config MODULE_PIR
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO
select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_GPIO_IRQ
select MODULE_XTIMER select ZTIMER64_USEC
config HAVE_PIR config HAVE_PIR
bool bool

View File

@ -1,3 +1,3 @@
FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_gpio_irq
USEMODULE += xtimer USEMODULE += ztimer64_usec

View File

@ -24,7 +24,7 @@
#include "irq.h" #include "irq.h"
#include "thread.h" #include "thread.h"
#include "msg.h" #include "msg.h"
#include "xtimer.h" #include "ztimer64.h"
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
@ -50,7 +50,7 @@ int pir_init(pir_t *dev, const pir_params_t *params)
dev->active = false; dev->active = false;
dev->accum_active_time = 0; dev->accum_active_time = 0;
dev->start_active_time = 0; dev->start_active_time = 0;
dev->last_read_time = xtimer_now_usec64(); dev->last_read_time = ztimer64_now(ZTIMER64_USEC);
gpio_mode_t gpio_mode; gpio_mode_t gpio_mode;
if (dev->p.active_high) { if (dev->p.active_high) {
@ -74,7 +74,7 @@ pir_event_t pir_get_status(const pir_t *dev)
int pir_get_occupancy(pir_t *dev, int16_t *occup) { int pir_get_occupancy(pir_t *dev, int16_t *occup) {
int irq_state = irq_disable(); int irq_state = irq_disable();
uint64_t now = xtimer_now_usec64(); uint64_t now = ztimer64_now(ZTIMER64_USEC);
uint64_t total_time = now - dev->last_read_time; uint64_t total_time = now - dev->last_read_time;
if (total_time == 0) { if (total_time == 0) {
irq_restore(irq_state); irq_restore(irq_state);
@ -145,7 +145,7 @@ static void pir_callback(void *arg)
DEBUG("pir_callback: %p\n", arg); DEBUG("pir_callback: %p\n", arg);
pir_t *dev = (pir_t*) arg; pir_t *dev = (pir_t*) arg;
bool pin_now = gpio_read(dev->p.gpio); bool pin_now = gpio_read(dev->p.gpio);
uint64_t now = xtimer_now_usec64(); uint64_t now = ztimer64_now(ZTIMER64_USEC);
/* We were busy counting */ /* We were busy counting */
if (dev->active) { if (dev->active) {

View File

@ -7,5 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := \
atmega328p-xplained-mini \ atmega328p-xplained-mini \
nucleo-f031k6 \ nucleo-f031k6 \
nucleo-l011k4 \ nucleo-l011k4 \
samd10-xmini \
stm32f030f4-demo \ stm32f030f4-demo \
# #

View File

@ -23,7 +23,8 @@
#include <stdio.h> #include <stdio.h>
#include "thread.h" #include "thread.h"
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#include "pir.h" #include "pir.h"
#include "pir_params.h" #include "pir_params.h"
@ -76,7 +77,7 @@ int main(void)
while (1) { while (1) {
printf("Status: %s\n", pir_get_status(&dev) == PIR_STATUS_INACTIVE ? printf("Status: %s\n", pir_get_status(&dev) == PIR_STATUS_INACTIVE ?
"inactive" : "active"); "inactive" : "active");
xtimer_usleep(1000 * 1000); ztimer_sleep(ZTIMER_USEC, 1 * US_PER_SEC);
} }
#else #else
thread_create( thread_create(