Rohan Gurav
/
Sean_AdiSense1000_V21
ADISense1000 Version 2.1 code base
Fork of AdiSense1000_V21 by
src/mbed/adi_sense_log.cpp@29:57edca10d78c, 2018-05-22 (annotated)
- Committer:
- kevin1990
- Date:
- Tue May 22 13:45:24 2018 +0100
- Branch:
- v2.0
- Revision:
- 29:57edca10d78c
- Parent:
- 27:567abf893938
Adding host library and example code for v1.3 release to v2.0 branch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
danodonovan | 26:12d0204be712 | 1 | /****************************************************************************** |
danodonovan | 26:12d0204be712 | 2 | Copyright 2017 (c) Analog Devices, Inc. |
danodonovan | 26:12d0204be712 | 3 | |
danodonovan | 26:12d0204be712 | 4 | All rights reserved. |
danodonovan | 26:12d0204be712 | 5 | |
danodonovan | 26:12d0204be712 | 6 | Redistribution and use in source and binary forms, with or without |
danodonovan | 26:12d0204be712 | 7 | modification, are permitted provided that the following conditions are met: |
danodonovan | 26:12d0204be712 | 8 | - Redistributions of source code must retain the above copyright |
danodonovan | 26:12d0204be712 | 9 | notice, this list of conditions and the following disclaimer. |
danodonovan | 26:12d0204be712 | 10 | - Redistributions in binary form must reproduce the above copyright |
danodonovan | 26:12d0204be712 | 11 | notice, this list of conditions and the following disclaimer in |
danodonovan | 26:12d0204be712 | 12 | the documentation and/or other materials provided with the |
danodonovan | 26:12d0204be712 | 13 | distribution. |
danodonovan | 26:12d0204be712 | 14 | - Neither the name of Analog Devices, Inc. nor the names of its |
danodonovan | 26:12d0204be712 | 15 | contributors may be used to endorse or promote products derived |
danodonovan | 26:12d0204be712 | 16 | from this software without specific prior written permission. |
danodonovan | 26:12d0204be712 | 17 | - The use of this software may or may not infringe the patent rights |
danodonovan | 26:12d0204be712 | 18 | of one or more patent holders. This license does not release you |
danodonovan | 26:12d0204be712 | 19 | from the requirement that you obtain separate licenses from these |
danodonovan | 26:12d0204be712 | 20 | patent holders to use this software. |
danodonovan | 26:12d0204be712 | 21 | - Use of the software either in source or binary form, must be run |
danodonovan | 26:12d0204be712 | 22 | on or directly connected to an Analog Devices Inc. component. |
danodonovan | 26:12d0204be712 | 23 | |
danodonovan | 26:12d0204be712 | 24 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
danodonovan | 26:12d0204be712 | 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
danodonovan | 26:12d0204be712 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
danodonovan | 26:12d0204be712 | 27 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
danodonovan | 26:12d0204be712 | 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
danodonovan | 26:12d0204be712 | 29 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
danodonovan | 26:12d0204be712 | 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
danodonovan | 26:12d0204be712 | 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
danodonovan | 26:12d0204be712 | 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
danodonovan | 26:12d0204be712 | 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
danodonovan | 26:12d0204be712 | 34 | * |
danodonovan | 26:12d0204be712 | 35 | *****************************************************************************/ |
danodonovan | 26:12d0204be712 | 36 | |
Dan O'Donovan |
27:567abf893938 | 37 | /*! |
Dan O'Donovan |
27:567abf893938 | 38 | ****************************************************************************** |
Dan O'Donovan |
27:567abf893938 | 39 | * @file: |
Dan O'Donovan |
27:567abf893938 | 40 | * @brief: ADISENSE OS-dependent wrapper layer for log functions |
Dan O'Donovan |
27:567abf893938 | 41 | *----------------------------------------------------------------------------- |
Dan O'Donovan |
27:567abf893938 | 42 | */ |
Dan O'Donovan |
27:567abf893938 | 43 | |
danodonovan | 26:12d0204be712 | 44 | #include <mbed.h> |
danodonovan | 26:12d0204be712 | 45 | #include "inc/adi_sense_log.h" |
danodonovan | 26:12d0204be712 | 46 | |
kevin1990 | 29:57edca10d78c | 47 | static Serial *gpUartDevice; |
danodonovan | 26:12d0204be712 | 48 | |
kevin1990 | 29:57edca10d78c | 49 | static ADI_SENSE_LOG_LEVEL gLogLevel = ADI_SENSE_LOG_LEVEL_DEBUG; |
danodonovan | 26:12d0204be712 | 50 | |
danodonovan | 26:12d0204be712 | 51 | #ifdef __cplusplus |
danodonovan | 26:12d0204be712 | 52 | extern "C" { |
danodonovan | 26:12d0204be712 | 53 | #endif |
danodonovan | 26:12d0204be712 | 54 | |
danodonovan | 26:12d0204be712 | 55 | /* |
danodonovan | 26:12d0204be712 | 56 | * Open the Log interface and allocate resources |
danodonovan | 26:12d0204be712 | 57 | */ |
kevin1990 | 29:57edca10d78c | 58 | ADI_SENSE_RESULT adi_sense_LogOpen( |
kevin1990 | 29:57edca10d78c | 59 | ADI_SENSE_PLATFORM_LOG_CONFIG *pConfig) |
danodonovan | 26:12d0204be712 | 60 | { |
kevin1990 | 29:57edca10d78c | 61 | if (pConfig->disableLogs) |
kevin1990 | 29:57edca10d78c | 62 | return ADI_SENSE_SUCCESS; |
kevin1990 | 29:57edca10d78c | 63 | |
kevin1990 | 29:57edca10d78c | 64 | gpUartDevice = new Serial((PinName)pConfig->txPin, |
kevin1990 | 29:57edca10d78c | 65 | (PinName)pConfig->rxPin, |
kevin1990 | 29:57edca10d78c | 66 | pConfig->baudRate); |
danodonovan | 26:12d0204be712 | 67 | if (!gpUartDevice) |
danodonovan | 26:12d0204be712 | 68 | { |
danodonovan | 26:12d0204be712 | 69 | ADI_SENSE_LOG_ERROR("Failed to allocate memory for Log UART context"); |
danodonovan | 26:12d0204be712 | 70 | return ADI_SENSE_NO_MEM; |
danodonovan | 26:12d0204be712 | 71 | } |
danodonovan | 26:12d0204be712 | 72 | |
danodonovan | 26:12d0204be712 | 73 | return ADI_SENSE_SUCCESS; |
danodonovan | 26:12d0204be712 | 74 | } |
danodonovan | 26:12d0204be712 | 75 | |
danodonovan | 26:12d0204be712 | 76 | /* |
danodonovan | 26:12d0204be712 | 77 | * Close the Log interface and free resources |
danodonovan | 26:12d0204be712 | 78 | */ |
danodonovan | 26:12d0204be712 | 79 | void adi_sense_LogClose(void) |
danodonovan | 26:12d0204be712 | 80 | { |
danodonovan | 26:12d0204be712 | 81 | if (gpUartDevice) |
danodonovan | 26:12d0204be712 | 82 | { |
danodonovan | 26:12d0204be712 | 83 | delete gpUartDevice; |
danodonovan | 26:12d0204be712 | 84 | gpUartDevice = 0; |
danodonovan | 26:12d0204be712 | 85 | } |
danodonovan | 26:12d0204be712 | 86 | } |
danodonovan | 26:12d0204be712 | 87 | |
danodonovan | 26:12d0204be712 | 88 | /* |
kevin1990 | 29:57edca10d78c | 89 | * Set the log level for uart communication |
kevin1990 | 29:57edca10d78c | 90 | */ |
kevin1990 | 29:57edca10d78c | 91 | void adi_sense_LogLevel(ADI_SENSE_LOG_LEVEL maxLevel) |
kevin1990 | 29:57edca10d78c | 92 | { |
kevin1990 | 29:57edca10d78c | 93 | gLogLevel = maxLevel; |
kevin1990 | 29:57edca10d78c | 94 | } |
kevin1990 | 29:57edca10d78c | 95 | |
kevin1990 | 29:57edca10d78c | 96 | /* |
danodonovan | 26:12d0204be712 | 97 | * Print a log message to the platform log interface |
danodonovan | 26:12d0204be712 | 98 | */ |
danodonovan | 26:12d0204be712 | 99 | void adi_sense_Log(ADI_SENSE_LOG_LEVEL level, const char* format, ...) |
danodonovan | 26:12d0204be712 | 100 | { |
danodonovan | 26:12d0204be712 | 101 | char buffer[256]; |
danodonovan | 26:12d0204be712 | 102 | va_list va_args; |
danodonovan | 26:12d0204be712 | 103 | |
danodonovan | 26:12d0204be712 | 104 | if (!gpUartDevice) |
danodonovan | 26:12d0204be712 | 105 | return; |
danodonovan | 26:12d0204be712 | 106 | |
kevin1990 | 29:57edca10d78c | 107 | if (level > gLogLevel) |
kevin1990 | 29:57edca10d78c | 108 | return; |
kevin1990 | 29:57edca10d78c | 109 | |
danodonovan | 26:12d0204be712 | 110 | va_start(va_args, format); |
danodonovan | 26:12d0204be712 | 111 | vsnprintf(buffer, sizeof(buffer), format, va_args); |
danodonovan | 26:12d0204be712 | 112 | va_end(va_args); |
danodonovan | 26:12d0204be712 | 113 | |
danodonovan | 26:12d0204be712 | 114 | gpUartDevice->printf("%s\r\n", buffer); |
danodonovan | 26:12d0204be712 | 115 | } |
danodonovan | 26:12d0204be712 | 116 | |
danodonovan | 26:12d0204be712 | 117 | #ifdef __cplusplus |
danodonovan | 26:12d0204be712 | 118 | } |
danodonovan | 26:12d0204be712 | 119 | #endif |