SDHI_driver patch (mbedOS 5.11.5)
Embed:
(wiki syntax)
Show/hide line numbers
SystemStorage.cpp
00001 /* 00002 * Copyright (c) 2018 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "SystemStorage.h" 00017 #include "BlockDevice.h" 00018 #include "FileSystem.h" 00019 #include "FATFileSystem.h" 00020 #include "LittleFileSystem.h" 00021 #include "mbed_error.h" 00022 00023 00024 #if COMPONENT_SPIF 00025 #include "SPIFBlockDevice.h" 00026 #endif 00027 00028 #if COMPONENT_QSPIF 00029 #include "QSPIFBlockDevice.h" 00030 #endif 00031 00032 #if COMPONENT_DATAFLASH 00033 #include "DataFlashBlockDevice.h" 00034 #endif 00035 00036 #if COMPONENT_SD 00037 #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) 00038 #include "SDHIBlockDevice.h" 00039 #else 00040 #include "SDBlockDevice.h" 00041 #endif 00042 #endif 00043 00044 #if COMPONENT_FLASHIAP 00045 #include "FlashIAPBlockDevice.h" 00046 #endif 00047 00048 using namespace mbed; 00049 00050 00051 00052 MBED_WEAK int avoid_conflict_nvstore_tdbstore(owner_type_e in_mem_owner) 00053 { 00054 int status = MBED_SUCCESS; 00055 static PlatformMutex _mutex; 00056 static owner_type_e internal_memory_owner = NONE; 00057 00058 _mutex.lock(); 00059 00060 if (internal_memory_owner != NONE && 00061 internal_memory_owner != in_mem_owner) { 00062 00063 status = MBED_ERROR_ALREADY_INITIALIZED; 00064 00065 } else { 00066 00067 internal_memory_owner = in_mem_owner; 00068 } 00069 00070 _mutex.unlock(); 00071 00072 return status; 00073 } 00074 00075 // Align a value to a specified size. 00076 // Parameters : 00077 // val - [IN] Value. 00078 // size - [IN] Size. 00079 // Return : Aligned value. 00080 static inline uint32_t align_up(uint32_t val, uint32_t size) 00081 { 00082 return (((val - 1) / size) + 1) * size; 00083 } 00084 00085 MBED_WEAK BlockDevice *BlockDevice::get_default_instance() 00086 { 00087 #if COMPONENT_SPIF 00088 00089 static SPIFBlockDevice default_bd( 00090 MBED_CONF_SPIF_DRIVER_SPI_MOSI, 00091 MBED_CONF_SPIF_DRIVER_SPI_MISO, 00092 MBED_CONF_SPIF_DRIVER_SPI_CLK, 00093 MBED_CONF_SPIF_DRIVER_SPI_CS, 00094 MBED_CONF_SPIF_DRIVER_SPI_FREQ 00095 ); 00096 00097 return &default_bd; 00098 00099 #elif COMPONENT_QSPIF 00100 00101 static QSPIFBlockDevice default_bd( 00102 MBED_CONF_QSPIF_QSPI_IO0, 00103 MBED_CONF_QSPIF_QSPI_IO1, 00104 MBED_CONF_QSPIF_QSPI_IO2, 00105 MBED_CONF_QSPIF_QSPI_IO3, 00106 MBED_CONF_QSPIF_QSPI_SCK, 00107 MBED_CONF_QSPIF_QSPI_CSN, 00108 MBED_CONF_QSPIF_QSPI_POLARITY_MODE, 00109 MBED_CONF_QSPIF_QSPI_FREQ 00110 ); 00111 00112 return &default_bd; 00113 00114 #elif COMPONENT_DATAFLASH 00115 00116 static DataFlashBlockDevice default_bd( 00117 MBED_CONF_DATAFLASH_SPI_MOSI, 00118 MBED_CONF_DATAFLASH_SPI_MISO, 00119 MBED_CONF_DATAFLASH_SPI_CLK, 00120 MBED_CONF_DATAFLASH_SPI_CS 00121 ); 00122 00123 return &default_bd; 00124 00125 #elif COMPONENT_SD 00126 00127 #if (defined(TARGET_VK_RZ_A1H) || defined(TARGET_VK_RZ_A1LU)) 00128 static SDHIBlockDevice default_bd( 00129 MBED_CONF_SD_SDHI_CH 00130 ); 00131 #else 00132 static SDBlockDevice default_bd( 00133 MBED_CONF_SD_SPI_MOSI, 00134 MBED_CONF_SD_SPI_MISO, 00135 MBED_CONF_SD_SPI_CLK, 00136 MBED_CONF_SD_SPI_CS 00137 ); 00138 #endif 00139 00140 return &default_bd; 00141 00142 #elif COMPONENT_FLASHIAP 00143 00144 #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) 00145 00146 size_t flash_size; 00147 uint32_t start_address; 00148 uint32_t bottom_address; 00149 FlashIAP flash; 00150 00151 int ret = flash.init(); 00152 if (ret != 0) { 00153 return 0; 00154 } 00155 00156 //Find the start of first sector after text area 00157 bottom_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR)); 00158 start_address = flash.get_flash_start(); 00159 flash_size = flash.get_flash_size(); 00160 00161 ret = flash.deinit(); 00162 00163 static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address); 00164 00165 #else 00166 00167 static FlashIAPBlockDevice default_bd; 00168 00169 #endif 00170 00171 return &default_bd; 00172 00173 #else 00174 00175 return NULL; 00176 00177 #endif 00178 00179 } 00180 00181 MBED_WEAK FileSystem *FileSystem::get_default_instance() 00182 { 00183 #if COMPONENT_SPIF || COMPONENT_QSPIF || COMPONENT_DATAFLASH 00184 00185 static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); 00186 flash.set_as_default(); 00187 00188 return &flash; 00189 00190 #elif COMPONENT_SD 00191 00192 static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); 00193 sdcard.set_as_default(); 00194 00195 return &sdcard; 00196 00197 #elif COMPONENT_FLASHIAP 00198 00199 static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); 00200 flash.set_as_default(); 00201 00202 return &flash; 00203 00204 #else 00205 00206 return NULL; 00207 00208 #endif 00209 00210 } 00211
Generated on Mon Jul 18 2022 23:15:42 by
1.7.2