:)

Dependencies:   Servo Cayenne-LPP

Committer:
mbed_official
Date:
Thu Mar 08 17:46:15 2018 +0000
Revision:
0:7037ed05f54f
Child:
8:7594ad70d2bf
Fix construction of LoRaWANInterface object

Since radio object is constructed by another source file, we have a
race condition. In order to prevent this race condition, LoRaWANInterface
object is now created in main().

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:7037ed05f54f 1 /**
mbed_official 0:7037ed05f54f 2 * Copyright (c) 2017, Arm Limited and affiliates.
mbed_official 0:7037ed05f54f 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 0:7037ed05f54f 4 *
mbed_official 0:7037ed05f54f 5 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 0:7037ed05f54f 6 * you may not use this file except in compliance with the License.
mbed_official 0:7037ed05f54f 7 * You may obtain a copy of the License at
mbed_official 0:7037ed05f54f 8 *
mbed_official 0:7037ed05f54f 9 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:7037ed05f54f 10 *
mbed_official 0:7037ed05f54f 11 * Unless required by applicable law or agreed to in writing, software
mbed_official 0:7037ed05f54f 12 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 0:7037ed05f54f 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 0:7037ed05f54f 14 * See the License for the specific language governing permissions and
mbed_official 0:7037ed05f54f 15 * limitations under the License.
mbed_official 0:7037ed05f54f 16 */
mbed_official 0:7037ed05f54f 17
mbed_official 0:7037ed05f54f 18 #include "drivers/Serial.h"
mbed_official 0:7037ed05f54f 19
mbed_official 0:7037ed05f54f 20 /**
mbed_official 0:7037ed05f54f 21 * Serial object for console tracing
mbed_official 0:7037ed05f54f 22 */
mbed_official 0:7037ed05f54f 23 mbed::Serial pc(USBTX, USBRX, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
mbed_official 0:7037ed05f54f 24
mbed_official 0:7037ed05f54f 25 /**
mbed_official 0:7037ed05f54f 26 * If we have tracing library available, we can see traces from within the
mbed_official 0:7037ed05f54f 27 * stack. The library could be made unavailable by removing FEATURE_COMMON_PAL
mbed_official 0:7037ed05f54f 28 * from the mbed_app.json to save RAM.
mbed_official 0:7037ed05f54f 29 */
mbed_official 0:7037ed05f54f 30 #if defined(FEATURE_COMMON_PAL)
mbed_official 0:7037ed05f54f 31
mbed_official 0:7037ed05f54f 32 #include "platform/PlatformMutex.h"
mbed_official 0:7037ed05f54f 33 #include "mbed_trace.h"
mbed_official 0:7037ed05f54f 34
mbed_official 0:7037ed05f54f 35 /**
mbed_official 0:7037ed05f54f 36 * Local mutex object for synchronization
mbed_official 0:7037ed05f54f 37 */
mbed_official 0:7037ed05f54f 38 static PlatformMutex mutex;
mbed_official 0:7037ed05f54f 39
mbed_official 0:7037ed05f54f 40 static void serial_lock();
mbed_official 0:7037ed05f54f 41 static void serial_unlock();
mbed_official 0:7037ed05f54f 42 static void trace_printer(const char* str);
mbed_official 0:7037ed05f54f 43
mbed_official 0:7037ed05f54f 44 /**
mbed_official 0:7037ed05f54f 45 * Sets up trace for the application
mbed_official 0:7037ed05f54f 46 * Wouldn't do anything if the FEATURE_COMMON_PAL is not added
mbed_official 0:7037ed05f54f 47 * or if the trace is disabled using mbed_app.json
mbed_official 0:7037ed05f54f 48 */
mbed_official 0:7037ed05f54f 49 void setup_trace()
mbed_official 0:7037ed05f54f 50 {
mbed_official 0:7037ed05f54f 51 // setting up Mbed trace.
mbed_official 0:7037ed05f54f 52 mbed_trace_mutex_wait_function_set(serial_lock);
mbed_official 0:7037ed05f54f 53 mbed_trace_mutex_release_function_set(serial_unlock);
mbed_official 0:7037ed05f54f 54 mbed_trace_init();
mbed_official 0:7037ed05f54f 55 mbed_trace_print_function_set(trace_printer);
mbed_official 0:7037ed05f54f 56 }
mbed_official 0:7037ed05f54f 57
mbed_official 0:7037ed05f54f 58 /**
mbed_official 0:7037ed05f54f 59 * Lock provided for serial printing used by trace library
mbed_official 0:7037ed05f54f 60 */
mbed_official 0:7037ed05f54f 61 static void serial_lock()
mbed_official 0:7037ed05f54f 62 {
mbed_official 0:7037ed05f54f 63 mutex.lock();
mbed_official 0:7037ed05f54f 64 }
mbed_official 0:7037ed05f54f 65
mbed_official 0:7037ed05f54f 66 /**
mbed_official 0:7037ed05f54f 67 * Releasing lock provided for serial printing used by trace library
mbed_official 0:7037ed05f54f 68 */
mbed_official 0:7037ed05f54f 69 static void serial_unlock()
mbed_official 0:7037ed05f54f 70 {
mbed_official 0:7037ed05f54f 71 mutex.unlock();
mbed_official 0:7037ed05f54f 72 }
mbed_official 0:7037ed05f54f 73
mbed_official 0:7037ed05f54f 74 /**
mbed_official 0:7037ed05f54f 75 * Prints the Mbed trace, used by trace library.
mbed_official 0:7037ed05f54f 76 * Not intended for local use.
mbed_official 0:7037ed05f54f 77 */
mbed_official 0:7037ed05f54f 78 static void trace_printer(const char* str)
mbed_official 0:7037ed05f54f 79 {
mbed_official 0:7037ed05f54f 80 printf("%s\r\n", str);
mbed_official 0:7037ed05f54f 81 }
mbed_official 0:7037ed05f54f 82
mbed_official 0:7037ed05f54f 83 #else
mbed_official 0:7037ed05f54f 84
mbed_official 0:7037ed05f54f 85 void setup_trace()
mbed_official 0:7037ed05f54f 86 {
mbed_official 0:7037ed05f54f 87 }
mbed_official 0:7037ed05f54f 88
mbed_official 0:7037ed05f54f 89 #endif
mbed_official 0:7037ed05f54f 90