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