DebugMacros.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Copyright (c) 2011-2022 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef DebugMacros_h
  26. #define DebugMacros_h
  27. #include "SysCall.h"
  28. // 0 - disable, 1 - fail, halt 2 - fail, halt, warn
  29. #define USE_DBG_MACROS 0
  30. #if USE_DBG_MACROS
  31. #include "Arduino.h"
  32. #ifndef DBG_FILE
  33. #error DBG_FILE not defined
  34. #endif // DBG_FILE
  35. __attribute__((unused)) static void dbgFail(uint16_t line) {
  36. Serial.print(F("DBG_FAIL: "));
  37. Serial.print(F(DBG_FILE));
  38. Serial.write('.');
  39. Serial.println(line);
  40. }
  41. __attribute__((unused)) static void dbgHalt(uint16_t line) {
  42. Serial.print(F("DBG_HALT: "));
  43. Serial.print(F(DBG_FILE));
  44. Serial.write('.');
  45. Serial.println(line);
  46. while (true) {}
  47. }
  48. #define DBG_FAIL_MACRO dbgFail(__LINE__)
  49. #define DBG_HALT_MACRO dbgHalt(__LINE__)
  50. #define DBG_HALT_IF(b) if (b) {dbgHalt(__LINE__);}
  51. #else // USE_DBG_MACROS
  52. #define DBG_FAIL_MACRO
  53. #define DBG_HALT_MACRO
  54. #define DBG_HALT_IF(b)
  55. #endif // USE_DBG_MACROS
  56. #if USE_DBG_MACROS > 1
  57. __attribute__((unused)) static void dbgWarn(uint16_t line) {
  58. Serial.print(F("DBG_WARN: "));
  59. Serial.print(F(DBG_FILE));
  60. Serial.write('.');
  61. Serial.println(line);
  62. }
  63. #define DBG_WARN_MACRO dbgWarn(__LINE__)
  64. #define DBG_WARN_IF(b) if (b) {dbgWarn(__LINE__);}
  65. #else // USE_DBG_MACROS > 1
  66. #define DBG_WARN_MACRO
  67. #define DBG_WARN_IF(b)
  68. #endif // USE_DBG_MACROS > 1
  69. #endif // DebugMacros_h