From 746153d3baa589a7578cbf76852140d18f8d02c1 Mon Sep 17 00:00:00 2001 From: abiradarti <104591549+abiradarti@users.noreply.github.com> Date: Tue, 28 Jun 2022 09:19:03 -0500 Subject: [PATCH] [TI] initial cc32xx support (#18822) * inital cc32xx commit Co-authored-by: Suyash Jain Co-authored-by: Kobi Leibovitch * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Restyled by prettier-markdown * check-spellcheck and misspell fixes * Restyled by gn * Restyled by prettier-markdown * added terms to .wordlist * backticks for code terms * dummy commit * dummy commit Co-authored-by: Suyash Jain Co-authored-by: Kobi Leibovitch Co-authored-by: Restyled.io Co-authored-by: Andrei Litvin --- .github/.wordlist.txt | 2 + .gitmodules | 5 + .vscode/settings.json | 6 +- config/cc32xx/toolchain/BUILD.gn | 25 + examples/lock-app/cc32xx/.gn | 28 + examples/lock-app/cc32xx/BUILD.gn | 119 ++++ examples/lock-app/cc32xx/README.md | 196 ++++++ examples/lock-app/cc32xx/args.gni | 43 ++ examples/lock-app/cc32xx/build_overrides | 1 + examples/lock-app/cc32xx/chip.syscfg | 74 +++ examples/lock-app/cc32xx/main/AppConfig.h | 34 ++ examples/lock-app/cc32xx/main/AppEvent.h | 60 ++ examples/lock-app/cc32xx/main/AppTask.cpp | 304 ++++++++++ examples/lock-app/cc32xx/main/AppTask.h | 78 +++ .../lock-app/cc32xx/main/BoltLockManager.cpp | 206 +++++++ .../lock-app/cc32xx/main/BoltLockManager.h | 87 +++ .../cc32xx/main/CXXExceptionStubs.cpp | 80 +++ .../lock-app/cc32xx/main/ZclCallbacks.cpp | 56 ++ .../lock-app/cc32xx/main/cc32xxWifiInit.c | 243 ++++++++ .../lock-app/cc32xx/main/debug_settings.h | 42 ++ .../cc32xx/main/include/CHIPProjectConfig.h | 150 +++++ examples/lock-app/cc32xx/main/main.cpp | 76 +++ examples/lock-app/cc32xx/main/wifi_settings.h | 103 ++++ .../cc32xx/third_party/connectedhomeip | 1 + examples/platform/cc32xx/BUILD.gn | 19 + examples/platform/cc32xx/args.gni | 23 + scripts/checkout_submodules.py | 1 + src/lwip/BUILD.gn | 16 +- src/lwip/cc32xx/arch/cc.h | 98 +++ src/lwip/cc32xx/arch/perf.h | 35 ++ src/lwip/cc32xx/lwipopts.h | 175 ++++++ src/lwip/cc32xx/lwippools.h | 2 + src/platform/BUILD.gn | 7 + src/platform/cc32xx/BUILD.gn | 63 ++ src/platform/cc32xx/BlePlatformConfig.h | 31 + src/platform/cc32xx/CC32XXConfig.cpp | 559 ++++++++++++++++++ src/platform/cc32xx/CC32XXConfig.h | 101 ++++ .../cc32xx/CHIPDevicePlatformConfig.h | 47 ++ src/platform/cc32xx/CHIPDevicePlatformEvent.h | 46 ++ src/platform/cc32xx/CHIPPlatformConfig.h | 89 +++ .../cc32xx/ConfigurationManagerImpl.cpp | 201 +++++++ .../cc32xx/ConfigurationManagerImpl.h | 73 +++ .../cc32xx/ConnectivityManagerImpl.cpp | 239 ++++++++ src/platform/cc32xx/ConnectivityManagerImpl.h | 168 ++++++ .../DeviceNetworkProvisioningDelegateImpl.cpp | 44 ++ .../DeviceNetworkProvisioningDelegateImpl.h | 43 ++ .../cc32xx/DiagnosticDataProviderImpl.cpp | 60 ++ .../cc32xx/DiagnosticDataProviderImpl.h | 46 ++ src/platform/cc32xx/FreeRTOSConfig.h | 212 +++++++ src/platform/cc32xx/InetPlatformConfig.h | 51 ++ .../cc32xx/KeyValueStoreManagerImpl.cpp | 66 +++ .../cc32xx/KeyValueStoreManagerImpl.h | 75 +++ src/platform/cc32xx/Logging.cpp | 151 +++++ src/platform/cc32xx/PlatformManagerImpl.cpp | 92 +++ src/platform/cc32xx/PlatformManagerImpl.h | 90 +++ src/platform/cc32xx/README.md | 83 +++ .../cc32xx/SoftwareUpdateManagerImpl.cpp | 41 ++ src/platform/cc32xx/SystemPlatformConfig.h | 54 ++ src/platform/cc32xx/args.gni | 36 ++ src/platform/cc32xx/cc32xx-mbedtls-config.h | 99 ++++ src/platform/device.gni | 18 +- third_party/ti_simplelink_sdk/BUILD.gn | 71 ++- third_party/ti_simplelink_sdk/repo_cc32xx | 1 + .../ti_simplelink_arm_platform_config.gni | 7 + .../ti_simplelink_sdk/ti_simplelink_board.gni | 14 + .../ti_simplelink_executable.gni | 30 +- .../ti_simplelink_sdk/ti_simplelink_sdk.gni | 194 +++--- 67 files changed, 5475 insertions(+), 115 deletions(-) create mode 100755 config/cc32xx/toolchain/BUILD.gn create mode 100644 examples/lock-app/cc32xx/.gn create mode 100755 examples/lock-app/cc32xx/BUILD.gn create mode 100644 examples/lock-app/cc32xx/README.md create mode 100755 examples/lock-app/cc32xx/args.gni create mode 120000 examples/lock-app/cc32xx/build_overrides create mode 100755 examples/lock-app/cc32xx/chip.syscfg create mode 100755 examples/lock-app/cc32xx/main/AppConfig.h create mode 100755 examples/lock-app/cc32xx/main/AppEvent.h create mode 100644 examples/lock-app/cc32xx/main/AppTask.cpp create mode 100755 examples/lock-app/cc32xx/main/AppTask.h create mode 100644 examples/lock-app/cc32xx/main/BoltLockManager.cpp create mode 100755 examples/lock-app/cc32xx/main/BoltLockManager.h create mode 100755 examples/lock-app/cc32xx/main/CXXExceptionStubs.cpp create mode 100644 examples/lock-app/cc32xx/main/ZclCallbacks.cpp create mode 100644 examples/lock-app/cc32xx/main/cc32xxWifiInit.c create mode 100644 examples/lock-app/cc32xx/main/debug_settings.h create mode 100644 examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h create mode 100644 examples/lock-app/cc32xx/main/main.cpp create mode 100644 examples/lock-app/cc32xx/main/wifi_settings.h create mode 120000 examples/lock-app/cc32xx/third_party/connectedhomeip create mode 100644 examples/platform/cc32xx/BUILD.gn create mode 100644 examples/platform/cc32xx/args.gni create mode 100644 src/lwip/cc32xx/arch/cc.h create mode 100644 src/lwip/cc32xx/arch/perf.h create mode 100644 src/lwip/cc32xx/lwipopts.h create mode 100644 src/lwip/cc32xx/lwippools.h create mode 100644 src/platform/cc32xx/BUILD.gn create mode 100644 src/platform/cc32xx/BlePlatformConfig.h create mode 100644 src/platform/cc32xx/CC32XXConfig.cpp create mode 100644 src/platform/cc32xx/CC32XXConfig.h create mode 100644 src/platform/cc32xx/CHIPDevicePlatformConfig.h create mode 100644 src/platform/cc32xx/CHIPDevicePlatformEvent.h create mode 100644 src/platform/cc32xx/CHIPPlatformConfig.h create mode 100644 src/platform/cc32xx/ConfigurationManagerImpl.cpp create mode 100644 src/platform/cc32xx/ConfigurationManagerImpl.h create mode 100644 src/platform/cc32xx/ConnectivityManagerImpl.cpp create mode 100644 src/platform/cc32xx/ConnectivityManagerImpl.h create mode 100644 src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.cpp create mode 100644 src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.h create mode 100644 src/platform/cc32xx/DiagnosticDataProviderImpl.cpp create mode 100644 src/platform/cc32xx/DiagnosticDataProviderImpl.h create mode 100644 src/platform/cc32xx/FreeRTOSConfig.h create mode 100644 src/platform/cc32xx/InetPlatformConfig.h create mode 100644 src/platform/cc32xx/KeyValueStoreManagerImpl.cpp create mode 100644 src/platform/cc32xx/KeyValueStoreManagerImpl.h create mode 100644 src/platform/cc32xx/Logging.cpp create mode 100644 src/platform/cc32xx/PlatformManagerImpl.cpp create mode 100644 src/platform/cc32xx/PlatformManagerImpl.h create mode 100644 src/platform/cc32xx/README.md create mode 100644 src/platform/cc32xx/SoftwareUpdateManagerImpl.cpp create mode 100644 src/platform/cc32xx/SystemPlatformConfig.h create mode 100755 src/platform/cc32xx/args.gni create mode 100755 src/platform/cc32xx/cc32xx-mbedtls-config.h create mode 160000 third_party/ti_simplelink_sdk/repo_cc32xx diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index 2157009d71b213..cfaa48864f70e3 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -100,6 +100,7 @@ auth AuthMode autoApplyImage autocompletion +AutoConf autoconnect autocrlf autogenerated @@ -1304,6 +1305,7 @@ trackFree TransferSession transitionTime TransportMgrBase +TRNG TrustedRootCertificates tsan TSG diff --git a/.gitmodules b/.gitmodules index cff8b82bb73661..f19fe86fa2da4d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -237,6 +237,11 @@ url = https://github.com/bouffalolab/bl_iot_sdk_matter.git branch = bl602_release platforms = bl602 +[submodule "third_party/ti_simplelink_sdk/repo_cc32xx"] + path = third_party/ti_simplelink_sdk/repo_cc32xx + url = https://github.com/TexasInstruments/cc32xx_open_sdk.git + branch = main + platform = cc32xx [submodule "third_party/nxp/mw320_sdk/repo"] path = third_party/nxp/mw320_sdk/repo url = https://github.com/nxptest/mw320_sdk diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ff631080c2465..ac8bf404d4ec08 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -111,7 +111,11 @@ "ratio": "cpp", "set": "cpp", "stack": "cpp", - "regex": "cpp" + "regex": "cpp", + "condition_variable": "cpp", + "numeric": "cpp", + "random": "cpp", + "thread": "cpp" }, "files.eol": "\n", "editor.formatOnSave": true, diff --git a/config/cc32xx/toolchain/BUILD.gn b/config/cc32xx/toolchain/BUILD.gn new file mode 100755 index 00000000000000..1e7d672c67bd6d --- /dev/null +++ b/config/cc32xx/toolchain/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni") + +arm_toolchain("cc32xx_lock_app") { + toolchain_args = { + current_os = "freertos" + import("${chip_root}/examples/lock-app/cc32xx/args.gni") + } +} diff --git a/examples/lock-app/cc32xx/.gn b/examples/lock-app/cc32xx/.gn new file mode 100644 index 00000000000000..3d48789e30ab3d --- /dev/null +++ b/examples/lock-app/cc32xx/.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + target_os = "freertos" + + import("//args.gni") +} diff --git a/examples/lock-app/cc32xx/BUILD.gn b/examples/lock-app/cc32xx/BUILD.gn new file mode 100755 index 00000000000000..d8fd3d4cceeef8 --- /dev/null +++ b/examples/lock-app/cc32xx/BUILD.gn @@ -0,0 +1,119 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") +import("//build_overrides/ti_simplelink_sdk.gni") +import("${build_root}/config/defaults.gni") +import("${chip_root}/src/platform/device.gni") +import("${ti_simplelink_sdk_build_root}/ti_simplelink_executable.gni") +import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni") + +assert(current_os == "freertos") + +project_dir = "${chip_root}/examples/lock-app/cc32xx" + +ti_simplelink_sdk("sdk") { + include_dirs = [ "${project_dir}/main/include" ] + + defines = [] + if (is_debug) { + defines += [ "BUILD_RELEASE=0" ] + } else { + defines += [ "BUILD_RELEASE=1" ] + } +} + +ti_sysconfig("sysconfig") { + sources = [ "${project_dir}/chip.syscfg" ] + outputs = [ + "ti_drivers_net_wifi_config.c", + "ti_net_config.c", + "ti_drivers_config.c", + "ti_drivers_config.h", + ] +} + +source_set("lock_app_sdk") { + defines = [] + + configs -= [ "${build_root}/config/compiler:std_default" ] + configs += [ ":sdk_posix_config" ] + + sources = [ + "${chip_root}/src/platform/cc32xx/Logging.cpp", + "${project_dir}/main/cc32xxWifiInit.c", + "${project_dir}/main/main.cpp", + "${ti_simplelink_sdk_root}/examples/rtos/common/ifmod/lwip_if.c", + "${ti_simplelink_sdk_root}/examples/rtos/common/ifmod/utils_if.c", + "${ti_simplelink_sdk_root}/examples/rtos/common/ifmod/wifi_if.c", + ] + + include_dirs = [ + "${project_dir}/include", + "${project_dir}/main", + "${project_dir}/main/ifmod/", + "${chip_root}/src/platform/cc32xx", + ] + + deps = [ + ":sdk", + ":sysconfig", + "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/src/lib", + "${chip_root}/src/setup_payload", + ] +} + +ti_simplelink_executable("lock_app") { + defines = [] + output_name = "chip-${ti_simplelink_board}-lock-example.out" + + sources = [ + "${project_dir}/main/AppTask.cpp", + "${project_dir}/main/BoltLockManager.cpp", + "${project_dir}/main/CXXExceptionStubs.cpp", + "${project_dir}/main/ZclCallbacks.cpp", + ] + + deps = [ + ":lock_app_sdk", + ":sdk", + ":sysconfig", + "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/src/lib", + "${chip_root}/src/setup_payload", + ] + + include_dirs = [ + "${project_dir}", + "${project_dir}/main", + ] + + cflags = [ + "-Wno-implicit-fallthrough", + "-Wno-sign-compare", + "-Wconversion", + ] + + output_dir = root_out_dir +} + +group("cc32xx") { + deps = [ ":lock_app" ] +} + +group("default") { + deps = [ ":cc32xx" ] +} diff --git a/examples/lock-app/cc32xx/README.md b/examples/lock-app/cc32xx/README.md new file mode 100644 index 00000000000000..c1474a096a6b25 --- /dev/null +++ b/examples/lock-app/cc32xx/README.md @@ -0,0 +1,196 @@ +# Matter `CC32XXSF` Lock Example Application + +An example application showing the use of [Matter][matter] on the Texas +Instruments CC32XX family of Wireless MCUs. + +--- + +- [Matter CC32XX Lock Example Application](#matter-cc32xx-lock-example-application) + - [Introduction](#introduction) + - [Device UI](#device-ui) + - [Building](#building) + - [Preparation](#preparation) + - [Compilation](#compilation) + - [Programming](#programming) + - [Code Composer Studio](#code-composer-studio) + - [UniFlash](#uniflash) + - [Viewing Logging Output](#viewing-logging-output) + - [Running the Example](#running-the-example) + - [Provisioning](#provisioning) + - [Matter Remote Commands](#matter-remote-commands) + - [TI Support](#ti-support) + +--- + +## Introduction + +![CC3235SF_LAUNCHXL](doc/images/cc3235sf_launchxl.jpg) + +The CC32XX lock example application provides a working demonstration of a +connected door lock device. This uses the open-source CHIP implementation and +the Texas Instruments SimpleLinkā„¢ Wi-FiĀ® CC32xx software development kit. + +By default this example targets the [CC3235SF_LAUNCHXL][cc3235sf_launchxl] +LaunchPad, but the example application is enabled to build on the whole `CC32XX` +family of MCUs. + +The lock example is intended to serve both as a means to explore the workings of +CHIP, as well as a template for creating real products based on the Texas +Instruments devices. + +## Device UI + +This example application has a simple User Interface to depict the state of the +door lock and to control the state. The user LEDs on the LaunchPad are set on +when the lock is locked, and are set off when unlocked. The LEDs will flash when +in the transition state between locked and unlocked. The user buttons are used +for requesting lock and unlock of the door lock. The left button (`BTN-1`) is +used to enable provisioning (provisioning is enabled as "oneshot" by default. +The right button (`BTN-2`) us used to toggle the "Lock" state. + +## Building + +### Preparation + +Some initial setup is necessary for preparing the build environment. This +section will need to be done when migrating to new versions of the SDK. This +guide assumes that the environment is linux based, and recommends Ubuntu 20.04. + +- Download and install [SysConfig][sysconfig] ([recommended + version][sysconfig_recommended]). This can be done simply with the following + commands. + + ``` + $ cd ~ + $ wget https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.12.1_2446-setup.run + $ chmod +x sysconfig-1.12.1_2446-setup.run + $ ./sysconfig-1.12.1_2446-setup.run + ``` + +- Run the bootstrap script to setup the build environment. + + ``` + $ cd ~/connectedhomeip + $ source ./scripts/bootstrap.sh + ``` + +### Compilation + +It is necessary to activate the environment in every new shell. Then run GN and +Ninja to build the executable. + +- Activate the build environment with the repository activate script. + + ``` + $ cd ~/connectedhomeip + $ source ./scripts/activate.sh + ``` + +- Run the build to produce a default executable. By default on Linux the + Sysconfig is located in a `ti` folder in the user's home directory, and you + must provide the absolute path for it. For example + `/home/username/ti/sysconfig_1.12.1`. On Windows the default directory is + `C:\ti`. Take note of this install path, as it will be used in the next + step. + + + ``` + $ cd ~/connectedhomeip/examples/lock-app/cc32xx + $ gn gen out/debug --args="ti_sysconfig_root=\"$HOME/ti/sysconfig_1.12.1\"" + $ ninja -C out/debug + ``` + +## Programming + +Loading the built image onto a LaunchPad is supported through Code Composer +Studio (CCS). Code Composer Studio can be used to load the image and debug the +source code. UniFlash programming (bin) image is not generated currently. + +### Code Composer Studio + +Programming with CCS will allow for a full debug environment within the IDE. +This is accomplished by creating a target connection to the XDS110 debugger and +starting a project-less debug session. The CCS IDE will attempt to find the +source files on the local machine based on the debug information embedded within +the ELF. CCS may prompt you to find the source code if the image was built on +another machine or the source code is located in a different location than is +recorded within the ELF. + +Download and install [Code Composer Studio][ccs]. + +First open CCS and create a new workspace. + +Create a target connection (sometimes called the CCXML) for your target SoC and +debugger as described in the [Manual Method][ccs_manual_method] section of the +CCS User's Guide. + +Next initiate a project-less debug session as described in the [Manual +Launch][ccs_manual_launch] section of the CCS User's Guide. + +CCS should switch to the debug view described in the [After +Launch][ccs_after_launch] section of the User's Guide. The SoC core will likely +be disconnected and symbols will not be loaded. Connect to the core as described +in the [Debug View][ccs_debug_view] section of the User's Guide. Once the core +is connected, use the `Load` button on the toolbar to load the ELF image. + +Note that the default configuration of the CCXML uses 2-wire cJTAG instead of +the full 4-wire JTAG connection to match the default jumper configuration of the +LaunchPad. + +## Viewing Logging Output + +By default the log output will be sent to the Application/User UART. Open a +terminal emulator to that port to see the output with the following options: + +| Parameter | Value | +| ------------ | -------- | +| Speed (baud) | `115200` | +| Data bits | `8` | +| Stop bits | `1` | +| Parity | `None` | +| Flow control | `None` | + +## Running the Example + +### Provisioning + +The first step to bring the Matter device onto the network is to provision it. +The example accomplishes this through the proprietary SimpleLink provisioning +method (AP or Smart Config) using the SimpleLink Starter Pro mobile app. Once +the device is connected to the local AP, commissioning can be triggered using +"OnNetwork" configuration. + +#### Bluetooth LE Provisioning + +BLE provisioning is not supported currently. + +### CHIP tool changes needed for Wi-Fi example + +The timeout for the CHIP tool needs to be increased from 10 to 15 seconds. This +can be done in `chip::System::Clock::Timeout GetWaitDuration` in +`connectedhomeip/examples/chip-tool/commands/clusters/ModelCommand.h` + +## TI Support + +For technical support, please consider creating a post on TI's [E2E forum][e2e]. +Additionally, we welcome any feedback. + +[matter]: https://github.com/project-chip/connectedhomeip +[ccs]: https://www.ti.com/tool/CCSTUDIO +[ccs_after_launch]: + https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#after-launch +[ccs_debug_view]: + https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#debug-view +[ccs_manual_launch]: + https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#manual-launch +[ccs_manual_method]: + https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html?configuration#manual-method +[cc3235sf_launchxl]: https://www.ti.com/tool/LAUNCHXL-CC3235SF +[e2e]: + https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum +[sysconfig]: https://www.ti.com/tool/SYSCONFIG +[sysconfig_recommended]: + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.12.1_2446-setup.run +[ti_cc32xx_matter_request]: + https://www.ti.com/tool/download/SIMPLELINK-CC32XX-SDK/5.30.00.08 +[uniflash]: https://www.ti.com/tool/download/UNIFLASH diff --git a/examples/lock-app/cc32xx/args.gni b/examples/lock-app/cc32xx/args.gni new file mode 100755 index 00000000000000..8d5afa600c2067 --- /dev/null +++ b/examples/lock-app/cc32xx/args.gni @@ -0,0 +1,43 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") +import("${chip_root}/examples/platform/cc32xx/args.gni") + +ti_simplelink_sdk_target = get_label_info(":sdk", "label_no_toolchain") +ti_simplelink_sysconfig_target = + get_label_info(":sysconfig", "label_no_toolchain") + +ti_simplelink_board = "CC3235SF_LAUNCHXL" + +# use -Os instead of -Og +#is_debug = false + +# disable BLE for now +chip_config_network_layer_ble = false +chip_bypass_rendezvous = false + +#enable logging +chip_progress_logging = true +chip_detail_logging = true +chip_automation_logging = true + +## Disable lock tracking, since our FreeRTOS configuration does not set +# INCLUDE_xSemaphoreGetMutexHolder +chip_stack_lock_tracking = "none" + +matter_device_vid = "0xFFF1" +matter_device_pid = "0x8006" +matter_software_ver = "0x0001" +matter_software_ver_str = "1.0d1" diff --git a/examples/lock-app/cc32xx/build_overrides b/examples/lock-app/cc32xx/build_overrides new file mode 120000 index 00000000000000..194ee0b812dc3d --- /dev/null +++ b/examples/lock-app/cc32xx/build_overrides @@ -0,0 +1 @@ +../../build_overrides/ \ No newline at end of file diff --git a/examples/lock-app/cc32xx/chip.syscfg b/examples/lock-app/cc32xx/chip.syscfg new file mode 100755 index 00000000000000..14fd3130d99c4f --- /dev/null +++ b/examples/lock-app/cc32xx/chip.syscfg @@ -0,0 +1,74 @@ +/** + * Import the modules used in this configuration. + */ +const Display = scripting.addModule("/ti/display/Display"); +const Display1 = Display.addInstance(); +const SPI = scripting.addModule("/ti/drivers/SPI"); +const Button = scripting.addModule("/ti/drivers/apps/Button"); +const Button1 = Button.addInstance(); +const Button2 = Button.addInstance(); +const LED = scripting.addModule("/ti/drivers/apps/LED"); +const LED1 = LED.addInstance(); +const LED2 = LED.addInstance(); +const LED3 = LED.addInstance(); +const SimpleLinkWifi = scripting.addModule("/ti/drivers/net/wifi/SimpleLinkWifi"); +const net_utils = scripting.addModule("/ti/drivers/net/wifi/net_utils", {}, false); +const net_utils1 = net_utils.addInstance(); +const HTTPClient = scripting.addModule("/ti/net/HTTPClient", {}, false); +const HTTPClient1 = HTTPClient.addInstance(); +const MQTT = scripting.addModule("/ti/net/MQTT", {}, false); +const MQTT1 = MQTT.addInstance(); +const SNTP = scripting.addModule("/ti/net/SNTP"); +const SlNet = scripting.addModule("/ti/net/SlNet", {}, false); +const SlNet1 = SlNet.addInstance(); + +/** + * Write custom configuration values to the imported modules. + */ +Display1.$name = "CONFIG_Display_0"; +Display1.$hardware = system.deviceData.board.components.XDS110UART; +Display1.uart.$name = "CONFIG_UART2_0"; + +const Power = scripting.addModule("/ti/drivers/Power", {}, false); +Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0"; + +Button1.$hardware = system.deviceData.board.components.SW2; +Button1.$name = "CONFIG_BTN_LEFT"; + +Button2.$hardware = system.deviceData.board.components.SW3; +Button2.$name = "CONFIG_BTN_RIGHT"; + +LED1.$hardware = system.deviceData.board.components.LED_BLUE; +LED1.$name = "CONFIG_LED_BLUE"; + +LED2.$hardware = system.deviceData.board.components.LED_GREEN; +LED2.$name = "CONFIG_LED_GREEN"; + +LED3.$hardware = system.deviceData.board.components.LED_RED; +LED3.dimmable = true; +LED3.$name = "CONFIG_LED_RED"; + +net_utils1.$name = "CONFIG_NET_UTILS_0"; + +HTTPClient1.$name = "CONFIG_HTTPCLIENT_0"; + +MQTT1.$name = "CONFIG_MQTT_0"; + +SlNet1.$name = "CONFIG_SLNET_0"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +Display1.uart.uart.$suggestSolution = "UART1"; +Display1.uart.uart.txPin.$suggestSolution = "ball.55"; +Display1.uart.uart.txDmaChannel.$suggestSolution = "UDMA_CH11"; +Display1.uart.uart.rxPin.$suggestSolution = "ball.57"; +Display1.uart.uart.rxDmaChannel.$suggestSolution = "UDMA_CH10"; +Button1.button.$suggestSolution = "boosterpack.3"; +Button2.button.$suggestSolution = "boosterpack.11"; +LED1.ledPin.$suggestSolution = "boosterpack.29"; +LED2.ledPin.$suggestSolution = "boosterpack.10"; +LED3.pwmPin.timer.$suggestSolution = "Timer3"; +LED3.pwmPin.timer.pwmPin.$suggestSolution = "boosterpack.9"; diff --git a/examples/lock-app/cc32xx/main/AppConfig.h b/examples/lock-app/cc32xx/main/AppConfig.h new file mode 100755 index 00000000000000..8eeee7fb61e3ed --- /dev/null +++ b/examples/lock-app/cc32xx/main/AppConfig.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef APP_CONFIG_H +#define APP_CONFIG_H + +// Logging +#ifdef __cplusplus +extern "C" { +#endif + +int cc32xxLogInit(void); +void cc32xxLog(const char * aFormat, ...); +#define PLAT_LOG(...) cc32xxLog(__VA_ARGS__); + +#ifdef __cplusplus +} +#endif +#endif // APP_CONFIG_H diff --git a/examples/lock-app/cc32xx/main/AppEvent.h b/examples/lock-app/cc32xx/main/AppEvent.h new file mode 100755 index 00000000000000..ad9e93ee3ad1a5 --- /dev/null +++ b/examples/lock-app/cc32xx/main/AppEvent.h @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2018 Nest Labs, Inc. + * 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. + */ + +#ifndef APP_EVENT_H +#define APP_EVENT_H + +struct AppEvent; +typedef void (*EventHandler)(AppEvent *); + +struct AppEvent +{ + enum AppEventType + { + kEventType_None = 0, + kEventType_ButtonLeft, + kEventType_ButtonRight, + kEventType_AppEvent, + }; + + enum AppEventButtonType + { + kAppEventButtonType_None = 0, + kAppEventButtonType_Clicked, + kAppEventButtonType_LongClicked, + }; + + enum AppEventType Type; + + union + { + struct + { + enum AppEventButtonType Type; + } ButtonEvent; + + struct + { + void * Context; + } BoltLockEvent; + }; + + EventHandler Handler; +}; + +#endif // APP_EVENT_H diff --git a/examples/lock-app/cc32xx/main/AppTask.cpp b/examples/lock-app/cc32xx/main/AppTask.cpp new file mode 100644 index 00000000000000..18196a25b751aa --- /dev/null +++ b/examples/lock-app/cc32xx/main/AppTask.cpp @@ -0,0 +1,304 @@ +/* + * + * Copyright (c) 2020 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 "AppConfig.h" +#include "AppEvent.h" +#include +#include +#include +#include + +#include "FreeRTOS.h" + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +/* syscfg */ +#include + +extern "C" { +extern int WiFi_init(); +extern void DisplayBanner(); +} + +/* Application Version and Naming*/ + +#define APP_TASK_STACK_SIZE (4096) +#define APP_TASK_PRIORITY 4 +#define APP_EVENT_QUEUE_SIZE 10 + +// Added the below three for DNS Server Initialization +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::System; + +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; + +static TaskHandle_t sAppTaskHandle; +static QueueHandle_t sAppEventQueue; + +extern LED_Handle gLedGreenHandle, gLedRedHandle; +static Button_Handle gButtonRightHandle; + +AppTask AppTask::sAppTask; + +int AppTask::StartAppTask() +{ + int ret = 0; + + sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent)); + if (sAppEventQueue == NULL) + { + PLAT_LOG("Failed to allocate app event queue"); + while (1) + ; + } + + // Start App task. + if (xTaskCreate(AppTaskMain, "APP", APP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, APP_TASK_PRIORITY, &sAppTaskHandle) != + pdPASS) + { + PLAT_LOG("Failed to create app task"); + while (1) + ; + } + return ret; +} + +int AppTask::Init() +{ + CHIP_ERROR ret; + LED_Params ledParams; + Button_Params buttonParams; + + cc32xxLogInit(); + + /* Initial Terminal, and print Application name */ + DisplayBanner(); + + // Init Chip memory management before the stack + PLAT_LOG("Initialize Memory"); + chip::Platform::MemoryInit(); + + // Initialize LEDs + PLAT_LOG("Initialize LEDs"); + LED_init(); + + LED_Params_init(&ledParams); // default PWM LED + gLedRedHandle = LED_open(CONFIG_LED_RED, &ledParams); + LED_setOff(gLedRedHandle); + + LED_Params_init(&ledParams); // default PWM LED + gLedGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams); + LED_setOff(gLedGreenHandle); + + // Initialize buttons + PLAT_LOG("Initialize buttons"); + Button_init(); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + gButtonRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(gButtonRightHandle, ButtonRightEventHandler); + + PLAT_LOG("Initialize Wi-Fi"); + WiFi_init(); + + PLAT_LOG("Initialize CHIP stack"); + ret = PlatformMgr().InitChipStack(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("PlatformMgr().InitChipStack() failed"); + while (1) + ; + } + PLAT_LOG("Start Event Loop Task"); + ret = PlatformMgr().StartEventLoopTask(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("PlatformMgr().StartEventLoopTask() failed"); + while (1) + ; + } + + // Init ZCL Data Model and start server + PLAT_LOG("Initialize Server"); + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + + // Initialize device attestation config + PLAT_LOG("Initialize device attestation config"); + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + + // Initialize BoltLock module + PLAT_LOG("Initialize BoltLock"); + BoltLockMgr().Init(); + + BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + + ConfigurationMgr().LogDeviceConfig(); + + // QR code will be used with CHIP Tool + PLAT_LOG("Print Onboarding Codes"); + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kOnNetwork)); + + PLAT_LOG("Start DNS Server"); + chip::app::DnssdServer::Instance().StartServer(); + + return 0; +} + +void AppTask::AppTaskMain(void * pvParameter) +{ + AppEvent event; + + sAppTask.Init(); + + while (1) + { + /* Task pend until we have stuff to do */ + if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE) + { + sAppTask.DispatchEvent(&event); + } + } +} + +void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask events) +{ + AppEvent event; + event.Type = AppEvent::kEventType_ButtonRight; + + if (events & Button_EV_CLICKED) + { + event.ButtonEvent.Type = AppEvent::kAppEventButtonType_Clicked; + } + else if (events & Button_EV_LONGCLICKED) + { + event.ButtonEvent.Type = AppEvent::kAppEventButtonType_LongClicked; + } + // button callbacks are in ISR context + if (xQueueSendFromISR(sAppEventQueue, &event, NULL) != pdPASS) + { + /* Failed to post the message */ + } +} + +void AppTask::PostEvent(const AppEvent * aEvent) +{ + if (xQueueSend(sAppEventQueue, aEvent, 0) != pdPASS) + { + /* Failed to post the message */ + } +} + +void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor) +{ + // If the action has been initiated by the lock, update the bolt lock trait + // and start flashing the LEDs rapidly to indicate action initiation. + if (aAction == BoltLockManager::LOCK_ACTION) + { + PLAT_LOG("Lock initiated"); + ; // TODO + } + else if (aAction == BoltLockManager::UNLOCK_ACTION) + { + PLAT_LOG("Unlock initiated"); + ; // TODO + } + + LED_setOn(gLedGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(gLedGreenHandle, 50 /* ms */, LED_BLINK_FOREVER); + LED_setOn(gLedRedHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(gLedRedHandle, 110 /* ms */, LED_BLINK_FOREVER); +} + +void AppTask::ActionCompleted(BoltLockManager::Action_t aAction) +{ + uint8_t state; + + // if the action has been completed by the lock, update the bolt lock trait. + // Turn on the lock LED if in a LOCKED state OR + // Turn off the lock LED if in an UNLOCKED state. + if (aAction == BoltLockManager::LOCK_ACTION) + { + PLAT_LOG("Lock completed"); + LED_stopBlinking(gLedGreenHandle); + LED_setOn(gLedGreenHandle, LED_BRIGHTNESS_MAX); + LED_stopBlinking(gLedRedHandle); + LED_setOn(gLedRedHandle, LED_BRIGHTNESS_MAX); + state = 1; + } + else if (aAction == BoltLockManager::UNLOCK_ACTION) + { + PLAT_LOG("Unlock completed"); + LED_stopBlinking(gLedGreenHandle); + LED_setOff(gLedGreenHandle); + LED_stopBlinking(gLedRedHandle); + LED_setOff(gLedRedHandle); + state = 0; + } + emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, &state, ZCL_BOOLEAN_ATTRIBUTE_TYPE); +} + +void AppTask::DispatchEvent(AppEvent * aEvent) +{ + switch (aEvent->Type) + { + case AppEvent::kEventType_ButtonRight: + if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) + { + if (BoltLockMgr().IsUnlocked()) + { + BoltLockMgr().InitiateAction(0, BoltLockManager::LOCK_ACTION); + } + else + { + BoltLockMgr().InitiateAction(0, BoltLockManager::UNLOCK_ACTION); + } + } + break; + + case AppEvent::kEventType_AppEvent: + if (NULL != aEvent->Handler) + { + // XXX: assume our caller isn't trying to crash our stack + aEvent->Handler(aEvent); + } + break; + + case AppEvent::kEventType_None: + default: + break; + } +} diff --git a/examples/lock-app/cc32xx/main/AppTask.h b/examples/lock-app/cc32xx/main/AppTask.h new file mode 100755 index 00000000000000..803db3d30c9362 --- /dev/null +++ b/examples/lock-app/cc32xx/main/AppTask.h @@ -0,0 +1,78 @@ +/* + * 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. + */ + +#ifndef APP_TASK_H +#define APP_TASK_H + +#include +#include + +#include "FreeRTOS.h" +#include "semphr.h" +#include "task.h" + +#include "AppEvent.h" +#include "BoltLockManager.h" + +#include + +class AppTask +{ +public: + int StartAppTask(); + static void AppTaskMain(void * pvParameter); + + void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction); + void PostEvent(const AppEvent * event); + +private: + friend AppTask & GetAppTask(void); + + int Init(); + + // should this be done by BoltLock Manager? I don't want to unravel this spaghetti quite yet + static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor); + static void ActionCompleted(BoltLockManager::Action_t aAction); + + void DispatchEvent(AppEvent * event); + + static void ButtonRightEventHandler(Button_Handle handle, Button_EventMask events); + + static void TimerEventHandler(void * p_context); + + enum Function_t + { + kFunction_NoneSelected = 0, + kFunction_SoftwareUpdate = 0, + kFunction_FactoryReset, + + kFunction_Invalid + } Function; + + Function_t mFunction; + bool mFunctionTimerActive; + + static AppTask sAppTask; +}; + +inline AppTask & GetAppTask(void) +{ + return AppTask::sAppTask; +} + +#endif // APP_TASK_H diff --git a/examples/lock-app/cc32xx/main/BoltLockManager.cpp b/examples/lock-app/cc32xx/main/BoltLockManager.cpp new file mode 100644 index 00000000000000..31c995f7d34d4c --- /dev/null +++ b/examples/lock-app/cc32xx/main/BoltLockManager.cpp @@ -0,0 +1,206 @@ +/* + * + * 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 "BoltLockManager.h" + +#include "AppConfig.h" +#include "AppTask.h" +#include "FreeRTOS.h" + +#define ACTUATOR_MOVEMENT_PERIOS_MS 1000 + +BoltLockManager BoltLockManager::sLock; + +int BoltLockManager::Init() +{ + int ret = 0; + + mTimerHandle = xTimerCreate("BLT_TIMER", pdMS_TO_TICKS(ACTUATOR_MOVEMENT_PERIOS_MS), pdFALSE, this, TimerEventHandler); + if (NULL == mTimerHandle) + { + PLAT_LOG("failed to create bolt lock timer"); + while (1) + ; + } + + mState = kState_UnlockingCompleted; + mAutoLockTimerArmed = false; + mAutoRelock = false; + mAutoLockDuration = 0; + + return ret; +} + +void BoltLockManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB) +{ + mActionInitiated_CB = aActionInitiated_CB; + mActionCompleted_CB = aActionCompleted_CB; +} + +bool BoltLockManager::IsActionInProgress() +{ + return (mState == kState_LockingInitiated || mState == kState_UnlockingInitiated) ? true : false; +} + +bool BoltLockManager::IsUnlocked() +{ + return (mState == kState_UnlockingCompleted) ? true : false; +} + +void BoltLockManager::EnableAutoRelock(bool aOn) +{ + mAutoRelock = aOn; +} + +void BoltLockManager::SetAutoLockDuration(uint32_t aDurationInSecs) +{ + mAutoLockDuration = aDurationInSecs; +} + +bool BoltLockManager::InitiateAction(int32_t aActor, Action_t aAction) +{ + bool action_initiated = false; + State_t new_state; + + // Initiate Lock/Unlock Action only when the previous one is complete. + if (mState == kState_LockingCompleted && aAction == UNLOCK_ACTION) + { + action_initiated = true; + + new_state = kState_UnlockingInitiated; + } + else if (mState == kState_UnlockingCompleted && aAction == LOCK_ACTION) + { + action_initiated = true; + + new_state = kState_LockingInitiated; + } + + if (action_initiated) + { + if (mAutoLockTimerArmed && new_state == kState_LockingInitiated) + { + // If auto lock timer has been armed and someone initiates locking, + // cancel the timer and continue as normal. + mAutoLockTimerArmed = false; + + CancelTimer(); + } + + StartTimer(ACTUATOR_MOVEMENT_PERIOS_MS); + + // Since the timer started successfully, update the state and trigger callback + mState = new_state; + + if (mActionInitiated_CB) + { + mActionInitiated_CB(aAction, aActor); + } + } + + return action_initiated; +} + +void BoltLockManager::StartTimer(uint32_t aTimeoutMs) +{ + // XXX: Seth check returns + xTimerChangePeriod(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs), 100); + xTimerStart(mTimerHandle, 100); +} + +void BoltLockManager::CancelTimer(void) +{ + xTimerStop(mTimerHandle, 100); +} + +void BoltLockManager::TimerEventHandler(TimerHandle_t aTimer) +{ + BoltLockManager * lock = static_cast(pvTimerGetTimerID(aTimer)); + + // The timer event handler will be called in the context of the timer task + // once sLockTimer expires. Post an event to apptask queue with the actual handler + // so that the event can be handled in the context of the apptask. + // XXX: Seth major spaghetti that I don't want to unravel + AppEvent event; + event.Type = AppEvent::kEventType_AppEvent; + event.BoltLockEvent.Context = static_cast(lock); + if (lock->mAutoLockTimerArmed) + { + event.Handler = AutoReLockTimerEventHandler; + } + else + { + event.Handler = ActuatorMovementTimerEventHandler; + } + GetAppTask().PostEvent(&event); +} + +void BoltLockManager::AutoReLockTimerEventHandler(AppEvent * aEvent) +{ + BoltLockManager * lock = static_cast(aEvent->BoltLockEvent.Context); + int32_t actor = 0; + + // Make sure auto lock timer is still armed. + if (!lock->mAutoLockTimerArmed) + { + return; + } + + lock->mAutoLockTimerArmed = false; + + PLAT_LOG("Auto Re-Lock has been triggered!"); + + lock->InitiateAction(actor, LOCK_ACTION); +} + +void BoltLockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) +{ + Action_t actionCompleted = INVALID_ACTION; + + BoltLockManager * lock = static_cast(aEvent->BoltLockEvent.Context); + + if (lock->mState == kState_LockingInitiated) + { + lock->mState = kState_LockingCompleted; + actionCompleted = LOCK_ACTION; + } + else if (lock->mState == kState_UnlockingInitiated) + { + lock->mState = kState_UnlockingCompleted; + actionCompleted = UNLOCK_ACTION; + } + + if (actionCompleted != INVALID_ACTION) + { + if (lock->mActionCompleted_CB) + { + lock->mActionCompleted_CB(actionCompleted); + } + + if (lock->mAutoRelock && actionCompleted == UNLOCK_ACTION) + { + // Start the timer for auto relock + lock->StartTimer(lock->mAutoLockDuration * 1000); + + lock->mAutoLockTimerArmed = true; + + PLAT_LOG("Auto Re-lock enabled. Will be triggered in %u seconds", lock->mAutoLockDuration); + } + } +} diff --git a/examples/lock-app/cc32xx/main/BoltLockManager.h b/examples/lock-app/cc32xx/main/BoltLockManager.h new file mode 100755 index 00000000000000..40fc4ffb338a67 --- /dev/null +++ b/examples/lock-app/cc32xx/main/BoltLockManager.h @@ -0,0 +1,87 @@ +/* + * + * 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. + */ + +#ifndef LOCK_MANAGER_H +#define LOCK_MANAGER_H + +#include +#include + +#include "AppEvent.h" + +#include +#include + +class BoltLockManager +{ +public: + enum Action_t + { + LOCK_ACTION = 0, + UNLOCK_ACTION, + + INVALID_ACTION + } Action; + + enum State_t + { + kState_LockingInitiated = 0, + kState_LockingCompleted, + kState_UnlockingInitiated, + kState_UnlockingCompleted, + } State; + + int Init(); + bool IsUnlocked(); + void EnableAutoRelock(bool aOn); + void SetAutoLockDuration(uint32_t aDurationInSecs); + bool IsActionInProgress(); + bool InitiateAction(int32_t aActor, Action_t aAction); + + typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor); + typedef void (*Callback_fn_completed)(Action_t); + void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); + +private: + friend BoltLockManager & BoltLockMgr(void); + State_t mState; + + Callback_fn_initiated mActionInitiated_CB; + Callback_fn_completed mActionCompleted_CB; + + bool mAutoRelock; + uint32_t mAutoLockDuration; + bool mAutoLockTimerArmed; + TimerHandle_t mTimerHandle; + + void CancelTimer(void); + void StartTimer(uint32_t aTimeoutMs); + + static void TimerEventHandler(TimerHandle_t aTimer); + static void AutoReLockTimerEventHandler(AppEvent * aEvent); + static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); + + static BoltLockManager sLock; +}; + +inline BoltLockManager & BoltLockMgr(void) +{ + return BoltLockManager::sLock; +} + +#endif // LOCK_MANAGER_H diff --git a/examples/lock-app/cc32xx/main/CXXExceptionStubs.cpp b/examples/lock-app/cc32xx/main/CXXExceptionStubs.cpp new file mode 100755 index 00000000000000..a4ef5137758023 --- /dev/null +++ b/examples/lock-app/cc32xx/main/CXXExceptionStubs.cpp @@ -0,0 +1,80 @@ +/* + * + * 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. + */ + +/** + * @file + * Stub implementations of the C++ ABI exception handling functions. + * + * These functions replace the standard C++ exception code from the system's + * C++ runtime library with stub implementations that simply abort. This + * reduces overall code size as well as eliminating some calls to malloc() + * that occur during global initialization (see the code in eh_alloc.cc). + * This provides significant memory savings on resource constrained devices + * that don't use exceptions. + * + */ + +#include + +extern "C" { + +void * __cxa_allocate_exception(size_t) +{ + abort(); +} + +void __cxa_free_exception(void *) +{ + abort(); +} + +void * __cxa_allocate_dependent_exception() +{ + abort(); +} + +void __cxa_free_dependent_exception(void *) +{ + abort(); +} + +void __cxa_throw(void *, void *, void (*)(void *)) +{ + abort(); +} + +void __cxa_rethrow() +{ + abort(); +} + +void * __cxa_begin_catch(void *) +{ + abort(); +} + +void __cxa_end_catch() +{ + abort(); +} + +void * __cxa_get_exception_ptr(void *) +{ + abort(); +} +} diff --git a/examples/lock-app/cc32xx/main/ZclCallbacks.cpp b/examples/lock-app/cc32xx/main/ZclCallbacks.cpp new file mode 100644 index 00000000000000..f3b352607c913e --- /dev/null +++ b/examples/lock-app/cc32xx/main/ZclCallbacks.cpp @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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 "AppConfig.h" +#include "BoltLockManager.h" + +#include +#include +#include +#include + +using namespace ::chip; +using namespace ::chip::app::Clusters; + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, + uint8_t * value) +{ + if (attributePath.mClusterId == OnOff::Id && attributePath.mAttributeId == OnOff::Attributes::OnOff::Id) + { + BoltLockMgr().InitiateAction(0, *value ? BoltLockManager::LOCK_ACTION : BoltLockManager::UNLOCK_ACTION); + } +} + +/** @brief OnOff Cluster Init + * + * This function is called when a specific cluster is initialized. It gives the + * application an opportunity to take care of cluster initialization procedures. + * It is called exactly once for each endpoint where cluster is present. + * + * @param endpoint Ver.: always + * + * TODO Issue #3841 + * emberAfOnOffClusterInitCallback happens before the stack initialize the cluster + * attributes to the default value. + * The logic here expects something similar to the deprecated Plugins callback + * emberAfPluginOnOffClusterServerPostInitCallback. + * + */ +void emberAfOnOffClusterInitCallback(EndpointId endpoint) +{ + // TODO: implement any additional Cluster Server init actions +} diff --git a/examples/lock-app/cc32xx/main/cc32xxWifiInit.c b/examples/lock-app/cc32xx/main/cc32xxWifiInit.c new file mode 100644 index 00000000000000..03bb5c18369e5b --- /dev/null +++ b/examples/lock-app/cc32xx/main/cc32xxWifiInit.c @@ -0,0 +1,243 @@ +/* + * + * Copyright (c) 2020 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. + */ + +//**************************************************************************** +// +//! \addtogroup +//! @{ +// +//**************************************************************************** + +/* Standard Include */ +#include +#include +#include +#include +#include +#include +#include +#include + +/* TI-DRIVERS Header files */ +#include +#include + +#include + +#include + +#include +#include + +#include "ti_drivers_config.h" +#include +#include +#include +#include +#include +#include +#include + +#include "utils_if.h" +#include "wifi_if.h" + +#include +int CHIP_IF_init(); + +/* Application Version and Naming*/ +#define APPLICATION_NAME "CC32XX-MATTER:: E-LOCK" +#define APPLICATION_VERSION "01.00.00.00" + +/* USER's defines */ +#define SLNETCONN_TASK_STACK_SIZE (2048) +#define DISPLAY_TASK_STACK_SIZE (512) + +/**************************************************************************** + LOCAL FUNCTION PROTOTYPES + ****************************************************************************/ +static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events); + +/**************************************************************************** + EXT. FUNCTION PROTOTYPES + ****************************************************************************/ +extern void LWIP_IF_start(); + +/**************************************************************************** + GLOBAL VARIABLES + ****************************************************************************/ +pthread_t gSlNetConnThread = (pthread_t) NULL; +Button_Handle gButtonLeftHandle, gButtonRightHandle; +LED_Handle gLedBlueHandle, gLedGreenHandle, gLedRedHandle; + +/**************************************************************************** + STATIC VARIABLES + ****************************************************************************/ +static bool gIsConnected = 0; + +//***************************************************************************** +// Local Functions +//***************************************************************************** + +void SimpleLinkSockEventHandler(SlSockEvent_t * pSock) +{ + /* Unused in this application */ +} + +void SimpleLinkHttpServerEventHandler(SlNetAppHttpServerEvent_t * pHttpEvent, SlNetAppHttpServerResponse_t * pHttpResponse) +{ + /* Unused in this application */ +} + +void SimpleLinkNetAppRequestEventHandler(SlNetAppRequest_t * pNetAppRequest, SlNetAppResponse_t * pNetAppResponse) +{ + /* Unused in this application */ +} + +void SimpleLinkNetAppRequestMemFreeEventHandler(uint8_t * buffer) +{ + /* Unused in this application */ +} + +//***************************************************************************** +// +//! \brief Application startup display on UART +//! +//! \param none +//! +//! \return none +//! +//***************************************************************************** +void DisplayBanner() +{ + cc32xxLog("\n\n\n\r"); + cc32xxLog("\t\t *************************************************\n\r"); + cc32xxLog("\t\t %s Application \n\r", APPLICATION_NAME); + cc32xxLog("\t\t %s \n\r", APPLICATION_VERSION); + cc32xxLog("\t\t *************************************************\n\r"); + cc32xxLog("\n\n\n\r"); +} + +//***************************************************************************** +// +//! \brief SlWifiConn Event Handler +//! +//***************************************************************************** +void SlNetConnEventHandler(uint32_t ifID, SlNetConnStatus_e netStatus, void * data) +{ + switch (netStatus) + { + case SLNETCONN_STATUS_CONNECTED_MAC: + gIsConnected = 1; + LED_setOn(gLedBlueHandle, LED_BRIGHTNESS_MAX); + cc32xxLog("[SlNetConnEventHandler] I/F %d - CONNECTED (MAC LEVEL)!\n\r", ifID); + break; + case SLNETCONN_STATUS_CONNECTED_IP: + gIsConnected = 1; + cc32xxLog("[SlNetConnEventHandler] I/F %d - CONNECTED (IP LEVEL)!\n\r", ifID); + break; + case SLNETCONN_STATUS_CONNECTED_INTERNET: + gIsConnected = 1; + cc32xxLog("[SlNetConnEventHandler] I/F %d - CONNECTED (INTERNET LEVEL)!\n\r", ifID); + break; + case SLNETCONN_STATUS_WAITING_FOR_CONNECTION: + case SLNETCONN_STATUS_DISCONNECTED: + gIsConnected = 0; + LED_setOff(gLedBlueHandle); + cc32xxLog("[SlNetConnEventHandler] I/F %d - DISCONNECTED!\n\r", ifID); + break; + default: + cc32xxLog("[SlNetConnEventHandler] I/F %d - UNKNOWN STATUS\n\r", ifID); + break; + } +} + +//***************************************************************************** +// +//! \brief Launchpad switch used to enable one shot provisioning +//! +//***************************************************************************** +static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events) +{ + // Enable Provisioning + int retVal = SlWifiConn_enableProvisioning(WifiProvMode_ONE_SHOT, PROVISIONING_CMD, 0); + assert(retVal == 0); +} + +//***************************************************************************** +// +//! \brief Main application thread +//! +//! \param none +//! +//! \return none +//! +//***************************************************************************** +int WiFi_init() +{ + int retVal; + Button_Params buttonParams; + LED_Params ledParams; + + SPI_init(); + +#ifdef NWP_LOG + // NWP log config + // If your application already has UART0 configured, no need for this line + MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK); + // Mux Pin 62 to mode 1 for outputting NWP logs + MAP_PinTypeUART(PIN_62, PIN_MODE_1); +#endif + + LED_Params_init(&ledParams); // default PWM LED + gLedBlueHandle = LED_open(CONFIG_LED_BLUE, &ledParams); + LED_setOff(gLedBlueHandle); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + gButtonLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(gButtonLeftHandle, ButtonLeftEventHandler); + + /* Enable SlWifiConn */ + retVal = WIFI_IF_init(); + assert(retVal >= 0); + + /* Enable SlNet framework */ + retVal = ti_net_SlNet_initConfig(); + assert(retVal == 0); + + /* Enable SlNetConn */ + retVal = SlNetConn_init(0); + assert(retVal == 0); + gSlNetConnThread = OS_createTask(1, SLNETCONN_TASK_STACK_SIZE, SlNetConn_process, NULL, OS_TASK_FLAG_DETACHED); + assert(gSlNetConnThread); + + return (retVal); +} + +int WiFi_deinit() +{ + int retVal; + cc32xxLog("[APP] Networking App Completed (entering low power mode)\r\n "); + retVal = SlNetConn_stop(SlNetConnEventHandler); + retVal = WIFI_IF_deinit(); + cc32xxLog("[APP] Exit (%d) \r\n", retVal); + assert(retVal == 0); + return (retVal); +} diff --git a/examples/lock-app/cc32xx/main/debug_settings.h b/examples/lock-app/cc32xx/main/debug_settings.h new file mode 100644 index 00000000000000..61cefd37e7fb51 --- /dev/null +++ b/examples/lock-app/cc32xx/main/debug_settings.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2021 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. + */ + +//***************************************************************************** +// Includes +//***************************************************************************** +// Standard includes +#ifndef DEBUG_SETTINGS_H +#define DEBUG_SETTINGS_H + +// Select the print method used in the main app +#define D_DEBUG_METHOD D_USER_DEFINED + +// Select Sevrity Color +#define _FATAL_CLR_ _CLR_B_RED_ +#define _ERROR_CLR_ _CLR_RED_ +#define _WARNING_CLR_ _CLR_MAGENTA_ +#define _INFO_CLR_ _CLR_GREEN_ +#define _DEBUG_CLR_ _CLR_YELLOW_ +#define _TRACE_CLR_ _CLR_RESET_ + +#if (D_DEBUG_METHOD == D_USER_DEFINED) +extern void cc32xxLog(const char * msg, ...); +#define PRINTF(...) cc32xxLog(__VA_ARGS__); +#endif + +#endif // DEBUG_SETTINGS_H diff --git a/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..d5187cc43a5d49 --- /dev/null +++ b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h @@ -0,0 +1,150 @@ +/* + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#ifndef CHIP_PROJECT_CONFIG_H +#define CHIP_PROJECT_CONFIG_H + +#if BUILD_RELEASE // release build + +// Security and Authentication enabled for release build. +#define CHIP_CONFIG_SECURITY_TEST_MODE 0 +#define CHIP_CONFIG_REQUIRE_AUTH 1 + +#else // development build + +// Security and Authentication disabled for development build. +// For convenience, enable CHIP Security Test Mode and disable the requirement for +// authentication in various protocols. +// WARNING: These options make it possible to circumvent basic CHIP security functionality, +// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. +#define CHIP_CONFIG_SECURITY_TEST_MODE 0 +#define CHIP_CONFIG_REQUIRE_AUTH 0 + +/** + * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY + * + * Enables the use of a hard-coded default CHIP device id and credentials if no device id + * is found in CHIP NV storage. + * + * This option is for testing only and should be disabled in production releases. + */ +#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" + +/** + * CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER + * + * Enables the use of a hard-coded default serial number if none + * is found in CHIP NV storage. + */ +#define CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER "DUMMY_SN" + +#endif // BUILD_RELEASE + +/** + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * + * 0xE100: Google's Vendor Id. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * + * 0xFE00: SDK Sample Lock Resource + */ +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8006 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION + * + * The product revision number assigned to device or product by the device vendor. This + * number is scoped to the device product id, and typically corresponds to a revision of the + * physical device, a change to its packaging, and/or a change to its marketing presentation. + * This value is generally *not* incremented for device software revisions. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION + * + * A string identifying the firmware revision running on the device. + * CHIP currently expects the firmware version to be in the format + * {MAJOR_VERSION}.0d{MINOR_VERSION} + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION +#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION "1.0d1" +#endif +/** + * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + * + * Enable support for CHIP-over-BLE (CHIPOBLE). + */ +#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 + +/** + * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC + * + * Enables synchronizing the device's real time clock with a remote CHIP Time service + * using the CHIP Time Sync protocol. + */ +//#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 + +/** + * CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE + * + * A size, in bytes, of the individual debug event logging buffer. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) + +/** + * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE + * + * For a development build, set the default importance of events to be logged as Debug. + * Since debug is the lowest importance level, this means all standard, critical, info and + * debug importance level vi events get logged. + */ +#if BUILD_RELEASE +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Production +#else +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Debug +#endif // BUILD_RELEASE + +#endif // CHIP_PROJECT_CONFIG_H diff --git a/examples/lock-app/cc32xx/main/main.cpp b/examples/lock-app/cc32xx/main/main.cpp new file mode 100644 index 00000000000000..4546931d83aba6 --- /dev/null +++ b/examples/lock-app/cc32xx/main/main.cpp @@ -0,0 +1,76 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated + * + * 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 +#include + +#include +#include +#include +#include + +#include +#include + +#include + +/* Driver Header files */ +#include +#include +#include + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::DeviceLayer; + +// ================================================================================ +// FreeRTOS Callbacks +// ================================================================================ +extern "C" void vApplicationStackOverflowHook(void) +{ + while (1) + { + ; + } +} + +// ================================================================================ +// Main Code +// ================================================================================ +int main(void) +{ + Board_init(); + GPIO_init(); + + mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); + + int ret = GetAppTask().StartAppTask(); + if (ret != 0) + { + // can't log until the kernel is started + // PLAT_LOG("GetAppTask().StartAppTask() failed"); + while (1) + ; + } + + vTaskStartScheduler(); + + // Should never get here. + while (1) + ; +} diff --git a/examples/lock-app/cc32xx/main/wifi_settings.h b/examples/lock-app/cc32xx/main/wifi_settings.h new file mode 100644 index 00000000000000..6fdf1f61603476 --- /dev/null +++ b/examples/lock-app/cc32xx/main/wifi_settings.h @@ -0,0 +1,103 @@ +/* + * + * Copyright (c) 2021 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. + */ + +//***************************************************************************** +// Includes +//***************************************************************************** +// Standard includes +#ifndef WIFI_SETTINGS_H +#define WIFI_SETTINGS_H + +//***************************************************************************** +// WIFI IF INTRODUCTION +//***************************************************************************** +/* This module enables an easy integration of Wi-Fi to a SimpleLink Networking + * framework. + * It was designed for applications that use the Wi-Fi Station role only. + * The simple API and settings enables the user to initiate the Wi-Fi and + * configure the provisioning method that will be used upon first connection + * attempt. + * Upon successful init (WIFI_IF_init()), the system enables the NWP for any + * SL commands. + * The NWP will be in a low power state (AUTO-CONNECT will be disabled) waiting + * for connection request (SlNetConn_Start()). + * User should not call sl_Start/sl_Stop when using this module. Please use + * WIFI_IF_restart() (for reseting the NWP) or WIFI_IF_deinit() instead. + */ + +//***************************************************************************** +// WIFI IF USER SETTINGS +//***************************************************************************** + +/* + * Defines the minimum severity level allowed. + * Use E_DEBUG to enable Wifi internal messages + * Options: E_TRACE, E_DEBUG, E_INFO, E_WARNING, E_ERROR, E_FATAL + */ +#define WIFI_IF_DEBUG_LEVEL E_INFO + +/* + * Defines Provisioning (initial) Parameters: + * Mode can be: WifiProvMode_OFF, WifiProvMode_ON, WifiProvMode_ONE_SHOT + * Command can be one of the following: + * SL_WLAN_PROVISIONING_CMD_START_MODE_AP, + * SL_WLAN_PROVISIONING_CMD_START_MODE_SC, + * SL_WLAN_PROVISIONING_CMD_START_MODE_APSC, + * SL_WLAN_PROVISIONING_CMD_START_MODE_APSC_EXTERNAL_CONFIGURATION, + * SL_WLAN_PROVISIONING_CMD_START_MODE_EXTERNAL_CONFIGURATION + */ +#define PROVISIONING_MODE WifiProvMode_ONE_SHOT +#define PROVISIONING_CMD SL_WLAN_PROVISIONING_CMD_START_MODE_APSC + +/* + * Defines Provisioning AP /SC Parameters: + */ +#define PROVISIONING_TIMEOUT 0 // 0 - use default +#define PROVISIONING_AP_PASSWORD "1234567890" // NULL - use default (OPEN) +#define PROVISIONING_SC_KEY "1234567890123456" // NULL - use defaults + +/* Force provisioning by deleting existing profiles. + * To be used for testing during development only. + * Note: When FORCE_PROVSIONING is enabled - the following static profile + * configurations are ignored + */ +#define FORCE_PROVISIONING (0) + +/* Static Profile setting - Method 1: Hard coded + * Define AP_SSID and optionally AP_PASSWORD - to connect to local network + * Hard-Coded Definition: update AP_SSID and AP_PASSWORD (NULL means OPEN, else is WPA2) + */ +#define AP_SSID NULL // "network-name" +#define AP_PASSWORD NULL // "network-password" + +/* Static Profile setting - Method 2: Configuration file + * File format should be: + * "' '" + * i.e. ssid and password with one space character between them + * Do not use newline, extra space symbols or quotation mark + */ +#define AP_CFG_FILENAME "network.cfg" // config file name +#define AP_CFG_TOKEN 12345678 // config file read access token +#define AP_CFG_MAX_SIZE 100 // config file Maximum file length + +/* Define (if needed) the external handle for TI Driver's LED for wi-fi status: + * off: disconnected, blinking: provisionig, on: connected + * Comment the definition in case the auto control is not required */ +#define WIFI_LED_HANDLE gLedBlueHandle + +#endif // WIFI_SETTINGS_H diff --git a/examples/lock-app/cc32xx/third_party/connectedhomeip b/examples/lock-app/cc32xx/third_party/connectedhomeip new file mode 120000 index 00000000000000..11a54ed360106c --- /dev/null +++ b/examples/lock-app/cc32xx/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../ \ No newline at end of file diff --git a/examples/platform/cc32xx/BUILD.gn b/examples/platform/cc32xx/BUILD.gn new file mode 100644 index 00000000000000..031d054e190927 --- /dev/null +++ b/examples/platform/cc32xx/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") + +config("chip_examples_project_config") { + include_dirs = [ "project_include" ] +} diff --git a/examples/platform/cc32xx/args.gni b/examples/platform/cc32xx/args.gni new file mode 100644 index 00000000000000..94754b21ecc522 --- /dev/null +++ b/examples/platform/cc32xx/args.gni @@ -0,0 +1,23 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") + +import("${chip_root}/src/platform/cc32xx/args.gni") + +chip_ble_project_config_include = "" +chip_device_project_config_include = "" +chip_project_config_include = "" +chip_inet_project_config_include = "" +chip_system_project_config_include = "" diff --git a/scripts/checkout_submodules.py b/scripts/checkout_submodules.py index 74a7b9f473ccb9..11ab89fbbb841d 100755 --- a/scripts/checkout_submodules.py +++ b/scripts/checkout_submodules.py @@ -29,6 +29,7 @@ 'android', 'bl602', 'cc13x2_26x2', + 'cc32xx', 'cyw30739', 'darwin', 'efr32', diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index f45667ed60fbf1..4490159793bbd0 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -29,11 +29,11 @@ if (lwip_platform == "") { } assert(lwip_platform == "external" || lwip_platform == "standalone" || - lwip_platform == "cc13x2_26x2" || lwip_platform == "efr32" || - lwip_platform == "k32w0" || lwip_platform == "qpg" || - lwip_platform == "mbed" || lwip_platform == "p6" || - lwip_platform == "cyw30739" || lwip_platform == "bl602" || - lwip_platform == "mw320", + lwip_platform == "cc13x2_26x2" || lwip_platform == "cc32xx" || + lwip_platform == "efr32" || lwip_platform == "k32w0" || + lwip_platform == "qpg" || lwip_platform == "mbed" || + lwip_platform == "p6" || lwip_platform == "cyw30739" || + lwip_platform == "bl602" || lwip_platform == "mw320", "Unsupported lwIP platform: ${lwip_platform}") if (lwip_platform != "external") { @@ -45,6 +45,8 @@ if (lwip_platform != "external") { if (lwip_platform == "cc13x2_26x2") { import("//build_overrides/ti_simplelink_sdk.gni") +} else if (lwip_platform == "cc32xx") { + import("//build_overrides/ti_simplelink_sdk.gni") } else if (lwip_platform == "efr32") { import("//build_overrides/efr32_sdk.gni") } else if (lwip_platform == "qpg") { @@ -167,6 +169,10 @@ if (current_os == "zephyr" || current_os == "mbed") { public_deps = [ ":lwip_buildconfig" ] if (lwip_platform == "cc13x2_26x2") { public_deps += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" ] + } else if (lwip_platform == "cc32xx") { + public_deps += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" ] + sources += + [ "${chip_root}/third_party/lwip/repo/lwip/src/apps/mdns/mdns.c" ] } else if (lwip_platform == "efr32") { public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ] } else if (lwip_platform == "standalone") { diff --git a/src/lwip/cc32xx/arch/cc.h b/src/lwip/cc32xx/arch/cc.h new file mode 100644 index 00000000000000..91174cc16f219e --- /dev/null +++ b/src/lwip/cc32xx/arch/cc.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018-2019 Google LLC. + * + * 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. + */ + +// XXX: Seth, what does this need for TI devices? + +/* + * + * Description: + * This file defines processor-architecture- and toolchain- + * specific constants and types required for building + * LwIP against FreeRTOS. + * + */ + +#ifndef CHIP_LWIP_FREERTOS_ARCH_CC_H +#define CHIP_LWIP_FREERTOS_ARCH_CC_H + +#include +#include +#include +#include +#include +#include + +#include + +//#include "app_error.h" + +#if __cplusplus +extern "C" { +#endif + +#ifndef LWIP_NOASSERT +#ifdef DEBUG +#define LWIP_PLATFORM_ASSERT(MSG) assert(0) +#else +#define LWIP_PLATFORM_ASSERT(MSG) assert(0) +#endif +#else +#define LWIP_PLATFORM_ASSERT(message) +#endif + +#ifndef BYTE_ORDER +#if defined(__LITTLE_ENDIAN__) +#define BYTE_ORDER LITTLE_ENDIAN +#elif defined(__BIG_ENDIAN__) +#define BYTE_ORDER BIG_ENDIAN +#elif defined(__BYTE_ORDER__) +#define BYTE_ORDER __BYTE_ORDER__ +#endif +#endif // BYTE_ORDER + +#define PACK_STRUCT_STRUCT __attribute__((__packed__)) +#define PACK_STRUCT_FIELD(x) x + +extern void LwIPLog(const char * fmt, ...); +#define LWIP_PLATFORM_DIAG(x) \ + do \ + { \ + LwIPLog x; \ + } while (0) + +// Place LwIP pools into their own subsections of .bss to make it easier to see +// their sizes in the linker map file. +extern uint8_t __attribute__((section(".bss.lwip_ND6_QUEUE"))) memp_memory_ND6_QUEUE_base[]; +extern uint8_t __attribute__((section(".bss.lwip_IP6_REASSDATA"))) memp_memory_IP6_REASSDATA_base[]; +extern uint8_t __attribute__((section(".bss.lwip_RAW_PCB"))) memp_memory_RAW_PCB_base[]; +extern uint8_t __attribute__((section(".bss.lwip_TCP_SEG"))) memp_memory_TCP_SEG_base[]; +extern uint8_t __attribute__((section(".bss.lwip_PBUF_POOL"))) memp_memory_PBUF_POOL_base[]; +extern uint8_t __attribute__((section(".bss.lwip_FRAG_PBUF"))) memp_memory_FRAG_PBUF_base[]; +extern uint8_t __attribute__((section(".bss.lwip_PBUF"))) memp_memory_PBUF_base[]; +extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB_LISTEN"))) memp_memory_TCP_PCB_LISTEN_base[]; +extern uint8_t __attribute__((section(".bss.lwip_REASSDATA"))) memp_memory_REASSDATA_base[]; +extern uint8_t __attribute__((section(".bss.lwip_UDP_PCB"))) memp_memory_UDP_PCB_base[]; +extern uint8_t __attribute__((section(".bss.lwip_MLD6_GROUP"))) memp_memory_MLD6_GROUP_base[]; +extern uint8_t __attribute__((section(".bss.lwip_IGMP_GROUP"))) memp_memory_IGMP_GROUP_base[]; +extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB"))) memp_memory_TCP_PCB_base[]; +extern uint8_t __attribute__((section(".bss.lwip_SYS_TIMEOUT"))) memp_memory_SYS_TIMEOUT_base[]; + +#if __cplusplus +} +#endif + +#endif /* CHIP_LWIP_FREERTOS_ARCH_CC_H */ diff --git a/src/lwip/cc32xx/arch/perf.h b/src/lwip/cc32xx/arch/perf.h new file mode 100644 index 00000000000000..6239d7e44e7b39 --- /dev/null +++ b/src/lwip/cc32xx/arch/perf.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018-2019 Google LLC. + * + * 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. + */ + +// XXX: Seth, what does this need for TI devices? + +/* + * + * Description: + * This file defines processor-architecture-specific constants, + * interfaces and types required for LwIP performance + * measurement. + * + */ + +#ifndef CHIP_LWIP_FREERTOS_ARCH_PERF_H +#define CHIP_LWIP_FREERTOS_ARCH_PERF_H + +#define PERF_START +#define PERF_STOP(s) + +#endif /* CHIP_LWIP_FREERTOS_ARCH_PERF_H */ diff --git a/src/lwip/cc32xx/lwipopts.h b/src/lwip/cc32xx/lwipopts.h new file mode 100644 index 00000000000000..146ff2bec8556a --- /dev/null +++ b/src/lwip/cc32xx/lwipopts.h @@ -0,0 +1,175 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Nest Labs, Inc. + * + * 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. + */ + +/** + * @file + * Compile-time configuration for LwIP on the TI CC32xx. + * + */ + +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#include + +#define NO_SYS 0 +#define MEM_ALIGNMENT (4) +#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1) +#define LWIP_TIMEVAL_PRIVATE (0) +#define MEM_LIBC_MALLOC (0) +#define LWIP_COMPAT_MUTEX (0) +#define SYS_LIGHTWEIGHT_PROT (1) +#define LWIP_AUTOIP (1) +#define LWIP_DHCP_AUTOIP_COOP (0) +#define LWIP_SOCKET_SET_ERRNO 0 +#define IP_REASS_MAX_PBUFS 0 +#define IP_REASSEMBLY 0 +#define MEMP_NUM_REASSDATA 0 +#define LWIP_SO_RCVTIMEO 0 +#define SO_REUSE (1) +#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1) +#define LWIP_STATS (0) +#define LWIP_TCPIP_CORE_LOCKING 1 +#define TCP_QUEUE_OOSEQ 0 +#define ARP_QUEUEING (0) +#define TCPIP_THREAD_NAME "LWIP" + +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_STATUS_CALLBACK 1 + +#define LWIP_SOCKET 0 + +// TODO: seems like this is unnecessary on Thread-only platforms +#define LWIP_RAW 1 +#define MEMP_NUM_RAW_PCB (5) + +#define MEMP_NUM_UDP_PCB (7) + +#define LWIP_HAVE_LOOPIF (0) + +// TODO: not sure why this is disabled +#define LWIP_NETIF_LOOPBACK (0) + +#define MEMP_NUM_NETCONN (0) + +// enable ethernet for ipv6 support +#define LWIP_ETHERNET 1 + +#define LWIP_IPV4 1 +#define LWIP_IPV6 1 +#define LWIP_ARP (1) +#define LWIP_DNS (0) +#define LWIP_ICMP (0) +#define LWIP_IGMP (1) +#define LWIP_DHCP (1) +#define LWIP_IPV6_REASS (0) +#define LWIP_IPV6_DHCP6 0 +#define LWIP_IPV6_AUTOCONFIG (0) +#define LWIP_IPV6_ROUTER_SUPPORT 0 +#define LWIP_ND6_LISTEN_RA 0 + +#define LWIP_ND6_NUM_NEIGHBORS (0) +#define LWIP_ND6_NUM_DESTINATIONS (0) +#define LWIP_ND6_NUM_PREFIXES (0) +#define LWIP_ND6_NUM_ROUTERS (0) +#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) +#define LWIP_ND6_MAX_UNICAST_SOLICIT (0) +#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0) +#define LWIP_ND6_TCP_REACHABILITY_HINTS (0) + +#define MEMP_SEPARATE_POOLS (1) +#define LWIP_PBUF_FROM_CUSTOM_POOLS (0) +#define MEMP_USE_CUSTOM_POOLS (0) +#define PBUF_POOL_SIZE (16) +#define PBUF_POOL_BUFSIZE (1500) +#define PBUF_POOL_SIZE_LARGE (3) +#define PBUF_POOL_SIZE_MEDIUM (4) +#define PBUF_POOL_SIZE_SMALL (5) +#define PBUF_POOL_BUFSIZE_LARGE (1280) +#define PBUF_POOL_BUFSIZE_MEDIUM (640) +#define PBUF_POOL_BUFSIZE_SMALL (256) +#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) +#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) + +#define TCP_MSS (1152) +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_LISTEN_BACKLOG (1) + +#define ETH_PAD_SIZE (0) +#define SUB_ETHERNET_HEADER_SPACE (0) +#define PBUF_LINK_HLEN (14) + +#define TCPIP_THREAD_STACKSIZE (4096) +#define TCPIP_THREAD_PRIO (2) + +#define NETIF_MAX_HWADDR_LEN 8U + +#define LWIP_IPV6_NUM_ADDRESSES 5 + +#define LWIP_IPV6_ND 1 +#define LWIP_IPV6_MLD 1 +#define LWIP_ND6_QUEUEING 0 + +#define LWIP_MULTICAST_PING 0 + +#define TCPIP_MBOX_SIZE 6 +#define DEFAULT_RAW_RECVMBOX_SIZE 6 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 + +// TODO: make LWIP_DEBUG conditional on build type + +#ifndef LWIP_DEBUG +#define LWIP_DEBUG 1 +#endif + +#define MEMP_OVERFLOW_CHECK (0) +#define MEMP_SANITY_CHECK (0) +#define MEM_DEBUG (LWIP_DBG_OFF) +#define MEMP_DEBUG (LWIP_DBG_OFF) +#define PBUF_DEBUG (LWIP_DBG_OFF) +#define API_LIB_DEBUG (LWIP_DBG_OFF) +#define API_MSG_DEBUG (LWIP_DBG_OFF) +#define TCPIP_DEBUG (LWIP_DBG_OFF) +#define NETIF_DEBUG (LWIP_DBG_OFF) +#define SOCKETS_DEBUG (LWIP_DBG_OFF) +#define DEMO_DEBUG (LWIP_DBG_OFF) +#define DHCP_DEBUG (LWIP_DBG_OFF) +#define AUTOIP_DEBUG (LWIP_DBG_OFF) +#define ETHARP_DEBUG (LWIP_DBG_OFF) +#define IP_DEBUG (LWIP_DBG_OFF) +#define IP_REASS_DEBUG (LWIP_DBG_OFF) +#define IP6_DEBUG (LWIP_DBG_OFF) +#define RAW_DEBUG (LWIP_DBG_OFF) +#define ICMP_DEBUG (LWIP_DBG_OFF) +#define UDP_DEBUG (LWIP_DBG_OFF) +#define TCP_DEBUG (LWIP_DBG_OFF) +#define TCP_INPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF) +#define TCP_RTO_DEBUG (LWIP_DBG_OFF) +#define TCP_CWND_DEBUG (LWIP_DBG_OFF) +#define TCP_WND_DEBUG (LWIP_DBG_OFF) +#define TCP_FR_DEBUG (LWIP_DBG_OFF) +#define TCP_QLEN_DEBUG (LWIP_DBG_OFF) +#define TCP_RST_DEBUG (LWIP_DBG_OFF) +#define PPP_DEBUG (LWIP_DBG_OFF) + +#define LWIP_DBG_TYPES_ON \ + (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/lwip/cc32xx/lwippools.h b/src/lwip/cc32xx/lwippools.h new file mode 100644 index 00000000000000..e8967a420f4344 --- /dev/null +++ b/src/lwip/cc32xx/lwippools.h @@ -0,0 +1,2 @@ + +// XXX: Seth, what does this need for TI devices? diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index f913cedd398c6b..4a5cdf0b61d204 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -156,6 +156,11 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { "CHIP_DEVICE_LAYER_TARGET_CC13X2_26X2=1", "CHIP_DEVICE_LAYER_TARGET=cc13x2_26x2", ] + } else if (chip_device_platform == "cc32xx") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_CC32XX=1", + "CHIP_DEVICE_LAYER_TARGET=cc32xx", + ] } else if (chip_device_platform == "darwin") { defines += [ "CHIP_DEVICE_LAYER_TARGET_DARWIN=1", @@ -390,6 +395,8 @@ if (chip_device_platform != "none") { if (chip_device_platform == "cc13x2_26x2") { _platform_target = "cc13x2_26x2" + } else if (chip_device_platform == "cc32xx") { + _platform_target = "cc32xx" } else if (chip_device_platform == "darwin") { _platform_target = "Darwin" } else if (chip_device_platform == "efr32") { diff --git a/src/platform/cc32xx/BUILD.gn b/src/platform/cc32xx/BUILD.gn new file mode 100644 index 00000000000000..5932becd949778 --- /dev/null +++ b/src/platform/cc32xx/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2021 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") + +import("${chip_root}/src/platform/device.gni") + +assert(chip_device_platform == "cc32xx") + +static_library("cc32xx") { + sources = [ + "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", + "CC32XXConfig.cpp", + "CC32XXConfig.h", + "CHIPDevicePlatformConfig.h", + "CHIPDevicePlatformEvent.h", + "ConfigurationManagerImpl.cpp", + "ConnectivityManagerImpl.cpp", + "ConnectivityManagerImpl.h", + "DeviceNetworkProvisioningDelegateImpl.cpp", + "DeviceNetworkProvisioningDelegateImpl.h", + "DiagnosticDataProviderImpl.cpp", + "DiagnosticDataProviderImpl.h", + "InetPlatformConfig.h", + "KeyValueStoreManagerImpl.cpp", + "KeyValueStoreManagerImpl.h", + + #"Logging.cpp", + "PlatformManagerImpl.cpp", + "PlatformManagerImpl.h", + + #"Random.c", + + "SystemPlatformConfig.h", + ] + + include_dirs = [ "ifmod/" ] + deps = [] + + public_deps = [ + "${chip_root}/src/crypto", + "${chip_root}/src/platform:platform_base", + ] + + if (chip_enable_ble) { + sources += [ + "BLEManagerImpl.cpp", + "BLEManagerImpl.h", + ] + } +} diff --git a/src/platform/cc32xx/BlePlatformConfig.h b/src/platform/cc32xx/BlePlatformConfig.h new file mode 100644 index 00000000000000..e271014ad01c7b --- /dev/null +++ b/src/platform/cc32xx/BlePlatformConfig.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the CHIP BLE + * Layer for the Texas Instruments CC32XX platform. + * + * NOTE: Empty because BLE is not enabled, but configure.ac defines this file + * to be included by the build configuration. + */ + +#ifndef BLE_PLATFORM_CONFIG_H +#define BLE_PLATFORM_CONFIG_H + +#endif // BLE_PLATFORM_CONFIG_H diff --git a/src/platform/cc32xx/CC32XXConfig.cpp b/src/platform/cc32xx/CC32XXConfig.cpp new file mode 100644 index 00000000000000..cdc59cd6d37ada --- /dev/null +++ b/src/platform/cc32xx/CC32XXConfig.cpp @@ -0,0 +1,559 @@ +/* + * + * Copyright (c) 2021 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. + */ + +/** + * @file + * Utilities for interacting with multiple file partitions and maps + * key-value config calls to the correct partition. + */ + +#include +#include + +#include +#include +#include +#include + +extern "C" { +int FILE_write(char * pFilename, uint16_t length, uint8_t * pValue, uint32_t * pToken, uint32_t flags); +int FILE_read(int8_t * pFilename, uint16_t length, uint8_t * pValue, uint32_t token); +}; + +// need to define custom tokens to read/write files from the file system +#define KVS_TOKEN 0x13578642 + +// need between 4k and 8k bytes to store the LL when reading/writing it as a buffer +#define NV_BUFFER_SIZE 8192 + +uint16_t NVBufferLength = 0; + +extern "C" void cc32xxLog(const char * aFormat, ...); + +char listName[] = "/sys/matter/kvs.cfg"; + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +/** + * This class is designed to be mixed-in to concrete implementation classes as a means to + * provide access to configuration information to generic base classes. + * + * This class contains the definition of a LL entry -- calling the constructor creates a LL entry only, adding the entry to a LL is + * handled in CC32XXKVSList + */ +class CC32XXKVSEntry +{ +private: + // KVS key + char mKey[40] = ""; + + // KVS values + uint16_t mValueLen; + uint8_t * mValue; + +public: + CC32XXKVSEntry * mPNext; + + CC32XXKVSEntry(char * key, const uint8_t * pBuf, uint16_t len) + { + uint32_t mKLen = strlen(key); + if (mKLen > 40) + { + strncpy(mKey, key, 39); + mKey[39] = '\0'; + } + else + { + strncpy(mKey, key, mKLen); + } + + mValueLen = len; + mValue = new uint8_t[len]; + if (mValue) + { + memcpy(mValue, pBuf, len); + } + mPNext = NULL; + } + + bool IsMatch(const char * key) { return (strcmp(mKey, key) == 0); } + + char * Key() { return mKey; } + + uint16_t Len() { return mValueLen; } + + uint8_t * Value() { return mValue; } + + CHIP_ERROR ReadVal(uint8_t * pBuff, size_t len) + { + CHIP_ERROR err = CHIP_ERROR_NOT_FOUND; + if (mValueLen <= (uint16_t) len) + { + memcpy(pBuff, mValue, mValueLen); + err = CHIP_NO_ERROR; + } + return err; + } + + CHIP_ERROR UpdateVal(const uint8_t * pBuff, uint16_t len) + { + CHIP_ERROR err = CHIP_ERROR_INVALID_MESSAGE_LENGTH; + if (len > 0) + { + if (mValue) + { + delete (mValue); + } + mValue = new uint8_t[len]; + mValueLen = len; + memcpy(mValue, pBuff, len); + err = CHIP_NO_ERROR; + } + return err; + } + + uint16_t DeleteVal(void) + { + delete mValue; + return 0; + } +}; + +/** + * Linked List traversal operations for when it is in RAM, and operations to read and write from NV + */ +class CC32XXKVSList +{ +private: + CC32XXKVSEntry * mPHead; + +public: + CC32XXKVSList() { mPHead = NULL; } + + CC32XXKVSEntry * GetEntryByKey(const char * key) + { + CC32XXKVSEntry * pEntry = mPHead; + while (pEntry) + { + if (pEntry->IsMatch(key)) + { + return pEntry; + } + pEntry = pEntry->mPNext; + } + return NULL; + } + + CHIP_ERROR AddEntryByKey(char * key, const uint8_t * pBuff, const uint16_t len) + { + CHIP_ERROR err; + CC32XXKVSEntry * pEntry = GetEntryByKey(key); + + if (!pEntry) + { + CC32XXKVSEntry * pEntryNew = new CC32XXKVSEntry(key, pBuff, len); + + if (mPHead) + { + pEntryNew->mPNext = mPHead; + } + + mPHead = pEntryNew; + + err = CHIP_NO_ERROR; + } + else + { + err = pEntry->UpdateVal(pBuff, len); + } + return err; + } + + CHIP_ERROR DeleteEntryByKey(char * key) + { + CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + + CC32XXKVSEntry * temp = mPHead; + CC32XXKVSEntry * prev = NULL; + + const char * tempKey = temp->Key(); + + if (strcmp(tempKey, key) == 0) + { + mPHead = temp->mPNext; + temp->DeleteVal(); + delete temp; + err = CHIP_NO_ERROR; + } + else + { + while (temp != NULL && strcmp(temp->Key(), key) != 0) + { + prev = temp; + temp = temp->mPNext; + } + if (temp != NULL) + { + prev->mPNext = temp->mPNext; + + delete temp; + err = CHIP_NO_ERROR; + } + } + + return err; + } + + uint8_t * SerializeLinkedList(uint16_t * length) + { + uint8_t * list = new uint8_t[8192]; + CC32XXKVSEntry * currentEntry = mPHead; + uint16_t bufferLength = 0; + + while (currentEntry != NULL) + { + // copy key length + list[bufferLength] = (uint8_t) strlen(currentEntry->Key()); + bufferLength++; + + // copy key + memcpy(list + bufferLength, currentEntry->Key(), strlen(currentEntry->Key())); + bufferLength += (uint16_t) strlen(currentEntry->Key()); + + // copy value length + list[bufferLength] = (uint8_t)(currentEntry->Len() & 0xFF); + list[bufferLength + 1] = (uint8_t)((currentEntry->Len() & 0xFF00) >> 8); + bufferLength = bufferLength + 2; + + // copy value + uint8_t * value = currentEntry->Value(); + memcpy(list + bufferLength, value, currentEntry->Len()); + bufferLength += currentEntry->Len(); + + currentEntry = currentEntry->mPNext; + } + + *length = bufferLength; + + return list; + } + + void CreateLinkedListFromNV(uint8_t * list, uint16_t length) + { + uint16_t currentLength = 0; + + // check for end of LL + while (currentLength < length) + { + // read in key length + uint8_t keyLen = list[currentLength]; + currentLength++; + + // read in key + + char key[40] = { 0 }; + memcpy(key, list + currentLength, keyLen); + currentLength += keyLen; + + // read in value length + + uint16_t valueLen = 0; + valueLen = (uint16_t)(list[currentLength] | list[currentLength + 1] << 8); + currentLength += 2; + + // read in value + + uint8_t * value = new uint8_t[valueLen]; + memcpy(value, list + currentLength, valueLen); + currentLength += valueLen; + + // add entry to LL + + AddEntryByKey(key, value, valueLen); + + // value is stored in the LL, we do not need the value variable above + + delete value; + } + } +}; + +// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices. + +// Keys stored in the Chip-factory namespace +const CC32XXConfig::Key CC32XXConfig::kConfigKey_SerialNum = { "TI_kConfigKey_SerialNum" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_MfrDeviceId = { "TI_kConfigKey_MfrDeviceId" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_MfrDeviceCert = { "TI_kConfigKey_MfrDeviceCert" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_MfrDeviceICACerts = { "TI_kConfigKey_MfrDeviceICACerts" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_MfrDevicePrivateKey = { "TI_kConfigKey_MfrDevicePrivateKey" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_HardwareVersion = { "TI_kConfigKey_HardwareVersion" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_ManufacturingDate = { "TI_kConfigKey_ManufacturingDate" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_SetupPinCode = { "TI_kConfigKey_SetupPinCode" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_SetupDiscriminator = { "TI_kConfigKey_SetupDiscriminator" }; + +// Keys stored in the Chip-config namespace +const CC32XXConfig::Key CC32XXConfig::kConfigKey_FabricId = { "TI_kConfigKey_FabricId" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_ServiceConfig = { "TI_kConfigKey_ServiceConfig" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_PairedAccountId = { "TI_kConfigKey_PairedAccountId" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_ServiceId = { "TI_kConfigKey_ServiceId" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_FabricSecret = { "TI_kConfigKey_FabricSecret" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_GroupKeyIndex = { "TI_kConfigKey_GroupKeyIndex" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_LastUsedEpochKeyId = { "TI_kConfigKey_LastUsedEpochKeyId" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_FailSafeArmed = { "TI_kConfigKey_FailSafeArmed" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_WiFiStationSecType = { "TI_kConfigKey_WiFiStationSecType" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_RegulatoryLocation = { "TI_kConfigKey_RegulatoryLocation" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_CountryCode = { "TI_kConfigKey_CountryCode" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_Breadcrumb = { "TI_kConfigKey_Breadcrumb" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_UniqueId = { "TI_kConfigKey_UniqueId" }; + +const CC32XXConfig::Key CC32XXConfig::kConfigKey_Spake2pIterationCount = { "TI_kConfigKey_Spake2pIterationCount" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_Spake2pSalt = { "TI_kConfigKey_Spake2pSalt" }; +const CC32XXConfig::Key CC32XXConfig::kConfigKey_Spake2pVerifier = { "TI_kConfigKey_Spake2pVerifier" }; + +CC32XXKVSList * pList; + +CHIP_ERROR CC32XXConfig::Init() +{ + cc32xxLog("[%s], KVS List created", __FUNCTION__); + pList = new CC32XXKVSList(); + ReadKVSFromNV(); + return CHIP_NO_ERROR; +} + +CHIP_ERROR CC32XXConfig::ReadConfigValue(Key key, bool & val) +{ + CHIP_ERROR ret; + size_t ignore; + uint8_t localVal; + cc32xxLog("[%s]", __FUNCTION__); + + ret = ReadConfigValueBin(key, &localVal, sizeof(localVal), ignore); + + // reference CC32XXConfig::WriteConfigValue(Key key, bool val) for storage of boolean values + val = (localVal != 0); + + return ret; +} + +CHIP_ERROR CC32XXConfig::ReadConfigValue(Key key, uint32_t & val) +{ + size_t ignore; + return ReadConfigValueBin(key, (uint8_t *) &val, sizeof(val), ignore); +} + +CHIP_ERROR CC32XXConfig::ReadConfigValue(Key key, uint64_t & val) +{ + size_t ignore; + return ReadConfigValueBin(key, (uint8_t *) &val, sizeof(val), ignore); +} + +CHIP_ERROR CC32XXConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return ReadConfigValueBin(key, (uint8_t *) buf, bufSize, outLen); +} + +CHIP_ERROR CC32XXConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + cc32xxLog("[%s]", __FUNCTION__); + + CC32XXKVSEntry * pEntry = pList->GetEntryByKey(key.key); + + VerifyOrReturnError(pEntry != nullptr, CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + + pEntry->ReadVal(buf, bufSize); + if (outLen) + { + outLen = pEntry->Len(); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR CC32XXConfig::WriteConfigValue(Key key, bool val) +{ + uint8_t localVal = val ? 1 : 0; + return WriteConfigValueBin(key, (const uint8_t *) &localVal, sizeof(localVal)); +} + +CHIP_ERROR CC32XXConfig::WriteConfigValue(Key key, uint32_t val) +{ + return WriteConfigValueBin(key, (const uint8_t *) &val, sizeof(val)); +} + +CHIP_ERROR CC32XXConfig::WriteConfigValue(Key key, uint64_t val) +{ + return WriteConfigValueBin(key, (const uint8_t *) &val, sizeof(val)); +} + +CHIP_ERROR CC32XXConfig::WriteConfigValueStr(Key key, const char * str) +{ + size_t strLen = strlen(str); + return WriteConfigValueBin(key, (const uint8_t *) str, strLen); +} +CHIP_ERROR CC32XXConfig::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return WriteConfigValueBin(key, (const uint8_t *) str, strLen); +} + +CHIP_ERROR CC32XXConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + cc32xxLog("[%s]", __FUNCTION__); + CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; + err = pList->AddEntryByKey(key.key, data, (uint16_t) dataLen); + return err; +} + +CHIP_ERROR CC32XXConfig::ClearConfigValue(Key key) +{ + cc32xxLog("[%s]", __FUNCTION__); + CHIP_ERROR err = CHIP_NO_ERROR; + pList->DeleteEntryByKey(key.key); + return err; +} + +bool CC32XXConfig::ConfigValueExists(Key key) +{ + cc32xxLog("[%s]", __FUNCTION__); + bool ret = false; + CC32XXKVSEntry * pEntry = pList->GetEntryByKey(key.key); + if (pEntry) + ret = true; + return ret; +} + +CHIP_ERROR CC32XXConfig::FactoryResetConfig() +{ + cc32xxLog("[%s]", __FUNCTION__); + while (1) + ; + CHIP_ERROR err = CHIP_NO_ERROR; + return err; +} + +void CC32XXConfig::RunConfigUnitTest() +{ + cc32xxLog("[%s]", __FUNCTION__); + // Run common unit test. + ::chip::DeviceLayer::Internal::RunConfigUnitTest(); +} + +CHIP_ERROR CC32XXConfig::ClearKVS(const char * key) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + char keyBuffer[40] = ""; + memcpy(keyBuffer, key, strlen(key)); + err = pList->DeleteEntryByKey(keyBuffer); + cc32xxLog("[%s] key %s", __FUNCTION__, key); + return err; +} + +CHIP_ERROR CC32XXConfig::WriteKVS(const char * key, const void * value, size_t value_size) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + cc32xxLog("[%s] Key is %s value size is %d ", __FUNCTION__, key, value_size); + // Write key value pair as LL entry in RAM buffer + char keyBuffer[40] = ""; + memcpy(keyBuffer, key, strlen(key)); + pList->AddEntryByKey(keyBuffer, (uint8_t *) value, value_size); + + return err; +} + +CHIP_ERROR CC32XXConfig::ReadKVS(const char * key, void * value, size_t value_size, size_t * read_bytes_size, size_t offset_bytes) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + CC32XXKVSEntry * entry = pList->GetEntryByKey(key); + // if (!entry) + // { + // err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + // return err; + // } + VerifyOrReturnError(entry != nullptr, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + uint8_t * entryValue = entry->Value(); + uint16_t valueLen = entry->Len(); + + size_t readLen; + + if ((offset_bytes + value_size) > valueLen) + { + // trying to read up to the end of the element + readLen = valueLen - offset_bytes; + } + else + { + readLen = value_size; + } + + memcpy(value, entryValue + offset_bytes, readLen); + + if (read_bytes_size) + { + *read_bytes_size = readLen; + } + + cc32xxLog("[%s] key %s, read %d bytes", __FUNCTION__, key, readLen); + return err; +} + +CHIP_ERROR CC32XXConfig::WriteKVSToNV() +{ + uint8_t * list = pList->SerializeLinkedList(&NVBufferLength); + + uint32_t token = KVS_TOKEN; + + uint32_t fileSystemFlags = SL_FS_CREATE_STATIC_TOKEN | SL_FS_CREATE_VENDOR_TOKEN; + + int ret = FILE_write(listName, NVBufferLength, list, &token, fileSystemFlags); + if (ret < 0) + { + cc32xxLog("could not write in Linked List to NV, error %d", ret); + return CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } + + else + { + return CHIP_NO_ERROR; + } + // return error +} + +CHIP_ERROR CC32XXConfig::ReadKVSFromNV() +{ + int rc; + uint16_t bufferLength; + + uint8_t * list = new uint8_t[NV_BUFFER_SIZE]; + rc = FILE_read((int8_t *) listName, NV_BUFFER_SIZE, list, KVS_TOKEN); + if (rc > 0) + { + bufferLength = rc; + pList->CreateLinkedListFromNV(list, bufferLength); + cc32xxLog("read in KVS Linked List from NV"); + return CHIP_NO_ERROR; + } + else + { + cc32xxLog("could not read in Linked List from NV, error %d", rc); + return CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/CC32XXConfig.h b/src/platform/cc32xx/CC32XXConfig.h new file mode 100644 index 00000000000000..5824afa3d50042 --- /dev/null +++ b/src/platform/cc32xx/CC32XXConfig.h @@ -0,0 +1,101 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Utilities for accessing persisted device configuration on + * Texas Instruments cc32xx SoCs. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +class CC32XXConfig +{ +public: + struct Key; + + // Key definitions for well-known keys. + static const Key kConfigKey_SerialNum; + static const Key kConfigKey_MfrDeviceId; + static const Key kConfigKey_MfrDeviceCert; + static const Key kConfigKey_MfrDeviceICACerts; + static const Key kConfigKey_MfrDevicePrivateKey; + static const Key kConfigKey_HardwareVersion; + static const Key kConfigKey_ManufacturingDate; + static const Key kConfigKey_SetupPinCode; + static const Key kConfigKey_SetupDiscriminator; + static const Key kConfigKey_FabricId; + static const Key kConfigKey_ServiceConfig; + static const Key kConfigKey_PairedAccountId; + static const Key kConfigKey_ServiceId; + static const Key kConfigKey_FabricSecret; + static const Key kConfigKey_GroupKeyIndex; + static const Key kConfigKey_LastUsedEpochKeyId; + static const Key kConfigKey_FailSafeArmed; + static const Key kConfigKey_WiFiStationSecType; + static const Key kConfigKey_RegulatoryLocation; + static const Key kConfigKey_CountryCode; + static const Key kConfigKey_Breadcrumb; + static const Key kConfigKey_UniqueId; + + static const Key kConfigKey_Spake2pIterationCount; + static const Key kConfigKey_Spake2pSalt; + static const Key kConfigKey_Spake2pVerifier; + + static CHIP_ERROR Init(void); + + // Config value accessors. + static CHIP_ERROR ReadConfigValue(Key key, bool & val); + static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val); + static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val); + static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen); + static CHIP_ERROR WriteConfigValue(Key key, bool val); + static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); + static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str); + static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen); + static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen); + static CHIP_ERROR ClearConfigValue(Key key); + static bool ConfigValueExists(Key key); + static CHIP_ERROR FactoryResetConfig(void); + + static void RunConfigUnitTest(void); + + // internal to the platform for KeyValueStoreManagerImpl.cpp + static CHIP_ERROR ReadKVS(const char * key, void * value, size_t value_size, size_t * read_bytes_size, size_t offset_bytes); + static CHIP_ERROR WriteKVS(const char * key, const void * value, size_t value_size); + static CHIP_ERROR ClearKVS(const char * key); + + static CHIP_ERROR WriteKVSToNV(void); + static CHIP_ERROR ReadKVSFromNV(void); +}; + +struct CC32XXConfig::Key +{ + char key[40]; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/CHIPDevicePlatformConfig.h b/src/platform/cc32xx/CHIPDevicePlatformConfig.h new file mode 100644 index 00000000000000..0a3b387aa4df0e --- /dev/null +++ b/src/platform/cc32xx/CHIPDevicePlatformConfig.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the chip Device Layer + * for the Texas Instruments CC32XX platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#ifndef CHIP_DEVICE_PLATFORM_CONFIG_H +#define CHIP_DEVICE_PLATFORM_CONFIG_H + +// XXX: Seth this needs to be updated for TI devices + +// ==================== Platform Adaptations ==================== + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP | CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + +// ========== Platform-specific Configuration ========= + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 +#define CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0 + +// ========== CHIP Platform Configuration ========= +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (8192) +#endif // CHIP_DEVICE_PLATFORM_CONFIG_H diff --git a/src/platform/cc32xx/CHIPDevicePlatformEvent.h b/src/platform/cc32xx/CHIPDevicePlatformEvent.h new file mode 100644 index 00000000000000..4085925ef7b5bc --- /dev/null +++ b/src/platform/cc32xx/CHIPDevicePlatformEvent.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Defines platform-specific event types and data for the chip + * for the Texas Instruments CC32XX platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#ifndef CHIP_DEVICE_PLATFORM_EVENT_H +#define CHIP_DEVICE_PLATFORM_EVENT_H + +#include + +// XXX: Seth, what device events do we need + +namespace chip { +namespace DeviceLayer { + +/** + * Represents platform-specific event information + */ +struct ChipDevicePlatformEvent final +{ +}; + +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_PLATFORM_EVENT_H diff --git a/src/platform/cc32xx/CHIPPlatformConfig.h b/src/platform/cc32xx/CHIPPlatformConfig.h new file mode 100644 index 00000000000000..5eb53c5f41452f --- /dev/null +++ b/src/platform/cc32xx/CHIPPlatformConfig.h @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for CHIP on + * the Texas Instruments CC32XX platform. + * + */ + +#ifndef CHIP_PLATFORM_CONFIG_H +#define CHIP_PLATFORM_CONFIG_H + +#include + +// ==================== General Platform Adaptations ==================== + +// XXX: Seth is there a platform specific error we can use?? +#define CHIP_CONFIG_ERROR_TYPE uint32_t +#define CHIP_CONFIG_NO_ERROR (0) + +// XXX: Seth is there a platform specific error we can use?? +#define ASN1_CONFIG_ERROR_TYPE uint32_t +#define ASN1_CONFIG_NO_ERROR (0) + +// XXX: Seth is there a platform specific version that would work better +#define ChipDie() assert() + +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE char * +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 + +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_GLOBAL_MESSAGE_COUNTER (char *) "GlobalMCTR" + +// ==================== Security Adaptations ==================== + +// XXX: Seth, how much of this can we move to mbedtls?? +#define CHIP_CONFIG_USE_OPENSSL_ECC 0 +#define CHIP_CONFIG_USE_MICRO_ECC 1 + +#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 +#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0 +#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1 +#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1 + +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1 + +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 + +#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 + +#define CHIP_CONFIG_ENABLE_SERVER_IM_EVENT 1 + +// ==================== General Configuration Overrides ==================== + +/* none yet */ + +#endif /* CHIP_PLATFORM_CONFIG_H */ diff --git a/src/platform/cc32xx/ConfigurationManagerImpl.cpp b/src/platform/cc32xx/ConfigurationManagerImpl.cpp new file mode 100644 index 00000000000000..36028eab69a18d --- /dev/null +++ b/src/platform/cc32xx/ConfigurationManagerImpl.cpp @@ -0,0 +1,201 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides the implementation of the Device Layer ConfigurationManager object + * for the Texas Instruments CC32XX platform. + * + */ + +/* this file behaves like a config.h, comes first */ +#include + +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include + +#include + +#include +extern "C" void cc32xxLog(const char * aFormat, ...); + +namespace chip { +namespace DeviceLayer { + +using namespace ::chip::DeviceLayer::Internal; + +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + +CHIP_ERROR ConfigurationManagerImpl::Init() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + // Initialize the generic implementation base class. + err = Internal::GenericConfigurationManagerImpl::Init(); + + return err; +} + +bool ConfigurationManagerImpl::CanFactoryReset() +{ + // TODO: query the application to determine if factory reset is allowed. + return true; +} + +void ConfigurationManagerImpl::InitiateFactoryReset() +{ + PlatformMgr().ScheduleWork(DoFactoryReset); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) +{ + + CC32XXConfig::Key configKey{ *key }; + + CHIP_ERROR err = ReadConfigValue(configKey, value); + + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + uint16_t macAddressLen = SL_MAC_ADDR_LEN; + uint16_t ConfigOpt = 0; + sl_NetCfgGet(SL_NETCFG_MAC_ADDRESS_GET, &ConfigOpt, &macAddressLen, (_u8 *) buf); + return CHIP_NO_ERROR; + +#else + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#endif +} + +CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) +{ + CC32XXConfig::Key configKey{ *key }; + return WriteConfigValue(configKey, value); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return CC32XXConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return CC32XXConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return CC32XXConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return CC32XXConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return CC32XXConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return CC32XXConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return CC32XXConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return CC32XXConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return CC32XXConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return CC32XXConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return CC32XXConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + CC32XXConfig::RunConfigUnitTest(); +} + +void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) +{ + CHIP_ERROR err; + + ChipLogProgress(DeviceLayer, "Performing factory reset"); + + err = CC32XXConfig::FactoryResetConfig(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); + } + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + + ChipLogProgress(DeviceLayer, "Clearing Thread provision"); + ThreadStackMgr().ErasePersistentInfo(); + +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD + + // Restart the system. + ChipLogProgress(DeviceLayer, "System restarting"); + // There should probably be an OS API for this + MAP_PRCMHibernateCycleTrigger(); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/ConfigurationManagerImpl.h b/src/platform/cc32xx/ConfigurationManagerImpl.h new file mode 100644 index 00000000000000..64be94ae27f57e --- /dev/null +++ b/src/platform/cc32xx/ConfigurationManagerImpl.h @@ -0,0 +1,73 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides an implementation of the ConfigurationManager object + * for the Texas Instruments CC32XX platform. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConfigurationManager singleton object for the CC32XX platform. + */ +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl +{ +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + +private: + // ===== Members that implement the ConfigurationManager public interface. + + CHIP_ERROR Init(void) override; + CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override; + bool CanFactoryReset(void) override; + void InitiateFactoryReset(void) override; + CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override; + CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; + + // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + + // ===== Private members reserved for use by this class only. + + static void DoFactoryReset(intptr_t arg); +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/ConnectivityManagerImpl.cpp b/src/platform/cc32xx/ConnectivityManagerImpl.cpp new file mode 100644 index 00000000000000..f1b6785bf78535 --- /dev/null +++ b/src/platform/cc32xx/ConnectivityManagerImpl.cpp @@ -0,0 +1,239 @@ +/* + * + * Copyright (c) 2020 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. + */ +/* this file behaves like a config.h, comes first */ +#include + +#include +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#endif +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +extern "C" { +#include + +#define SLNETCONN_TIMEOUT 0xffff // "infinite" Timeout + +extern int LWIP_IF_start(); +extern void SlNetConnEventHandler(uint32_t ifID, SlNetConnStatus_e netStatus, void * data); +} + +#if !CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#error "WiFi Station support must be enabled when building for CC32XX" +#endif + +#if !CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP +#error "WiFi AP support must be enabled when building for CC32XX" +#endif + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::System; +using namespace ::chip::TLV; + +extern "C" void cc32xxLog(const char * aFormat, ...); + +namespace chip { +namespace DeviceLayer { + +ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; + +ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void) +{ + cc32xxLog("ConnectivityManagerImpl::_GetWiFiStationMode()\n\r"); + return mWiFiStationMode; +} + +bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) +{ + cc32xxLog("ConnectivityManagerImpl::_IsWiFiStationEnabled()\n\r"); + return GetWiFiStationMode() == kWiFiStationMode_Enabled; +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val) +{ + cc32xxLog("ConnectivityManagerImpl::_SetWiFiStationMode(%d)\n\r", val); + return CHIP_NO_ERROR; +} + +bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) +{ + cc32xxLog("ConnectivityManagerImpl::_IsWiFiStationProvisioned()\n\r"); + return true; +} + +void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) +{ + cc32xxLog("ConnectivityManagerImpl::_ClearWiFiStationProvision()\n\r"); +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + cc32xxLog("ConnectivityManagerImpl::_SetWiFiAPMode(%d)\n\r", val); + return err; +} + +void ConnectivityManagerImpl::_DemandStartWiFiAP(void) +{ + cc32xxLog("ConnectivityManagerImpl::_DemandStartWiFiAP()\n\r"); +} + +void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void) +{ + cc32xxLog("ConnectivityManagerImpl::_StopOnDemandWiFiAP()\n\r"); +} + +void ConnectivityManagerImpl::_MaintainOnDemandWiFiAP(void) +{ + cc32xxLog("ConnectivityManagerImpl::_MaintainOnDemandWiFiAP()\n\r"); +} + +void ConnectivityManagerImpl::_SetWiFiAPIdleTimeoutMS(uint32_t val) +{ + cc32xxLog("ConnectivityManagerImpl::_SetWiFiAPIdleTimeoutMS()\n\r"); + mWiFiAPIdleTimeoutMS = val; + // SystemLayer.ScheduleWork(DriveAPState, NULL); +} + +CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWifiStatsCounters(void) +{ + cc32xxLog("ConnectivityManagerImpl::_GetAndLogWifiStatsCounters()\n\r"); + return CHIP_NO_ERROR; +} + +// ==================== ConnectivityManager Platform Internal Methods ==================== + +CHIP_ERROR ConnectivityManagerImpl::_Init() +{ + + cc32xxLog("ConnectivityManagerImpl::_Init()\n\r"); + + int rc; + cc32xxLog("Start Wi-Fi\r\n"); + /* Try to connect to AP and go through provisioning (if needed) */ + rc = SlNetConn_start(SLNETCONN_SERVICE_LVL_MAC, SlNetConnEventHandler, SLNETCONN_TIMEOUT, 0); + assert(rc == 0); + + cc32xxLog("Start LWIP IF\n\r"); + rc = LWIP_IF_start(); + if (rc != 0) + { + cc32xxLog("LWIP IF not started, error = ", rc); + } + + return CHIP_NO_ERROR; +} + +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) +{ + cc32xxLog("ConnectivityManagerImpl::_OnPlatformEvent()\n\r"); + + if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete) + { + // if (event->CommissioningComplete.Status == CHIP_NO_ERROR) + // { + ChipLogProgress(AppServer, "Commissioning completed successfully"); + DeviceLayer::Internal::CC32XXConfig::WriteKVSToNV(); + // } + // else + // { + // ChipLogError(AppServer, "Commissioning failed with error %" CHIP_ERROR_FORMAT, + // event->CommissioningComplete.Status.Format()); + // } + } +} + +void ConnectivityManagerImpl::_OnWiFiScanDone() +{ + cc32xxLog("ConnectivityManagerImpl::_OnWiFiScanDone()\n\r"); +} +void ConnectivityManagerImpl::_OnWiFiStationProvisionChange() +{ + cc32xxLog("ConnectivityManagerImpl::_OnWiFiStationProvisionChange()\n\r"); +} + +// ==================== ConnectivityManager Private Methods ==================== + +void ConnectivityManagerImpl::DriveStationState() +{ + cc32xxLog("ConnectivityManagerImpl::DriveStationState()\n\r"); +} + +void ConnectivityManagerImpl::OnStationConnected() +{ + cc32xxLog("ConnectivityManagerImpl::OnStationConnected()\n\r"); +} + +void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState) +{ + cc32xxLog("ConnectivityManagerImpl::ChangeWiFiStationState()\n\r"); +} + +CHIP_ERROR ConnectivityManagerImpl::ConfigureWiFiAP() +{ + cc32xxLog("ConnectivityManagerImpl::ConfigureWiFiAP()\n\r"); + return CHIP_NO_ERROR; +} + +void ConnectivityManagerImpl::ChangeWiFiAPState(WiFiAPState newState) +{ + cc32xxLog("ConnectivityManagerImpl::ChangeWiFiAPState()\n\r"); +} + +void ConnectivityManagerImpl::UpdateInternetConnectivityState(void) +{ + cc32xxLog("ConnectivityManagerImpl::UpdateInternetConnectivityState()\n\r"); +} + +void ConnectivityManagerImpl::OnStationIPv4AddressAvailable() +{ + cc32xxLog("ConnectivityManagerImpl::OnStationIPv4AddressAvailable()\n\r"); +} + +void ConnectivityManagerImpl::OnStationIPv4AddressLost(void) +{ + cc32xxLog("ConnectivityManagerImpl::OnStationIPv4AddressLost()\n\r"); +} + +void ConnectivityManagerImpl::OnIPv6AddressAvailable() +{ + cc32xxLog("ConnectivityManagerImpl::OnIPv6AddressAvailable()\n\r"); +} + +void ConnectivityManagerImpl::RefreshMessageLayer(void) +{ + cc32xxLog("ConnectivityManagerImpl::RefreshMessageLayer()\n\r"); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/ConnectivityManagerImpl.h b/src/platform/cc32xx/ConnectivityManagerImpl.h new file mode 100644 index 00000000000000..75d9866fbcb5af --- /dev/null +++ b/src/platform/cc32xx/ConnectivityManagerImpl.h @@ -0,0 +1,168 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ +/** + * @file + * Platform-specific connectivity manager class + * for the Texas Instruments CC32XX platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#pragma once + +#include +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#else +#include +#endif +#include + +namespace chip { +namespace Inet { + +class IPAddress; + +} // namespace Inet +} // namespace chip + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConnectivityManager singleton object for the CC32XX platforms. + */ +class ConnectivityManagerImpl final : public ConnectivityManager, + public Internal::GenericConnectivityManagerImpl, + public Internal::GenericConnectivityManagerImpl_WiFi, +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif + public Internal::GenericConnectivityManagerImpl_NoThread + +{ + // Allow the ConnectivityManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConnectivityManager; + +private: + // ===== Members that implement the ConnectivityManager abstract interface. + + WiFiStationMode _GetWiFiStationMode(void); + CHIP_ERROR _SetWiFiStationMode(WiFiStationMode val); + bool _IsWiFiStationEnabled(void); + bool _IsWiFiStationApplicationControlled(void); + bool _IsWiFiStationConnected(void); + uint32_t _GetWiFiStationReconnectIntervalMS(void); + CHIP_ERROR _SetWiFiStationReconnectIntervalMS(uint32_t val); + bool _IsWiFiStationProvisioned(void); + void _ClearWiFiStationProvision(void); + WiFiAPMode _GetWiFiAPMode(void); + CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val); + bool _IsWiFiAPActive(void); + bool _IsWiFiAPApplicationControlled(void); + void _DemandStartWiFiAP(void); + void _StopOnDemandWiFiAP(void); + void _MaintainOnDemandWiFiAP(void); + uint32_t _GetWiFiAPIdleTimeoutMS(void); + void _SetWiFiAPIdleTimeoutMS(uint32_t val); + CHIP_ERROR _GetAndLogWifiStatsCounters(void); + bool _HaveIPv4InternetConnectivity(void); + bool _HaveIPv6InternetConnectivity(void); + bool _HaveServiceConnectivity(void); + CHIP_ERROR _Init(void); + void _OnPlatformEvent(const ChipDeviceEvent * event); + bool _CanStartWiFiScan(); + void _OnWiFiScanDone(); + void _OnWiFiStationProvisionChange(); + + // ===== Members for internal use by the following friends. + + friend ConnectivityManager & ConnectivityMgr(void); + friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); + + static ConnectivityManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + + uint64_t mLastStationConnectFailTime; + uint64_t mLastAPDemandTime; + WiFiStationMode mWiFiStationMode; + WiFiStationState mWiFiStationState; + WiFiAPMode mWiFiAPMode; + WiFiAPState mWiFiAPState; + uint32_t mWiFiStationReconnectIntervalMS; + uint32_t mWiFiAPIdleTimeoutMS; + uint16_t mFlags; + + void DriveStationState(void); + void OnStationConnected(void); + void OnStationDisconnected(void); + void ChangeWiFiStationState(WiFiStationState newState); + // static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError); + + void DriveAPState(void); + CHIP_ERROR ConfigureWiFiAP(void); + void ChangeWiFiAPState(WiFiAPState newState); + // static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError); + + void UpdateInternetConnectivityState(void); + void OnStationIPv4AddressAvailable(); + void OnStationIPv4AddressLost(void); + void OnIPv6AddressAvailable(); + + static void RefreshMessageLayer(void); +}; + +inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void) +{ + return false; +} + +inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void) +{ + return false; +} + +/** + * Returns the public interface of the ConnectivityManager singleton object. + * + * chip applications should use this to access features of the ConnectivityManager object + * that are common to all platforms. + */ +inline ConnectivityManager & ConnectivityMgr(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConnectivityManager singleton object. + * + * chip applications can use this to gain access to features of the ConnectivityManager + * that are specific to the CC32XX platform + */ +inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.cpp new file mode 100644 index 00000000000000..0f87641906c80b --- /dev/null +++ b/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.cpp @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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 "DeviceNetworkProvisioningDelegateImpl.h" + +#if CHIP_ENABLE_OPENTHREAD +#include +#endif + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR +DeviceNetworkProvisioningDelegateImpl::_ProvisionThreadNetwork(ByteSpan threadData) +{ +#if CHIP_ENABLE_OPENTHREAD + CHIP_ERROR error = CHIP_NO_ERROR; + + SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(false)); + SuccessOrExit(error = ThreadStackMgr().SetThreadProvision(threadData)); + SuccessOrExit(error = ThreadStackMgr().SetThreadEnabled(true)); +exit: + return error; +#else + return CHIP_ERROR_NOT_IMPLEMENTED; +#endif // CHIP_ENABLE_OPENTHREAD +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.h new file mode 100644 index 00000000000000..e799358e4b7536 --- /dev/null +++ b/src/platform/cc32xx/DeviceNetworkProvisioningDelegateImpl.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +namespace Internal { + +template +class GenericDeviceNetworkProvisioningDelegateImpl; + +} // namespace Internal + +class DeviceNetworkProvisioningDelegateImpl final + : public Internal::GenericDeviceNetworkProvisioningDelegateImpl +{ + friend class GenericDeviceNetworkProvisioningDelegateImpl; + +private: + CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData); +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/DiagnosticDataProviderImpl.cpp b/src/platform/cc32xx/DiagnosticDataProviderImpl.cpp new file mode 100644 index 00000000000000..17f9fbbe3cca41 --- /dev/null +++ b/src/platform/cc32xx/DiagnosticDataProviderImpl.cpp @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides an implementation of the DiagnosticDataProvider object + * for cc32xx platform. + */ + +#include + +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance() +{ + static DiagnosticDataProviderImpl sInstance; + return sInstance; +} + +/* + * The following Heap stats are compiled values done by the heap4 heap implementation. + */ +CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree) +{ + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeapUsed) +{ + return CHIP_NO_ERROR; +} + +CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut) +{ + return CHIP_NO_ERROR; +} + +void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetrics) {} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/DiagnosticDataProviderImpl.h b/src/platform/cc32xx/DiagnosticDataProviderImpl.h new file mode 100644 index 00000000000000..b742146267621d --- /dev/null +++ b/src/platform/cc32xx/DiagnosticDataProviderImpl.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides an implementation of the DiagnosticDataProvider object. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the PlatformManager singleton object for Linux platforms. + */ +class DiagnosticDataProviderImpl : public DiagnosticDataProvider +{ +public: + static DiagnosticDataProviderImpl & GetDefaultInstance(); + + // ===== Methods that implement the PlatformManager abstract interface. + CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override; + CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override; + CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut) override; + void ReleaseThreadMetrics(ThreadMetrics * threadMetrics) override; +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/FreeRTOSConfig.h b/src/platform/cc32xx/FreeRTOSConfig.h new file mode 100644 index 00000000000000..feece6421568b9 --- /dev/null +++ b/src/platform/cc32xx/FreeRTOSConfig.h @@ -0,0 +1,212 @@ +/* + * + * Copyright (c) 2020 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. + */ + +/****************************************************************************** + See http://www.freertos.org/a00110.html for an explanation of the + definitions contained in this file. +******************************************************************************/ + +#pragma once + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* Constants related to the behaviour or the scheduler. */ +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#define configTICK_RATE_HZ ((TickType_t) 1000) +#define configUSE_PREEMPTION 1 +#define configUSE_TIME_SLICING 0 +#define configMAX_PRIORITIES (10UL) +#define configIDLE_SHOULD_YIELD 0 +#define configUSE_16_BIT_TICKS 0 /* Only for 8 and 16-bit hardware. */ + +/* Constants used to specify if only static allocation is to be supported (in +which case a heap_n.c file is not required), only dynamic allocation is to be +supported, or if both static and dynamic allocation are supported. */ +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 + +/* Constants that describe the hardware and memory usage. */ +#define configCPU_CLOCK_HZ ((unsigned long) 80000000) +/* Smallest stack size allowed in words */ +#define configMINIMAL_STACK_SIZE ((unsigned short) 256) // changed from 128 +#define configMAX_TASK_NAME_LEN (12) + +#define configTOTAL_HEAP_SIZE ((size_t)(0x14000)) // inreased from 0xe000 + +/* Idle task stack size in words */ +#define configIDLE_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) + +/* Default stack size for TI-POSIX threads (in words) */ +#define configPOSIX_STACK_SIZE ((unsigned short) 512) // changed from 256 + +/* Constants that build features in or out. */ +#define configUSE_MUTEXES 1 +#define configUSE_TICKLESS_IDLE 1 +#define configUSE_APPLICATION_TASK_TAG 1 /* Need by POSIX/pthread */ +#define configUSE_CO_ROUTINES 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_QUEUE_SETS 0 +#define configUSE_TASK_NOTIFICATIONS 1 + +/* Constants that define which hook (callback) functions should be used. */ +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configUSE_MALLOC_FAILED_HOOK 0 + +/* Constants provided for debugging and optimisation assistance. */ +#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configASSERT(x) \ + if ((x) == 0) \ + { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) \ + ; \ + } +#define configQUEUE_REGISTRY_SIZE 0 + +/* + * Minimum number of full tick periods of idle time required to run Power + * sleep policy function. + */ +#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 5 + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (6) +#define configTIMER_QUEUE_LENGTH (20) +/* Timer task stack size in words */ +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) + +#define configENABLE_BACKWARD_COMPATIBILITY 1 + +#if defined(__TI_COMPILER_VERSION__) || defined(__ti_version__) +#include +#define traceTASK_DELETE(pxTCB) PTLS_taskDeleteHook(pxTCB) +#elif defined(__IAR_SYSTEMS_ICC__) +#ifndef __IAR_SYSTEMS_ASM__ +#include +#define traceTASK_DELETE(pxTCB) Mtx_taskDeleteHook(pxTCB) +#endif +#endif + +/* + * Enable thread local storage + * + * Assign TLS array index ownership here to avoid collisions. + * TLS storage is needed to implement thread-safe errno with + * TI and IAR compilers. With GNU compiler, we enable newlib. + */ +#if defined(__TI_COMPILER_VERSION__) || defined(__ti_version__) || defined(__IAR_SYSTEMS_ICC__) + +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1 + +#if defined(__TI_COMPILER_VERSION__) || defined(__ti_version__) +#define PTLS_TLS_INDEX 0 /* ti.posix.freertos.PTLS */ +#elif defined(__IAR_SYSTEMS_ICC__) +#define MTX_TLS_INDEX 0 /* ti.posix.freertos.Mtx */ +#endif + +#elif defined(__GNUC__) +/* note: system locks required by newlib are not implemented */ +#define configUSE_NEWLIB_REENTRANT 1 +#endif + +/* + * Set the following definitions to 1 to include the API function, or zero + * to exclude the API function. NOTE: Setting an INCLUDE_ parameter to 0 is only + * necessary if the linker does not automatically remove functions that are not + * referenced anyway. + */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 0 +#define INCLUDE_xTaskGetIdleTaskHandle 0 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTaskResumeFromISR 0 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_xTaskGetSchedulerState 0 +#define INCLUDE_xSemaphoreGetMutexHolder 0 +#define INCLUDE_xTimerPendFunctionCall 0 + +/* Cortex-M3/4 interrupt priority configuration follows...................... */ + +/* Use the system definition, if there is one. */ +#ifdef __NVIC_PRIO_BITS +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 3 /* 8 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0x07 + +/* + * The highest interrupt priority that can be used by any interrupt service + * routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL + * INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER + * PRIORITY THAN THIS! (higher priorities are lower numeric values. + */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1 + +/* + * Priority 7 (shifted 5 since only the top 3 bits are implemented). + * Priority 7 is the lowest priority. + */ +#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* + * Priority 1 (shifted 5 since only the top 3 bits are implemented). + * Priority 1 is the second highest priority. + * Priority 0 is the highest priority. + * !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. + */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* The trace facility is turned on to make some functions available for use in +CLI commands. */ +#define configUSE_TRACE_FACILITY 1 + +/* Constants related to the generation of run time stats. */ +#define configGENERATE_RUN_TIME_STATS 0 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() +#define portGET_RUN_TIME_COUNTER_VALUE() 0 + +/* + * Runtime Object View is a Texas Instrument host tool that helps visualize + * the application. When enabled, the ISR stack will be initialized in the + * startup__.c file to 0xa5a5a5a5. The stack peak can then + * be displayed in Runtime Object View. + */ +#define configENABLE_ISR_STACK_INIT 1 diff --git a/src/platform/cc32xx/InetPlatformConfig.h b/src/platform/cc32xx/InetPlatformConfig.h new file mode 100644 index 00000000000000..c40a4031de6033 --- /dev/null +++ b/src/platform/cc32xx/InetPlatformConfig.h @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the Openchip Inet + * Layer on CC32XX platforms using the Texas Instruments SDK. + * + */ + +#ifndef INET_PLATFORM_CONFIG_H +#define INET_PLATFORM_CONFIG_H + +// XXX: Seth update config? + +// ==================== Platform Adaptations ==================== + +// XXX: Seth is there a proper platform error type?? +#define INET_CONFIG_ERROR_TYPE uint32_t +#define INET_CONFIG_NO_ERROR (0) + +#define INET_CONFIG_ERROR_MIN 1000000 +#define INET_CONFIG_ERROR_MAX 1000999 + +#define INET_CONFIG_ENABLE_IPV4 1 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef INET_CONFIG_NUM_TCP_ENDPOINTS +#define INET_CONFIG_NUM_TCP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_TCP_ENDPOINTS + +#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS +#define INET_CONFIG_NUM_UDP_ENDPOINTS 4 +#endif // INET_CONFIG_NUM_UDP_ENDPOINTS + +#endif // INET_PLATFORM_CONFIG_H diff --git a/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp new file mode 100644 index 00000000000000..13c1a023443594 --- /dev/null +++ b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp @@ -0,0 +1,66 @@ +/* + * + * Copyright (c) 2021 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. + */ + +/** + * @file + * Platform-specific key value storage implementation for CC32XX + */ + +/* this file behaves like a config.h, comes first */ +#include + +#include + +#include + +#include + +namespace chip { +namespace DeviceLayer { +namespace PersistedStorage { + +using namespace ::chip::DeviceLayer::Internal; + +KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; + +CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, + size_t offset_bytes) const +{ + VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + + return CC32XXConfig::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); +} + +CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) +{ + VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(value_size > 0, CHIP_ERROR_INVALID_ARGUMENT); + + return CC32XXConfig::WriteKVS(key, value, value_size); +} + +CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) +{ + return CC32XXConfig::ClearKVS(key); +} + +} // namespace PersistedStorage +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/KeyValueStoreManagerImpl.h b/src/platform/cc32xx/KeyValueStoreManagerImpl.h new file mode 100644 index 00000000000000..285447bfa543d0 --- /dev/null +++ b/src/platform/cc32xx/KeyValueStoreManagerImpl.h @@ -0,0 +1,75 @@ +/* + * + * Copyright (c) 2021 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. + */ + +/** + * @file + * Platform-specific key value storage implementation for CC32XX + */ + +#pragma once + +namespace chip { +namespace DeviceLayer { +namespace PersistedStorage { + +class KeyValueStoreManagerImpl final : public KeyValueStoreManager +{ + // Allow the KeyValueStoreManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class KeyValueStoreManager; + +public: + CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0) const; + + CHIP_ERROR _Delete(const char * key); + + CHIP_ERROR _Put(const char * key, const void * value, size_t value_size); + +private: + // ===== Members for internal use by the following friends. + friend KeyValueStoreManager & KeyValueStoreMgr(); + friend KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(); + + static KeyValueStoreManagerImpl sInstance; +}; + +/** + * Returns the public interface of the KeyValueStoreManager singleton object. + * + * Chip applications should use this to access features of the KeyValueStoreManager object + * that are common to all platforms. + */ +inline KeyValueStoreManager & KeyValueStoreMgr(void) +{ + return KeyValueStoreManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the KeyValueStoreManager singleton object. + * + * Chip applications can use this to gain access to features of the KeyValueStoreManager + * that are specific to the ESP32 platform. + */ +inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void) +{ + return KeyValueStoreManagerImpl::sInstance; +} + +} // namespace PersistedStorage +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/Logging.cpp b/src/platform/cc32xx/Logging.cpp new file mode 100644 index 00000000000000..4afe6d2db05f8d --- /dev/null +++ b/src/platform/cc32xx/Logging.cpp @@ -0,0 +1,151 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides implementations for the CHIP and LwIP logging functions + * for the Texas Instruments CC32XX platform. This uses one of the + * UARTs configured with SysConfig. Future implementations may use + * ITM. + * + */ + +#include "ti_drivers_config.h" +#include +#include +#include +#include + +#include + +using namespace ::chip; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; + +#define DEVICE_LAYER_LOG_BUFFER_SIZE (256) +static UART2_Handle sDebugUartHandle; +static char sDebugUartBuffer[DEVICE_LAYER_LOG_BUFFER_SIZE]; +// static pthread_mutex_t mutex; + +extern "C" int cc32xxLogInit(void) +{ + UART2_Params uartParams; + + UART2_Params_init(&uartParams); + + uartParams.baudRate = 115200; + sDebugUartHandle = UART2_open(CONFIG_UART2_0, &uartParams); + + /* Remove uart receive from LPDS dependency */ + UART2_rxDisable(sDebugUartHandle); + + /* Enable debug mutex */ + // pthread_mutex_init(&mutex, NULL); + return 0; +} + +extern "C" void cc32xxVLog(const char * msg, va_list v) +{ + int ret; + + // pthread_mutex_lock(&mutex); + ret = vsnprintf(sDebugUartBuffer, sizeof(sDebugUartBuffer), msg, v); + if (0 < ret) + { + // PuTTY likes \r\n + size_t len = (ret + 2U) < sizeof(sDebugUartBuffer) ? (ret + 2) : sizeof(sDebugUartBuffer); + sDebugUartBuffer[len - 2] = '\r'; + sDebugUartBuffer[len - 1] = '\n'; + sDebugUartBuffer[len] = '\0'; + + UART2_write(sDebugUartHandle, sDebugUartBuffer, len, &len); + } + // pthread_mutex_unlock(&mutex); +} + +namespace chip { +namespace DeviceLayer { + +/** + * Called whenever a log message is emitted. + * + * Can be overridden by the device logging file + */ +void __attribute__((weak)) OnLogOutput(void) {} + +} // namespace DeviceLayer +} // namespace chip + +namespace chip { +namespace Logging { +namespace Platform { + +void LogV(const char * module_name, uint8_t category, const char * msg, va_list v) +{ + (void) module_name; + (void) category; + + cc32xxVLog(msg, v); + + DeviceLayer::OnLogOutput(); +} + +void LogV(uint8_t module, uint8_t category, const char * msg, va_list v) +{ + (void) module; + (void) category; + + cc32xxVLog(msg, v); + + DeviceLayer::OnLogOutput(); +} + +} // namespace Platform +} // namespace Logging +} // namespace chip + +/** + * LwIP log output function. + */ +extern "C" void LwIPLog(const char * msg, ...) +{ + va_list v; + + va_start(v, msg); + + cc32xxVLog(msg, v); + + DeviceLayer::OnLogOutput(); + va_end(v); +} + +/** + * Platform log output function. + */ +extern "C" void cc32xxLog(const char * msg, ...) +{ + va_list v; + + va_start(v, msg); + + cc32xxVLog(msg, v); + + DeviceLayer::OnLogOutput(); + va_end(v); +} + +# diff --git a/src/platform/cc32xx/PlatformManagerImpl.cpp b/src/platform/cc32xx/PlatformManagerImpl.cpp new file mode 100644 index 00000000000000..a8795b4891ddcc --- /dev/null +++ b/src/platform/cc32xx/PlatformManagerImpl.cpp @@ -0,0 +1,92 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides an implementation of the PlatformManager object + * for the Texas Instruments CC32XX platform. + */ + +/* this file behaves like a config.h, comes first */ +#include + +#include +#include +#include +#include + +#include + +namespace chip { +namespace DeviceLayer { + +PlatformManagerImpl PlatformManagerImpl::sInstance; + +static int app_get_random(uint8_t * aOutput, size_t aLen) +{ + size_t i; + + // TBD add implementation + for (i = 0; i < aLen; i++) + { + aOutput[i] = i * 31 + 17; + } + return 0; +} + +static void app_random_init(void) +{ + return; +} + +static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen) +{ + + app_get_random(reinterpret_cast(output), static_cast(len)); + *olen = len; + + return 0; +} + +CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) +{ + CHIP_ERROR err; + + // Initialize the configuration system. + err = Internal::CC32XXConfig::Init(); + SuccessOrExit(err); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); + SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance()); + + // Initialize LwIP. + tcpip_init(NULL, NULL); + + app_random_init(); + err = chip::Crypto::add_entropy_source(app_entropy_source, NULL, 16); + SuccessOrExit(err); + + // Call _InitChipStack() on the generic implementation base class + // to finish the initialization process. + err = Internal::GenericPlatformManagerImpl_FreeRTOS::_InitChipStack(); + SuccessOrExit(err); + +exit: + return err; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/PlatformManagerImpl.h b/src/platform/cc32xx/PlatformManagerImpl.h new file mode 100644 index 00000000000000..077e36b98a535e --- /dev/null +++ b/src/platform/cc32xx/PlatformManagerImpl.h @@ -0,0 +1,90 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Provides an implementation of the PlatformManager object. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the PlatformManager singleton object for the CC32XX platform. + */ +class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS +{ + // Allow the PlatformManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend PlatformManager; + + // Allow the generic implementation base class to call helper methods on + // this class. +#ifndef DOXYGEN_SHOULD_SKIP_THIS + friend Internal::GenericPlatformManagerImpl_FreeRTOS; +#endif + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + /* none so far */ + +private: + // ===== Methods that implement the PlatformManager abstract interface. + + CHIP_ERROR _InitChipStack(void); + + // ===== Members for internal use by the following friends. + + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl & PlatformMgrImpl(void); + friend class Internal::BLEManagerImpl; + + static PlatformManagerImpl sInstance; + + using Internal::GenericPlatformManagerImpl_FreeRTOS::PostEventFromISR; +}; + +/** + * Returns the public interface of the PlatformManager singleton object. + * + * chip applications should use this to access features of the PlatformManager + * object that are common to all platforms. + */ +inline PlatformManager & PlatformMgr(void) +{ + return PlatformManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the PlatformManager + * singleton object. + * + * chip applications can use this to gain access to features of the + * PlatformManager that are specific to the CC32XX SoC. + */ +inline PlatformManagerImpl & PlatformMgrImpl(void) +{ + return PlatformManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc32xx/README.md b/src/platform/cc32xx/README.md new file mode 100644 index 00000000000000..d9488eac3aa4ad --- /dev/null +++ b/src/platform/cc32xx/README.md @@ -0,0 +1,83 @@ +# Overview of CHIP CC32XX Adaption + +The following is an overview of the CC32XX adaptation of CHIP. Most of this code +will have parallels in any new adaptation. + +(All file names are relative to `connectedhomeip/src/platform/CC32XX...`). + +`BlePlatformConfig.h` + +- Configuration header for BLE specific configurations +- Required by AutoConf build + +**NOTE** empty for now + +`CC32XXConfig.h`
`CC32XXConfig.cpp` + +- Concrete implementation of the Non-Volatile storage of information for chip + +**NOTE** empty for now + +`CHIPDevicePlatformConfig.h` + +- Configuration for the chip stack for the CC32XX platform + +`CHIPDevicePlatformEvent.h` + +- Definition of platform events to be handled by the chip processing loop +- Currently there are no events that need special handling + +`CHIPPlatformConfig.h`
`InetPlatformConfig.h`
`SystemPlatformConfig.h` + +- Definitions for the chip stack to work with the configurations of the CC32XX + platform + +`ConfigurationManagerImpl.h`
`ConfigurationManagerImpl.cpp` + +- Concrete implementation of ConfigurationManager interface +- Manages storage and retrieval of persistent configuration data +- Relies on GenericConfigurationManagerImpl<> classes to implement most API + functionality +- Delegates low-level reading and writing of persistent values to + `CC32XXConfig` class + +`ConnectivityManagerImpl.h`
`ConnectivityManagerImpl.cpp` + +- Concrete implementation of `ConnectivityManager` interface +- Provides high-level APIs for managing device connectivity +- Relies on `GenericConnectivityManagerImpl_Thread<>` class to provide most of + the implementation + +`Entropy.cpp` + +- Concrete implementation of an entropy source based on the TRNG + +**NOTE** empty for now + +`Logging.cpp` + +- Concrete implementation of the logging functions +- Currently logs out the User UART interface on the XDS110 + +`ThreadStackManagerImpl.h`
`ThreadStackManagerImpl.cpp` + +- Concrete implementation of ThreadStackManager interface +- Supports Thread stack initialization and core event loop processing +- Relies on `GenericThreadStackManagerImpl_OpenThread/FreeRTOS/LwIP<>` classes + to implement most API functionality + +**NOTE** Currently disabled because OpenThread Libraries are not built or linked +in. + +`PlatformManagerImpl.h`
`PlatformManagerImpl.cpp` + +- Concrete implementation of `PlatformManager` interface +- Provides initialization of the CHIP stack and core event loop for the chip + task +- Relies on `GenericPlatformManagerImpl_FreeRTOS<>` class to provide most of + the implementation + +`SoftwareUpdateManagerImpl.cpp` + +- Concrete implementation of the Software Update Manager +- Relies on the `GenericSoftwareUpdateManagerImpl` diff --git a/src/platform/cc32xx/SoftwareUpdateManagerImpl.cpp b/src/platform/cc32xx/SoftwareUpdateManagerImpl.cpp new file mode 100644 index 00000000000000..4b6f5222e31905 --- /dev/null +++ b/src/platform/cc32xx/SoftwareUpdateManagerImpl.cpp @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +// XXX: Seth done in generic?? + +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER + +#include + +namespace chip { +namespace DeviceLayer { + +SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; + +CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) +{ + Internal::GenericSoftwareUpdateManagerImpl::DoInit(); + + return CHIP_NO_ERROR; +} + +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/cc32xx/SystemPlatformConfig.h b/src/platform/cc32xx/SystemPlatformConfig.h new file mode 100644 index 00000000000000..baee83449978b9 --- /dev/null +++ b/src/platform/cc32xx/SystemPlatformConfig.h @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * Platform-specific configuration overrides for the CHIP System + * Layer on CC32XX platforms using the Texas Instruments SDK. + * + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +struct ChipDeviceEvent; +} // namespace DeviceLayer +} // namespace chip + +// ==================== Platform Adaptations ==================== + +//#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 0 +//#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0 +//#define CHIP_SYSTEM_CONFIG_NO_LOCKING 1 +//#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +//#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int +#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * + +// #define CHIP_SYSTEM_CONFIG_ERROR_TYPE uint32_t +// #define CHIP_SYSTEM_CONFIG_NO_ERROR (0) + +// #define CHIP_SYSTEM_CONFIG_ERROR_MIN 0 +// #define CHIP_SYSTEM_CONFIG_ERROR_MAX 999 +// #define _CHIP_SYSTEM_CONFIG_ERROR(e) (CHIP_SYSTEM_CONFIG_ERROR_MIN + (e)) + +// ========== Platform-specific Configuration Overrides ========= + +/* none yet */ diff --git a/src/platform/cc32xx/args.gni b/src/platform/cc32xx/args.gni new file mode 100755 index 00000000000000..288aa5a1edc188 --- /dev/null +++ b/src/platform/cc32xx/args.gni @@ -0,0 +1,36 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") +import("//build_overrides/ti_simplelink_sdk.gni") + +# ARM architecture flags will be set based on Device Family +arm_platform_config = + "${ti_simplelink_sdk_build_root}/ti_simplelink_arm_platform_config.gni" + +chip_device_platform = "cc32xx" + +freertos_target = "${chip_root}/third_party/ti_simplelink_sdk:freertos" + +mbedtls_target = "${chip_root}/third_party/ti_simplelink_sdk:mbedtls" + +lwip_platform = "cc32xx" +lwip_ipv6 = true +lwip_ipv4 = true +lwip_api = true + +chip_inet_config_enable_ipv4 = true +chip_inet_config_enable_dns_resolver = false + +chip_build_tests = false diff --git a/src/platform/cc32xx/cc32xx-mbedtls-config.h b/src/platform/cc32xx/cc32xx-mbedtls-config.h new file mode 100755 index 00000000000000..ad08ee6cf1fca8 --- /dev/null +++ b/src/platform/cc32xx/cc32xx-mbedtls-config.h @@ -0,0 +1,99 @@ +/* + * + * Copyright (c) 2021 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. + */ + +#pragma once + +#include +#include + +#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf + +#define MBEDTLS_AES_C +#define MBEDTLS_AES_ROM_TABLES +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_CCM_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CMAC_C +#define MBEDTLS_CTR_DRBG_C +#define MBEDTLS_ECJPAKE_C +#define MBEDTLS_ECP_C +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_ECP_NIST_OPTIM +#define MBEDTLS_ENTROPY_C +#define MBEDTLS_HAVE_ASM +#define MBEDTLS_HMAC_DRBG_C +#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +#define MBEDTLS_MD_C +#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES +#define MBEDTLS_NO_PLATFORM_ENTROPY +#define MBEDTLS_PK_C +#define MBEDTLS_PK_PARSE_C +#define MBEDTLS_PK_WRITE_C +#define MBEDTLS_PLATFORM_C +#define MBEDTLS_PLATFORM_MEMORY +#define MBEDTLS_PLATFORM_STD_CALLOC calloc +#define MBEDTLS_PLATFORM_STF_FREE free +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_SHA256_C +#define MBEDTLS_SHA256_SMALLER +#define MBEDTLS_SSL_CLI_C +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY +#define MBEDTLS_SSL_EXPORT_KEYS +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +#define MBEDTLS_SSL_PROTO_TLS1_2 +#define MBEDTLS_SSL_PROTO_DTLS +#define MBEDTLS_SSL_TLS_C +#define MBEDTLS_ERROR_STRERROR_DUMMY +#define MBEDTLS_HKDF_C +#define MBEDTLS_X509_CREATE_C +#define MBEDTLS_X509_CSR_WRITE_C +#define MBEDTLS_BASE64_C +#define MBEDTLS_PEM_WRITE_C + +#define MBEDTLS_SSL_COOKIE_C +#define MBEDTLS_SSL_SRV_C + +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + +#define MBEDTLS_BASE64_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_ECDSA_C +#define MBEDTLS_OID_C +#define MBEDTLS_PEM_PARSE_C +#define MBEDTLS_X509_USE_C +#define MBEDTLS_X509_CRT_PARSE_C +#define MBEDTLS_PKCS5_C + +#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */ +#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */ +#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */ +#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */ +#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */ +#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */ + +#define MBEDTLS_MEMORY_BUFFER_ALLOC_C + +#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */ + +#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 + +#include "mbedtls/check_config.h" diff --git a/src/platform/device.gni b/src/platform/device.gni index 8bf94a7e788ae0..9af7d49c0d3141 100755 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -16,7 +16,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/ble/ble.gni") declare_args() { - # Device platform layer: cc13x2_26x2, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, cyw30739, bl602, mw320, zephyr, none. + # Device platform layer: cc13x2_26x2, cc32xx, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, cyw30739, bl602, mw320, zephyr, none. chip_device_platform = "auto" chip_platform_target = "" @@ -62,8 +62,8 @@ declare_args() { chip_device_platform == "linux" || chip_device_platform == "esp32" || chip_device_platform == "mbed" || chip_device_platform == "tizen" || chip_device_platform == "android" || chip_device_platform == "ameba" || - chip_device_platform == "webos" || chip_device_platform == "bl602" || - chip_device_platform == "mw320" + chip_device_platform == "webos" || chip_device_platform == "cc32xx" || + chip_device_platform == "bl602" || chip_device_platform == "bl602" # Enable ble support. if (chip_device_platform == "fake") { @@ -82,7 +82,8 @@ declare_args() { if (chip_device_platform == "linux" || chip_device_platform == "esp32" || chip_device_platform == "mbed" || chip_device_platform == "p6" || chip_device_platform == "ameba" || chip_device_platform == "webos" || - chip_device_platform == "mw320" || chip_device_platform == "bl602") { + chip_device_platform == "cc32xx" || chip_device_platform == "bl602" || + chip_device_platform == "mw320") { chip_mdns = "minimal" } else if (chip_device_platform == "darwin" || chip_device_platform == "cc13x2_26x2" || current_os == "android" || @@ -97,6 +98,8 @@ declare_args() { _chip_device_layer = "none" if (chip_device_platform == "cc13x2_26x2") { _chip_device_layer = "cc13x2_26x2" +} else if (chip_device_platform == "cc32xx") { + _chip_device_layer = "cc32xx" } else if (chip_device_platform == "darwin") { _chip_device_layer = "Darwin" } else if (chip_device_platform == "efr32") { @@ -182,9 +185,10 @@ assert( (current_os != "freertos" && chip_device_platform == "none") || chip_device_platform == "fake" || chip_device_platform == "cc13x2_26x2" || - chip_device_platform == "darwin" || chip_device_platform == "efr32" || - chip_device_platform == "esp32" || chip_device_platform == "external" || - chip_device_platform == "linux" || chip_device_platform == "tizen" || + chip_device_platform == "cc32xx" || chip_device_platform == "darwin" || + chip_device_platform == "efr32" || chip_device_platform == "esp32" || + chip_device_platform == "external" || chip_device_platform == "linux" || + chip_device_platform == "tizen" || chip_device_platform == "nrfconnect" || chip_device_platform == "k32w0" || chip_device_platform == "qpg" || chip_device_platform == "telink" || chip_device_platform == "mbed" || diff --git a/third_party/ti_simplelink_sdk/BUILD.gn b/third_party/ti_simplelink_sdk/BUILD.gn index f968324d78170f..2451ab80e67195 100644 --- a/third_party/ti_simplelink_sdk/BUILD.gn +++ b/third_party/ti_simplelink_sdk/BUILD.gn @@ -35,24 +35,34 @@ group("ti_simplelink_sysconfig") { } config("ti_simplelink_mbedtls_config") { - defines = [ "MBEDTLS_CONFIG_FILE=\"cc13x2_26x2-mbedtls-config.h\"" ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + defines = [ "MBEDTLS_CONFIG_FILE=\"cc13x2_26x2-mbedtls-config.h\"" ] - include_dirs = [ - "${chip_root}/src/platform/cc13x2_26x2", - "${chip_root}/src/platform/cc13x2_26x2/crypto", - "${ti_simplelink_sdk_root}/source", - ] + include_dirs = [ + "${chip_root}/src/platform/cc13x2_26x2", + "${chip_root}/src/platform/cc13x2_26x2/crypto", + "${ti_simplelink_sdk_root}/source", + ] + } else if (ti_simplelink_device_family == "cc32xx") { + defines = [ "MBEDTLS_CONFIG_FILE=\"cc32xx-mbedtls-config.h\"" ] + + include_dirs = [ "${chip_root}/src/platform/cc32xx" ] + } } mbedtls_target("mbedtls") { # Hardware acceleration - sources = [ - "${chip_root}/src/platform/cc13x2_26x2/crypto/aes_alt.c", - "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdh_alt.c", - "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c", - "${chip_root}/src/platform/cc13x2_26x2/crypto/ecjpake_alt.c", - "${chip_root}/src/platform/cc13x2_26x2/crypto/sha256_alt.c", - ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + sources = [ + "${chip_root}/src/platform/cc13x2_26x2/crypto/aes_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdh_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/ecjpake_alt.c", + "${chip_root}/src/platform/cc13x2_26x2/crypto/sha256_alt.c", + ] + } public_configs = [ ":ti_simplelink_mbedtls_config" ] @@ -60,17 +70,33 @@ mbedtls_target("mbedtls") { } config("ti_simplelink_freertos_config") { - include_dirs = [ - "${chip_root}/src/platform/cc13x2_26x2", - "${freertos_root}/repo/portable/GCC/ARM_CM4F", - ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + include_dirs = [ + "${chip_root}/src/platform/cc13x2_26x2", + "${freertos_root}/repo/portable/GCC/ARM_CM4F", + ] + } else if (ti_simplelink_device_family == "cc32xx") { + include_dirs = [ + "${chip_root}/src/platform/cc32xx", + "${freertos_root}/repo/portable/GCC/ARM_CM3", + ] + } } freertos_target("freertos") { - sources = [ - "${freertos_root}/repo/portable/GCC/ARM_CM4F/port.c", - #"${freertos_root}/repo/portable/MemMang/heap_4.c", - ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + sources = [ + "${freertos_root}/repo/portable/GCC/ARM_CM4F/port.c", + #"${freertos_root}/repo/portable/MemMang/heap_4.c", + ] + } else if (ti_simplelink_device_family == "cc32xx") { + sources = [ + "${freertos_root}/repo/portable/GCC/ARM_CM3/port.c", + "${freertos_root}/repo/portable/MemMang/heap_4.c", + ] + } public_configs = [ ":ti_simplelink_freertos_config" ] @@ -78,5 +104,8 @@ freertos_target("freertos") { # BLE has to have it's own heap config public_deps = [ "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig" ] + } else if (ti_simplelink_device_family == "cc32xx") { + public_deps = + [ "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig" ] } } diff --git a/third_party/ti_simplelink_sdk/repo_cc32xx b/third_party/ti_simplelink_sdk/repo_cc32xx new file mode 160000 index 00000000000000..e5fbefba9c3c3a --- /dev/null +++ b/third_party/ti_simplelink_sdk/repo_cc32xx @@ -0,0 +1 @@ +Subproject commit e5fbefba9c3c3afa9c2c967b713c77e282d560fe diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_arm_platform_config.gni b/third_party/ti_simplelink_sdk/ti_simplelink_arm_platform_config.gni index 91cd5911d7df99..2ee40881b23bca 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_arm_platform_config.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_arm_platform_config.gni @@ -22,6 +22,13 @@ if (ti_simplelink_device_family == "cc13x2_26x2" || arm_float_abi = "hard" arm_fpu = "fpv5-sp-d16" arm_use_thumb = true +} else if (ti_simplelink_device_family == "cc32xx") { + arm_arch = "armv7e-m" + arm_abi = "" + arm_cpu = "cortex-m4" + arm_float_abi = "soft" + arm_fpu = "" + arm_use_thumb = true } else { assert(false, "ti_simplelink_device_family must be specified") } diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_board.gni b/third_party/ti_simplelink_sdk/ti_simplelink_board.gni index 782b382b18c590..c6ae89ab2d8d43 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_board.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_board.gni @@ -30,6 +30,8 @@ assert(ti_simplelink_board != "", "ti_simplelink_board must be specified") # | CC1352R1_LAUNCHXL | cc13x2_26x2 | cc1352r1f3 | Thread MTD + no BLE | # | CC2652R1_LAUNCHXL | cc13x2_26x2 | cc2652r1f3 | Thread MTD + no BLE | # | LP_CC2652R7 | cc13x2x7_26x2x7 | cc2652r1f7 | Thread FTD + BLE | +# | CC3220SF_LAUNCHXL | cc32xx | cc3220SF | Wi-Fi | +# | CC3235SF_LAUNCHXL | cc32xx | cc3235SF | Wi-Fi | # XXX: Can we do an array with a case statement? if (ti_simplelink_board == "CC1352R1_LAUNCHXL") { @@ -56,6 +58,18 @@ if (ti_simplelink_board == "CC1352R1_LAUNCHXL") { # set -DDeviceFamily_CC26X2? ti_simplelink_soc = "cc2652r1f7" ti_simplelink_bim_name = "cc2652r7lp" +} else if (ti_simplelink_board == "CC3220SF_LAUNCHXL") { + ti_simplelink_device_family = "cc32xx" + ti_simplelink_soc_family = "cc32xx" + + # set -DDeviceFamily_CC3220 + ti_simplelink_soc = "cc32xxSF" +} else if (ti_simplelink_board == "CC3235SF_LAUNCHXL") { + ti_simplelink_device_family = "cc32xx" + ti_simplelink_soc_family = "cc32xx" + + # set -DDeviceFamily_CC3220 + ti_simplelink_soc = "cc32xxSF" } else { print("Please provide a valid value for TI_SIMPLELINK_BOARD env variable") assert(false, "The board ${ti_simplelink_board} is unsupported as for now.") diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni index 53e3b437876b17..650f336c443d22 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni @@ -46,8 +46,14 @@ template("ti_simplelink_executable") { } output_base_name = get_path_info(invoker.output_name, "name") - objcopy_image_name = output_base_name + ".hex" - objcopy_image_format = "ihex" + #used for OTA image creator for the cc13xx + if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + objcopy_image_name = output_base_name + ".hex" + objcopy_image_format = "ihex" + } else { + objcopy_image_name = output_base_name + ".bin" + objcopy_image_format = "binary" + } objcopy = "arm-none-eabi-objcopy" config("${simplelink_target_name}_config") { @@ -79,17 +85,19 @@ template("ti_simplelink_executable") { } else { ldscript = "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/cc13x2x7_cc26x2x7.lds" } + } else if (ti_simplelink_device_family == "cc32xx") { + ldscript = "${ti_simplelink_sdk_root}/source/ti/boards/cc32xxsf/cc32xxsf_freertos.lds" + } - inputs = [ ldscript ] + inputs = [ ldscript ] - ldflags = [ - "-L" + rebase_path(ti_simplelink_sdk_root + "/source", root_build_dir), - rebase_path( - "${target_gen_dir}/sysconfig/ti_utils_build_linker.cmd.genlibs", - root_build_dir), - "-T" + rebase_path(ldscript, root_build_dir), - ] - } + ldflags = [ + "-L" + rebase_path(ti_simplelink_sdk_root + "/source", root_build_dir), + rebase_path( + "${target_gen_dir}/sysconfig/ti_utils_build_linker.cmd.genlibs", + root_build_dir), + "-T" + rebase_path(ldscript, root_build_dir), + ] } if (chip_enable_ota_requestor && diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni index caf6d1ffeefdbd..3613a0bb6b6fe7 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni @@ -28,8 +28,16 @@ import("ti_simplelink_board.gni") declare_args() { # Location of the TI SimpleLink SDK. - ti_simplelink_sdk_root = - "${chip_root}/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx" + + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + ti_simplelink_sdk_root = + "${chip_root}/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx" + } else if (ti_simplelink_device_family == "cc32xx") { + ti_simplelink_sdk_root = + "${chip_root}/third_party/ti_simplelink_sdk/repo_cc32xx" + } + ti_sysconfig_root = "" } @@ -37,7 +45,7 @@ assert(ti_simplelink_sdk_root != "", "ti_simplelink_sdk_root must be specified") assert(ti_sysconfig_root != "", "ti_sysconfig_root must be specified") template("ti_sysconfig") { - assert(ti_sysconfig_root != "", "ti_sysconfig_root must be specified") + assert(ti_sysconfig_root != "", "must be specified") assert(ti_simplelink_sdk_root != "", "ti_simplelink_sdk_root must be specified") @@ -65,6 +73,9 @@ template("ti_sysconfig") { } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { ldflags += [ "-nostartfiles" ] defines += [ "DeviceFamily_CC26X2X7" ] + } else if (ti_simplelink_device_family == "cc32xx") { + ldflags += [ "-nostartfiles" ] + defines += [ "CC32XXWARE" ] } if (defined(invoker.cflags)) { cflags = invoker.cflags @@ -130,11 +141,8 @@ template("ti_simplelink_sdk") { # Treat these includes as system includes, so warnings in them are not fatal. include_dirs += [ - "${ti_simplelink_sdk_root}/kernel/freertos/builds/${ti_simplelink_device_family}/release", - "${ti_simplelink_sdk_root}/source", "${ti_simplelink_sdk_root}/source/third_party/CMSIS/Include", - "${chip_root}/third_party/mbedtls/repo/include", ] defines = [] @@ -150,6 +158,25 @@ template("ti_simplelink_sdk") { "${ti_simplelink_sdk_root}/source/ti/drivers/lib/gcc/${ti_simplelink_isa}/drivers_${ti_simplelink_soc_family}.a", "${ti_simplelink_sdk_root}/source/ti/drivers/rf/lib/gcc/${ti_simplelink_isa}/rf_multiMode_${ti_simplelink_soc_family}.a", ] + } else if (ti_simplelink_device_family == "cc32xx") { + assert(ti_simplelink_soc_family != "", + "ti_simplelink_soc_family must be specified") + assert(ti_simplelink_device_family != "", + "ti_simplelink_device_family must be specified") + + defines += [ "DeviceFamily_CC3220" ] + + libs += [ + "${ti_simplelink_sdk_root}/source/ti/drivers/lib/gcc/m4/drivers_cc32xx.a", + "${ti_simplelink_sdk_root}/source/ti/devices/cc32xx/driverlib/gcc/Release/driverlib.a", + "${ti_simplelink_sdk_root}/source/ti/drivers/net/wifi/gcc/rtos/simplelink.a", + "${ti_simplelink_sdk_root}/source/ti/net/lib/gcc/m4/slnetsock_debug.a", + "${ti_simplelink_sdk_root}/source/ti/drivers/net/wifi/slnetif/gcc/Release/slnetifwifi.a", + ] + include_dirs += [ + "${ti_simplelink_sdk_root}/examples/rtos/common/", + "${ti_simplelink_sdk_root}/examples/rtos/common/ifmod", + ] } if (ti_simplelink_device_family == "cc13x2_26x2") { @@ -160,6 +187,15 @@ template("ti_simplelink_sdk") { libs += [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/driverlib/bin/gcc/driverlib.lib" ] } + if (ti_simplelink_device_family == "cc32xx") { + assert(ti_simplelink_soc_family != "", + "ti_simplelink_soc_family must be specified") + assert(ti_simplelink_device_family != "", + "ti_simplelink_device_family must be specified") + + libs += [ "${ti_simplelink_sdk_root}/source/ti/drivers/lib/gcc/m4/drivers_${ti_simplelink_soc_family}.a" ] + } + if (defined(invoker.defines)) { defines += invoker.defines } @@ -173,19 +209,31 @@ template("ti_simplelink_sdk") { sources = [ "${ti_simplelink_sdk_root}/kernel/freertos/dpl/AppHooks_freertos.c", - "${ti_simplelink_sdk_root}/kernel/freertos/dpl/ClockPCC26X2_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/DebugP_freertos.c", - "${ti_simplelink_sdk_root}/kernel/freertos/dpl/HwiPCC26X2_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/MutexP_freertos.c", - "${ti_simplelink_sdk_root}/kernel/freertos/dpl/PowerCC26X2_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/QueueP_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/SemaphoreP_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/StaticAllocs_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/SwiP_freertos.c", "${ti_simplelink_sdk_root}/kernel/freertos/dpl/SystemP_freertos.c", - "${ti_simplelink_sdk_root}/kernel/freertos/dpl/TimerPCC26XX_freertos.c", - "${ti_simplelink_sdk_root}/kernel/freertos/startup/startup_cc13x2_cc26x2_gcc.c", ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + sources += [ + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/ClockPCC26X2_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/HwiPCC26X2_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/PowerCC26X2_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/TimerPCC26XX_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/startup/startup_cc13x2_cc26x2_gcc.c", + ] + } else if (ti_simplelink_device_family == "cc32xx") { + sources += [ + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/ClockP_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/HwiPCC32XX_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/dpl/PowerCC32XX_freertos.c", + "${ti_simplelink_sdk_root}/kernel/freertos/startup/startup_cc32xx_gcc.c", + ] + } if (defined(invoker.sources)) { sources += invoker.sources @@ -233,72 +281,78 @@ template("ti_simplelink_sdk") { public_configs = [ ":${sdk_target_name}_config" ] } - if (chip_openthread_ftd) { - openthread_example = "cli_ftd" - } else { - openthread_example = "cli_mtd" - } + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + if (chip_openthread_ftd) { + openthread_example = "cli_ftd" + } else { + openthread_example = "cli_mtd" + } - config("${sdk_target_name}_openthread_platform_config") { - defines = [ "NVOCMP_POSIX_MUTEX" ] - include_dirs = [ - "${chip_root}/third_party/openthread/repo/examples/platforms", - "${chip_root}/third_party/openthread/repo/src/core", - "${ti_simplelink_sdk_root}/source/ti/devices/${ti_simplelink_device_family}", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}", - ] + config("${sdk_target_name}_openthread_platform_config") { + defines = [ "NVOCMP_POSIX_MUTEX" ] + include_dirs = [ + "${chip_root}/third_party/openthread/repo/examples/platforms", + "${chip_root}/third_party/openthread/repo/src/core", + "${ti_simplelink_sdk_root}/source/ti/devices/${ti_simplelink_device_family}", + ] - if (ti_simplelink_device_family == "cc13x2_26x2") { - include_dirs += - [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2_cc26x2" ] - } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { - include_dirs += - [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7" ] + if (ti_simplelink_device_family == "cc13x2_26x2") { + include_dirs += [ + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2_cc26x2", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}", + ] + } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + include_dirs += [ + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}", + ] + } } - } - source_set("${sdk_target_name}_openthread_platform") { - cflags = [ - "-Wno-int-conversion", - "-Wno-address-of-packed-member", - "-Wno-implicit-fallthrough", - "-Wno-unused-label", - ] - public_deps = [ - ":${sdk_target_name}_freertos", - "${chip_root}/third_party/ti_simplelink_sdk:freertos", - "${chip_root}/third_party/ti_simplelink_sdk:mbedtls", - "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", - "${openthread_root}/src/core:libopenthread_core_headers", - ] + source_set("${sdk_target_name}_openthread_platform") { + cflags = [ + "-Wno-int-conversion", + "-Wno-address-of-packed-member", + "-Wno-implicit-fallthrough", + "-Wno-unused-label", + ] + public_deps = [ + ":${sdk_target_name}_freertos", + "${chip_root}/third_party/ti_simplelink_sdk:freertos", + "${chip_root}/third_party/ti_simplelink_sdk:mbedtls", + "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", + "${openthread_root}/src/core:libopenthread_core_headers", + ] - configs -= [ "${build_root}/config/compiler:std_default" ] - configs += [ ":${sdk_target_name}_posix_config" ] - sources = [ - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/alarm.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/alarm_micro.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/diag.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/entropy.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/misc.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/nv/crc.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/nv/nvocmp.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/radio.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/settings.c", - "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/system.c", - ] + configs -= [ "${build_root}/config/compiler:std_default" ] + configs += [ ":${sdk_target_name}_posix_config" ] + sources = [ + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/alarm.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/alarm_micro.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/diag.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/entropy.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/misc.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/nv/crc.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/nv/nvocmp.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/radio.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/settings.c", + "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/thread/${openthread_example}/platform/system.c", + ] - public_configs = [ - ":${sdk_target_name}_config", - ":${sdk_target_name}_openthread_platform_config", - "${chip_root}/third_party/openthread/repo:openthread_config", - ] + public_configs = [ + ":${sdk_target_name}_config", + ":${sdk_target_name}_openthread_platform_config", + "${chip_root}/third_party/openthread/repo:openthread_config", + ] - if (chip_openthread_ftd) { - public_configs += - [ "${chip_root}/third_party/openthread/repo:openthread_ftd_config" ] - } else { - public_configs += - [ "${chip_root}/third_party/openthread/repo:openthread_mtd_config" ] + if (chip_openthread_ftd) { + public_configs += + [ "${chip_root}/third_party/openthread/repo:openthread_ftd_config" ] + } else { + public_configs += + [ "${chip_root}/third_party/openthread/repo:openthread_mtd_config" ] + } } }