119ea8026Sopenharmony_ci/* 219ea8026Sopenharmony_ci * Block device emulated in RAM 319ea8026Sopenharmony_ci * 419ea8026Sopenharmony_ci * Copyright (c) 2022, The littlefs authors. 519ea8026Sopenharmony_ci * Copyright (c) 2017, Arm Limited. All rights reserved. 619ea8026Sopenharmony_ci * SPDX-License-Identifier: BSD-3-Clause 719ea8026Sopenharmony_ci */ 819ea8026Sopenharmony_ci#ifndef LFS_RAMBD_H 919ea8026Sopenharmony_ci#define LFS_RAMBD_H 1019ea8026Sopenharmony_ci 1119ea8026Sopenharmony_ci#include "lfs.h" 1219ea8026Sopenharmony_ci#include "lfs_util.h" 1319ea8026Sopenharmony_ci 1419ea8026Sopenharmony_ci#ifdef __cplusplus 1519ea8026Sopenharmony_ciextern "C" 1619ea8026Sopenharmony_ci{ 1719ea8026Sopenharmony_ci#endif 1819ea8026Sopenharmony_ci 1919ea8026Sopenharmony_ci 2019ea8026Sopenharmony_ci// Block device specific tracing 2119ea8026Sopenharmony_ci#ifndef LFS_RAMBD_TRACE 2219ea8026Sopenharmony_ci#ifdef LFS_RAMBD_YES_TRACE 2319ea8026Sopenharmony_ci#define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__) 2419ea8026Sopenharmony_ci#else 2519ea8026Sopenharmony_ci#define LFS_RAMBD_TRACE(...) 2619ea8026Sopenharmony_ci#endif 2719ea8026Sopenharmony_ci#endif 2819ea8026Sopenharmony_ci 2919ea8026Sopenharmony_ci// rambd config 3019ea8026Sopenharmony_cistruct lfs_rambd_config { 3119ea8026Sopenharmony_ci // Minimum size of a read operation in bytes. 3219ea8026Sopenharmony_ci lfs_size_t read_size; 3319ea8026Sopenharmony_ci 3419ea8026Sopenharmony_ci // Minimum size of a program operation in bytes. 3519ea8026Sopenharmony_ci lfs_size_t prog_size; 3619ea8026Sopenharmony_ci 3719ea8026Sopenharmony_ci // Size of an erase operation in bytes. 3819ea8026Sopenharmony_ci lfs_size_t erase_size; 3919ea8026Sopenharmony_ci 4019ea8026Sopenharmony_ci // Number of erase blocks on the device. 4119ea8026Sopenharmony_ci lfs_size_t erase_count; 4219ea8026Sopenharmony_ci 4319ea8026Sopenharmony_ci // Optional statically allocated buffer for the block device. 4419ea8026Sopenharmony_ci void *buffer; 4519ea8026Sopenharmony_ci}; 4619ea8026Sopenharmony_ci 4719ea8026Sopenharmony_ci// rambd state 4819ea8026Sopenharmony_citypedef struct lfs_rambd { 4919ea8026Sopenharmony_ci uint8_t *buffer; 5019ea8026Sopenharmony_ci const struct lfs_rambd_config *cfg; 5119ea8026Sopenharmony_ci} lfs_rambd_t; 5219ea8026Sopenharmony_ci 5319ea8026Sopenharmony_ci 5419ea8026Sopenharmony_ci// Create a RAM block device 5519ea8026Sopenharmony_ciint lfs_rambd_create(const struct lfs_config *cfg, 5619ea8026Sopenharmony_ci const struct lfs_rambd_config *bdcfg); 5719ea8026Sopenharmony_ci 5819ea8026Sopenharmony_ci// Clean up memory associated with block device 5919ea8026Sopenharmony_ciint lfs_rambd_destroy(const struct lfs_config *cfg); 6019ea8026Sopenharmony_ci 6119ea8026Sopenharmony_ci// Read a block 6219ea8026Sopenharmony_ciint lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, 6319ea8026Sopenharmony_ci lfs_off_t off, void *buffer, lfs_size_t size); 6419ea8026Sopenharmony_ci 6519ea8026Sopenharmony_ci// Program a block 6619ea8026Sopenharmony_ci// 6719ea8026Sopenharmony_ci// The block must have previously been erased. 6819ea8026Sopenharmony_ciint lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, 6919ea8026Sopenharmony_ci lfs_off_t off, const void *buffer, lfs_size_t size); 7019ea8026Sopenharmony_ci 7119ea8026Sopenharmony_ci// Erase a block 7219ea8026Sopenharmony_ci// 7319ea8026Sopenharmony_ci// A block must be erased before being programmed. The 7419ea8026Sopenharmony_ci// state of an erased block is undefined. 7519ea8026Sopenharmony_ciint lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block); 7619ea8026Sopenharmony_ci 7719ea8026Sopenharmony_ci// Sync the block device 7819ea8026Sopenharmony_ciint lfs_rambd_sync(const struct lfs_config *cfg); 7919ea8026Sopenharmony_ci 8019ea8026Sopenharmony_ci 8119ea8026Sopenharmony_ci#ifdef __cplusplus 8219ea8026Sopenharmony_ci} /* extern "C" */ 8319ea8026Sopenharmony_ci#endif 8419ea8026Sopenharmony_ci 8519ea8026Sopenharmony_ci#endif 86