Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lfs_emubd.h Source File

lfs_emubd.h

00001 /*
00002  * Block device emulated on standard files
00003  *
00004  * Copyright (c) 2017, Arm Limited. All rights reserved.
00005  * SPDX-License-Identifier: BSD-3-Clause
00006  */
00007 #ifndef LFS_EMUBD_H
00008 #define LFS_EMUBD_H
00009 
00010 #include "lfs.h"
00011 #include "lfs_util.h"
00012 
00013 #ifdef __cplusplus
00014 extern "C"
00015 {
00016 #endif
00017 
00018 
00019 // Config options
00020 #ifndef LFS_EMUBD_READ_SIZE
00021 #define LFS_EMUBD_READ_SIZE 1
00022 #endif
00023 
00024 #ifndef LFS_EMUBD_PROG_SIZE
00025 #define LFS_EMUBD_PROG_SIZE 1
00026 #endif
00027 
00028 #ifndef LFS_EMUBD_ERASE_SIZE
00029 #define LFS_EMUBD_ERASE_SIZE 512
00030 #endif
00031 
00032 #ifndef LFS_EMUBD_TOTAL_SIZE
00033 #define LFS_EMUBD_TOTAL_SIZE 524288
00034 #endif
00035 
00036 
00037 // The emu bd state
00038 typedef struct lfs_emubd {
00039     char *path;
00040     char *child;
00041 
00042     struct {
00043         uint64_t read_count;
00044         uint64_t prog_count;
00045         uint64_t erase_count;
00046     } stats;
00047 
00048     struct {
00049         uint32_t read_size;
00050         uint32_t prog_size;
00051         uint32_t block_size;
00052         uint32_t block_count;
00053     } cfg;
00054 } lfs_emubd_t;
00055 
00056 
00057 // Create a block device using path for the directory to store blocks
00058 int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
00059 
00060 // Clean up memory associated with emu block device
00061 void lfs_emubd_destroy(const struct lfs_config *cfg);
00062 
00063 // Read a block
00064 int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
00065         lfs_off_t off, void *buffer, lfs_size_t size);
00066 
00067 // Program a block
00068 //
00069 // The block must have previously been erased.
00070 int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
00071         lfs_off_t off, const void *buffer, lfs_size_t size);
00072 
00073 // Erase a block
00074 //
00075 // A block must be erased before being programmed. The
00076 // state of an erased block is undefined.
00077 int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
00078 
00079 // Sync the block device
00080 int lfs_emubd_sync(const struct lfs_config *cfg);
00081 
00082 
00083 #ifdef __cplusplus
00084 } /* extern "C" */
00085 #endif
00086 
00087 #endif