kopia lustrzana https://github.com/OpenRTX/OpenRTX
Added wrapper to NVM device API for Zephyr flash API.
Wrapped Zephyr flash API calls for OpenRTX interface, added additional settings specific to T-TWR Plus. TG-553pull/218/head
rodzic
d20f0e2c8d
commit
09587ab6c8
|
@ -0,0 +1,72 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2023 by Federico Amedeo Izzo IU2NUO, *
|
||||||
|
* Niccolò Izzo IU2KIN *
|
||||||
|
* Frederik Saraci IU2NRO *
|
||||||
|
* Silvano Seva IU2KWO *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <zephyr/drivers/flash.h>
|
||||||
|
#include "flash_zephyr.h"
|
||||||
|
|
||||||
|
static int nvm_api_read(const struct nvmDevice *dev, uint32_t offset,
|
||||||
|
void *data, size_t len)
|
||||||
|
{
|
||||||
|
const struct device *fDev = (const struct device *)(dev->config);
|
||||||
|
|
||||||
|
return flash_read(fDev, offset, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nvm_api_write(const struct nvmDevice *dev, uint32_t offset,
|
||||||
|
const void *data, size_t len)
|
||||||
|
{
|
||||||
|
const struct device *fDev = (const struct device *)(dev->config);
|
||||||
|
|
||||||
|
return flash_write(fDev, offset, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nvm_api_erase(const struct nvmDevice *dev, uint32_t offset, size_t size)
|
||||||
|
{
|
||||||
|
const struct device *fDev = (const struct device *)(dev->config);
|
||||||
|
|
||||||
|
return flash_erase(fDev, offset, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct nvmParams *nvm_api_params(const struct nvmDevice *dev)
|
||||||
|
{
|
||||||
|
struct nvmParams *params = (struct nvmParams *)(dev->priv);
|
||||||
|
const struct device *fDev = (const struct device *)(dev->config);
|
||||||
|
|
||||||
|
// Retrieve write size
|
||||||
|
const struct flash_parameters *info = flash_get_parameters(fDev);
|
||||||
|
params->write_size = info->write_block_size;
|
||||||
|
|
||||||
|
// TODO: erase size and erase cycles to be retrieved from the real device.
|
||||||
|
params->erase_size = 4096;
|
||||||
|
params->erase_cycles = 100000;
|
||||||
|
params->type = NVM_FLASH;
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct nvmApi zephyr_flash_api =
|
||||||
|
{
|
||||||
|
.read = nvm_api_read,
|
||||||
|
.write = nvm_api_write,
|
||||||
|
.erase = nvm_api_erase,
|
||||||
|
.sync = NULL,
|
||||||
|
.params = nvm_api_params
|
||||||
|
};
|
|
@ -0,0 +1,52 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2023 by Federico Amedeo Izzo IU2NUO, *
|
||||||
|
* Niccolò Izzo IU2KIN *
|
||||||
|
* Frederik Saraci IU2NRO *
|
||||||
|
* Silvano Seva IU2KWO *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FLASH_ZEPHYR_H
|
||||||
|
#define FLASH_ZEPHYR_H
|
||||||
|
|
||||||
|
#include <interfaces/nvmem.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper interface for the Zephyr RTOS flash memory device driver.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device driver API for Zephyr RTOS flash memory.
|
||||||
|
*/
|
||||||
|
extern const struct nvmApi zephyr_flash_api;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a nonvolatile memory device based on Zephyr RTOS flash device
|
||||||
|
* driver.
|
||||||
|
*
|
||||||
|
* @param name: device name.
|
||||||
|
* @param alias: devicetree alias of the flash device.
|
||||||
|
*/
|
||||||
|
#define ZEPHYR_FLASH_DEVICE_DEFINE(name, alias) \
|
||||||
|
static struct nvmParams flash_params_##name; \
|
||||||
|
static const struct nvmDevice name = \
|
||||||
|
{ \
|
||||||
|
.config = DEVICE_DT_GET(DT_ALIAS(alias)), \
|
||||||
|
.priv = &flash_params_##name, \
|
||||||
|
.api = &zephyr_flash_api \
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FLASH_ZEPHYR_H */
|
|
@ -19,6 +19,7 @@ target_sources(app
|
||||||
${OPENRTX_ROOT}/platform/drivers/baseband/SA8x8.c
|
${OPENRTX_ROOT}/platform/drivers/baseband/SA8x8.c
|
||||||
${OPENRTX_ROOT}/platform/drivers/GPS/GPS_ttwrplus.c
|
${OPENRTX_ROOT}/platform/drivers/GPS/GPS_ttwrplus.c
|
||||||
${OPENRTX_ROOT}/platform/drivers/audio/audio_ttwrplus.c
|
${OPENRTX_ROOT}/platform/drivers/audio/audio_ttwrplus.c
|
||||||
|
${OPENRTX_ROOT}/platform/drivers/NVM/flash_zephyr.c
|
||||||
|
|
||||||
${OPENRTX_ROOT}/platform/drivers/stubs/cps_io_stub.c
|
${OPENRTX_ROOT}/platform/drivers/stubs/cps_io_stub.c
|
||||||
${OPENRTX_ROOT}/platform/drivers/stubs/nvmem_stub.c
|
${OPENRTX_ROOT}/platform/drivers/stubs/nvmem_stub.c
|
||||||
|
|
|
@ -21,3 +21,6 @@ CONFIG_WS2812_STRIP=y
|
||||||
CONFIG_WS2812_STRIP_SPI=y
|
CONFIG_WS2812_STRIP_SPI=y
|
||||||
CONFIG_PICOLIBC_IO_FLOAT=y
|
CONFIG_PICOLIBC_IO_FLOAT=y
|
||||||
CONFIG_POSIX_API=y
|
CONFIG_POSIX_API=y
|
||||||
|
CONFIG_FLASH=y
|
||||||
|
CONFIG_FLASH_MAP=y
|
||||||
|
CONFIG_SOC_FLASH_ESP32=y
|
||||||
|
|
Ładowanie…
Reference in New Issue