this hurts

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
boo

Who changed what in which revision?

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