test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ommpy 0:d383e2dee0f7 1
ommpy 0:d383e2dee0f7 2 /** \addtogroup hal */
ommpy 0:d383e2dee0f7 3 /** @{*/
ommpy 0:d383e2dee0f7 4 /*
ommpy 0:d383e2dee0f7 5 * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
ommpy 0:d383e2dee0f7 6 * SPDX-License-Identifier: Apache-2.0
ommpy 0:d383e2dee0f7 7 *
ommpy 0:d383e2dee0f7 8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
ommpy 0:d383e2dee0f7 9 * not use this file except in compliance with the License.
ommpy 0:d383e2dee0f7 10 * You may obtain a copy of the License at
ommpy 0:d383e2dee0f7 11 *
ommpy 0:d383e2dee0f7 12 * http://www.apache.org/licenses/LICENSE-2.0
ommpy 0:d383e2dee0f7 13 *
ommpy 0:d383e2dee0f7 14 * Unless required by applicable law or agreed to in writing, software
ommpy 0:d383e2dee0f7 15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
ommpy 0:d383e2dee0f7 16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ommpy 0:d383e2dee0f7 17 * See the License for the specific language governing permissions and
ommpy 0:d383e2dee0f7 18 * limitations under the License.
ommpy 0:d383e2dee0f7 19 */
ommpy 0:d383e2dee0f7 20
ommpy 0:d383e2dee0f7 21 #ifndef __DRIVER_STORAGE_H
ommpy 0:d383e2dee0f7 22 #define __DRIVER_STORAGE_H
ommpy 0:d383e2dee0f7 23
ommpy 0:d383e2dee0f7 24 #include <stdint.h>
ommpy 0:d383e2dee0f7 25
ommpy 0:d383e2dee0f7 26 /****** This file has been deprecated since mbed-os-5.5 *****/
ommpy 0:d383e2dee0f7 27
ommpy 0:d383e2dee0f7 28 #ifdef __cplusplus
ommpy 0:d383e2dee0f7 29 extern "C" {
ommpy 0:d383e2dee0f7 30 #endif // __cplusplus
ommpy 0:d383e2dee0f7 31
ommpy 0:d383e2dee0f7 32 #include "Driver_Common.h"
ommpy 0:d383e2dee0f7 33
ommpy 0:d383e2dee0f7 34 #define ARM_STORAGE_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) /* API version */
ommpy 0:d383e2dee0f7 35
ommpy 0:d383e2dee0f7 36
ommpy 0:d383e2dee0f7 37 #define _ARM_Driver_Storage_(n) Driver_Storage##n
ommpy 0:d383e2dee0f7 38 #define ARM_Driver_Storage_(n) _ARM_Driver_Storage_(n)
ommpy 0:d383e2dee0f7 39
ommpy 0:d383e2dee0f7 40 #define ARM_STORAGE_INVALID_OFFSET (0xFFFFFFFFFFFFFFFFULL) ///< Invalid address (relative to a storage controller's
ommpy 0:d383e2dee0f7 41 ///< address space). A storage block may never start at this address.
ommpy 0:d383e2dee0f7 42
ommpy 0:d383e2dee0f7 43 #define ARM_STORAGE_INVALID_ADDRESS (0xFFFFFFFFUL) ///< Invalid address within the processor's memory address space.
ommpy 0:d383e2dee0f7 44 ///< Refer to memory-mapped storage, i.e. < \ref ARM_DRIVER_STORAGE::ResolveAddress().
ommpy 0:d383e2dee0f7 45
ommpy 0:d383e2dee0f7 46 /****** Storage specific error codes *****/
ommpy 0:d383e2dee0f7 47 #define ARM_STORAGE_ERROR_NOT_ERASABLE (ARM_DRIVER_ERROR_SPECIFIC - 1) ///< Part (or all) of the range provided to Erase() isn't erasable.
ommpy 0:d383e2dee0f7 48 #define ARM_STORAGE_ERROR_NOT_PROGRAMMABLE (ARM_DRIVER_ERROR_SPECIFIC - 2) ///< Part (or all) of the range provided to ProgramData() isn't programmable.
ommpy 0:d383e2dee0f7 49 #define ARM_STORAGE_ERROR_PROTECTED (ARM_DRIVER_ERROR_SPECIFIC - 3) ///< Part (or all) of the range to Erase() or ProgramData() is protected.
ommpy 0:d383e2dee0f7 50 #define ARM_STORAGE_ERROR_RUNTIME_OR_INTEGRITY_FAILURE (ARM_DRIVER_ERROR_SPECIFIC - 4) ///< Runtime or sanity-check failure.
ommpy 0:d383e2dee0f7 51
ommpy 0:d383e2dee0f7 52 /**
ommpy 0:d383e2dee0f7 53 * \brief Attributes of the storage range within a storage block.
ommpy 0:d383e2dee0f7 54 */
ommpy 0:d383e2dee0f7 55 typedef struct _ARM_STORAGE_BLOCK_ATTRIBUTES {
ommpy 0:d383e2dee0f7 56 uint32_t erasable : 1; ///< Erasing blocks is permitted with a minimum granularity of 'erase_unit'.
ommpy 0:d383e2dee0f7 57 ///< @note: if 'erasable' is 0--i.e. the 'erase' operation isn't available--then
ommpy 0:d383e2dee0f7 58 ///< 'erase_unit' (see below) is immaterial and should be 0.
ommpy 0:d383e2dee0f7 59 uint32_t programmable : 1; ///< Writing to ranges is permitted with a minimum granularity of 'program_unit'.
ommpy 0:d383e2dee0f7 60 ///< Writes are typically achieved through the ProgramData operation (following an erase);
ommpy 0:d383e2dee0f7 61 ///< if storage isn't erasable (see 'erasable' above) but is memory-mapped
ommpy 0:d383e2dee0f7 62 ///< (i.e. 'memory_mapped'), it can be written directly using memory-store operations.
ommpy 0:d383e2dee0f7 63 uint32_t executable : 1; ///< This storage block can hold program data; the processor can fetch and execute code
ommpy 0:d383e2dee0f7 64 ///< sourced from it. Often this is accompanied with the device being 'memory_mapped' (see \ref ARM_STORAGE_INFO).
ommpy 0:d383e2dee0f7 65 uint32_t protectable : 1; ///< The entire block can be protected from program and erase operations. Once protection
ommpy 0:d383e2dee0f7 66 ///< is enabled for a block, its 'erasable' and 'programmable' bits are turned off.
ommpy 0:d383e2dee0f7 67 uint32_t reserved : 28;
ommpy 0:d383e2dee0f7 68 uint32_t erase_unit; ///< Minimum erase size in bytes.
ommpy 0:d383e2dee0f7 69 ///< The offset of the start of the erase-range should also be aligned with this value.
ommpy 0:d383e2dee0f7 70 ///< Applicable if the 'erasable' attribute is set for the block.
ommpy 0:d383e2dee0f7 71 ///< @note: if 'erasable' (see above) is 0--i.e. the 'erase' operation isn't available--then
ommpy 0:d383e2dee0f7 72 ///< 'erase_unit' is immaterial and should be 0.
ommpy 0:d383e2dee0f7 73 uint32_t protection_unit; ///< Minimum protectable size in bytes. Applicable if the 'protectable'
ommpy 0:d383e2dee0f7 74 ///< attribute is set for the block. This should be a divisor of the block's size. A
ommpy 0:d383e2dee0f7 75 ///< block can be considered to be made up of consecutive, individually-protectable fragments.
ommpy 0:d383e2dee0f7 76 } ARM_STORAGE_BLOCK_ATTRIBUTES;
ommpy 0:d383e2dee0f7 77
ommpy 0:d383e2dee0f7 78 /**
ommpy 0:d383e2dee0f7 79 * \brief A storage block is a range of memory with uniform attributes. Storage blocks
ommpy 0:d383e2dee0f7 80 * combine to make up the address map of a storage controller.
ommpy 0:d383e2dee0f7 81 */
ommpy 0:d383e2dee0f7 82 typedef struct _ARM_STORAGE_BLOCK {
ommpy 0:d383e2dee0f7 83 uint64_t addr; ///< This is the start address of the storage block. It is
ommpy 0:d383e2dee0f7 84 ///< expressed as an offset from the start of the storage map
ommpy 0:d383e2dee0f7 85 ///< maintained by the owning storage controller.
ommpy 0:d383e2dee0f7 86 uint64_t size; ///< This is the size of the storage block, in units of bytes.
ommpy 0:d383e2dee0f7 87 ///< Together with addr, it describes a range [addr, addr+size).
ommpy 0:d383e2dee0f7 88 ARM_STORAGE_BLOCK_ATTRIBUTES attributes; ///< Attributes for this block.
ommpy 0:d383e2dee0f7 89 } ARM_STORAGE_BLOCK;
ommpy 0:d383e2dee0f7 90
ommpy 0:d383e2dee0f7 91 /**
ommpy 0:d383e2dee0f7 92 * The check for a valid ARM_STORAGE_BLOCK.
ommpy 0:d383e2dee0f7 93 */
ommpy 0:d383e2dee0f7 94 #define ARM_STORAGE_VALID_BLOCK(BLK) (((BLK)->addr != ARM_STORAGE_INVALID_OFFSET) && ((BLK)->size != 0))
ommpy 0:d383e2dee0f7 95
ommpy 0:d383e2dee0f7 96 /**
ommpy 0:d383e2dee0f7 97 * \brief Values for encoding storage memory-types with respect to programmability.
ommpy 0:d383e2dee0f7 98 *
ommpy 0:d383e2dee0f7 99 * Please ensure that the maximum of the following memory types doesn't exceed 16; we
ommpy 0:d383e2dee0f7 100 * encode this in a 4-bit field within ARM_STORAGE_INFO::programmability.
ommpy 0:d383e2dee0f7 101 */
ommpy 0:d383e2dee0f7 102 #define ARM_STORAGE_PROGRAMMABILITY_RAM (0x0)
ommpy 0:d383e2dee0f7 103 #define ARM_STORAGE_PROGRAMMABILITY_ROM (0x1) ///< Read-only memory.
ommpy 0:d383e2dee0f7 104 #define ARM_STORAGE_PROGRAMMABILITY_WORM (0x2) ///< write-once-read-only-memory (WORM).
ommpy 0:d383e2dee0f7 105 #define ARM_STORAGE_PROGRAMMABILITY_ERASABLE (0x3) ///< re-programmable based on erase. Supports multiple writes.
ommpy 0:d383e2dee0f7 106
ommpy 0:d383e2dee0f7 107 /**
ommpy 0:d383e2dee0f7 108 * Values for encoding data-retention levels for storage blocks.
ommpy 0:d383e2dee0f7 109 *
ommpy 0:d383e2dee0f7 110 * Please ensure that the maximum of the following retention types doesn't exceed 16; we
ommpy 0:d383e2dee0f7 111 * encode this in a 4-bit field within ARM_STORAGE_INFO::retention_level.
ommpy 0:d383e2dee0f7 112 */
ommpy 0:d383e2dee0f7 113 #define ARM_RETENTION_WHILE_DEVICE_ACTIVE (0x0) ///< Data is retained only during device activity.
ommpy 0:d383e2dee0f7 114 #define ARM_RETENTION_ACROSS_SLEEP (0x1) ///< Data is retained across processor sleep.
ommpy 0:d383e2dee0f7 115 #define ARM_RETENTION_ACROSS_DEEP_SLEEP (0x2) ///< Data is retained across processor deep-sleep.
ommpy 0:d383e2dee0f7 116 #define ARM_RETENTION_BATTERY_BACKED (0x3) ///< Data is battery-backed. Device can be powered off.
ommpy 0:d383e2dee0f7 117 #define ARM_RETENTION_NVM (0x4) ///< Data is retained in non-volatile memory.
ommpy 0:d383e2dee0f7 118
ommpy 0:d383e2dee0f7 119 /**
ommpy 0:d383e2dee0f7 120 * Device Data Security Protection Features. Applicable mostly to EXTERNAL_NVM.
ommpy 0:d383e2dee0f7 121 */
ommpy 0:d383e2dee0f7 122 typedef struct _ARM_STORAGE_SECURITY_FEATURES {
ommpy 0:d383e2dee0f7 123 uint32_t acls : 1; ///< Protection against internal software attacks using ACLs.
ommpy 0:d383e2dee0f7 124 uint32_t rollback_protection : 1; ///< Roll-back protection. Set to true if the creator of the storage
ommpy 0:d383e2dee0f7 125 ///< can ensure that an external attacker can't force an
ommpy 0:d383e2dee0f7 126 ///< older firmware to run or to revert back to a previous state.
ommpy 0:d383e2dee0f7 127 uint32_t tamper_proof : 1; ///< Tamper-proof memory (will be deleted on tamper-attempts using board level or chip level sensors).
ommpy 0:d383e2dee0f7 128 uint32_t internal_flash : 1; ///< Internal flash.
ommpy 0:d383e2dee0f7 129 uint32_t reserved1 : 12;
ommpy 0:d383e2dee0f7 130
ommpy 0:d383e2dee0f7 131 /**
ommpy 0:d383e2dee0f7 132 * Encode support for hardening against various classes of attacks.
ommpy 0:d383e2dee0f7 133 */
ommpy 0:d383e2dee0f7 134 uint32_t software_attacks : 1; ///< device software (malware running on the device).
ommpy 0:d383e2dee0f7 135 uint32_t board_level_attacks : 1; ///< board level attacks (debug probes, copy protection fuses.)
ommpy 0:d383e2dee0f7 136 uint32_t chip_level_attacks : 1; ///< chip level attacks (tamper-protection).
ommpy 0:d383e2dee0f7 137 uint32_t side_channel_attacks : 1; ///< side channel attacks.
ommpy 0:d383e2dee0f7 138 uint32_t reserved2 : 12;
ommpy 0:d383e2dee0f7 139 } ARM_STORAGE_SECURITY_FEATURES;
ommpy 0:d383e2dee0f7 140
ommpy 0:d383e2dee0f7 141 #define ARM_STORAGE_PROGRAM_CYCLES_INFINITE (0UL) /**< Infinite or unknown endurance for reprogramming. */
ommpy 0:d383e2dee0f7 142
ommpy 0:d383e2dee0f7 143 /**
ommpy 0:d383e2dee0f7 144 * \brief Storage information. This contains device-metadata. It is the return
ommpy 0:d383e2dee0f7 145 * value from calling GetInfo() on the storage driver.
ommpy 0:d383e2dee0f7 146 *
ommpy 0:d383e2dee0f7 147 * \details These fields serve a different purpose than the ones contained in
ommpy 0:d383e2dee0f7 148 * \ref ARM_STORAGE_CAPABILITIES, which is another structure containing
ommpy 0:d383e2dee0f7 149 * device-level metadata. ARM_STORAGE_CAPABILITIES describes the API
ommpy 0:d383e2dee0f7 150 * capabilities, whereas ARM_STORAGE_INFO describes the device. Furthermore
ommpy 0:d383e2dee0f7 151 * ARM_STORAGE_CAPABILITIES fits within a single word, and is designed to be
ommpy 0:d383e2dee0f7 152 * passed around by value; ARM_STORAGE_INFO, on the other hand, contains
ommpy 0:d383e2dee0f7 153 * metadata which doesn't fit into a single word and requires the use of
ommpy 0:d383e2dee0f7 154 * pointers to be moved around.
ommpy 0:d383e2dee0f7 155 */
ommpy 0:d383e2dee0f7 156 typedef struct _ARM_STORAGE_INFO {
ommpy 0:d383e2dee0f7 157 uint64_t total_storage; ///< Total available storage, in bytes.
ommpy 0:d383e2dee0f7 158 uint32_t program_unit; ///< Minimum programming size in bytes.
ommpy 0:d383e2dee0f7 159 ///< The offset of the start of the program-range should also be aligned with this value.
ommpy 0:d383e2dee0f7 160 ///< Applicable only if the 'programmable' attribute is set for a block.
ommpy 0:d383e2dee0f7 161 ///< @note: setting program_unit to 0 has the effect of disabling the size and alignment
ommpy 0:d383e2dee0f7 162 ///< restrictions (setting it to 1 also has the same effect).
ommpy 0:d383e2dee0f7 163 uint32_t optimal_program_unit; ///< Optimal programming page-size in bytes. Some storage controllers
ommpy 0:d383e2dee0f7 164 ///< have internal buffers into which to receive data. Writing in chunks of
ommpy 0:d383e2dee0f7 165 ///< 'optimal_program_unit' would achieve maximum programming speed.
ommpy 0:d383e2dee0f7 166 ///< Applicable only if the 'programmable' attribute is set for the underlying block(s).
ommpy 0:d383e2dee0f7 167 uint32_t program_cycles; ///< A measure of endurance for reprogramming.
ommpy 0:d383e2dee0f7 168 ///< Use ARM_STORAGE_PROGRAM_CYCLES_INFINITE for infinite or unknown endurance.
ommpy 0:d383e2dee0f7 169 uint32_t erased_value : 1; ///< Contents of erased memory (usually 1 to indicate erased bytes with state 0xFF).
ommpy 0:d383e2dee0f7 170 uint32_t memory_mapped : 1; ///< This storage device has a mapping onto the processor's memory address space.
ommpy 0:d383e2dee0f7 171 ///< @note: For a memory-mapped block which isn't erasable but is programmable (i.e. if
ommpy 0:d383e2dee0f7 172 ///< 'erasable' is set to 0, but 'programmable' is 1), writes should be possible directly to
ommpy 0:d383e2dee0f7 173 ///< the memory-mapped storage without going through the ProgramData operation.
ommpy 0:d383e2dee0f7 174 uint32_t programmability : 4; ///< A value to indicate storage programmability.
ommpy 0:d383e2dee0f7 175 uint32_t retention_level : 4;
ommpy 0:d383e2dee0f7 176 uint32_t reserved : 22;
ommpy 0:d383e2dee0f7 177 ARM_STORAGE_SECURITY_FEATURES security; ///< \ref ARM_STORAGE_SECURITY_FEATURES
ommpy 0:d383e2dee0f7 178 } ARM_STORAGE_INFO;
ommpy 0:d383e2dee0f7 179
ommpy 0:d383e2dee0f7 180 /**
ommpy 0:d383e2dee0f7 181 \brief Operating status of the storage controller.
ommpy 0:d383e2dee0f7 182 */
ommpy 0:d383e2dee0f7 183 typedef struct _ARM_STORAGE_STATUS {
ommpy 0:d383e2dee0f7 184 uint32_t busy : 1; ///< Controller busy flag
ommpy 0:d383e2dee0f7 185 uint32_t error : 1; ///< Read/Program/Erase error flag (cleared on start of next operation)
ommpy 0:d383e2dee0f7 186 } ARM_STORAGE_STATUS;
ommpy 0:d383e2dee0f7 187
ommpy 0:d383e2dee0f7 188 /**
ommpy 0:d383e2dee0f7 189 * \brief Storage Driver API Capabilities.
ommpy 0:d383e2dee0f7 190 *
ommpy 0:d383e2dee0f7 191 * This data structure is designed to fit within a single word so that it can be
ommpy 0:d383e2dee0f7 192 * fetched cheaply using a call to driver->GetCapabilities().
ommpy 0:d383e2dee0f7 193 */
ommpy 0:d383e2dee0f7 194 typedef struct _ARM_STORAGE_CAPABILITIES {
ommpy 0:d383e2dee0f7 195 uint32_t asynchronous_ops : 1; ///< Used to indicate if APIs like initialize,
ommpy 0:d383e2dee0f7 196 ///< read, erase, program, etc. can operate in asynchronous mode.
ommpy 0:d383e2dee0f7 197 ///< Setting this bit to 1 means that the driver is capable
ommpy 0:d383e2dee0f7 198 ///< of launching asynchronous operations; command completion is
ommpy 0:d383e2dee0f7 199 ///< signaled by the invocation of a completion callback. If
ommpy 0:d383e2dee0f7 200 ///< set to 1, drivers may still complete asynchronous
ommpy 0:d383e2dee0f7 201 ///< operations synchronously as necessary--in which case they
ommpy 0:d383e2dee0f7 202 ///< return a positive error code to indicate synchronous completion.
ommpy 0:d383e2dee0f7 203 uint32_t erase_all : 1; ///< Supports EraseAll operation.
ommpy 0:d383e2dee0f7 204 uint32_t reserved : 30;
ommpy 0:d383e2dee0f7 205 } ARM_STORAGE_CAPABILITIES;
ommpy 0:d383e2dee0f7 206
ommpy 0:d383e2dee0f7 207 /**
ommpy 0:d383e2dee0f7 208 * Command opcodes for Storage. Completion callbacks use these codes to refer to
ommpy 0:d383e2dee0f7 209 * completing commands. Refer to \ref ARM_Storage_Callback_t.
ommpy 0:d383e2dee0f7 210 */
ommpy 0:d383e2dee0f7 211 typedef enum _ARM_STORAGE_OPERATION {
ommpy 0:d383e2dee0f7 212 ARM_STORAGE_OPERATION_GET_VERSION,
ommpy 0:d383e2dee0f7 213 ARM_STORAGE_OPERATION_GET_CAPABILITIES,
ommpy 0:d383e2dee0f7 214 ARM_STORAGE_OPERATION_INITIALIZE,
ommpy 0:d383e2dee0f7 215 ARM_STORAGE_OPERATION_UNINITIALIZE,
ommpy 0:d383e2dee0f7 216 ARM_STORAGE_OPERATION_POWER_CONTROL,
ommpy 0:d383e2dee0f7 217 ARM_STORAGE_OPERATION_READ_DATA,
ommpy 0:d383e2dee0f7 218 ARM_STORAGE_OPERATION_PROGRAM_DATA,
ommpy 0:d383e2dee0f7 219 ARM_STORAGE_OPERATION_ERASE,
ommpy 0:d383e2dee0f7 220 ARM_STORAGE_OPERATION_ERASE_ALL,
ommpy 0:d383e2dee0f7 221 ARM_STORAGE_OPERATION_GET_STATUS,
ommpy 0:d383e2dee0f7 222 ARM_STORAGE_OPERATION_GET_INFO,
ommpy 0:d383e2dee0f7 223 ARM_STORAGE_OPERATION_RESOLVE_ADDRESS,
ommpy 0:d383e2dee0f7 224 ARM_STORAGE_OPERATION_GET_NEXT_BLOCK,
ommpy 0:d383e2dee0f7 225 ARM_STORAGE_OPERATION_GET_BLOCK
ommpy 0:d383e2dee0f7 226 } ARM_STORAGE_OPERATION;
ommpy 0:d383e2dee0f7 227
ommpy 0:d383e2dee0f7 228 /**
ommpy 0:d383e2dee0f7 229 * Declaration of the callback-type for command completion.
ommpy 0:d383e2dee0f7 230 *
ommpy 0:d383e2dee0f7 231 * @param [in] status
ommpy 0:d383e2dee0f7 232 * A code to indicate the status of the completed operation. For data
ommpy 0:d383e2dee0f7 233 * transfer operations, the status field is overloaded in case of
ommpy 0:d383e2dee0f7 234 * success to return the count of items successfully transferred; this
ommpy 0:d383e2dee0f7 235 * can be done safely because error codes are negative values.
ommpy 0:d383e2dee0f7 236 *
ommpy 0:d383e2dee0f7 237 * @param [in] operation
ommpy 0:d383e2dee0f7 238 * The command op-code. This value isn't essential for the callback in
ommpy 0:d383e2dee0f7 239 * the presence of the command instance-id, but it is expected that
ommpy 0:d383e2dee0f7 240 * this information could be a quick and useful filter.
ommpy 0:d383e2dee0f7 241 */
ommpy 0:d383e2dee0f7 242 typedef void (*ARM_Storage_Callback_t)(int32_t status, ARM_STORAGE_OPERATION operation);
ommpy 0:d383e2dee0f7 243
ommpy 0:d383e2dee0f7 244 /**
ommpy 0:d383e2dee0f7 245 * This is the set of operations constituting the Storage driver. Their
ommpy 0:d383e2dee0f7 246 * implementation is platform-specific, and needs to be supplied by the
ommpy 0:d383e2dee0f7 247 * porting effort.
ommpy 0:d383e2dee0f7 248 *
ommpy 0:d383e2dee0f7 249 * Some APIs within `ARM_DRIVER_STORAGE` will always operate synchronously:
ommpy 0:d383e2dee0f7 250 * GetVersion, GetCapabilities, GetStatus, GetInfo, ResolveAddress,
ommpy 0:d383e2dee0f7 251 * GetNextBlock, and GetBlock. This means that control returns to the caller
ommpy 0:d383e2dee0f7 252 * with a relevant status code only after the completion of the operation (or
ommpy 0:d383e2dee0f7 253 * the discovery of a failure condition).
ommpy 0:d383e2dee0f7 254 *
ommpy 0:d383e2dee0f7 255 * The remainder of the APIs: Initialize, Uninitialize, PowerControl, ReadData,
ommpy 0:d383e2dee0f7 256 * ProgramData, Erase, EraseAll, can function asynchronously if the underlying
ommpy 0:d383e2dee0f7 257 * controller supports it--i.e. if ARM_STORAGE_CAPABILITIES::asynchronous_ops is
ommpy 0:d383e2dee0f7 258 * set. In the case of asynchronous operation, the invocation returns early
ommpy 0:d383e2dee0f7 259 * (with ARM_DRIVER_OK) and results in a completion callback later. If
ommpy 0:d383e2dee0f7 260 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is not set, then all such APIs
ommpy 0:d383e2dee0f7 261 * execute synchronously, and control returns to the caller with a status code
ommpy 0:d383e2dee0f7 262 * only after the completion of the operation (or the discovery of a failure
ommpy 0:d383e2dee0f7 263 * condition).
ommpy 0:d383e2dee0f7 264 *
ommpy 0:d383e2dee0f7 265 * If ARM_STORAGE_CAPABILITIES::asynchronous_ops is set, a storage driver may
ommpy 0:d383e2dee0f7 266 * still choose to execute asynchronous operations in a synchronous manner. If
ommpy 0:d383e2dee0f7 267 * so, the driver returns a positive value to indicate successful synchronous
ommpy 0:d383e2dee0f7 268 * completion (or an error code in case of failure) and no further invocation of
ommpy 0:d383e2dee0f7 269 * completion callback should be expected. The expected return value for
ommpy 0:d383e2dee0f7 270 * synchronous completion of such asynchronous operations varies depending on
ommpy 0:d383e2dee0f7 271 * the operation. For operations involving data access, it often equals the
ommpy 0:d383e2dee0f7 272 * amount of data transferred or affected. For non data-transfer operations,
ommpy 0:d383e2dee0f7 273 * such as EraseAll or Initialize, it is usually 1.
ommpy 0:d383e2dee0f7 274 *
ommpy 0:d383e2dee0f7 275 * Here's a code snippet to suggest how asynchronous APIs might be used by
ommpy 0:d383e2dee0f7 276 * callers to handle both synchronous and asynchronous execution by the
ommpy 0:d383e2dee0f7 277 * underlying storage driver:
ommpy 0:d383e2dee0f7 278 * \code
ommpy 0:d383e2dee0f7 279 * ASSERT(ARM_DRIVER_OK == 0); // this is a precondition; it doesn't need to be put in code
ommpy 0:d383e2dee0f7 280 * int32_t returnValue = drv->asynchronousAPI(...);
ommpy 0:d383e2dee0f7 281 * if (returnValue < ARM_DRIVER_OK) {
ommpy 0:d383e2dee0f7 282 * // handle error.
ommpy 0:d383e2dee0f7 283 * } else if (returnValue == ARM_DRIVER_OK) {
ommpy 0:d383e2dee0f7 284 * ASSERT(drv->GetCapabilities().asynchronous_ops == 1);
ommpy 0:d383e2dee0f7 285 * // handle early return from asynchronous execution; remainder of the work is done in the callback handler.
ommpy 0:d383e2dee0f7 286 * } else {
ommpy 0:d383e2dee0f7 287 * ASSERT(returnValue == EXPECTED_RETURN_VALUE_FOR_SYNCHRONOUS_COMPLETION);
ommpy 0:d383e2dee0f7 288 * // handle synchronous completion.
ommpy 0:d383e2dee0f7 289 * }
ommpy 0:d383e2dee0f7 290 * \endcode
ommpy 0:d383e2dee0f7 291 */
ommpy 0:d383e2dee0f7 292 typedef struct _ARM_DRIVER_STORAGE {
ommpy 0:d383e2dee0f7 293 /**
ommpy 0:d383e2dee0f7 294 * \brief Get driver version.
ommpy 0:d383e2dee0f7 295 *
ommpy 0:d383e2dee0f7 296 * The function GetVersion() returns version information of the driver implementation in ARM_DRIVER_VERSION.
ommpy 0:d383e2dee0f7 297 *
ommpy 0:d383e2dee0f7 298 * - API version is the version of the CMSIS-Driver specification used to implement this driver.
ommpy 0:d383e2dee0f7 299 * - Driver version is source code version of the actual driver implementation.
ommpy 0:d383e2dee0f7 300 *
ommpy 0:d383e2dee0f7 301 * Example:
ommpy 0:d383e2dee0f7 302 * \code
ommpy 0:d383e2dee0f7 303 * extern ARM_DRIVER_STORAGE *drv_info;
ommpy 0:d383e2dee0f7 304 *
ommpy 0:d383e2dee0f7 305 * void read_version (void) {
ommpy 0:d383e2dee0f7 306 * ARM_DRIVER_VERSION version;
ommpy 0:d383e2dee0f7 307 *
ommpy 0:d383e2dee0f7 308 * version = drv_info->GetVersion ();
ommpy 0:d383e2dee0f7 309 * if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
ommpy 0:d383e2dee0f7 310 * // error handling
ommpy 0:d383e2dee0f7 311 * return;
ommpy 0:d383e2dee0f7 312 * }
ommpy 0:d383e2dee0f7 313 * }
ommpy 0:d383e2dee0f7 314 * \endcode
ommpy 0:d383e2dee0f7 315 *
ommpy 0:d383e2dee0f7 316 * @return \ref ARM_DRIVER_VERSION.
ommpy 0:d383e2dee0f7 317 *
ommpy 0:d383e2dee0f7 318 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 319 * of a completion callback.
ommpy 0:d383e2dee0f7 320 *
ommpy 0:d383e2dee0f7 321 * @note The function GetVersion() can be called any time to obtain the
ommpy 0:d383e2dee0f7 322 * required information from the driver (even before initialization). It
ommpy 0:d383e2dee0f7 323 * always returns the same information.
ommpy 0:d383e2dee0f7 324 */
ommpy 0:d383e2dee0f7 325 ARM_DRIVER_VERSION (*GetVersion)(void);
ommpy 0:d383e2dee0f7 326
ommpy 0:d383e2dee0f7 327 /**
ommpy 0:d383e2dee0f7 328 * \brief Get driver capabilities.
ommpy 0:d383e2dee0f7 329 *
ommpy 0:d383e2dee0f7 330 * \details The function GetCapabilities() returns information about
ommpy 0:d383e2dee0f7 331 * capabilities in this driver implementation. The data fields of the struct
ommpy 0:d383e2dee0f7 332 * ARM_STORAGE_CAPABILITIES encode various capabilities, for example if the device
ommpy 0:d383e2dee0f7 333 * is able to execute operations asynchronously.
ommpy 0:d383e2dee0f7 334 *
ommpy 0:d383e2dee0f7 335 * Example:
ommpy 0:d383e2dee0f7 336 * \code
ommpy 0:d383e2dee0f7 337 * extern ARM_DRIVER_STORAGE *drv_info;
ommpy 0:d383e2dee0f7 338 *
ommpy 0:d383e2dee0f7 339 * void read_capabilities (void) {
ommpy 0:d383e2dee0f7 340 * ARM_STORAGE_CAPABILITIES drv_capabilities;
ommpy 0:d383e2dee0f7 341 *
ommpy 0:d383e2dee0f7 342 * drv_capabilities = drv_info->GetCapabilities ();
ommpy 0:d383e2dee0f7 343 * // interrogate capabilities
ommpy 0:d383e2dee0f7 344 *
ommpy 0:d383e2dee0f7 345 * }
ommpy 0:d383e2dee0f7 346 * \endcode
ommpy 0:d383e2dee0f7 347 *
ommpy 0:d383e2dee0f7 348 * @return \ref ARM_STORAGE_CAPABILITIES.
ommpy 0:d383e2dee0f7 349 *
ommpy 0:d383e2dee0f7 350 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 351 * of a completion callback.
ommpy 0:d383e2dee0f7 352 *
ommpy 0:d383e2dee0f7 353 * @note The function GetCapabilities() can be called any time to obtain the
ommpy 0:d383e2dee0f7 354 * required information from the driver (even before initialization). It
ommpy 0:d383e2dee0f7 355 * always returns the same information.
ommpy 0:d383e2dee0f7 356 */
ommpy 0:d383e2dee0f7 357 ARM_STORAGE_CAPABILITIES (*GetCapabilities)(void);
ommpy 0:d383e2dee0f7 358
ommpy 0:d383e2dee0f7 359 /**
ommpy 0:d383e2dee0f7 360 * \brief Initialize the Storage Interface.
ommpy 0:d383e2dee0f7 361 *
ommpy 0:d383e2dee0f7 362 * The function Initialize is called when the middleware component starts
ommpy 0:d383e2dee0f7 363 * operation. In addition to bringing the controller to a ready state,
ommpy 0:d383e2dee0f7 364 * Initialize() receives a callback handler to be invoked upon completion of
ommpy 0:d383e2dee0f7 365 * asynchronous operations.
ommpy 0:d383e2dee0f7 366 *
ommpy 0:d383e2dee0f7 367 * Initialize() needs to be called explicitly before
ommpy 0:d383e2dee0f7 368 * powering the peripheral using PowerControl(), and before initiating other
ommpy 0:d383e2dee0f7 369 * accesses to the storage controller.
ommpy 0:d383e2dee0f7 370 *
ommpy 0:d383e2dee0f7 371 * The function performs the following operations:
ommpy 0:d383e2dee0f7 372 * - Initializes the resources needed for the Storage interface.
ommpy 0:d383e2dee0f7 373 * - Registers the \ref ARM_Storage_Callback_t callback function.
ommpy 0:d383e2dee0f7 374 *
ommpy 0:d383e2dee0f7 375 * To start working with a peripheral the functions Initialize and PowerControl need to be called in this order:
ommpy 0:d383e2dee0f7 376 * drv->Initialize (...); // Allocate I/O pins
ommpy 0:d383e2dee0f7 377 * drv->PowerControl (ARM_POWER_FULL); // Power up peripheral, setup IRQ/DMA
ommpy 0:d383e2dee0f7 378 *
ommpy 0:d383e2dee0f7 379 * - Initialize() typically allocates the I/O resources (pins) for the
ommpy 0:d383e2dee0f7 380 * peripheral. The function can be called multiple times; if the I/O resources
ommpy 0:d383e2dee0f7 381 * are already initialized it performs no operation and just returns with
ommpy 0:d383e2dee0f7 382 * ARM_DRIVER_OK.
ommpy 0:d383e2dee0f7 383 *
ommpy 0:d383e2dee0f7 384 * - PowerControl (ARM_POWER_FULL) sets the peripheral registers including
ommpy 0:d383e2dee0f7 385 * interrupt (NVIC) and optionally DMA. The function can be called multiple
ommpy 0:d383e2dee0f7 386 * times; if the registers are already set it performs no operation and just
ommpy 0:d383e2dee0f7 387 * returns with ARM_DRIVER_OK.
ommpy 0:d383e2dee0f7 388 *
ommpy 0:d383e2dee0f7 389 * To stop working with a peripheral the functions PowerControl and Uninitialize need to be called in this order:
ommpy 0:d383e2dee0f7 390 * drv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
ommpy 0:d383e2dee0f7 391 * drv->Uninitialize (...); // Release I/O pins
ommpy 0:d383e2dee0f7 392 *
ommpy 0:d383e2dee0f7 393 * The functions PowerControl and Uninitialize always execute and can be used
ommpy 0:d383e2dee0f7 394 * to put the peripheral into a Safe State, for example after any data
ommpy 0:d383e2dee0f7 395 * transmission errors. To restart the peripheral in an error condition,
ommpy 0:d383e2dee0f7 396 * you should first execute the Stop Sequence and then the Start Sequence.
ommpy 0:d383e2dee0f7 397 *
ommpy 0:d383e2dee0f7 398 * @param [in] callback
ommpy 0:d383e2dee0f7 399 * Caller-defined callback to be invoked upon command completion
ommpy 0:d383e2dee0f7 400 * for asynchronous APIs (including the completion of
ommpy 0:d383e2dee0f7 401 * initialization). Use a NULL pointer when no callback
ommpy 0:d383e2dee0f7 402 * signals are required.
ommpy 0:d383e2dee0f7 403 *
ommpy 0:d383e2dee0f7 404 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 405 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 406 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 407 *
ommpy 0:d383e2dee0f7 408 * @return If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 409 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 410 * future with a status value of ARM_DRIVER_OK or an error-code. In the
ommpy 0:d383e2dee0f7 411 * case of synchronous execution, control returns after completion with a
ommpy 0:d383e2dee0f7 412 * value of 1. Return values less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 413 */
ommpy 0:d383e2dee0f7 414 int32_t (*Initialize)(ARM_Storage_Callback_t callback);
ommpy 0:d383e2dee0f7 415
ommpy 0:d383e2dee0f7 416 /**
ommpy 0:d383e2dee0f7 417 * \brief De-initialize the Storage Interface.
ommpy 0:d383e2dee0f7 418 *
ommpy 0:d383e2dee0f7 419 * The function Uninitialize() de-initializes the resources of Storage interface.
ommpy 0:d383e2dee0f7 420 *
ommpy 0:d383e2dee0f7 421 * It is called when the middleware component stops operation, and wishes to
ommpy 0:d383e2dee0f7 422 * release the software resources used by the interface.
ommpy 0:d383e2dee0f7 423 *
ommpy 0:d383e2dee0f7 424 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 425 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 426 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 427 *
ommpy 0:d383e2dee0f7 428 * @return If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 429 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 430 * future with a status value of ARM_DRIVER_OK or an error-code. In the
ommpy 0:d383e2dee0f7 431 * case of synchronous execution, control returns after completion with a
ommpy 0:d383e2dee0f7 432 * value of 1. Return values less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 433 */
ommpy 0:d383e2dee0f7 434 int32_t (*Uninitialize)(void);
ommpy 0:d383e2dee0f7 435
ommpy 0:d383e2dee0f7 436 /**
ommpy 0:d383e2dee0f7 437 * \brief Control the Storage interface power.
ommpy 0:d383e2dee0f7 438 *
ommpy 0:d383e2dee0f7 439 * The function \b ARM_Storage_PowerControl operates the power modes of the Storage interface.
ommpy 0:d383e2dee0f7 440 *
ommpy 0:d383e2dee0f7 441 * To start working with a peripheral the functions Initialize and PowerControl need to be called in this order:
ommpy 0:d383e2dee0f7 442 * drv->Initialize (...); // Allocate I/O pins
ommpy 0:d383e2dee0f7 443 * drv->PowerControl (ARM_POWER_FULL); // Power up peripheral, setup IRQ/DMA
ommpy 0:d383e2dee0f7 444 *
ommpy 0:d383e2dee0f7 445 * - Initialize() typically allocates the I/O resources (pins) for the
ommpy 0:d383e2dee0f7 446 * peripheral. The function can be called multiple times; if the I/O resources
ommpy 0:d383e2dee0f7 447 * are already initialized it performs no operation and just returns with
ommpy 0:d383e2dee0f7 448 * ARM_DRIVER_OK.
ommpy 0:d383e2dee0f7 449 *
ommpy 0:d383e2dee0f7 450 * - PowerControl (ARM_POWER_FULL) sets the peripheral registers including
ommpy 0:d383e2dee0f7 451 * interrupt (NVIC) and optionally DMA. The function can be called multiple
ommpy 0:d383e2dee0f7 452 * times; if the registers are already set it performs no operation and just
ommpy 0:d383e2dee0f7 453 * returns with ARM_DRIVER_OK.
ommpy 0:d383e2dee0f7 454 *
ommpy 0:d383e2dee0f7 455 * To stop working with a peripheral the functions PowerControl and Uninitialize need to be called in this order:
ommpy 0:d383e2dee0f7 456 *
ommpy 0:d383e2dee0f7 457 * drv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
ommpy 0:d383e2dee0f7 458 * drv->Uninitialize (...); // Release I/O pins
ommpy 0:d383e2dee0f7 459 *
ommpy 0:d383e2dee0f7 460 * The functions PowerControl and Uninitialize always execute and can be used
ommpy 0:d383e2dee0f7 461 * to put the peripheral into a Safe State, for example after any data
ommpy 0:d383e2dee0f7 462 * transmission errors. To restart the peripheral in an error condition,
ommpy 0:d383e2dee0f7 463 * you should first execute the Stop Sequence and then the Start Sequence.
ommpy 0:d383e2dee0f7 464 *
ommpy 0:d383e2dee0f7 465 * @param state
ommpy 0:d383e2dee0f7 466 * \ref ARM_POWER_STATE. The target power-state for the storage controller.
ommpy 0:d383e2dee0f7 467 * The parameter state can have the following values:
ommpy 0:d383e2dee0f7 468 * - ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts
ommpy 0:d383e2dee0f7 469 * (NVIC) and optionally DMA. Can be called multiple times. If the peripheral
ommpy 0:d383e2dee0f7 470 * is already in this mode, then the function performs no operation and returns
ommpy 0:d383e2dee0f7 471 * with ARM_DRIVER_OK.
ommpy 0:d383e2dee0f7 472 * - ARM_POWER_LOW : may use power saving. Returns ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
ommpy 0:d383e2dee0f7 473 * - ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
ommpy 0:d383e2dee0f7 474 *
ommpy 0:d383e2dee0f7 475 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 476 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 477 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 478 *
ommpy 0:d383e2dee0f7 479 * @return If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 480 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 481 * future with a status value of ARM_DRIVER_OK or an error-code. In the
ommpy 0:d383e2dee0f7 482 * case of synchronous execution, control returns after completion with a
ommpy 0:d383e2dee0f7 483 * value of 1. Return values less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 484 */
ommpy 0:d383e2dee0f7 485 int32_t (*PowerControl)(ARM_POWER_STATE state);
ommpy 0:d383e2dee0f7 486
ommpy 0:d383e2dee0f7 487 /**
ommpy 0:d383e2dee0f7 488 * \brief read the contents of a given address range from the storage device.
ommpy 0:d383e2dee0f7 489 *
ommpy 0:d383e2dee0f7 490 * \details Read the contents of a range of storage memory into a buffer
ommpy 0:d383e2dee0f7 491 * supplied by the caller. The buffer is owned by the caller and should
ommpy 0:d383e2dee0f7 492 * remain accessible for the lifetime of this command.
ommpy 0:d383e2dee0f7 493 *
ommpy 0:d383e2dee0f7 494 * @param [in] addr
ommpy 0:d383e2dee0f7 495 * This specifies the address from where to read data.
ommpy 0:d383e2dee0f7 496 *
ommpy 0:d383e2dee0f7 497 * @param [out] data
ommpy 0:d383e2dee0f7 498 * The destination of the read operation. The buffer
ommpy 0:d383e2dee0f7 499 * is owned by the caller and should remain accessible for the
ommpy 0:d383e2dee0f7 500 * lifetime of this command.
ommpy 0:d383e2dee0f7 501 *
ommpy 0:d383e2dee0f7 502 * @param [in] size
ommpy 0:d383e2dee0f7 503 * The number of bytes requested to read. The data buffer
ommpy 0:d383e2dee0f7 504 * should be at least as large as this size.
ommpy 0:d383e2dee0f7 505 *
ommpy 0:d383e2dee0f7 506 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 507 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 508 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 509 *
ommpy 0:d383e2dee0f7 510 * @return If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 511 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 512 * future with the number of successfully transferred bytes passed in as
ommpy 0:d383e2dee0f7 513 * the 'status' parameter. In the case of synchronous execution, control
ommpy 0:d383e2dee0f7 514 * returns after completion with a positive transfer-count. Return values
ommpy 0:d383e2dee0f7 515 * less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 516 */
ommpy 0:d383e2dee0f7 517 int32_t (*ReadData)(uint64_t addr, void *data, uint32_t size);
ommpy 0:d383e2dee0f7 518
ommpy 0:d383e2dee0f7 519 /**
ommpy 0:d383e2dee0f7 520 * \brief program (write into) the contents of a given address range of the storage device.
ommpy 0:d383e2dee0f7 521 *
ommpy 0:d383e2dee0f7 522 * \details Write the contents of a given memory buffer into a range of
ommpy 0:d383e2dee0f7 523 * storage memory. In the case of flash memory, the destination range in
ommpy 0:d383e2dee0f7 524 * storage memory typically has its contents in an erased state from a
ommpy 0:d383e2dee0f7 525 * preceding erase operation. The source memory buffer is owned by the
ommpy 0:d383e2dee0f7 526 * caller and should remain accessible for the lifetime of this command.
ommpy 0:d383e2dee0f7 527 *
ommpy 0:d383e2dee0f7 528 * @param [in] addr
ommpy 0:d383e2dee0f7 529 * This is the start address of the range to be written into. It
ommpy 0:d383e2dee0f7 530 * needs to be aligned to the device's \em program_unit
ommpy 0:d383e2dee0f7 531 * specified in \ref ARM_STORAGE_INFO.
ommpy 0:d383e2dee0f7 532 *
ommpy 0:d383e2dee0f7 533 * @param [in] data
ommpy 0:d383e2dee0f7 534 * The source of the write operation. The buffer is owned by the
ommpy 0:d383e2dee0f7 535 * caller and should remain accessible for the lifetime of this
ommpy 0:d383e2dee0f7 536 * command.
ommpy 0:d383e2dee0f7 537 *
ommpy 0:d383e2dee0f7 538 * @param [in] size
ommpy 0:d383e2dee0f7 539 * The number of bytes requested to be written. The buffer
ommpy 0:d383e2dee0f7 540 * should be at least as large as this size. \note 'size' should
ommpy 0:d383e2dee0f7 541 * be a multiple of the device's 'program_unit' (see \ref
ommpy 0:d383e2dee0f7 542 * ARM_STORAGE_INFO).
ommpy 0:d383e2dee0f7 543 *
ommpy 0:d383e2dee0f7 544 * @note It is best for the middleware to write in units of
ommpy 0:d383e2dee0f7 545 * 'optimal_program_unit' (\ref ARM_STORAGE_INFO) of the device.
ommpy 0:d383e2dee0f7 546 *
ommpy 0:d383e2dee0f7 547 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 548 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 549 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 550 *
ommpy 0:d383e2dee0f7 551 * @return If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 552 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 553 * future with the number of successfully transferred bytes passed in as
ommpy 0:d383e2dee0f7 554 * the 'status' parameter. In the case of synchronous execution, control
ommpy 0:d383e2dee0f7 555 * returns after completion with a positive transfer-count. Return values
ommpy 0:d383e2dee0f7 556 * less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 557 */
ommpy 0:d383e2dee0f7 558 int32_t (*ProgramData)(uint64_t addr, const void *data, uint32_t size);
ommpy 0:d383e2dee0f7 559
ommpy 0:d383e2dee0f7 560 /**
ommpy 0:d383e2dee0f7 561 * @brief Erase Storage range.
ommpy 0:d383e2dee0f7 562 *
ommpy 0:d383e2dee0f7 563 * @details This function erases a range of storage specified by [addr, addr +
ommpy 0:d383e2dee0f7 564 * size). Both 'addr' and 'addr + size' should align with the
ommpy 0:d383e2dee0f7 565 * 'erase_unit'(s) of the respective owning storage block(s) (see \ref
ommpy 0:d383e2dee0f7 566 * ARM_STORAGE_BLOCK and \ref ARM_STORAGE_BLOCK_ATTRIBUTES). The range to
ommpy 0:d383e2dee0f7 567 * be erased will have its contents returned to the un-programmed state--
ommpy 0:d383e2dee0f7 568 * i.e. to 'erased_value' (see \ref ARM_STORAGE_BLOCK_ATTRIBUTES), which
ommpy 0:d383e2dee0f7 569 * is usually 1 to indicate the pattern of all ones: 0xFF.
ommpy 0:d383e2dee0f7 570 *
ommpy 0:d383e2dee0f7 571 * @param [in] addr
ommpy 0:d383e2dee0f7 572 * This is the start-address of the range to be erased. It must
ommpy 0:d383e2dee0f7 573 * start at an 'erase_unit' boundary of the underlying block.
ommpy 0:d383e2dee0f7 574 *
ommpy 0:d383e2dee0f7 575 * @param [in] size
ommpy 0:d383e2dee0f7 576 * Size (in bytes) of the range to be erased. 'addr + size'
ommpy 0:d383e2dee0f7 577 * must be aligned with the 'erase_unit' of the underlying
ommpy 0:d383e2dee0f7 578 * block.
ommpy 0:d383e2dee0f7 579 *
ommpy 0:d383e2dee0f7 580 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 581 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 582 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 583 *
ommpy 0:d383e2dee0f7 584 * @return
ommpy 0:d383e2dee0f7 585 * If the range to be erased doesn't align with the erase_units of the
ommpy 0:d383e2dee0f7 586 * respective start and end blocks, ARM_DRIVER_ERROR_PARAMETER is returned.
ommpy 0:d383e2dee0f7 587 * If any part of the range is protected, ARM_STORAGE_ERROR_PROTECTED is
ommpy 0:d383e2dee0f7 588 * returned. If any part of the range is not erasable,
ommpy 0:d383e2dee0f7 589 * ARM_STORAGE_ERROR_NOT_ERASABLE is returned. All such sanity-check
ommpy 0:d383e2dee0f7 590 * failures result in the error code being returned synchronously and the
ommpy 0:d383e2dee0f7 591 * storage bytes within the range remain unaffected.
ommpy 0:d383e2dee0f7 592 * Otherwise the function executes in the following ways:
ommpy 0:d383e2dee0f7 593 * If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 594 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 595 * future with the number of successfully erased bytes passed in as
ommpy 0:d383e2dee0f7 596 * the 'status' parameter. In the case of synchronous execution, control
ommpy 0:d383e2dee0f7 597 * returns after completion with a positive erase-count. Return values
ommpy 0:d383e2dee0f7 598 * less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 599 *
ommpy 0:d383e2dee0f7 600 * @note Erase() may return a smaller (positive) value than the size of the
ommpy 0:d383e2dee0f7 601 * requested range. The returned value indicates the actual number of bytes
ommpy 0:d383e2dee0f7 602 * erased. It is the caller's responsibility to follow up with an appropriate
ommpy 0:d383e2dee0f7 603 * request to complete the operation.
ommpy 0:d383e2dee0f7 604 *
ommpy 0:d383e2dee0f7 605 * @note in the case of a failed erase (except when
ommpy 0:d383e2dee0f7 606 * ARM_DRIVER_ERROR_PARAMETER, ARM_STORAGE_ERROR_PROTECTED, or
ommpy 0:d383e2dee0f7 607 * ARM_STORAGE_ERROR_NOT_ERASABLE is returned synchronously), the
ommpy 0:d383e2dee0f7 608 * requested range should be assumed to be in an unknown state. The
ommpy 0:d383e2dee0f7 609 * previous contents may not be retained.
ommpy 0:d383e2dee0f7 610 */
ommpy 0:d383e2dee0f7 611 int32_t (*Erase)(uint64_t addr, uint32_t size);
ommpy 0:d383e2dee0f7 612
ommpy 0:d383e2dee0f7 613 /**
ommpy 0:d383e2dee0f7 614 * @brief Erase complete storage. Optional function for faster erase of the complete device.
ommpy 0:d383e2dee0f7 615 *
ommpy 0:d383e2dee0f7 616 * This optional function erases the complete device. If the device does not
ommpy 0:d383e2dee0f7 617 * support global erase then the function returns the error value \ref
ommpy 0:d383e2dee0f7 618 * ARM_DRIVER_ERROR_UNSUPPORTED. The data field \em 'erase_all' = 1
ommpy 0:d383e2dee0f7 619 * of the structure \ref ARM_STORAGE_CAPABILITIES encodes that
ommpy 0:d383e2dee0f7 620 * ARM_STORAGE_EraseAll is supported.
ommpy 0:d383e2dee0f7 621 *
ommpy 0:d383e2dee0f7 622 * @note This API may execute asynchronously if
ommpy 0:d383e2dee0f7 623 * ARM_STORAGE_CAPABILITIES::asynchronous_ops is set. Asynchronous
ommpy 0:d383e2dee0f7 624 * execution is optional even if 'asynchronous_ops' is set.
ommpy 0:d383e2dee0f7 625 *
ommpy 0:d383e2dee0f7 626 * @return
ommpy 0:d383e2dee0f7 627 * If any part of the storage range is protected,
ommpy 0:d383e2dee0f7 628 * ARM_STORAGE_ERROR_PROTECTED is returned. If any part of the storage
ommpy 0:d383e2dee0f7 629 * range is not erasable, ARM_STORAGE_ERROR_NOT_ERASABLE is returned. All
ommpy 0:d383e2dee0f7 630 * such sanity-check failures result in the error code being returned
ommpy 0:d383e2dee0f7 631 * synchronously and the storage bytes within the range remain unaffected.
ommpy 0:d383e2dee0f7 632 * Otherwise the function executes in the following ways:
ommpy 0:d383e2dee0f7 633 * If asynchronous activity is launched, an invocation returns
ommpy 0:d383e2dee0f7 634 * ARM_DRIVER_OK, and the caller can expect to receive a callback in the
ommpy 0:d383e2dee0f7 635 * future with ARM_DRIVER_OK passed in as the 'status' parameter. In the
ommpy 0:d383e2dee0f7 636 * case of synchronous execution, control returns after completion with a
ommpy 0:d383e2dee0f7 637 * value of 1. Return values less than ARM_DRIVER_OK (0) signify errors.
ommpy 0:d383e2dee0f7 638 */
ommpy 0:d383e2dee0f7 639 int32_t (*EraseAll)(void);
ommpy 0:d383e2dee0f7 640
ommpy 0:d383e2dee0f7 641 /**
ommpy 0:d383e2dee0f7 642 * @brief Get the status of the current (or previous) command executed by the
ommpy 0:d383e2dee0f7 643 * storage controller; stored in the structure \ref ARM_STORAGE_STATUS.
ommpy 0:d383e2dee0f7 644 *
ommpy 0:d383e2dee0f7 645 * @return
ommpy 0:d383e2dee0f7 646 * The status of the underlying controller.
ommpy 0:d383e2dee0f7 647 *
ommpy 0:d383e2dee0f7 648 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 649 * of a completion callback.
ommpy 0:d383e2dee0f7 650 */
ommpy 0:d383e2dee0f7 651 ARM_STORAGE_STATUS (*GetStatus)(void);
ommpy 0:d383e2dee0f7 652
ommpy 0:d383e2dee0f7 653 /**
ommpy 0:d383e2dee0f7 654 * @brief Get information about the Storage device; stored in the structure \ref ARM_STORAGE_INFO.
ommpy 0:d383e2dee0f7 655 *
ommpy 0:d383e2dee0f7 656 * @param [out] info
ommpy 0:d383e2dee0f7 657 * A caller-supplied buffer capable of being filled in with an
ommpy 0:d383e2dee0f7 658 * \ref ARM_STORAGE_INFO.
ommpy 0:d383e2dee0f7 659 *
ommpy 0:d383e2dee0f7 660 * @return ARM_DRIVER_OK if a ARM_STORAGE_INFO structure containing top level
ommpy 0:d383e2dee0f7 661 * metadata about the storage controller is filled into the supplied
ommpy 0:d383e2dee0f7 662 * buffer, else an appropriate error value.
ommpy 0:d383e2dee0f7 663 *
ommpy 0:d383e2dee0f7 664 * @note It is the caller's responsibility to ensure that the buffer passed in
ommpy 0:d383e2dee0f7 665 * is able to be initialized with a \ref ARM_STORAGE_INFO.
ommpy 0:d383e2dee0f7 666 *
ommpy 0:d383e2dee0f7 667 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 668 * of a completion callback.
ommpy 0:d383e2dee0f7 669 */
ommpy 0:d383e2dee0f7 670 int32_t (*GetInfo)(ARM_STORAGE_INFO *info);
ommpy 0:d383e2dee0f7 671
ommpy 0:d383e2dee0f7 672 /**
ommpy 0:d383e2dee0f7 673 * \brief For memory-mapped storage, resolve an address relative to
ommpy 0:d383e2dee0f7 674 * the storage controller into a memory address.
ommpy 0:d383e2dee0f7 675 *
ommpy 0:d383e2dee0f7 676 * @param addr
ommpy 0:d383e2dee0f7 677 * This is the address for which we want a resolution to the
ommpy 0:d383e2dee0f7 678 * processor's physical address space. It is an offset from the
ommpy 0:d383e2dee0f7 679 * start of the storage map maintained by the owning storage
ommpy 0:d383e2dee0f7 680 * controller.
ommpy 0:d383e2dee0f7 681 *
ommpy 0:d383e2dee0f7 682 * @return
ommpy 0:d383e2dee0f7 683 * The resolved address in the processor's address space; else
ommpy 0:d383e2dee0f7 684 * ARM_STORAGE_INVALID_ADDRESS, if no resolution is possible.
ommpy 0:d383e2dee0f7 685 *
ommpy 0:d383e2dee0f7 686 * @note This API returns synchronously. The invocation should return quickly,
ommpy 0:d383e2dee0f7 687 * and result in a resolved address.
ommpy 0:d383e2dee0f7 688 */
ommpy 0:d383e2dee0f7 689 uint32_t (*ResolveAddress)(uint64_t addr);
ommpy 0:d383e2dee0f7 690
ommpy 0:d383e2dee0f7 691 /**
ommpy 0:d383e2dee0f7 692 * @brief Advance to the successor of the current block (iterator), or fetch
ommpy 0:d383e2dee0f7 693 * the first block (if 'prev_block' is passed in as NULL).
ommpy 0:d383e2dee0f7 694 *
ommpy 0:d383e2dee0f7 695 * @details This helper function fetches (an iterator to) the next block (or
ommpy 0:d383e2dee0f7 696 * the first block if 'prev_block' is passed in as NULL). In the failure
ommpy 0:d383e2dee0f7 697 * case, a terminating, invalid block iterator is filled into the out
ommpy 0:d383e2dee0f7 698 * parameter: 'next_block'. In combination with \ref
ommpy 0:d383e2dee0f7 699 * ARM_STORAGE_VALID_BLOCK(), it can be used to iterate over the sequence
ommpy 0:d383e2dee0f7 700 * of blocks within the storage map:
ommpy 0:d383e2dee0f7 701 *
ommpy 0:d383e2dee0f7 702 * \code
ommpy 0:d383e2dee0f7 703 * ARM_STORAGE_BLOCK block;
ommpy 0:d383e2dee0f7 704 * for (drv->GetNextBlock(NULL, &block); ARM_STORAGE_VALID_BLOCK(&block); drv->GetNextBlock(&block, &block)) {
ommpy 0:d383e2dee0f7 705 * // make use of block
ommpy 0:d383e2dee0f7 706 * }
ommpy 0:d383e2dee0f7 707 * \endcode
ommpy 0:d383e2dee0f7 708 *
ommpy 0:d383e2dee0f7 709 * @param[in] prev_block
ommpy 0:d383e2dee0f7 710 * An existing block (iterator) within the same storage
ommpy 0:d383e2dee0f7 711 * controller. The memory buffer holding this block is owned
ommpy 0:d383e2dee0f7 712 * by the caller. This pointer may be NULL; if so, the
ommpy 0:d383e2dee0f7 713 * invocation fills in the first block into the out parameter:
ommpy 0:d383e2dee0f7 714 * 'next_block'.
ommpy 0:d383e2dee0f7 715 *
ommpy 0:d383e2dee0f7 716 * @param[out] next_block
ommpy 0:d383e2dee0f7 717 * A caller-owned buffer large enough to be filled in with
ommpy 0:d383e2dee0f7 718 * the following ARM_STORAGE_BLOCK. It is legal to provide the
ommpy 0:d383e2dee0f7 719 * same buffer using 'next_block' as was passed in with 'prev_block'. It
ommpy 0:d383e2dee0f7 720 * is also legal to pass a NULL into this parameter if the
ommpy 0:d383e2dee0f7 721 * caller isn't interested in populating a buffer with the next
ommpy 0:d383e2dee0f7 722 * block--i.e. if the caller only wishes to establish the
ommpy 0:d383e2dee0f7 723 * presence of a next block.
ommpy 0:d383e2dee0f7 724 *
ommpy 0:d383e2dee0f7 725 * @return ARM_DRIVER_OK if a valid next block is found (or first block, if
ommpy 0:d383e2dee0f7 726 * prev_block is passed as NULL); upon successful operation, the contents
ommpy 0:d383e2dee0f7 727 * of the next (or first) block are filled into the buffer pointed to by
ommpy 0:d383e2dee0f7 728 * the parameter 'next_block' and ARM_STORAGE_VALID_BLOCK(next_block) is
ommpy 0:d383e2dee0f7 729 * guaranteed to be true. Upon reaching the end of the sequence of blocks
ommpy 0:d383e2dee0f7 730 * (iterators), or in case the driver is unable to fetch information about
ommpy 0:d383e2dee0f7 731 * the next (or first) block, an error (negative) value is returned and an
ommpy 0:d383e2dee0f7 732 * invalid StorageBlock is populated into the supplied buffer. If
ommpy 0:d383e2dee0f7 733 * prev_block is NULL, the first block is returned.
ommpy 0:d383e2dee0f7 734 *
ommpy 0:d383e2dee0f7 735 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 736 * of a completion callback.
ommpy 0:d383e2dee0f7 737 */
ommpy 0:d383e2dee0f7 738 int32_t (*GetNextBlock)(const ARM_STORAGE_BLOCK* prev_block, ARM_STORAGE_BLOCK *next_block);
ommpy 0:d383e2dee0f7 739
ommpy 0:d383e2dee0f7 740 /**
ommpy 0:d383e2dee0f7 741 * @brief Find the storage block (iterator) encompassing a given storage address.
ommpy 0:d383e2dee0f7 742 *
ommpy 0:d383e2dee0f7 743 * @param[in] addr
ommpy 0:d383e2dee0f7 744 * Storage address in bytes.
ommpy 0:d383e2dee0f7 745 *
ommpy 0:d383e2dee0f7 746 * @param[out] block
ommpy 0:d383e2dee0f7 747 * A caller-owned buffer large enough to be filled in with the
ommpy 0:d383e2dee0f7 748 * ARM_STORAGE_BLOCK encapsulating the given address. This value
ommpy 0:d383e2dee0f7 749 * can also be passed in as NULL if the caller isn't interested
ommpy 0:d383e2dee0f7 750 * in populating a buffer with the block--if the caller only
ommpy 0:d383e2dee0f7 751 * wishes to establish the presence of a containing storage
ommpy 0:d383e2dee0f7 752 * block.
ommpy 0:d383e2dee0f7 753 *
ommpy 0:d383e2dee0f7 754 * @return ARM_DRIVER_OK if a containing storage-block is found. In this case,
ommpy 0:d383e2dee0f7 755 * if block is non-NULL, the buffer pointed to by it is populated with
ommpy 0:d383e2dee0f7 756 * the contents of the storage block--i.e. if block is valid and a block is
ommpy 0:d383e2dee0f7 757 * found, ARM_STORAGE_VALID_BLOCK(block) would return true following this
ommpy 0:d383e2dee0f7 758 * call. If there is no storage block containing the given offset, or in
ommpy 0:d383e2dee0f7 759 * case the driver is unable to resolve an address to a storage-block, an
ommpy 0:d383e2dee0f7 760 * error (negative) value is returned and an invalid StorageBlock is
ommpy 0:d383e2dee0f7 761 * populated into the supplied buffer.
ommpy 0:d383e2dee0f7 762 *
ommpy 0:d383e2dee0f7 763 * @note This API returns synchronously--it does not result in an invocation
ommpy 0:d383e2dee0f7 764 * of a completion callback.
ommpy 0:d383e2dee0f7 765 */
ommpy 0:d383e2dee0f7 766 int32_t (*GetBlock)(uint64_t addr, ARM_STORAGE_BLOCK *block);
ommpy 0:d383e2dee0f7 767 } const ARM_DRIVER_STORAGE;
ommpy 0:d383e2dee0f7 768
ommpy 0:d383e2dee0f7 769 #ifdef __cplusplus
ommpy 0:d383e2dee0f7 770 }
ommpy 0:d383e2dee0f7 771 #endif // __cplusplus
ommpy 0:d383e2dee0f7 772
ommpy 0:d383e2dee0f7 773 #endif /* __DRIVER_STORAGE_H */
ommpy 0:d383e2dee0f7 774
ommpy 0:d383e2dee0f7 775 /** @}*/