Rizky Ardi Maulana / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cfstore_svm.cpp Source File

cfstore_svm.cpp

Go to the documentation of this file.
00001 /*
00002  * mbed Microcontroller Library
00003  * Copyright (c) 2006-2016 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  *
00017  */
00018 
00019 #include <stdint.h>
00020 #include <Driver_Common.h>
00021 #include "storage_volume_manager.h"
00022 #include "cfstore_config.h"
00023 #include "cfstore_debug.h"
00024 #include "cfstore_svm.h"
00025 
00026 /** @file   cfstore_svm.cpp
00027  *
00028  * This module is provides a C wrapper to the C++ storage-volume-manager.h API,
00029  * so it can be called by the C-HAL implementation configuration_store.c
00030  */
00031 
00032 #define CFSTORE_SVM_VOL_01_START_OFFSET       0x80000UL
00033 #define CFSTORE_SVM_VOL_01_SIZE               0x80000UL
00034 
00035 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00036 extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
00037 static ARM_DRIVER_STORAGE *cfstore_svm_storage_drv = &ARM_Driver_Storage_MTD_K64F;
00038 
00039 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00040 
00041 /* the storage volume manager instance used to generate virtual mtd descriptors */
00042 static StorageVolumeManager volumeManager;
00043 
00044 /* used only for the initialization of the volume-manager. */
00045 static void cfstore_svm_volume_manager_initialize_callback(int32_t status)
00046 {
00047     CFSTORE_FENTRYLOG("%s: operation %d with status %d" , __func__, (int) operation, (int) status);
00048 }
00049 
00050 static void cfstore_svm_journal_mtc_callback(int32_t status, ARM_STORAGE_OPERATION operation)
00051 {
00052     CFSTORE_FENTRYLOG("%s: operation %d with status %d" , __func__, (int) operation, (int) status);
00053 }
00054 
00055 int32_t cfstore_svm_init(struct _ARM_DRIVER_STORAGE *storage_mtd)
00056 {
00057     int32_t ret = ARM_DRIVER_OK;
00058 
00059     CFSTORE_FENTRYLOG("%s:entered\n", __func__);
00060     ret = volumeManager.initialize(cfstore_svm_storage_drv, cfstore_svm_volume_manager_initialize_callback);
00061     if(ret < ARM_DRIVER_OK) {
00062         CFSTORE_ERRLOG("%s:debug: volume-manager::initialize() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00063         return ret;
00064     }
00065     ret = volumeManager.addVolume_C(CFSTORE_SVM_VOL_01_START_OFFSET, CFSTORE_SVM_VOL_01_SIZE, storage_mtd);
00066     if(ret < ARM_DRIVER_OK) {
00067         CFSTORE_ERRLOG("%s:debug: volume-manager::addVolume_C() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00068         return ret;
00069     }
00070     ret = storage_mtd->Initialize(cfstore_svm_journal_mtc_callback);
00071     if(ret < ARM_DRIVER_OK) {
00072         CFSTORE_ERRLOG("%s:debug: storage_mtd->initialize() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00073         return ret;
00074     }
00075     return ret;
00076 }