DebugTrace.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**************************************************************************************************
  2. Filename: DebugTrace.c
  3. Revised: $Date: 2008-01-17 12:22:57 -0800 (Thu, 17 Jan 2008) $
  4. Revision: $Revision: 16223 $
  5. Description: This interface provides quick one-function-call functions to
  6. Monitor and Test reporting mechanisms.
  7. Copyright 2007 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. **************************************************************************************************/
  34. #if defined( MT_TASK ) || defined( APP_DEBUG )
  35. /*********************************************************************
  36. * INCLUDES
  37. */
  38. #include "ZComDef.h"
  39. #include "OSAL.h"
  40. #include "MT.h"
  41. #include "MT_TASK.h"
  42. #include "MT_DEBUG.h"
  43. #include "DebugTrace.h"
  44. #if defined ( APP_DEBUG )
  45. #include "DebugApp.h"
  46. #endif
  47. /*********************************************************************
  48. * MACROS
  49. */
  50. /*********************************************************************
  51. * CONSTANTS
  52. */
  53. /*********************************************************************
  54. * TYPEDEFS
  55. */
  56. /*********************************************************************
  57. * GLOBAL VARIABLES
  58. */
  59. /*********************************************************************
  60. * EXTERNAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * EXTERNAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. /*********************************************************************
  69. * LOCAL FUNCTIONS
  70. */
  71. /*********************************************************************
  72. * @fn debug_msg
  73. *
  74. * @brief
  75. *
  76. * This feature allows modules to display debug information as
  77. * applications execute in real-time. This feature will work similar
  78. * to "printf()" but will output to the serial port for display in
  79. * the Z-Test tool.
  80. *
  81. * This feature will most likely be compiled out in the production code
  82. * to save code space.
  83. *
  84. * @param byte compID - Component ID
  85. * @param byte severity - CRITICAL(0x01), ERROR(0x02), INFORMATION(0x03)
  86. * or TRACE(0x04)
  87. * @param byte numParams - number of parameter fields (param1-3)
  88. * @param UINT16 param1 - user defined data
  89. * @param UINT16 param2 - user defined data
  90. * @param UINT16 param3 - user defined data
  91. *
  92. * @return void
  93. */
  94. void debug_msg( byte compID, byte severity, byte numParams, UINT16 param1,
  95. UINT16 param2, UINT16 param3 )
  96. {
  97. mtDebugMsg_t *mtDebugMsg;
  98. UINT16 timestamp;
  99. if ( debugThreshold == 0 || debugCompId != compID )
  100. return;
  101. // Fill in the timestamp
  102. timestamp = 0;
  103. // Get a message buffer to build the debug message
  104. mtDebugMsg = (mtDebugMsg_t *)osal_msg_allocate( sizeof( mtDebugMsg_t ) );
  105. if ( mtDebugMsg )
  106. {
  107. mtDebugMsg->hdr.event = CMD_DEBUG_MSG;
  108. mtDebugMsg->compID = compID;
  109. mtDebugMsg->severity = severity;
  110. mtDebugMsg->numParams = numParams;
  111. mtDebugMsg->param1 = param1;
  112. mtDebugMsg->param2 = param2;
  113. mtDebugMsg->param3 = param3;
  114. mtDebugMsg->timestamp = timestamp;
  115. osal_msg_send( MT_TaskID, (uint8 *)mtDebugMsg );
  116. }
  117. } /* debug_msg() */
  118. /*********************************************************************
  119. * @fn debug_str
  120. *
  121. * @brief
  122. *
  123. * This feature allows modules to display a debug text string as
  124. * applications execute in real-time. This feature will output to
  125. * the serial port for display in the Z-Test tool.
  126. *
  127. * This feature will most likely be compiled out in the production
  128. * code in order to save code space.
  129. *
  130. * @param byte *str_ptr - pointer to null-terminated string
  131. *
  132. * @return void
  133. */
  134. void debug_str( byte *str_ptr )
  135. {
  136. mtDebugStr_t *msg;
  137. byte mln;
  138. byte strLen;
  139. // Text string length
  140. strLen = (byte)osal_strlen( (void*)str_ptr );
  141. // Debug string message length
  142. mln = sizeof ( mtDebugStr_t ) + strLen;
  143. // Get a message buffer to build the debug message
  144. msg = (mtDebugStr_t *)osal_msg_allocate( mln );
  145. if ( msg )
  146. {
  147. // Message type, length
  148. msg->hdr.event = CMD_DEBUG_STR;
  149. msg->strLen = strLen;
  150. // Append message, no terminator
  151. msg->pString = (uint8 *)(msg+1);
  152. osal_memcpy ( msg->pString, str_ptr, strLen );
  153. osal_msg_send( MT_TaskID, (uint8 *)msg );
  154. }
  155. } // debug_str()
  156. /*********************************************************************
  157. *********************************************************************/
  158. #endif // MT_TASK