File tree Expand file tree Collapse file tree 4 files changed +83
-0
lines changed Expand file tree Collapse file tree 4 files changed +83
-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
@@ -952,13 +953,21 @@ int TDBStore::init()
952
953
uint32_t actual_data_size;
953
954
int os_ret, ret = MBED_SUCCESS, reserved_ret;
954
955
uint16_t versions[_num_areas];
956
+ internal_mem_resident_type_e out_in_mem_res;
955
957
956
958
_mutex.lock ();
957
959
958
960
if (_is_initialized) {
959
961
goto end;
960
962
}
961
963
964
+ // Check if we are on internal memory && try to set the internal memory for TDBStore use.
965
+ if (strcmp (_bd->get_type (), " FLASHIAP" )==0 &&
966
+ set_internal_storage_ownership (TDBSTORE, &out_in_mem_res) == MBED_ERROR_ALREADY_INITIALIZED) {
967
+
968
+ MBED_ERROR (MBED_ERROR_ALREADY_INITIALIZED, " TDBStore in internal memory can not be initialize when NVStore is in use" );
969
+ }
970
+
962
971
_max_keys = initial_max_keys;
963
972
964
973
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>
@@ -849,11 +851,18 @@ int NVStore::init()
849
851
uint16_t keys[NVSTORE_NUM_AREAS];
850
852
uint16_t actual_size;
851
853
uint8_t owner;
854
+ internal_mem_resident_type_e out_in_mem_res;
852
855
853
856
if (_init_done) {
854
857
return NVSTORE_SUCCESS;
855
858
}
856
859
860
+ // Check if we are on internal memory && try to set the internal memory for TDBStore use.
861
+ ret = set_internal_storage_ownership (NVSTORE, &out_in_mem_res);
862
+ // NVstore in internal memory can not be initialize when TDBStore is in use
863
+ MBED_ASSERT (ret != MBED_ERROR_ALREADY_INITIALIZED);
864
+
865
+
857
866
// This handles the case that init function is called by more than one thread concurrently.
858
867
// Only the one who gets the value of 1 in _init_attempts_val will proceed, while others will
859
868
// 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
+ static internal_mem_resident_type_e internal_memory_residency = NONE;
47
+ static SingletonPtr<PlatformMutex> system_storage_mutex;
48
+
49
+ MBED_WEAK int set_internal_storage_ownership (internal_mem_resident_type_e in_mem_res, internal_mem_resident_type_e *out_mem_res)
50
+ {
51
+ int status = MBED_SUCCESS;
52
+
53
+ system_storage_mutex->lock ();
54
+
55
+ if (internal_memory_residency != NONE &&
56
+ internal_memory_residency != in_mem_res) {
57
+
58
+ status = MBED_ERROR_ALREADY_INITIALIZED;
59
+
60
+ } else {
61
+
62
+ internal_memory_residency = in_mem_res;
63
+ }
64
+
65
+ *out_mem_res = internal_memory_residency;
66
+ system_storage_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
+ } internal_mem_resident_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_res Enum parameter to specify NVSTORE or KVSTORE as the storage owner
32
+ * @param[in] out_mem_res Enum parameter which specify who is the current owner of the storage.
33
+ * @returns MBED_SUCCESS if succeeded or MBED_ERROR_ALREADY_INITIALIZED if fails.
34
+ */
35
+ int set_internal_storage_ownership (internal_mem_resident_type_e in_mem_res , internal_mem_resident_type_e * out_mem_res );
36
+
37
+ #endif
You can’t perform that action at this time.
0 commit comments