123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- #include "ZComDef.h"
- #include "MT.h"
- #include "MT_DEBUG.h"
- #include "MT_UART.h"
- #include "mac_main.h"
- #include "mac_data.h"
- #include "mac_rx.h"
- #include "mac_tx.h"
- #include "nwk_globals.h"
- #if defined (MT_DEBUG_FUNC)
- static void MT_DebugSetThreshold(uint8 *pBuf);
- static void MT_DebugMacDataDump(void);
- #endif
- #if defined (MT_DEBUG_FUNC)
- uint8 MT_DebugCommandProcessing(uint8 *pBuf)
- {
- uint8 status = MT_RPC_SUCCESS;
- switch (pBuf[MT_RPC_POS_CMD1])
- {
- case MT_DEBUG_SET_THRESHOLD:
- MT_DebugSetThreshold(pBuf);
- break;
- case MT_DEBUG_MAC_DATA_DUMP:
- MT_DebugMacDataDump();
- break;
- default:
- status = MT_RPC_ERR_COMMAND_ID;
- break;
- }
- return status;
- }
- static void MT_DebugSetThreshold(uint8 *pBuf)
- {
- uint8 retValue = ZSuccess;
- uint8 cmdId;
-
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
-
- debugCompId = *pBuf++;
- debugThreshold = *pBuf++;
-
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_DBG), cmdId, 1, &retValue);
- }
- static void MT_DebugMacDataDump(void)
- {
- uint8 buf[sizeof(mtDebugMacDataDump_t)];
- uint8 *pBuf = buf;
- #ifdef PACKET_FILTER_STATS
- *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 0);
- *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 1);
- *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 2);
- *pBuf++ = BREAK_UINT32(nwkInvalidPackets, 3);
- *pBuf++ = BREAK_UINT32(rxCrcFailure, 0);
- *pBuf++ = BREAK_UINT32(rxCrcFailure, 1);
- *pBuf++ = BREAK_UINT32(rxCrcFailure, 2);
- *pBuf++ = BREAK_UINT32(rxCrcFailure, 3);
- *pBuf++ = BREAK_UINT32(rxCrcSuccess, 0);
- *pBuf++ = BREAK_UINT32(rxCrcSuccess, 1);
- *pBuf++ = BREAK_UINT32(rxCrcSuccess, 2);
- *pBuf++ = BREAK_UINT32(rxCrcSuccess, 3);
- #endif
- #if defined HAL_MCU_CC2530
- *pBuf++ = FSMSTAT0;
- *pBuf++ = FSMSTAT1;
- #else
- *pBuf++ = macSpiReadReg(FSMSTAT0);
- *pBuf++ = macSpiReadReg(FSMSTAT1);
- #endif
- *pBuf++ = macData.rxCount;
- *pBuf++ = macData.directCount;
- *pBuf++ = macMain.state;
- *pBuf++ = macRxActive;
- *pBuf = macTxActive;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_DBG),
- MT_DEBUG_MAC_DATA_DUMP, sizeof(buf), buf);
- }
- #endif
- void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
- {
- byte *msg_ptr;
- byte dataLen;
- uint8 buf[11];
- uint8 *pBuf;
-
- dataLen = 5 + (msg->numParams * sizeof ( uint16 ));
-
- msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
- if ( msg_ptr )
- {
-
- pBuf = buf;
- *pBuf++ = msg->compID;
- *pBuf++ = msg->severity;
- *pBuf++ = msg->numParams;
- if ( msg->numParams >= 1 )
- {
- *pBuf++ = LO_UINT16( msg->param1 );
- *pBuf++ = HI_UINT16( msg->param1 );
- }
- if ( msg->numParams >= 2 )
- {
- *pBuf++ = LO_UINT16( msg->param2 );
- *pBuf++ = HI_UINT16( msg->param2 );
- }
- if ( msg->numParams == 3 )
- {
- *pBuf++ = LO_UINT16( msg->param3 );
- *pBuf++ = HI_UINT16( msg->param3 );
- }
- *pBuf++ = LO_UINT16( msg->timestamp );
- *pBuf++ = HI_UINT16( msg->timestamp );
- #ifdef MT_UART_DEFAULT_PORT
-
-
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), 0x80, dataLen, buf);
- #endif
- osal_msg_deallocate( msg_ptr );
- }
- }
- void MT_ProcessDebugStr(mtDebugStr_t *dstr)
- {
- byte *msg_ptr;
-
- msg_ptr = osal_mem_alloc( (byte)(SPI_0DATA_MSG_LEN + dstr->strLen) );
- if ( msg_ptr )
- {
- #ifdef MT_UART_DEFAULT_PORT
-
-
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_DBG), MT_DEBUG_MSG, dstr->strLen, dstr->pString);
- #endif
- osal_mem_free( msg_ptr );
- }
- }
|