1 /* 2 * Copyright (c) 2023 Sebastian Bedin <sebabedin@gmail.com>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * @file : logger.h 33 * @author : Sebastian Bedin <sebabedin@gmail.com> 34 * @version v1.0.0 35 */ 36 37 #ifndef INC_LOGGER_H_ 38 #define INC_LOGGER_H_ 39 40 /********************** CPP guard ********************************************/ 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /********************** inclusions *******************************************/ 46 47 #include <stdio.h> 48 #include <stdint.h> 49 #include <stdbool.h> 50 #include <string.h> 51 52 /********************** macros ***********************************************/ 53 54 #define LOGGER_CONFIG_ENABLE (1) 55 #define LOGGER_CONFIG_MAXLEN (64) 56 #define LOGGER_CONFIG_USE_SEMIHOSTING (1) 57 58 #if 1 == LOGGER_CONFIG_ENABLE 59 #define LOGGER_LOG(...)\ 60 __asm("CPSID i"); /* disable interrupts*/\ 61 {\ 62 logger_msg_len = snprintf(logger_msg, (LOGGER_CONFIG_MAXLEN - 1), __VA_ARGS__);\ 63 logger_log_print_(logger_msg);\ 64 }\ 65 __asm("CPSIE i"); /* enable interrupts*/ 66 #else 67 #define LOGGER_LOG(...) 68 #endif 69 70 #define GET_NAME(var) #var 71 72 /********************** typedef **********************************************/ 73 74 extern char* const logger_msg; 75 extern int logger_msg_len; // only for debug information 76 77 /********************** external functions declaration ***********************/ 78 79 void logger_log_print_(char* const msg); 80 81 /********************** End of CPP guard *************************************/ 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* INC_LOGGER_H_ */ 87 88 /********************** end of file ******************************************/
