/********************************************************************* * @fn OTA_Dongle_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void OTA_Dongle_Init( byte task_id ) { OTA_Dongle_TaskID = task_id; uint8 RxOnIdle = TRUE; OTA_Dongle_SeqNo = 0; ZMacSetReq( ZMacRxOnIdle, &RxOnIdle ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( OTA_DONGLE_ENDPOINT, &OTA_Dongle_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( OTA_DONGLE_ENDPOINT, OTA_DONGLE_MAX_ATTRIBUTES, OTA_Dongle_Attrs ); // Register the application's cluster option list zcl_registerClusterOptionList( OTA_DONGLE_ENDPOINT, OTA_DONGLE_MAX_OPTIONS, OTA_Dongle_Options ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( OTA_Dongle_TaskID ); // Register for all key events - This app will handle all key events RegisterForKeys( OTA_Dongle_TaskID ); // Register endpoints afRegister( &ota_DongleEp ); afRegister( &ota_SysAppEp ); // Register with the ZDO to receive Match Descriptor Responses ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp); ZDO_RegisterForZDOMsg(task_id, Device_annce); // Start a timer to notify the console about the dongle osal_start_timerEx( OTA_Dongle_TaskID, OTA_DONGLE_DONGLE_NOTIFY_EVT, 4000 ); }
/********************************************************************* * @fn zclHA_Init * * @brief Register the Simple descriptor with the HA profile. * This function also registers the profile's cluster * conversion table. * * @param simpleDesc * * @return none */ void zclHA_Init( SimpleDescriptionFormat_t *simpleDesc ) { endPointDesc_t *epDesc; // Set up the Real Cluster ID to Logical Cluster ID conversion if ( !zclHA_RegisteredClusterList ) { zcl_registerClusterConvertTable( ZCL_HA_PROFILE_ID, (sizeof( ha_ClusterConvertTable ) / sizeof( zclConvertClusterRec_t )) , (GENERIC zclConvertClusterRec_t *)ha_ClusterConvertTable ); zclHA_RegisteredClusterList = TRUE; } // Register the application's endpoint descriptor // - This memory is allocated and never freed. epDesc = osal_mem_alloc( sizeof ( endPointDesc_t ) ); if ( epDesc ) { // Fill out the endpoint description. epDesc->endPoint = simpleDesc->EndPoint; epDesc->task_id = &zcl_TaskID; // all messages get sent to ZCL first epDesc->simpleDesc = simpleDesc; epDesc->latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( epDesc ); } }
/********************************************************************* * @fn zclSampleSw_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclSampleSw_Init( byte task_id ) { osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, ieeeAddr); zclSampleSw_TaskID = task_id; // Set destination address to indirect zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; zclSampleSw_DstAddr.endPoint = 0; zclSampleSw_DstAddr.addr.shortAddr = 0; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleSw_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( SAMPLESW_ENDPOINT, &zclSampleSw_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( SAMPLESW_ENDPOINT, SAMPLESW_MAX_ATTRIBUTES, zclSampleSw_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclSampleSw_TaskID ); // Register for all key events - This app will handle all key events RegisterForKeys( zclSampleSw_TaskID ); // Register for a test endpoint afRegister( &sampleSw_TestEp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, Match_Desc_rsp ); }
/********************************************************************* * @fn GenericApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void GenericApp_Init( byte task_id ) { GenericApp_TaskID = task_id; GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; //¶Ç°e¼Ò¦¡-AddrNotPresent=0; AddrBroadcast=15(¼s¼½) GenericApp_DstAddr.endPoint = 0; GenericApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &GenericApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( GenericApp_TaskID ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp ); }
/********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the SampleApp OSAL task. * * @param task_id - the ID assigned by OSAL. * * @return none */ static void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; /* Sample NV Restore. if ( ZSUCCESS == osal_nv_item_init( SAMPLE_APP_NV_ITEM, sizeof( sampleAppNV_Item_t ), &sampleAppNV_Item ) ) { osal_nv_read( SAMPLE_APP_NV_ITEM, 0, sizeof( sampleAppNV_Item_t ), &sampleAppNV_Item ) ) } else { osal_nv_read( SAMPLE_APP_NV_ITEM, 0, sizeof( sampleAppNV_Item_t ), &sampleAppNV_Item ) ) } */ // Register the endpoint/interface description with the AF. afRegister( (endPointDesc_t *)&SampleApp_epDesc ); // Register for all key events - This app will handle all key events. RegisterForKeys( SampleApp_TaskID ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "<--- SampleApp --->", HAL_LCD_LINE_1 ); #endif }
/************************************************************************************************** * @fn MHMSAppInit * * @brief This function is the application's task initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void MHMSAppInit(uint8 id) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; //uartConfig.baudRate = HAL_UART_BR_38400; //MHMS This baud rate is required to communicate with Zigbee Sensor Monitor uartConfig.baudRate = HAL_UART_BR_115200; //MHMS This baud rate is required to communicate with the Pulse sketching program and reworked Mobile health monitor software on PC uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 16; uartConfig.rx.maxBufSize = 32; uartConfig.tx.maxBufSize = 254; uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = MHMSUartRx; HalUARTOpen(MHMS_PORT, &uartConfig); MHMSDat[MHMS_TYP_IDX] = (uint8)MHMS_DEVICE_ID; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 3] = (uint8)MHMS_DEVICE_ID; #if defined MHMS_SRC_RTG MHMSDat[MHMS_OPT_IDX] = MHMS_OPT_SRC_RTG; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 1] = MHMS_OPT_SRC_RTG; #endif MHMSTaskId = id; MHMSAddr = INVALID_NODE_ADDR; (void)afRegister((endPointDesc_t *)&MHMS_epDesc); //MHMS registers endpoint object //Initialize Px.y (5.0) to power Pulse sensor P5DIR = 0x1; //Set IO direction as output P5OUT = 0x1; //Set output to high //Setup ADC reference REFCTL0 = REFVSEL_2; // REF Reference Voltage Level Select 2.5V }
/********************************************************************* * @fn zclSampleLight_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclSampleLight_Init( byte task_id ) { zclSampleLight_TaskID = task_id; // Set destination address to indirect //zclSampleLight_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; //zclSampleLight_DstAddr.endPoint = 0; //zclSampleLight_DstAddr.addr.shortAddr = 0; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleLight_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT, &zclSampleLight_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( SAMPLELIGHT_ENDPOINT, SAMPLELIGHT_MAX_ATTRIBUTES, zclSampleLight_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclSampleLight_TaskID ); // Register for all key events - This app will handle all key events RegisterForKeys( zclSampleLight_TaskID ); // Register for a test endpoint afRegister( &sampleLight_TestEp ); }
/********************************************************************* * @fn LCD_Init * * @brief Initialization function for the Sensor App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void WirelessMonitorSystem_Init( uint8 task_id ) { // Init the Stack LCD_TaskID = task_id; LCD_NwkState = DEV_INIT; LCD_TransID = 0; // Init the LCD state ackFlag = 0; shiftToRoomInformation = 0; // init the queue LCD_InitMessageQueue(); // Init the uart for the LCD LCD_UartInit(); // init destination address LCD_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; LCD_DstAddr.endPoint = Monitor_ENDPOINT; LCD_DstAddr.addr.shortAddr = 0x0000; // coordinator // Fill out the endpoint description. LCD_epDesc.endPoint = Monitor_ENDPOINT; LCD_epDesc.task_id = &LCD_TaskID; LCD_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&LCD_SimpleDesc; LCD_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &LCD_epDesc ); }
/********************************************************************* * @fn Monitor_Init * * @brief Initialization function for the Sensor App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void WirelessMonitorSystem_Init( uint8 task_id ) { Monitor_TaskID = task_id; Monitor_NwkState = DEV_INIT; Monitor_TransID = 0; // init the uart, keep care do not use flow control Monitor_UartInit(); // Destinations Monitor_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; Monitor_DstAddr.endPoint = Monitor_ENDPOINT; Monitor_DstAddr.addr.shortAddr = 0xFFFF; // Fill out the endpoint description. Monitor_epDesc.endPoint = Monitor_ENDPOINT; Monitor_epDesc.task_id = &Monitor_TaskID; Monitor_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&Monitor_SimpleDesc; Monitor_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &Monitor_epDesc ); }
/*************************************************************************************************** * @fn MT_SapiAppRegister * * @brief Process SAPI App Register * * @param pBuf - pointer to received buffer * * @return none ***************************************************************************************************/ void MT_SapiAppRegister(uint8 *pBuf) { uint8 ret = ZApsIllegalRequest; /* check if sapi is alredy registered with an endpoint */ if ( (sapi_epDesc.endPoint == 0) && (*pBuf != 0) ) { ret = MT_BuildEndpointDesc( pBuf+MT_RPC_FRAME_HDR_SZ, &sapi_epDesc ); if ( ret == ZSuccess ) { ret = afRegister( &sapi_epDesc ); // Turn off match descriptor response by default afSetMatch(sapi_epDesc.simpleDesc->EndPoint, FALSE); } if ( ret != ZSuccess ) { sapi_epDesc.endPoint = 0; } } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SAPI), MT_SAPI_APP_REGISTER_REQ, 1, &ret); }
/*************************************************************************************************** * @fn MT_AfRegister * * @brief Process AF Register command * * @param pBuf - pointer to the received buffer * * @return none ***************************************************************************************************/ void MT_AfRegister(uint8 *pBuf) { uint8 cmdId; uint8 retValue = ZMemError; endPointDesc_t *epDesc; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; epDesc = (endPointDesc_t *)osal_mem_alloc(sizeof(endPointDesc_t)); if ( epDesc ) { epDesc->task_id = &MT_TaskID; retValue = MT_BuildEndpointDesc( pBuf, epDesc ); if ( retValue == ZSuccess ) { retValue = afRegister( epDesc ); } if ( retValue != ZSuccess ) { osal_mem_free( epDesc ); } } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_AF), cmdId, 1, &retValue); }
/********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; // Device state : Initialized - not connected to anything SampleApp_TransID = 0; // The unique message ID (counter) // Device hardware initialization can be added here or in main() (Zmain.c). If the hardware is application // specific(¯S©wÀ³¥Î) - add it here. If the hardware is other parts of the device(¨ä¥L¸Ë¸mªº³¡¤À) add it in main(). //#if defined ( BUILD_ALL_DEVICES ) // // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START We are looking at a // // jumper (defined in SampleAppHw.c) to be jumpered together - if they are - we will start up a // // coordinator. Otherwise, the device will start as a router. -> ·íjumper¦³±µ¤W®É,¸Ë¸m¥HCoordinator±Ò°Ê,§_«h¥Hrouter±Ò°Ê. // if ( readCoordinatorJumper() ) // zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; // else // zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; //#endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START½sĶ¿ï¶µ·|¥õ¨îZDAppªº±Ò°Ê¸Ë¸m¤ÎÀ³¥Îµ{§Ç // HOLD_AUTO_START is a compile option that will surpress ZDApp from starting the device // and wait for the application to start the device. ZDOInitDevice(0); #endif /* SampleApp_Periodic Message's */ // Setup for the periodic message's destination address Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; // ¶Ç°e¼Ò¦¡-¼s¼½ SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; // end-point½s¸¹:20 SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // ºô¸ô¦ì§}(0xFFFF -> ¼s¼½¨ìºô¸ô¤¤©Ò¦³¸Ë¸m(§t¥ð¯v)) /* SampleApp_Flash Command's */ // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; // ¶Ç°e¼Ò¦¡-¸s²Õ¦ì§} SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; // end-point½s¸¹:20 SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // ¸s²Õ¦WºÙ¦ì§} /* SampleApp_epDesc description */ // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; // SampleApp´yzªºendpoint½s¸¹ SampleApp_epDesc.task_id = &SampleApp_TaskID; // SampleApp´yzªºTaskID SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; // SampleApp´yzªº²Å¸¹ SampleApp_epDesc.latencyReq = noLatencyReqs; // ¦bAF¼hµù¥U§ï¥Îend-point // Register the endpoint description with the AF(¦V¤U¼hµù¥U¦¹À³¥Îµ{¦¡) afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events(¦V¤U¼hµù¥U«ö¶s¨Æ¥ó) RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 //µù¥U¸s²Õ SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); #endif }
/* @fn LoacationApp_Init * @brief Initialization function for the LoacationApp OSAL task. * @param task_id - the ID assigned by OSAL. * @return none*/ static void LoacationApp_Init( uint8 task_id ) { LoacationApp_TaskID = task_id; afRegister((endPointDesc_t *)&LoacationApp_epDesc); //Register for AF RegisterForKeys(LoacationApp_TaskID); //Register for all key events #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "<-LoacationApp->", HAL_LCD_LINE_1 ); #endif }
/********************************************************************* * @fn TransmitApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void TransmitApp_Init( byte task_id ) { #if !defined ( TRANSMITAPP_FRAGMENTED ) afDataReqMTU_t mtu; #endif uint16 i; TransmitApp_TaskID = task_id; TransmitApp_NwkState = DEV_INIT; TransmitApp_TransID = 0; pktCounter = 0; TransmitApp_State = TRANSMITAPP_STATE_WAITING; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). TransmitApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; TransmitApp_DstAddr.endPoint = 0; TransmitApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. TransmitApp_epDesc.endPoint = TRANSMITAPP_ENDPOINT; TransmitApp_epDesc.task_id = &TransmitApp_TaskID; TransmitApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&TransmitApp_SimpleDesc; TransmitApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint/interface description with the AF afRegister( &TransmitApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( TransmitApp_TaskID ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "TransmitApp", HAL_LCD_LINE_2 ); #endif // Set the data length #if defined ( TRANSMITAPP_FRAGMENTED ) TransmitApp_MaxDataLength = TRANSMITAPP_MAX_DATA_LEN; #else mtu.kvp = FALSE; mtu.aps.secure = FALSE; TransmitApp_MaxDataLength = afDataReqMTU( &mtu ); #endif // Generate the data for (i=0; i<TransmitApp_MaxDataLength; i++) { TransmitApp_Msg[i] = (uint8) i; } }
/********************************************************************* * @fn zclSampleSw_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclSampleSw_Init( byte task_id ) { zclSampleSw_TaskID = task_id; #ifdef ZCL_ON_OFF // Set destination address to indirect zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; zclSampleSw_DstAddr.endPoint = 0; zclSampleSw_DstAddr.addr.shortAddr = 0; #endif // This app is part of the Home Automation Profile zclHA_Init( &zclSampleSw_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( SAMPLESW_ENDPOINT, &zclSampleSw_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( SAMPLESW_ENDPOINT, SAMPLESW_MAX_ATTRIBUTES, zclSampleSw_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclSampleSw_TaskID ); #ifdef ZCL_EZMODE // Register EZ-Mode zcl_RegisterEZMode( &zclSampleSw_RegisterEZModeData ); // Register with the ZDO to receive Match Descriptor Responses ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp); #endif // Register for all key events - This app will handle all key events RegisterForKeys( zclSampleSw_TaskID ); // Register for a test endpoint afRegister( &sampleSw_TestEp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, Match_Desc_rsp ); #ifdef LCD_SUPPORTED HalLcdWriteString ( (char *)sDeviceName, HAL_LCD_LINE_3 ); #endif #if defined (OTA_CLIENT) && (OTA_CLIENT == TRUE) // Register for callback events from the ZCL OTA zclOTA_Register(zclSampleSw_TaskID); #endif }
void AT_AF_Register(uint8 *task_id){ // Fill out the endpoint description. AT_AF_epDesc.endPoint = AT_AF_ENDPOINT; AT_AF_epDesc.task_id = task_id; AT_AF_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&AT_AF_SimpleDesc; AT_AF_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &AT_AF_epDesc ); aps_AddGroup( AT_AF_ENDPOINT, &AT_AF_Group ); }
/********************************************************************* * @fn SerialApp_Init * * @brief This is called during OSAL tasks' initialization. * * @param task_id - the Task ID assigned by OSAL. * * @return none */ void SerialApp_Init( uint8 task_id ) { halUARTCfg_t uartConfig; SerialApp_MsgID = 0x00; SerialApp_SeqRx = 0xC3; SerialApp_TaskID = task_id; SerialApp_DstAddr.endPoint = 0; SerialApp_DstAddr.addr.shortAddr = 0; SerialApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; SerialApp_RspDstAddr.endPoint = 0; SerialApp_RspDstAddr.addr.shortAddr = 0; SerialApp_RspDstAddr.addrMode = (afAddrMode_t)AddrNotPresent; afRegister( (endPointDesc_t *)&SerialApp_epDesc ); RegisterForKeys( task_id ); uartConfig.configured = TRUE; // 2430 don't care. uartConfig.baudRate = SERIAL_APP_BAUD; uartConfig.flowControl = TRUE; uartConfig.flowControlThreshold = SERIAL_APP_THRESH; uartConfig.rx.maxBufSize = SERIAL_APP_RX_MAX; uartConfig.tx.maxBufSize = SERIAL_APP_TX_MAX; uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2430 don't care. uartConfig.intEnable = TRUE; // 2430 don't care. #if SERIAL_APP_LOOPBACK uartConfig.callBackFunc = rxCB_Loopback; #else uartConfig.callBackFunc = rxCB; #endif HalUARTOpen (SERIAL_APP_PORT, &uartConfig); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SerialApp2", HAL_LCD_LINE_2 ); #endif HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF); HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); HalLedSet(HAL_LED_3,HAL_LED_MODE_OFF); ZDO_RegisterForZDOMsg( SerialApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( SerialApp_TaskID, Match_Desc_rsp ); osal_start_timerEx(SerialApp_TaskID,SERIALAPP_MSG_AUTOMATCH,2000); }
/********************************************************************* * @fn zclHA_Init * * @brief Register the Simple descriptor with the HA profile. * This function also registers the profile's cluster conversion table. * * @param simpleDesc - a pointer to a valid SimpleDescriptionFormat_t, must not be NULL. * * @return none */ void zclHA_Init( SimpleDescriptionFormat_t *simpleDesc ){ endPointDesc_t *epDesc; // Register the application's endpoint descriptor // - This memory is allocated and never freed. epDesc = osal_mem_alloc( sizeof ( endPointDesc_t ) ); if ( epDesc ) { // Fill out the endpoint description. epDesc->endPoint = simpleDesc->EndPoint; epDesc->task_id = &zcl_TaskID; // all messages get sent to ZCL first epDesc->simpleDesc = simpleDesc; epDesc->latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( epDesc ); } }
/********************************************************************* * @fn GenericApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void GenericApp_Init( byte task_id ) { GenericApp_TaskID = task_id; GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; GenericApp_DstAddr.endPoint = 0; GenericApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &GenericApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( GenericApp_TaskID ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp ); ZDO_RegisterForZDOMsg( GenericApp_TaskID, SPI_INCOMING_ZAPP_DATA ); /*****for SHP *************begin******************/{ //extern void shp_example_init_called_by_system(void); //shp_example_init_called_by_system(); /*****for SHP *************end********************/} //QBing MT_UartRegisterTaskID(GenericApp_TaskID); MT_UartZAppBufferLengthRegister(100); osal_start_timerEx(GenericApp_TaskID,GENERICAPP_TIMER_EVT,1000); }
/************************************************************************************************** * @fn pulseAppInit * * @brief This function is the application's task initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void pulseAppInit(uint8 id) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = HAL_UART_BR_38400; //MHMS This baud rate is required to communicate with Zigbee Sensor Monitor //uartConfig.baudRate = HAL_UART_BR_115200; //MHMS This baud rate is required to communicate with the Pulse processing program on PC uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 16; // 2x30 don't care - see uart driver. uartConfig.rx.maxBufSize = 32; // 2x30 don't care - see uart driver. uartConfig.tx.maxBufSize = 254; // 2x30 don't care - see uart driver. uartConfig.idleTimeout = 6; // 2x30 don't care - see uart driver. uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver. uartConfig.callBackFunc = pulseUartRx; HalUARTOpen(PULSE_PORT, &uartConfig); pulseDat[PULSE_TYP_IDX] = (uint8)PULSE_DEVICE_ID; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 3] = (uint8)PULSE_DEVICE_ID; #if defined PULSE_SRC_RTG pulseDat[PULSE_OPT_IDX] = PULSE_OPT_SRC_RTG; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 1] = PULSE_OPT_SRC_RTG; #endif pulseTaskId = id; pulseAddr = INVALID_NODE_ADDR; (void)afRegister((endPointDesc_t *)&PULSE_epDesc); //MHMS registers endpoint object //Initialize Px.y (5.0) to power Pulse sensor P5DIR = 0x1; //Set IO direction as output P5OUT = 0x1; //Set output to high //Test P4DIR = 0x1; P4OUT = 0x1; //Setup ADC reference REFCTL0 = REFVSEL_2; // REF Reference Voltage Level Select 2.5V }
/********************************************************************* * @fn zclRouterVersion1_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclRouterVersion1_Init( byte task_id ) { zclRouterVersion1_TaskID = task_id; // Set destination address to indirect zclRouterVersion1_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; zclRouterVersion1_DstAddr.endPoint = 2; zclRouterVersion1_DstAddr.addr.shortAddr = 0x0000; // This app is part of the Home Automation Profile zclHA_Init( &zclRouterVersion1_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( ROUTERVERSION1_ENDPOINT, &zclRouterVersion1_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( ROUTERVERSION1_ENDPOINT, zclRouterVersion1_NumAttributes, zclRouterVersion1_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclRouterVersion1_TaskID ); // Register for all key events - This app will handle all key events RegisterForKeys( zclRouterVersion1_TaskID ); // Register for a test endpoint afRegister( &sampleLight_TestEp ); ZDO_RegisterForZDOMsg(task_id, Device_annce); osal_start_timerEx(zclRouterVersion1_TaskID, SET_PARAMETER, 1000); HAL_CONFIG_IO_OUTPUT(1,2,0); HAL_CONFIG_IO_OUTPUT(1,3,0); HAL_CONFIG_IO_OUTPUT(0,0,0); HAL_CONFIG_IO_OUTPUT(0,1,0); HAL_CONFIG_IO_OUTPUT(0,2,0); HAL_CONFIG_IO_OUTPUT(0,3,0); HAL_CONFIG_IO_OUTPUT(0,4,0); HAL_CONFIG_IO_OUTPUT(0,7,0); HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF); HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); //ZDOInitDevice(0); if (ZDApp_ReadNetworkRestoreState() == 0) { ZDOInitDevice(0); } }
/********************************************************************* * @fn SAPI_Init * * @brief Initialization function for the Simple API Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notification ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SAPI_Init( byte task_id ) { sapi_TaskID = task_id; sapi_bindInProgress = 0xffff; sapi_epDesc.task_id = &sapi_TaskID; sapi_epDesc.endPoint = 0; #if ( SAPI_CB_FUNC ) sapi_epDesc.endPoint = zb_SimpleDesc.EndPoint; sapi_epDesc.task_id = &sapi_TaskID; sapi_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&zb_SimpleDesc; sapi_epDesc.latencyReq = noLatencyReqs; // Register the endpoint/interface description with the AF afRegister( &sapi_epDesc ); #endif // Turn off match descriptor response by default afSetMatch(sapi_epDesc.simpleDesc->EndPoint, FALSE); // Register callback evetns from the ZDApp ZDO_RegisterForZDOMsg( sapi_TaskID, NWK_addr_rsp ); ZDO_RegisterForZDOMsg( sapi_TaskID, Match_Desc_rsp ); #if ( SAPI_CB_FUNC ) #if (defined HAL_KEY) && (HAL_KEY == TRUE) // Register for HAL events RegisterForKeys( sapi_TaskID ); if ( HalKeyRead () == HAL_KEY_SW_5) { // If SW5 is pressed and held while powerup, force auto-start and nv-restore off and reset uint8 startOptions = ZCD_STARTOPT_CLEAR_STATE | ZCD_STARTOPT_CLEAR_CONFIG; zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); zb_SystemReset(); } #endif // HAL_KEY // Set an event to start the application osal_set_event(task_id, ZB_ENTRY_EVENT); #endif }
/********************************************************************* * @fn zclSampleTemperatureSensor_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclSampleTemperatureSensor_Init( byte task_id ) { zclSampleTemperatureSensor_TaskID = task_id; // Set destination address to indirect zclSampleTemperatureSensor_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; zclSampleTemperatureSensor_DstAddr.endPoint = 0; zclSampleTemperatureSensor_DstAddr.addr.shortAddr = 0; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleTemperatureSensor_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( SAMPLETEMPERATURESENSOR_ENDPOINT, &zclSampleTemperatureSensor_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( SAMPLETEMPERATURESENSOR_ENDPOINT, SAMPLETEMPERATURESENSOR_MAX_ATTRIBUTES, zclSampleTemperatureSensor_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclSampleTemperatureSensor_TaskID ); #ifdef ZCL_EZMODE // Register EZ-Mode zcl_RegisterEZMode( &zclSampleTemperatureSensor_RegisterEZModeData ); // Register with the ZDO to receive Match Descriptor Responses ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp); #endif // Register for all key events - This app will handle all key events RegisterForKeys( zclSampleTemperatureSensor_TaskID ); // Register for a test endpoint afRegister( &sampleTemperatureSensor_TestEp ); #ifdef LCD_SUPPORTED // display the device name HalLcdWriteString( (char *)sDeviceName, HAL_LCD_LINE_3 ); #endif }
//Initialization function for the Park Way task. This is called during initialization and should contain any application specific initialization (ie. hardware initialization/setup, table initialization, power up notificaiton ... ) void ParkWay_Init( uint8 task_id ) { ParkWay_TaskID = task_id; ParkWay_NwkState = DEV_INIT; ParkWay_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). ParkWay_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; ParkWay_DstAddr.endPoint = 0; ParkWay_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. ParkWay_epDesc.endPoint = ParkWay_ENDPOINT; ParkWay_epDesc.task_id = &ParkWay_TaskID; ParkWay_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&ParkWay_SimpleDesc; ParkWay_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &ParkWay_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( ParkWay_TaskID ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "ParkWay-Coord", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( ParkWay_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( ParkWay_TaskID, Match_Desc_rsp ); osal_start_timerEx( ParkWay_TaskID, POLL_PARWAY_EVT, TIME_PARKWAY_POLL); }
/********************************************************************* * @fn temcoApp_Init */ void temcoApp_Init(uint8 task_id) { temcoAPP_TaskID = task_id; temco_epDesc.endPoint = TEMCO_ENDPOINT; temco_epDesc.task_id = &temcoAPP_TaskID; temco_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&temcoSimpleDesc; temco_epDesc.latencyReq = noLatencyReqs; // register the endpoint description with the AF afRegister( &temco_epDesc); #if 0 if( zgDeviceLogicalType == ZG_DEVICETYPE_COORDINATOR) { tstat_id = 254; // NC's modbus id always is 9 } #endif if( zgDeviceLogicalType == ZG_DEVICETYPE_COORDINATOR) { osal_set_event( temcoAPP_TaskID, SEND_ZIGBEE_FLAG); } else osal_set_event( temcoAPP_TaskID, ASK_MODBUS_ID); }
/********************************************************************* * @fn Router_Init * * @brief Initialization function for the Sensor App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void WirelessMonitorSystem_Init( uint8 task_id ) { Router_TaskID = task_id; Router_NwkState = DEV_INIT; Router_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). Router_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; Router_DstAddr.endPoint = Monitor_ENDPOINT; Router_DstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; // 0xFFFF // Fill out the endpoint description. Router_epDesc.endPoint = Monitor_ENDPOINT; Router_epDesc.task_id = &Router_TaskID; Router_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&Router_SimpleDesc; Router_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &Router_epDesc ); }
void zclEnergyHarvester_Init( byte task_id ) { zclEnergyHarvester_TaskID = task_id; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleLight_SimpleDesc ); // Register for a test endpoint afRegister( &testEp ); zcl_registerPlugin( ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT, ZCL_CLUSTER_ID_MS_ALL, zclEnergyHarvester_HdlIncoming ); ZDO_RegisterForZDOMsg( zclEnergyHarvester_TaskID, End_Device_Bind_rsp ); #if DEV_TYPE == COORDINATOR ZDO_RegisterForZDOMsg( zclEnergyHarvester_TaskID, Device_annce ); #else adc_Init(); // Configure signal from off-chip timer to be wake-up signal GPIODirModeSet( GPIO_B_BASE, GPIO_PIN_3 , GPIO_DIR_MODE_IN ); // Configure deep sleep in power mode 3, woken up by off-chip timer SysCtrlDeepSleepSetting(); SysCtrlPowerModeSet( SYS_CTRL_PM_3 ); GPIODirModeSet( GPIO_B_BASE, GPIO_PIN_4 , GPIO_DIR_MODE_IN ); HWREG( SYS_CTRL_IWE ) = 0x02; GPIOPowIntTypeSet( GPIO_B_BASE, GPIO_PIN_4, GPIO_POW_RISING_EDGE ); GPIOPowIntClear( GPIO_B_BASE, GPIO_PIN_4 ); GPIOPowIntEnable( GPIO_B_BASE, GPIO_PIN_4 ); // Done with off-chip timer acknowledge GPIOPinWrite( GPIO_B_BASE, GPIO_PIN_5, GPIO_PIN_5 ); #endif }
void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; //uart open(SampleApp_TaskID); // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). #if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // SOFT_START #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = 0xFFFF; //�s�� //end device /* coordinator to end device must 0xffff end device to coordinator must 0x0000 */ //mpleApp_Flash_DstAddr.addr.shortAddr = 0x0000; //SampleApp_Flash_DstAddr.addr.shortAddr =SAMPLEAPP_FLASH_GROUP; //coordinator // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = SAMPLEAPP_FLASH_GROUP; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined( HAL_UART ) open(SampleApp_TaskID); #endif #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); #endif }
/********************************************************************* * @fn HVACTest_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void HVACTest_Init( uint8 task_id ) { HVACTest_TaskID = task_id; HVACTest_NwkState = DEV_INIT; HVACTest_TransID = 0; uint8 initVersion = 0; uint8 startupMsg[4] = {0xFF,0xFF,0,0}; // use this code to trick compiler initVersion = firm_version + hardware_version + chip_version; (void)initVersion; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). hvac_STM32ResetInit(); // Register UART, init UART MT_UartInit (); MT_UartRegisterTaskID (HVACTest_TaskID); HVACTest_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; HVACTest_DstAddr.endPoint = HVACQUEEN_ENDPOINT; HVACTest_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. HVACTest_epDesc.endPoint = HVACQUEEN_ENDPOINT; HVACTest_epDesc.task_id = &HVACTest_TaskID; HVACTest_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&HVACTest_SimpleDesc; HVACTest_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &HVACTest_epDesc ); // Register ZDO Message ZDO_RegisterForZDOMsg( HVACTest_TaskID, Device_annce ); ZDO_RegisterForZDOMsg( HVACTest_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( HVACTest_TaskID, Match_Desc_rsp ); // Init critical resource ptl0_initPTL0Status(); // check valid MAC address? // // If a mac address copy is valid in flash, send "FF FF FF" Msg to // STM32 and start the zigbee network. // // If not, send "FF FF 00" Msg to STM32, and prepare to handle MAC // address message. // // The forth byte is the firmware version // Test program, no need init white list // However, to disable any device to join, enable the empty white list function // Add firmware version startupMsg[3] = firm_version; // send valid flash startup mag while(HalUARTWrite(0, startupMsg, 4) != 4) { #ifdef WDT_IN_PM1 // clear WDT WDCTL |= WDCLP1; WDCTL |= WDCLP2; #endif HalUARTPoll(); } // start network directly, form a network and check ZDOInitDevice(0); // Init timer osal_start_timerEx( HVACTest_TaskID, HVAC_PTL0_GUT_EVT, HVAC_PTL0_FAIL_TIMEOUT ); // WDT #ifdef WDT_IN_PM1 // Start WDT reset timer osal_start_timerEx( HVACTest_TaskID, HVAC_WDT_CLEAR_EVT, HVAC_WDT_CLEAR_TIMEOUT ); #endif #if defined( IAR_ARMCM3_LM ) // Register this task with RTOS task initiator RTOS_RegisterApp( task_id, HVACQUEEN_RTOS_MSG_EVT ); #endif }
/********************************************************************* * @fn SampleApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; SampleApp_NwkState = DEV_INIT; SampleApp_TransID = 0; MT_UartInit();//串口初始化 MT_UartRegisterTaskID(task_id);//登记任务号 #ifdef MODE_ED //终端节点下才配置 /**************超声波***************/ #define trig P0_1 #define echo P0_0 P0DIR |= 0x02; //P01输出trig P0DIR &= ~0x01; //P00输入echo trig=0; /*定时器配置*/ HalTimerInit(); HalTimerConfig(HAL_TIMER_0, HAL_TIMER_MODE_CTC, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OUTPUT_COMPARE, TRUE, timer_callback); /***********步进电机**************/ #define in1 P0_4 #define in2 P0_5 #define in3 P0_6 #define in4 P0_7 P0SEL &=~0xf0; P0DIR |= 0xf0; P0INP &=~0Xf0; //打开上拉 in1=0; in2=0; in3=0; in4=0; /*测试*/ int i=0; for(i=0;i<128;i++) { MotorCW(); } for(i=0;i<128;i++) { MotorCCW(); } HalLedBlink( HAL_LED_2, 2,50, 500); #endif // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). #if defined ( BUILD_ALL_DEVICES ) // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJumper() ) zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES #if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif // Setup for the periodic message's destination address // Broadcast to everyone SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // Setup for the flash command's destination address - Group 1 SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; // 网蜂点对点通讯定义 Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//点播 Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器 // Fill out the endpoint description. SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; SampleApp_epDesc.task_id = &SampleApp_TaskID; SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc; SampleApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SampleApp_epDesc ); // Register for all key events - This app will handle all key events RegisterForKeys( SampleApp_TaskID ); // By default, all devices start out in Group 1 SampleApp_Group.ID = 0x0001; osal_memcpy( SampleApp_Group.name, "Group 1", 7 ); aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group ); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SmartPark", HAL_LCD_LINE_1 ); #endif }