MT_DEBUG.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /***************************************************************************************************
  2. Filename: MT.c
  3. Revised: $Date: 2011-06-07 14:34:55 -0700 (Tue, 07 Jun 2011) $
  4. Revision: $Revision: 26241 $
  5. Description:
  6. Copyright 2007-2011 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. #include "mac_main.h"
  41. #include "mac_data.h"
  42. #include "mac_rx.h"
  43. #include "mac_tx.h"
  44. #include "nwk_globals.h"
  45. /***************************************************************************************************
  46. * LOCAL FUNCTIONs
  47. ***************************************************************************************************/
  48. #if defined (MT_DEBUG_FUNC)
  49. static void MT_DebugSetThreshold(uint8 *pBuf);
  50. static void MT_DebugMacDataDump(void);
  51. #endif
  52. #if defined (MT_DEBUG_FUNC)
  53. /***************************************************************************************************
  54. * @fn MT_DebugProcessing
  55. *
  56. * @brief Process all the DEBUG commands that are issued by test tool
  57. *
  58. * @param pBuf - pointer to received buffer
  59. *
  60. * @return status
  61. ***************************************************************************************************/
  62. uint8 MT_DebugCommandProcessing(uint8 *pBuf)
  63. {
  64. uint8 status = MT_RPC_SUCCESS;
  65. switch (pBuf[MT_RPC_POS_CMD1])
  66. {
  67. case MT_DEBUG_SET_THRESHOLD:
  68. MT_DebugSetThreshold(pBuf);
  69. break;
  70. case MT_DEBUG_MAC_DATA_DUMP:
  71. MT_DebugMacDataDump();
  72. break;
  73. default:
  74. status = MT_RPC_ERR_COMMAND_ID;
  75. break;
  76. }
  77. return status;
  78. }
  79. /***************************************************************************************************
  80. * @fn MT_DebugSetThreshold
  81. *
  82. * @brief Process Debug Set Threshold
  83. *
  84. * @param pBuf - pointer to received buffer
  85. *
  86. * @return void
  87. ***************************************************************************************************/
  88. static void MT_DebugSetThreshold(uint8 *pBuf)
  89. {
  90. uint8 retValue = ZSuccess;
  91. uint8 cmdId;
  92. /* parse header */
  93. cmdId = pBuf[MT_RPC_POS_CMD1];
  94. pBuf += MT_RPC_FRAME_HDR_SZ;
  95. /* Populate info */
  96. debugCompId = *pBuf++;
  97. debugThreshold = *pBuf++;
  98. /* Build and send back the response */
  99. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_DBG), cmdId, 1, &retValue);
  100. }
  101. /***************************************************************************************************
  102. * @fn MT_DebugMacDataDump
  103. *
  104. * @brief Process the debug MAC Data Dump request.
  105. *
  106. * @param pBuf - pointer to received buffer
  107. *
  108. * @return void
  109. ***************************************************************************************************/
  110. static void MT_DebugMacDataDump(void)
  111. {
  112. uint8 buf[sizeof(mtDebugMacDataDump_t)];
  113. uint8 *pBuf = buf;
  114. #ifdef PACKET_FILTER_STATS
  115. *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 0);
  116. *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 1);
  117. *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 2);
  118. *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 3);
  119. *pBuf++ = BREAK_UINT32(rxCrcFailure, 0);
  120. *pBuf++ = BREAK_UINT32(rxCrcFailure, 1);
  121. *pBuf++ = BREAK_UINT32(rxCrcFailure, 2);
  122. *pBuf++ = BREAK_UINT32(rxCrcFailure, 3);
  123. *pBuf++ = BREAK_UINT32(rxCrcSuccess, 0);
  124. *pBuf++ = BREAK_UINT32(rxCrcSuccess, 1);
  125. *pBuf++ = BREAK_UINT32(rxCrcSuccess, 2);
  126. *pBuf++ = BREAK_UINT32(rxCrcSuccess, 3);
  127. #endif
  128. #if defined HAL_MCU_CC2530
  129. *pBuf++ = FSMSTAT0;
  130. *pBuf++ = FSMSTAT1;
  131. #else
  132. *pBuf++ = macSpiReadReg(FSMSTAT0);
  133. *pBuf++ = macSpiReadReg(FSMSTAT1);
  134. #endif
  135. *pBuf++ = macData.rxCount;
  136. *pBuf++ = macData.directCount;
  137. *pBuf++ = macMain.state;
  138. *pBuf++ = macRxActive;
  139. *pBuf = macTxActive;
  140. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_DBG),
  141. MT_DEBUG_MAC_DATA_DUMP, sizeof(buf), buf);
  142. }
  143. #endif
  144. /***************************************************************************************************
  145. * @fn MT_ProcessDebugMsg
  146. *
  147. * @brief Build and send a debug message.
  148. *
  149. * @param byte *data - pointer to the data portion of the debug message
  150. *
  151. * @return void
  152. ***************************************************************************************************/
  153. void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
  154. {
  155. byte *msg_ptr;
  156. byte dataLen;
  157. uint8 buf[11];
  158. uint8 *pBuf;
  159. /* Calculate the data length based */
  160. dataLen = 5 + (msg->numParams * sizeof ( uint16 ));
  161. /* Get a message buffer to build the debug message */
  162. msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
  163. if ( msg_ptr )
  164. {
  165. /* Build the message */
  166. pBuf = buf;
  167. *pBuf++ = msg->compID;
  168. *pBuf++ = msg->severity;
  169. *pBuf++ = msg->numParams;
  170. if ( msg->numParams >= 1 )
  171. {
  172. *pBuf++ = LO_UINT16( msg->param1 );
  173. *pBuf++ = HI_UINT16( msg->param1 );
  174. }
  175. if ( msg->numParams >= 2 )
  176. {
  177. *pBuf++ = LO_UINT16( msg->param2 );
  178. *pBuf++ = HI_UINT16( msg->param2 );
  179. }
  180. if ( msg->numParams == 3 )
  181. {
  182. *pBuf++ = LO_UINT16( msg->param3 );
  183. *pBuf++ = HI_UINT16( msg->param3 );
  184. }
  185. *pBuf++ = LO_UINT16( msg->timestamp );
  186. *pBuf++ = HI_UINT16( msg->timestamp );
  187. #ifdef MT_UART_DEFAULT_PORT
  188. /* Debug message is set to AREQ CMD 0x80 for now */
  189. /* Build and send back the response */
  190. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), 0x80, dataLen, buf);
  191. #endif
  192. osal_msg_deallocate( msg_ptr );
  193. }
  194. }
  195. /***************************************************************************************************
  196. * @fn MT_ProcessDebugStr
  197. *
  198. * @brief Build and send a debug string.
  199. *
  200. * @param byte *dstr - pointer to the data portion of the debug message
  201. *
  202. * @return void
  203. ***************************************************************************************************/
  204. void MT_ProcessDebugStr(mtDebugStr_t *dstr)
  205. {
  206. byte *msg_ptr;
  207. /* Get a message buffer to build the debug message */
  208. msg_ptr = osal_mem_alloc( (byte)(SPI_0DATA_MSG_LEN + dstr->strLen) );
  209. if ( msg_ptr )
  210. {
  211. #ifdef MT_UART_DEFAULT_PORT
  212. /* Debug message is set to AREQ CMD 0x80 for now */
  213. /* Build and send back the response */
  214. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), MT_DEBUG_MSG, dstr->strLen, dstr->pString);
  215. #endif
  216. osal_mem_free( msg_ptr );
  217. }
  218. }
  219. /**************************************************************************************************
  220. */