mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/nvmram_spi: convert to ztimer_usec
This commit is contained in:
parent
24a848e844
commit
0398fb3f83
@ -28,7 +28,8 @@
|
|||||||
#include "periph/spi.h"
|
#include "periph/spi.h"
|
||||||
#include "nvram-spi.h"
|
#include "nvram-spi.h"
|
||||||
#include "nvram.h"
|
#include "nvram.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer.h"
|
||||||
|
#include "timex.h"
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
#include "fs/devfs.h"
|
#include "fs/devfs.h"
|
||||||
#include "mtd_spi_nor.h"
|
#include "mtd_spi_nor.h"
|
||||||
@ -115,7 +116,7 @@ void board_init(void)
|
|||||||
|
|
||||||
|
|
||||||
/* NVRAM requires xtimer for timing */
|
/* NVRAM requires xtimer for timing */
|
||||||
xtimer_init();
|
ztimer_init();
|
||||||
|
|
||||||
/* Initialize NVRAM */
|
/* Initialize NVRAM */
|
||||||
status = mulle_nvram_init();
|
status = mulle_nvram_init();
|
||||||
|
@ -11,4 +11,4 @@ config MODULE_NVRAM_SPI
|
|||||||
depends on TEST_KCONFIG
|
depends on TEST_KCONFIG
|
||||||
select MODULE_NVRAM
|
select MODULE_NVRAM
|
||||||
select MODULE_PERIPH_SPI
|
select MODULE_PERIPH_SPI
|
||||||
select MODULE_XTIMER
|
select ZTIMER_USEC
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
FEATURES_REQUIRED += periph_spi
|
FEATURES_REQUIRED += periph_spi
|
||||||
USEMODULE += nvram
|
USEMODULE += nvram
|
||||||
USEMODULE += xtimer
|
USEMODULE += ztimer_usec
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
#include "periph/spi.h"
|
#include "periph/spi.h"
|
||||||
#include "periph/gpio.h"
|
#include "periph/gpio.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup drivers_nvram
|
* @ingroup drivers_nvram
|
||||||
@ -42,7 +42,7 @@ typedef enum {
|
|||||||
|
|
||||||
/** @brief Delay to wait between toggling CS pin, on most chips this can probably be
|
/** @brief Delay to wait between toggling CS pin, on most chips this can probably be
|
||||||
* removed. */
|
* 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.
|
* @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 */
|
/* Enable writes */
|
||||||
spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN);
|
spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN);
|
||||||
/* Make sure we have a minimum gap between transfers */
|
/* 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 */
|
/* Write command and address */
|
||||||
spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, NVRAM_SPI_CMD_WRITE);
|
spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, NVRAM_SPI_CMD_WRITE);
|
||||||
spi_transfer_bytes(spi_dev->spi, spi_dev->cs, true,
|
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 */
|
/* Enable writes */
|
||||||
spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN);
|
spi_transfer_byte(spi_dev->spi, spi_dev->cs, false, NVRAM_SPI_CMD_WREN);
|
||||||
/* Insert needed delay between transactions */
|
/* 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 */
|
/* 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, cmd);
|
||||||
spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, addr);
|
spi_transfer_byte(spi_dev->spi, spi_dev->cs, true, addr);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
include ../Makefile.tests_common
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
USEMODULE += nvram_spi
|
USEMODULE += nvram_spi
|
||||||
USEMODULE += xtimer
|
USEMODULE += ztimer_usec
|
||||||
|
|
||||||
# set default device parameters in case they are undefined
|
# set default device parameters in case they are undefined
|
||||||
TEST_NVRAM_SPI_DEV ?= SPI_DEV\(0\)
|
TEST_NVRAM_SPI_DEV ?= SPI_DEV\(0\)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# this file enables modules defined in Kconfig. Do not use this file for
|
# this file enables modules defined in Kconfig. Do not use this file for
|
||||||
# application configuration. This is only needed during migration.
|
# application configuration. This is only needed during migration.
|
||||||
CONFIG_MODULE_NVRAM_SPI=y
|
CONFIG_MODULE_NVRAM_SPI=y
|
||||||
CONFIG_MODULE_XTIMER=y
|
CONFIG_ZTIMER_USEC=y
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer.h"
|
||||||
|
#include "timex.h"
|
||||||
#include "periph/spi.h"
|
#include "periph/spi.h"
|
||||||
#include "nvram-spi.h"
|
#include "nvram-spi.h"
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ int main(void)
|
|||||||
puts("!!! This test will erase everything on the NVRAM !!!");
|
puts("!!! This test will erase everything on the NVRAM !!!");
|
||||||
puts("!!! Unplug/reset/halt device now if this is not acceptable !!!");
|
puts("!!! Unplug/reset/halt device now if this is not acceptable !!!");
|
||||||
puts("Waiting for 10 seconds before continuing...");
|
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...");
|
puts("Reading current memory contents...");
|
||||||
for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
|
for (i = 0; i < TEST_NVRAM_SPI_SIZE; ++i) {
|
||||||
|
7
tests/events/Makefile.board.dep
Normal file
7
tests/events/Makefile.board.dep
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user