MT_DEBUG.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /***************************************************************************************************
  2. Filename: MT.c
  3. Revised: $Date: 2008-02-12 16:28:45 -0800 (Tue, 12 Feb 2008) $
  4. Revision: $Revision: 16392 $
  5. Description:
  6. Copyright 2007 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. ***************************************************************************************************/
  33. /***************************************************************************************************
  34. * INCLUDES
  35. ***************************************************************************************************/
  36. #include "ZComDef.h"
  37. #include "MT.h"
  38. #include "MT_DEBUG.h"
  39. #include "MT_UART.h"
  40. /***************************************************************************************************
  41. * LOCAL FUNCTIONs
  42. ***************************************************************************************************/
  43. #if defined (MT_DEBUG_FUNC)
  44. void MT_DebugSetThreshold(uint8 *pBuf);
  45. #endif
  46. #if defined (MT_DEBUG_FUNC)
  47. /***************************************************************************************************
  48. * @fn MT_DebugProcessing
  49. *
  50. * @brief Process all the DEBUG commands that are issued by test tool
  51. *
  52. * @param pBuf - pointer to received buffer
  53. *
  54. * @return status
  55. ***************************************************************************************************/
  56. uint8 MT_DebugCommandProcessing(uint8 *pBuf)
  57. {
  58. uint8 status = MT_RPC_SUCCESS;
  59. switch (pBuf[MT_RPC_POS_CMD1])
  60. {
  61. case MT_DEBUG_SET_THRESHOLD:
  62. MT_DebugSetThreshold(pBuf);
  63. break;
  64. default:
  65. status = MT_RPC_ERR_COMMAND_ID;
  66. break;
  67. }
  68. return status;
  69. }
  70. /***************************************************************************************************
  71. * @fn MT_DebugSetThreshold
  72. *
  73. * @brief Process Debug Set Threshold
  74. *
  75. * @param pBuf - pointer to received buffer
  76. *
  77. * @return void
  78. ***************************************************************************************************/
  79. void MT_DebugSetThreshold(uint8 *pBuf)
  80. {
  81. uint8 retValue = ZSuccess;
  82. uint8 cmdId;
  83. /* parse header */
  84. cmdId = pBuf[MT_RPC_POS_CMD1];
  85. pBuf += MT_RPC_FRAME_HDR_SZ;
  86. /* Populate info */
  87. debugCompId = *pBuf++;
  88. debugThreshold = *pBuf++;
  89. /* Build and send back the response */
  90. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_DBG), cmdId, 1, &retValue);
  91. }
  92. #endif /* MT_DEBUG_FUNC */
  93. /***************************************************************************************************
  94. * @fn MT_ProcessDebugMsg
  95. *
  96. * @brief Build and send a debug message.
  97. *
  98. * @param byte *data - pointer to the data portion of the debug message
  99. *
  100. * @return void
  101. ***************************************************************************************************/
  102. void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
  103. {
  104. byte *msg_ptr;
  105. byte dataLen;
  106. uint8 buf[11];
  107. uint8 *pBuf;
  108. /* Calculate the data length based */
  109. dataLen = 5 + (msg->numParams * sizeof ( uint16 ));
  110. /* Get a message buffer to build the debug message */
  111. msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
  112. if ( msg_ptr )
  113. {
  114. /* Build the message */
  115. pBuf = buf;
  116. *pBuf++ = msg->compID;
  117. *pBuf++ = msg->severity;
  118. *pBuf++ = msg->numParams;
  119. if ( msg->numParams >= 1 )
  120. {
  121. *pBuf++ = LO_UINT16( msg->param1 );
  122. *pBuf++ = HI_UINT16( msg->param1 );
  123. }
  124. if ( msg->numParams >= 2 )
  125. {
  126. *pBuf++ = LO_UINT16( msg->param2 );
  127. *pBuf++ = HI_UINT16( msg->param2 );
  128. }
  129. if ( msg->numParams == 3 )
  130. {
  131. *pBuf++ = LO_UINT16( msg->param3 );
  132. *pBuf++ = HI_UINT16( msg->param3 );
  133. }
  134. *pBuf++ = LO_UINT16( msg->timestamp );
  135. *pBuf++ = HI_UINT16( msg->timestamp );
  136. #ifdef MT_UART_DEFAULT_PORT
  137. /* Debug message is set to AREQ CMD 0x80 for now */
  138. /* Build and send back the response */
  139. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), 0x80, dataLen, buf);
  140. #endif
  141. osal_msg_deallocate( msg_ptr );
  142. }
  143. }
  144. /***************************************************************************************************
  145. * @fn MT_ProcessDebugStr
  146. *
  147. * @brief Build and send a debug string.
  148. *
  149. * @param byte *dstr - pointer to the data portion of the debug message
  150. *
  151. * @return void
  152. ***************************************************************************************************/
  153. void MT_ProcessDebugStr(mtDebugStr_t *dstr)
  154. {
  155. byte *msg_ptr;
  156. /* Get a message buffer to build the debug message */
  157. msg_ptr = osal_mem_alloc( (byte)(SPI_0DATA_MSG_LEN + dstr->strLen) );
  158. if ( msg_ptr )
  159. {
  160. #ifdef MT_UART_DEFAULT_PORT
  161. /* Debug message is set to AREQ CMD 0x80 for now */
  162. /* Build and send back the response */
  163. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), MT_DEBUG_MSG, dstr->strLen, dstr->pString);
  164. #endif
  165. osal_mem_free( msg_ptr );
  166. }
  167. }
  168. /***************************************************************************************************
  169. ***************************************************************************************************/