/* * * Copyright (c) 2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "AppTask.h" #include #include #include "FreeRTOS.h" #include #include #include #include #include #include #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR #include #include #include #include #include #endif #include #include #include #include #include /* syscfg */ #include #define APP_TASK_STACK_SIZE (4096) #define APP_TASK_PRIORITY 4 using namespace ::chip; using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; using chip::Shell::Engine; AppTask AppTask::sAppTask; Clusters::ModeSelect::StaticSupportedModesManager sStaticSupportedModesManager; static TaskHandle_t sAppTaskHandle; // Logging extern "C" { int cc13xx_26xxLogInit(void); } #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR static DefaultOTARequestor sRequestorCore; static DefaultOTARequestorStorage sRequestorStorage; static DefaultOTARequestorDriver sRequestorUser; static BDXDownloader sDownloader; static OTAImageProcessorImpl sImageProcessor; void InitializeOTARequestor(void) { // Initialize and interconnect the Requestor and Image Processor objects SetRequestorInstance(&sRequestorCore); sRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); sRequestorCore.Init(Server::GetInstance(), sRequestorStorage, sRequestorUser, sDownloader); sImageProcessor.SetOTADownloader(&sDownloader); sDownloader.SetImageProcessorDelegate(&sImageProcessor); sRequestorUser.Init(&sRequestorCore, &sImageProcessor); } #endif CHIP_ERROR AppTask::StartAppTask() { CHIP_ERROR err = CHIP_NO_ERROR; // Start App task. if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, APP_TASK_PRIORITY, &sAppTaskHandle) != pdPASS) { while (true) ; } return err; } CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; cc13xx_26xxLogInit(); // Init Chip memory management before the stack Platform::MemoryInit(); Engine::Root().Init(); CHIP_ERROR ret = PlatformMgr().InitChipStack(); if (ret != CHIP_NO_ERROR) { while (true) ; } ret = ThreadStackMgr().InitThreadStack(); if (ret != CHIP_NO_ERROR) { while (true) ; } #ifdef CHIP_CONFIG_ENABLE_ICD_SERVER ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice); #elif CONFIG_OPENTHREAD_MTD ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); #else ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); #endif if (ret != CHIP_NO_ERROR) { while (true) ; } ret = ThreadStackMgrImpl().StartThreadTask(); if (ret != CHIP_NO_ERROR) { while (true) ; } // Initialize device attestation config #ifdef CC13X4_26X4_ATTESTATION_CREDENTIALS #ifdef CC13XX_26XX_FACTORY_DATA SetDeviceInstanceInfoProvider(&mFactoryDataProvider); SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); SetCommissionableDataProvider(&mFactoryDataProvider); #else SetDeviceAttestationCredentialsProvider(CC13X4_26X4::GetCC13X4_26X4DacProvider()); #endif #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); ret = PlatformMgr().StartEventLoopTask(); if (ret != CHIP_NO_ERROR) { while (true) ; } #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); #endif Clusters::ModeSelect::setSupportedModesManager(&sStaticSupportedModesManager); return err; } void AppTask::AppTaskMain(void * pvParameter) { CHIP_ERROR err = sAppTask.Init(); if (err != CHIP_NO_ERROR) { while (true) ; } Engine::Root().RunMainLoop(); }