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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

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

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
156:ff21514d8981
mbed library. Release version 162

Who changed what in which revision?

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