diff options
Diffstat (limited to 'Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c')
-rw-r--r-- | Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c | 185 |
1 files changed, 123 insertions, 62 deletions
diff --git a/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c b/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c index 3f5a04de3..7a3ccc81f 100644 --- a/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c +++ b/Projects/P-NUCLEO-WB55.USBDongle/Applications/Zigbee/Zigbee_OnOff_Server_Coord/STM32_WPAN/App/app_zigbee.c @@ -56,12 +56,14 @@ static void Receive_Notification_From_M0(void); /* Private variables -----------------------------------------------*/ static TL_CmdPacket_t *p_ZIGBEE_otcmdbuffer; static TL_EvtPacket_t *p_ZIGBEE_notif_M0_to_M4; -static __IO uint32_t CptReceiveMsgFromM0 = 0; +static TL_EvtPacket_t *p_ZIGBEE_request_M0_to_M4; +static __IO uint32_t CptReceiveNotifyFromM0 = 0; +static __IO uint32_t CptReceiveRequestFromM0 = 0; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_ZIGBEE_Config_t ZigbeeConfigBuffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t ZigbeeOtCmdBuffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ZigbeeNotifRspEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ZigbeeNotifLoggingBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ZigbeeNotifRequestBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U]; struct zigbee_app_info { bool has_init; @@ -74,17 +76,12 @@ struct zigbee_app_info { struct ZbZclClusterT *onoff_server_1; }; static struct zigbee_app_info zigbee_app_info; - -static enum ZclStatusCodeT onoff_server_attr_cb(struct ZbZclClusterT *clusterPtr, struct ZbZclAttrCbInfoT *cb); - -static const struct ZbZclAttrT onoff_server_attr_list[] = { - /* OnOff Server Attributes */ - { - ZCL_ONOFF_ATTR_ONOFF, ZCL_DATATYPE_BOOLEAN, - ZCL_ATTR_FLAG_REPORTABLE | ZCL_ATTR_FLAG_PERSISTABLE | ZCL_ATTR_FLAG_DEFAULTABLE | ZCL_ATTR_FLAG_CB_NOTIFY, 0, - onoff_server_attr_cb, {0, 0}, {0, 0} - }, -}; +static enum ZclStatusCodeT onoff_server_off(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg); +static enum ZclStatusCodeT onoff_server_on(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg); +static enum ZclStatusCodeT onoff_server_toggle(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg); /* Functions Definition ------------------------------------------------------*/ @@ -105,7 +102,9 @@ void APP_ZIGBEE_Init(void) /* Register task */ /* Create the different tasks */ - UTIL_SEQ_RegTask(1U << (uint32_t)CFG_TASK_MSG_FROM_M0_TO_M4, UTIL_SEQ_RFU,APP_ZIGBEE_ProcessMsgM0ToM4); + + UTIL_SEQ_RegTask(1U << (uint32_t)CFG_TASK_NOTIFY_FROM_M0_TO_M4, UTIL_SEQ_RFU, APP_ZIGBEE_ProcessNotifyM0ToM4); + UTIL_SEQ_RegTask(1U << (uint32_t)CFG_TASK_REQUEST_FROM_M0_TO_M4, UTIL_SEQ_RFU, APP_ZIGBEE_ProcessRequestM0ToM4); /* Task associated with network creation process */ UTIL_SEQ_RegTask(1U << CFG_TASK_ZIGBEE_NETWORK_FORM, UTIL_SEQ_RFU, APP_ZIGBEE_NwkForm); @@ -155,20 +154,25 @@ static void APP_ZIGBEE_ConfigEndpoints(void) { ZbApsmeAddEndpointReqT req; ZbApsmeAddEndpointConfT conf; + struct ZbZclOnOffServerCallbacksT onoff_callbacks; memset(&req, 0, sizeof(req)); req.profileId = ZCL_PROFILE_HOME_AUTOMATION; req.deviceId = ZCL_DEVICE_ONOFF_SWITCH; + memset(&onoff_callbacks, 0, sizeof(onoff_callbacks)); + onoff_callbacks.off = onoff_server_off; + onoff_callbacks.on = onoff_server_on; + onoff_callbacks.toggle = onoff_server_toggle; + /* Endpoint: SW1_ENDPOINT */ req.endpoint = SW1_ENDPOINT; ZbZclAddEndpoint(zigbee_app_info.zb, &req, &conf); assert(conf.status == ZB_STATUS_SUCCESS); /* OnOff Server */ - zigbee_app_info.onoff_server_1 = ZbZclOnOffServerAlloc(zigbee_app_info.zb, SW1_ENDPOINT, NULL); + zigbee_app_info.onoff_server_1 = ZbZclOnOffServerAlloc(zigbee_app_info.zb, SW1_ENDPOINT, &onoff_callbacks, NULL); assert(zigbee_app_info.onoff_server_1 != NULL); - ZbZclAttrAppendList(zigbee_app_info.onoff_server_1, onoff_server_attr_list, ZCL_ATTR_LIST_LEN(onoff_server_attr_list)); ZbZclClusterEndpointRegister(zigbee_app_info.onoff_server_1); } /* config_endpoints */ @@ -256,34 +260,60 @@ static void APP_ZIGBEE_ConfigGroupAddr(void) } /* APP_ZIGBEE_ConfigGroupAddr */ -static enum ZclStatusCodeT onoff_server_attr_cb(struct ZbZclClusterT *clusterPtr, struct ZbZclAttrCbInfoT *cb) +/* Functions Definition ------------------------------------------------------*/ + +static enum ZclStatusCodeT onoff_server_off(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg) { - uint8_t endpoint; - uint8_t attrVal; + uint8_t endpoint; - endpoint = ZbZclClusterGetEndpoint(clusterPtr); - APP_DBG("onoff_server_attr_cb : endpoint = %d", endpoint); - switch (cb->info->attributeId) { - case ZCL_ONOFF_ATTR_ONOFF: + endpoint = ZbZclClusterGetEndpoint(clusterPtr); if (endpoint == SW1_ENDPOINT) { - if (ZbZclAttrRead(zigbee_app_info.onoff_server_1, ZCL_ONOFF_ATTR_ONOFF, NULL, &attrVal, sizeof(attrVal), false) == ZCL_STATUS_SUCCESS) { - if (attrVal != 0) { - APP_DBG("LED_RED ON"); - BSP_LED_On(LED_RED); - } - else { - APP_DBG("LED_RED OFF"); - BSP_LED_Off(LED_RED); - } - } + APP_DBG("LED_RED OFF"); + BSP_LED_Off(LED_RED); + (void)ZbZclAttrIntegerWrite(clusterPtr, ZCL_ONOFF_ATTR_ONOFF, 0); } - break; + else { + /* Unknown endpoint */ + return ZCL_STATUS_FAILURE; + } + return ZCL_STATUS_SUCCESS; +} - default: - break; - } /* switch */ - return ZCL_STATUS_SUCCESS; -} /* onoff_server_attr_notify */ +static enum ZclStatusCodeT onoff_server_on(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg) +{ + uint8_t endpoint; + + endpoint = ZbZclClusterGetEndpoint(clusterPtr); + if (endpoint == SW1_ENDPOINT) { + APP_DBG("LED_RED ON"); + BSP_LED_On(LED_RED); + (void)ZbZclAttrIntegerWrite(clusterPtr, ZCL_ONOFF_ATTR_ONOFF, 1); + } + else { + /* Unknown endpoint */ + return ZCL_STATUS_FAILURE; + } + return ZCL_STATUS_SUCCESS; +} + +static enum ZclStatusCodeT onoff_server_toggle(struct ZbZclClusterT *clusterPtr, + struct ZbZclAddrInfoT *srcInfo, void *arg) +{ + uint8_t attrVal; + + if (ZbZclAttrRead(clusterPtr, ZCL_ONOFF_ATTR_ONOFF, NULL, + &attrVal, sizeof(attrVal), false) != ZCL_STATUS_SUCCESS) { + return ZCL_STATUS_FAILURE; + } + if (attrVal != 0) { + return onoff_server_off(clusterPtr, srcInfo, arg); + } + else { + return onoff_server_on(clusterPtr, srcInfo, arg); + } +} /************************************************************* * ZbStartupWait Blocking Call @@ -299,6 +329,7 @@ static void ZbStartupWaitCb(enum ZbStatusCodeT status, void *cb_arg) info->status = status; info->active = false; + UTIL_SEQ_SetEvt(EVENT_ZIGBEE_STARTUP_ENDED); } /* ZbStartupWaitCb */ enum ZbStatusCodeT ZbStartupWait(struct ZigBeeT *zb, struct ZbStartupT *config) @@ -318,9 +349,7 @@ enum ZbStatusCodeT ZbStartupWait(struct ZigBeeT *zb, struct ZbStartupT *config) info->active = false; return status; } - while (info->active) { - UTIL_SEQ_Run( UTIL_SEQ_DEFAULT ); - } + UTIL_SEQ_WaitEvt(EVENT_ZIGBEE_STARTUP_ENDED); status = info->status; free(info); return status; @@ -427,6 +456,11 @@ Zigbee_Cmd_Request_t * ZIGBEE_Get_NotificationPayloadBuffer(void) return (Zigbee_Cmd_Request_t *)(p_ZIGBEE_notif_M0_to_M4)->evtserial.evt.payload; } /* ZIGBEE_Get_NotificationPayloadBuffer */ +Zigbee_Cmd_Request_t * ZIGBEE_Get_M0RequestPayloadBuffer(void) +{ + return (Zigbee_Cmd_Request_t *)(p_ZIGBEE_request_M0_to_M4)->evtserial.evt.payload; +} + /** * @brief This function is used to transfer the commands from the M4 to the M0. * @@ -443,7 +477,7 @@ void ZIGBEE_CmdTransfer(void) * + ID (4 bytes) + Size (4 bytes) */ p_ZIGBEE_otcmdbuffer->cmdserial.cmd.plen = 8U + (cmd_req->Size * 4U); - TL_ZIGBEE_SendAppliCmdToM0(); + TL_ZIGBEE_SendM4RequestToM0(); /* Wait completion of cmd */ Wait_Getting_Ack_From_M0(); @@ -521,9 +555,23 @@ static void Receive_Ack_From_M0(void) */ static void Receive_Notification_From_M0(void) { - CptReceiveMsgFromM0++; - UTIL_SEQ_SetTask(1U << CFG_TASK_MSG_FROM_M0_TO_M4, CFG_SCH_PRIO_0); -} /* Receive_Notification_From_M0 */ + CptReceiveNotifyFromM0++; + UTIL_SEQ_SetTask(1U << (uint32_t)CFG_TASK_NOTIFY_FROM_M0_TO_M4, CFG_SCH_PRIO_0); +} + +/** + * @brief This function is called when a request from M0+ is received. + * + * @param Notbuffer : a pointer to TL_EvtPacket_t + * @return None + */ +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t *Reqbuffer) +{ + p_ZIGBEE_request_M0_to_M4 = Reqbuffer; + + CptReceiveRequestFromM0++; + UTIL_SEQ_SetTask(1U << (uint32_t)CFG_TASK_REQUEST_FROM_M0_TO_M4, CFG_SCH_PRIO_0); +} /** * @brief Perform initialization of TL for Zigbee. @@ -532,30 +580,43 @@ static void Receive_Notification_From_M0(void) */ void APP_ZIGBEE_TL_INIT(void) { - ZigbeeConfigBuffer.p_ZigbeeOtCmdRspBuffer = (uint8_t *)&ZigbeeOtCmdBuffer; - ZigbeeConfigBuffer.p_ZigbeeNotAckBuffer = (uint8_t *)ZigbeeNotifRspEvtBuffer; - ZigbeeConfigBuffer.p_ZigbeeLoggingBuffer = (uint8_t *)ZigbeeNotifLoggingBuffer; - TL_ZIGBEE_Init(&ZigbeeConfigBuffer); -} /* APP_ZIGBEE_TL_INIT */ + ZigbeeConfigBuffer.p_ZigbeeOtCmdRspBuffer = (uint8_t *)&ZigbeeOtCmdBuffer; + ZigbeeConfigBuffer.p_ZigbeeNotAckBuffer = (uint8_t *)ZigbeeNotifRspEvtBuffer; + ZigbeeConfigBuffer.p_ZigbeeNotifRequestBuffer = (uint8_t *)ZigbeeNotifRequestBuffer; + TL_ZIGBEE_Init(&ZigbeeConfigBuffer); +} /** * @brief Process the messages coming from the M0. * @param None * @retval None */ -void APP_ZIGBEE_ProcessMsgM0ToM4(void) +void APP_ZIGBEE_ProcessNotifyM0ToM4(void) { - if (CptReceiveMsgFromM0 != 0) { - /* If CptReceiveMsgFromM0 is > 1. it means that we did not serve all the events from the radio */ - if (CptReceiveMsgFromM0 > 1U) { - APP_ZIGBEE_Error(ERR_REC_MULTI_MSG_FROM_M0, 0); + if (CptReceiveNotifyFromM0 != 0) { + /* If CptReceiveNotifyFromM0 is > 1. it means that we did not serve all the events from the radio */ + if (CptReceiveNotifyFromM0 > 1U) { + APP_ZIGBEE_Error(ERR_REC_MULTI_MSG_FROM_M0, 0); + } + else { + Zigbee_CallBackProcessing(); + } + /* Reset counter */ + CptReceiveNotifyFromM0 = 0; } - else { - Zigbee_CallBackProcessing(); +} + +/** + * @brief Process the requests coming from the M0. + * @param + * @return + */ +void APP_ZIGBEE_ProcessRequestM0ToM4(void) +{ + if (CptReceiveRequestFromM0 != 0) { + Zigbee_M0RequestProcessing(); + CptReceiveRequestFromM0 = 0; } - /* Reset counter */ - CptReceiveMsgFromM0 = 0; - } -} /* APP_ZIGBEE_ProcessMsgM0ToM4 */ +} /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |