File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 24
24
#include " mbed_error.h"
25
25
#include " mbed_wait_api.h"
26
26
#include " MbedCRC.h"
27
+ #include " SystemStorage.h"
27
28
28
29
using namespace mbed ;
29
30
@@ -989,6 +990,13 @@ int TDBStore::init()
989
990
goto end;
990
991
}
991
992
993
+ // Check if we are on internal memory && try to set the internal memory for TDBStore use.
994
+ if (strcmp (_bd->get_type (), " FLASHIAP" ) == 0 &&
995
+ avoid_conflict_nvstore_tdbstore (TDBSTORE) == MBED_ERROR_ALREADY_INITIALIZED) {
996
+
997
+ MBED_ERROR (MBED_ERROR_ALREADY_INITIALIZED, " TDBStore in internal memory can not be initialize when NVStore is in use" );
998
+ }
999
+
992
1000
_max_keys = initial_max_keys;
993
1001
994
1002
ram_table = new ram_table_entry_t [_max_keys];
Original file line number Diff line number Diff line change 21
21
#if NVSTORE_ENABLED
22
22
23
23
#include " FlashIAP.h"
24
+ #include " SystemStorage.h"
24
25
#include " mbed_critical.h"
25
26
#include " mbed_assert.h"
27
+ #include " mbed_error.h"
26
28
#include " mbed_wait_api.h"
27
29
#include < algorithm>
28
30
#include < string.h>
@@ -854,6 +856,12 @@ int NVStore::init()
854
856
return NVSTORE_SUCCESS;
855
857
}
856
858
859
+ // Check if we are on internal memory && try to set the internal memory for TDBStore use.
860
+ ret = avoid_conflict_nvstore_tdbstore (NVSTORE);
861
+ // NVstore in internal memory can not be initialize when TDBStore is in use
862
+ MBED_ASSERT (ret != MBED_ERROR_ALREADY_INITIALIZED);
863
+
864
+
857
865
// This handles the case that init function is called by more than one thread concurrently.
858
866
// Only the one who gets the value of 1 in _init_attempts_val will proceed, while others will
859
867
// wait until init is finished.
Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+ #include " SystemStorage.h"
16
17
#include " BlockDevice.h"
17
18
#include " FileSystem.h"
18
19
#include " FATFileSystem.h"
19
20
#include " LittleFileSystem.h"
21
+ #include " mbed_error.h"
22
+
20
23
21
24
#if COMPONENT_SPIF
22
25
#include " SPIFBlockDevice.h"
40
43
41
44
using namespace mbed ;
42
45
46
+
47
+
48
+ MBED_WEAK int avoid_conflict_nvstore_tdbstore (owner_type_e in_mem_owner)
49
+ {
50
+ int status = MBED_SUCCESS;
51
+ static PlatformMutex _mutex;
52
+ static owner_type_e internal_memory_owner = NONE;
53
+
54
+ _mutex.lock ();
55
+
56
+ if (internal_memory_owner != NONE &&
57
+ internal_memory_owner != in_mem_owner) {
58
+
59
+ status = MBED_ERROR_ALREADY_INITIALIZED;
60
+
61
+ } else {
62
+
63
+ internal_memory_owner = in_mem_owner;
64
+ }
65
+
66
+ _mutex.unlock ();
67
+
68
+ return status;
69
+ }
70
+
43
71
// Align a value to a specified size.
44
72
// Parameters :
45
73
// val - [IN] Value.
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 ARM Limited. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ * Licensed under the Apache License, Version 2.0 (the License); you may
5
+ * not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ #ifndef MBED_SYSTEM_STORAGE_H
17
+ #define MBED_SYSTEM_STORAGE_H
18
+
19
+ #include "mbed_error.h"
20
+
21
+ typedef enum {
22
+ NONE = 0 ,
23
+ NVSTORE ,
24
+ TDBSTORE
25
+ } owner_type_e ;
26
+
27
+ /**
28
+ * @brief Try to get an ownership for the internal flash memory storage type.
29
+ * KVSTORE or NVSTORE is the current option and once the ownership is taken by one
30
+ * second one can not be initialize.
31
+ * @param[in] in_mem_owner Enum parameter to specify NVSTORE or KVSTORE as the storage owner
32
+ * @returns MBED_SUCCESS if succeeded or MBED_ERROR_ALREADY_INITIALIZED if fails.
33
+ */
34
+ int avoid_conflict_nvstore_tdbstore (owner_type_e in_mem_owner );
35
+
36
+ #endif
You can’t perform that action at this time.
0 commit comments