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

Committer:
mbed_official
Date:
Wed Sep 26 10:30:19 2018 +0100
Revision:
105:0b691b27144a
Parent:
99:8d5085231b0d
Child:
116:b2f0131722a0
Merge branch 'mbed-os-5.10.0-oob'

* mbed-os-5.10.0-oob:
Update mbed-os to 5.10.0-rc3 (#220)
Updating mbed-os to mbed-os-5.10.0-rc2
Use Default meshinterface from Mbed OS 5.10
Update Jenkinsfile
Updating mbed-os to mbed-os-5.10.0-rc1
Remove sd-driver and update README (#213)
Remove external RF drivers

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-mesh-minimal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:27692043e962 1 /*
mbed_official 52:27692043e962 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
mbed_official 52:27692043e962 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 52:27692043e962 4 * Licensed under the Apache License, Version 2.0 (the License); you may
mbed_official 52:27692043e962 5 * not use this file except in compliance with the License.
mbed_official 52:27692043e962 6 * You may obtain a copy of the License at
mbed_official 52:27692043e962 7 *
mbed_official 52:27692043e962 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 52:27692043e962 9 *
mbed_official 52:27692043e962 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 52:27692043e962 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
mbed_official 52:27692043e962 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 52:27692043e962 13 * See the License for the specific language governing permissions and
mbed_official 52:27692043e962 14 * limitations under the License.
mbed_official 52:27692043e962 15 */
Seppo Takalo 0:bde1843b9885 16 #include "mbed.h"
Seppo Takalo 0:bde1843b9885 17 #include "rtos.h"
Seppo Takalo 0:bde1843b9885 18 #include "NanostackInterface.h"
mbed_official 52:27692043e962 19 #include "mbed-trace/mbed_trace.h"
mbed_official 72:a7c594402382 20 #include "mesh_nvm.h"
mbed_official 52:27692043e962 21
mbed_official 52:27692043e962 22 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 23 #include "mesh_led_control_example.h"
mbed_official 52:27692043e962 24 #endif
mbed_official 52:27692043e962 25
mbed_official 52:27692043e962 26 void trace_printer(const char* str) {
mbed_official 52:27692043e962 27 printf("%s\n", str);
mbed_official 52:27692043e962 28 }
Seppo Takalo 0:bde1843b9885 29
mbed_official 105:0b691b27144a 30 MeshInterface *mesh;
mbed_official 16:22f072355a2c 31
mbed_official 52:27692043e962 32 static Mutex SerialOutMutex;
mbed_official 52:27692043e962 33
mbed_official 97:6dee44085a18 34 void thread_eui64_trace()
mbed_official 97:6dee44085a18 35 {
mbed_official 105:0b691b27144a 36 #define LOWPAN 1
mbed_official 105:0b691b27144a 37 #define THREAD 2
mbed_official 105:0b691b27144a 38 #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == THREAD && (MBED_VERSION >= MBED_ENCODE_VERSION(5,10,0))
mbed_official 97:6dee44085a18 39 uint8_t eui64[8] = {0};
mbed_official 105:0b691b27144a 40 static_cast<ThreadInterface*>(mesh)->device_eui64_get(eui64);
mbed_official 97:6dee44085a18 41 printf("Device EUI64 address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]);
mbed_official 97:6dee44085a18 42 #endif
mbed_official 97:6dee44085a18 43 }
mbed_official 97:6dee44085a18 44
mbed_official 52:27692043e962 45 void serial_out_mutex_wait()
mbed_official 52:27692043e962 46 {
mbed_official 52:27692043e962 47 SerialOutMutex.lock();
mbed_official 52:27692043e962 48 }
mbed_official 52:27692043e962 49
mbed_official 52:27692043e962 50 void serial_out_mutex_release()
mbed_official 52:27692043e962 51 {
mbed_official 52:27692043e962 52 SerialOutMutex.unlock();
mbed_official 52:27692043e962 53 }
mbed_official 52:27692043e962 54
Seppo Takalo 0:bde1843b9885 55 int main()
Seppo Takalo 0:bde1843b9885 56 {
mbed_official 52:27692043e962 57 mbed_trace_init();
mbed_official 52:27692043e962 58 mbed_trace_print_function_set(trace_printer);
mbed_official 52:27692043e962 59 mbed_trace_mutex_wait_function_set( serial_out_mutex_wait );
mbed_official 52:27692043e962 60 mbed_trace_mutex_release_function_set( serial_out_mutex_release );
mbed_official 105:0b691b27144a 61
mbed_official 52:27692043e962 62 printf("Start mesh-minimal application\n");
mbed_official 105:0b691b27144a 63
mbed_official 105:0b691b27144a 64 #define STR(s) #s
mbed_official 105:0b691b27144a 65 printf("Build: %s %s\nMesh type: %s\n", __DATE__, __TIME__, STR(MBED_CONF_NSAPI_DEFAULT_MESH_TYPE));
mbed_official 97:6dee44085a18 66 #ifdef MBED_MAJOR_VERSION
mbed_official 97:6dee44085a18 67 printf("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
mbed_official 97:6dee44085a18 68 #endif
mbed_official 4:567d72fb3d84 69
mbed_official 52:27692043e962 70 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 71 if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
mbed_official 52:27692043e962 72 start_blinking();
mbed_official 52:27692043e962 73 } else {
mbed_official 52:27692043e962 74 printf("pins not configured. Skipping the LED control.\n");
mbed_official 52:27692043e962 75 }
mbed_official 4:567d72fb3d84 76 #endif
mbed_official 105:0b691b27144a 77 mesh = MeshInterface::get_default_instance();
mbed_official 105:0b691b27144a 78 if (!mesh) {
mbed_official 105:0b691b27144a 79 printf("Error! MeshInterface not found!\n");
mbed_official 105:0b691b27144a 80 return -1;
mbed_official 105:0b691b27144a 81 }
mbed_official 105:0b691b27144a 82
mbed_official 97:6dee44085a18 83 thread_eui64_trace();
mbed_official 72:a7c594402382 84 mesh_nvm_initialize();
mbed_official 97:6dee44085a18 85 printf("Connecting...\n");
mbed_official 105:0b691b27144a 86 int error = mesh->connect();
mbed_official 52:27692043e962 87 if (error) {
mbed_official 52:27692043e962 88 printf("Connection failed! %d\n", error);
mbed_official 52:27692043e962 89 return error;
Seppo Takalo 0:bde1843b9885 90 }
Seppo Takalo 0:bde1843b9885 91
mbed_official 105:0b691b27144a 92 while (NULL == mesh->get_ip_address())
mbed_official 17:ee2610e1cb78 93 Thread::wait(500);
mbed_official 17:ee2610e1cb78 94
mbed_official 105:0b691b27144a 95 printf("Connected. IP = %s\n", mesh->get_ip_address());
mbed_official 52:27692043e962 96
mbed_official 52:27692043e962 97 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 98 // Network found, start socket example
mbed_official 52:27692043e962 99 if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
mbed_official 52:27692043e962 100 cancel_blinking();
mbed_official 105:0b691b27144a 101 start_mesh_led_control_example((NetworkInterface *)mesh);
mbed_official 52:27692043e962 102 }
mbed_official 52:27692043e962 103 #endif
mbed_official 1:24cff46332de 104 }