/**************************************************************************************************
 * @fn      MT_SysReset
 *
 * @brief   Reset the device.
 * @param   typID: 0=reset, 1=serial bootloader
 *
 * @return  None
 *************************************************************************************************/
void MT_SysReset(uint8 *pBuf)
{
  if (pBuf[MT_RPC_POS_DAT0] == 0)
  {
    SystemReset();
  }
#if !(defined(HAL_BOARD_F2618) || defined(HAL_BOARD_F5438) || defined(HAL_BOARD_LM3S))
  else
  {
    SystemResetSoft();  // Especially useful for CC2531 to not break comm with USB Host.
  }
#endif

}
示例#2
0
/**************************************************************************************************
 * @fn          znpBasicCfg
 *
 * @brief       Process the Conglomerate Basic Configuration command.
 *
 * input parameters
 *
 * @param       pBuf - Pointer to the MT buffer containing the conglomerated configuration.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 */
static void znpBasicCfg(uint8 *pBuf)
{
  uint32 t32 = osal_build_uint32( &pBuf[0], 4 );
  if (MT_PeriodicMsgRate != t32)
  {
    MT_PeriodicMsgRate = t32;
    (void)osal_start_reload_timer(MT_TaskID, MT_PERIODIC_MSG_EVENT, t32);
  }

  t32 = osal_build_uint32( &pBuf[4], 4 );
  if (osal_memcmp(&zgDefaultChannelList, &t32, 4) == FALSE)
  {
    (void)osal_nv_write(ZCD_NV_CHANLIST, 0, 4, &t32);
  }

  uint16 t16 = osal_build_uint16( &pBuf[8] );
  if (osal_memcmp(&zgConfigPANID, &t16, 2) == FALSE)
  {
    (void)osal_nv_write(ZCD_NV_PANID, 0, 2, &t16);
  }

  if (zgDeviceLogicalType != pBuf[10])
  {
    (void)osal_nv_write(ZCD_NV_LOGICAL_TYPE, 0, 1, pBuf+10);
  }

  if (pBuf[11] & MT_ZNP_CMD_DISC_RESET_NWK)
  {
    pBuf[0] = ZCD_STARTOPT_DEFAULT_NETWORK_STATE;
    (void)osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, 1, pBuf);
#if defined CC2531ZNP
    SystemResetSoft();
#else
    SystemReset();
#endif
  }
  else if (pBuf[11] & MT_ZNP_CMD_DISC_ZDO_START)
  {
    if (devState == DEV_HOLD)
    {
      ZDOInitDevice(0);
    }
  }
}
/******************************************************************************
 * @fn          zb_SystemReset
 *
 * @brief       The zb_SystemReset function reboots the ZigBee device.  The
 *              zb_SystemReset function can be called after a call to
 *              zb_WriteConfiguration to restart Z-Stack with the updated
 *              configuration.
 *
 * @param       none
 *
 * @return      none
 */
void zb_SystemReset ( void )
{
  SystemResetSoft();  // Especially useful for CC2531 to not break comm with USB Host.
}
/*********************************************************************
 * @fn          zclServerApp_event_loop
 *
 * @brief       Event Loop Processor for the ZCL Commissioing Cluster
 *              Server Application.
 *
 * @param       task_id - task id
 * @param       events - event bitmap
 *
 * @return      unprocessed events
 */
uint16 zclCCServer_event_loop( uint8 task_id, uint16 events )
{
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
    afIncomingMSGPacket_t *MSGpkt;

    while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclCCServer_TaskID )) )
    {
      switch ( MSGpkt->hdr.event )
      {
        case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          break;

        case ZDO_STATE_CHANGE:
          // Process State Change messages
          break;

        case KEY_CHANGE:
          zclCCServer_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
          break;

        default:
          break;
      }

      // Release the memory
      osal_msg_deallocate( (uint8 *)MSGpkt );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }
  
  if ( events & CCSERVER_LEAVE_TIMER_EVT )
  {
    if ( zcl_CCStartupMode( restartDevice.options ) == CC_STARTUP_MODE_REPLACE_RESTART )
    {
      // Perform a Leave on our old network
      if ( zclCCServer_SendLeaveReq() == ZSuccess )
      {
        // Wait for Leave confirmation before joining the new network
        leaveInitiated = TO_JOIN_OPERATIONAL_NWK;
      }
      else
      {
        // Notify our task to restart the network
        osal_set_event( zclCCServer_TaskID, CCSERVER_RESTART_TIMER_EVT );
      }
    }
    else
    {
      // Notify our task to restart the network
      osal_set_event( zclCCServer_TaskID, CCSERVER_RESTART_TIMER_EVT );
    }

    return ( events ^ CCSERVER_LEAVE_TIMER_EVT );
  }

  if ( events & CCSERVER_RESTART_TIMER_EVT )
  {
    if ( zcl_CCStartupMode( restartDevice.options ) == CC_STARTUP_MODE_REPLACE_RESTART )
    {
      // Set the NV startup option to force a "new" join.
      zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );         
    }
    else
    {
      // Reset the NV startup option to resume from NV by clearing
      // the "new" join option.
      zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );
    }

    SystemResetSoft();

    return ( events ^ CCSERVER_RESTART_TIMER_EVT );
  }

  if ( events & CCSERVER_RESET_TIMER_EVT )
  {
    // Set the NV startup option to default the Config state values
    zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );

    // Set the NV startup option to force a "new" join.
    zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );

    SystemResetSoft();

    return ( events ^ CCSERVER_RESET_TIMER_EVT );
  }

  // Discard unknown events
  return 0;
}