mbed Open Thread example with nRF52-DK (nRF52840 SoC).

Committer:
djabi
Date:
Fri Jan 04 23:55:03 2019 +0000
Revision:
120:e8a17278fb1a
Parent:
109:4799ef092b94
Removed unused parts of the example code.

Who changed what in which revision?

UserRevisionLine numberNew 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 87:a6a7b64f4f48 18 #include "Nanostack.h"
mbed_official 72:a7c594402382 19
mbed_official 78:fc7a81fd524c 20 /* Application configuration values from json */
mbed_official 109:4799ef092b94 21 #define MESH_NVM_HEAP 1
mbed_official 109:4799ef092b94 22 #define MESH_NVM_SD_CARD 2
mbed_official 109:4799ef092b94 23 #define MESH_NVM_NONE 3
mbed_official 78:fc7a81fd524c 24
mbed_official 72:a7c594402382 25 /* At the moment, Thread builds using K64F support NVM */
mbed_official 109:4799ef092b94 26 #if defined MBED_CONF_APP_STORAGE_DEVICE && MBED_CONF_APP_STORAGE_DEVICE != MESH_NVM_NONE && 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 LittleFileSystem *fs;
mbed_official 72:a7c594402382 37 BlockDevice *bd;
mbed_official 72:a7c594402382 38
mbed_official 72:a7c594402382 39 void mesh_nvm_initialize()
mbed_official 72:a7c594402382 40 {
mbed_official 72:a7c594402382 41 fs = new LittleFileSystem("fs");
mbed_official 109:4799ef092b94 42 #if MBED_CONF_APP_STORAGE_DEVICE == MESH_NVM_HEAP
mbed_official 72:a7c594402382 43 const char *bd_info = "NVM: Heap";
mbed_official 72:a7c594402382 44 bd = new HeapBlockDevice(16 * 512, 512);
mbed_official 72:a7c594402382 45 #else
mbed_official 72:a7c594402382 46 const char *bd_info = "NVM: SD";
mbed_official 72:a7c594402382 47 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 48 #endif
mbed_official 72:a7c594402382 49
mbed_official 109:4799ef092b94 50 tr_debug("%s", bd_info);
mbed_official 72:a7c594402382 51 int mount_status = fs->mount(bd);
mbed_official 72:a7c594402382 52 if (mount_status) {
mbed_official 72:a7c594402382 53 tr_warning("mount error: %d, trying format...", mount_status);
mbed_official 72:a7c594402382 54 mount_status = fs->reformat(bd);
mbed_official 72:a7c594402382 55 tr_info("reformat %s (%d)", mount_status ? "failed" : "OK", mount_status);
mbed_official 72:a7c594402382 56 }
mbed_official 72:a7c594402382 57
mbed_official 72:a7c594402382 58 if (!mount_status) {
mbed_official 87:a6a7b64f4f48 59 Nanostack::get_instance(); // ensure Nanostack is initialised
mbed_official 72:a7c594402382 60 ns_file_system_set_root_path("/fs/");
mbed_official 87:a6a7b64f4f48 61 // Should be like: Nanostack::get_instance().file_system_set_root_path("/fs/");
mbed_official 72:a7c594402382 62 }
mbed_official 72:a7c594402382 63 }
mbed_official 72:a7c594402382 64
mbed_official 109:4799ef092b94 65 #else /* #if defined MBED_CONF_APP_STORAGE_DEVICE && MBED_CONF_APP_STORAGE_DEVICE != MESH_NVM_NONE && defined(TARGET_K64F) */
mbed_official 109:4799ef092b94 66
mbed_official 72:a7c594402382 67 void mesh_nvm_initialize()
mbed_official 72:a7c594402382 68 {
mbed_official 72:a7c594402382 69 /* NVM not supported */
mbed_official 72:a7c594402382 70 }
mbed_official 72:a7c594402382 71
mbed_official 109:4799ef092b94 72 #endif /* #if defined MBED_CONF_APP_STORAGE_DEVICE && MBED_CONF_APP_STORAGE_DEVICE != MESH_NVM_NONE && defined(TARGET_K64F) */
mbed_official 109:4799ef092b94 73