Rtos API example

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 // This file is deprecated so deprecation warnings when building it are silenced
00020 #if   defined ( __CC_ARM )
00021 #pragma diag_suppress 1361  // Deprecated declaration
00022 #elif defined ( __GNUC__ )
00023 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
00024 #endif
00025 
00026 #include <stdint.h>
00027 #include <Driver_Common.h>
00028 #include "storage_volume_manager.h"
00029 #include "cfstore_config.h"
00030 #include "cfstore_debug.h"
00031 #include "cfstore_svm.h"
00032 
00033 /** @file   cfstore_svm.cpp
00034  *
00035  * This module is provides a C wrapper to the C++ storage-volume-manager.h API,
00036  * so it can be called by the C-HAL implementation configuration_store.c
00037  */
00038 
00039 #ifndef CFSTORE_SVM_VOL_01_START_OFFSET
00040 #define CFSTORE_SVM_VOL_01_START_OFFSET       0x80000UL
00041 #endif
00042 
00043 #ifndef CFSTORE_SVM_VOL_01_SIZE
00044 #define CFSTORE_SVM_VOL_01_SIZE               0x80000UL
00045 #endif
00046 
00047 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
00048 extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
00049 static ARM_DRIVER_STORAGE *cfstore_svm_storage_drv = &ARM_Driver_Storage_MTD_K64F;
00050 
00051 /* the storage volume manager instance used to generate virtual mtd descriptors */
00052 StorageVolumeManager volumeManager;
00053 
00054 /* used only for the initialization of the volume-manager. */
00055 static void cfstore_svm_volume_manager_initialize_callback(int32_t status)
00056 {
00057     CFSTORE_FENTRYLOG("%s: with status %d" , __func__, (int) status);
00058 }
00059 
00060 static void cfstore_svm_journal_mtc_callback(int32_t status, ARM_STORAGE_OPERATION operation)
00061 {
00062     CFSTORE_FENTRYLOG("%s: operation %d with status %d" , __func__, (int) operation, (int) status);
00063 }
00064 
00065 int32_t cfstore_svm_init(struct _ARM_DRIVER_STORAGE *storage_mtd)
00066 {
00067     int32_t ret = ARM_DRIVER_OK;
00068 
00069     CFSTORE_FENTRYLOG("%s:entered\n", __func__);
00070     ret = volumeManager.initialize(cfstore_svm_storage_drv, cfstore_svm_volume_manager_initialize_callback);
00071     if(ret < ARM_DRIVER_OK) {
00072         CFSTORE_ERRLOG("%s:debug: volume-manager::initialize() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00073         return ret;
00074     }
00075     ret = volumeManager.addVolume_C(CFSTORE_SVM_VOL_01_START_OFFSET, CFSTORE_SVM_VOL_01_SIZE, storage_mtd);
00076     if(ret < ARM_DRIVER_OK) {
00077         CFSTORE_ERRLOG("%s:debug: volume-manager::addVolume_C() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00078         return ret;
00079     }
00080     ret = storage_mtd->Initialize(cfstore_svm_journal_mtc_callback);
00081     if(ret < ARM_DRIVER_OK) {
00082         CFSTORE_ERRLOG("%s:debug: storage_mtd->initialize() failed for storage_mtd=%p (ret=%d)", __func__, storage_mtd, (int) ret);
00083         return ret;
00084     }
00085     return ret;
00086 }
00087 
00088 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
00089