Initial release
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
fds_types_internal.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 #ifndef FDS_TYPES_INTERNAL__ 00034 #define FDS_TYPES_INTERNAL__ 00035 00036 #include "fds.h" 00037 #include <stdint.h> 00038 #include <stdbool.h> 00039 #include "nrf_soc.h" 00040 00041 00042 #define COMMAND_EXECUTING (NRF_SUCCESS) 00043 #define COMMAND_COMPLETED (0x1234) 00044 //#define COMMAND_FAILED (0x1236) 00045 00046 #define FDS_MAGIC_HWORD (0xF11E) 00047 #define FDS_MAGIC_WORD (0x15ABE11A) 00048 #define FDS_ERASED_WORD (0xFFFFFFFF) 00049 00050 #define FDS_PAGE_TAG_SIZE (4) /**< Page tag size, in 4 byte words. */ 00051 00052 #define FDS_VPAGE_ID_UNKNOWN (0xFFFF) 00053 00054 #define FDS_WRITE_OFFSET_TL (0) /**< Offset of TL from the record base address, in 4 byte words. */ 00055 #define FDS_WRITE_OFFSET_IC (1) /**< Offset of IC from the record base address, in 4 byte words. */ 00056 #define FDS_WRITE_OFFSET_ID (2) /**< Offset of ID from the record base address, in 4 byte words. */ 00057 #define FDS_WRITE_OFFSET_DATA (3) /**< Offset of the data (chunks) from the record base address, in 4 byte words. */ 00058 00059 #define FDS_HEADER_SIZE_TL (1) /**< Size of the TL part of the header, in 4 byte words. */ 00060 #define FDS_HEADER_SIZE_ID (1) /**< Size of the IC part of the header, in 4 byte words. */ 00061 #define FDS_HEADER_SIZE_IC (1) /**< Size of the IC part of the header, in 4 byte words. */ 00062 #define FDS_HEADER_SIZE (3) /**< Size of the whole header, in 4 byte words. */ 00063 00064 #define FDS_CMD_QUEUE_SIZE_INIT (1) 00065 #define FDS_CMD_QUEUE_SIZE_WRITE (1) 00066 #define FDS_CMD_QUEUE_SIZE_CLEAR (1) 00067 #define FDS_CMD_QUEUE_SIZE_UPDATE (2) 00068 #define FDS_CMD_QUEUE_SIZE_GC (1) 00069 00070 00071 static uint8_t m_nested_critical; 00072 00073 /** Macros to enable and disable application interrupts. */ 00074 #define CRITICAL_SECTION_ENTER() //sd_nvic_critical_region_enter(&m_nested_critical) 00075 #define CRITICAL_SECTION_EXIT() //sd_nvic_critical_region_exit ( m_nested_critical) 00076 00077 /**@brief Page types. */ 00078 typedef enum 00079 { 00080 FDS_PAGE_UNDEFINED, /**< Undefined page type. */ 00081 FDS_PAGE_ERASED, /**< Page is erased. */ 00082 FDS_PAGE_VALID, /**< Page is ready for storage. */ 00083 FDS_PAGE_SWAP, /**< Page is reserved for GC. */ 00084 FDS_PAGE_GC /**< Page is being garbage collected. */ 00085 } fds_page_type_t; 00086 00087 00088 typedef enum 00089 { 00090 FDS_OP_NONE = 0x00, /**< No operation. */ 00091 FDS_OP_WRITE_TL, /**< Write the type and length. */ 00092 FDS_OP_WRITE_ID, /**< Write the record ID. */ 00093 FDS_OP_WRITE_CHUNK, /**< Write the record value. */ 00094 FDS_OP_WRITE_IC, /**< Write the instance and checksum. */ 00095 FDS_OP_CLEAR_TL, 00096 FDS_OP_CLEAR_INSTANCE, 00097 FDS_OP_DONE, 00098 } fds_opcode_t; 00099 00100 00101 typedef enum 00102 { 00103 FDS_FLAG_INITIALIZING = (1 << 0), /**< TODO: Not really needed atm? */ 00104 FDS_FLAG_INITIALIZED = (1 << 1), /**< Flag indicating that flash data storage has been initialized. */ 00105 FDS_FLAG_PROCESSING = (1 << 2), /**< Flag indicating that queue is being processed. */ 00106 FDS_FLAG_CAN_GC = (1 << 3), /**< Flag indicating that fds can regain data by performing garbage collection. */ 00107 } fds_flags_t; 00108 00109 00110 typedef struct 00111 { 00112 uint32_t const * start_addr; 00113 uint16_t vpage_id; /**< The page logical ID. */ 00114 uint16_t volatile write_offset; /**< The page write offset, in 4 bytes words. */ 00115 uint16_t volatile words_reserved; /**< The amount of words reserved by fds_write_reserve() on this page. */ 00116 uint16_t volatile records_open; 00117 fds_page_type_t page_type : 4; /**< The page type. */ 00118 } fds_page_t; 00119 00120 00121 typedef struct 00122 { 00123 fds_cmd_id_t id : 4; /**< The ID of the command. */ 00124 fds_opcode_t op_code : 4; 00125 uint8_t num_chunks; /**< Number of operations this command has left in the operation queue. */ 00126 uint16_t chunk_offset; /**< Offset used for writing the record value(s), in 4 byte words. */ 00127 uint16_t vpage_id; /**< The virtual page ID where we reserved the flash space for this command. */ 00128 fds_record_header_t record_header; 00129 } fds_cmd_t; 00130 00131 00132 /**@brief Defines command queue, an element is free if the op_code field is not invalid. 00133 * 00134 * @details Defines commands enqueued for flash access. At any point in time, this queue has one or 00135 * more flash access operations pending if the count field is not zero. When the queue is 00136 * not empty, the rp (read pointer) field points to the flash access command in progress 00137 * or, if none is in progress, the command to be requested next. The queue implements a 00138 * simple first in first out algorithm. Data addresses are assumed to be resident. 00139 */ 00140 typedef struct 00141 { 00142 fds_cmd_t cmd[FDS_CMD_QUEUE_SIZE]; /**< Array to maintain flash access operation details. */ 00143 uint8_t volatile rp; /**< The index of the command being executed. */ 00144 uint8_t volatile count; /**< Number of elements in the queue. */ 00145 } fds_cmd_queue_t; 00146 00147 00148 typedef struct 00149 { 00150 fds_record_chunk_t chunk[FDS_CHUNK_QUEUE_SIZE]; 00151 uint8_t volatile rp; 00152 uint8_t volatile count; 00153 } fds_chunk_queue_t; 00154 00155 00156 typedef enum 00157 { 00158 NONE, 00159 BEGIN, 00160 RESUME, 00161 GC_PAGE, 00162 COPY_RECORD, 00163 READY_SWAP, 00164 NEW_SWAP, 00165 INIT_SWAP 00166 } fds_gc_state_t; 00167 00168 00169 typedef struct 00170 { 00171 uint16_t cur_page; 00172 uint16_t swap_page; 00173 uint32_t const * p_scan_addr; 00174 fds_gc_state_t state; 00175 bool do_gc_page[FDS_MAX_PAGES]; 00176 } fds_gc_data_t; 00177 00178 #endif // FDS_TYPES_INTERNAL__
Generated on Tue Jul 12 2022 11:17:17 by 1.7.2