Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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