diff --git a/examples/persistent-storage/KeyValueStorageTest.cpp b/examples/persistent-storage/KeyValueStorageTest.cpp index edb6b1582e2f5f..9be95a2100bb31 100644 --- a/examples/persistent-storage/KeyValueStorageTest.cpp +++ b/examples/persistent-storage/KeyValueStorageTest.cpp @@ -36,7 +36,7 @@ using namespace chip::DeviceLayer::PersistedStorage; { \ char error_str[255]; \ chip::FormatCHIPError(error_str, sizeof(error_str), temp_test_result); \ - ChipLogError(NotSpecified, "%s: FAILED %d [%s]", #test_result, temp_test_result, chip::ErrorStr(temp_test_result)); \ + ChipLogError(NotSpecified, "%s: FAILED %ld [%s]", #test_result, temp_test_result, chip::ErrorStr(temp_test_result)); \ } \ else \ { \ diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/.gn b/examples/persistent-storage/cc13x2x7_26x2x7/.gn new file mode 100644 index 00000000000000..3d48789e30ab3d --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/.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/persistent-storage/cc13x2x7_26x2x7/BUILD.gn b/examples/persistent-storage/cc13x2x7_26x2x7/BUILD.gn new file mode 100644 index 00000000000000..26088b371f4386 --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/BUILD.gn @@ -0,0 +1,103 @@ +# 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/openthread.gni") +import("//build_overrides/ti_simplelink_sdk.gni") + +import("${build_root}/config/defaults.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/persistent-storage/cc13x2x7_26x2x7" + +ti_simplelink_sdk("sdk") { + include_dirs = [ "${project_dir}/include" ] + + defines = [] + if (is_debug) { + defines += [ "BUILD_RELEASE=0" ] + } else { + defines += [ "BUILD_RELEASE=1" ] + } +} + +ti_sysconfig("sysconfig") { + sources = [ "${project_dir}/chip.syscfg" ] + + outputs = [ + "ti_devices_config.c", + "ti_drivers_config.c", + "ti_drivers_config.h", + ] + + public_configs = [ ":sdk_dmm_config" ] + + cflags = [ + "-Wno-comment", + "@" + rebase_path("${target_gen_dir}/sysconfig/ti_ble_app_config.opt", + root_build_dir), + "@" + rebase_path("${target_gen_dir}/sysconfig/ti_build_config.opt", + root_build_dir), + ] +} + +ti_simplelink_executable("persistent_storage") { + output_name = "chip-${ti_simplelink_board}-persistent_storage.out" + + sources = [ + "${project_dir}/../KeyValueStorageTest.cpp", + "${project_dir}/main.cpp", + ] + + deps = [ + ":sdk", + ":sysconfig", + "${chip_root}/src/lib", + ] + + include_dirs = [ + "${project_dir}", + "${project_dir}/..", + ] + + cflags = [ + "-Wno-implicit-fallthrough", + "-Wno-sign-compare", + "-Wconversion", + ] + + ldscript = "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/cc13x2x7_cc26x2x7.lds" + + inputs = [ ldscript ] + + ldflags = [ + "-L${ti_simplelink_sdk_root}/source", + "-T" + rebase_path(ldscript, root_build_dir), + ] + + output_dir = root_out_dir +} + +group("cc13x2x7_26x2x7") { + deps = [ ":persistent_storage" ] +} + +group("default") { + deps = [ ":cc13x2x7_26x2x7" ] +} diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/README.md b/examples/persistent-storage/cc13x2x7_26x2x7/README.md new file mode 100644 index 00000000000000..dba97e2896a48c --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/README.md @@ -0,0 +1,255 @@ +# CHIP CC1352 CC2652 Persistent Storage Example Application + +An example test application showing the persistent storage system for +[CHIP][chip] on the Texas Instruments CC13X2_26X2 family of Wireless MCUs. + +--- + +- [CHIP CC1352 CC2652 Persistent Storage Application](#chip-cc1352-cc2652-persistent-storage-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) + - [TI Support](#ti-support) + +--- + +## Introduction + +This example serves to test the key value storage implementation and API and +offers information on proper usage of the KVS system. + +This example is enabled to build for CC2652R7 devices. This upcoming devices are +currently not yet in full production. For more information on device +availability or early access to an engineering build of our CHIP-enabled SDK, +please reach out [here][ti_cc13x2_26x2_r7_chip_request]. + +## Device UI + +Over the debug UART connection you should see the output: + +``` +Running Tests: +TestEmptyString(): PASSED +TestString(): PASSED +TestUint32(): PASSED +TestArray(): PASSED +TestStruct(): PASSED +TestUpdateValue(): PASSED +TestMultiRead(): PASSED +``` + +This indicates a successful run of the test suite. + +## 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. + +- An engineering SDK from TI is required. Please request access for it + [here][ti_cc13x2_26x2_r7_chip_request]. + + - Follow the default installation instructions when executing the + installer. + + - The version of OpenThread used in this repository is newer than the one + packaged with the TI SDK. Check the following section for a list of + changes needed. + +- Download and install [SysConfig][sysconfig] ([recommended + version][sysconfig_recommended]) + + - This may have already been installed with your SimpleLink SDK install. + +- If you have installed different versions, the build defaults will need to be + changed to reflect this in + `${chip_root}/examples/build_overrides/ti_simplelink_sdk.gni`. + +- Install Python 3.8 for the GN build system: + + ``` + # Linux + $ sudo apt-get install python3.8 python3.8-distutils python3.8-dev python3.8-venv + # Distutils listed due to a package manager error on Ubuntu 18.04 + + ``` + + - You will have to ensure that the default version of Python 3 is Python + 3.8. + + - Check python3 version: + + ``` + $ python3 --version + Python 3.8.0 + ``` + + - If it is not Python 3.8: + + ``` + $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 + ``` + + - This may affect your environment in other ways if there was a + specific dependency on the prior python3 version (e.g. apt). + After completing the build process for this example, you can + revert the python3 version, for instance: + + ``` + $ sudo update-alternatives --config python3 + There are 2 choices for the alternative python3 (providing /usr/bin/python3). + + Selection Path Priority Status + ------------------------------------------------------------- + 0 /usr/bin/python3.8 1 auto mode + 1 /usr/bin/python3.6 1 manual mode + * 2 /usr/bin/python3.8 1 manual mode + + Press to keep the current choice[*], or type selection number: 1 + update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in manual mode + ``` + +- 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 both the + TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's + home directory, and you must provide the absolute path to them. For example + `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and + `/home/username/ti/sysconfig_1.7.0`. 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/cc13x2x7_26x2x7 + $ export TI_SIMPLELINK_SDK_ROOT=$HOME/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng + $ export TI_SYSCONFIG_ROOT=$HOME/ti/sysconfig_1.7.0 + $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" + $ ninja -C out/debug + + ``` + +## Programming + +Loading the built image onto a LaunchPad is supported through two methods; +Uniflash and Code Composer Studio (CCS). UniFlash can be used to load the image. +Code Composer Studio can be used to load the image and debug the source code. + +### 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. + +### UniFlash + +Uniflash is Texas Instrument's uniform programming tool for embedded processors. +This will allow you to erase, flash, and inspect the SoC without setting up a +debugging environment. + +Download and install [UniFlash][uniflash]. + +First open UniFlash. Debug probes connected to the computer will usually be +displayed under the Detected Devices due to the automatic device detection +feature. If your device does not show up in this view it my be disconnected, or +you may have to create a New Configuration. If you already have a CCXML for your +SoC and debug connection you can use that in the section at the bottom. Once +your device is selected, click the `Start` button within the section to launch +the session. + +Select the ELF image to load on the device with the `Browse` button. This file +is placed in the `out/debug` folder by this guide and ends with the `*.out` file +extension. + +Finally click the `Load Image` button to load the executable image onto the +device. You should be able to see the log output over the XDS110 User UART. + +Note that programming the device through JTAG sets the Halt-in-Boot flag and may +cause issues when performing a software reset. This flag can be reset by +power-cycling 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` | + +## TI Support + +For technical support, please consider creating a post on TI's [E2E forum][e2e]. +Additionally, we welcome any feedback. + +[chip]: 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 +[e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread +[sysconfig]: https://www.ti.com/tool/SYSCONFIG +[sysconfig_recommended]: + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.7.0_1746-setup.run +[ti_cc13x2_26x2_r7_chip_request]: https://ti.com/chip_sdk +[uniflash]: https://www.ti.com/tool/download/UNIFLASH diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/args.gni b/examples/persistent-storage/cc13x2x7_26x2x7/args.gni new file mode 100644 index 00000000000000..96bab211852345 --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/args.gni @@ -0,0 +1,29 @@ +# 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/cc13x2_26x2/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 = "LP_CC2652R7" + +# use -Os instead of -Og +#is_debug = false + +# BLE options +chip_config_network_layer_ble = true +chip_bypass_rendezvous = false diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/build_overrides b/examples/persistent-storage/cc13x2x7_26x2x7/build_overrides new file mode 120000 index 00000000000000..e578e73312ebd1 --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/build_overrides @@ -0,0 +1 @@ +../../build_overrides \ No newline at end of file diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg new file mode 100644 index 00000000000000..c93e60f4846aaa --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg @@ -0,0 +1,214 @@ +/* + * + * 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. + */ + +/* Modules */ +var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); +var AESECB = scripting.addModule("/ti/drivers/AESECB"); +var Button = scripting.addModule("/ti/drivers/apps/Button"); +var ECJPAKE = scripting.addModule("/ti/drivers/ECJPAKE"); +var LED = scripting.addModule("/ti/drivers/apps/LED"); +var NVS = scripting.addModule("/ti/drivers/NVS"); +var RF = scripting.addModule("/ti/drivers/RF"); +var RFDesign = scripting.addModule("ti/devices/radioconfig/rfdesign"); +var RTOS = scripting.addModule("/ti/drivers/RTOS"); +var TRNG = scripting.addModule("/ti/drivers/TRNG"); +var Thread = scripting.addModule("/ti/thread/thread"); +var SHA2 = scripting.addModule("/ti/drivers/SHA2"); +var UART = scripting.addModule("/ti/drivers/UART"); +var ble = scripting.addModule("/ti/ble5stack/ble"); +var dmm = scripting.addModule("/ti/dmm/dmm"); +var AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); +var ECDH = scripting.addModule("/ti/drivers/ECDH"); + +/* Instances */ +var AESCCM1 = AESCCM.addInstance(); +var AESCCM2 = AESCCM.addInstance(); +var AESECB1 = AESECB.addInstance(); +var AESECB2 = AESECB.addInstance(); +var Button1 = Button.addInstance(); +var Button2 = Button.addInstance(); +var ECJPAKE = ECJPAKE.addInstance(); +var NVS1 = NVS.addInstance(); +var SHA21 = SHA2.addInstance(); +var LED1 = LED.addInstance(); +var LED2 = LED.addInstance(); +var TRNG1 = TRNG.addInstance(); +var TRNG2 = TRNG.addInstance(); +var TRNG3 = TRNG.addInstance(); +var UART1 = UART.addInstance(); +var UART2 = UART.addInstance(); +var AESCTRDRBG1 = AESCTRDRBG.addInstance(); +var ECDH1 = ECDH.addInstance(); +var ECDH2 = ECDH.addInstance(); + +AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; +AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; + +AESCCM1.$name = "CONFIG_AESCCM0"; +AESCCM2.$name = "CONFIG_AESCCM_1"; + +AESECB1.$name = "CONFIG_AESECB0"; +AESECB2.$name = "CONFIG_AESECB_1"; + +ECDH1.$name = "CONFIG_ECDH0"; +ECDH2.$name = "CONFIG_ECDH_1"; + +/* RTOS */ +RTOS.name = "FreeRTOS"; + +/* Left Button */ +Button1.$name = "CONFIG_BTN_LEFT"; +Button1.$hardware = system.deviceData.board.components["BTN-1"]; +Button1.gpioPin.$name = "CONFIG_GPIO_BTN1"; +Button1.gpioPin.pull = "Pull Up"; +Button1.gpioPin.interruptTrigger = "Falling Edge"; +Button1.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN1"; + +/* Left Button */ +Button2.$name = "CONFIG_BTN_RIGHT"; +Button2.$hardware = system.deviceData.board.components["BTN-2"]; +Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; +Button2.gpioPin.pull = "Pull Up"; +Button2.gpioPin.interruptTrigger = "Falling Edge"; +Button2.gpioPin.pinInstance.$name = "CONFIG_PIN_BTN2"; + +/* ======== CCFG ======== */ +var CCFG = scripting.addModule("/ti/devices/CCFG"); +const deviceName = system.getScript("/ti/ti154stack/ti154stack_common.js").getLaunchPadFromDevice(); +const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings; +for(var setting in ccfgSettings) +{ + CCFG[setting] = ccfgSettings[setting]; +} + +// Update LF Clock Source for CC2652RB devices +if(deviceName.includes("RB")) +{ + CCFG.srcClkLF = "Derived from HF XOSC"; +} +/* NVS */ +NVS1.$name = "CONFIG_NVSINTERNAL"; +NVS1.internalFlash.regionBase = 0x78000; +NVS1.internalFlash.regionSize = 0x4000; + +/* RF */ +RF.$name = "CONFIG_RF0"; +/* if an antenna component exists, assign it to the rf instance */ +if (system.deviceData.board && system.deviceData.board.components.RF) { + RF.$hardware = system.deviceData.board.components.RF; +} + +const rfDesignSettings = system.getScript("/ti/common/lprf_rf_design_settings.js").rfDesignSettings; +for(var setting in rfDesignSettings) +{ + RFDesign[setting] = rfDesignSettings[setting]; +} + +/* Red LED */ +LED1.$name = "CONFIG_LED_RED"; +LED1.$hardware = system.deviceData.board.components.LED_RED; +LED1.gpioPin.$name = "CONFIG_GPIO_RLED"; +LED1.gpioPin.mode = "Output"; +LED1.gpioPin.callbackFunction = ""; +LED1.gpioPin.pinInstance.$name = "CONFIG_PIN_RLED"; + +/* Green LED */ +LED2.$name = "CONFIG_LED_GREEN"; +LED2.$hardware = system.deviceData.board.components.LED_GREEN; +LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; +LED2.gpioPin.mode = "Output"; +LED2.gpioPin.callbackFunction = ""; +LED2.gpioPin.pinInstance.$name = "CONFIG_PIN_GLED"; + +/* Debug UART */ +UART1.$hardware = system.deviceData.board.components.XDS110UART; +UART1.$name = "CONFIG_UART_DEBUG"; + +/* Display UART */ +UART2.$name = "CONFIG_DISPLAY_UART"; +UART2.uart.txPin.$suggestSolution = "boosterpack.32"; +UART2.uart.rxPin.$suggestSolution = "boosterpack.18"; + +/* TRNG */ +TRNG1.$name = "CONFIG_TRNG_0"; +TRNG2.$name = "CONFIG_TRNG_1"; +TRNG3.$name = "CONFIG_TRNG_APP"; + +/* Thread */ +Thread.deviceType = "ftd"; +Thread.deviceTypeReadOnly = true; +/* Thread SysConfig generated sources are not used until the upstream modules + * can be updated to enable CHIP. + */ +RTOS.name = "FreeRTOS"; + +/* BLE */ +ble.addressMode = "ADDRMODE_RP_WITH_PUBLIC_ID"; +ble.maxConnNum = 1; +ble.numOfAdvSets = 1; +ble.lockProject = true; +ble.oneLibSizeOpt = true; +ble.maxPDUSize = 255; +ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param1"; +ble.connUpdateParamsPeripheral.$name = "ti_ble5stack_general_ble_conn_update_params0"; +ble.connUpdateParamsPeripheral.reqMinConnInt = 30; +ble.connUpdateParamsPeripheral.reqMaxConnInt = 50; + +ble.advSet1.$name = "ti_ble5stack_broadcaster_advertisement_set0"; +ble.advSet1.advParam1.$name = "ti_ble5stack_broadcaster_advertisement_params0"; +ble.advSet1.advParam1.primIntMin = 100; +ble.advSet1.advParam1.primIntMax = 200; + +/* DMM */ +dmm.project = "ti_thread_thermostat_remote_display"; +dmm.stackRoles = ["blePeripheral","threadFTD"]; +dmm.lockStackRoles = true; +dmm.numApplicationStates = 10; +dmm.applicationState0 = "ANY"; +dmm.applicationState1 = "DMMPOLICY_BLE_IDLE"; +dmm.applicationState2 = "DMMPOLICY_BLE_ADV"; +dmm.applicationState3 = "DMMPOLICY_BLE_CONNECTING"; +dmm.applicationState4 = "DMMPOLICY_BLE_HIGH_BANDWIDTH"; +dmm.applicationState5 = "DMMPOLICY_BLE_CONNECTED"; +dmm.applicationState6 = "DMMPOLICY_BLE_OAD"; +dmm.applicationState7 = "DMMPOLICY_THREAD_IDLE"; +dmm.applicationState8 = "DMMPOLICY_THREAD_LINK_EST"; +dmm.applicationState9 = "DMMPOLICY_THREAD_DATA"; +dmm.policyArray.create(4); +dmm.policyArray[0].$name = "ti_dmm_policy_dmm_policy0"; +dmm.policyArray[0].blePeripheral.$name = "ti_dmm_policy_stack_dmm_stack_ble0"; +dmm.policyArray[0].blePeripheral.applicationStates = ["applicationState6"]; +dmm.policyArray[0].threadFTD.$name = "ti_dmm_policy_stack_dmm_stack_thread0"; +dmm.policyArray[0].threadFTD.pause = "DMMPOLICY_PAUSED"; +dmm.policyArray[1].$name = "ti_dmm_policy_dmm_policy1"; +dmm.policyArray[1].blePeripheral.$name = "ti_dmm_policy_stack_dmm_stack_ble1"; +dmm.policyArray[1].blePeripheral.applicationStates = ["applicationState3","applicationState4"]; +dmm.policyArray[1].blePeripheral.weight = 25; +dmm.policyArray[1].blePeripheral.appliedActivity = ["DMMPOLICY_APPLIED_ACTIVITY_BLE_CONNECTION"]; +dmm.policyArray[1].threadFTD.$name = "ti_dmm_policy_stack_dmm_stack_thread1"; +dmm.policyArray[2].$name = "ti_dmm_policy_dmm_policy2"; +dmm.policyArray[2].blePeripheral.$name = "ti_dmm_policy_stack_dmm_stack_ble2"; +dmm.policyArray[2].threadFTD.$name = "ti_dmm_policy_stack_dmm_stack_thread2"; +dmm.policyArray[2].threadFTD.weight = 30; +dmm.policyArray[2].threadFTD.applicationStates = ["applicationState8"]; +dmm.policyArray[2].threadFTD.appliedActivity = ["DMMPOLICY_APPLIED_ACTIVITY_ALL"]; +dmm.policyArray[3].$name = "ti_dmm_policy_dmm_policy3"; +dmm.policyArray[3].blePeripheral.$name = "ti_dmm_policy_stack_dmm_stack_ble3"; +dmm.policyArray[3].threadFTD.$name = "ti_dmm_policy_stack_dmm_stack_thread3"; +dmm.policyArray[3].threadFTD.weight = 1; diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h b/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h new file mode 100644 index 00000000000000..3cead418532caa --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/include/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 cc13x2_26x2LogInit(void); +void cc13x2_26x2Log(const char * aFormat, ...); +#define PLAT_LOG(...) cc13x2_26x2Log(__VA_ARGS__); + +#ifdef __cplusplus +} +#endif +#endif // APP_CONFIG_H diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..c0330d33d649df --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -0,0 +1,164 @@ +/* + * 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 1 +#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_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_TEST_SERIAL_NUMBER "TEST_SN" + +#endif // BUILD_RELEASE + +/** + * CHIP_DEVICE_CONFIG_THREAD_FTD + * + * Disable Full Thread Device features + */ +#define CHIP_DEVICE_CONFIG_THREAD_FTD 1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * + * 0x235A: Chip's Vendor Id. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x235A + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * + * 0x434B: cc13x2x7_26x2x7 lock-app + */ +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x434B + +/** + * 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_STRING + * + * 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_STRING +#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "1.0d1" +#endif +/** + * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + * + * Enable support for CHIP-over-BLE (CHIPOBLE). + */ +#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 + +/** + * 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_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT + * + * Enable the OpenThread SRP client to allow for CHIP device discovery. + */ +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 + +/** + * 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/persistent-storage/cc13x2x7_26x2x7/include/OpenThreadConfig.h b/examples/persistent-storage/cc13x2x7_26x2x7/include/OpenThreadConfig.h new file mode 100644 index 00000000000000..4079b251280ddc --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/include/OpenThreadConfig.h @@ -0,0 +1,60 @@ +/* + * + * 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 + * Overrides to default OpenThread configuration. + * + */ + +#ifndef OPENTHREAD_PLATFORM_CONFIG_H +#define OPENTHREAD_PLATFORM_CONFIG_H + +// Disable the Nordic-supplied OpenThread logging facilities and use +// the facilities provided by the CHIP Device Layer +#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_APP + +// When operating in a less than ideal RF environment, having a more forgiving configuration +// of OpenThread makes thread a great deal more reliable. +#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY 120 // default is 28800 +#define OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_DIRECT 15 // default is 3 +#define OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_INDIRECT 1 // default is 0 +#define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 16 // default is 4 + +// Enable periodic parent search to speed up finding a better parent. +#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 1 // default is 0 +#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -45 // default is -65 +#define OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH 1 // default is 0 + +// Use smaller maximum interval to speed up reattaching. +#define OPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_MAXIMUM_INTERVAL (60 * 10 * 1000) // default 1200000 ms + +#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 +#define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 0 +#define UART_AS_SERIAL_TRANSPORT 1 +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 + +#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1 + +// Use the TI-supplied default platform configuration for remainder +#include "openthread-core-cc13x2_26x2-config.h" + +#endif // OPENTHREAD_PLATFORM_CONFIG_H diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/main.cpp b/examples/persistent-storage/cc13x2x7_26x2x7/main.cpp new file mode 100644 index 00000000000000..9a39bfa9f04e9c --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/main.cpp @@ -0,0 +1,88 @@ +/* + * + * 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 "KeyValueStorageTest.h" +#include + +#include +#include + +/* Driver Header files */ +#include +#include +#include + +#include +#define TOTAL_ICALL_HEAP_SIZE (0xf000) + +__attribute__((section(".heap"))) uint8_t GlobalHeapZoneBuffer[TOTAL_ICALL_HEAP_SIZE]; +uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE; + +// ================================================================================ +// FreeRTOS Callbacks +// ================================================================================ +extern "C" void vApplicationStackOverflowHook(void) +{ + while (1) + { + ; + } +} + +// ================================================================================ +// Main Code +// ================================================================================ + +static TaskHandle_t sTestTaskHandle; +void TestTask(void * pvParameter) +{ + cc13x2_26x2LogInit(); + + chip::DeviceLayer::Internal::CC13X2_26X2Config().Init(); + + while (1) + { + PLAT_LOG("Running Tests:"); + chip::RunKvsTest(); + vTaskDelay(60 * configTICK_RATE_HZ); // Run every minute + } +} + +int main(void) +{ + Board_init(); + bpool((void *) GlobalHeapZoneBuffer, TOTAL_ICALL_HEAP_SIZE); + + NVS_init(); + + UART_init(); + + // Run tests + xTaskCreate(TestTask, "Test", 2048, NULL, 1, &sTestTaskHandle); + + vTaskStartScheduler(); + + // Should never get here. + while (1) + ; +} diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/third_party/connectedhomeip b/examples/persistent-storage/cc13x2x7_26x2x7/third_party/connectedhomeip new file mode 120000 index 00000000000000..c866b86874994d --- /dev/null +++ b/examples/persistent-storage/cc13x2x7_26x2x7/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../.. \ No newline at end of file diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp index 644a89b0251612..e0f7eb4e39ac5e 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp @@ -40,37 +40,70 @@ namespace Internal { // *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices. +/* itemID and subID are limited to 10 bits, even though their types are uint16_t */ + // Keys stored in the Chip-factory namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = { { kCC13X2_26X2ChipConfig_Sysid, 0x0001 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { { kCC13X2_26X2ChipConfig_Sysid, 0x0002 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { { kCC13X2_26X2ChipConfig_Sysid, 0x0003 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { { kCC13X2_26X2ChipConfig_Sysid, 0x0004 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { { kCC13X2_26X2ChipConfig_Sysid, 0x0005 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ProductRevision = { { kCC13X2_26X2ChipConfig_Sysid, 0x0006 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { { kCC13X2_26X2ChipConfig_Sysid, 0x0007 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { { kCC13X2_26X2ChipConfig_Sysid, 0x0008 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { { kCC13X2_26X2ChipConfig_Sysid, 0x0009 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SerialNum = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0001 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0002 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0003 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0004 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0005 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ProductRevision = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0006 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0007 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0008 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { { .systemID = kCC13X2_26X2ChipConfig_Sysid, + .itemID = 0x0009 } }; // Keys stored in the Chip-config namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FabricId = { { kCC13X2_26X2ChipFactory_Sysid, 0x0011 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { { kCC13X2_26X2ChipFactory_Sysid, 0x0012 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { { kCC13X2_26X2ChipFactory_Sysid, 0x0013 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { { kCC13X2_26X2ChipFactory_Sysid, 0x0014 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FabricSecret = { { kCC13X2_26X2ChipFactory_Sysid, 0x0015 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_GroupKeyIndex = { { kCC13X2_26X2ChipFactory_Sysid, 0x0016 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { { kCC13X2_26X2ChipFactory_Sysid, 0x0017 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { { kCC13X2_26X2ChipFactory_Sysid, 0x0018 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { { kCC13X2_26X2ChipFactory_Sysid, 0x0019 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceId = { { kCC13X2_26X2ChipFactory_Sysid, 0x001a } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceCert = { { kCC13X2_26X2ChipFactory_Sysid, 0x001b } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceICACerts = { { kCC13X2_26X2ChipFactory_Sysid, - 0x001c } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDevicePrivateKey = { { kCC13X2_26X2ChipFactory_Sysid, - 0x001d } }; - -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { { kCC13X2_26X2ChipFactory_Sysid, 0x001e } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { { kCC13X2_26X2ChipFactory_Sysid, 0x001f } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Breadcrumb = { { kCC13X2_26X2ChipFactory_Sysid, 0x0020 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FabricId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0011 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0012 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0013 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0014 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FabricSecret = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0015 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_GroupKeyIndex = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0016 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0017 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0018 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0019 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceId = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x001a } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceCert = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x001b } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDeviceICACerts = { + { .systemID = kCC13X2_26X2ChipFactory_Sysid, .itemID = 0x001c } +}; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_OperationalDevicePrivateKey = { + { .systemID = kCC13X2_26X2ChipFactory_Sysid, .itemID = 0x001d } +}; + +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x001e } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x001f } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Breadcrumb = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0020 } }; + +/* Internal for the KVS interface. */ +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0021 } }; +const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2ChipFactory_Sysid, + .itemID = 0x0020 } }; /* Static local variables */ static NVINTF_nvFuncts_t sNvoctpFps = { 0 }; @@ -142,6 +175,73 @@ CHIP_ERROR CC13X2_26X2Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t return err; } +/* Iterate through the key range to find a key that matches. */ +static uint8_t FindKVSSubID(const char * key, uint16_t & subID) +{ + char key_scratch[32]; // 32 characters seems large enough for a key + NVINTF_nvProxy_t nvProxy = { 0 }; + uint8_t status = NVINTF_SUCCESS; + + nvProxy.sysid = CC13X2_26X2Config::kConfigKey_KVS_key.nvID.systemID; + nvProxy.itemid = CC13X2_26X2Config::kConfigKey_KVS_key.nvID.itemID; + nvProxy.buffer = key_scratch; + nvProxy.len = sizeof(key_scratch); + nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DOREAD; + + intptr_t lock_key = sNvoctpFps.lockNV(); + do + { + memset(key_scratch, 0, sizeof(key_scratch)); + status = sNvoctpFps.doNext(&nvProxy); + if (NVINTF_SUCCESS != status) + { + break; + } + if (0 == strcmp(key, (char *) nvProxy.buffer)) + { + subID = nvProxy.subid; + break; + } + } while (NVINTF_SUCCESS == status); + + sNvoctpFps.unlockNV(lock_key); + return status; +} + +CHIP_ERROR CC13X2_26X2Config::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; + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + uint16_t subID; + size_t len; + + VerifyOrExit(FindKVSSubID(key, subID) == NVINTF_SUCCESS, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + + val_item.subID = subID; + + len = sNvoctpFps.getItemLen(val_item); + VerifyOrExit(len > 0, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // key not found + + VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, (uint16_t) value_size, value) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + + if (read_bytes_size) + { + if (len - offset_bytes > value_size) + { + *read_bytes_size = value_size; + } + else + { + *read_bytes_size = len - offset_bytes; + } + } + +exit: + return err; +} + CHIP_ERROR CC13X2_26X2Config::WriteConfigValue(Key key, bool val) { uint8_t localVal = val ? 1 : 0; @@ -168,6 +268,60 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueStr(Key key, const char * str, siz return WriteConfigValueBin(key, (const uint8_t *) str, strLen); } +CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, size_t value_size) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint16_t subID; + + if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) + { + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + // key already exists, update value + val_item.subID = subID; + VerifyOrExit(sNvoctpFps.updateItem(val_item, (uint16_t) value_size, (void *) value) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + } + else + { + // key does not exist, likely case + intptr_t lock_key = sNvoctpFps.lockNV(); + + NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + + /* Iterate through the subID range to find an unused subID in the + * keyspace. SubID is a 10 bit value, reference + * `/source/ti/common/nv/nvocmp.c:MVOCMP_MAXSUBID`. + */ + for (uint16_t i = 0; i < 0x3FF; i++) + { + key_item.subID = i; + if (sNvoctpFps.getItemLen(key_item) == 0U) + { + val_item.subID = i; + break; + } + } + // write they key item + if (sNvoctpFps.writeItem(key_item, (uint16_t) strlen(key), (void *) key) == NVINTF_SUCCESS) + { + if (sNvoctpFps.writeItem(val_item, (uint16_t) value_size, (void *) value) != NVINTF_SUCCESS) + { + // try to delete the key item + sNvoctpFps.deleteItem(key_item); + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } + } + else + { + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } + sNvoctpFps.unlockNV(lock_key); + } +exit: + return err; +} + CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -178,6 +332,32 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, return err; } +CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint16_t subID; + NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + + if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) + { + key_item.subID = subID; + val_item.subID = subID; + // delete the value item + if (sNvoctpFps.deleteItem(val_item) != NVINTF_SUCCESS) + { + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } + // delete the key item + if (sNvoctpFps.deleteItem(key_item) != NVINTF_SUCCESS) + { + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; + } + } + + return err; +} + CHIP_ERROR CC13X2_26X2Config::ClearConfigValue(Key key) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h index 12ef94c62fe431..6a7058d46b50ac 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.h @@ -70,6 +70,8 @@ class CC13X2_26X2Config static const Key kConfigKey_RegulatoryLocation; static const Key kConfigKey_CountryCode; static const Key kConfigKey_Breadcrumb; + static const Key kConfigKey_KVS_key; // special key for KVS system, key storage + static const Key kConfigKey_KVS_value; // special key for KVS system, value storage static CHIP_ERROR Init(void); @@ -90,6 +92,11 @@ class CC13X2_26X2Config 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); }; struct CC13X2_26X2Config::Key diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp index 4d982b58126610..118945be4337d2 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp @@ -21,14 +21,46 @@ * Platform-specific key value storage implementation for CC1352 */ +/* 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 CC13X2_26X2Config::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 CC13X2_26X2Config::WriteKVS(key, value, value_size); +} + +CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) +{ + return CC13X2_26X2Config::ClearKVS(key); +} + } // namespace PersistedStorage } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h index 24f46ee57d1356..1b12844115fcf5 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h +++ b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h @@ -34,16 +34,11 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager friend class KeyValueStoreManager; public: - // NOTE: Currently this platform does not support partial and offset reads - // these will return CHIP_ERROR_NOT_IMPLEMENTED. - CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0) - { - return CHIP_ERROR_NOT_IMPLEMENTED; - } + 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) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _Delete(const char * key); - CHIP_ERROR _Put(const char * key, const void * value, size_t value_size) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _Put(const char * key, const void * value, size_t value_size); private: // ===== Members for internal use by the following friends.