trace.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * trace.h - CC31xx/CC32xx Host Driver Implementation
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  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. * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * Neither the name of Texas Instruments Incorporated nor the names of
  20. * its contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #include "simplelink.h"
  37. #ifndef __SIMPLELINK_TRACE_H__
  38. #define __SIMPLELINK_TRACE_H__
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /*****************************************************************************/
  43. /* Macro declarations */
  44. /*****************************************************************************/
  45. #define SL_SYNC_SCAN_THRESHOLD (( _u32 )2000)
  46. #define _SL_ASSERT(expr) { ASSERT(expr); }
  47. #define _SL_ERROR(expr, error) { if(!(expr)){return (error); } }
  48. #define SL_HANDLING_ASSERT 2
  49. #define SL_HANDLING_ERROR 1
  50. #define SL_HANDLING_NONE 0
  51. #define SL_SELF_COND_HANDLING SL_HANDLING_NONE
  52. #define SL_PROTOCOL_HANDLING SL_HANDLING_NONE
  53. #define SL_DRV_RET_CODE_HANDLING SL_HANDLING_NONE
  54. #define SL_NWP_IF_HANDLING SL_HANDLING_NONE
  55. #define SL_OSI_RET_OK_HANDLING SL_HANDLING_NONE
  56. #define SL_MALLOC_OK_HANDLING SL_HANDLING_NONE
  57. #define SL_USER_ARGS_HANDLING SL_HANDLING_NONE
  58. #if (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ASSERT)
  59. #define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)}
  60. #elif (SL_DRV_RET_CODE_HANDLING == SL_HANDLING_ERROR)
  61. #define VERIFY_RET_OK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return _RetVal;}
  62. #else
  63. #define VERIFY_RET_OK(Func) (Func);
  64. #endif
  65. #if (SL_PROTOCOL_HANDLING == SL_HANDLING_ASSERT)
  66. #define VERIFY_PROTOCOL(expr) _SL_ASSERT(expr)
  67. #elif (SL_PROTOCOL_HANDLING == SL_HANDLING_ERROR)
  68. #define VERIFY_PROTOCOL(expr) _SL_ERROR(expr, SL_RET_CODE_PROTOCOL_ERROR)
  69. #else
  70. #define VERIFY_PROTOCOL(expr)
  71. #endif
  72. #if (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ASSERT))
  73. #define VERIFY_SOCKET_CB(expr) _SL_ASSERT(expr)
  74. #elif (defined(PROTECT_SOCKET_ASYNC_RESP) && (SL_SELF_COND_HANDLING == SL_HANDLING_ERROR))
  75. #define VERIFY_SOCKET_CB(expr) _SL_ERROR(expr, SL_RET_CODE_SELF_ERROR)
  76. #else
  77. #define VERIFY_SOCKET_CB(expr)
  78. #endif
  79. #if (SL_NWP_IF_HANDLING == SL_HANDLING_ASSERT)
  80. #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (len); RetSize = sl_IfWrite((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)}
  81. #define NWP_IF_READ_CHECK(fd,pBuff,len) { _i16 RetSize, ExpSize = (len); RetSize = sl_IfRead((fd),(pBuff),ExpSize); _SL_ASSERT(ExpSize == RetSize)}
  82. #elif (SL_NWP_IF_HANDLING == SL_HANDLING_ERROR)
  83. #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfWrite((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);}
  84. #define NWP_IF_READ_CHECK(fd,pBuff,len) { _SL_ERROR((len == sl_IfRead((fd),(pBuff),(len))), SL_RET_CODE_NWP_IF_ERROR);}
  85. #else
  86. #define NWP_IF_WRITE_CHECK(fd,pBuff,len) { sl_IfWrite((fd),(pBuff),(len));}
  87. #define NWP_IF_READ_CHECK(fd,pBuff,len) { sl_IfRead((fd),(pBuff),(len));}
  88. #endif
  89. #if (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ASSERT)
  90. #define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); _SL_ASSERT((_SlReturnVal_t)SL_OS_RET_CODE_OK == _RetVal)}
  91. #elif (SL_OSI_RET_OK_HANDLING == SL_HANDLING_ERROR)
  92. #define OSI_RET_OK_CHECK(Func) {_SlReturnVal_t _RetVal = (Func); if (SL_OS_RET_CODE_OK != _RetVal) return _RetVal;}
  93. #else
  94. #define OSI_RET_OK_CHECK(Func) (Func);
  95. #endif
  96. #if (SL_MALLOC_OK_HANDLING == SL_HANDLING_ASSERT)
  97. #define MALLOC_OK_CHECK(Ptr) _SL_ASSERT(NULL != Ptr)
  98. #elif (SL_MALLOC_OK_HANDLING == SL_HANDLING_ERROR)
  99. #define MALLOC_OK_CHECK(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_MALLOC_ERROR)
  100. #else
  101. #define MALLOC_OK_CHECK(Ptr)
  102. #endif
  103. #ifdef SL_INC_ARG_CHECK
  104. #if (SL_USER_ARGS_HANDLING == SL_HANDLING_ASSERT)
  105. #define ARG_CHECK_PTR(Ptr) _SL_ASSERT(NULL != Ptr)
  106. #elif (SL_USER_ARGS_HANDLING == SL_HANDLING_ERROR)
  107. #define ARG_CHECK_PTR(Ptr) _SL_ERROR((NULL != Ptr), SL_RET_CODE_INVALID_INPUT)
  108. #else
  109. #define ARG_CHECK_PTR(Ptr)
  110. #endif
  111. #else
  112. #define ARG_CHECK_PTR(Ptr)
  113. #endif
  114. #define SL_TRACE0(level,msg_id,str)
  115. #define SL_TRACE1(level,msg_id,str,p1)
  116. #define SL_TRACE2(level,msg_id,str,p1,p2)
  117. #define SL_TRACE3(level,msg_id,str,p1,p2,p3)
  118. #define SL_TRACE4(level,msg_id,str,p1,p2,p3,p4)
  119. #define SL_ERROR_TRACE(msg_id,str)
  120. #define SL_ERROR_TRACE1(msg_id,str,p1)
  121. #define SL_ERROR_TRACE2(msg_id,str,p1,p2)
  122. #define SL_ERROR_TRACE3(msg_id,str,p1,p2,p3)
  123. #define SL_ERROR_TRACE4(msg_id,str,p1,p2,p3,p4)
  124. #define SL_TRACE_FLUSH()
  125. /* #define SL_DBG_CNT_ENABLE */
  126. #ifdef SL_DBG_CNT_ENABLE
  127. #define _SL_DBG_CNT_INC(Cnt) g_DbgCnt. ## Cnt++
  128. #define _SL_DBG_SYNC_LOG(index,value) {if(index < SL_DBG_SYNC_LOG_SIZE){*(_u32 *)&g_DbgCnt.SyncLog[index] = *(_u32 *)(value);}}
  129. #else
  130. #define _SL_DBG_CNT_INC(Cnt)
  131. #define _SL_DBG_SYNC_LOG(index,value)
  132. #endif
  133. #define SL_DBG_LEVEL_1 1
  134. #define SL_DBG_LEVEL_2 2
  135. #define SL_DBG_LEVEL_3 4
  136. #define SL_DBG_LEVEL_MASK (SL_DBG_LEVEL_2|SL_DBG_LEVEL_3)
  137. #define SL_INCLUDE_DBG_FUNC(Name) ((Name ## _DBG_LEVEL) & SL_DBG_LEVEL_MASK)
  138. #define _SlDrvPrintStat_DBG_LEVEL SL_DBG_LEVEL_3
  139. #define _SlDrvOtherFunc_DBG_LEVEL SL_DBG_LEVEL_1
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /*__SIMPLELINK_TRACE_H__*/