blob: 701e86fed40e05b67a208ce352c3c4f1d15fc095 [file] [log] [blame]
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2020 Texas Instruments Incorporated
* 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 <app/server/Server.h>
#include <lib/core/ErrorStr.h>
#include "FreeRTOS.h"
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <lib/support/ThreadOperationalDataset.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/internal/DeviceNetworkInfo.h>
#include <examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.h>
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <platform/cc13xx_26xx/OTAImageProcessorImpl.h>
#endif
#include <lib/shell/Engine.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <app/server/OnboardingCodesUtil.h>
/* syscfg */
#include <ti_drivers_config.h>
#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;
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)
;
}
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
if (ret != CHIP_NO_ERROR)
{
while (true)
;
}
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
while (true)
;
}
ret = ThreadStackMgrImpl().StartThreadTask();
if (ret != CHIP_NO_ERROR)
{
while (true)
;
}
// Initialize device attestation config
#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS
#ifdef CC13XX_26XX_FACTORY_DATA
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);
SetCommissionableDataProvider(&mFactoryDataProvider);
#else
SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider());
#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);
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
InitializeOTARequestor();
#endif
return err;
}
void AppTask::AppTaskMain(void * pvParameter)
{
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
while (true)
;
}
Engine::Root().RunMainLoop();
}