nrfx_log.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2018 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef NRFX_LOG_H
  27. #define NRFX_LOG_H
  28. #include <stdio.h>
  29. #include "mphalport.h"
  30. #include "nrfx_config.h"
  31. #define LOG_TEST_UART 1
  32. #define TEST_MODULE_IMPL(x, y) LOG_TEST_ ## x == LOG_TEST_ ## y
  33. #define TEST_MODULE(x, y) TEST_MODULE_IMPL(x, y)
  34. #if (!defined(NRFX_LOG_ENABLED) || (NRFX_LOG_ENABLED == 0)) || \
  35. (TEST_MODULE(NRFX_LOG_MODULE, UART) && defined(NRFX_LOG_UART_DISABLED) && NRFX_LOG_UART_DISABLED)
  36. #define NRFX_LOG_DEBUG(fmt, ...)
  37. #define NRFX_LOG_ERROR(fmt, ...)
  38. #define NRFX_LOG_WARNING(fmt, ...)
  39. #define NRFX_LOG_INFO(fmt, ...)
  40. #define NRFX_LOG_HEXDUMP_ERROR(p_memory, length)
  41. #define NRFX_LOG_HEXDUMP_WARNING(p_memory, length)
  42. #define NRFX_LOG_HEXDUMP_INFO(p_memory, length)
  43. #define NRFX_LOG_HEXDUMP_DEBUG(p_memory, length)
  44. #define NRFX_LOG_ERROR_STRING_GET(error_code) ""
  45. #else
  46. #define VALUE_TO_STR(x) #x
  47. #define VALUE(x) VALUE_TO_STR(x)
  48. #define LOG_PRINTF(fmt, ...) \
  49. do { \
  50. printf("%s: ", VALUE(NRFX_LOG_MODULE)); \
  51. printf(fmt, ##__VA_ARGS__); \
  52. printf("\n"); \
  53. } while (0)
  54. #define NRFX_LOG_DEBUG LOG_PRINTF
  55. #define NRFX_LOG_ERROR LOG_PRINTF
  56. #define NRFX_LOG_WARNING LOG_PRINTF
  57. #define NRFX_LOG_INFO LOG_PRINTF
  58. #define NRFX_LOG_HEXDUMP_ERROR(p_memory, length)
  59. #define NRFX_LOG_HEXDUMP_WARNING(p_memory, length)
  60. #define NRFX_LOG_HEXDUMP_INFO(p_memory, length)
  61. #define NRFX_LOG_HEXDUMP_DEBUG(p_memory, length)
  62. #define NRFX_LOG_ERROR_STRING_GET(error_code) \
  63. nrfx_error_code_lookup(error_code)
  64. #endif // NRFX_LOG_ENABLED
  65. #endif // NRFX_LOG_H