The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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