Daiki Kato / mbed-os-lychee

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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