mbed official / mbed-dev

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
<>
Date:
Wed Apr 12 16:21:43 2017 +0100
Revision:
162:e13f6fdb2ac4
This updates the lib to the mbed lib v140

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 162:e13f6fdb2ac4 1 /*
<> 162:e13f6fdb2ac4 2 * Copyright (c) 2015 Nordic Semiconductor ASA
<> 162:e13f6fdb2ac4 3 * All rights reserved.
<> 162:e13f6fdb2ac4 4 *
<> 162:e13f6fdb2ac4 5 * Redistribution and use in source and binary forms, with or without modification,
<> 162:e13f6fdb2ac4 6 * are permitted provided that the following conditions are met:
<> 162:e13f6fdb2ac4 7 *
<> 162:e13f6fdb2ac4 8 * 1. Redistributions of source code must retain the above copyright notice, this list
<> 162:e13f6fdb2ac4 9 * of conditions and the following disclaimer.
<> 162:e13f6fdb2ac4 10 *
<> 162:e13f6fdb2ac4 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
<> 162:e13f6fdb2ac4 12 * integrated circuit in a product or a software update for such product, must reproduce
<> 162:e13f6fdb2ac4 13 * the above copyright notice, this list of conditions and the following disclaimer in
<> 162:e13f6fdb2ac4 14 * the documentation and/or other materials provided with the distribution.
<> 162:e13f6fdb2ac4 15 *
<> 162:e13f6fdb2ac4 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
<> 162:e13f6fdb2ac4 17 * used to endorse or promote products derived from this software without specific prior
<> 162:e13f6fdb2ac4 18 * written permission.
<> 162:e13f6fdb2ac4 19 *
<> 162:e13f6fdb2ac4 20 * 4. This software, with or without modification, must only be used with a
<> 162:e13f6fdb2ac4 21 * Nordic Semiconductor ASA integrated circuit.
<> 162:e13f6fdb2ac4 22 *
<> 162:e13f6fdb2ac4 23 * 5. Any software provided in binary or object form under this license must not be reverse
<> 162:e13f6fdb2ac4 24 * engineered, decompiled, modified and/or disassembled.
<> 162:e13f6fdb2ac4 25 *
<> 162:e13f6fdb2ac4 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<> 162:e13f6fdb2ac4 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<> 162:e13f6fdb2ac4 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 162:e13f6fdb2ac4 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
<> 162:e13f6fdb2ac4 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<> 162:e13f6fdb2ac4 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<> 162:e13f6fdb2ac4 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
<> 162:e13f6fdb2ac4 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<> 162:e13f6fdb2ac4 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<> 162:e13f6fdb2ac4 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 162:e13f6fdb2ac4 36 *
<> 162:e13f6fdb2ac4 37 */
<> 162:e13f6fdb2ac4 38
<> 162:e13f6fdb2ac4 39 #ifndef FDS_INTERNAL_DEFS_H__
<> 162:e13f6fdb2ac4 40 #define FDS_INTERNAL_DEFS_H__
<> 162:e13f6fdb2ac4 41 #include "sdk_config.h"
<> 162:e13f6fdb2ac4 42 #include <stdint.h>
<> 162:e13f6fdb2ac4 43 #include <stdbool.h>
<> 162:e13f6fdb2ac4 44
<> 162:e13f6fdb2ac4 45 #if defined (FDS_THREADS)
<> 162:e13f6fdb2ac4 46 #include "nrf_soc.h"
<> 162:e13f6fdb2ac4 47 #include "app_util_platform.h"
<> 162:e13f6fdb2ac4 48 #endif
<> 162:e13f6fdb2ac4 49
<> 162:e13f6fdb2ac4 50 #ifdef __cplusplus
<> 162:e13f6fdb2ac4 51 extern "C" {
<> 162:e13f6fdb2ac4 52 #endif
<> 162:e13f6fdb2ac4 53
<> 162:e13f6fdb2ac4 54 #define FDS_PAGE_TAG_SIZE (2) // Page tag size, in 4-byte words.
<> 162:e13f6fdb2ac4 55 #define FDS_PAGE_TAG_WORD_0 (0) // Offset of the first word in the page tag from the page address.
<> 162:e13f6fdb2ac4 56 #define FDS_PAGE_TAG_WORD_1 (1) // Offset of the second word in the page tag from the page address.
<> 162:e13f6fdb2ac4 57
<> 162:e13f6fdb2ac4 58 // Page tag constants
<> 162:e13f6fdb2ac4 59 #define FDS_PAGE_TAG_MAGIC (0xDEADC0DE)
<> 162:e13f6fdb2ac4 60 #define FDS_PAGE_TAG_SWAP (0xF11E01FF)
<> 162:e13f6fdb2ac4 61 #define FDS_PAGE_TAG_DATA (0xF11E01FE)
<> 162:e13f6fdb2ac4 62
<> 162:e13f6fdb2ac4 63 #define FDS_ERASED_WORD (0xFFFFFFFF)
<> 162:e13f6fdb2ac4 64
<> 162:e13f6fdb2ac4 65 #define FDS_OFFSET_TL (0) // Offset of TL from the record base address, in 4-byte words.
<> 162:e13f6fdb2ac4 66 #define FDS_OFFSET_IC (1) // Offset of IC from the record base address, in 4-byte words.
<> 162:e13f6fdb2ac4 67 #define FDS_OFFSET_ID (2) // Offset of ID from the record base address, in 4-byte words.
<> 162:e13f6fdb2ac4 68 #define FDS_OFFSET_DATA (3) // Offset of the data (chunks) from the record base address, in 4-byte words.
<> 162:e13f6fdb2ac4 69
<> 162:e13f6fdb2ac4 70 #define FDS_HEADER_SIZE_TL (1) // Size of the TL part of the header, in 4-byte words.
<> 162:e13f6fdb2ac4 71 #define FDS_HEADER_SIZE_IC (1) // Size of the IC part of the header, in 4-byte words.
<> 162:e13f6fdb2ac4 72 #define FDS_HEADER_SIZE_ID (1) // Size of the record ID in the header, in 4-byte words.
<> 162:e13f6fdb2ac4 73 #define FDS_HEADER_SIZE (3) // Size of the whole header, in 4-byte words.
<> 162:e13f6fdb2ac4 74
<> 162:e13f6fdb2ac4 75 #define FDS_OP_EXECUTING (FS_SUCCESS)
<> 162:e13f6fdb2ac4 76 #define FDS_OP_COMPLETED (0x1D1D)
<> 162:e13f6fdb2ac4 77
<> 162:e13f6fdb2ac4 78 // The size of a physical page, in 4-byte words.
<> 162:e13f6fdb2ac4 79 #if defined(NRF51)
<> 162:e13f6fdb2ac4 80 #define FDS_PHY_PAGE_SIZE (256)
<> 162:e13f6fdb2ac4 81 #elif (defined(NRF52) || defined(NRF52840_XXAA))
<> 162:e13f6fdb2ac4 82 #define FDS_PHY_PAGE_SIZE (1024)
<> 162:e13f6fdb2ac4 83 #endif
<> 162:e13f6fdb2ac4 84
<> 162:e13f6fdb2ac4 85 // The number of physical pages to be used. This value is configured indirectly.
<> 162:e13f6fdb2ac4 86 #define FDS_PHY_PAGES ((FDS_VIRTUAL_PAGES * FDS_VIRTUAL_PAGE_SIZE) / FDS_PHY_PAGE_SIZE)
<> 162:e13f6fdb2ac4 87
<> 162:e13f6fdb2ac4 88 // The size of a virtual page, in number of physical pages.
<> 162:e13f6fdb2ac4 89 #define FDS_PHY_PAGES_IN_VPAGE (FDS_VIRTUAL_PAGE_SIZE / FDS_PHY_PAGE_SIZE)
<> 162:e13f6fdb2ac4 90
<> 162:e13f6fdb2ac4 91 // The number of pages available to store data; which is the total minus one (the swap).
<> 162:e13f6fdb2ac4 92 #define FDS_MAX_PAGES (FDS_VIRTUAL_PAGES - 1)
<> 162:e13f6fdb2ac4 93
<> 162:e13f6fdb2ac4 94 // Just a shorter name for the size, in words, of a virtual page.
<> 162:e13f6fdb2ac4 95 #define FDS_PAGE_SIZE (FDS_VIRTUAL_PAGE_SIZE)
<> 162:e13f6fdb2ac4 96
<> 162:e13f6fdb2ac4 97
<> 162:e13f6fdb2ac4 98 #if (FDS_VIRTUAL_PAGE_SIZE % FDS_PHY_PAGE_SIZE != 0)
<> 162:e13f6fdb2ac4 99 #error "FDS_VIRTUAL_PAGE_SIZE must be a multiple of the size of a physical page."
<> 162:e13f6fdb2ac4 100 #endif
<> 162:e13f6fdb2ac4 101
<> 162:e13f6fdb2ac4 102 #if (FDS_VIRTUAL_PAGES < 2)
<> 162:e13f6fdb2ac4 103 #error "FDS requires at least two virtual pages."
<> 162:e13f6fdb2ac4 104 #endif
<> 162:e13f6fdb2ac4 105
<> 162:e13f6fdb2ac4 106
<> 162:e13f6fdb2ac4 107 // FDS internal status flags.
<> 162:e13f6fdb2ac4 108 typedef enum
<> 162:e13f6fdb2ac4 109 {
<> 162:e13f6fdb2ac4 110 FDS_FLAG_INITIALIZING = (1 << 0), // The module is initializing.
<> 162:e13f6fdb2ac4 111 FDS_FLAG_INITIALIZED = (1 << 1), // The module is initialized.
<> 162:e13f6fdb2ac4 112 FDS_FLAG_PROCESSING = (1 << 2), // The queue is being processed.
<> 162:e13f6fdb2ac4 113 FDS_FLAG_VERIFY_CRC = (1 << 3), // Verify CRC upon writing a record.
<> 162:e13f6fdb2ac4 114 } fds_flags_t;
<> 162:e13f6fdb2ac4 115
<> 162:e13f6fdb2ac4 116
<> 162:e13f6fdb2ac4 117 // Page types.
<> 162:e13f6fdb2ac4 118 typedef enum
<> 162:e13f6fdb2ac4 119 {
<> 162:e13f6fdb2ac4 120 FDS_PAGE_DATA, // Page is ready for storage.
<> 162:e13f6fdb2ac4 121 FDS_PAGE_SWAP, // Page is reserved for garbage collection.
<> 162:e13f6fdb2ac4 122 FDS_PAGE_ERASED, // Page is erased.
<> 162:e13f6fdb2ac4 123 FDS_PAGE_UNDEFINED, // Undefined page type.
<> 162:e13f6fdb2ac4 124 } fds_page_type_t;
<> 162:e13f6fdb2ac4 125
<> 162:e13f6fdb2ac4 126
<> 162:e13f6fdb2ac4 127 typedef struct
<> 162:e13f6fdb2ac4 128 {
<> 162:e13f6fdb2ac4 129 fds_page_type_t page_type; // The page type.
<> 162:e13f6fdb2ac4 130 uint32_t const * p_addr; // The address of the page.
<> 162:e13f6fdb2ac4 131 uint16_t write_offset; // The page write offset, in 4-byte words.
<> 162:e13f6fdb2ac4 132 uint16_t words_reserved; // The amount of words reserved by fds_write_reserve().
<> 162:e13f6fdb2ac4 133 uint16_t records_open; // The number of records opened using fds_open().
<> 162:e13f6fdb2ac4 134 bool can_gc; // Indicates that there are some records that have been deleted.
<> 162:e13f6fdb2ac4 135 } fds_page_t;
<> 162:e13f6fdb2ac4 136
<> 162:e13f6fdb2ac4 137
<> 162:e13f6fdb2ac4 138 typedef struct
<> 162:e13f6fdb2ac4 139 {
<> 162:e13f6fdb2ac4 140 uint32_t const * p_addr;
<> 162:e13f6fdb2ac4 141 uint16_t write_offset;
<> 162:e13f6fdb2ac4 142 } fds_swap_page_t;
<> 162:e13f6fdb2ac4 143
<> 162:e13f6fdb2ac4 144
<> 162:e13f6fdb2ac4 145 // FDS op-codes.
<> 162:e13f6fdb2ac4 146 typedef enum
<> 162:e13f6fdb2ac4 147 {
<> 162:e13f6fdb2ac4 148 FDS_OP_NONE,
<> 162:e13f6fdb2ac4 149 FDS_OP_INIT, // Initialize the module.
<> 162:e13f6fdb2ac4 150 FDS_OP_WRITE, // Write a record to flash.
<> 162:e13f6fdb2ac4 151 FDS_OP_UPDATE, // Update a record.
<> 162:e13f6fdb2ac4 152 FDS_OP_DEL_RECORD, // Delete a record.
<> 162:e13f6fdb2ac4 153 FDS_OP_DEL_FILE, // Delete a file.
<> 162:e13f6fdb2ac4 154 FDS_OP_GC // Run garbage collection.
<> 162:e13f6fdb2ac4 155 } fds_op_code_t;
<> 162:e13f6fdb2ac4 156
<> 162:e13f6fdb2ac4 157
<> 162:e13f6fdb2ac4 158 typedef enum
<> 162:e13f6fdb2ac4 159 {
<> 162:e13f6fdb2ac4 160 FDS_OP_INIT_TAG_SWAP,
<> 162:e13f6fdb2ac4 161 FDS_OP_INIT_TAG_DATA,
<> 162:e13f6fdb2ac4 162 FDS_OP_INIT_ERASE_SWAP,
<> 162:e13f6fdb2ac4 163 FDS_OP_INIT_PROMOTE_SWAP,
<> 162:e13f6fdb2ac4 164 } fds_init_step_t;
<> 162:e13f6fdb2ac4 165
<> 162:e13f6fdb2ac4 166
<> 162:e13f6fdb2ac4 167 typedef enum
<> 162:e13f6fdb2ac4 168 {
<> 162:e13f6fdb2ac4 169 FDS_OP_WRITE_HEADER_BEGIN, // Write the record key and length.
<> 162:e13f6fdb2ac4 170 FDS_OP_WRITE_HEADER_FINALIZE, // Write the file ID and CRC.
<> 162:e13f6fdb2ac4 171 FDS_OP_WRITE_RECORD_ID, // Write the record ID.
<> 162:e13f6fdb2ac4 172 FDS_OP_WRITE_CHUNKS, // Write the record data.
<> 162:e13f6fdb2ac4 173 FDS_OP_WRITE_FIND_RECORD,
<> 162:e13f6fdb2ac4 174 FDS_OP_WRITE_FLAG_DIRTY, // Flag a record as dirty (as part of an update operation).
<> 162:e13f6fdb2ac4 175 FDS_OP_WRITE_DONE,
<> 162:e13f6fdb2ac4 176 } fds_write_step_t;
<> 162:e13f6fdb2ac4 177
<> 162:e13f6fdb2ac4 178
<> 162:e13f6fdb2ac4 179 typedef enum
<> 162:e13f6fdb2ac4 180 {
<> 162:e13f6fdb2ac4 181 FDS_OP_DEL_RECORD_FLAG_DIRTY, // Flag a record as dirty.
<> 162:e13f6fdb2ac4 182 FDS_OP_DEL_FILE_FLAG_DIRTY, // Flag multiple records as dirty.
<> 162:e13f6fdb2ac4 183 FDS_OP_DEL_DONE,
<> 162:e13f6fdb2ac4 184 } fds_delete_step_t;
<> 162:e13f6fdb2ac4 185
<> 162:e13f6fdb2ac4 186
<> 162:e13f6fdb2ac4 187 #if defined(__CC_ARM)
<> 162:e13f6fdb2ac4 188 #pragma push
<> 162:e13f6fdb2ac4 189 #pragma anon_unions
<> 162:e13f6fdb2ac4 190 #elif defined(__ICCARM__)
<> 162:e13f6fdb2ac4 191 #pragma language=extended
<> 162:e13f6fdb2ac4 192 #elif defined(__GNUC__)
<> 162:e13f6fdb2ac4 193 // anonymous unions are enabled by default
<> 162:e13f6fdb2ac4 194 #endif
<> 162:e13f6fdb2ac4 195
<> 162:e13f6fdb2ac4 196 typedef struct
<> 162:e13f6fdb2ac4 197 {
<> 162:e13f6fdb2ac4 198 fds_op_code_t op_code; // The opcode for the operation.
<> 162:e13f6fdb2ac4 199 union
<> 162:e13f6fdb2ac4 200 {
<> 162:e13f6fdb2ac4 201 struct
<> 162:e13f6fdb2ac4 202 {
<> 162:e13f6fdb2ac4 203 fds_init_step_t step; // The current step the operation is at.
<> 162:e13f6fdb2ac4 204 } init;
<> 162:e13f6fdb2ac4 205 struct
<> 162:e13f6fdb2ac4 206 {
<> 162:e13f6fdb2ac4 207 fds_header_t header;
<> 162:e13f6fdb2ac4 208 fds_write_step_t step; // The current step the operation is at.
<> 162:e13f6fdb2ac4 209 uint16_t page; // The page the flash space for this command was reserved.
<> 162:e13f6fdb2ac4 210 uint16_t chunk_offset; // Offset used for writing record chunks, in 4-byte words.
<> 162:e13f6fdb2ac4 211 uint8_t chunk_count; // Number of chunks to be written.
<> 162:e13f6fdb2ac4 212 uint32_t record_to_delete; // The record to delete in case this is an update.
<> 162:e13f6fdb2ac4 213 } write;
<> 162:e13f6fdb2ac4 214 struct
<> 162:e13f6fdb2ac4 215 {
<> 162:e13f6fdb2ac4 216 fds_delete_step_t step;
<> 162:e13f6fdb2ac4 217 uint16_t file_id;
<> 162:e13f6fdb2ac4 218 uint16_t record_key;
<> 162:e13f6fdb2ac4 219 uint32_t record_to_delete;
<> 162:e13f6fdb2ac4 220 } del;
<> 162:e13f6fdb2ac4 221 };
<> 162:e13f6fdb2ac4 222 } fds_op_t;
<> 162:e13f6fdb2ac4 223
<> 162:e13f6fdb2ac4 224 #if defined(__CC_ARM)
<> 162:e13f6fdb2ac4 225 #pragma pop
<> 162:e13f6fdb2ac4 226 #elif defined(__ICCARM__)
<> 162:e13f6fdb2ac4 227 // leave anonymous unions enabled
<> 162:e13f6fdb2ac4 228 #elif defined(__GNUC__)
<> 162:e13f6fdb2ac4 229 // anonymous unions are enabled by default
<> 162:e13f6fdb2ac4 230 #endif
<> 162:e13f6fdb2ac4 231
<> 162:e13f6fdb2ac4 232
<> 162:e13f6fdb2ac4 233 typedef struct
<> 162:e13f6fdb2ac4 234 {
<> 162:e13f6fdb2ac4 235 fds_op_t op[FDS_OP_QUEUE_SIZE]; // Queued flash operations.
<> 162:e13f6fdb2ac4 236 uint32_t rp; // The index of the command being executed.
<> 162:e13f6fdb2ac4 237 uint32_t count; // Number of elements in the queue.
<> 162:e13f6fdb2ac4 238 } fds_op_queue_t;
<> 162:e13f6fdb2ac4 239
<> 162:e13f6fdb2ac4 240
<> 162:e13f6fdb2ac4 241 typedef struct
<> 162:e13f6fdb2ac4 242 {
<> 162:e13f6fdb2ac4 243 fds_record_chunk_t chunk[FDS_CHUNK_QUEUE_SIZE];
<> 162:e13f6fdb2ac4 244 uint32_t rp;
<> 162:e13f6fdb2ac4 245 uint32_t count;
<> 162:e13f6fdb2ac4 246 } fds_chunk_queue_t;
<> 162:e13f6fdb2ac4 247
<> 162:e13f6fdb2ac4 248
<> 162:e13f6fdb2ac4 249 enum
<> 162:e13f6fdb2ac4 250 {
<> 162:e13f6fdb2ac4 251 PAGE_ERASED = 0x1,
<> 162:e13f6fdb2ac4 252 PAGE_DATA = 0x2,
<> 162:e13f6fdb2ac4 253 SWAP_EMPTY = 0x4,
<> 162:e13f6fdb2ac4 254 SWAP_DIRTY = 0x8,
<> 162:e13f6fdb2ac4 255 };
<> 162:e13f6fdb2ac4 256
<> 162:e13f6fdb2ac4 257
<> 162:e13f6fdb2ac4 258 typedef enum
<> 162:e13f6fdb2ac4 259 {
<> 162:e13f6fdb2ac4 260 // This is a fatal error.
<> 162:e13f6fdb2ac4 261 NO_PAGES,
<> 162:e13f6fdb2ac4 262
<> 162:e13f6fdb2ac4 263 // All pages are erased. Perform a fresh installation.
<> 162:e13f6fdb2ac4 264 FRESH_INSTALL = (PAGE_ERASED),
<> 162:e13f6fdb2ac4 265
<> 162:e13f6fdb2ac4 266 // Swap is missing. Tag an erased page as swap.
<> 162:e13f6fdb2ac4 267 TAG_SWAP = (PAGE_ERASED | PAGE_DATA),
<> 162:e13f6fdb2ac4 268
<> 162:e13f6fdb2ac4 269 // Swap is empty. Tag all erased pages as data.
<> 162:e13f6fdb2ac4 270 TAG_DATA = (PAGE_ERASED | SWAP_EMPTY),
<> 162:e13f6fdb2ac4 271
<> 162:e13f6fdb2ac4 272 // Swap is empty. Tag all remaining erased pages as data.
<> 162:e13f6fdb2ac4 273 TAG_DATA_INST = (PAGE_ERASED | PAGE_DATA | SWAP_EMPTY),
<> 162:e13f6fdb2ac4 274
<> 162:e13f6fdb2ac4 275 // The swap is dirty. This indicates that the device powered off during GC. However, since there
<> 162:e13f6fdb2ac4 276 // is also an erased page, it is possible to assume that that page had been entirely garbage
<> 162:e13f6fdb2ac4 277 // collected. Hence, tag the swap as data, one erased page as swap and any remaining pages as data.
<> 162:e13f6fdb2ac4 278 PROMOTE_SWAP = (PAGE_ERASED | SWAP_DIRTY),
<> 162:e13f6fdb2ac4 279
<> 162:e13f6fdb2ac4 280 // Similar to the above. Tag the swap as data, one erased page as swap, and any remain
<> 162:e13f6fdb2ac4 281 // pages as data.
<> 162:e13f6fdb2ac4 282 PROMOTE_SWAP_INST = (PAGE_ERASED | PAGE_DATA | SWAP_DIRTY),
<> 162:e13f6fdb2ac4 283
<> 162:e13f6fdb2ac4 284 // The swap is dirty (written) and there are no erased pages. This indicates that the device
<> 162:e13f6fdb2ac4 285 // was powered off during GC. It is safe to discard (erase) the swap, since data that was
<> 162:e13f6fdb2ac4 286 // swapped out lies in one of the valid pages.
<> 162:e13f6fdb2ac4 287 DISCARD_SWAP = (PAGE_DATA | SWAP_DIRTY),
<> 162:e13f6fdb2ac4 288
<> 162:e13f6fdb2ac4 289 // Do nothing.
<> 162:e13f6fdb2ac4 290 ALREADY_INSTALLED = (PAGE_DATA | SWAP_EMPTY),
<> 162:e13f6fdb2ac4 291
<> 162:e13f6fdb2ac4 292 } fds_init_opts_t;
<> 162:e13f6fdb2ac4 293
<> 162:e13f6fdb2ac4 294
<> 162:e13f6fdb2ac4 295 typedef enum
<> 162:e13f6fdb2ac4 296 {
<> 162:e13f6fdb2ac4 297 GC_BEGIN, // Begin GC.
<> 162:e13f6fdb2ac4 298 GC_NEXT_PAGE, // GC a page.
<> 162:e13f6fdb2ac4 299 GC_FIND_NEXT_RECORD, // Find a valid record to copy.
<> 162:e13f6fdb2ac4 300 GC_COPY_RECORD, // Copy a valid record to swap.
<> 162:e13f6fdb2ac4 301 GC_ERASE_PAGE, // Erase the page being garbage collected.
<> 162:e13f6fdb2ac4 302 GC_DISCARD_SWAP, // Erase (discard) the swap page.
<> 162:e13f6fdb2ac4 303 GC_PROMOTE_SWAP, // Tag the swap as valid.
<> 162:e13f6fdb2ac4 304 GC_TAG_NEW_SWAP // Tag a freshly erased (GCed) page as swap.
<> 162:e13f6fdb2ac4 305 } fds_gc_state_t;
<> 162:e13f6fdb2ac4 306
<> 162:e13f6fdb2ac4 307
<> 162:e13f6fdb2ac4 308 // Holds garbage collection status and related data.
<> 162:e13f6fdb2ac4 309 typedef struct
<> 162:e13f6fdb2ac4 310 {
<> 162:e13f6fdb2ac4 311 fds_gc_state_t state; // The current GC step.
<> 162:e13f6fdb2ac4 312 uint16_t cur_page; // The current page being garbage collected.
<> 162:e13f6fdb2ac4 313 uint32_t const * p_record_src; // The current record being copied to swap.
<> 162:e13f6fdb2ac4 314 uint16_t run_count; // Total number of times GC was run.
<> 162:e13f6fdb2ac4 315 bool do_gc_page[FDS_MAX_PAGES]; // Controls which pages to garbage collect.
<> 162:e13f6fdb2ac4 316 bool resume; // Whether or not GC should be resumed.
<> 162:e13f6fdb2ac4 317 } fds_gc_data_t;
<> 162:e13f6fdb2ac4 318
<> 162:e13f6fdb2ac4 319
<> 162:e13f6fdb2ac4 320 // Macros to enable and disable application interrupts.
<> 162:e13f6fdb2ac4 321 #if defined (FDS_THREADS)
<> 162:e13f6fdb2ac4 322
<> 162:e13f6fdb2ac4 323 #define CRITICAL_SECTION_ENTER() CRITICAL_REGION_ENTER()
<> 162:e13f6fdb2ac4 324 #define CRITICAL_SECTION_EXIT() CRITICAL_REGION_EXIT()
<> 162:e13f6fdb2ac4 325
<> 162:e13f6fdb2ac4 326 #else
<> 162:e13f6fdb2ac4 327
<> 162:e13f6fdb2ac4 328 #define CRITICAL_SECTION_ENTER()
<> 162:e13f6fdb2ac4 329 #define CRITICAL_SECTION_EXIT()
<> 162:e13f6fdb2ac4 330
<> 162:e13f6fdb2ac4 331 #endif
<> 162:e13f6fdb2ac4 332
<> 162:e13f6fdb2ac4 333
<> 162:e13f6fdb2ac4 334
<> 162:e13f6fdb2ac4 335 #ifdef __cplusplus
<> 162:e13f6fdb2ac4 336 }
<> 162:e13f6fdb2ac4 337 #endif
<> 162:e13f6fdb2ac4 338
<> 162:e13f6fdb2ac4 339 #endif // FDS_INTERNAL_DEFS_H__