From 0398fb3f83f39c60fc8a14cc79ae2d70001cbc83 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 9 Dec 2021 12:41:53 +0100 Subject: [PATCH] drivers/nvmram_spi: convert to ztimer_usec --- boards/mulle/board.c | 5 +++-- drivers/nvram_spi/Kconfig | 2 +- drivers/nvram_spi/Makefile.dep | 2 +- drivers/nvram_spi/nvram-spi.c | 8 ++++---- tests/driver_nvram_spi/Makefile | 2 +- tests/driver_nvram_spi/app.config.test | 2 +- tests/driver_nvram_spi/main.c | 5 +++-- tests/events/Makefile.board.dep | 7 +++++++ 8 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 tests/events/Makefile.board.dep diff --git a/boards/mulle/board.c b/boards/mulle/board.c index 50df907e80..6774901cb6 100644 --- a/boards/mulle/board.c +++ b/boards/mulle/board.c @@ -28,7 +28,8 @@ #include "periph/spi.h" #include "nvram-spi.h" #include "nvram.h" -#include "xtimer.h" +#include "ztimer.h" +#include "timex.h" #include "vfs.h" #include "fs/devfs.h" #include "mtd_spi_nor.h" @@ -115,7 +116,7 @@ void board_init(void) /* NVRAM requires xtimer for timing */ - xtimer_init(); + ztimer_init(); /* Initialize NVRAM */ status = mulle_nvram_init(); diff --git a/drivers/nvram_spi/Kconfig b/drivers/nvram_spi/Kconfig index 49aa0041de..9d0af2163a 100644 --- a/drivers/nvram_spi/Kconfig +++ b/drivers/nvram_spi/Kconfig @@ -11,4 +11,4 @@ config MODULE_NVRAM_SPI depends on TEST_KCONFIG select MODULE_NVRAM select MODULE_PERIPH_SPI - select MODULE_XTIMER + select ZTIMER_USEC diff --git a/drivers/nvram_spi/Makefile.dep b/drivers/nvram_spi/Makefile.dep index dc07832471..2e7594ee97 100644 --- a/drivers/nvram_spi/Makefile.dep +++ b/drivers/nvram_spi/Makefile.dep @@ -1,3 +1,3 @@ FEATURES_REQUIRED += periph_spi USEMODULE += nvram -USEMODULE += xtimer +USEMODULE += ztimer_usec diff --git a/drivers/nvram_spi/nvram-spi.c b/drivers/nvram_spi/nvram-spi.c index 3ecd0a18d6..9f82077b09 100644 --- a/drivers/nvram_spi/nvram-spi.c +++ b/drivers/nvram_spi/nvram-spi.c @@ -14,7 +14,7 @@ #include "byteorder.h" #include "periph/spi.h" #include "periph/gpio.h" -#include "xtimer.h" +#include "ztimer.h" /** * @ingroup drivers_nvram @@ -42,7 +42,7 @@ typedef enum { /** @brief Delay to wait between toggling CS pin, on most chips this can probably be * removed. */ -#define NVRAM_SPI_CS_TOGGLE_TICKS xtimer_ticks_from_usec(1) +#define NVRAM_SPI_CS_TOGGLE_US 1 /** * @brief Copy data from system memory to NVRAM. @@ -140,7 +140,7 @@ static int nvram_spi_write(nvram_t *dev, const uint8_t *src, uint32_t dst, size_ /* Enable writes */ spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN); /* Make sure we have a minimum gap between transfers */ - xtimer_spin(NVRAM_SPI_CS_TOGGLE_TICKS); + ztimer_spin(ZTIMER_USEC, NVRAM_SPI_CS_TOGGLE_US); /* Write command and address */ spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, NVRAM_SPI_CMD_WRITE); spi_transfer_bytes(spi_dev->spi, spi_dev->cs, true, @@ -200,7 +200,7 @@ static int nvram_spi_write_9bit_addr(nvram_t *dev, const uint8_t *src, uint32_t /* Enable writes */ spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN); /* Insert needed delay between transactions */ - xtimer_spin(NVRAM_SPI_CS_TOGGLE_TICKS); + ztimer_spin(ZTIMER_USEC, NVRAM_SPI_CS_TOGGLE_US); /* Write command and address */ spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, cmd); spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, addr); diff --git a/tests/driver_nvram_spi/Makefile b/tests/driver_nvram_spi/Makefile index d056bae463..8b485a5cc9 100644 --- a/tests/driver_nvram_spi/Makefile +++ b/tests/driver_nvram_spi/Makefile @@ -1,7 +1,7 @@ include ../Makefile.tests_common USEMODULE += nvram_spi -USEMODULE += xtimer +USEMODULE += ztimer_usec # set default device parameters in case they are undefined TEST_NVRAM_SPI_DEV ?= SPI_DEV\(0\) diff --git a/tests/driver_nvram_spi/app.config.test b/tests/driver_nvram_spi/app.config.test index a56d76d65f..68e9fc72c0 100644 --- a/tests/driver_nvram_spi/app.config.test +++ b/tests/driver_nvram_spi/app.config.test @@ -1,4 +1,4 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. CONFIG_MODULE_NVRAM_SPI=y -CONFIG_MODULE_XTIMER=y +CONFIG_ZTIMER_USEC=y diff --git a/tests/driver_nvram_spi/main.c b/tests/driver_nvram_spi/main.c index a517784068..46f70a6c9b 100644 --- a/tests/driver_nvram_spi/main.c +++ b/tests/driver_nvram_spi/main.c @@ -23,7 +23,8 @@ #include #include "board.h" -#include "xtimer.h" +#include "ztimer.h" +#include "timex.h" #include "periph/spi.h" #include "nvram-spi.h" @@ -137,7 +138,7 @@ int main(void) puts("!!! This test will erase everything on the NVRAM !!!"); puts("!!! Unplug/reset/halt device now if this is not acceptable !!!"); puts("Waiting for 10 seconds before continuing..."); - xtimer_sleep(start_delay); + ztimer_sleep(ZTIMER_USEC, start_delay * US_PER_SEC); puts("Reading current memory contents..."); for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) { diff --git a/tests/events/Makefile.board.dep b/tests/events/Makefile.board.dep new file mode 100644 index 0000000000..76e7d4dd4a --- /dev/null +++ b/tests/events/Makefile.board.dep @@ -0,0 +1,7 @@ +# mulle will always select ztimer through requiring nvram_spi module +# because of order of inclusion 'make' depency resolution will still select +# xtimer while 'Kconfig' wont, so early require 'ztimer_usec' +# for 'make' to avoid this +ifneq (,$(filter mulle,$(BOARD))) + USEMODULE += ztimer_usec +endif