Nordic stack and drivers for the mbed BLE API
Dependents: Sensen-classic-v8-IAQ_copy_4
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/libraries/fds/fds_types_internal.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | #ifndef FDS_TYPES_INTERNAL__ |
Vincent Coubard |
638:c90ae1400bf2 | 34 | #define FDS_TYPES_INTERNAL__ |
Vincent Coubard |
638:c90ae1400bf2 | 35 | |
Vincent Coubard |
638:c90ae1400bf2 | 36 | #include "fds.h" |
Vincent Coubard |
638:c90ae1400bf2 | 37 | #include <stdint.h> |
Vincent Coubard |
638:c90ae1400bf2 | 38 | #include <stdbool.h> |
Vincent Coubard |
638:c90ae1400bf2 | 39 | #include "nrf_soc.h" |
Vincent Coubard |
638:c90ae1400bf2 | 40 | |
Vincent Coubard |
638:c90ae1400bf2 | 41 | |
Vincent Coubard |
638:c90ae1400bf2 | 42 | #define COMMAND_EXECUTING (NRF_SUCCESS) |
Vincent Coubard |
638:c90ae1400bf2 | 43 | #define COMMAND_COMPLETED (0x1234) |
Vincent Coubard |
638:c90ae1400bf2 | 44 | //#define COMMAND_FAILED (0x1236) |
Vincent Coubard |
638:c90ae1400bf2 | 45 | |
Vincent Coubard |
638:c90ae1400bf2 | 46 | #define FDS_MAGIC_HWORD (0xF11E) |
Vincent Coubard |
638:c90ae1400bf2 | 47 | #define FDS_MAGIC_WORD (0x15ABE11A) |
Vincent Coubard |
638:c90ae1400bf2 | 48 | #define FDS_ERASED_WORD (0xFFFFFFFF) |
Vincent Coubard |
638:c90ae1400bf2 | 49 | |
Vincent Coubard |
638:c90ae1400bf2 | 50 | #define FDS_PAGE_TAG_SIZE (4) /**< Page tag size, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 51 | |
Vincent Coubard |
638:c90ae1400bf2 | 52 | #define FDS_VPAGE_ID_UNKNOWN (0xFFFF) |
Vincent Coubard |
638:c90ae1400bf2 | 53 | |
Vincent Coubard |
638:c90ae1400bf2 | 54 | #define FDS_WRITE_OFFSET_TL (0) /**< Offset of TL from the record base address, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | #define FDS_WRITE_OFFSET_IC (1) /**< Offset of IC from the record base address, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 56 | #define FDS_WRITE_OFFSET_ID (2) /**< Offset of ID from the record base address, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 57 | #define FDS_WRITE_OFFSET_DATA (3) /**< Offset of the data (chunks) from the record base address, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 58 | |
Vincent Coubard |
638:c90ae1400bf2 | 59 | #define FDS_HEADER_SIZE_TL (1) /**< Size of the TL part of the header, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 60 | #define FDS_HEADER_SIZE_ID (1) /**< Size of the IC part of the header, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 61 | #define FDS_HEADER_SIZE_IC (1) /**< Size of the IC part of the header, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 62 | #define FDS_HEADER_SIZE (3) /**< Size of the whole header, in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 63 | |
Vincent Coubard |
638:c90ae1400bf2 | 64 | #define FDS_CMD_QUEUE_SIZE_INIT (1) |
Vincent Coubard |
638:c90ae1400bf2 | 65 | #define FDS_CMD_QUEUE_SIZE_WRITE (1) |
Vincent Coubard |
638:c90ae1400bf2 | 66 | #define FDS_CMD_QUEUE_SIZE_CLEAR (1) |
Vincent Coubard |
638:c90ae1400bf2 | 67 | #define FDS_CMD_QUEUE_SIZE_UPDATE (2) |
Vincent Coubard |
638:c90ae1400bf2 | 68 | #define FDS_CMD_QUEUE_SIZE_GC (1) |
Vincent Coubard |
638:c90ae1400bf2 | 69 | |
Vincent Coubard |
638:c90ae1400bf2 | 70 | |
Vincent Coubard |
638:c90ae1400bf2 | 71 | static uint8_t m_nested_critical; |
Vincent Coubard |
638:c90ae1400bf2 | 72 | |
Vincent Coubard |
638:c90ae1400bf2 | 73 | /** Macros to enable and disable application interrupts. */ |
Vincent Coubard |
638:c90ae1400bf2 | 74 | #define CRITICAL_SECTION_ENTER() //sd_nvic_critical_region_enter(&m_nested_critical) |
Vincent Coubard |
638:c90ae1400bf2 | 75 | #define CRITICAL_SECTION_EXIT() //sd_nvic_critical_region_exit ( m_nested_critical) |
Vincent Coubard |
638:c90ae1400bf2 | 76 | |
Vincent Coubard |
638:c90ae1400bf2 | 77 | /**@brief Page types. */ |
Vincent Coubard |
638:c90ae1400bf2 | 78 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 79 | { |
Vincent Coubard |
638:c90ae1400bf2 | 80 | FDS_PAGE_UNDEFINED, /**< Undefined page type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 81 | FDS_PAGE_ERASED, /**< Page is erased. */ |
Vincent Coubard |
638:c90ae1400bf2 | 82 | FDS_PAGE_VALID, /**< Page is ready for storage. */ |
Vincent Coubard |
638:c90ae1400bf2 | 83 | FDS_PAGE_SWAP, /**< Page is reserved for GC. */ |
Vincent Coubard |
638:c90ae1400bf2 | 84 | FDS_PAGE_GC /**< Page is being garbage collected. */ |
Vincent Coubard |
638:c90ae1400bf2 | 85 | } fds_page_type_t; |
Vincent Coubard |
638:c90ae1400bf2 | 86 | |
Vincent Coubard |
638:c90ae1400bf2 | 87 | |
Vincent Coubard |
638:c90ae1400bf2 | 88 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 89 | { |
Vincent Coubard |
638:c90ae1400bf2 | 90 | FDS_OP_NONE = 0x00, /**< No operation. */ |
Vincent Coubard |
638:c90ae1400bf2 | 91 | FDS_OP_WRITE_TL, /**< Write the type and length. */ |
Vincent Coubard |
638:c90ae1400bf2 | 92 | FDS_OP_WRITE_ID, /**< Write the record ID. */ |
Vincent Coubard |
638:c90ae1400bf2 | 93 | FDS_OP_WRITE_CHUNK, /**< Write the record value. */ |
Vincent Coubard |
638:c90ae1400bf2 | 94 | FDS_OP_WRITE_IC, /**< Write the instance and checksum. */ |
Vincent Coubard |
638:c90ae1400bf2 | 95 | FDS_OP_CLEAR_TL, |
Vincent Coubard |
638:c90ae1400bf2 | 96 | FDS_OP_CLEAR_INSTANCE, |
Vincent Coubard |
638:c90ae1400bf2 | 97 | FDS_OP_DONE, |
Vincent Coubard |
638:c90ae1400bf2 | 98 | } fds_opcode_t; |
Vincent Coubard |
638:c90ae1400bf2 | 99 | |
Vincent Coubard |
638:c90ae1400bf2 | 100 | |
Vincent Coubard |
638:c90ae1400bf2 | 101 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 102 | { |
Vincent Coubard |
638:c90ae1400bf2 | 103 | FDS_FLAG_INITIALIZING = (1 << 0), /**< TODO: Not really needed atm? */ |
Vincent Coubard |
638:c90ae1400bf2 | 104 | FDS_FLAG_INITIALIZED = (1 << 1), /**< Flag indicating that flash data storage has been initialized. */ |
Vincent Coubard |
638:c90ae1400bf2 | 105 | FDS_FLAG_PROCESSING = (1 << 2), /**< Flag indicating that queue is being processed. */ |
Vincent Coubard |
638:c90ae1400bf2 | 106 | FDS_FLAG_CAN_GC = (1 << 3), /**< Flag indicating that fds can regain data by performing garbage collection. */ |
Vincent Coubard |
638:c90ae1400bf2 | 107 | } fds_flags_t; |
Vincent Coubard |
638:c90ae1400bf2 | 108 | |
Vincent Coubard |
638:c90ae1400bf2 | 109 | |
Vincent Coubard |
638:c90ae1400bf2 | 110 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 111 | { |
Vincent Coubard |
638:c90ae1400bf2 | 112 | uint32_t const * start_addr; |
Vincent Coubard |
638:c90ae1400bf2 | 113 | uint16_t vpage_id; /**< The page logical ID. */ |
Vincent Coubard |
638:c90ae1400bf2 | 114 | uint16_t volatile write_offset; /**< The page write offset, in 4 bytes words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 115 | uint16_t volatile words_reserved; /**< The amount of words reserved by fds_write_reserve() on this page. */ |
Vincent Coubard |
638:c90ae1400bf2 | 116 | uint16_t volatile records_open; |
Vincent Coubard |
638:c90ae1400bf2 | 117 | fds_page_type_t page_type : 4; /**< The page type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 118 | } fds_page_t; |
Vincent Coubard |
638:c90ae1400bf2 | 119 | |
Vincent Coubard |
638:c90ae1400bf2 | 120 | |
Vincent Coubard |
638:c90ae1400bf2 | 121 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 122 | { |
Vincent Coubard |
638:c90ae1400bf2 | 123 | fds_cmd_id_t id : 4; /**< The ID of the command. */ |
Vincent Coubard |
638:c90ae1400bf2 | 124 | fds_opcode_t op_code : 4; |
Vincent Coubard |
638:c90ae1400bf2 | 125 | uint8_t num_chunks; /**< Number of operations this command has left in the operation queue. */ |
Vincent Coubard |
638:c90ae1400bf2 | 126 | uint16_t chunk_offset; /**< Offset used for writing the record value(s), in 4 byte words. */ |
Vincent Coubard |
638:c90ae1400bf2 | 127 | uint16_t vpage_id; /**< The virtual page ID where we reserved the flash space for this command. */ |
Vincent Coubard |
638:c90ae1400bf2 | 128 | fds_record_header_t record_header; |
Vincent Coubard |
638:c90ae1400bf2 | 129 | } fds_cmd_t; |
Vincent Coubard |
638:c90ae1400bf2 | 130 | |
Vincent Coubard |
638:c90ae1400bf2 | 131 | |
Vincent Coubard |
638:c90ae1400bf2 | 132 | /**@brief Defines command queue, an element is free if the op_code field is not invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 133 | * |
Vincent Coubard |
638:c90ae1400bf2 | 134 | * @details Defines commands enqueued for flash access. At any point in time, this queue has one or |
Vincent Coubard |
638:c90ae1400bf2 | 135 | * more flash access operations pending if the count field is not zero. When the queue is |
Vincent Coubard |
638:c90ae1400bf2 | 136 | * not empty, the rp (read pointer) field points to the flash access command in progress |
Vincent Coubard |
638:c90ae1400bf2 | 137 | * or, if none is in progress, the command to be requested next. The queue implements a |
Vincent Coubard |
638:c90ae1400bf2 | 138 | * simple first in first out algorithm. Data addresses are assumed to be resident. |
Vincent Coubard |
638:c90ae1400bf2 | 139 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 140 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 141 | { |
Vincent Coubard |
638:c90ae1400bf2 | 142 | fds_cmd_t cmd[FDS_CMD_QUEUE_SIZE]; /**< Array to maintain flash access operation details. */ |
Vincent Coubard |
638:c90ae1400bf2 | 143 | uint8_t volatile rp; /**< The index of the command being executed. */ |
Vincent Coubard |
638:c90ae1400bf2 | 144 | uint8_t volatile count; /**< Number of elements in the queue. */ |
Vincent Coubard |
638:c90ae1400bf2 | 145 | } fds_cmd_queue_t; |
Vincent Coubard |
638:c90ae1400bf2 | 146 | |
Vincent Coubard |
638:c90ae1400bf2 | 147 | |
Vincent Coubard |
638:c90ae1400bf2 | 148 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 149 | { |
Vincent Coubard |
638:c90ae1400bf2 | 150 | fds_record_chunk_t chunk[FDS_CHUNK_QUEUE_SIZE]; |
Vincent Coubard |
638:c90ae1400bf2 | 151 | uint8_t volatile rp; |
Vincent Coubard |
638:c90ae1400bf2 | 152 | uint8_t volatile count; |
Vincent Coubard |
638:c90ae1400bf2 | 153 | } fds_chunk_queue_t; |
Vincent Coubard |
638:c90ae1400bf2 | 154 | |
Vincent Coubard |
638:c90ae1400bf2 | 155 | |
Vincent Coubard |
638:c90ae1400bf2 | 156 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 157 | { |
Vincent Coubard |
638:c90ae1400bf2 | 158 | NONE, |
Vincent Coubard |
638:c90ae1400bf2 | 159 | BEGIN, |
Vincent Coubard |
638:c90ae1400bf2 | 160 | RESUME, |
Vincent Coubard |
638:c90ae1400bf2 | 161 | GC_PAGE, |
Vincent Coubard |
638:c90ae1400bf2 | 162 | COPY_RECORD, |
Vincent Coubard |
638:c90ae1400bf2 | 163 | READY_SWAP, |
Vincent Coubard |
638:c90ae1400bf2 | 164 | NEW_SWAP, |
Vincent Coubard |
638:c90ae1400bf2 | 165 | INIT_SWAP |
Vincent Coubard |
638:c90ae1400bf2 | 166 | } fds_gc_state_t; |
Vincent Coubard |
638:c90ae1400bf2 | 167 | |
Vincent Coubard |
638:c90ae1400bf2 | 168 | |
Vincent Coubard |
638:c90ae1400bf2 | 169 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 170 | { |
Vincent Coubard |
638:c90ae1400bf2 | 171 | uint16_t cur_page; |
Vincent Coubard |
638:c90ae1400bf2 | 172 | uint16_t swap_page; |
Vincent Coubard |
638:c90ae1400bf2 | 173 | uint32_t const * p_scan_addr; |
Vincent Coubard |
638:c90ae1400bf2 | 174 | fds_gc_state_t state; |
Vincent Coubard |
638:c90ae1400bf2 | 175 | bool do_gc_page[FDS_MAX_PAGES]; |
Vincent Coubard |
638:c90ae1400bf2 | 176 | } fds_gc_data_t; |
Vincent Coubard |
638:c90ae1400bf2 | 177 | |
Vincent Coubard |
638:c90ae1400bf2 | 178 | #endif // FDS_TYPES_INTERNAL__ |