debug.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*****************************************************************************\
  2. * EFSL - Embedded Filesystems Library *
  3. * ----------------------------------- *
  4. * *
  5. * Filename : debug.c *
  6. * Release : 0.3 - devel *
  7. * Description : These functions are used for debugging output on different *
  8. * environments *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  11. * modify it under the terms of the GNU General Public License *
  12. * as published by the Free Software Foundation; version 2 *
  13. * of the License. *
  14. * *
  15. * This program is distributed in the hope that it will be useful, *
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  18. * GNU General Public License for more details. *
  19. * *
  20. * As a special exception, if other files instantiate templates or *
  21. * use macros or inline functions from this file, or you compile this *
  22. * file and link it with other works to produce a work based on this file, *
  23. * this file does not by itself cause the resulting work to be covered *
  24. * by the GNU General Public License. However the source code for this *
  25. * file must still be made available in accordance with section (3) of *
  26. * the GNU General Public License. *
  27. * *
  28. * This exception does not invalidate any other reasons why a work based *
  29. * on this file might be covered by the GNU General Public License. *
  30. * *
  31. * (c)2006 Lennart Yseboodt *
  32. * (c)2006 Michael De Nil *
  33. \*****************************************************************************/
  34. /* COMMENT REGARDING FUNCTION COMMENTS IN THIS FILE
  35. * Only the linuxfile debug functions are commented since all functions
  36. * perform the same logical task.
  37. */
  38. /*****************************************************************************/
  39. #include "debug.h"
  40. /*****************************************************************************/
  41. /*****************************************************************************/
  42. #ifdef DEBUG
  43. #ifdef HW_ENDPOINT_LINUX_ALL
  44. /*****************************************************************************/
  45. /* ****************************************************************************
  46. * void debug(const eint8 *format, ...)
  47. * Description: This function prints debug output to the screen (target dependant)
  48. * and if DO_FUNC_DEBUG is defined also to a localfile.
  49. * Return value: void
  50. */
  51. void debug(const eint8 *format, ...)
  52. {
  53. va_list ap;
  54. #ifdef DO_FUNC_DEBUG
  55. euint8 c;
  56. extern FILE* debugfile;
  57. extern volatile euint8 tw;
  58. #endif
  59. va_start(ap, format);
  60. vprintf(format,ap);
  61. #ifdef DO_FUNC_DEBUG
  62. for(c=0;c<tw+1;c++)
  63. {
  64. fprintf(debugfile," ");
  65. }
  66. vfprintf(debugfile,format,ap);
  67. #endif
  68. va_end(ap);
  69. }
  70. /*****************************************************************************/
  71. /* ****************************************************************************
  72. * void debug_funcin(const eint8 *format, ...)
  73. * Description: This function marks the entrance of a function, which
  74. * increments a tabfieldcounter. A tree like structure can the be found in the
  75. * debugging file.
  76. * Return value: void
  77. */
  78. void debug_funcin(const eint8 *format, ...)
  79. {
  80. #ifdef DO_FUNC_DEBUG
  81. eint8 c;
  82. va_list ap;
  83. extern FILE* debugfile;
  84. extern volatile unsigned char tw;
  85. if(debugfile==RT_NULL)return;
  86. for(c=0;c<tw;c++){
  87. fprintf(debugfile," ");
  88. }
  89. va_start(ap, format);
  90. vfprintf(debugfile,format,ap);
  91. va_end(ap);
  92. fprintf(debugfile,"\n");
  93. tw++;
  94. #endif
  95. }
  96. /*****************************************************************************/
  97. /* ****************************************************************************
  98. * void debug_funcout(const eint8 *format, ...)
  99. * Description: Decrements the tabfieldcounter. This function is called everywhere
  100. * a function is left.
  101. * Return value: void
  102. */
  103. void debug_funcout(const eint8 *format, ...)
  104. {
  105. #ifdef DO_FUNC_DEBUG
  106. eint8 c;
  107. va_list ap;
  108. extern FILE* debugfile;
  109. extern volatile euint8 tw;
  110. if(debugfile==RT_NULL)return;
  111. if(tw>0)tw--;
  112. for(c=0;c<tw;c++){
  113. fprintf(debugfile," ");
  114. }
  115. va_start(ap, format);
  116. vfprintf(debugfile,format,ap);
  117. va_end(ap);
  118. fprintf(debugfile,"\n");
  119. #endif
  120. }
  121. /*****************************************************************************/
  122. /* ****************************************************************************
  123. * void debug_init()
  124. * Description: This function optionally opens the debugfile, or does any other
  125. * initialisation to enable debugoutput.
  126. * Return value: void
  127. */
  128. void debug_init()
  129. {
  130. #ifdef DO_FUNC_DEBUG
  131. extern FILE* debugfile;
  132. extern volatile unsigned char tw;
  133. debugfile=RT_NULL;
  134. tw=0;
  135. debugfile=fopen("DBG.OUT","w");
  136. #endif
  137. }
  138. /*****************************************************************************/
  139. /* ****************************************************************************
  140. * void debug_end()
  141. * Description: This function closes the debugfile.
  142. * Return value: void
  143. */
  144. void debug_end()
  145. {
  146. #ifdef DO_FUNC_DEBUG
  147. extern FILE* debugfile;
  148. fflush(debugfile);
  149. fclose(debugfile);
  150. #endif
  151. }
  152. /*****************************************************************************/
  153. /*****************************************************************************/
  154. #endif
  155. #endif
  156. /*****************************************************************************/