PoC_Team
/
ADMW1001_example_firmware
Host API Example for the ADMW1001
Embed:
(wiki syntax)
Show/hide line numbers
admw_log.cpp
Go to the documentation of this file.
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: ADMW OS-dependent wrapper layer for log functions 00041 *----------------------------------------------------------------------------- 00042 */ 00043 00044 #include <mbed.h> 00045 #include "inc/admw_log.h" 00046 00047 static Serial *gpUartDevice; 00048 00049 static ADMW_LOG_LEVEL gLogLevel = ADMW_LOG_LEVEL_DEBUG ; 00050 00051 #ifdef __cplusplus 00052 extern "C" { 00053 #endif 00054 00055 /* 00056 * Open the Log interface and allocate resources 00057 */ 00058 ADMW_RESULT admw_LogOpen( 00059 ADMW_PLATFORM_LOG_CONFIG *pConfig) 00060 { 00061 if (pConfig->disableLogs) 00062 return ADMW_SUCCESS ; 00063 00064 gpUartDevice = new Serial((PinName)pConfig->txPin, 00065 (PinName)pConfig->rxPin, 00066 pConfig->baudRate); 00067 if (!gpUartDevice) { 00068 ADMW_LOG_ERROR("Failed to allocate memory for Log UART context"); 00069 return ADMW_NO_MEM ; 00070 } 00071 00072 return ADMW_SUCCESS ; 00073 } 00074 00075 /* 00076 * Close the Log interface and free resources 00077 */ 00078 void admw_LogClose(void) 00079 { 00080 if (gpUartDevice) { 00081 delete gpUartDevice; 00082 gpUartDevice = 0; 00083 } 00084 } 00085 00086 /* 00087 * Set the log level for uart communication 00088 */ 00089 void admw_LogLevel(ADMW_LOG_LEVEL maxLevel) 00090 { 00091 gLogLevel = maxLevel; 00092 } 00093 00094 /* 00095 * Print a log message to the platform log interface 00096 */ 00097 void admw_Log(ADMW_LOG_LEVEL level, const char* format, ...) 00098 { 00099 char buffer[256]; 00100 va_list va_args; 00101 00102 if (!gpUartDevice) 00103 return; 00104 00105 if (level > gLogLevel) 00106 return; 00107 00108 va_start(va_args, format); 00109 vsnprintf(buffer, sizeof(buffer), format, va_args); 00110 va_end(va_args); 00111 00112 gpUartDevice->printf("%s\r\n", buffer); 00113 } 00114 00115 #ifdef __cplusplus 00116 } 00117 #endif
Generated on Wed Jul 13 2022 03:04:54 by 1.7.2