usbhost_trace.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /****************************************************************************
  2. * include/nuttx/usb/usbhost_trace.h
  3. *
  4. * Copyright (C) 2013 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_USB_USBHOST_TRACE_H
  36. #define __INCLUDE_NUTTX_USB_USBHOST_TRACE_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. /****************************************************************************
  42. * Pre-processor definitions
  43. ****************************************************************************/
  44. /* Configuration ************************************************************/
  45. /* Debug/Trace-related definitions */
  46. #ifndef CONFIG_DEBUG_FEATURES
  47. # undef CONFIG_DEBUG_USB
  48. # undef CONFIG_DEBUG_INFO
  49. #endif
  50. #ifndef CONFIG_USBHOST_TRACE
  51. # undef CONFIG_USBHOST_TRACE_VERBOSE
  52. #endif
  53. /* Trace support is needed if either USB host tracing or USB debug output is enabled */
  54. #if defined(CONFIG_USBHOST_TRACE) || defined(CONFIG_DEBUG_USB)
  55. # define HAVE_USBHOST_TRACE 1
  56. # if defined(CONFIG_USBHOST_TRACE_VERBOSE) || defined(CONFIG_DEBUG_USB_INFO)
  57. # define HAVE_USBHOST_TRACE_VERBOSE 1
  58. # endif
  59. #endif
  60. /* Event encoding/decoding macros *******************************************/
  61. #define TRACE_ENCODE1(id,u23) (((uint32_t)(id) & 0x1ff) << 23 | \
  62. ((uint32_t)(u23) & 0x007fffff))
  63. #define TRACE_ENCODE2(id,u7,u16) (((uint32_t)(id) & 0x1ff) << 23 | \
  64. ((uint32_t)(u7) & 0x7f) << 16 | \
  65. ((u16) & 0x0000ffff))
  66. #define TRACE_DECODE_NDX(ev) (((ev) >> 23) & 0x1ff)
  67. #define TRACE_DECODE_U7(ev) (((ev) >> 16) & 0x7f)
  68. #define TRACE_DECODE_U16(ev) ((ev) & 0x0000ffff)
  69. #define TRACE_DECODE_U23(ev) ((ev) & 0x007fffff)
  70. /****************************************************************************
  71. * Public Types
  72. ****************************************************************************/
  73. /* Enumeration callback function signature */
  74. typedef CODE int (*usbhost_trcallback_t)(FAR uint32_t trace, FAR void *arg);
  75. /****************************************************************************
  76. * Public Data
  77. ****************************************************************************/
  78. #undef EXTERN
  79. #if defined(__cplusplus)
  80. # define EXTERN extern "C"
  81. extern "C"
  82. {
  83. #else
  84. # define EXTERN extern
  85. #endif
  86. /****************************************************************************
  87. * Public Functions
  88. ****************************************************************************/
  89. /****************************************************************************
  90. * Name: usbhost_trace and usbhost_trace2
  91. *
  92. * Description:
  93. * Record a USB event (tracing or USB debug must be enabled)
  94. *
  95. * Assumptions:
  96. * May be called from an interrupt handler
  97. *
  98. ****************************************************************************/
  99. #ifndef CONFIG_DEBUG_FEATURES
  100. # undef CONFIG_DEBUG_INFO
  101. # undef CONFIG_DEBUG_USB
  102. #endif
  103. #ifdef HAVE_USBHOST_TRACE
  104. void usbhost_trace1(uint16_t id, uint32_t u23);
  105. void usbhost_trace2(uint16_t id, uint8_t u7, uint16_t u16);
  106. #ifdef HAVE_USBHOST_TRACE_VERBOSE
  107. # define usbhost_vtrace1(id, u23) usbhost_trace1(id, u23)
  108. # define usbhost_vtrace2(id, u7, u16) usbhost_trace2(id, u7, u16)
  109. #else
  110. # define usbhost_vtrace1(id, u23)
  111. # define usbhost_vtrace2(id, u7, u16)
  112. #endif
  113. #else
  114. # define usbhost_trace1(id, u23)
  115. # define usbhost_trace2(id, u7, u16)
  116. # define usbhost_vtrace1(id, u23)
  117. # define usbhost_vtrace2(id, u7, u16)
  118. #endif
  119. /****************************************************************************
  120. * Name: usbhost_trenumerate
  121. *
  122. * Description:
  123. * Enumerate all buffer trace data (will temporarily disable tracing)
  124. *
  125. * Assumptions:
  126. * NEVER called from an interrupt handler
  127. *
  128. ****************************************************************************/
  129. #ifdef CONFIG_USBHOST_TRACE
  130. int usbhost_trenumerate(usbhost_trcallback_t callback, FAR void *arg);
  131. #else
  132. # define usbhost_trenumerate(callback,arg)
  133. #endif
  134. /****************************************************************************
  135. * Name: usbhost_trdump
  136. *
  137. * Description:
  138. * Used usbhost_trenumerate to dump all buffer trace data to syslog().
  139. *
  140. * Assumptions:
  141. * NEVER called from an interrupt handler
  142. *
  143. ****************************************************************************/
  144. #ifdef CONFIG_USBHOST_TRACE
  145. int usbhost_trdump(void);
  146. #else
  147. # define usbhost_trdump(void)
  148. #endif
  149. /****************************************************************************
  150. * Name: usbhost_trformat1 and usbhost_trformat2
  151. *
  152. * Description:
  153. * This interface must be provided by platform specific logic that knows
  154. * the HCDs encoding of USB trace data.
  155. *
  156. * Given an 9-bit index, return a format string suitable for use with, say,
  157. * printf. The returned format is expected to handle two unsigned integer
  158. * values.
  159. *
  160. ****************************************************************************/
  161. #ifdef HAVE_USBHOST_TRACE
  162. FAR const char *usbhost_trformat1(uint16_t id);
  163. FAR const char *usbhost_trformat2(uint16_t id);
  164. #endif
  165. #undef EXTERN
  166. #if defined(__cplusplus)
  167. }
  168. #endif
  169. #endif /* __INCLUDE_NUTTX_USB_USBHOST_TRACE_H */