Rohan Gurav
/
Sean_AdiSense1000_V21
ADISense1000 Version 2.1 code base
Fork of AdiSense1000_V21 by
Diff: src/mbed/adi_sense_log.cpp
- Revision:
- 28:4eb837cd71df
- Parent:
- 26:12d0204be712
--- a/src/mbed/adi_sense_log.cpp Mon Mar 26 14:50:05 2018 +0000 +++ b/src/mbed/adi_sense_log.cpp Thu May 17 10:34:45 2018 +0100 @@ -1,10 +1,3 @@ -/*! - ****************************************************************************** - * @file: adi_sense_log.cpp - * @brief: ADISENSE OS-dependent wrapper layer for log functions - *----------------------------------------------------------------------------- - */ - /****************************************************************************** Copyright 2017 (c) Analog Devices, Inc. @@ -41,19 +34,19 @@ * *****************************************************************************/ +/*! + ****************************************************************************** + * @file: + * @brief: ADISENSE OS-dependent wrapper layer for log functions + *----------------------------------------------------------------------------- + */ + #include <mbed.h> #include "inc/adi_sense_log.h" -#define ADI_SENSE_LOG_UART_BAUDRATE (115200) +static Serial *gpUartDevice; -#ifdef TARGET_STM32F411xE -#define ADI_SENSE_LOG_UART_TX_PIN (PA_11) -#define ADI_SENSE_LOG_UART_RX_PIN (PA_12) -#else -#error "unsupported target platform" -#endif - -static Serial *gpUartDevice; +static ADI_SENSE_LOG_LEVEL gLogLevel = ADI_SENSE_LOG_LEVEL_DEBUG; #ifdef __cplusplus extern "C" { @@ -62,11 +55,15 @@ /* * Open the Log interface and allocate resources */ -ADI_SENSE_RESULT adi_sense_LogOpen(void) +ADI_SENSE_RESULT adi_sense_LogOpen( + ADI_SENSE_PLATFORM_LOG_CONFIG *pConfig) { - gpUartDevice = new Serial(ADI_SENSE_LOG_UART_TX_PIN, - ADI_SENSE_LOG_UART_RX_PIN, - ADI_SENSE_LOG_UART_BAUDRATE); + if (pConfig->disableLogs) + return ADI_SENSE_SUCCESS; + + gpUartDevice = new Serial((PinName)pConfig->txPin, + (PinName)pConfig->rxPin, + pConfig->baudRate); if (!gpUartDevice) { ADI_SENSE_LOG_ERROR("Failed to allocate memory for Log UART context"); @@ -89,6 +86,14 @@ } /* + * Set the log level for uart communication + */ +void adi_sense_LogLevel(ADI_SENSE_LOG_LEVEL maxLevel) +{ + gLogLevel = maxLevel; +} + +/* * Print a log message to the platform log interface */ void adi_sense_Log(ADI_SENSE_LOG_LEVEL level, const char* format, ...) @@ -99,6 +104,9 @@ if (!gpUartDevice) return; + if (level > gLogLevel) + return; + va_start(va_args, format); vsnprintf(buffer, sizeof(buffer), format, va_args); va_end(va_args); @@ -109,4 +117,3 @@ #ifdef __cplusplus } #endif -