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.
Fork of AdiSense1000_V21 by
adi_sense_log.cpp
00001 /****************************************************************************** 00002 Copyright 2017 (c) Analog Devices, Inc. 00003 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 - Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 - Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in 00012 the documentation and/or other materials provided with the 00013 distribution. 00014 - Neither the name of Analog Devices, Inc. nor the names of its 00015 contributors may be used to endorse or promote products derived 00016 from this software without specific prior written permission. 00017 - The use of this software may or may not infringe the patent rights 00018 of one or more patent holders. This license does not release you 00019 from the requirement that you obtain separate licenses from these 00020 patent holders to use this software. 00021 - Use of the software either in source or binary form, must be run 00022 on or directly connected to an Analog Devices Inc. component. 00023 00024 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00025 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00027 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *****************************************************************************/ 00036 00037 /*! 00038 ****************************************************************************** 00039 * @file: 00040 * @brief: ADISENSE OS-dependent wrapper layer for log functions 00041 *----------------------------------------------------------------------------- 00042 */ 00043 00044 #include <mbed.h> 00045 #include "inc/adi_sense_log.h" 00046 00047 static Serial *gpUartDevice; 00048 00049 static ADI_SENSE_LOG_LEVEL gLogLevel = ADI_SENSE_LOG_LEVEL_DEBUG ; 00050 00051 #ifdef __cplusplus 00052 extern "C" { 00053 #endif 00054 00055 /* 00056 * Open the Log interface and allocate resources 00057 */ 00058 ADI_SENSE_RESULT adi_sense_LogOpen( 00059 ADI_SENSE_PLATFORM_LOG_CONFIG *pConfig) 00060 { 00061 if (pConfig->disableLogs) 00062 return ADI_SENSE_SUCCESS ; 00063 00064 gpUartDevice = new Serial((PinName)pConfig->txPin, 00065 (PinName)pConfig->rxPin, 00066 pConfig->baudRate); 00067 if (!gpUartDevice) 00068 { 00069 ADI_SENSE_LOG_ERROR("Failed to allocate memory for Log UART context"); 00070 return ADI_SENSE_NO_MEM ; 00071 } 00072 00073 return ADI_SENSE_SUCCESS ; 00074 } 00075 00076 /* 00077 * Close the Log interface and free resources 00078 */ 00079 void adi_sense_LogClose(void) 00080 { 00081 if (gpUartDevice) 00082 { 00083 delete gpUartDevice; 00084 gpUartDevice = 0; 00085 } 00086 } 00087 00088 /* 00089 * Set the log level for uart communication 00090 */ 00091 void adi_sense_LogLevel(ADI_SENSE_LOG_LEVEL maxLevel) 00092 { 00093 gLogLevel = maxLevel; 00094 } 00095 00096 /* 00097 * Print a log message to the platform log interface 00098 */ 00099 void adi_sense_Log(ADI_SENSE_LOG_LEVEL level, const char* format, ...) 00100 { 00101 char buffer[256]; 00102 va_list va_args; 00103 00104 if (!gpUartDevice) 00105 return; 00106 00107 if (level > gLogLevel) 00108 return; 00109 00110 va_start(va_args, format); 00111 vsnprintf(buffer, sizeof(buffer), format, va_args); 00112 va_end(va_args); 00113 00114 gpUartDevice->printf("%s\r\n", buffer); 00115 } 00116 00117 #ifdef __cplusplus 00118 } 00119 #endif
Generated on Wed Jul 13 2022 04:26:17 by
1.7.2
