Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_logging.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - logging support
  27. =============================================================================*/
  28. #ifndef VCOS_LOGGING_H
  29. #define VCOS_LOGGING_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #include <stdarg.h>
  34. #include "vcos_types.h"
  35. #include "pthreads/vcos_platform.h"
  36. #include "vcos_logging_control.h"
  37. /**
  38. * \file
  39. *
  40. * Logging support
  41. *
  42. * This provides categorised logging. Clients register
  43. * a category, and then get a number of logging levels for
  44. * that category.
  45. *
  46. * The logging level flag is tested using a flag *before* the
  47. * function call, which makes logging very fast when disabled - there
  48. * is no function call overhead just to find out that this log
  49. * message is disabled.
  50. *
  51. * \section VCOS_LOG_CATEGORY
  52. *
  53. * As a convenience, clients define VCOS_LOG_CATEGORY to point to
  54. * their category; the various vcos_log_xxx() macros then expand to
  55. * use this.
  56. *
  57. * e.g.
  58. *
  59. * #define VCOS_LOG_CATEGORY (&my_category)
  60. *
  61. * #include <vcos.h>
  62. *
  63. * VCOS_LOG_CAT_T my_category;
  64. *
  65. * ....
  66. *
  67. * vcos_log_trace("Stuff happened: %d", n_stuff);
  68. *
  69. */
  70. /** Logging levels */
  71. typedef enum VCOS_LOG_LEVEL_T
  72. {
  73. VCOS_LOG_UNINITIALIZED = 0,
  74. VCOS_LOG_NEVER,
  75. VCOS_LOG_ERROR,
  76. VCOS_LOG_WARN,
  77. VCOS_LOG_INFO,
  78. VCOS_LOG_TRACE,
  79. } VCOS_LOG_LEVEL_T;
  80. /** Initialize a logging category without going through vcos_log_register().
  81. *
  82. * This is useful for the case where there is no obvious point to do the
  83. * registration (no initialization function for the module). However, it
  84. * means that your logging category is not registered, so cannot be easily
  85. * changed at run-time.
  86. */
  87. #define VCOS_LOG_INIT(n,l) { l, n, 0, {0}, 0, 0 }
  88. /** A registered logging category.
  89. */
  90. typedef struct VCOS_LOG_CAT_T
  91. {
  92. VCOS_LOG_LEVEL_T level; /**< Which levels are enabled for this category */
  93. const char *name; /**< Name for this category. */
  94. struct VCOS_LOG_CAT_T *next;
  95. struct {
  96. unsigned int want_prefix:1;
  97. } flags;
  98. unsigned int refcount;
  99. void *platform_data; /**< platform specific data */
  100. } VCOS_LOG_CAT_T;
  101. typedef void (*VCOS_VLOG_IMPL_FUNC_T)(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args);
  102. /** Convert a VCOS_LOG_LEVEL_T into a printable string.
  103. * The platform needs to implement this function.
  104. */
  105. VCOSPRE_ const char * VCOSPOST_ vcos_log_level_to_string( VCOS_LOG_LEVEL_T level );
  106. /** Convert a string into a VCOS_LOG_LEVEL_T
  107. * The platform needs to implement this function.
  108. */
  109. VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_string_to_log_level( const char *str, VCOS_LOG_LEVEL_T *level );
  110. /** Log a message. Basic API. Normal code should not use this.
  111. * The platform needs to implement this function.
  112. */
  113. VCOSPRE_ void VCOSPOST_ vcos_log_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, ...) VCOS_FORMAT_ATTR_(printf, 3, 4);
  114. /** Log a message using a varargs parameter list. Normal code should
  115. * not use this.
  116. */
  117. VCOSPRE_ void VCOSPOST_ vcos_vlog_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args) VCOS_FORMAT_ATTR_(printf, 3, 0);
  118. /** Set the function which does the actual logging output.
  119. * Passing in NULL causes the default logging function to be
  120. * used.
  121. */
  122. VCOSPRE_ void VCOSPOST_ vcos_set_vlog_impl( VCOS_VLOG_IMPL_FUNC_T vlog_impl_func );
  123. /** The default logging function, which is provided by each
  124. * platform.
  125. */
  126. VCOSPRE_ void VCOSPOST_ vcos_vlog_default_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args) VCOS_FORMAT_ATTR_(printf, 3, 0);
  127. /*
  128. * Initialise the logging subsystem. This is called from
  129. * vcos_init() so you don't normally need to call it.
  130. */
  131. VCOSPRE_ void VCOSPOST_ vcos_logging_init(void);
  132. /** Register a logging category.
  133. *
  134. * @param name the name of this category.
  135. * @param category the category to register.
  136. */
  137. VCOSPRE_ void VCOSPOST_ vcos_log_register(const char *name, VCOS_LOG_CAT_T *category);
  138. /** Unregister a logging category.
  139. */
  140. VCOSPRE_ void VCOSPOST_ vcos_log_unregister(VCOS_LOG_CAT_T *category);
  141. /** Return a default logging category, for people too lazy to create their own.
  142. *
  143. * Using the default category will be slow (there's an extra function
  144. * call overhead). Don't do this in normal code.
  145. */
  146. VCOSPRE_ const VCOS_LOG_CAT_T * VCOSPOST_ vcos_log_get_default_category(void);
  147. VCOSPRE_ void VCOSPOST_ vcos_set_log_options(const char *opt);
  148. /** Set the logging level for a category at run time. Without this, the level
  149. * will be that set by vcos_log_register from a platform-specific source.
  150. *
  151. * @param category the category to modify.
  152. * @param level the new logging level for this category.
  153. */
  154. VCOS_STATIC_INLINE void vcos_log_set_level(VCOS_LOG_CAT_T *category, VCOS_LOG_LEVEL_T level)
  155. {
  156. category->level = level;
  157. }
  158. #define vcos_log_dump_mem(cat,label,addr,voidMem,numBytes) do { if (vcos_is_log_enabled(cat,VCOS_LOG_TRACE)) vcos_log_dump_mem_impl(cat,label,addr,voidMem,numBytes); } while (0)
  159. void vcos_log_dump_mem_impl( const VCOS_LOG_CAT_T *cat,
  160. const char *label,
  161. uint32_t addr,
  162. const void *voidMem,
  163. size_t numBytes );
  164. /*
  165. * Platform specific hooks (optional).
  166. */
  167. #ifndef vcos_log_platform_init
  168. #define vcos_log_platform_init() (void)0
  169. #endif
  170. #ifndef vcos_log_platform_register
  171. #define vcos_log_platform_register(category) (void)0
  172. #endif
  173. #ifndef vcos_log_platform_unregister
  174. #define vcos_log_platform_unregister(category) (void)0
  175. #endif
  176. /* VCOS_TRACE() - deprecated macro which just outputs in a debug build and
  177. * is a no-op in a release build.
  178. *
  179. * _VCOS_LOG_X() - internal macro which outputs if the current level for the
  180. * particular category is higher than the supplied message level.
  181. */
  182. #define VCOS_LOG_DFLT_CATEGORY vcos_log_get_default_category()
  183. #define _VCOS_LEVEL(x) (x)
  184. #define vcos_is_log_enabled(cat,_level) (_VCOS_LEVEL((cat)->level) >= _VCOS_LEVEL(_level))
  185. #if defined(_VCOS_METAWARE) || defined(__GNUC__)
  186. # if !defined(AMPUTATE_ALL_VCOS_LOGGING) && (!defined(NDEBUG) || defined(VCOS_ALWAYS_WANT_LOGGING))
  187. # define VCOS_LOGGING_ENABLED
  188. # define _VCOS_LOG_X(cat, _level, fmt...) do { if (vcos_is_log_enabled(cat,_level)) vcos_log_impl(cat,_level,fmt); } while (0)
  189. # define _VCOS_VLOG_X(cat, _level, fmt, ap) do { if (vcos_is_log_enabled(cat,_level)) vcos_vlog_impl(cat,_level,fmt,ap); } while (0)
  190. # else
  191. # define _VCOS_LOG_X(cat, _level, fmt...) (void)0
  192. # define _VCOS_VLOG_X(cat, _level, fmt, ap) (void)0
  193. # endif
  194. # define vcos_log_error(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, __VA_ARGS__)
  195. # define vcos_log_warn(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, __VA_ARGS__)
  196. # define vcos_log_info(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
  197. # define vcos_log_trace(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, __VA_ARGS__)
  198. # define vcos_vlog_error(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, fmt, ap)
  199. # define vcos_vlog_warn(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, fmt, ap)
  200. # define vcos_vlog_info(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, fmt, ap)
  201. # define vcos_vlog_trace(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, fmt, ap)
  202. # define vcos_logc_error(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_ERROR, __VA_ARGS__)
  203. # define vcos_logc_warn(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_WARN, __VA_ARGS__)
  204. # define vcos_logc_info(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_INFO, __VA_ARGS__)
  205. # define vcos_logc_trace(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_TRACE, __VA_ARGS__)
  206. # define vcos_vlogc_error(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_ERROR, fmt, ap)
  207. # define vcos_vlogc_warn(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_WARN, fmt, ap)
  208. # define vcos_vlogc_info(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_INFO, fmt, ap)
  209. # define vcos_vlogc_trace(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_TRACE, fmt, ap)
  210. # define vcos_log(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
  211. # define vcos_vlog(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, ap)
  212. # define VCOS_ALERT(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_ERROR, __VA_ARGS__)
  213. # define VCOS_TRACE(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
  214. /*
  215. * MS Visual Studio - pre 2005 does not grok variadic macros
  216. */
  217. #elif defined(_MSC_VER)
  218. # if _MSC_VER >= 1400
  219. # if !defined(AMPUTATE_ALL_VCOS_LOGGING) && (!defined(NDEBUG) || defined(VCOS_ALWAYS_WANT_LOGGING))
  220. # define VCOS_LOGGING_ENABLED
  221. # define _VCOS_LOG_X(cat, _level, fmt,...) do { if (vcos_is_log_enabled(cat,_level)) vcos_log_impl(cat, _level, fmt, __VA_ARGS__); } while (0)
  222. # else
  223. # define _VCOS_LOG_X(cat, _level, fmt,...) (void)0
  224. # endif
  225. # define vcos_log_error(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
  226. # define vcos_log_warn(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, fmt, __VA_ARGS__)
  227. # define vcos_log_info(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
  228. # define vcos_log_trace(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, fmt, __VA_ARGS__)
  229. # define vcos_logc_error(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
  230. # define vcos_logc_warn(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_WARN, fmt, __VA_ARGS__)
  231. # define vcos_logc_info(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_INFO, fmt, __VA_ARGS__)
  232. # define vcos_logc_trace(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_TRACE, fmt, __VA_ARGS__)
  233. # define vcos_log(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
  234. # define VCOS_ALERT(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
  235. # define VCOS_TRACE(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
  236. # else /* _MSC_VER >= 1400 */
  237. /* do not define these */
  238. # endif /* _MSC_VER >= 1400 */
  239. #endif
  240. #if VCOS_HAVE_CMD
  241. #include "vcos_cmd.h"
  242. /*
  243. * These are the log sub-commands. They're exported here for user-mode apps which
  244. * may want to call these, since the "log" command isn't registered for user-mode
  245. * apps (vcdbg for example, has its own log command).
  246. */
  247. VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_assert_cmd( VCOS_CMD_PARAM_T *param );
  248. VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_set_cmd( VCOS_CMD_PARAM_T *param );
  249. VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_status_cmd( VCOS_CMD_PARAM_T *param );
  250. VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_test_cmd( VCOS_CMD_PARAM_T *param );
  251. #endif
  252. #ifdef __cplusplus
  253. }
  254. #endif
  255. #endif /* VCOS_LOGGING_H */