SDHI_driver patch (mbedOS 5.11.5)
mbed-os-program/mbed-os/features/storage/system_storage/SystemStorage.cpp@0:e1f465d87307, 2019-03-18 (annotated)
- Committer:
- tvendov
- Date:
- Mon Mar 18 16:54:40 2019 +0000
- Revision:
- 0:e1f465d87307
Initial_II
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tvendov | 0:e1f465d87307 | 1 | /* |
| tvendov | 0:e1f465d87307 | 2 | * Copyright (c) 2018 ARM Limited. All rights reserved. |
| tvendov | 0:e1f465d87307 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| tvendov | 0:e1f465d87307 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| tvendov | 0:e1f465d87307 | 5 | * not use this file except in compliance with the License. |
| tvendov | 0:e1f465d87307 | 6 | * You may obtain a copy of the License at |
| tvendov | 0:e1f465d87307 | 7 | * |
| tvendov | 0:e1f465d87307 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| tvendov | 0:e1f465d87307 | 9 | * |
| tvendov | 0:e1f465d87307 | 10 | * Unless required by applicable law or agreed to in writing, software |
| tvendov | 0:e1f465d87307 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| tvendov | 0:e1f465d87307 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| tvendov | 0:e1f465d87307 | 13 | * See the License for the specific language governing permissions and |
| tvendov | 0:e1f465d87307 | 14 | * limitations under the License. |
| tvendov | 0:e1f465d87307 | 15 | */ |
| tvendov | 0:e1f465d87307 | 16 | #include "SystemStorage.h" |
| tvendov | 0:e1f465d87307 | 17 | #include "BlockDevice.h" |
| tvendov | 0:e1f465d87307 | 18 | #include "FileSystem.h" |
| tvendov | 0:e1f465d87307 | 19 | #include "FATFileSystem.h" |
| tvendov | 0:e1f465d87307 | 20 | #include "LittleFileSystem.h" |
| tvendov | 0:e1f465d87307 | 21 | #include "mbed_error.h" |
| tvendov | 0:e1f465d87307 | 22 | |
| tvendov | 0:e1f465d87307 | 23 | |
| tvendov | 0:e1f465d87307 | 24 | #if COMPONENT_SPIF |
| tvendov | 0:e1f465d87307 | 25 | #include "SPIFBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 26 | #endif |
| tvendov | 0:e1f465d87307 | 27 | |
| tvendov | 0:e1f465d87307 | 28 | #if COMPONENT_QSPIF |
| tvendov | 0:e1f465d87307 | 29 | #include "QSPIFBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 30 | #endif |
| tvendov | 0:e1f465d87307 | 31 | |
| tvendov | 0:e1f465d87307 | 32 | #if COMPONENT_DATAFLASH |
| tvendov | 0:e1f465d87307 | 33 | #include "DataFlashBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 34 | #endif |
| tvendov | 0:e1f465d87307 | 35 | |
| tvendov | 0:e1f465d87307 | 36 | #if COMPONENT_SD |
| tvendov | 0:e1f465d87307 | 37 | #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) |
| tvendov | 0:e1f465d87307 | 38 | #include "SDHIBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 39 | #else |
| tvendov | 0:e1f465d87307 | 40 | #include "SDBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 41 | #endif |
| tvendov | 0:e1f465d87307 | 42 | #endif |
| tvendov | 0:e1f465d87307 | 43 | |
| tvendov | 0:e1f465d87307 | 44 | #if COMPONENT_FLASHIAP |
| tvendov | 0:e1f465d87307 | 45 | #include "FlashIAPBlockDevice.h" |
| tvendov | 0:e1f465d87307 | 46 | #endif |
| tvendov | 0:e1f465d87307 | 47 | |
| tvendov | 0:e1f465d87307 | 48 | using namespace mbed; |
| tvendov | 0:e1f465d87307 | 49 | |
| tvendov | 0:e1f465d87307 | 50 | |
| tvendov | 0:e1f465d87307 | 51 | |
| tvendov | 0:e1f465d87307 | 52 | MBED_WEAK int avoid_conflict_nvstore_tdbstore(owner_type_e in_mem_owner) |
| tvendov | 0:e1f465d87307 | 53 | { |
| tvendov | 0:e1f465d87307 | 54 | int status = MBED_SUCCESS; |
| tvendov | 0:e1f465d87307 | 55 | static PlatformMutex _mutex; |
| tvendov | 0:e1f465d87307 | 56 | static owner_type_e internal_memory_owner = NONE; |
| tvendov | 0:e1f465d87307 | 57 | |
| tvendov | 0:e1f465d87307 | 58 | _mutex.lock(); |
| tvendov | 0:e1f465d87307 | 59 | |
| tvendov | 0:e1f465d87307 | 60 | if (internal_memory_owner != NONE && |
| tvendov | 0:e1f465d87307 | 61 | internal_memory_owner != in_mem_owner) { |
| tvendov | 0:e1f465d87307 | 62 | |
| tvendov | 0:e1f465d87307 | 63 | status = MBED_ERROR_ALREADY_INITIALIZED; |
| tvendov | 0:e1f465d87307 | 64 | |
| tvendov | 0:e1f465d87307 | 65 | } else { |
| tvendov | 0:e1f465d87307 | 66 | |
| tvendov | 0:e1f465d87307 | 67 | internal_memory_owner = in_mem_owner; |
| tvendov | 0:e1f465d87307 | 68 | } |
| tvendov | 0:e1f465d87307 | 69 | |
| tvendov | 0:e1f465d87307 | 70 | _mutex.unlock(); |
| tvendov | 0:e1f465d87307 | 71 | |
| tvendov | 0:e1f465d87307 | 72 | return status; |
| tvendov | 0:e1f465d87307 | 73 | } |
| tvendov | 0:e1f465d87307 | 74 | |
| tvendov | 0:e1f465d87307 | 75 | // Align a value to a specified size. |
| tvendov | 0:e1f465d87307 | 76 | // Parameters : |
| tvendov | 0:e1f465d87307 | 77 | // val - [IN] Value. |
| tvendov | 0:e1f465d87307 | 78 | // size - [IN] Size. |
| tvendov | 0:e1f465d87307 | 79 | // Return : Aligned value. |
| tvendov | 0:e1f465d87307 | 80 | static inline uint32_t align_up(uint32_t val, uint32_t size) |
| tvendov | 0:e1f465d87307 | 81 | { |
| tvendov | 0:e1f465d87307 | 82 | return (((val - 1) / size) + 1) * size; |
| tvendov | 0:e1f465d87307 | 83 | } |
| tvendov | 0:e1f465d87307 | 84 | |
| tvendov | 0:e1f465d87307 | 85 | MBED_WEAK BlockDevice *BlockDevice::get_default_instance() |
| tvendov | 0:e1f465d87307 | 86 | { |
| tvendov | 0:e1f465d87307 | 87 | #if COMPONENT_SPIF |
| tvendov | 0:e1f465d87307 | 88 | |
| tvendov | 0:e1f465d87307 | 89 | static SPIFBlockDevice default_bd( |
| tvendov | 0:e1f465d87307 | 90 | MBED_CONF_SPIF_DRIVER_SPI_MOSI, |
| tvendov | 0:e1f465d87307 | 91 | MBED_CONF_SPIF_DRIVER_SPI_MISO, |
| tvendov | 0:e1f465d87307 | 92 | MBED_CONF_SPIF_DRIVER_SPI_CLK, |
| tvendov | 0:e1f465d87307 | 93 | MBED_CONF_SPIF_DRIVER_SPI_CS, |
| tvendov | 0:e1f465d87307 | 94 | MBED_CONF_SPIF_DRIVER_SPI_FREQ |
| tvendov | 0:e1f465d87307 | 95 | ); |
| tvendov | 0:e1f465d87307 | 96 | |
| tvendov | 0:e1f465d87307 | 97 | return &default_bd; |
| tvendov | 0:e1f465d87307 | 98 | |
| tvendov | 0:e1f465d87307 | 99 | #elif COMPONENT_QSPIF |
| tvendov | 0:e1f465d87307 | 100 | |
| tvendov | 0:e1f465d87307 | 101 | static QSPIFBlockDevice default_bd( |
| tvendov | 0:e1f465d87307 | 102 | MBED_CONF_QSPIF_QSPI_IO0, |
| tvendov | 0:e1f465d87307 | 103 | MBED_CONF_QSPIF_QSPI_IO1, |
| tvendov | 0:e1f465d87307 | 104 | MBED_CONF_QSPIF_QSPI_IO2, |
| tvendov | 0:e1f465d87307 | 105 | MBED_CONF_QSPIF_QSPI_IO3, |
| tvendov | 0:e1f465d87307 | 106 | MBED_CONF_QSPIF_QSPI_SCK, |
| tvendov | 0:e1f465d87307 | 107 | MBED_CONF_QSPIF_QSPI_CSN, |
| tvendov | 0:e1f465d87307 | 108 | MBED_CONF_QSPIF_QSPI_POLARITY_MODE, |
| tvendov | 0:e1f465d87307 | 109 | MBED_CONF_QSPIF_QSPI_FREQ |
| tvendov | 0:e1f465d87307 | 110 | ); |
| tvendov | 0:e1f465d87307 | 111 | |
| tvendov | 0:e1f465d87307 | 112 | return &default_bd; |
| tvendov | 0:e1f465d87307 | 113 | |
| tvendov | 0:e1f465d87307 | 114 | #elif COMPONENT_DATAFLASH |
| tvendov | 0:e1f465d87307 | 115 | |
| tvendov | 0:e1f465d87307 | 116 | static DataFlashBlockDevice default_bd( |
| tvendov | 0:e1f465d87307 | 117 | MBED_CONF_DATAFLASH_SPI_MOSI, |
| tvendov | 0:e1f465d87307 | 118 | MBED_CONF_DATAFLASH_SPI_MISO, |
| tvendov | 0:e1f465d87307 | 119 | MBED_CONF_DATAFLASH_SPI_CLK, |
| tvendov | 0:e1f465d87307 | 120 | MBED_CONF_DATAFLASH_SPI_CS |
| tvendov | 0:e1f465d87307 | 121 | ); |
| tvendov | 0:e1f465d87307 | 122 | |
| tvendov | 0:e1f465d87307 | 123 | return &default_bd; |
| tvendov | 0:e1f465d87307 | 124 | |
| tvendov | 0:e1f465d87307 | 125 | #elif COMPONENT_SD |
| tvendov | 0:e1f465d87307 | 126 | |
| tvendov | 0:e1f465d87307 | 127 | #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) |
| tvendov | 0:e1f465d87307 | 128 | static SDHIBlockDevice default_bd( |
| tvendov | 0:e1f465d87307 | 129 | MBED_CONF_SD_SDHI_CH |
| tvendov | 0:e1f465d87307 | 130 | ); |
| tvendov | 0:e1f465d87307 | 131 | #else |
| tvendov | 0:e1f465d87307 | 132 | static SDBlockDevice default_bd( |
| tvendov | 0:e1f465d87307 | 133 | MBED_CONF_SD_SPI_MOSI, |
| tvendov | 0:e1f465d87307 | 134 | MBED_CONF_SD_SPI_MISO, |
| tvendov | 0:e1f465d87307 | 135 | MBED_CONF_SD_SPI_CLK, |
| tvendov | 0:e1f465d87307 | 136 | MBED_CONF_SD_SPI_CS |
| tvendov | 0:e1f465d87307 | 137 | ); |
| tvendov | 0:e1f465d87307 | 138 | #endif |
| tvendov | 0:e1f465d87307 | 139 | |
| tvendov | 0:e1f465d87307 | 140 | return &default_bd; |
| tvendov | 0:e1f465d87307 | 141 | |
| tvendov | 0:e1f465d87307 | 142 | #elif COMPONENT_FLASHIAP |
| tvendov | 0:e1f465d87307 | 143 | |
| tvendov | 0:e1f465d87307 | 144 | #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) |
| tvendov | 0:e1f465d87307 | 145 | |
| tvendov | 0:e1f465d87307 | 146 | size_t flash_size; |
| tvendov | 0:e1f465d87307 | 147 | uint32_t start_address; |
| tvendov | 0:e1f465d87307 | 148 | uint32_t bottom_address; |
| tvendov | 0:e1f465d87307 | 149 | FlashIAP flash; |
| tvendov | 0:e1f465d87307 | 150 | |
| tvendov | 0:e1f465d87307 | 151 | int ret = flash.init(); |
| tvendov | 0:e1f465d87307 | 152 | if (ret != 0) { |
| tvendov | 0:e1f465d87307 | 153 | return 0; |
| tvendov | 0:e1f465d87307 | 154 | } |
| tvendov | 0:e1f465d87307 | 155 | |
| tvendov | 0:e1f465d87307 | 156 | //Find the start of first sector after text area |
| tvendov | 0:e1f465d87307 | 157 | bottom_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR)); |
| tvendov | 0:e1f465d87307 | 158 | start_address = flash.get_flash_start(); |
| tvendov | 0:e1f465d87307 | 159 | flash_size = flash.get_flash_size(); |
| tvendov | 0:e1f465d87307 | 160 | |
| tvendov | 0:e1f465d87307 | 161 | ret = flash.deinit(); |
| tvendov | 0:e1f465d87307 | 162 | |
| tvendov | 0:e1f465d87307 | 163 | static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address); |
| tvendov | 0:e1f465d87307 | 164 | |
| tvendov | 0:e1f465d87307 | 165 | #else |
| tvendov | 0:e1f465d87307 | 166 | |
| tvendov | 0:e1f465d87307 | 167 | static FlashIAPBlockDevice default_bd; |
| tvendov | 0:e1f465d87307 | 168 | |
| tvendov | 0:e1f465d87307 | 169 | #endif |
| tvendov | 0:e1f465d87307 | 170 | |
| tvendov | 0:e1f465d87307 | 171 | return &default_bd; |
| tvendov | 0:e1f465d87307 | 172 | |
| tvendov | 0:e1f465d87307 | 173 | #else |
| tvendov | 0:e1f465d87307 | 174 | |
| tvendov | 0:e1f465d87307 | 175 | return NULL; |
| tvendov | 0:e1f465d87307 | 176 | |
| tvendov | 0:e1f465d87307 | 177 | #endif |
| tvendov | 0:e1f465d87307 | 178 | |
| tvendov | 0:e1f465d87307 | 179 | } |
| tvendov | 0:e1f465d87307 | 180 | |
| tvendov | 0:e1f465d87307 | 181 | MBED_WEAK FileSystem *FileSystem::get_default_instance() |
| tvendov | 0:e1f465d87307 | 182 | { |
| tvendov | 0:e1f465d87307 | 183 | #if COMPONENT_SPIF || COMPONENT_QSPIF || COMPONENT_DATAFLASH |
| tvendov | 0:e1f465d87307 | 184 | |
| tvendov | 0:e1f465d87307 | 185 | static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); |
| tvendov | 0:e1f465d87307 | 186 | flash.set_as_default(); |
| tvendov | 0:e1f465d87307 | 187 | |
| tvendov | 0:e1f465d87307 | 188 | return &flash; |
| tvendov | 0:e1f465d87307 | 189 | |
| tvendov | 0:e1f465d87307 | 190 | #elif COMPONENT_SD |
| tvendov | 0:e1f465d87307 | 191 | |
| tvendov | 0:e1f465d87307 | 192 | static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); |
| tvendov | 0:e1f465d87307 | 193 | sdcard.set_as_default(); |
| tvendov | 0:e1f465d87307 | 194 | |
| tvendov | 0:e1f465d87307 | 195 | return &sdcard; |
| tvendov | 0:e1f465d87307 | 196 | |
| tvendov | 0:e1f465d87307 | 197 | #elif COMPONENT_FLASHIAP |
| tvendov | 0:e1f465d87307 | 198 | |
| tvendov | 0:e1f465d87307 | 199 | static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); |
| tvendov | 0:e1f465d87307 | 200 | flash.set_as_default(); |
| tvendov | 0:e1f465d87307 | 201 | |
| tvendov | 0:e1f465d87307 | 202 | return &flash; |
| tvendov | 0:e1f465d87307 | 203 | |
| tvendov | 0:e1f465d87307 | 204 | #else |
| tvendov | 0:e1f465d87307 | 205 | |
| tvendov | 0:e1f465d87307 | 206 | return NULL; |
| tvendov | 0:e1f465d87307 | 207 | |
| tvendov | 0:e1f465d87307 | 208 | #endif |
| tvendov | 0:e1f465d87307 | 209 | |
| tvendov | 0:e1f465d87307 | 210 | } |
| tvendov | 0:e1f465d87307 | 211 |