⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtel.s51

📁 cc2430应用实例
💻 S51
📖 第 1 页 / 共 5 页
字号:
//  196   MT_TaskID = task_id;
//  197 
//  198   debugThreshold = 0;
//  199   debugCompId = 0;
//  200 
//  201   // Initialize the Serial port
//  202   SPIMgr_Init();
//  203 
//  204 } /* MT_TaskInit() */
//  205 
//  206 #ifdef ZTOOL_PORT
//  207 /*********************************************************************
//  208  * @fn      MT_IndReset()
//  209  *
//  210  * @brief   Sends a ZTOOL "reset response" message.
//  211  *
//  212  * @param   None
//  213  *
//  214  * @return  None
//  215  *
//  216  *********************************************************************/
//  217 void MT_IndReset( void )
//  218 {
//  219 
//  220   byte rsp = 0;  // Reset type==0 indicates Z-Stack reset
//  221 
//  222   // Send out Reset Response message
//  223   MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + sizeof( rsp )),
//  224                                 (SPI_RESPONSE_BIT | SPI_CMD_SYS_RESET),
//  225                                 sizeof( rsp ), &rsp );
//  226 }
//  227 #endif
//  228 
//  229 /*********************************************************************
//  230  * @fn      MT_ProcessEvent
//  231  *
//  232  * @brief
//  233  *
//  234  *   MonitorTest Task Event Processor.  This task is put into the
//  235  *   task table.
//  236  *
//  237  * @param   byte task_id - task ID of the MT Task
//  238  * @param   UINT16 events - event(s) for the MT Task
//  239  *
//  240  * @return  void
//  241  */
//  242 UINT16 MT_ProcessEvent( byte task_id, UINT16 events )
//  243 {
//  244   uint8 *msg_ptr;
//  245 
//  246   // Could be multiple events, so switch won't work
//  247 
//  248   if ( events & SYS_EVENT_MSG )
//  249   {
//  250     while ( (msg_ptr = osal_msg_receive( MT_TaskID )) )
//  251     {
//  252       MT_ProcessCommand( (mtOSALSerialData_t *)msg_ptr );
//  253     }
//  254 
//  255     // Return unproccessed events
//  256     return (events ^ SYS_EVENT_MSG);
//  257   }
//  258 
//  259 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  260   if ( events & MT_ZTOOL_SERIAL_RCV_BUFFER_FULL )
//  261   {
//  262     // Do sometype of error processing
//  263     MT_SendErrorNotification(RECEIVE_BUFFER_FULL);
//  264 
//  265     // Return unproccessed events
//  266     return (events ^ MT_ZTOOL_SERIAL_RCV_BUFFER_FULL);
//  267   }
//  268 #endif
//  269 
//  270   // Discard or make more handlers
//  271   return 0;
//  272 
//  273 } /* MT_ProcessEvent() */
//  274 
//  275 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  276 /*********************************************************************
//  277  * @fn      MT_BuildSPIMsg
//  278  *
//  279  * @brief
//  280  *
//  281  *   Format an SPI message.
//  282  *
//  283  * @param   UINT16 cmd - command id
//  284  * @param   byte *msg - pointer to message buffer
//  285  * @param   byte dataLen - length of data field
//  286  * @param   byte *pData - pointer to data field
//  287  *
//  288  * @return  void
//  289  */
//  290 void MT_BuildSPIMsg( UINT16 cmd, byte *msg, byte dataLen, byte *pData )
//  291 {
//  292   byte *msgPtr;
//  293 
//  294   *msg++ = SOP_VALUE;
//  295 
//  296   msgPtr = msg;
//  297 
//  298   *msg++ = (byte)(HI_UINT16( cmd ));
//  299   *msg++ = (byte)(LO_UINT16( cmd ));
//  300 
//  301   if ( pData )
//  302   {
//  303     *msg++ = dataLen;
//  304 
//  305     msg = osal_memcpy( msg, pData, dataLen );
//  306   }
//  307   else
//  308     *msg++ = 0;
//  309 
//  310   *msg = SPIMgr_CalcFCS( msgPtr, (byte)(3 + dataLen) );
//  311 }
//  312 #endif
//  313 
//  314 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  315 /*********************************************************************
//  316  * @fn      MT_BuildAndSendZToolResponse
//  317  *
//  318  * @brief
//  319  *
//  320  *   Build and send a ZTOOL msg
//  321  *
//  322  * @param   byte err
//  323  *
//  324  * @return  void
//  325  */
//  326 void MT_BuildAndSendZToolResponse( byte msgLen, uint16 cmd,
//  327                                    byte dataLen, byte *pData )
//  328 {
//  329   byte *msg_ptr;
//  330 
//  331   // Get a message buffer to build response message
//  332   msg_ptr = osal_mem_alloc( msgLen );
//  333   if ( msg_ptr )
//  334   {
//  335 #ifdef SPI_MGR_DEFAULT_PORT
//  336     MT_BuildSPIMsg( cmd, msg_ptr, dataLen, pData );
//  337     HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msg_ptr, msgLen );
//  338 #endif
//  339     osal_mem_free( msg_ptr );
//  340   }
//  341 }
//  342 #endif
//  343 
//  344 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  345 /*********************************************************************
//  346  * @fn      MT_BuildAndSendZToolCB
//  347  *
//  348  * @brief
//  349  *
//  350  *   Build and send a ZTOOL Callback msg
//  351  *
//  352  * @param   len - length of data portion of the message
//  353  *
//  354  * @return  void
//  355  */
//  356 void MT_BuildAndSendZToolCB( uint16 callbackID, byte len, byte *pData )
//  357 {
//  358   byte msgLen;
//  359   mtOSALSerialData_t *msgPtr;
//  360   byte *msg;
//  361 
//  362   msgLen = sizeof ( mtOSALSerialData_t ) + SPI_0DATA_MSG_LEN + len;
//  363 
//  364   msgPtr = (mtOSALSerialData_t *)osal_msg_allocate( msgLen );
//  365   if ( msgPtr )
//  366   {
//  367     msgPtr->hdr.event = CB_FUNC;
//  368     msgPtr->msg = (uint8 *)(msgPtr+1);
//  369     msg = msgPtr->msg;
//  370 
//  371     //First byte is used as the event type for MT
//  372     *msg++ = SOP_VALUE;
//  373     *msg++ = HI_UINT16( callbackID );
//  374     *msg++ = LO_UINT16( callbackID );
//  375     *msg++ = len;
//  376 
//  377     //Fill up the data bytes
//  378     osal_memcpy( msg, pData, len );
//  379 
//  380     osal_msg_send( MT_TaskID, (uint8 *)msgPtr );
//  381   }
//  382 }
//  383 #endif
//  384 
//  385 /*********************************************************************
//  386  * @fn      MT_ProcessCommand
//  387  *
//  388  * @brief
//  389  *
//  390  *   Process Event Messages.
//  391  *
//  392  * @param   byte *msg - pointer to event message
//  393  *
//  394  * @return
//  395  */
//  396 void MT_ProcessCommand( mtOSALSerialData_t *msg )
//  397 {
//  398   byte deallocate;
//  399 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  400   byte *msg_ptr;
//  401   byte len;
//  402 
//  403   // A little setup for AF, CB_FUNC and MT_SYS_APP_RSP_MSG
//  404   msg_ptr = msg->msg;
//  405 #endif // ZTOOL
//  406 
//  407   deallocate = true;
//  408 
//  409   // Use the first byte of the message as the command ID
//  410   switch ( msg->hdr.event )
//  411   {
//  412 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  413     case CMD_SERIAL_MSG:
//  414       MT_ProcessSerialCommand( msg->msg );
//  415       break;
//  416 
//  417     case CMD_DEBUG_MSG:
//  418       MT_ProcessDebugMsg( (mtDebugMsg_t *)msg );
//  419       break;
//  420 
//  421     case CMD_DEBUG_STR:
//  422       MT_ProcessDebugStr( (mtDebugStr_t *)msg );
//  423       break;
//  424 
//  425     case CB_FUNC:
//  426       /*
//  427         Build SPI message here instead of redundantly calling MT_BuildSPIMsg
//  428         because we have copied data already in the allocated message
//  429       */
//  430 
//  431       /* msg_ptr is the beginning of the intended SPI message */
//  432       len = SPI_0DATA_MSG_LEN + msg_ptr[DATALEN_FIELD];
//  433 
//  434       /*
//  435         FCS goes to the last byte in the message and is calculated over all
//  436         the bytes except FCS and SOP
//  437       */
//  438       msg_ptr[len-1] = SPIMgr_CalcFCS( msg_ptr + 1 , (byte)(len-2) );
//  439 
//  440 #ifdef SPI_MGR_DEFAULT_PORT
//  441       HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msg_ptr, len );
//  442 #endif
//  443       break;
//  444 
//  445 #if !defined ( NONWK )
//  446     case MT_SYS_APP_RSP_MSG:
//  447       len = SPI_0DATA_MSG_LEN + msg_ptr[DATALEN_FIELD];
//  448       MTProcessAppRspMsg( msg_ptr, len );
//  449       break;
//  450 #endif  // NONWK
//  451 #endif  // ZTOOL
//  452 
//  453     default:
//  454       break;
//  455   }
//  456 
//  457   if ( deallocate )
//  458   {
//  459     osal_msg_deallocate( (uint8 *)msg );
//  460   }
//  461 }
//  462 
//  463 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  464 /*********************************************************************
//  465  * @fn      MT_ProcessDebugMsg
//  466  *
//  467  * @brief
//  468  *
//  469  *   Build and send a debug message.
//  470  *
//  471  * @param   byte *data - pointer to the data portion of the debug message
//  472  *
//  473  * @return  void
//  474  */
//  475 void MT_ProcessDebugMsg( mtDebugMsg_t *msg )
//  476 {
//  477   byte *msg_ptr;
//  478   byte dataLen;
//  479   uint8 buf[11];
//  480   uint8 *pBuf;
//  481 
//  482   // Calculate the data length based
//  483   dataLen = 5 + (msg->numParams * sizeof ( uint16 ));
//  484 
//  485   // Get a message buffer to build the debug message
//  486   msg_ptr = osal_msg_allocate( (byte)(SPI_0DATA_MSG_LEN + dataLen + 1) );
//  487   if ( msg_ptr )
//  488   {
//  489     // Build the message
//  490     pBuf = buf;
//  491     *pBuf++ = msg->compID;
//  492     *pBuf++ = msg->severity;
//  493     *pBuf++ = msg->numParams;
//  494 
//  495     if ( msg->numParams >= 1 )
//  496     {
//  497       *pBuf++ = HI_UINT16( msg->param1 );
//  498       *pBuf++ = LO_UINT16( msg->param1 );
//  499     }
//  500 
//  501     if ( msg->numParams >= 2 )
//  502     {
//  503       *pBuf++ = HI_UINT16( msg->param2 );
//  504       *pBuf++ = LO_UINT16( msg->param2 );
//  505     }
//  506 
//  507     if ( msg->numParams == 3 )
//  508     {
//  509       *pBuf++ = HI_UINT16( msg->param3 );
//  510       *pBuf++ = LO_UINT16( msg->param3 );
//  511     }
//  512 
//  513     *pBuf++ = HI_UINT16( msg->timestamp );
//  514     *pBuf++ = LO_UINT16( msg->timestamp );
//  515 
//  516 #ifdef SPI_MGR_DEFAULT_PORT
//  517     MT_BuildSPIMsg( SPI_CMD_DEBUG_MSG, &msg_ptr[1], dataLen, buf );
//  518     HalUARTWrite ( SPI_MGR_DEFAULT_PORT, &msg_ptr[1], SPI_0DATA_MSG_LEN + dataLen );
//  519 #endif
//  520     osal_msg_deallocate( msg_ptr );
//  521   }
//  522 }
//  523 #endif // ZTOOL
//  524 
//  525 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
//  526 /*********************************************************************
//  527  * @fn      MT_ProcessDebugStr
//  528  *
//  529  * @brief
//  530  *
//  531  *   Build and send a debug string.
//  532  *
//  533  * @param   byte *dstr - pointer to the data portion of the debug message
//  534  *
//  535  * @return  void
//  536  */
//  537 void MT_ProcessDebugStr( mtDebugStr_t *dstr )
//  538 {
//  539   byte *msg_ptr;
//  540 
//  541   // Get a message buffer to build the debug message

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -