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