| /* |
| * |
| * Copyright (c) 2020 Project CHIP Authors |
| * Copyright (c) 2019 Google LLC. |
| * 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 <bsp.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include <stdarg.h> |
| #include <stdbool.h> |
| #include <stdint.h> |
| |
| #include <FreeRTOS.h> |
| #include <mbedtls/threading.h> |
| |
| #include <ChipShellCollection.h> |
| #include <lib/core/CHIPCore.h> |
| #include <lib/shell/Engine.h> |
| #include <lib/support/CHIPMem.h> |
| #include <lib/support/CHIPPlatformMemory.h> |
| #include <platform/CHIPDeviceLayer.h> |
| #include <platform/KeyValueStoreManager.h> |
| |
| #include "matter_shell.h" |
| #include <AppConfig.h> |
| #include <app/server/Server.h> |
| #include <init_efrPlatform.h> |
| #include <sl_system_kernel.h> |
| |
| #ifdef HEAP_MONITORING |
| #include "MemMonitoring.h" |
| #endif |
| |
| #if CHIP_ENABLE_OPENTHREAD |
| #include <mbedtls/platform.h> |
| #include <openthread/cli.h> |
| #include <openthread/dataset.h> |
| #include <openthread/error.h> |
| #include <openthread/heap.h> |
| #include <openthread/icmp6.h> |
| #include <openthread/instance.h> |
| #include <openthread/link.h> |
| #include <openthread/platform/openthread-system.h> |
| #include <openthread/tasklet.h> |
| #include <openthread/thread.h> |
| #endif // CHIP_ENABLE_OPENTHREAD |
| |
| using namespace ::chip; |
| using namespace ::chip::DeviceLayer; |
| using chip::Shell::Engine; |
| |
| // ================================================================================ |
| // Supporting functions |
| // ================================================================================ |
| |
| void appError(int err) |
| { |
| SILABS_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err); |
| portDISABLE_INTERRUPTS(); |
| while (true) |
| ; |
| } |
| |
| void appError(CHIP_ERROR error) |
| { |
| appError(static_cast<int>(error.AsInteger())); |
| } |
| |
| extern "C" void vApplicationIdleHook(void) |
| { |
| // FreeRTOS Idle callback |
| |
| // Check CHIP Config nvm3 and repack flash if necessary. |
| Internal::EFR32Config::RepackNvm3Flash(); |
| } |
| |
| // ================================================================================ |
| // Main Code |
| // ================================================================================ |
| |
| int main(void) |
| { |
| init_efrPlatform(); |
| mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); |
| |
| #ifdef HEAP_MONITORING |
| MemMonitoring::startHeapMonitoring(); |
| #endif |
| |
| SILABS_LOG("=================================================="); |
| SILABS_LOG("chip-efr32-shell-example starting"); |
| SILABS_LOG("=================================================="); |
| |
| SILABS_LOG("Init CHIP Stack"); |
| |
| // Init Chip memory management before the stack |
| chip::Platform::MemoryInit(); |
| |
| CHIP_ERROR ret = PlatformMgr().InitChipStack(); |
| if (ret != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("PlatformMgr().InitChipStack() failed"); |
| appError(ret); |
| } |
| chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("EFR32_SHELL"); |
| |
| SILABS_LOG("Starting Platform Manager Event Loop"); |
| ret = PlatformMgr().StartEventLoopTask(); |
| if (ret != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("PlatformMgr().StartEventLoopTask() failed"); |
| appError(ret); |
| } |
| |
| #if CHIP_ENABLE_OPENTHREAD |
| SILABS_LOG("Initializing OpenThread stack"); |
| ret = ThreadStackMgr().InitThreadStack(); |
| if (ret != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("ThreadStackMgr().InitThreadStack() failed"); |
| appError(ret); |
| } |
| |
| ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); |
| if (ret != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("ConnectivityMgr().SetThreadDeviceType() failed"); |
| appError(ret); |
| } |
| #endif // CHIP_ENABLE_OPENTHREAD |
| |
| #if CHIP_ENABLE_OPENTHREAD |
| SILABS_LOG("Starting OpenThread task"); |
| |
| // Start OpenThread task |
| ret = ThreadStackMgrImpl().StartThreadTask(); |
| if (ret != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("ThreadStackMgr().StartThreadTask() failed"); |
| appError(ret); |
| } |
| #endif // CHIP_ENABLE_OPENTHREAD |
| |
| chip::startShellTask(); |
| sl_system_kernel_start(); |
| } |