ads1115 only

Fork of mbed by mbed official

Committer:
<>
Date:
Thu Oct 27 16:45:56 2016 +0100
Revision:
128:9bcdf88f62b0
Release 128 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

2966: Add kw24 support https://github.com/ARMmbed/mbed-os/pull/2966
3068: MultiTech mDot - clean up PeripheralPins.c and add new pin names https://github.com/ARMmbed/mbed-os/pull/3068
3089: Kinetis HAL: Remove clock initialization code from serial and ticker https://github.com/ARMmbed/mbed-os/pull/3089
2943: [NRF5] NVIC_SetVector functionality https://github.com/ARMmbed/mbed-os/pull/2943
2938: InterruptIn changes in NCS36510 HAL. https://github.com/ARMmbed/mbed-os/pull/2938
3108: Fix sleep function for NRF52. https://github.com/ARMmbed/mbed-os/pull/3108
3076: STM32F1: Correct timer master value reading https://github.com/ARMmbed/mbed-os/pull/3076
3085: Add LOWPOWERTIMER capability for NUCLEO_F303ZE https://github.com/ARMmbed/mbed-os/pull/3085
3046: [BEETLE] Update BLE stack on Beetle board https://github.com/ARMmbed/mbed-os/pull/3046
3122: [Silicon Labs] Update of Silicon Labs HAL https://github.com/ARMmbed/mbed-os/pull/3122
3022: OnSemi RAM usage fix https://github.com/ARMmbed/mbed-os/pull/3022
3121: STM32F3: Correct UART4 and UART5 defines when using DEVICE_SERIAL_ASYNCH https://github.com/ARMmbed/mbed-os/pull/3121
3142: Targets- NUMAKER_PFM_NUC47216 remove mbed 2 https://github.com/ARMmbed/mbed-os/pull/3142

Who changed what in which revision?

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