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.
Dependencies: Cayenne-LPP SDBlockDevice
trace_helper.cpp
00001 /** 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "drivers/Serial.h" 00019 00020 /** 00021 * Serial object for console tracing 00022 */ 00023 mbed::Serial pc(USBTX, USBRX, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); 00024 00025 /** 00026 * If we have tracing library available, we can see traces from within the 00027 * stack. The library could be made unavailable by removing FEATURE_COMMON_PAL 00028 * from the mbed_app.json to save RAM. 00029 */ 00030 #if defined(FEATURE_COMMON_PAL) 00031 00032 #include "platform/PlatformMutex.h" 00033 #include "mbed_trace.h" 00034 00035 /** 00036 * Local mutex object for synchronization 00037 */ 00038 static PlatformMutex mutex; 00039 00040 static void serial_lock(); 00041 static void serial_unlock(); 00042 static void trace_printer(const char* str); 00043 00044 /** 00045 * Sets up trace for the application 00046 * Wouldn't do anything if the FEATURE_COMMON_PAL is not added 00047 * or if the trace is disabled using mbed_app.json 00048 */ 00049 void setup_trace() 00050 { 00051 // setting up Mbed trace. 00052 mbed_trace_mutex_wait_function_set(serial_lock); 00053 mbed_trace_mutex_release_function_set(serial_unlock); 00054 mbed_trace_init(); 00055 mbed_trace_print_function_set(trace_printer); 00056 } 00057 00058 /** 00059 * Lock provided for serial printing used by trace library 00060 */ 00061 static void serial_lock() 00062 { 00063 mutex.lock(); 00064 } 00065 00066 /** 00067 * Releasing lock provided for serial printing used by trace library 00068 */ 00069 static void serial_unlock() 00070 { 00071 mutex.unlock(); 00072 } 00073 00074 /** 00075 * Prints the Mbed trace, used by trace library. 00076 * Not intended for local use. 00077 */ 00078 static void trace_printer(const char* str) 00079 { 00080 pc.printf("%s\r\n", str); 00081 } 00082 00083 #else 00084 00085 void setup_trace() 00086 { 00087 } 00088 00089 #endif 00090
Generated on Sat Jul 16 2022 05:24:58 by
1.7.2