Tiny storage(file) system on MCU internal flash memory for Nucleo F4xx. The purpose of SOFBlock class is to provide a way to write data on flash memory in the same way of file handling class in the file system.
SOF_dev.h
00001 /** 00002 * @file SOF_dev.c 00003 * 00004 * @author hillkim7@gmail.com 00005 * @brief Storage On Flash device interface 00006 * 00007 */ 00008 00009 #pragma once 00010 00011 #include <stdint.h> 00012 #include <stddef.h> 00013 00014 /** The default value of erased flash memory */ 00015 #define SOF_ERASED_BYTE_VALUE 0xFF 00016 00017 #define SOF_INVALID_HANDLE 0xFFFFFFFF 00018 00019 /** Error code definition */ 00020 typedef enum { 00021 kSOF_ErrNone = 0, 00022 kSOF_ErrParam, 00023 kSOF_ErrNoInfo, 00024 kSOF_ErrBusyBlock, 00025 kSOF_ErrBadBlock, 00026 kSOF_ErrDataCurrupted, 00027 kSOF_ErrFatal, 00028 } SOF_Error_t;; 00029 00030 /** Flash sector specification */ 00031 typedef struct { 00032 uint32_t sec_no; 00033 uint32_t sec_addr; 00034 uint32_t sec_size; 00035 } SOF_SectorSpec_t; 00036 00037 /** statics of SOF block */ 00038 typedef struct { 00039 uint8_t *data_addr; 00040 uint32_t data_size; 00041 uint32_t free_size; 00042 } SOF_Statics_t; 00043 00044 typedef uint32_t SOF_DevHandle_t; 00045 00046 class SOF_BlockHandle; 00047 typedef SOF_BlockHandle* SOF_BlockHandle_t; 00048 00049 /*-----------------------------------------------------------------------------------------------------*/ 00050 /* Flash device interface */ 00051 /*-----------------------------------------------------------------------------------------------------*/ 00052 int SOF_dev_is_valid_sector(uint8_t sector_index); 00053 const SOF_SectorSpec_t *SOF_dev_info(SOF_DevHandle_t hdev); 00054 const SOF_SectorSpec_t *SOF_dev_info_by_index(uint8_t sector_index); 00055 SOF_DevHandle_t SOF_dev_open(uint8_t sector_index); 00056 void SOF_dev_close(SOF_DevHandle_t hdev); 00057 uint8_t *SOF_dev_get_hw_addr(SOF_DevHandle_t hdev); 00058 void SOF_dev_erase(SOF_DevHandle_t handle); 00059 int SOF_dev_write_word(SOF_DevHandle_t handle, uint32_t offset_addr, uint32_t data); 00060 uint32_t SOF_dev_read_word(SOF_DevHandle_t handle, uint32_t offset_addr); 00061 int SOF_dev_write_byte(SOF_DevHandle_t handle, uint32_t offset_addr, uint8_t data); 00062 uint8_t SOF_dev_read_byte(SOF_DevHandle_t handle, uint32_t offset_addr); 00063 00064 /*-----------------------------------------------------------------------------------------------------*/ 00065 /* Flash block device interface */ 00066 /*-----------------------------------------------------------------------------------------------------*/ 00067 bool SOF_block_format(uint8_t sector_index); 00068 SOF_BlockHandle_t SOF_block_open_storage(uint8_t sector_index, SOF_Error_t *err); 00069 SOF_BlockHandle_t SOF_block_create_storage(uint8_t sector_index, SOF_Error_t *err); 00070 bool SOF_block_close(SOF_BlockHandle_t handle); 00071 uint8_t *SOF_block_base_addr(SOF_BlockHandle_t handle); 00072 bool SOF_block_putc(SOF_BlockHandle_t handle, uint8_t c); 00073 size_t SOF_block_write(SOF_BlockHandle_t handle, const uint8_t *p, size_t p_size); 00074 bool SOF_block_getc(SOF_BlockHandle_t handle, uint8_t *c); 00075 size_t SOF_block_read(SOF_BlockHandle_t handle, uint8_t *p, size_t p_size); 00076 size_t SOF_block_get_free_size(SOF_BlockHandle_t handle); 00077 uint32_t SOF_block_storage_size(SOF_BlockHandle_t handle); 00078 SOF_Error_t SOF_block_get_statics(uint8_t sector_index, SOF_Statics_t *stat); 00079 const SOF_SectorSpec_t *SOF_block_get_info(uint8_t sector_index); 00080 00081
Generated on Fri Nov 18 2022 07:19:36 by
1.7.2