Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mesh_nvm.cpp@78:fc7a81fd524c, 2018-03-27 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Mar 27 12:45:15 2018 +0100
- Revision:
- 78:fc7a81fd524c
- Parent:
- 73:cea274cdbb5d
- Child:
- 87:a6a7b64f4f48
Merge branch 'mbed-os-5.8.0-oob'
* mbed-os-5.8.0-oob:
Updating mbed-os to mbed-os-5.8.0-rc2
Update Thread storage device config
Updating mbed-os to mbed-os-5.8.0-rc1
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-mesh-minimal
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 72:a7c594402382 | 1 | /* |
| mbed_official | 72:a7c594402382 | 2 | * Copyright (c) 2018 ARM Limited. All rights reserved. |
| mbed_official | 72:a7c594402382 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| mbed_official | 72:a7c594402382 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| mbed_official | 72:a7c594402382 | 5 | * not use this file except in compliance with the License. |
| mbed_official | 72:a7c594402382 | 6 | * You may obtain a copy of the License at |
| mbed_official | 72:a7c594402382 | 7 | * |
| mbed_official | 72:a7c594402382 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mbed_official | 72:a7c594402382 | 9 | * |
| mbed_official | 72:a7c594402382 | 10 | * Unless required by applicable law or agreed to in writing, software |
| mbed_official | 72:a7c594402382 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| mbed_official | 72:a7c594402382 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mbed_official | 72:a7c594402382 | 13 | * See the License for the specific language governing permissions and |
| mbed_official | 72:a7c594402382 | 14 | * limitations under the License. |
| mbed_official | 72:a7c594402382 | 15 | */ |
| mbed_official | 72:a7c594402382 | 16 | |
| mbed_official | 72:a7c594402382 | 17 | #include "mbed.h" |
| mbed_official | 72:a7c594402382 | 18 | |
| mbed_official | 78:fc7a81fd524c | 19 | /* Application configuration values from json */ |
| mbed_official | 73:cea274cdbb5d | 20 | #define MESH_LOWPAN 1 |
| mbed_official | 73:cea274cdbb5d | 21 | #define MESH_THREAD 2 |
| mbed_official | 78:fc7a81fd524c | 22 | #define MESH_HEAP 3 |
| mbed_official | 78:fc7a81fd524c | 23 | #define MESH_SD_CARD 4 |
| mbed_official | 78:fc7a81fd524c | 24 | |
| mbed_official | 72:a7c594402382 | 25 | /* At the moment, Thread builds using K64F support NVM */ |
| mbed_official | 72:a7c594402382 | 26 | #if MBED_CONF_APP_MESH_TYPE == MESH_THREAD && defined(TARGET_K64F) |
| mbed_official | 72:a7c594402382 | 27 | |
| mbed_official | 72:a7c594402382 | 28 | #include "LittleFileSystem.h" |
| mbed_official | 72:a7c594402382 | 29 | #include "SDBlockDevice.h" |
| mbed_official | 72:a7c594402382 | 30 | #include "HeapBlockDevice.h" |
| mbed_official | 72:a7c594402382 | 31 | #include "ns_file_system.h" |
| mbed_official | 72:a7c594402382 | 32 | #include "mbed_trace.h" |
| mbed_official | 72:a7c594402382 | 33 | |
| mbed_official | 72:a7c594402382 | 34 | #define TRACE_GROUP "mnvm" |
| mbed_official | 72:a7c594402382 | 35 | |
| mbed_official | 72:a7c594402382 | 36 | /* By default use HEAP as NVM storage, comment macro in order to use SD card */ |
| mbed_official | 78:fc7a81fd524c | 37 | #ifdef MBED_CONF_APP_STORAGE_DEVICE |
| mbed_official | 78:fc7a81fd524c | 38 | |
| mbed_official | 78:fc7a81fd524c | 39 | #if MBED_CONF_APP_STORAGE_DEVICE == MESH_HEAP |
| mbed_official | 78:fc7a81fd524c | 40 | // Use Heap block device |
| mbed_official | 72:a7c594402382 | 41 | #define USE_HEAP_BLOCK_DEVICE |
| mbed_official | 78:fc7a81fd524c | 42 | #elif MBED_CONF_APP_STORAGE_DEVICE == MESH_SD_CARD |
| mbed_official | 78:fc7a81fd524c | 43 | // Use SD CARD - lack of USE_HEAP_BLOCK_DEVICE selects SD_CARD |
| mbed_official | 78:fc7a81fd524c | 44 | #endif |
| mbed_official | 78:fc7a81fd524c | 45 | |
| mbed_official | 78:fc7a81fd524c | 46 | #endif /* MBED_CONF_APP_STORAGE_OPTION */ |
| mbed_official | 72:a7c594402382 | 47 | |
| mbed_official | 72:a7c594402382 | 48 | LittleFileSystem *fs; |
| mbed_official | 72:a7c594402382 | 49 | BlockDevice *bd; |
| mbed_official | 72:a7c594402382 | 50 | |
| mbed_official | 72:a7c594402382 | 51 | void mesh_nvm_initialize() |
| mbed_official | 72:a7c594402382 | 52 | { |
| mbed_official | 72:a7c594402382 | 53 | fs = new LittleFileSystem("fs"); |
| mbed_official | 72:a7c594402382 | 54 | #ifdef USE_HEAP_BLOCK_DEVICE |
| mbed_official | 72:a7c594402382 | 55 | const char *bd_info = "NVM: Heap"; |
| mbed_official | 72:a7c594402382 | 56 | bd = new HeapBlockDevice(16 * 512, 512); |
| mbed_official | 72:a7c594402382 | 57 | #else |
| mbed_official | 72:a7c594402382 | 58 | const char *bd_info = "NVM: SD"; |
| mbed_official | 72:a7c594402382 | 59 | bd = new SDBlockDevice(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS); |
| mbed_official | 72:a7c594402382 | 60 | #endif |
| mbed_official | 72:a7c594402382 | 61 | |
| mbed_official | 72:a7c594402382 | 62 | tr_debug("%s", bd_info); |
| mbed_official | 72:a7c594402382 | 63 | int mount_status = fs->mount(bd); |
| mbed_official | 72:a7c594402382 | 64 | if (mount_status) { |
| mbed_official | 72:a7c594402382 | 65 | tr_warning("mount error: %d, trying format...", mount_status); |
| mbed_official | 72:a7c594402382 | 66 | mount_status = fs->reformat(bd); |
| mbed_official | 72:a7c594402382 | 67 | tr_info("reformat %s (%d)", mount_status ? "failed" : "OK", mount_status); |
| mbed_official | 72:a7c594402382 | 68 | } |
| mbed_official | 72:a7c594402382 | 69 | |
| mbed_official | 72:a7c594402382 | 70 | if (!mount_status) { |
| mbed_official | 72:a7c594402382 | 71 | ns_file_system_set_root_path("/fs/"); |
| mbed_official | 72:a7c594402382 | 72 | } |
| mbed_official | 72:a7c594402382 | 73 | } |
| mbed_official | 72:a7c594402382 | 74 | |
| mbed_official | 72:a7c594402382 | 75 | #else /* MBED_CONF_APP_MESH_TYPE == MESH_THREAD && defined(TARGET_K64F) */ |
| mbed_official | 72:a7c594402382 | 76 | void mesh_nvm_initialize() |
| mbed_official | 72:a7c594402382 | 77 | { |
| mbed_official | 72:a7c594402382 | 78 | /* NVM not supported */ |
| mbed_official | 72:a7c594402382 | 79 | } |
| mbed_official | 72:a7c594402382 | 80 | #endif /* MBED_CONF_APP_MESH_TYPE == MESH_THREAD && defined(TARGET_K64F) */ |
| mbed_official | 72:a7c594402382 | 81 |