diff --git a/.github/workflows/examples-cc13x2x7_26x2x7.yaml b/.github/workflows/examples-cc13x2x7_26x2x7.yaml index aaeaf094910373..f3703f38b85f69 100644 --- a/.github/workflows/examples-cc13x2x7_26x2x7.yaml +++ b/.github/workflows/examples-cc13x2x7_26x2x7.yaml @@ -53,7 +53,7 @@ jobs: attempt_limit: 3 attempt_delay: 2000 - name: Checkout submodules - run: scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform cc13x2_26x2 + run: scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform cc13xx_26xx - name: Set up environment for size reports if: ${{ !env.ACT }} env: @@ -79,75 +79,5 @@ jobs: path: | .environment/gn_out/.ninja_log .environment/pigweed-venv/*.log + - - name: Build examples - timeout-minutes: 100 - run: | - scripts/run_in_build_env.sh "\ - ./scripts/build/build_examples.py \ - --target cc13x2x7_26x2x7-all-clusters-mtd \ - --target cc13x2x7_26x2x7-all-clusters-minimal \ - --target cc13x2x7_26x2x7-lock-ftd \ - --target cc13x2x7_26x2x7-lock-mtd \ - --target cc13x2x7_26x2x7-pump \ - --target cc13x2x7_26x2x7-pump-controller \ - --target cc13x2x7_26x2x7-shell \ - build \ - --copy-artifacts-to out/artifacts \ - " - - name: Get lock FTD size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 lock-ftd \ - out/artifacts/cc13x2x7_26x2x7-lock-ftd/chip-LP_CC2652R7-lock-example.out \ - /tmp/bloat_reports/ - - name: Get lock MTD size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 lock-mtd \ - out/artifacts/cc13x2x7_26x2x7-lock-mtd/chip-LP_CC2652R7-lock-example.out \ - /tmp/bloat_reports/ - - name: Get Pump App size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 pump-app \ - out/artifacts/cc13x2x7_26x2x7-pump/chip-LP_CC2652R7-pump-example.out \ - /tmp/bloat_reports/ - - name: Get Pump Controller App size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 pump-controller-app \ - out/artifacts/cc13x2x7_26x2x7-pump-controller/chip-LP_CC2652R7-pump-controller-example.out \ - /tmp/bloat_reports/ - - name: Get All Clusters App size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 all-clusters-app \ - out/artifacts/cc13x2x7_26x2x7-all-clusters-mtd/chip-LP_CC2652R7-all-clusters-example.out \ - /tmp/bloat_reports/ - - name: Get All Clusters Minimal App size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 all-clusters-minimal-app \ - out/artifacts/cc13x2x7_26x2x7-all-clusters-minimal/chip-LP_CC2652R7-all-clusters-minimal-example.out \ - /tmp/bloat_reports/ - - name: Get Shell App size stats - timeout-minutes: 5 - run: | - .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - cc13x2_26x2 LP_CC2652R7 shell \ - out/artifacts/cc13x2x7_26x2x7-shell/chip-LP_CC2652R7-shell-example.out \ - /tmp/bloat_reports/ - - name: Uploading Size Reports - uses: actions/upload-artifact@v3 - if: ${{ !env.ACT }} - with: - name: Size,cc13x2x7_26x2x7-Examples,${{ env.GH_EVENT_PR }},${{ env.GH_EVENT_HASH }},${{ env.GH_EVENT_PARENT }},${{ github.event_name }} - path: | - /tmp/bloat_reports/ diff --git a/.gitmodules b/.gitmodules index d368b904833686..0f5d8dfa6e39e5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,7 +58,7 @@ path = third_party/freertos/repo url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git branch = V10.3.1-kernel-only - platforms = ameba,cc13x2_26x2,bouffalolab,efr32,esp32,k32w0,infineon,qpg,cc32xx,silabs_docker + platforms = ameba,cc13xx_26xx,bouffalolab,efr32,esp32,k32w0,infineon,qpg,cc32xx,silabs_docker [submodule "simw-top-mini"] path = third_party/simw-top-mini/repo url = https://github.com/NXP/plug-and-trust.git @@ -224,12 +224,17 @@ path = third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx url = https://github.com/TexasInstruments/cc13xx_cc26xx_sdk.git branch = main - platforms = cc13x2_26x2 + platforms = cc13xx_26xx [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 platforms = cc32xx +[submodule "third_party/openthread/ot-ti"] + path = third_party/openthread/ot-ti + url = https://github.com/TexasInstruments/ot-ti.git + branch = main + platforms = cc13xx_26xx [submodule "third_party/nxp/mw320_sdk/repo"] path = third_party/nxp/mw320_sdk/repo url = https://github.com/nxptest/mw320_sdk diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/README.md b/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/README.md deleted file mode 100644 index 6f67dfa903ff0f..00000000000000 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/README.md +++ /dev/null @@ -1,244 +0,0 @@ -# Matter CC1352 CC2652 All-clusters Example Application - -An example application showing the use of [Matter][matter] on the Texas -Instruments CC13XX_26XX family of Wireless MCUs. - ---- - -- [Matter CC1352 CC2652 All Clusters Example Application](#matter-cc1352-cc2652-all-clusters-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) - - [Bluetooth LE Advertising](#bluetooth-le-advertising) - - [Bluetooth LE Rendezvous](#bluetooth-le-rendezvous) - - [TI Support](#ti-support) - ---- - -## Introduction - -![CC1352R1_LAUNCHXL](../../pump-app/cc13x2x7_26x2x7/doc/images/cc1352r1_launchxl.jpg) - -The CC13XX_26XX all clusters example application provides the basis to query and -run commands for all currently implemented Matter clusters. This uses the -open-source Matter implementation and the Texas Instruments SimpleLinkā„¢ CC13XX -and CC26XX software development kit. - -This example is enabled to build for CC2652R7 devices. - -The all-clusters example is intended to serve both as a means to explore the -workings of Matter, 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 -various Matter clusters and the attribute changes associated with them. The user -LEDs on the LaunchPad are used for the onoff, levelcontrol and identify clusters -to provide a working demonstration of the cluster attribute changes. The Green -LED is used to represent attribute changes to endpoint 1 while the Red LED is -used to represent changes to endpoint 2. - -Short presses (less than 1000ms) of the user buttons are used currently unused -in the all-clusters application, but stubs are provided. - -Long presses (greater than 1000ms) of the user buttons are used for controlling -BLE advertisements and resets. The left button (`BTN-1`) is used to perform a -factory reset of the device. The Right button (`BTN-2`) is used to disable BLE -advertisements (if enabled) or enable advertisements (if disabled). - -## 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.11.0_2225-setup.run - $ chmod +x sysconfig-1.11.0_2225-setup.run - $ ./sysconfig-1.11.0_2225-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 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/sysconfig_1.11.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/all-clusters-minimal-app/cc13x2x7_26x2x7 - $ gn gen out/debug --args="ti_sysconfig_root=\"$HOME/ti/sysconfig_1.11.0\"" - $ 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` | - -## Running the Example - -Once a device has been flashed with this example, it can now join and operate in -an existing Thread network. The following sections assume that a Thread network -is already active, and has at least one [OpenThread Border -Router][ot_border_router_setup]. - -For insight into what other components are needed to run this example, please -refer to our [Matter Getting Started Guide][matter-e2e-faq]. - -### Provisioning - -Interacting with the application begins by enabling BLE advertisements and then -pairing the device into a Thread network. - -#### Bluetooth LE Advertising - -To provision this example onto a Thread network, the device must be discoverable -over Bluetooth LE. BLE advertising is started by long pressing the right button -(greater than 1000ms), labeled `BTN-2` on the silkscreen. Once the device is -fully provisioned, BLE advertising will stop. - -#### Bluetooth LE Rendezvous - -Pairing this application with `ble-thread` can be done with any of the enabled -[CHIP Controller](../../../src/controller/README.md) applications. Use the -information printed on the console to aide in pairing the device. The controller -application can also be used to control the example app with the cluster -commands. - -## 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 -[cc1352r1_launchxl]: https://www.ti.com/tool/LAUNCHXL-CC1352R1 -[e2e]: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread -[matter-e2e-faq]: - https://e2e.ti.com/support/wireless-connectivity/zigbee-thread-group/zigbee-and-thread/f/zigbee-thread-forum/1082428/faq-cc2652r7-matter----getting-started-guide -[sysconfig]: https://www.ti.com/tool/SYSCONFIG -[sysconfig_recommended]: - https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.11.0_2225-setup.run -[ti_thread_dnd]: - https://www.ti.com/wireless-connectivity/thread/design-development.html -[ot_border_router_setup]: https://openthread.io/guides/border-router/build -[uniflash]: https://www.ti.com/tool/download/UNIFLASH diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ClusterManager.cpp b/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ClusterManager.cpp deleted file mode 100644 index b55ffa374e9788..00000000000000 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ClusterManager.cpp +++ /dev/null @@ -1,177 +0,0 @@ - -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "ClusterManager.h" -#include "Globals.h" -#include -#include -#include -#include -#include - -#ifdef AUTO_PRINT_METRICS -#include -#endif - -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::System; -using namespace ::chip::DeviceLayer; - -constexpr uint32_t kIdentifyTimerDelayMS = 250; -constexpr uint32_t kIdentifyTimerDelayPerSec = 4; -ClusterManager ClusterManager::sCluster; - -#define ENDPOINT_ID_0 (0) -#define ENDPOINT_ID_1 (1) -#define ENDPOINT_ID_2 (2) - -void OnIdentifyTriggerEffect(Identify * identify) -{ - switch (identify->mCurrentEffectIdentifier) - { - case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK: - PLAT_LOG("EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK"); - break; - case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE: - PLAT_LOG("EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE"); - break; - case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY: - PLAT_LOG("EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY"); - break; - case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE: - PLAT_LOG("EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE"); - break; - default: - PLAT_LOG("No identifier effect"); - break; - } - return; -} - -Identify gIdentify0 = { - chip::EndpointId{ 0 }, - [](Identify *) { PLAT_LOG("onIdentifyStart"); }, - [](Identify *) { PLAT_LOG("onIdentifyStop"); }, - EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, - OnIdentifyTriggerEffect, -}; - -Identify gIdentify1 = { - chip::EndpointId{ 1 }, - [](Identify *) { PLAT_LOG("onIdentifyStart"); }, - [](Identify *) { PLAT_LOG("onIdentifyStop"); }, - EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, - OnIdentifyTriggerEffect, -}; - -void ClusterManager::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) -{ - VerifyOrExit(attributeId == app::Clusters::OnOff::Attributes::OnOff::Id, - PLAT_LOG("Unhandled Attribute ID: '0x%04x", attributeId)); - VerifyOrExit(endpointId == ENDPOINT_ID_1 || endpointId == ENDPOINT_ID_2, - PLAT_LOG("Unexpected EndPoint ID: `0x%02x'", endpointId)); - - // At this point we can assume that value points to a bool value. - mEndpointOnOffState[endpointId - 1] = *value; - endpointId == ENDPOINT_ID_1 ? LED_write(sAppGreenHandle, *value) : LED_write(sAppRedHandle, *value); - -exit: - return; -} - -void ClusterManager::OnLevelControlAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) -{ - bool onOffState = mEndpointOnOffState[endpointId - 1]; - uint8_t brightness = onOffState ? *value : 0; - - VerifyOrExit(brightness > 0, PLAT_LOG("Brightness set to 0, ignoring")); - VerifyOrExit(attributeId == app::Clusters::LevelControl::Attributes::CurrentLevel::Id, - PLAT_LOG("Unhandled Attribute ID: '0x%04x", attributeId)); - VerifyOrExit(endpointId == ENDPOINT_ID_1 || endpointId == ENDPOINT_ID_2, - PLAT_LOG("Unexpected EndPoint ID: `0x%02x'", endpointId)); - - if (brightness > LED_BRIGHTNESS_MAX) - { - brightness = LED_BRIGHTNESS_MAX; - } - - endpointId == ENDPOINT_ID_1 ? LED_setOn(sAppGreenHandle, brightness) : LED_setOn(sAppRedHandle, brightness); - -exit: - return; -} - -void ClusterManager::OnColorControlAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) -{ - using namespace app::Clusters::ColorControl::Attributes; - - VerifyOrExit(attributeId == CurrentHue::Id || attributeId == CurrentSaturation::Id, - PLAT_LOG("Unhandled AttributeId ID: '0x%04x", attributeId)); - VerifyOrExit(endpointId == ENDPOINT_ID_1 || endpointId == ENDPOINT_ID_2, - PLAT_LOG("Unexpected EndPoint ID: `0x%02x'", endpointId)); - - if (endpointId == ENDPOINT_ID_1) - { - uint8_t hue, saturation; - if (attributeId == CurrentHue::Id) - { - hue = *value; - /* Read Current Saturation value when Attribute change callback for HUE Attribute */ - CurrentSaturation::Get(endpointId, &saturation); - } - else - { - saturation = *value; - /* Read Current Hue value when Attribute change callback for SATURATION Attribute */ - CurrentHue::Get(endpointId, &hue); - } - PLAT_LOG("Color Control triggered: Hue: %d Saturation: %d", hue, saturation); - } -exit: - return; -} - -void ClusterManager::OnIdentifyPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint16_t size, - uint8_t * value) -{ - if (attributeId == app::Clusters::Identify::Attributes::IdentifyTime::Id && size == 2) - { - uint16_t identifyTime; - memcpy(&identifyTime, value, size); - if (identifyTime) - { - // Currently we have no separate indicator LEDs on each endpoints. - // We are using LED1 for endpoint 0,1 and LED2 for endpoint 2 - if (endpointId == ENDPOINT_ID_2) - { - LED_startBlinking(sAppGreenHandle, kIdentifyTimerDelayMS, identifyTime * kIdentifyTimerDelayPerSec); - } - else - { - LED_startBlinking(sAppRedHandle, kIdentifyTimerDelayMS, identifyTime * kIdentifyTimerDelayPerSec); - } - } - else - { - bool onOffState; - endpointId == ENDPOINT_ID_0 ? onOffState = mEndpointOnOffState[0] : onOffState = mEndpointOnOffState[endpointId - 1]; - endpointId == ENDPOINT_ID_2 ? LED_write(sAppRedHandle, onOffState) : LED_write(sAppGreenHandle, onOffState); - } - } -} diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/Globals.cpp b/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/Globals.cpp deleted file mode 100644 index 01a945e1a33d12..00000000000000 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/Globals.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Globals.h" - -LED_Handle sAppRedHandle; -LED_Handle sAppGreenHandle; diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/ClusterManager.h b/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/ClusterManager.h deleted file mode 100644 index 1599ef1ef19264..00000000000000 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/ClusterManager.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * Copyright 2021, Cypress Semiconductor Corporation (an Infineon company) - * 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 ClusterManager.h - * - * Declarations for the ClusterManager callbacks for this application - * - **/ - -#pragma once - -#include -#include -#include - -class ClusterManager -{ -public: - void OnOnOffPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); - void OnLevelControlAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); - void OnColorControlAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); - void OnIdentifyPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint16_t size, - uint8_t * value); - -private: - friend ClusterManager & ClusterMgr(void); - bool mEndpointOnOffState[2]; - static ClusterManager sCluster; -}; - -inline ClusterManager & ClusterMgr(void) -{ - return ClusterManager::sCluster; -} diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/.gn b/examples/lighting-app/cc13x2x7_26x2x7/.gn similarity index 99% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/.gn rename to examples/lighting-app/cc13x2x7_26x2x7/.gn index 0adefc6ff99c6a..3d48789e30ab3d 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/.gn +++ b/examples/lighting-app/cc13x2x7_26x2x7/.gn @@ -23,5 +23,6 @@ check_system_includes = true default_args = { target_cpu = "arm" target_os = "freertos" + import("//args.gni") } diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/BUILD.gn b/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn similarity index 71% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/BUILD.gn rename to examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn index 6c20ed346ec530..aec1e66b95939c 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/lighting-app/cc13x2x7_26x2x7/BUILD.gn @@ -26,18 +26,17 @@ import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni") assert(current_os == "freertos") -project_dir = "${chip_root}/examples/all-clusters-minimal-app/cc13x2x7_26x2x7" +project_dir = "${chip_root}/examples/lighting-app/cc13x2x7_26x2x7" ti_simplelink_sdk("sdk") { - include_dirs = [ "${project_dir}/main/include" ] - public_configs = [ ":all-clusters-minimal-app_config" ] + include_dirs = [ "${project_dir}/include" ] + public_configs = [ ":lighting_app_config" ] } ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", @@ -71,25 +70,22 @@ ti_sysconfig("sysconfig") { ] } -ti_simplelink_executable("all-clusters-minimal-app") { - output_name = "chip-${ti_simplelink_board}-all-clusters-minimal-example.out" +ti_simplelink_executable("lighting_app") { + output_name = "chip-${ti_simplelink_board}-lighting-example.out" sources = [ - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", - "${project_dir}/main/AppTask.cpp", - "${project_dir}/main/ClusterManager.cpp", - "${project_dir}/main/Globals.cpp", - "${project_dir}/main/ZclCallbacks.cpp", - "${project_dir}/main/main.cpp", + "${project_dir}/src/AppTask.cpp", + "${project_dir}/src/LightingManager.cpp", + "${project_dir}/src/ZclCallbacks.cpp", + "${project_dir}/src/main.cpp", ] deps = [ ":sdk", ":sysconfig", - "${chip_root}/examples/all-clusters-minimal-app/all-clusters-common", + "${chip_root}/examples/lighting-app/lighting-common", + "${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials", "${chip_root}/src/lib", ] @@ -101,8 +97,6 @@ ti_simplelink_executable("all-clusters-minimal-app") { include_dirs = [ "${project_dir}", - "${project_dir}/main", - "${chip_root}/examples/all-clusters-app/all-clusters-common/include", "${chip_root}/examples/providers/", ] @@ -116,7 +110,7 @@ ti_simplelink_executable("all-clusters-minimal-app") { } group("cc13x2x7_26x2x7") { - deps = [ ":all-clusters-minimal-app" ] + deps = [ ":lighting_app" ] } group("default") { diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/args.gni b/examples/lighting-app/cc13x2x7_26x2x7/args.gni similarity index 83% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/args.gni rename to examples/lighting-app/cc13x2x7_26x2x7/args.gni index 9228f70c4a0f03..a6a8662c4d14cb 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/args.gni +++ b/examples/lighting-app/cc13x2x7_26x2x7/args.gni @@ -27,17 +27,15 @@ ti_simplelink_board = "LP_CC2652R7" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true -# Disable FTD Build for all-clusters app to save Flash chip_openthread_ftd = false +openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2" # Disable CHIP Logging -chip_progress_logging = false - -# Dsiable verbose logs for all-clusters app to save Flash -chip_detail_logging = false -chip_automation_logging = false +#chip_progress_logging = false +#chip_detail_logging = false +#chip_automation_logging = false # BLE options chip_config_network_layer_ble = true @@ -47,6 +45,6 @@ chip_config_network_layer_ble = true chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" -matter_device_pid = "0x8006" +matter_device_pid = "0x8005" matter_software_ver = "0x0001" matter_software_ver_str = "1.0d1" diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/build_overrides b/examples/lighting-app/cc13x2x7_26x2x7/build_overrides similarity index 100% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/build_overrides rename to examples/lighting-app/cc13x2x7_26x2x7/build_overrides diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/chip.syscfg b/examples/lighting-app/cc13x2x7_26x2x7/chip.syscfg similarity index 82% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/chip.syscfg rename to examples/lighting-app/cc13x2x7_26x2x7/chip.syscfg index 4f02a9fd40da9a..995ad22af6b435 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/lighting-app/cc13x2x7_26x2x7/chip.syscfg @@ -26,11 +26,10 @@ 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 RFCustom = scripting.addModule("/ti/devices/radioconfig/custom"); 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 UART2 = scripting.addModule("/ti/drivers/UART2"); var ble = scripting.addModule("/ti/ble5stack/ble"); var dmm = scripting.addModule("/ti/dmm/dmm"); var AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); @@ -50,12 +49,11 @@ var LED2 = LED.addInstance(); var TRNG1 = TRNG.addInstance(); var TRNG2 = TRNG.addInstance(); var TRNG3 = TRNG.addInstance(); -var UART1 = UART.addInstance(); +var UART2 = UART2.addInstance(); var AESCTRDRBG1 = AESCTRDRBG.addInstance(); var ECDH1 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; -AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; AESCCM1.$name = "CONFIG_AESCCM0"; @@ -64,9 +62,6 @@ AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -/* RTOS */ -RTOS.name = "FreeRTOS"; - /* Left Button */ Button1.$name = "CONFIG_BTN_LEFT"; Button1.$hardware = system.deviceData.board.components["BTN-1"]; @@ -89,11 +84,11 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +// Disable CCFG generation, this is added by the BIM project +CCFG.enableCodeGeneration = false; /* NVS */ NVS1.$name = "CONFIG_NVSINTERNAL"; - NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; @@ -113,6 +108,58 @@ for(var setting in rfDesignSettings) RFDesign[setting] = rfDesignSettings[setting]; } +/* Handling for RF frontend characterization */ +if(RFDesign.rfDesign.match(/LP_CC2652PSIP/)) +{ + RFCustom.ieee = ["ieee154p10"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154p10.codeExportConfig +} +else +{ + RFCustom.ieee = ["ieee154"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154.codeExportConfig +} + +var cmdList = [ + "cmdIeeeTx", + "cmdIeeeRx", + "cmdIeeeCsma", + "cmdIeeeEdScan", + "cmdIeeeRxAck", + "cmdTxTest" +]; + +rfCodeExportConfig.useConst = true; +rfCodeExportConfig.useMulti = true; +rfCodeExportConfig.symGenMethod = "Custom"; + +const deviceId = system.deviceData.deviceId; + +// Add high PA options if present +if(deviceId.match(/CC(265[12]R|2674R|1352R1|1354R)/)) +{ + cmdList.push("cmdRadioSetup"); + rfCodeExportConfig.cmdRadioSetup = "RF_cmdIeeeRadioSetup"; +} +else if(deviceId.match(/CC(265[12]P|2674P|1352P)/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + rfCodeExportConfig.paExport = "combined"; +} +else if(deviceId.match(/CC(265[34]|1354)P/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + // currently not characterized for high PA +} +else +{ + throw new Error("Could not match platform to any known platform types"); +} + +rfCodeExportConfig.cmdList_ieee_15_4 = cmdList; + /* Red LED */ LED1.$name = "CONFIG_LED_RED"; LED1.$hardware = system.deviceData.board.components.LED_RED; @@ -128,16 +175,14 @@ LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; /* Debug UART */ -UART1.$hardware = system.deviceData.board.components.XDS110UART; -UART1.$name = "CONFIG_UART_DEBUG"; +UART2.$hardware = system.deviceData.board.components.XDS110UART; +UART2.$name = "CONFIG_UART2_DEBUG"; /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; -TRNG2.$name = "CONFIG_TRNG_1"; +TRNG2.$name = "CONFIG_TRNG_THREAD"; TRNG3.$name = "CONFIG_TRNG_APP"; -RTOS.name = "FreeRTOS"; - /* BLE */ ble.addressMode = "ADDRMODE_RP_WITH_PUBLIC_ID"; ble.maxConnNum = 1; @@ -145,11 +190,12 @@ ble.numOfAdvSets = 1; ble.lockProject = true; ble.oneLibSizeOpt = true; ble.maxPDUSize = 255; -ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param1"; +ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param2"; 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"; diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h similarity index 95% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h rename to examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index 4d50a5a05c08d9..0f5090d7d9f320 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -55,7 +55,9 @@ * physical device, a change to its packaging, and/or a change to its marketing presentation. * This value is generally *not* incremented for device software versions. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION #define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 +#endif /** * Values set by args.gni: @@ -79,7 +81,7 @@ */ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) -#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 1 +#define MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED 1 /** * CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT @@ -108,13 +110,13 @@ * * @brief Defines the maximum number of CommandHandler, limits the number of active commands transactions on server. */ -#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 1 +#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 2 /** * @def CHIP_IM_MAX_NUM_WRITE_HANDLER * * @brief Defines the maximum number of WriteHandler, limits the number of active write transactions on server. */ -#define CHIP_IM_MAX_NUM_WRITE_HANDLER 1 +#define CHIP_IM_MAX_NUM_WRITE_HANDLER 2 #endif // CHIP_PROJECT_CONFIG_H diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/Globals.h b/examples/lighting-app/cc13x2x7_26x2x7/src/AppConfig.h similarity index 75% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/Globals.h rename to examples/lighting-app/cc13x2x7_26x2x7/src/AppConfig.h index 43f9362e0341b9..a818b21d641875 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/Globals.h +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppConfig.h @@ -1,5 +1,4 @@ /* - * * Copyright (c) 2020 Project CHIP Authors * All rights reserved. * @@ -16,20 +15,21 @@ * limitations under the License. */ -#pragma once +#ifndef APP_CONFIG_H +#define APP_CONFIG_H -#include // Logging #ifdef __cplusplus extern "C" { #endif -int cc13x2_26x2LogInit(void); -void cc13x2_26x2Log(const char * aFormat, ...); -#define PLAT_LOG(...) cc13x2_26x2Log(__VA_ARGS__); +int cc13xx_26xxLogInit(void); +void cc13xx_26xxLog(const char * aFormat, ...); +#define PLAT_LOG(...) cc13xx_26xxLog(__VA_ARGS__); + +#define ACTUATOR_MOVEMENT_PERIOD_MS 1000 #ifdef __cplusplus } #endif -extern LED_Handle sAppRedHandle; -extern LED_Handle sAppGreenHandle; +#endif // APP_CONFIG_H diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/AppEvent.h b/examples/lighting-app/cc13x2x7_26x2x7/src/AppEvent.h new file mode 100644 index 00000000000000..9c55e1bf674531 --- /dev/null +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppEvent.h @@ -0,0 +1,84 @@ +/* + * + * 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. + */ +#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, + kEventType_IdentifyStart, + kEventType_IdentifyStop, + kEventType_Light, + kEventType_Timer, + }; + + enum AppEventButtonType + { + kAppEventButtonType_None = 0, + kAppEventButtonType_Clicked, + kAppEventButtonType_LongClicked, + }; + + enum AppEventIdentifyType + { + kAppEventIdentifyType_Blink = 0, + kAppEventIdentifyType_Breathe, + kAppEventIdentifyType_Okay, + kAppEventIdentifyType_Finish, + kAppEventIdentifyType_Stop, + }; + + enum AppEventType Type; + + union + { + struct + { + enum AppEventButtonType Type; + } ButtonEvent; + + struct + { + void * Context; + } TimerEvent; + + struct + { + uint8_t Action; + int32_t Actor; + void * Context; + } LightEvent; + + struct + { + enum AppEventIdentifyType Type; + } IdentifyEvent; + }; + + EventHandler Handler; +}; + +#endif // APP_EVENT_H diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp similarity index 56% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/AppTask.cpp rename to examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp index 871a5f71d6acc0..945679b5e1e853 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.cpp @@ -20,13 +20,12 @@ #include "AppTask.h" #include "AppConfig.h" #include "AppEvent.h" -#include -#include #include "FreeRTOS.h" -#include "Globals.h" + #include #include +#include #include #include @@ -36,15 +35,19 @@ #include #include #include -#include +#include #endif + #include #include -#ifdef AUTO_PRINT_METRICS -#include -#endif +#include + +#include +#include #include +#include +#include #include #include @@ -52,10 +55,19 @@ /* syscfg */ #include -#define APP_TASK_STACK_SIZE (5000) +#define APP_TASK_STACK_SIZE (4096) #define APP_TASK_PRIORITY 4 #define APP_EVENT_QUEUE_SIZE 10 +#define IDENTIFY_TRIGGER_EFFECT_BLINK 0 +#define IDENTIFY_TRIGGER_EFFECT_BREATHE 1 +#define IDENTIFY_TRIGGER_EFFECT_OKAY 2 +#define IDENTIFY_TRIGGER_EFFECT_FINISH_STOP 3 + +static uint32_t identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_FINISH_STOP; + +#define LIGHTING_APPLICATION_IDENTIFY_ENDPOINT 1 + using namespace ::chip; using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; @@ -63,14 +75,14 @@ using namespace ::chip::DeviceLayer; static TaskHandle_t sAppTaskHandle; static QueueHandle_t sAppEventQueue; +static LED_Handle sAppRedHandle; +static LED_Handle sAppGreenHandle; static Button_Handle sAppLeftHandle; static Button_Handle sAppRightHandle; static DeviceInfoProviderImpl sExampleDeviceInfoProvider; AppTask AppTask::sAppTask; -constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; - #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR static DefaultOTARequestor sRequestorCore; static DefaultOTARequestorStorage sRequestorStorage; @@ -91,54 +103,8 @@ void InitializeOTARequestor(void) } #endif -#ifdef AUTO_PRINT_METRICS -static void printMetrics(void) -{ - chip::DeviceLayer::ThreadMetrics *threadMetricsOut, *currThread; - uint64_t heapFree, heapUsed; - - DiagnosticDataProviderImpl::GetDefaultInstance().GetCurrentHeapUsed(heapUsed); - DiagnosticDataProviderImpl::GetDefaultInstance().GetCurrentHeapFree(heapFree); - DiagnosticDataProviderImpl::GetDefaultInstance().GetThreadMetrics(&threadMetricsOut); - - PLAT_LOG("Heap Metrics\n Heap Free: %d Heap Used: %d", (uint32_t) heapFree, (uint32_t) heapUsed); - - PLAT_LOG("Thread Metrics\n"); - - currThread = threadMetricsOut; - while (currThread) - { - PLAT_LOG("Task Name: %s ID: %d Stack Free Min: %d", currThread->name, (uint32_t) currThread->id, - (uint32_t) currThread->stackFreeMinimum); - - currThread = currThread->Next; - } - - DiagnosticDataProviderImpl::GetDefaultInstance().ReleaseThreadMetrics(threadMetricsOut); -} -#endif - -void DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) -{ - switch (event->Type) - { - case DeviceEventType::kCHIPoBLEConnectionEstablished: - PLAT_LOG("CHIPoBLE connection established"); - break; - - case DeviceEventType::kCHIPoBLEConnectionClosed: - PLAT_LOG("CHIPoBLE disconnected"); - break; - - case DeviceEventType::kCommissioningComplete: - PLAT_LOG("Commissioning complete"); - break; - } - -#ifdef AUTO_PRINT_METRICS - printMetrics(); -#endif -} +::Identify stIdentify = { LIGHTING_APPLICATION_IDENTIFY_ENDPOINT, AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler, + EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, AppTask::TriggerIdentifyEffectHandler }; int AppTask::StartAppTask() { @@ -148,7 +114,7 @@ int AppTask::StartAppTask() if (sAppEventQueue == NULL) { PLAT_LOG("Failed to allocate app event queue"); - while (true) + while (1) ; } @@ -157,46 +123,50 @@ int AppTask::StartAppTask() pdPASS) { PLAT_LOG("Failed to create app task"); - while (true) + while (1) ; } return ret; } -int AppTask::Init() +// Action initiated callback +void uiTurnOn(void) { - LED_Params ledParams; - Button_Params buttonParams; + PLAT_LOG("Light On initiated"); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER); +} - cc13x2_26x2LogInit(); +// Action completed callback +void uiTurnedOn(void) +{ + PLAT_LOG("Light On completed"); + LED_stopBlinking(sAppRedHandle); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); +} - // Initialize LEDs - PLAT_LOG("Initialize LEDs"); - LED_init(); +// Action initiated callback +void uiTurnOff(void) +{ + PLAT_LOG("Light Off initiated"); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER); +} - LED_Params_init(&ledParams); // default PWM LED - sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams); +// Action completed callback +void uiTurnedOff(void) +{ + PLAT_LOG("Light Off completed"); + LED_stopBlinking(sAppRedHandle); LED_setOff(sAppRedHandle); +} - LED_Params_init(&ledParams); // default PWM LED - sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams); - LED_setOff(sAppGreenHandle); - - // Initialize buttons - PLAT_LOG("Initialize buttons"); - Button_init(); +int AppTask::Init() +{ + LED_Params ledParams; + Button_Params buttonParams; - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); - Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); - - Button_Params_init(&buttonParams); - buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; - buttonParams.longPressDuration = 1000U; // ms - sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); - Button_setCallback(sAppRightHandle, ButtonRightEventHandler); + cc13xx_26xxLogInit(); // Init Chip memory management before the stack Platform::MemoryInit(); @@ -205,7 +175,7 @@ int AppTask::Init() if (ret != CHIP_NO_ERROR) { PLAT_LOG("PlatformMgr().InitChipStack() failed"); - while (true) + while (1) ; } @@ -213,15 +183,18 @@ int AppTask::Init() if (ret != CHIP_NO_ERROR) { PLAT_LOG("ThreadStackMgr().InitThreadStack() failed"); - while (true) + while (1) ; } - +#if CHIP_DEVICE_CONFIG_THREAD_FTD + ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); +#else ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); +#endif if (ret != CHIP_NO_ERROR) { PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed"); - while (true) + while (1) ; } @@ -229,7 +202,7 @@ int AppTask::Init() if (ret != CHIP_NO_ERROR) { PLAT_LOG("PlatformMgr().StartEventLoopTask() failed"); - while (true) + while (1) ; } @@ -237,32 +210,68 @@ int AppTask::Init() if (ret != CHIP_NO_ERROR) { PLAT_LOG("ThreadStackMgr().StartThreadTask() failed"); - while (true) + while (1) ; } // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); - static chip::CommonCaseDeviceServerInitParams initParams; + static CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); // Initialize info provider sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); SetDeviceInfoProvider(&sExampleDeviceInfoProvider); - chip::Server::GetInstance().Init(initParams); - - ConfigurationMgr().LogDeviceConfig(); + Server::GetInstance().Init(initParams); // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + + // Initialize LEDs + PLAT_LOG("Initialize LEDs"); + LED_init(); + + LED_Params_init(&ledParams); // default PWM LED + sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams); + LED_setOff(sAppRedHandle); + + LED_Params_init(&ledParams); // default PWM LED + sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams); + LED_setOff(sAppGreenHandle); - // We only have network commissioning on endpoint 0. - emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); + // Initialize buttons + PLAT_LOG("Initialize buttons"); + Button_init(); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(sAppRightHandle, ButtonRightEventHandler); + + ret = LightMgr().Init(); + + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("LightMgr().Init() failed"); + while (1) + ; + } + + LightMgr().SetCallbacks(ActionInitiated, ActionCompleted); - // Register a function to receive events from the CHIP device layer. Note that calls to - // this function will happen on the CHIP event loop thread, not the app_main thread. - PlatformMgr().AddEventHandler(DeviceEventCallback, reinterpret_cast(nullptr)); + ConfigurationMgr().LogDeviceConfig(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); @@ -279,7 +288,7 @@ void AppTask::AppTaskMain(void * pvParameter) sAppTask.Init(); - while (true) + while (1) { /* Task pend until we have stuff to do */ if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE) @@ -289,14 +298,6 @@ void AppTask::AppTaskMain(void * pvParameter) } } -void AppTask::PostEvent(const AppEvent * aEvent) -{ - if (xQueueSend(sAppEventQueue, aEvent, 0) != pdPASS) - { - /* Failed to post the message */ - } -} - void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events) { AppEvent event; @@ -337,13 +338,80 @@ void AppTask::ButtonRightEventHandler(Button_Handle handle, Button_EventMask eve } } +void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor) +{ + if (aAction == LightingManager::ON_ACTION) + { + uiTurnOn(); + } + else if (aAction == LightingManager::OFF_ACTION) + { + uiTurnOff(); + } +} + +void AppTask::ActionCompleted(LightingManager::Action_t aAction) +{ + if (aAction == LightingManager::ON_ACTION) + { + uiTurnedOn(); + } + else if (aAction == LightingManager::OFF_ACTION) + { + uiTurnedOff(); + } +} + +void AppTask::PostEvent(const AppEvent * aEvent) +{ + if (sAppEventQueue != NULL) + { + BaseType_t status; + if (xPortIsInsideInterrupt()) + { + BaseType_t higherPrioTaskWoken = pdFALSE; + status = xQueueSendFromISR(sAppEventQueue, aEvent, &higherPrioTaskWoken); + +#ifdef portYIELD_FROM_ISR + portYIELD_FROM_ISR(higherPrioTaskWoken); +#elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR + portEND_SWITCHING_ISR(higherPrioTaskWoken); +#else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR +#error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR" +#endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR + } + else + { + status = xQueueSend(sAppEventQueue, aEvent, 1); + } + + if (status != pdTRUE) + { + PLAT_LOG("Failed to post event to app task event queue"); + } + } + else + { + PLAT_LOG("Event Queue is NULL should never happen"); + } +} + void AppTask::DispatchEvent(AppEvent * aEvent) { + int32_t actor; + switch (aEvent->Type) { + case AppEvent::kEventType_Light: { + actor = aEvent->LightEvent.Actor; + LightMgr().IsLightOn() ? LightMgr().InitiateAction(actor, LightingManager::OFF_ACTION) + : LightMgr().InitiateAction(actor, LightingManager::ON_ACTION); + } case AppEvent::kEventType_ButtonLeft: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { + actor = AppEvent::kEventType_ButtonLeft; + LightMgr().InitiateAction(actor, LightingManager::ON_ACTION); } else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) { @@ -354,6 +422,8 @@ void AppTask::DispatchEvent(AppEvent * aEvent) case AppEvent::kEventType_ButtonRight: if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) { + actor = AppEvent::kEventType_ButtonRight; + LightMgr().InitiateAction(actor, LightingManager::OFF_ACTION); } else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) { @@ -378,6 +448,33 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } break; + case AppEvent::kEventType_IdentifyStart: + switch (identify_trigger_effect) + { + case IDENTIFY_TRIGGER_EFFECT_BLINK: + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 1000, LED_BLINK_FOREVER); + break; + case IDENTIFY_TRIGGER_EFFECT_BREATHE: + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 100, LED_BLINK_FOREVER); + break; + case IDENTIFY_TRIGGER_EFFECT_OKAY: + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 500, LED_BLINK_FOREVER); + break; + default: + break; + } + PLAT_LOG("Identify started"); + break; + + case AppEvent::kEventType_IdentifyStop: + LED_stopBlinking(sAppGreenHandle); + LED_setOff(sAppGreenHandle); + PLAT_LOG("Identify stopped"); + break; + case AppEvent::kEventType_AppEvent: if (NULL != aEvent->Handler) { @@ -390,3 +487,54 @@ void AppTask::DispatchEvent(AppEvent * aEvent) break; } } + +void AppTask::IdentifyStartHandler(::Identify *) +{ + AppEvent event; + event.Type = AppEvent::kEventType_IdentifyStart; + sAppTask.PostEvent(&event); +} + +void AppTask::IdentifyStopHandler(::Identify *) +{ + AppEvent event; + event.Type = AppEvent::kEventType_IdentifyStop; + sAppTask.PostEvent(&event); +} + +void AppTask::TriggerIdentifyEffectHandler(::Identify * identify) +{ + switch (identify->mCurrentEffectIdentifier) + { + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK: + PLAT_LOG("Starting blink identifier effect"); + identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_BLINK; + IdentifyStartHandler(identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE: + PLAT_LOG("Starting breathe identifier effect"); + identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_BREATHE; + IdentifyStartHandler(identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY: + PLAT_LOG("Starting okay identifier effect"); + identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_OKAY; + IdentifyStartHandler(identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE: + PLAT_LOG("Channel Change identifier effect not implemented"); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT: + PLAT_LOG("Finish identifier effect"); + identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_FINISH_STOP; + IdentifyStopHandler(identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT: + PLAT_LOG("Stop identifier effect"); + identify_trigger_effect = IDENTIFY_TRIGGER_EFFECT_FINISH_STOP; + IdentifyStopHandler(identify); + break; + default: + PLAT_LOG("No identifier effect"); + } +} diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h new file mode 100644 index 00000000000000..3d305601bc12f7 --- /dev/null +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/AppTask.h @@ -0,0 +1,93 @@ +/* + * 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. + */ + +#pragma once + +#include +#include + +#include "FreeRTOS.h" +#include "semphr.h" +#include "task.h" + +#include "AppEvent.h" +#include "LightingManager.h" + +#include + +// Application-defined error codes in the CHIP_ERROR space. +#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) +#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) +#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03) +#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04) +#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05) +#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06) +#define APP_ERROR_ALLOCATION_FAILED CHIP_APPLICATION_ERROR(0x07) +struct Identify; + +class AppTask +{ + +public: + int StartAppTask(); + static void AppTaskMain(void * pvParameter); + + static AppTask & GetAppTask() { return sAppTask; } + + void PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction); + void PostEvent(const AppEvent * event); + + static void IdentifyStartHandler(::Identify *); + static void IdentifyStopHandler(::Identify *); + static void TriggerIdentifyEffectHandler(::Identify * identify); + +private: + friend AppTask & GetAppTask(void); + + int Init(); + + static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor); + static void ActionCompleted(LightingManager::Action_t aAction); + + void DispatchEvent(AppEvent * event); + static void UpdateClusterState(intptr_t context); + static void SingleButtonEventHandler(AppEvent * aEvent); + static void ButtonTimerEventHandler(AppEvent * aEvent); + + static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events); + 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; +} diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.cpp b/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.cpp new file mode 100644 index 00000000000000..ed5fc52e7e5638 --- /dev/null +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.cpp @@ -0,0 +1,176 @@ +/* + * + * 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 "LightingManager.h" + +#include "AppConfig.h" +#include "AppTask.h" +#include + +using namespace chip; +using namespace ::chip::DeviceLayer; + +LightingManager LightingManager::sLight; + +TimerHandle_t sLightTimer; + +CHIP_ERROR LightingManager::Init() +{ + // Create FreeRTOS sw timer for light timer. + sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel + 1, // == default timer period (mS) + false, // no timer reload (==one-shot) + (void *) this, // init timer id = light obj context + TimerEventHandler // timer callback handler + ); + + if (sLightTimer == NULL) + { + PLAT_LOG("sLightTimer timer create failed"); + } + + bool currentLedState; + // read current on/off value on endpoint one. + OnOffServer::Instance().getOnOffValue(1, ¤tLedState); + + mState = currentLedState ? kState_OnCompleted : kState_OffCompleted; + + return CHIP_NO_ERROR; +} + +void LightingManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB) +{ + mActionInitiated_CB = aActionInitiated_CB; + mActionCompleted_CB = aActionCompleted_CB; +} + +bool LightingManager::IsActionInProgress() +{ + return (mState == kState_OffInitiated || mState == kState_OnInitiated); +} + +bool LightingManager::IsLightOn() +{ + return (mState == kState_OnCompleted); +} + +bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction) +{ + bool action_initiated = false; + State_t new_state; + + // Initiate Turn On/Off Action only when the previous one is complete. + if (mState == kState_OffCompleted && aAction == ON_ACTION) + { + action_initiated = true; + + new_state = kState_OnInitiated; + } + else if (mState == kState_OnCompleted && aAction == OFF_ACTION) + { + action_initiated = true; + + new_state = kState_OffInitiated; + } + + if (action_initiated) + { + StartTimer(ACTUATOR_MOVEMENT_PERIOD_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 LightingManager::StartTimer(uint32_t aTimeoutMs) +{ + if (xTimerIsTimerActive(sLightTimer)) + { + PLAT_LOG("app timer already started!"); + CancelTimer(); + } + + // timer is not active, change its period to required value (== restart). + // FreeRTOS- Block for a maximum of 100 ticks if the change period command + // cannot immediately be sent to the timer command queue. + if (xTimerChangePeriod(sLightTimer, pdMS_TO_TICKS(aTimeoutMs), 100) != pdPASS) + { + PLAT_LOG("sLightTimer timer start() failed"); + } +} + +void LightingManager::CancelTimer(void) +{ + if (xTimerStop(sLightTimer, 0) == pdFAIL) + { + PLAT_LOG("sLightTimer stop() failed"); + } +} + +void LightingManager::TimerEventHandler(TimerHandle_t xTimer) +{ + // Get light obj context from timer id. + LightingManager * light = static_cast(pvTimerGetTimerID(xTimer)); + + // The timer event handler will be called in the context of the timer task + // once sLightTimer expires. Post an event to apptask queue with the actual handler + // so that the event can be handled in the context of the apptask. + AppEvent event; + event.Type = AppEvent::kEventType_AppEvent; + event.LightEvent.Context = light; + + event.Handler = ActuatorMovementTimerEventHandler; + + AppTask::GetAppTask().PostEvent(&event); +} + +void LightingManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) +{ + Action_t actionCompleted = INVALID_ACTION; + + LightingManager * light = static_cast(aEvent->LightEvent.Context); + + if (light->mState == kState_OffInitiated) + { + light->mState = kState_OffCompleted; + actionCompleted = OFF_ACTION; + OnOffServer::Instance().setOnOffValue(1, 0, false); + } + else if (light->mState == kState_OnInitiated) + { + light->mState = kState_OnCompleted; + actionCompleted = ON_ACTION; + OnOffServer::Instance().setOnOffValue(1, 1, false); + } + + if (actionCompleted != INVALID_ACTION) + { + if (light->mActionCompleted_CB) + { + light->mActionCompleted_CB(actionCompleted); + } + } +} diff --git a/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.h b/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.h new file mode 100644 index 00000000000000..818feed45ee87a --- /dev/null +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/LightingManager.h @@ -0,0 +1,82 @@ +/* + * + * 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. + */ + +#pragma once + +#include +#include + +#include "AppEvent.h" + +#include "FreeRTOS.h" +#include "timers.h" // provides FreeRTOS timer support +#include + +#include + +class LightingManager +{ +public: + enum Action_t + { + ON_ACTION = 0, + OFF_ACTION, + + INVALID_ACTION + } Action; + + enum State_t + { + kState_OffInitiated = 0, + kState_OffCompleted, + kState_OnInitiated, + kState_OnCompleted, + } State; + + CHIP_ERROR Init(); + bool IsLightOn(); + 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); + + static void OnTriggerOffWithEffect(OnOffEffect * effect); + +private: + friend LightingManager & LightMgr(void); + State_t mState; + + Callback_fn_initiated mActionInitiated_CB; + Callback_fn_completed mActionCompleted_CB; + + void CancelTimer(void); + void StartTimer(uint32_t aTimeoutMs); + + static void TimerEventHandler(TimerHandle_t xTimer); + static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); + static void OffEffectTimerEventHandler(AppEvent * aEvent); + + static LightingManager sLight; +}; + +inline LightingManager & LightMgr(void) +{ + return LightingManager::sLight; +} diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp b/examples/lighting-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp similarity index 57% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp rename to examples/lighting-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp index ba3f7bd1c205f8..7bb20a45944545 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp @@ -1,7 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors - * Copyright 2021, Cypress Semiconductor Corporation (an Infineon company) + * 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. @@ -22,17 +21,12 @@ */ #include "AppConfig.h" -#include "Globals.h" -#include - -#include "ClusterManager.h" +#include "LightingManager.h" #include #include -#include -#include -#include -#include +#include +#include using namespace ::chip; using namespace ::chip::app::Clusters; @@ -40,35 +34,26 @@ using namespace ::chip::app::Clusters; void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) { - EndpointId endpoint = attributePath.mEndpointId; ClusterId clusterId = attributePath.mClusterId; AttributeId attributeId = attributePath.mAttributeId; - PLAT_LOG("MatterPostAttributeChangeCallback - Cluster ID: " ChipLogFormatMEI - ", EndPoint ID: '0x%02x', Attribute ID: " ChipLogFormatMEI, - ChipLogValueMEI(clusterId), endpoint, ChipLogValueMEI(attributeId)); + ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); - switch (clusterId) + if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id) { - case OnOff::Id: - ClusterMgr().OnOnOffPostAttributeChangeCallback(endpoint, attributeId, value); - break; - - case Identify::Id: - ClusterMgr().OnIdentifyPostAttributeChangeCallback(endpoint, attributeId, size, value); - break; - - case LevelControl::Id: - ClusterMgr().OnLevelControlAttributeChangeCallback(endpoint, attributeId, value); - break; - - case ColorControl::Id: - ClusterMgr().OnColorControlAttributeChangeCallback(endpoint, attributeId, value); - break; - default: - PLAT_LOG("Unhandled cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); - break; + LightMgr().InitiateAction(AppEvent::kEventType_Light, *value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION); + } + else if (clusterId == Identify::Id) + { + ChipLogProgress(Zcl, "Identify attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", + ChipLogValueMEI(attributeId), type, *value, size); + } + else if (clusterId == Groups::Id) + { + ChipLogProgress(Zcl, "Groups attribute ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u", + ChipLogValueMEI(attributeId), type, *value, size); } } + /** @brief OnOff Cluster Init * * This function is called when a specific cluster is initialized. It gives the @@ -76,6 +61,13 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & * 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) { diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/main.cpp b/examples/lighting-app/cc13x2x7_26x2x7/src/main.cpp similarity index 79% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/main.cpp rename to examples/lighting-app/cc13x2x7_26x2x7/src/main.cpp index 8311c8990aa5c6..4fdb88703acab6 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/lighting-app/cc13x2x7_26x2x7/src/main.cpp @@ -21,8 +21,8 @@ #include -#include -#include +#include "AppConfig.h" +#include "AppTask.h" #include @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -38,7 +37,7 @@ #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xc800) +#define TOTAL_ICALL_HEAP_SIZE (0xc600) using namespace ::chip; using namespace ::chip::Inet; @@ -52,12 +51,23 @@ uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE; // ================================================================================ extern "C" void vApplicationStackOverflowHook(void) { - while (true) + while (1) { ; } } +/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */ +extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +extern "C" void vQueueUnregisterQueueWrapper(QueueHandle_t xQueue) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + // ================================================================================ // Main Code // ================================================================================ @@ -70,8 +80,6 @@ int main(void) NVS_init(); - UART_init(); - ECDH_init(); ECDSA_init(); @@ -85,13 +93,13 @@ int main(void) { // can't log until the kernel is started // PLAT_LOG("GetAppTask().StartAppTask() failed"); - while (true) + while (1) ; } vTaskStartScheduler(); // Should never get here. - while (true) + while (1) ; } diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/third_party/connectedhomeip b/examples/lighting-app/cc13x2x7_26x2x7/third_party/connectedhomeip similarity index 100% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/third_party/connectedhomeip rename to examples/lighting-app/cc13x2x7_26x2x7/third_party/connectedhomeip diff --git a/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn b/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn index ba2b327339e516..0bd2dfef85d615 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/lock-app/cc13x2x7_26x2x7/BUILD.gn @@ -29,7 +29,7 @@ assert(current_os == "freertos") project_dir = "${chip_root}/examples/lock-app/cc13x2x7_26x2x7" ti_simplelink_sdk("sdk") { - include_dirs = [ "${project_dir}/main/include" ] + include_dirs = [ "${project_dir}/include" ] public_configs = [ ":lock_app_config" ] } @@ -75,16 +75,17 @@ ti_simplelink_executable("lock_app") { sources = [ "${chip_root}/examples/providers/DeviceInfoProviderImpl.cpp", - "${project_dir}/main/AppTask.cpp", - "${project_dir}/main/BoltLockManager.cpp", - "${project_dir}/main/ZclCallbacks.cpp", - "${project_dir}/main/main.cpp", + "${project_dir}/src/AppTask.cpp", + "${project_dir}/src/LockManager.cpp", + "${project_dir}/src/ZclCallbacks.cpp", + "${project_dir}/src/main.cpp", ] deps = [ ":sdk", ":sysconfig", "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials", "${chip_root}/src/lib", ] @@ -96,7 +97,6 @@ ti_simplelink_executable("lock_app") { include_dirs = [ "${project_dir}", - "${project_dir}/main", "${chip_root}/examples/providers/", ] diff --git a/examples/lock-app/cc13x2x7_26x2x7/args.gni b/examples/lock-app/cc13x2x7_26x2x7/args.gni index 58a0bbbf2f366b..bd3e05a0055114 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/args.gni +++ b/examples/lock-app/cc13x2x7_26x2x7/args.gni @@ -29,8 +29,11 @@ lwip_debug = false chip_enable_ota_requestor = true +chip_openthread_ftd = false +openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2" + # Disable CHIP Logging -#chip_progress_logging = false +chip_progress_logging = false chip_detail_logging = false chip_automation_logging = false @@ -41,8 +44,6 @@ chip_config_network_layer_ble = true # INCLUDE_xSemaphoreGetMutexHolder chip_stack_lock_tracking = "none" -chip_openthread_ftd = false - matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" diff --git a/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg b/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg index b55c57b9c364be..47cd09c1a31165 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/lock-app/cc13x2x7_26x2x7/chip.syscfg @@ -133,8 +133,8 @@ UART1.$name = "CONFIG_UART_DEBUG"; /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; -TRNG2.$name = "CONFIG_TRNG_1"; -TRNG3.$name = "CONFIG_TRNG_APP"; +TRNG2.$name = "CONFIG_TRNG_APP"; +TRNG3.$name = "CONFIG_TRNG_THREAD"; RTOS.name = "FreeRTOS"; @@ -152,6 +152,8 @@ 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"; diff --git a/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..a808f37a72d7b5 --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -0,0 +1,130 @@ +/* + * 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 +// Note: Default Pairing/PIN/Serial Numbers being used. These should not be enabled for production builds +#endif // BUILD_RELEASE + +// 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" + +/** + * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION + * + * The hardware version 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 versions. + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION +#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 +#endif + +/** + * Values set by args.gni: + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION + */ + +/** + * 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_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) + +#define MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED 1 + +/** + * 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 + +#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 + +/** + * @def CHIP_IM_MAX_NUM_COMMAND_HANDLER + * + * @brief Defines the maximum number of CommandHandler, limits the number of active commands transactions on server. + */ +#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 2 + +/** + * @def CHIP_IM_MAX_NUM_WRITE_HANDLER + * + * @brief Defines the maximum number of WriteHandler, limits the number of active write transactions on server. + */ +#define CHIP_IM_MAX_NUM_WRITE_HANDLER 2 + +#endif // CHIP_PROJECT_CONFIG_H diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppConfig.h b/examples/lock-app/cc13x2x7_26x2x7/src/AppConfig.h similarity index 74% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppConfig.h rename to examples/lock-app/cc13x2x7_26x2x7/src/AppConfig.h index f7302b6efd10cd..a818b21d641875 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppConfig.h +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppConfig.h @@ -1,6 +1,5 @@ /* * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,4 +18,18 @@ #ifndef APP_CONFIG_H #define APP_CONFIG_H +// Logging +#ifdef __cplusplus +extern "C" { +#endif + +int cc13xx_26xxLogInit(void); +void cc13xx_26xxLog(const char * aFormat, ...); +#define PLAT_LOG(...) cc13xx_26xxLog(__VA_ARGS__); + +#define ACTUATOR_MOVEMENT_PERIOD_MS 1000 + +#ifdef __cplusplus +} +#endif #endif // APP_CONFIG_H diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppEvent.h b/examples/lock-app/cc13x2x7_26x2x7/src/AppEvent.h similarity index 86% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppEvent.h rename to examples/lock-app/cc13x2x7_26x2x7/src/AppEvent.h index ad9e93ee3ad1a5..dc4ce143338e1e 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppEvent.h +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppEvent.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2018 Nest Labs, Inc. + * Copyright (c) 2021 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,8 @@ struct AppEvent kEventType_ButtonLeft, kEventType_ButtonRight, kEventType_AppEvent, + kEventType_IdentifyStart, + kEventType_IdentifyStop, }; enum AppEventButtonType @@ -52,6 +54,12 @@ struct AppEvent { void * Context; } BoltLockEvent; + + struct + { + uint8_t Action; + int32_t Actor; + } LockEvent; }; EventHandler Handler; diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp new file mode 100644 index 00000000000000..772070fc7a0eab --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.cpp @@ -0,0 +1,561 @@ +/* + * + * 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 "FreeRTOS.h" + +#include +#include + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +#include +#include +#include +#include +#include +#endif + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +/* syscfg */ +#include + +#define APP_TASK_STACK_SIZE (4096) +#define APP_TASK_PRIORITY 4 +#define APP_EVENT_QUEUE_SIZE 10 + +using namespace ::chip; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; +using namespace ::chip::app::Clusters::DoorLock; + +static TaskHandle_t sAppTaskHandle; +static QueueHandle_t sAppEventQueue; + +static LED_Handle sAppRedHandle; +static LED_Handle sAppGreenHandle; +static Button_Handle sAppLeftHandle; +static Button_Handle sAppRightHandle; +static DeviceInfoProviderImpl sExampleDeviceInfoProvider; + +AppTask AppTask::sAppTask; + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +static DefaultOTARequestor sRequestorCore; +static DefaultOTARequestorStorage sRequestorStorage; +static DefaultOTARequestorDriver sRequestorUser; +static BDXDownloader sDownloader; +static OTAImageProcessorImpl sImageProcessor; + +void InitializeOTARequestor(void) +{ + // Initialize and interconnect the Requestor and Image Processor objects + SetRequestorInstance(&sRequestorCore); + + sRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); + sRequestorCore.Init(Server::GetInstance(), sRequestorStorage, sRequestorUser, sDownloader); + sImageProcessor.SetOTADownloader(&sDownloader); + sDownloader.SetImageProcessorDelegate(&sImageProcessor); + sRequestorUser.Init(&sRequestorCore, &sImageProcessor); +} +#endif + +::Identify stIdentify = { 0, AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler, + EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, AppTask::TriggerIdentifyEffectHandler }; + +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; +} + +void uiLocking(void) +{ + PLAT_LOG("Lock initiated"); + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 50 /* ms */, LED_BLINK_FOREVER); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER); +} + +void uiLocked(void) +{ + PLAT_LOG("Lock completed"); + LED_stopBlinking(sAppGreenHandle); + LED_setOff(sAppGreenHandle); + LED_stopBlinking(sAppRedHandle); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); +} + +void uiUnlocking(void) +{ + PLAT_LOG("Unlock initiated"); + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 50 /* ms */, LED_BLINK_FOREVER); + LED_setOn(sAppRedHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppRedHandle, 110 /* ms */, LED_BLINK_FOREVER); +} + +void uiUnlocked(void) +{ + PLAT_LOG("Unlock completed"); + LED_stopBlinking(sAppGreenHandle); + LED_setOff(sAppGreenHandle); + LED_stopBlinking(sAppRedHandle); + LED_setOff(sAppRedHandle); +} + +int AppTask::Init() +{ + LED_Params ledParams; + Button_Params buttonParams; + + cc13xx_26xxLogInit(); + + // Init Chip memory management before the stack + Platform::MemoryInit(); + + CHIP_ERROR ret = PlatformMgr().InitChipStack(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("PlatformMgr().InitChipStack() failed"); + while (1) + ; + } + + ret = ThreadStackMgr().InitThreadStack(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("ThreadStackMgr().InitThreadStack() failed"); + while (1) + ; + } +#if CHIP_DEVICE_CONFIG_THREAD_FTD + ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router); +#else + ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); +#endif + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed"); + while (1) + ; + } + + ret = PlatformMgr().StartEventLoopTask(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("PlatformMgr().StartEventLoopTask() failed"); + while (1) + ; + } + + ret = ThreadStackMgrImpl().StartThreadTask(); + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("ThreadStackMgr().StartThreadTask() failed"); + while (1) + ; + } + + // Init ZCL Data Model and start server + PLAT_LOG("Initialize Server"); + static CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + + // Initialize info provider + sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); + SetDeviceInfoProvider(&sExampleDeviceInfoProvider); + + Server::GetInstance().Init(initParams); + + // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#else + SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + + // Initialize LEDs + PLAT_LOG("Initialize LEDs"); + LED_init(); + + LED_Params_init(&ledParams); // default PWM LED + sAppRedHandle = LED_open(CONFIG_LED_RED, &ledParams); + LED_setOff(sAppRedHandle); + + LED_Params_init(&ledParams); // default PWM LED + sAppGreenHandle = LED_open(CONFIG_LED_GREEN, &ledParams); + LED_setOff(sAppGreenHandle); + + // Initialize buttons + PLAT_LOG("Initialize buttons"); + Button_init(); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppLeftHandle = Button_open(CONFIG_BTN_LEFT, &buttonParams); + Button_setCallback(sAppLeftHandle, ButtonLeftEventHandler); + + Button_Params_init(&buttonParams); + buttonParams.buttonEventMask = Button_EV_CLICKED | Button_EV_LONGCLICKED; + buttonParams.longPressDuration = 1000U; // ms + sAppRightHandle = Button_open(CONFIG_BTN_RIGHT, &buttonParams); + Button_setCallback(sAppRightHandle, ButtonRightEventHandler); + + PlatformMgr().LockChipStack(); + { + uint8_t numberOfCredentialsPerUser = 0; + uint16_t numberOfUsers = 0; + uint8_t numberOfWeekdaySchedulesPerUser = 0; + uint8_t numberOfYeardaySchedulesPerUser = 0; + uint8_t numberOfHolidaySchedules = 0; + chip::app::DataModel::Nullable state; + EndpointId endpointId{ 1 }; + + if (!DoorLockServer::Instance().GetNumberOfCredentialsSupportedPerUser(endpointId, numberOfCredentialsPerUser)) + { + numberOfCredentialsPerUser = 5; + } + + if (!DoorLockServer::Instance().GetNumberOfUserSupported(endpointId, numberOfUsers)) + { + numberOfUsers = 10; + } + + if (!DoorLockServer::Instance().GetNumberOfWeekDaySchedulesPerUserSupported(endpointId, numberOfWeekdaySchedulesPerUser)) + { + numberOfWeekdaySchedulesPerUser = 10; + } + + if (!DoorLockServer::Instance().GetNumberOfYearDaySchedulesPerUserSupported(endpointId, numberOfYeardaySchedulesPerUser)) + { + numberOfYeardaySchedulesPerUser = 10; + } + + if (!DoorLockServer::Instance().GetNumberOfHolidaySchedulesSupported(endpointId, numberOfHolidaySchedules)) + { + numberOfHolidaySchedules = 10; + } + + Attributes::LockState::Get(endpointId, state); + ret = LockMgr().Init(state, + CC13X2_26X2DoorLock::LockInitParams::ParamBuilder() + .SetNumberOfUsers(numberOfUsers) + .SetNumberOfCredentialsPerUser(numberOfCredentialsPerUser) + .SetNumberOfWeekdaySchedulesPerUser(numberOfWeekdaySchedulesPerUser) + .SetNumberOfYeardaySchedulesPerUser(numberOfYeardaySchedulesPerUser) + .SetNumberOfHolidaySchedules(numberOfHolidaySchedules) + .GetLockParam()); + + if (state.Value() == DlLockState::kLocked) + { + uiLocked(); + } + else + { + uiUnlocked(); + } + } + + PlatformMgr().UnlockChipStack(); + + if (ret != CHIP_NO_ERROR) + { + PLAT_LOG("LockMgr().Init() failed"); + while (1) + ; + } + + LockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + + ConfigurationMgr().LogDeviceConfig(); + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + InitializeOTARequestor(); +#endif + // QR code will be used with CHIP Tool + PrintOnboardingCodes(RendezvousInformationFlags(RendezvousInformationFlag::kBLE)); + + return 0; +} + +void AppTask::AppTaskMain(void * pvParameter) +{ + AppEvent event; + + sAppTask.Init(); + + LockMgr().ReadConfigValues(); + + while (1) + { + /* Task pend until we have stuff to do */ + if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE) + { + sAppTask.DispatchEvent(&event); + } + } +} + +void AppTask::ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events) +{ + AppEvent event; + event.Type = AppEvent::kEventType_ButtonLeft; + + 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::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::ActionInitiated(LockManager::Action_t aAction) +{ + if (aAction == LockManager::LOCK_ACTION) + { + uiLocking(); + } + else if (aAction == LockManager::UNLOCK_ACTION) + { + uiUnlocking(); + } +} + +void AppTask::ActionCompleted(LockManager::Action_t aAction) +{ + if (aAction == LockManager::LOCK_ACTION) + { + uiLocked(); + } + else if (aAction == LockManager::UNLOCK_ACTION) + { + uiUnlocked(); + } +} + +void AppTask::PostEvent(const AppEvent * aEvent) +{ + if (sAppEventQueue != NULL) + { + BaseType_t status; + if (xPortIsInsideInterrupt()) + { + BaseType_t higherPrioTaskWoken = pdFALSE; + status = xQueueSendFromISR(sAppEventQueue, aEvent, &higherPrioTaskWoken); + +#ifdef portYIELD_FROM_ISR + portYIELD_FROM_ISR(higherPrioTaskWoken); +#elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR + portEND_SWITCHING_ISR(higherPrioTaskWoken); +#else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR +#error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR" +#endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR + } + else + { + status = xQueueSend(sAppEventQueue, aEvent, 1); + } + + if (status != pdTRUE) + { + PLAT_LOG("Failed to post event to app task event queue"); + } + } + else + { + PLAT_LOG("Event Queue is NULL should never happen"); + } +} + +void AppTask::DispatchEvent(AppEvent * aEvent) +{ + switch (aEvent->Type) + { + case AppEvent::kEventType_ButtonLeft: + if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) + { + LockMgr().InitiateAction(LockManager::UNLOCK_ACTION); + } + else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) + { + chip::Server::GetInstance().ScheduleFactoryReset(); + } + break; + + case AppEvent::kEventType_ButtonRight: + if (AppEvent::kAppEventButtonType_Clicked == aEvent->ButtonEvent.Type) + { + LockMgr().InitiateAction(LockManager::LOCK_ACTION); + } + else if (AppEvent::kAppEventButtonType_LongClicked == aEvent->ButtonEvent.Type) + { + // Enable BLE advertisements + if (!ConnectivityMgr().IsBLEAdvertisingEnabled()) + { + if (Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR) + { + PLAT_LOG("Enabled BLE Advertisements"); + } + else + { + PLAT_LOG("OpenBasicCommissioningWindow() failed"); + } + } + else + { + // Disable BLE advertisements + ConnectivityMgr().SetBLEAdvertisingEnabled(false); + PLAT_LOG("Disabled BLE Advertisements"); + } + } + break; + + case AppEvent::kEventType_IdentifyStart: + LED_setOn(sAppGreenHandle, LED_BRIGHTNESS_MAX); + LED_startBlinking(sAppGreenHandle, 500, LED_BLINK_FOREVER); + PLAT_LOG("Identify started"); + break; + + case AppEvent::kEventType_IdentifyStop: + LED_stopBlinking(sAppGreenHandle); + + LED_setOff(sAppGreenHandle); + PLAT_LOG("Identify stopped"); + break; + + case AppEvent::kEventType_AppEvent: + if (NULL != aEvent->Handler) + { + aEvent->Handler(aEvent); + } + break; + + case AppEvent::kEventType_None: + default: + break; + } +} + +void AppTask::IdentifyStartHandler(::Identify *) +{ + AppEvent event; + event.Type = AppEvent::kEventType_IdentifyStart; + sAppTask.PostEvent(&event); +} + +void AppTask::IdentifyStopHandler(::Identify *) +{ + AppEvent event; + event.Type = AppEvent::kEventType_IdentifyStop; + sAppTask.PostEvent(&event); +} + +void AppTask::TriggerIdentifyEffectHandler(::Identify * identify) +{ + switch (identify->mCurrentEffectIdentifier) + { + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK: + PLAT_LOG("Starting blink identifier effect"); + IdentifyStartHandler(identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE: + PLAT_LOG("Breathe identifier effect not implemented"); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY: + PLAT_LOG("Okay identifier effect not implemented"); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE: + PLAT_LOG("Channel Change identifier effect not implemented"); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT: + PLAT_LOG("Finish identifier effect not implemented"); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT: + PLAT_LOG("Stop identifier effect"); + IdentifyStopHandler(identify); + break; + default: + PLAT_LOG("No identifier effect"); + } +} diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h similarity index 60% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppTask.h rename to examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h index 002e1b3f70557c..15939e6581737b 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ b/examples/lock-app/cc13x2x7_26x2x7/src/AppTask.h @@ -16,8 +16,7 @@ * limitations under the License. */ -#ifndef APP_TASK_H -#define APP_TASK_H +#pragma once #include #include @@ -27,22 +26,44 @@ #include "task.h" #include "AppEvent.h" +#include "LockManager.h" #include +// Application-defined error codes in the CHIP_ERROR space. +#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) +#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) +#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03) +#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04) +#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05) +#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06) +#define APP_ERROR_ALLOCATION_FAILED CHIP_APPLICATION_ERROR(0x07) + +struct Identify; + class AppTask { + public: int StartAppTask(); static void AppTaskMain(void * pvParameter); + void PostLockActionRequest(int32_t aActor, LockManager::Action_t aAction); void PostEvent(const AppEvent * event); + static void IdentifyStartHandler(::Identify *); + static void IdentifyStopHandler(::Identify *); + static void TriggerIdentifyEffectHandler(::Identify * identify); + 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(LockManager::Action_t aAction); + static void ActionCompleted(LockManager::Action_t aAction); + void DispatchEvent(AppEvent * event); static void ButtonLeftEventHandler(Button_Handle handle, Button_EventMask events); @@ -60,6 +81,7 @@ class AppTask Function_t mFunction; bool mFunctionTimerActive; + bool mSyncClusterToButtonAction; static AppTask sAppTask; }; @@ -68,5 +90,3 @@ inline AppTask & GetAppTask(void) { return AppTask::sAppTask; } - -#endif // APP_TASK_H diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.cpp b/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.cpp new file mode 100644 index 00000000000000..acd9c00b41c4d5 --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.cpp @@ -0,0 +1,703 @@ +/* + * + * 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 "LockManager.h" + +#include "AppConfig.h" +#include "AppTask.h" +#include "platform/KeyValueStoreManager.h" +#include +#include +#include +#include + +LockManager LockManager::sLock; + +TimerHandle_t sLockTimer; + +using namespace CC13X2_26X2DoorLock::LockInitParams; +using namespace chip::DeviceLayer::PersistedStorage; + +// persisted storage keys +const char LockUser[] = "a/lu"; +const char Credential[] = "a/c"; +const char LockUserName[] = "a/lun"; +const char CredentialData[] = "a/cd"; +const char UserCredentials[] = "a/uc"; +const char WeekDaySchedules[] = "a/wds"; +const char YearDaySchedules[] = "a/yds"; +const char HolidaySchedules[] = "a/hs"; + +CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable state, LockParam lockParam) +{ + + LockParams = lockParam; + + if (LockParams.numberOfUsers > kMaxUsers) + { + PLAT_LOG("Max number of users is greater than %d, the maximum amount of users currently supported on this platform", + kMaxUsers); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfCredentialsPerUser > kMaxCredentialsPerUser) + { + PLAT_LOG("Max number of credentials per user is greater than %d, the maximum amount of users currently supported on this " + "platform", + kMaxCredentialsPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfWeekdaySchedulesPerUser > kMaxWeekdaySchedulesPerUser) + { + PLAT_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxWeekdaySchedulesPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfYeardaySchedulesPerUser > kMaxYeardaySchedulesPerUser) + { + PLAT_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxYeardaySchedulesPerUser); + return APP_ERROR_ALLOCATION_FAILED; + } + + if (LockParams.numberOfHolidaySchedules > kMaxHolidaySchedules) + { + PLAT_LOG("Max number of schedules is greater than %d, the maximum amount of schedules currently supported on this platform", + kMaxHolidaySchedules); + return APP_ERROR_ALLOCATION_FAILED; + } + + // Create FreeRTOS sw timer for lock timer. + sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel + 1, // == default timer period (mS) + false, // no timer reload (==one-shot) + (void *) this, // init timer id = lock obj context + TimerEventHandler // timer callback handler + ); + + if (sLockTimer == NULL) + { + PLAT_LOG("sLockTimer timer create failed"); + return APP_ERROR_CREATE_TIMER_FAILED; + } + + if (state.Value() == DlLockState::kUnlocked) + { + mState = kState_UnlockCompleted; + } + else + { + mState = kState_LockCompleted; + } + + return CHIP_NO_ERROR; +} + +bool LockManager::IsValidUserIndex(uint16_t userIndex) +{ + return (userIndex < kMaxUsers); +} + +bool LockManager::IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type) +{ + if (CredentialTypeEnum::kProgrammingPIN == type) + { + return (0 == credentialIndex); // 0 is required index for Programming PIN + } + return (credentialIndex < kMaxCredentialsPerUser); +} + +bool LockManager::IsValidWeekdayScheduleIndex(uint8_t scheduleIndex) +{ + return (scheduleIndex < kMaxWeekdaySchedulesPerUser); +} + +bool LockManager::IsValidYeardayScheduleIndex(uint8_t scheduleIndex) +{ + return (scheduleIndex < kMaxYeardaySchedulesPerUser); +} + +bool LockManager::IsValidHolidayScheduleIndex(uint8_t scheduleIndex) +{ + return (scheduleIndex < kMaxHolidaySchedules); +} + +bool LockManager::ReadConfigValues() +{ + size_t outLen; + KeyValueStoreMgr().Get(LockUser, reinterpret_cast(&mLockUsers), + sizeof(EmberAfPluginDoorLockUserInfo) * ArraySize(mLockUsers), &outLen); + + KeyValueStoreMgr().Get(Credential, reinterpret_cast(&mLockCredentials), + sizeof(EmberAfPluginDoorLockCredentialInfo) * ArraySize(mLockCredentials), &outLen); + + KeyValueStoreMgr().Get(LockUserName, reinterpret_cast(mUserNames), sizeof(mUserNames), &outLen); + + KeyValueStoreMgr().Get(CredentialData, reinterpret_cast(mCredentialData), sizeof(mCredentialData), &outLen); + + KeyValueStoreMgr().Get(UserCredentials, reinterpret_cast(mCredentials), + sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser, &outLen); + + KeyValueStoreMgr().Get(WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * LockParams.numberOfWeekdaySchedulesPerUser * + LockParams.numberOfUsers, + &outLen); + + KeyValueStoreMgr().Get(YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * LockParams.numberOfYeardaySchedulesPerUser * + LockParams.numberOfUsers, + &outLen); + + KeyValueStoreMgr().Get(HolidaySchedules, reinterpret_cast(&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * LockParams.numberOfHolidaySchedules, &outLen); + + return true; +} + +void LockManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB) +{ + mActionInitiated_CB = aActionInitiated_CB; + mActionCompleted_CB = aActionCompleted_CB; +} + +bool LockManager::InitiateAction(Action_t aAction) +{ + bool action_initiated = false; + State_t new_state; + + // Initiate Turn Lock/Unlock Action only when the previous one is complete. + if (mState == kState_LockCompleted && aAction == UNLOCK_ACTION) + { + action_initiated = true; + + new_state = kState_UnlockInitiated; + } + else if (mState == kState_UnlockCompleted && aAction == LOCK_ACTION) + { + action_initiated = true; + + new_state = kState_LockInitiated; + } + + if (action_initiated) + { + + StartTimer(ACTUATOR_MOVEMENT_PERIOD_MS); + + // Since the timer started successfully, update the state and trigger callback + mState = new_state; + + if (mActionInitiated_CB) + { + mActionInitiated_CB(aAction); + } + } + + return action_initiated; +} + +void LockManager::StartTimer(uint32_t aTimeoutMs) +{ + if (xTimerIsTimerActive(sLockTimer)) + { + PLAT_LOG("app timer already started!"); + CancelTimer(); + } + + // timer is not active, change its period to required value (== restart). + // FreeRTOS- Block for a maximum of 100 ticks if the change period command + // cannot immediately be sent to the timer command queue. + if (xTimerChangePeriod(sLockTimer, pdMS_TO_TICKS(aTimeoutMs), 100) != pdPASS) + { + PLAT_LOG("sLockTimer timer start() failed"); + } +} + +void LockManager::CancelTimer(void) +{ + if (xTimerStop(sLockTimer, 0) == pdFAIL) + { + PLAT_LOG("sLockTimer stop() failed"); + } +} + +void LockManager::TimerEventHandler(TimerHandle_t xTimer) +{ + // Get lock obj context from timer id. + LockManager * lock = static_cast(pvTimerGetTimerID(xTimer)); + + // 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. + AppEvent event; + event.Type = AppEvent::kEventType_AppEvent; + event.BoltLockEvent.Context = lock; + event.Handler = ActuatorMovementTimerEventHandler; + GetAppTask().PostEvent(&event); +} + +void LockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent) +{ + Action_t actionCompleted = INVALID_ACTION; + + LockManager * lock = static_cast(aEvent->BoltLockEvent.Context); + + if (lock->mState == kState_LockInitiated) + { + lock->mState = kState_LockCompleted; + actionCompleted = LOCK_ACTION; + DoorLockServer::Instance().SetLockState(1, DlLockState::kLocked); + } + else if (lock->mState == kState_UnlockInitiated) + { + lock->mState = kState_UnlockCompleted; + actionCompleted = UNLOCK_ACTION; + DoorLockServer::Instance().SetLockState(1, DlLockState::kUnlocked); + } + + if (actionCompleted != INVALID_ACTION) + { + if (lock->mActionCompleted_CB) + { + lock->mActionCompleted_CB(actionCompleted); + } + } +} + +bool LockManager::Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) +{ + return checkPin(endpointId, DlLockState::kLocked, pin, err); +} + +bool LockManager::Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err) +{ + return checkPin(endpointId, DlLockState::kUnlocked, pin, err); +} + +bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) +{ + VerifyOrReturnValue(userIndex > 0, false); // indices are one-indexed + + userIndex--; + + VerifyOrReturnValue(IsValidUserIndex(userIndex), false); + + ChipLogProgress(Zcl, "Door Lock App: LockManager::GetUser [endpoint=%d,userIndex=%hu]", endpointId, userIndex); + + const auto & userInDb = mLockUsers[userIndex]; + + user.userStatus = userInDb.userStatus; + if (UserStatusEnum::kAvailable == user.userStatus) + { + ChipLogDetail(Zcl, "Found unoccupied user [endpoint=%d]", endpointId); + return true; + } + + user.userName = chip::CharSpan(userInDb.userName.data(), userInDb.userName.size()); + user.credentials = chip::Span(mCredentials[userIndex], userInDb.credentials.size()); + user.userUniqueId = userInDb.userUniqueId; + user.userType = userInDb.userType; + user.credentialRule = userInDb.credentialRule; + // So far there's no way to actually create the credential outside Matter, so here we always set the creation/modification + // source to Matter + user.creationSource = DlAssetSource::kMatterIM; + user.createdBy = userInDb.createdBy; + user.modificationSource = DlAssetSource::kMatterIM; + user.lastModifiedBy = userInDb.lastModifiedBy; + + ChipLogDetail(Zcl, + "Found occupied user " + "[endpoint=%d,name=\"%.*s\",credentialsCount=%u,uniqueId=%lx,type=%u,credentialRule=%u," + "createdBy=%d,lastModifiedBy=%d]", + endpointId, static_cast(user.userName.size()), user.userName.data(), user.credentials.size(), + user.userUniqueId, to_underlying(user.userType), to_underlying(user.credentialRule), user.createdBy, + user.lastModifiedBy); + + return true; +} + +bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, + const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype, + CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials) +{ + ChipLogProgress(Zcl, + "Door Lock App: LockManager::SetUser " + "[endpoint=%d,userIndex=%d,creator=%d,modifier=%d,userName=%s,uniqueId=%ld " + "userStatus=%u,userType=%u,credentialRule=%u,credentials=%p,totalCredentials=%u]", + endpointId, userIndex, creator, modifier, userName.data(), uniqueId, to_underlying(userStatus), + to_underlying(usertype), to_underlying(credentialRule), credentials, totalCredentials); + + VerifyOrReturnValue(userIndex > 0, false); // indices are one-indexed + + userIndex--; + + VerifyOrReturnValue(IsValidUserIndex(userIndex), false); + + auto & userInStorage = mLockUsers[userIndex]; + + if (userName.size() > DOOR_LOCK_MAX_USER_NAME_SIZE) + { + ChipLogError(Zcl, "Cannot set user - user name is too long [endpoint=%d,index=%d]", endpointId, userIndex); + return false; + } + + if (totalCredentials > LockParams.numberOfCredentialsPerUser) + { + ChipLogError(Zcl, "Cannot set user - total number of credentials is too big [endpoint=%d,index=%d,totalCredentials=%u]", + endpointId, userIndex, totalCredentials); + return false; + } + + chip::Platform::CopyString(mUserNames[userIndex], userName); + userInStorage.userName = chip::CharSpan(mUserNames[userIndex], userName.size()); + userInStorage.userUniqueId = uniqueId; + userInStorage.userStatus = userStatus; + userInStorage.userType = usertype; + userInStorage.credentialRule = credentialRule; + userInStorage.lastModifiedBy = modifier; + userInStorage.createdBy = creator; + + for (size_t i = 0; i < totalCredentials; ++i) + { + mCredentials[userIndex][i] = credentials[i]; + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; + } + + userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); + + // Save user information in NVM flash + KeyValueStoreMgr().Put(LockUser, reinterpret_cast(&mLockUsers), + sizeof(EmberAfPluginDoorLockUserInfo) * LockParams.numberOfUsers); + + KeyValueStoreMgr().Put(UserCredentials, reinterpret_cast(mCredentials), + sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser); + + KeyValueStoreMgr().Put(LockUserName, reinterpret_cast(mUserNames), sizeof(mUserNames)); + + ChipLogProgress(Zcl, "Successfully set the user [mEndpointId=%d,index=%d]", endpointId, userIndex); + + return true; +} + +bool LockManager::GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, + EmberAfPluginDoorLockCredentialInfo & credential) +{ + + if (CredentialTypeEnum::kProgrammingPIN == credentialType) + { + VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), + false); // programming pin index is only index allowed to contain 0 + } + else + { + VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed + } + + ChipLogProgress(Zcl, "Lock App: LockManager::GetCredential [credentialType=%u], credentialIndex=%d", + to_underlying(credentialType), credentialIndex); + + const auto & credentialInStorage = mLockCredentials[credentialIndex]; + + credential.status = credentialInStorage.status; + ChipLogDetail(Zcl, "CredentialStatus: %d, CredentialIndex: %d ", (int) credential.status, credentialIndex); + + if (DlCredentialStatus::kAvailable == credential.status) + { + ChipLogDetail(Zcl, "Found unoccupied credential "); + return true; + } + credential.credentialType = credentialInStorage.credentialType; + credential.credentialData = credentialInStorage.credentialData; + credential.createdBy = credentialInStorage.createdBy; + credential.lastModifiedBy = credentialInStorage.lastModifiedBy; + // So far there's no way to actually create the credential outside Matter, so here we always set the creation/modification + // source to Matter + credential.creationSource = DlAssetSource::kMatterIM; + credential.modificationSource = DlAssetSource::kMatterIM; + + ChipLogDetail(Zcl, "Found occupied credential [type=%u,dataSize=%u]", to_underlying(credential.credentialType), + credential.credentialData.size()); + + return true; +} + +bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, + chip::FabricIndex modifier, DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType, + const chip::ByteSpan & credentialData) +{ + + if (CredentialTypeEnum::kProgrammingPIN == credentialType) + { + VerifyOrReturnValue(IsValidCredentialIndex(credentialIndex, credentialType), + false); // programming pin index is only index allowed to contain 0 + } + else + { + VerifyOrReturnValue(IsValidCredentialIndex(--credentialIndex, credentialType), false); // otherwise, indices are one-indexed + } + + ChipLogProgress(Zcl, + "Door Lock App: LockManager::SetCredential " + "[credentialStatus=%u,credentialType=%u,credentialDataSize=%u,creator=%d,modifier=%d]", + to_underlying(credentialStatus), to_underlying(credentialType), credentialData.size(), creator, modifier); + + auto & credentialInStorage = mLockCredentials[credentialIndex]; + + credentialInStorage.status = credentialStatus; + credentialInStorage.credentialType = credentialType; + credentialInStorage.createdBy = creator; + credentialInStorage.lastModifiedBy = modifier; + + memcpy(mCredentialData[credentialIndex], credentialData.data(), credentialData.size()); + credentialInStorage.credentialData = chip::ByteSpan{ mCredentialData[credentialIndex], credentialData.size() }; + + // Save credential information in NVM flash + KeyValueStoreMgr().Put(Credential, reinterpret_cast(&mLockCredentials), + sizeof(EmberAfPluginDoorLockCredentialInfo) * LockParams.numberOfCredentialsPerUser); + + KeyValueStoreMgr().Put(CredentialData, reinterpret_cast(&mCredentialData), sizeof(mCredentialData)); + + ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType)); + + return true; +} + +DlStatus LockManager::GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule) +{ + + VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + weekdayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + const auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } + + schedule = scheduleInStorage.schedule; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, + uint8_t endHour, uint8_t endMinute) +{ + + VerifyOrReturnValue(weekdayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + weekdayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidWeekdayScheduleIndex(weekdayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mWeekdaySchedule[userIndex][weekdayIndex]; + + scheduleInStorage.schedule.daysMask = daysMask; + scheduleInStorage.schedule.startHour = startHour; + scheduleInStorage.schedule.startMinute = startMinute; + scheduleInStorage.schedule.endHour = endHour; + scheduleInStorage.schedule.endMinute = endMinute; + scheduleInStorage.status = status; + + // Save schedule information in NVM flash + KeyValueStoreMgr().Put(WeekDaySchedules, reinterpret_cast(mWeekdaySchedule), + sizeof(EmberAfPluginDoorLockWeekDaySchedule) * LockParams.numberOfWeekdaySchedulesPerUser * + LockParams.numberOfUsers); + + return DlStatus::kSuccess; +} + +DlStatus LockManager::GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule) +{ + VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + yearDayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + const auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } + + schedule = scheduleInStorage.schedule; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) +{ + VerifyOrReturnValue(yearDayIndex > 0, DlStatus::kFailure); // indices are one-indexed + VerifyOrReturnValue(userIndex > 0, DlStatus::kFailure); // indices are one-indexed + + yearDayIndex--; + userIndex--; + + VerifyOrReturnValue(IsValidYeardayScheduleIndex(yearDayIndex), DlStatus::kFailure); + VerifyOrReturnValue(IsValidUserIndex(userIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mYeardaySchedule[userIndex][yearDayIndex]; + + scheduleInStorage.schedule.localStartTime = localStartTime; + scheduleInStorage.schedule.localEndTime = localEndTime; + scheduleInStorage.status = status; + + // Save schedule information in NVM flash + KeyValueStoreMgr().Put(YearDaySchedules, reinterpret_cast(mYeardaySchedule), + sizeof(EmberAfPluginDoorLockYearDaySchedule) * LockParams.numberOfYeardaySchedulesPerUser * + LockParams.numberOfUsers); + + return DlStatus::kSuccess; +} + +DlStatus LockManager::GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, + EmberAfPluginDoorLockHolidaySchedule & schedule) +{ + VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed + + holidayIndex--; + + VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure); + + const auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + if (DlScheduleStatus::kAvailable == scheduleInStorage.status) + { + return DlStatus::kNotFound; + } + + schedule = scheduleInStorage.schedule; + + return DlStatus::kSuccess; +} + +DlStatus LockManager::SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode) +{ + VerifyOrReturnValue(holidayIndex > 0, DlStatus::kFailure); // indices are one-indexed + + holidayIndex--; + + VerifyOrReturnValue(IsValidHolidayScheduleIndex(holidayIndex), DlStatus::kFailure); + + auto & scheduleInStorage = mHolidaySchedule[holidayIndex]; + + scheduleInStorage.schedule.localStartTime = localStartTime; + scheduleInStorage.schedule.localEndTime = localEndTime; + scheduleInStorage.schedule.operatingMode = operatingMode; + scheduleInStorage.status = status; + + // Save schedule information in NVM flash + KeyValueStoreMgr().Put(HolidaySchedules, reinterpret_cast(&(mHolidaySchedule)), + sizeof(EmberAfPluginDoorLockHolidaySchedule) * LockParams.numberOfHolidaySchedules); + + return DlStatus::kSuccess; +} + +const char * LockManager::lockStateToString(DlLockState lockState) const +{ + switch (lockState) + { + case DlLockState::kNotFullyLocked: + return "Not Fully Locked"; + case DlLockState::kLocked: + return "Locked"; + case DlLockState::kUnlocked: + return "Unlocked"; + case DlLockState::kUnknownEnumValue: + break; + } + + return "Unknown"; +} + +bool LockManager::checkPin(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, + OperationErrorEnum & err) +{ + // Assume pin is required until told otherwise + bool requirePin = true; + chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(endpointId, &requirePin); + + // If a pin code is not given + if (!pin.HasValue()) + { + ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified [endpointId=%d]", endpointId); + + // If a pin code is not required + if (!requirePin) + { + ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState), + endpointId); + + return true; + } + + ChipLogError(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", endpointId); + + err = OperationErrorEnum::kInvalidCredential; + DoorLockServer::Instance().HandleWrongCodeEntry(endpointId); + return false; + } + + // Check the PIN code + for (uint8_t i = 0; i < kMaxCredentials; i++) + { + if (mLockCredentials[i].credentialType != CredentialTypeEnum::kPin || + mLockCredentials[i].status == DlCredentialStatus::kAvailable) + { + continue; + } + + if (mLockCredentials[i].credentialData.data_equal(pin.Value())) + { + ChipLogDetail(Zcl, + "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]", + lockStateToString(lockState), endpointId); + + return true; + } + } + + ChipLogDetail(Zcl, + "Door Lock App: specified PIN code was not found in the database, ignoring command to set lock state to \"%s\" " + "[endpointId=%d]", + lockStateToString(lockState), endpointId); + + err = OperationErrorEnum::kInvalidCredential; + DoorLockServer::Instance().HandleWrongCodeEntry(endpointId); + return false; +} diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.h b/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.h new file mode 100644 index 00000000000000..74129260bd9172 --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/src/LockManager.h @@ -0,0 +1,221 @@ +/* + * + * 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. + */ + +#pragma once + +#include + +#include +#include + +#include "AppEvent.h" + +#include "FreeRTOS.h" +#include "timers.h" // provides FreeRTOS timer support + +#include + +struct WeekDaysScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockWeekDaySchedule schedule; +}; + +struct YearDayScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockYearDaySchedule schedule; +}; + +struct HolidayScheduleInfo +{ + DlScheduleStatus status; + EmberAfPluginDoorLockHolidaySchedule schedule; +}; + +namespace CC13X2_26X2DoorLock { +namespace ResourceRanges { +// Used to size arrays +static constexpr uint16_t kMaxUsers = 10; +static constexpr uint8_t kMaxCredentialsPerUser = 10; +static constexpr uint8_t kMaxWeekdaySchedulesPerUser = 10; +static constexpr uint8_t kMaxYeardaySchedulesPerUser = 10; +static constexpr uint8_t kMaxHolidaySchedules = 10; +static constexpr uint8_t kMaxCredentialSize = 8; + +// Indices received for user/credential/schedules are 1-indexed +static constexpr uint8_t kStartIndexValue = 1; + +static constexpr uint8_t kMaxCredentials = kMaxUsers * kMaxCredentialsPerUser; +} // namespace ResourceRanges + +namespace LockInitParams { + +struct LockParam +{ + // Read from zap attributes + uint16_t numberOfUsers = 0; + uint8_t numberOfCredentialsPerUser = 0; + uint8_t numberOfWeekdaySchedulesPerUser = 0; + uint8_t numberOfYeardaySchedulesPerUser = 0; + uint8_t numberOfHolidaySchedules = 0; +}; + +class ParamBuilder +{ +public: + ParamBuilder & SetNumberOfUsers(uint16_t numberOfUsers) + { + lockParam_.numberOfUsers = numberOfUsers; + return *this; + } + ParamBuilder & SetNumberOfCredentialsPerUser(uint8_t numberOfCredentialsPerUser) + { + lockParam_.numberOfCredentialsPerUser = numberOfCredentialsPerUser; + return *this; + } + ParamBuilder & SetNumberOfWeekdaySchedulesPerUser(uint8_t numberOfWeekdaySchedulesPerUser) + { + lockParam_.numberOfWeekdaySchedulesPerUser = numberOfWeekdaySchedulesPerUser; + return *this; + } + ParamBuilder & SetNumberOfYeardaySchedulesPerUser(uint8_t numberOfYeardaySchedulesPerUser) + { + lockParam_.numberOfYeardaySchedulesPerUser = numberOfYeardaySchedulesPerUser; + return *this; + } + ParamBuilder & SetNumberOfHolidaySchedules(uint8_t numberOfHolidaySchedules) + { + lockParam_.numberOfHolidaySchedules = numberOfHolidaySchedules; + return *this; + } + LockParam GetLockParam() { return lockParam_; } + +private: + LockParam lockParam_; +}; + +} // namespace LockInitParams +} // namespace CC13X2_26X2DoorLock + +using namespace ::chip; +using namespace CC13X2_26X2DoorLock::ResourceRanges; + +class LockManager +{ +public: + enum Action_t + { + LOCK_ACTION = 0, + UNLOCK_ACTION, + + INVALID_ACTION + } Action; + + enum State_t + { + kState_LockInitiated = 0, + kState_LockCompleted, + kState_UnlockInitiated, + kState_UnlockCompleted, + } State; + + CHIP_ERROR Init(chip::app::DataModel::Nullable state, + CC13X2_26X2DoorLock::LockInitParams::LockParam lockParam); + bool InitiateAction(Action_t aAction); + + typedef void (*Callback_fn_initiated)(Action_t); + typedef void (*Callback_fn_completed)(Action_t); + void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB); + + bool Lock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); + bool Unlock(chip::EndpointId endpointId, const Optional & pin, OperationErrorEnum & err); + + bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user); + bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, + const chip::CharSpan & userName, uint32_t uniqueId, UserStatusEnum userStatus, UserTypeEnum usertype, + CredentialRuleEnum credentialRule, const CredentialStruct * credentials, size_t totalCredentials); + + bool GetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, + EmberAfPluginDoorLockCredentialInfo & credential); + + bool SetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, chip::FabricIndex modifier, + DlCredentialStatus credentialStatus, CredentialTypeEnum credentialType, + const chip::ByteSpan & credentialData); + + DlStatus GetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule); + + DlStatus SetWeekdaySchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, DlScheduleStatus status, + DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, uint8_t endHour, uint8_t endMinute); + + DlStatus GetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule); + + DlStatus SetYeardaySchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime); + + DlStatus GetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, EmberAfPluginDoorLockHolidaySchedule & schedule); + + DlStatus SetHolidaySchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, uint32_t localStartTime, + uint32_t localEndTime, OperatingModeEnum operatingMode); + + bool IsValidUserIndex(uint16_t userIndex); + bool IsValidCredentialIndex(uint16_t credentialIndex, CredentialTypeEnum type); + bool IsValidWeekdayScheduleIndex(uint8_t scheduleIndex); + bool IsValidYeardayScheduleIndex(uint8_t scheduleIndex); + bool IsValidHolidayScheduleIndex(uint8_t scheduleIndex); + + bool checkPin(chip::EndpointId endpointId, DlLockState lockState, const Optional & pin, + OperationErrorEnum & err); + const char * lockStateToString(DlLockState lockState) const; + + bool ReadConfigValues(); + +private: + friend LockManager & LockMgr(); + State_t mState; + + Callback_fn_initiated mActionInitiated_CB; + Callback_fn_completed mActionCompleted_CB; + + void CancelTimer(void); + void StartTimer(uint32_t aTimeoutMs); + + static void TimerEventHandler(TimerHandle_t xTimer); + static void AutoLockTimerEventHandler(AppEvent * aEvent); + static void ActuatorMovementTimerEventHandler(AppEvent * aEvent); + + EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers]; + EmberAfPluginDoorLockCredentialInfo mLockCredentials[kMaxCredentials]; + WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser]; + YearDayScheduleInfo mYeardaySchedule[kMaxUsers][kMaxYeardaySchedulesPerUser]; + HolidayScheduleInfo mHolidaySchedule[kMaxHolidaySchedules]; + + char mUserNames[ArraySize(mLockUsers)][DOOR_LOCK_MAX_USER_NAME_SIZE]; + uint8_t mCredentialData[kMaxCredentials][kMaxCredentialSize]; + CredentialStruct mCredentials[kMaxUsers][kMaxCredentialsPerUser]; + + static LockManager sLock; + CC13X2_26X2DoorLock::LockInitParams::LockParam LockParams; +}; + +inline LockManager & LockMgr() +{ + return LockManager::sLock; +} diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp b/examples/lock-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp new file mode 100644 index 00000000000000..0fb673f020c5c5 --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/src/ZclCallbacks.cpp @@ -0,0 +1,149 @@ +/* + * + * 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 + * This file implements the handler for data model messages. + */ + +#include "AppConfig.h" +#include "LockManager.h" +#include + +#include +#include +#include +#include + +using namespace ::chip::app::Clusters; +using namespace ::chip::DeviceLayer::Internal; + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, + uint8_t * value) +{ + ClusterId clusterId = attributePath.mClusterId; + AttributeId attributeId = attributePath.mAttributeId; + ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); + + if (clusterId == DoorLock::Id && attributeId == DoorLock::Attributes::LockState::Id) + { + ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); + } +} + +/** @brief DoorLock 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 + * + */ +void emberAfDoorLockClusterInitCallback(EndpointId endpoint) {} + +bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional & pinCode, + OperationErrorEnum & err) +{ + ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId); + bool status = LockMgr().Lock(endpointId, pinCode, err); + if (status == true) + { + LockMgr().InitiateAction(LockManager::LOCK_ACTION); + } + return status; +} + +bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional & pinCode, + OperationErrorEnum & err) +{ + ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId); + bool status = LockMgr().Unlock(endpointId, pinCode, err); + if (status == true) + { + LockMgr().InitiateAction(LockManager::UNLOCK_ACTION); + } + + return status; +} + +bool emberAfPluginDoorLockGetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, CredentialTypeEnum credentialType, + EmberAfPluginDoorLockCredentialInfo & credential) +{ + return LockMgr().GetCredential(endpointId, credentialIndex, credentialType, credential); +} + +bool emberAfPluginDoorLockSetCredential(chip::EndpointId endpointId, uint16_t credentialIndex, chip::FabricIndex creator, + chip::FabricIndex modifier, DlCredentialStatus credentialStatus, + CredentialTypeEnum credentialType, const chip::ByteSpan & credentialData) +{ + return LockMgr().SetCredential(endpointId, credentialIndex, creator, modifier, credentialStatus, credentialType, + credentialData); +} + +bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) +{ + return LockMgr().GetUser(endpointId, userIndex, user); +} + +bool emberAfPluginDoorLockSetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, + chip::FabricIndex modifier, const chip::CharSpan & userName, uint32_t uniqueId, + UserStatusEnum userStatus, UserTypeEnum usertype, CredentialRuleEnum credentialRule, + const CredentialStruct * credentials, size_t totalCredentials) +{ + + return LockMgr().SetUser(endpointId, userIndex, creator, modifier, userName, uniqueId, userStatus, usertype, credentialRule, + credentials, totalCredentials); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + EmberAfPluginDoorLockWeekDaySchedule & schedule) +{ + return LockMgr().GetWeekdaySchedule(endpointId, weekdayIndex, userIndex, schedule); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + EmberAfPluginDoorLockYearDaySchedule & schedule) +{ + return LockMgr().GetYeardaySchedule(endpointId, yearDayIndex, userIndex, schedule); +} + +DlStatus emberAfPluginDoorLockGetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, + EmberAfPluginDoorLockHolidaySchedule & holidaySchedule) +{ + return LockMgr().GetHolidaySchedule(endpointId, holidayIndex, holidaySchedule); +} + +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t weekdayIndex, uint16_t userIndex, + DlScheduleStatus status, DaysMaskMap daysMask, uint8_t startHour, uint8_t startMinute, + uint8_t endHour, uint8_t endMinute) +{ + return LockMgr().SetWeekdaySchedule(endpointId, weekdayIndex, userIndex, status, daysMask, startHour, startMinute, endHour, + endMinute); +} + +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t yearDayIndex, uint16_t userIndex, + DlScheduleStatus status, uint32_t localStartTime, uint32_t localEndTime) +{ + return LockMgr().SetYeardaySchedule(endpointId, yearDayIndex, userIndex, status, localStartTime, localEndTime); +} + +DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t holidayIndex, DlScheduleStatus status, + uint32_t localStartTime, uint32_t localEndTime, OperatingModeEnum operatingMode) +{ + return LockMgr().SetHolidaySchedule(endpointId, holidayIndex, status, localStartTime, localEndTime, operatingMode); +} diff --git a/examples/lock-app/cc13x2x7_26x2x7/src/main.cpp b/examples/lock-app/cc13x2x7_26x2x7/src/main.cpp new file mode 100644 index 00000000000000..4fdb88703acab6 --- /dev/null +++ b/examples/lock-app/cc13x2x7_26x2x7/src/main.cpp @@ -0,0 +1,105 @@ +/* + * + * 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 "AppConfig.h" +#include "AppTask.h" + +#include + +/* Driver Header files */ +#include +#include +#include + +#include +#include +#include +#include + +#include +#define TOTAL_ICALL_HEAP_SIZE (0xc600) + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::DeviceLayer; + +__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) + { + ; + } +} + +/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */ +extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +extern "C" void vQueueUnregisterQueueWrapper(QueueHandle_t xQueue) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +// ================================================================================ +// Main Code +// ================================================================================ +int main(void) +{ + Board_init(); + bpool((void *) GlobalHeapZoneBuffer, TOTAL_ICALL_HEAP_SIZE); + + GPIO_init(); + + NVS_init(); + + ECDH_init(); + + ECDSA_init(); + + AESECB_init(); + + SHA2_init(); + + 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/persistent-storage/cc13x2x7_26x2x7/chip.syscfg b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg index b2409535110003..995ad22af6b435 100644 --- a/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg @@ -22,16 +22,14 @@ 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 RFCustom = scripting.addModule("/ti/devices/radioconfig/custom"); 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 UART2 = scripting.addModule("/ti/drivers/UART2"); var ble = scripting.addModule("/ti/ble5stack/ble"); var dmm = scripting.addModule("/ti/dmm/dmm"); var AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); @@ -43,20 +41,19 @@ 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 NVS2 = 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 = UART2.addInstance(); var AESCTRDRBG1 = AESCTRDRBG.addInstance(); var ECDH1 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; -AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; AESCCM1.$name = "CONFIG_AESCCM0"; @@ -65,9 +62,6 @@ AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -/* RTOS */ -RTOS.name = "FreeRTOS"; - /* Left Button */ Button1.$name = "CONFIG_BTN_LEFT"; Button1.$hardware = system.deviceData.board.components["BTN-1"]; @@ -84,23 +78,24 @@ Button2.gpioPin.interruptTrigger = "Falling Edge"; /* ======== 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"; -} +// Disable CCFG generation, this is added by the BIM project +CCFG.enableCodeGeneration = false; + /* NVS */ NVS1.$name = "CONFIG_NVSINTERNAL"; NVS1.internalFlash.regionBase = 0xAA000; NVS1.internalFlash.regionSize = 0x4000; +NVS2.$name = "CONFIG_NVSEXTERNAL"; +NVS2.nvsType = "External"; // NVS Region Type +NVS2.$hardware = system.deviceData.board.components.MX25R8035F; + /* RF */ /* if an antenna component exists, assign it to the rf instance */ if (system.deviceData.board && system.deviceData.board.components.RF) { @@ -113,6 +108,58 @@ for(var setting in rfDesignSettings) RFDesign[setting] = rfDesignSettings[setting]; } +/* Handling for RF frontend characterization */ +if(RFDesign.rfDesign.match(/LP_CC2652PSIP/)) +{ + RFCustom.ieee = ["ieee154p10"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154p10.codeExportConfig +} +else +{ + RFCustom.ieee = ["ieee154"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154.codeExportConfig +} + +var cmdList = [ + "cmdIeeeTx", + "cmdIeeeRx", + "cmdIeeeCsma", + "cmdIeeeEdScan", + "cmdIeeeRxAck", + "cmdTxTest" +]; + +rfCodeExportConfig.useConst = true; +rfCodeExportConfig.useMulti = true; +rfCodeExportConfig.symGenMethod = "Custom"; + +const deviceId = system.deviceData.deviceId; + +// Add high PA options if present +if(deviceId.match(/CC(265[12]R|2674R|1352R1|1354R)/)) +{ + cmdList.push("cmdRadioSetup"); + rfCodeExportConfig.cmdRadioSetup = "RF_cmdIeeeRadioSetup"; +} +else if(deviceId.match(/CC(265[12]P|2674P|1352P)/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + rfCodeExportConfig.paExport = "combined"; +} +else if(deviceId.match(/CC(265[34]|1354)P/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + // currently not characterized for high PA +} +else +{ + throw new Error("Could not match platform to any known platform types"); +} + +rfCodeExportConfig.cmdList_ieee_15_4 = cmdList; + /* Red LED */ LED1.$name = "CONFIG_LED_RED"; LED1.$hardware = system.deviceData.board.components.LED_RED; @@ -128,16 +175,14 @@ LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; /* Debug UART */ -UART1.$hardware = system.deviceData.board.components.XDS110UART; -UART1.$name = "CONFIG_UART_DEBUG"; +UART2.$hardware = system.deviceData.board.components.XDS110UART; +UART2.$name = "CONFIG_UART2_DEBUG"; /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; -TRNG2.$name = "CONFIG_TRNG_1"; +TRNG2.$name = "CONFIG_TRNG_THREAD"; TRNG3.$name = "CONFIG_TRNG_APP"; -RTOS.name = "FreeRTOS"; - /* BLE */ ble.addressMode = "ADDRMODE_RP_WITH_PUBLIC_ID"; ble.maxConnNum = 1; @@ -145,15 +190,14 @@ ble.numOfAdvSets = 1; ble.lockProject = true; ble.oneLibSizeOpt = true; ble.maxPDUSize = 255; -ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param1"; +ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param2"; 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"; diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h b/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h index 3cead418532caa..77f2cc37421d36 100644 --- a/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h +++ b/examples/persistent-storage/cc13x2x7_26x2x7/include/AppConfig.h @@ -1,6 +1,5 @@ /* * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/platform/cc13x2_26x2/BUILD.gn b/examples/platform/cc13x2_26x2/BUILD.gn index 619ecdfa446dc5..06beceb9d75d01 100644 --- a/examples/platform/cc13x2_26x2/BUILD.gn +++ b/examples/platform/cc13x2_26x2/BUILD.gn @@ -14,6 +14,15 @@ import("//build_overrides/chip.gni") +config("chip_examples_project_config") { + include_dirs = [ "project_include" ] +} + +source_set("openthread_core_config_cc13x2_26x2_chip_examples") { + sources = [ "project_include/OpenThreadConfig.h" ] + public_configs = [ ":chip_examples_project_config" ] +} + config("attestation-credentials-config") { include_dirs = [ "${chip_root}" ] diff --git a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp index 9e39a54c263668..ddde42c932d590 100644 --- a/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp +++ b/examples/platform/cc13x2_26x2/CC13X2_26X2DeviceAttestationCreds.cpp @@ -15,8 +15,6 @@ * limitations under the License. */ #include "CC13X2_26X2DeviceAttestationCreds.h" -#include -#include #include #include #include @@ -30,6 +28,10 @@ namespace CC13X2_26X2 { namespace { +extern "C" { + +extern void cc13x2_26x2Log(const char * aFormat, ...); + typedef struct { const uint32_t len; @@ -127,6 +129,8 @@ const factoryData gFactoryData = { }, }; +} // extern "C" + CHIP_ERROR LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public_key, Crypto::P256Keypair & keypair) { Crypto::P256SerializedKeypair serialized_keypair; diff --git a/examples/platform/cc13x2_26x2/args.gni b/examples/platform/cc13x2_26x2/args.gni index 7d18cc869d4831..ff1f8159857fc6 100644 --- a/examples/platform/cc13x2_26x2/args.gni +++ b/examples/platform/cc13x2_26x2/args.gni @@ -14,10 +14,10 @@ import("//build_overrides/chip.gni") -import("${chip_root}/src/platform/cc13x2_26x2/args.gni") +import("${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/args.gni") openthread_config_file = "" -openthread_core_config_deps = [] +openthread_core_config_deps = [ "${chip_root}/examples/platform/cc13x2_26x2:openthread_core_config_cc13x2_26x2_chip_examples" ] chip_ble_project_config_include = "" chip_device_project_config_include = "" diff --git a/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h b/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h new file mode 100644 index 00000000000000..7747508d80bfdb --- /dev/null +++ b/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h @@ -0,0 +1,98 @@ +/* + * + * 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. + */ + +/** + * @file + * Overrides to default OpenThread configuration. + * + */ + +#pragma once + +#ifdef DeviceFamily_CC13X2_CC26X2 + +/* Number of message buffers reduced to fit into CC26x2x3 RAM */ +#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 + +#endif // DeviceFamily_CC13X2_CC26X2 + +#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_HEAP_EXTERNAL_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 +#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE 1 + +#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0 +#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0 +#define OPENTHREAD_CONFIG_JOINER_ENABLE 0 + +#define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS 0 +// TCP disabled until OpenThread has a GN/Ninja build for the tcplp library +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 + +#define OPENTHREAD_CONFIG_THREAD_VERSION OT_THREAD_VERSION_1_3 + +//#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 1 +//#define OPENTHREAD_CONFIG_COAP_API_ENABLE 1 +#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0 +#define OPENTHREAD_CONFIG_COAP_API_ENABLE 0 +#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 0 +#define OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_DIAG_ENABLE 0 +#define OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_DUA_ENABLE 1 +#define OPENTHREAD_CONFIG_LINK_RAW_ENABLE 1 +#define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 1 +#define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE 1 +#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 0 +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 1 +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 1 +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 1 +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1 +#define OPENTHREAD_CONFIG_MLR_ENABLE 1 +#define OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE 1 +#define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE 1 +#define OPENTHREAD_CONFIG_SRP_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 1 + +// Use the TI-supplied default platform configuration for remainder +#include "openthread-core-cc13xx_cc26xx-config.h" diff --git a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn index 7eadbc73e8c4a9..5a9aed051d28fc 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/pump-app/cc13x2x7_26x2x7/BUILD.gn @@ -36,7 +36,6 @@ ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", diff --git a/examples/pump-app/cc13x2x7_26x2x7/args.gni b/examples/pump-app/cc13x2x7_26x2x7/args.gni index 8baf8977c88bb2..aeeb0708a235e7 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/args.gni +++ b/examples/pump-app/cc13x2x7_26x2x7/args.gni @@ -29,10 +29,12 @@ lwip_debug = false chip_enable_ota_requestor = true +openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2" + # Disable CHIP Logging #chip_progress_logging = false -#chip_detail_logging = false -#chip_automation_logging = false +chip_detail_logging = false +chip_automation_logging = false # BLE options chip_config_network_layer_ble = true diff --git a/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg b/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg index 6bbd36becbf9cc..995ad22af6b435 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/pump-app/cc13x2x7_26x2x7/chip.syscfg @@ -17,159 +17,51 @@ * limitations under the License. */ -/** - * These arguments were used when this file was generated. They will be automatically applied on subsequent loads - * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. - * @cliArgs --board "/ti/boards/CC26X2R1_LAUNCHXL" --product "simplelink_cc13x2_26x2_sdk@4.40.05.02_eng" - * @versions {"tool":"1.9.0+2015","templates":null} - */ - -/** - * Import the modules used in this configuration. - */ -const ble = scripting.addModule("/ti/ble5stack/ble"); -const CCFG = scripting.addModule("/ti/devices/CCFG"); -const rfdesign = scripting.addModule("/ti/devices/radioconfig/rfdesign"); -const dmm = scripting.addModule("/ti/dmm/dmm"); -const AESCCM = scripting.addModule("/ti/drivers/AESCCM"); -const AESCCM1 = AESCCM.addInstance(); -const AESCCM2 = AESCCM.addInstance(); -const AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); -const AESCTRDRBG1 = AESCTRDRBG.addInstance(); -const AESECB = scripting.addModule("/ti/drivers/AESECB"); -const AESECB1 = AESECB.addInstance(); -const AESECB2 = AESECB.addInstance(); -const ECDH = scripting.addModule("/ti/drivers/ECDH"); -const ECDH1 = ECDH.addInstance(); -const ECDH2 = ECDH.addInstance(); -const NVS = scripting.addModule("/ti/drivers/NVS"); -const NVS1 = NVS.addInstance(); -const NVS2 = NVS.addInstance(); -const RF = scripting.addModule("/ti/drivers/RF"); -const RTOS = scripting.addModule("/ti/drivers/RTOS"); -const SHA2 = scripting.addModule("/ti/drivers/SHA2"); -const SHA21 = SHA2.addInstance(); -const TRNG = scripting.addModule("/ti/drivers/TRNG"); -const TRNG1 = TRNG.addInstance(); -const TRNG2 = TRNG.addInstance(); -const TRNG3 = TRNG.addInstance(); -const UART = scripting.addModule("/ti/drivers/UART"); -const UART1 = UART.addInstance(); -const UART2 = UART.addInstance(); -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 thread = scripting.addModule("/ti/thread/thread"); - -/** - * Write custom configuration values to the imported modules. - */ -ble.maxConnNum = 1; -ble.numOfAdvSets = 1; -ble.lockProject = 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.advData1.$name = "ti_ble5stack_broadcaster_advertisement_data0"; -ble.advSet1.scanRes1.$name = "ti_ble5stack_broadcaster_advertisement_data1"; - -CCFG.enableBootloader = true; -CCFG.enableBootloaderBackdoor = true; -CCFG.dioBootloaderBackdoor = 13; -CCFG.levelBootloaderBackdoor = "Active low"; -CCFG.srcClkLF = "Derived from HF XOSC"; -CCFG.ccfgTemplate.$name = "ti_devices_CCFGTemplate0"; - -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; -AESCCM1.$name = "CONFIG_AESCCM0"; - -AESCCM2.$name = "CONFIG_AESCCM_1"; +/* Modules */ +var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); +var AESECB = scripting.addModule("/ti/drivers/AESECB"); +var Button = scripting.addModule("/ti/drivers/apps/Button"); +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 RFCustom = scripting.addModule("/ti/devices/radioconfig/custom"); +var TRNG = scripting.addModule("/ti/drivers/TRNG"); +var SHA2 = scripting.addModule("/ti/drivers/SHA2"); +var UART2 = scripting.addModule("/ti/drivers/UART2"); +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 AESECB1 = AESECB.addInstance(); +var AESECB2 = AESECB.addInstance(); +var Button1 = Button.addInstance(); +var Button2 = Button.addInstance(); +var NVS1 = NVS.addInstance(); +var NVS2 = 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 UART2 = UART2.addInstance(); +var AESCTRDRBG1 = AESCTRDRBG.addInstance(); +var ECDH1 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; -AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; -AESECB1.$name = "CONFIG_AESECB0"; +AESCCM1.$name = "CONFIG_AESCCM0"; +AESECB1.$name = "CONFIG_AESECB0"; AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -ECDH2.$name = "CONFIG_ECDH_1"; - -NVS1.$name = "CONFIG_NVSINTERNAL"; -NVS1.internalFlash.$name = "ti_drivers_nvs_NVSCC26XX0"; -NVS1.internalFlash.regionBase = 0xAA000; -NVS1.internalFlash.regionSize = 0x4000; - -NVS2.$name = "CONFIG_NVSEXTERNAL"; -NVS2.nvsType = "External"; // NVS Region Type -NVS2.$hardware = system.deviceData.board.components.MX25R8035F; - -RTOS.name = "FreeRTOS"; - -SHA21.$name = "CONFIG_SHA2_0"; - -TRNG1.$name = "CONFIG_TRNG_0"; - -TRNG2.$name = "CONFIG_TRNG_1"; - -TRNG3.$name = "CONFIG_TRNG_APP"; - -UART1.$name = "CONFIG_UART_DEBUG"; -UART1.uart.$assign = "UART1"; -UART1.uart.txPin.$assign = "boosterpack.4"; -UART1.uart.rxPin.$assign = "boosterpack.3"; -UART1.txPinInstance.$name = "CONFIG_PIN_4"; -UART1.rxPinInstance.$name = "CONFIG_PIN_5"; - -UART2.$name = "CONFIG_DISPLAY_UART"; -UART2.txPinInstance.$name = "CONFIG_PIN_6"; -UART2.rxPinInstance.$name = "CONFIG_PIN_7"; - - /* Left Button */ Button1.$name = "CONFIG_BTN_LEFT"; Button1.$hardware = system.deviceData.board.components["BTN-1"]; @@ -184,6 +76,90 @@ Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; Button2.gpioPin.pull = "Pull Up"; Button2.gpioPin.interruptTrigger = "Falling Edge"; +/* ======== CCFG ======== */ +var CCFG = scripting.addModule("/ti/devices/CCFG"); +const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings; +for(var setting in ccfgSettings) +{ + CCFG[setting] = ccfgSettings[setting]; +} + +// Disable CCFG generation, this is added by the BIM project +CCFG.enableCodeGeneration = false; + +/* NVS */ +NVS1.$name = "CONFIG_NVSINTERNAL"; +NVS1.internalFlash.regionBase = 0xAA000; +NVS1.internalFlash.regionSize = 0x4000; + +NVS2.$name = "CONFIG_NVSEXTERNAL"; +NVS2.nvsType = "External"; // NVS Region Type +NVS2.$hardware = system.deviceData.board.components.MX25R8035F; + +/* RF */ +/* 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]; +} + +/* Handling for RF frontend characterization */ +if(RFDesign.rfDesign.match(/LP_CC2652PSIP/)) +{ + RFCustom.ieee = ["ieee154p10"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154p10.codeExportConfig +} +else +{ + RFCustom.ieee = ["ieee154"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154.codeExportConfig +} + +var cmdList = [ + "cmdIeeeTx", + "cmdIeeeRx", + "cmdIeeeCsma", + "cmdIeeeEdScan", + "cmdIeeeRxAck", + "cmdTxTest" +]; + +rfCodeExportConfig.useConst = true; +rfCodeExportConfig.useMulti = true; +rfCodeExportConfig.symGenMethod = "Custom"; + +const deviceId = system.deviceData.deviceId; + +// Add high PA options if present +if(deviceId.match(/CC(265[12]R|2674R|1352R1|1354R)/)) +{ + cmdList.push("cmdRadioSetup"); + rfCodeExportConfig.cmdRadioSetup = "RF_cmdIeeeRadioSetup"; +} +else if(deviceId.match(/CC(265[12]P|2674P|1352P)/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + rfCodeExportConfig.paExport = "combined"; +} +else if(deviceId.match(/CC(265[34]|1354)P/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + // currently not characterized for high PA +} +else +{ + throw new Error("Could not match platform to any known platform types"); +} + +rfCodeExportConfig.cmdList_ieee_15_4 = cmdList; + /* Red LED */ LED1.$name = "CONFIG_LED_RED"; LED1.$hardware = system.deviceData.board.components.LED_RED; @@ -198,19 +174,65 @@ LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; -thread.deviceTypeReadOnly = true; -thread.pm.$name = "ti_thread_pm_thread_pm0"; -thread.rf.$name = "ti_thread_rf_thread_rf0"; -thread.rf.radioConfig.$name = "ti_devices_radioconfig_settings_ieee_15_40"; -thread.rf.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param0"; -thread.network.$name = "ti_thread_network_thread_network0"; -thread.security.$name = "ti_thread_security_thread_security0"; - -/** - * 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. - */ -UART2.uart.$suggestSolution = "UART0"; -UART2.uart.txPin.$suggestSolution = "boosterpack.30"; -UART2.uart.rxPin.$suggestSolution = "boosterpack.29"; +/* Debug UART */ +UART2.$hardware = system.deviceData.board.components.XDS110UART; +UART2.$name = "CONFIG_UART2_DEBUG"; + +/* TRNG */ +TRNG1.$name = "CONFIG_TRNG_0"; +TRNG2.$name = "CONFIG_TRNG_THREAD"; +TRNG3.$name = "CONFIG_TRNG_APP"; + +/* 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_param2"; +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"; + +/* 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/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index 5eb903e6ca0688..4514cd7cd8b8d8 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #endif #include #include @@ -135,7 +135,7 @@ int AppTask::Init() LED_Params ledParams; Button_Params buttonParams; - cc13x2_26x2LogInit(); + cc13xx_26xxLogInit(); // Init Chip memory management before the stack Platform::MemoryInit(); @@ -221,7 +221,7 @@ int AppTask::Init() (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); -// Initialize device attestation config + // Initialize device attestation config #ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); #else diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp index a66a9e1a7ba1b4..54faa0db6e7314 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp @@ -7,7 +7,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - *BoltLockManager + * * 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. diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppConfig.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppConfig.h index 3cead418532caa..b925344ddb4c9a 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppConfig.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppConfig.h @@ -1,6 +1,5 @@ /* * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +23,9 @@ extern "C" { #endif -int cc13x2_26x2LogInit(void); -void cc13x2_26x2Log(const char * aFormat, ...); -#define PLAT_LOG(...) cc13x2_26x2Log(__VA_ARGS__); +int cc13xx_26xxLogInit(void); +void cc13xx_26xxLog(const char * aFormat, ...); +#define PLAT_LOG(...) cc13xx_26xxLog(__VA_ARGS__); #ifdef __cplusplus } diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppEvent.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppEvent.h index 0f501990b2ab76..3a9c606e95c330 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppEvent.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppEvent.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2018 Nest Labs, Inc. + * Copyright (c) 2021 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index 5cb1c4369f9dd7..f99523c278db0c 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -74,7 +74,7 @@ */ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) -#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 1 +#define MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED 1 /** * CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp index 6137478fc2ffcc..2b4be76e9c33da 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/main.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -38,7 +37,7 @@ #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xCB00) +#define TOTAL_ICALL_HEAP_SIZE (0xC700) using namespace ::chip; using namespace ::chip::Inet; @@ -58,6 +57,17 @@ extern "C" void vApplicationStackOverflowHook(void) } } +/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */ +extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +extern "C" void vQueueUnregisterQueueWrapper(QueueHandle_t xQueue) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + // ================================================================================ // Main Code // ================================================================================ @@ -70,8 +80,6 @@ int main(void) NVS_init(); - UART_init(); - ECDH_init(); ECDSA_init(); diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn b/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn index d3031712c04a58..0155ff6461ddd9 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/BUILD.gn @@ -37,7 +37,6 @@ ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", @@ -84,6 +83,7 @@ ti_simplelink_executable("pump_controller_app") { deps = [ ":sdk", ":sysconfig", + "${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials", "${chip_root}/examples/pump-controller-app/pump-controller-common", "${chip_root}/src/lib", ] diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni b/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni index 7d386dc216df2f..fb13057bc99474 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/args.gni @@ -29,10 +29,12 @@ lwip_debug = false chip_enable_ota_requestor = true +openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2" + # Disable CHIP Logging #chip_progress_logging = false -#chip_detail_logging = false -#chip_automation_logging = false +chip_detail_logging = false +chip_automation_logging = false # BLE options chip_config_network_layer_ble = true diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg b/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg index 47c7ded81c1b56..995ad22af6b435 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/chip.syscfg @@ -17,158 +17,51 @@ * limitations under the License. */ -/** - * These arguments were used when this file was generated. They will be automatically applied on subsequent loads - * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. - * @cliArgs --board "/ti/boards/CC26X2R1_LAUNCHXL" --product "simplelink_cc13x2_26x2_sdk@4.40.05.02_eng" - * @versions {"tool":"1.9.0+2015","templates":null} - */ - -/** - * Import the modules used in this configuration. - */ -const ble = scripting.addModule("/ti/ble5stack/ble"); -const CCFG = scripting.addModule("/ti/devices/CCFG"); -const rfdesign = scripting.addModule("/ti/devices/radioconfig/rfdesign"); -const dmm = scripting.addModule("/ti/dmm/dmm"); -const AESCCM = scripting.addModule("/ti/drivers/AESCCM"); -const AESCCM1 = AESCCM.addInstance(); -const AESCCM2 = AESCCM.addInstance(); -const AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); -const AESCTRDRBG1 = AESCTRDRBG.addInstance(); -const AESECB = scripting.addModule("/ti/drivers/AESECB"); -const AESECB1 = AESECB.addInstance(); -const AESECB2 = AESECB.addInstance(); -const ECDH = scripting.addModule("/ti/drivers/ECDH"); -const ECDH1 = ECDH.addInstance(); -const ECDH2 = ECDH.addInstance(); -const NVS = scripting.addModule("/ti/drivers/NVS"); -const NVS1 = NVS.addInstance(); -const NVS2 = NVS.addInstance(); -const RF = scripting.addModule("/ti/drivers/RF"); -const RTOS = scripting.addModule("/ti/drivers/RTOS"); -const SHA2 = scripting.addModule("/ti/drivers/SHA2"); -const SHA21 = SHA2.addInstance(); -const TRNG = scripting.addModule("/ti/drivers/TRNG"); -const TRNG1 = TRNG.addInstance(); -const TRNG2 = TRNG.addInstance(); -const TRNG3 = TRNG.addInstance(); -const UART = scripting.addModule("/ti/drivers/UART"); -const UART1 = UART.addInstance(); -const UART2 = UART.addInstance(); -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 thread = scripting.addModule("/ti/thread/thread"); - -/** - * Write custom configuration values to the imported modules. - */ -ble.maxConnNum = 1; -ble.numOfAdvSets = 1; -ble.lockProject = 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.advData1.$name = "ti_ble5stack_broadcaster_advertisement_data0"; -ble.advSet1.scanRes1.$name = "ti_ble5stack_broadcaster_advertisement_data1"; - -CCFG.enableBootloader = true; -CCFG.enableBootloaderBackdoor = true; -CCFG.dioBootloaderBackdoor = 13; -CCFG.levelBootloaderBackdoor = "Active low"; -CCFG.srcClkLF = "Derived from HF XOSC"; -CCFG.ccfgTemplate.$name = "ti_devices_CCFGTemplate0"; - -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; -AESCCM1.$name = "CONFIG_AESCCM0"; - -AESCCM2.$name = "CONFIG_AESCCM_1"; +/* Modules */ +var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); +var AESECB = scripting.addModule("/ti/drivers/AESECB"); +var Button = scripting.addModule("/ti/drivers/apps/Button"); +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 RFCustom = scripting.addModule("/ti/devices/radioconfig/custom"); +var TRNG = scripting.addModule("/ti/drivers/TRNG"); +var SHA2 = scripting.addModule("/ti/drivers/SHA2"); +var UART2 = scripting.addModule("/ti/drivers/UART2"); +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 AESECB1 = AESECB.addInstance(); +var AESECB2 = AESECB.addInstance(); +var Button1 = Button.addInstance(); +var Button2 = Button.addInstance(); +var NVS1 = NVS.addInstance(); +var NVS2 = 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 UART2 = UART2.addInstance(); +var AESCTRDRBG1 = AESCTRDRBG.addInstance(); +var ECDH1 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; -AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; -AESECB1.$name = "CONFIG_AESECB0"; +AESCCM1.$name = "CONFIG_AESCCM0"; +AESECB1.$name = "CONFIG_AESECB0"; AESECB2.$name = "CONFIG_AESECB_1"; ECDH1.$name = "CONFIG_ECDH0"; -ECDH2.$name = "CONFIG_ECDH_1"; - -NVS1.$name = "CONFIG_NVSINTERNAL"; -NVS1.internalFlash.$name = "ti_drivers_nvs_NVSCC26XX0"; -NVS1.internalFlash.regionBase = 0xAA000; -NVS1.internalFlash.regionSize = 0x4000; - -NVS2.$name = "CONFIG_NVSEXTERNAL"; -NVS2.nvsType = "External"; // NVS Region Type -NVS2.$hardware = system.deviceData.board.components.MX25R8035F; - -RTOS.name = "FreeRTOS"; - -SHA21.$name = "CONFIG_SHA2_0"; - -TRNG1.$name = "CONFIG_TRNG_0"; - -TRNG2.$name = "CONFIG_TRNG_1"; - -TRNG3.$name = "CONFIG_TRNG_APP"; - -UART1.$name = "CONFIG_UART_DEBUG"; -UART1.uart.$assign = "UART1"; -UART1.uart.txPin.$assign = "boosterpack.4"; -UART1.uart.rxPin.$assign = "boosterpack.3"; -UART1.txPinInstance.$name = "CONFIG_PIN_4"; -UART1.rxPinInstance.$name = "CONFIG_PIN_5"; - -UART2.$name = "CONFIG_DISPLAY_UART"; -UART2.txPinInstance.$name = "CONFIG_PIN_6"; -UART2.rxPinInstance.$name = "CONFIG_PIN_7"; - /* Left Button */ Button1.$name = "CONFIG_BTN_LEFT"; Button1.$hardware = system.deviceData.board.components["BTN-1"]; @@ -183,6 +76,90 @@ Button2.gpioPin.$name = "CONFIG_GPIO_BTN2"; Button2.gpioPin.pull = "Pull Up"; Button2.gpioPin.interruptTrigger = "Falling Edge"; +/* ======== CCFG ======== */ +var CCFG = scripting.addModule("/ti/devices/CCFG"); +const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings; +for(var setting in ccfgSettings) +{ + CCFG[setting] = ccfgSettings[setting]; +} + +// Disable CCFG generation, this is added by the BIM project +CCFG.enableCodeGeneration = false; + +/* NVS */ +NVS1.$name = "CONFIG_NVSINTERNAL"; +NVS1.internalFlash.regionBase = 0xAA000; +NVS1.internalFlash.regionSize = 0x4000; + +NVS2.$name = "CONFIG_NVSEXTERNAL"; +NVS2.nvsType = "External"; // NVS Region Type +NVS2.$hardware = system.deviceData.board.components.MX25R8035F; + +/* RF */ +/* 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]; +} + +/* Handling for RF frontend characterization */ +if(RFDesign.rfDesign.match(/LP_CC2652PSIP/)) +{ + RFCustom.ieee = ["ieee154p10"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154p10.codeExportConfig +} +else +{ + RFCustom.ieee = ["ieee154"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154.codeExportConfig +} + +var cmdList = [ + "cmdIeeeTx", + "cmdIeeeRx", + "cmdIeeeCsma", + "cmdIeeeEdScan", + "cmdIeeeRxAck", + "cmdTxTest" +]; + +rfCodeExportConfig.useConst = true; +rfCodeExportConfig.useMulti = true; +rfCodeExportConfig.symGenMethod = "Custom"; + +const deviceId = system.deviceData.deviceId; + +// Add high PA options if present +if(deviceId.match(/CC(265[12]R|2674R|1352R1|1354R)/)) +{ + cmdList.push("cmdRadioSetup"); + rfCodeExportConfig.cmdRadioSetup = "RF_cmdIeeeRadioSetup"; +} +else if(deviceId.match(/CC(265[12]P|2674P|1352P)/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + rfCodeExportConfig.paExport = "combined"; +} +else if(deviceId.match(/CC(265[34]|1354)P/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + // currently not characterized for high PA +} +else +{ + throw new Error("Could not match platform to any known platform types"); +} + +rfCodeExportConfig.cmdList_ieee_15_4 = cmdList; + /* Red LED */ LED1.$name = "CONFIG_LED_RED"; LED1.$hardware = system.deviceData.board.components.LED_RED; @@ -197,19 +174,65 @@ LED2.gpioPin.$name = "CONFIG_GPIO_GLED"; LED2.gpioPin.mode = "Output"; LED2.gpioPin.callbackFunction = ""; -thread.deviceTypeReadOnly = true; -thread.pm.$name = "ti_thread_pm_thread_pm0"; -thread.rf.$name = "ti_thread_rf_thread_rf0"; -thread.rf.radioConfig.$name = "ti_devices_radioconfig_settings_ieee_15_40"; -thread.rf.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param0"; -thread.network.$name = "ti_thread_network_thread_network0"; -thread.security.$name = "ti_thread_security_thread_security0"; - -/** - * 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. - */ -UART2.uart.$suggestSolution = "UART0"; -UART2.uart.txPin.$suggestSolution = "boosterpack.30"; -UART2.uart.rxPin.$suggestSolution = "boosterpack.29"; +/* Debug UART */ +UART2.$hardware = system.deviceData.board.components.XDS110UART; +UART2.$name = "CONFIG_UART2_DEBUG"; + +/* TRNG */ +TRNG1.$name = "CONFIG_TRNG_0"; +TRNG2.$name = "CONFIG_TRNG_THREAD"; +TRNG3.$name = "CONFIG_TRNG_APP"; + +/* 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_param2"; +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"; + +/* 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/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp index e8611622fc28dd..8c4e51f44431fd 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -24,7 +24,8 @@ #include "FreeRTOS.h" #include -#include + +#include #include #include @@ -34,7 +35,7 @@ #include #include #include -#include +#include #endif #include #include @@ -122,7 +123,7 @@ int AppTask::Init() LED_Params ledParams; Button_Params buttonParams; - cc13x2_26x2LogInit(); + cc13xx_26xxLogInit(); // Init Chip memory management before the stack chip::Platform::MemoryInit(); @@ -174,7 +175,11 @@ int AppTask::Init() chip::Server::GetInstance().Init(initParams); // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif // Initialize LEDs PLAT_LOG("Initialize LEDs"); diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp index 9dfc7e22e76687..e450a4b233eddb 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp @@ -7,7 +7,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - *BoltLockManager + * * 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. diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppConfig.h b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppConfig.h index 3cead418532caa..b925344ddb4c9a 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppConfig.h +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppConfig.h @@ -1,6 +1,5 @@ /* * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +23,9 @@ extern "C" { #endif -int cc13x2_26x2LogInit(void); -void cc13x2_26x2Log(const char * aFormat, ...); -#define PLAT_LOG(...) cc13x2_26x2Log(__VA_ARGS__); +int cc13xx_26xxLogInit(void); +void cc13xx_26xxLog(const char * aFormat, ...); +#define PLAT_LOG(...) cc13xx_26xxLog(__VA_ARGS__); #ifdef __cplusplus } diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppEvent.h b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppEvent.h index 0f501990b2ab76..3a9c606e95c330 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppEvent.h +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/AppEvent.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2018 Nest Labs, Inc. + * Copyright (c) 2021 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index aca4a63dc9798f..97dac7bf1fe313 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -74,7 +74,7 @@ */ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) -#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 1 +#define MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED 1 /** * CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp index 6137478fc2ffcc..2b4be76e9c33da 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/main.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -38,7 +37,7 @@ #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xCB00) +#define TOTAL_ICALL_HEAP_SIZE (0xC700) using namespace ::chip; using namespace ::chip::Inet; @@ -58,6 +57,17 @@ extern "C" void vApplicationStackOverflowHook(void) } } +/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */ +extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +extern "C" void vQueueUnregisterQueueWrapper(QueueHandle_t xQueue) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + // ================================================================================ // Main Code // ================================================================================ @@ -70,8 +80,6 @@ int main(void) NVS_init(); - UART_init(); - ECDH_init(); ECDSA_init(); diff --git a/examples/shell/cc13x2x7_26x2x7/BUILD.gn b/examples/shell/cc13x2x7_26x2x7/BUILD.gn index 1b4716017365b7..691853a6f8ebc8 100644 --- a/examples/shell/cc13x2x7_26x2x7/BUILD.gn +++ b/examples/shell/cc13x2x7_26x2x7/BUILD.gn @@ -85,6 +85,7 @@ ti_simplelink_executable("shell_app") { ":sdk", ":sysconfig", "${chip_root}/examples/all-clusters-app/all-clusters-common", + "${chip_root}/examples/platform/cc13x2_26x2:cc13x2_26x2-attestation-credentials", "${chip_root}/examples/shell/shell_common:shell_common", "${chip_root}/src/lib", "${chip_root}/src/lib/shell:shell", diff --git a/examples/shell/cc13x2x7_26x2x7/args.gni b/examples/shell/cc13x2x7_26x2x7/args.gni index 58ec5edf1dbb5a..92dd1dcdfdd0b2 100644 --- a/examples/shell/cc13x2x7_26x2x7/args.gni +++ b/examples/shell/cc13x2x7_26x2x7/args.gni @@ -30,6 +30,7 @@ chip_enable_ota_requestor = false # Disable FTD Build for all-clusters app to save Flash chip_openthread_ftd = false +openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2" # Disable CHIP Logging chip_progress_logging = false diff --git a/examples/shell/cc13x2x7_26x2x7/chip.syscfg b/examples/shell/cc13x2x7_26x2x7/chip.syscfg index 738502f344e309..ed0e4a5c8d5fd6 100644 --- a/examples/shell/cc13x2x7_26x2x7/chip.syscfg +++ b/examples/shell/cc13x2x7_26x2x7/chip.syscfg @@ -18,19 +18,16 @@ */ - /* Modules */ var AESCCM = scripting.addModule("/ti/drivers/AESCCM"); var AESECB = scripting.addModule("/ti/drivers/AESECB"); -var ECJPAKE = scripting.addModule("/ti/drivers/ECJPAKE"); 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 RFCustom = scripting.addModule("/ti/devices/radioconfig/custom"); 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 UART2 = scripting.addModule("/ti/drivers/UART2"); var ble = scripting.addModule("/ti/ble5stack/ble"); var dmm = scripting.addModule("/ti/dmm/dmm"); var AESCTRDRBG = scripting.addModule("/ti/drivers/AESCTRDRBG"); @@ -40,19 +37,17 @@ var ECDH = scripting.addModule("/ti/drivers/ECDH"); var AESCCM1 = AESCCM.addInstance(); var AESECB1 = AESECB.addInstance(); var AESECB2 = AESECB.addInstance(); -var ECJPAKE = ECJPAKE.addInstance(); var NVS1 = NVS.addInstance(); var NVS2 = NVS.addInstance(); var SHA21 = SHA2.addInstance(); var TRNG1 = TRNG.addInstance(); var TRNG2 = TRNG.addInstance(); var TRNG3 = TRNG.addInstance(); -var UART1 = UART.addInstance(); +var UART2 = UART2.addInstance(); var AESCTRDRBG1 = AESCTRDRBG.addInstance(); var ECDH1 = ECDH.addInstance(); AESCTRDRBG1.$name = "CONFIG_AESCTRDRBG_0"; -AESCTRDRBG1.aesctrObject.$name = "CONFIG_AESCTR_0"; AESCCM1.$name = "CONFIG_AESCCM0"; @@ -92,17 +87,68 @@ for(var setting in rfDesignSettings) RFDesign[setting] = rfDesignSettings[setting]; } -/* Streamer UART */ -UART1.$hardware = system.deviceData.board.components.XDS110UART; -UART1.$name = "CONFIG_UART_STREAMER"; + +/* Handling for RF frontend characterization */ +if(RFDesign.rfDesign.match(/LP_CC2652PSIP/)) +{ + RFCustom.ieee = ["ieee154p10"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154p10.codeExportConfig +} +else +{ + RFCustom.ieee = ["ieee154"]; + var rfCodeExportConfig = RFCustom.radioConfigieee154.codeExportConfig +} + +var cmdList = [ + "cmdIeeeTx", + "cmdIeeeRx", + "cmdIeeeCsma", + "cmdIeeeEdScan", + "cmdIeeeRxAck", + "cmdTxTest" +]; + +rfCodeExportConfig.useConst = true; +rfCodeExportConfig.useMulti = true; +rfCodeExportConfig.symGenMethod = "Custom"; + +const deviceId = system.deviceData.deviceId; + +// Add high PA options if present +if(deviceId.match(/CC(265[12]R|2674R|1352R1|1354R)/)) +{ + cmdList.push("cmdRadioSetup"); + rfCodeExportConfig.cmdRadioSetup = "RF_cmdIeeeRadioSetup"; +} +else if(deviceId.match(/CC(265[12]P|2674P|1352P)/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + rfCodeExportConfig.paExport = "combined"; +} +else if(deviceId.match(/CC(265[34]|1354)P/)) +{ + cmdList.push("cmdRadioSetupPa"); + rfCodeExportConfig.cmdRadioSetupPa = "RF_cmdIeeeRadioSetup"; + // currently not characterized for high PA +} +else +{ + throw new Error("Could not match platform to any known platform types"); +} + +rfCodeExportConfig.cmdList_ieee_15_4 = cmdList; + +/* Debug UART */ +UART2.$hardware = system.deviceData.board.components.XDS110UART; +UART2.$name = "CONFIG_UART_STREAMER"; /* TRNG */ TRNG1.$name = "CONFIG_TRNG_0"; -TRNG2.$name = "CONFIG_TRNG_1"; +TRNG2.$name = "CONFIG_TRNG_THREAD"; TRNG3.$name = "CONFIG_TRNG_APP"; -RTOS.name = "FreeRTOS"; - /* BLE */ ble.addressMode = "ADDRMODE_RP_WITH_PUBLIC_ID"; ble.maxConnNum = 1; @@ -110,7 +156,7 @@ ble.numOfAdvSets = 1; ble.lockProject = true; ble.oneLibSizeOpt = true; ble.maxPDUSize = 255; -ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param1"; +ble.radioConfig.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param2"; ble.connUpdateParamsPeripheral.$name = "ti_ble5stack_general_ble_conn_update_params0"; ble.connUpdateParamsPeripheral.reqMinConnInt = 30; ble.connUpdateParamsPeripheral.reqMaxConnInt = 50; diff --git a/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index 969a02acb089ca..1e8f718031e90f 100644 --- a/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h +++ b/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -75,7 +75,7 @@ */ #define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (256) -#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 0 +#define MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED 0 /** * CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT diff --git a/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp index 8e29789d2639cd..dda97f4e566ef5 100644 --- a/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/shell/cc13x2x7_26x2x7/main/AppTask.cpp @@ -25,17 +25,18 @@ #include #include -#include #include #include #include +#include + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR #include #include #include #include -#include +#include #endif #include #include @@ -60,7 +61,7 @@ static TaskHandle_t sAppTaskHandle; // Logging extern "C" { -int cc13x2_26x2LogInit(void); +int cc13xx_26xxLogInit(void); } #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR @@ -102,7 +103,7 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; - cc13x2_26x2LogInit(); + cc13xx_26xxLogInit(); // Init Chip memory management before the stack Platform::MemoryInit(); @@ -150,7 +151,12 @@ CHIP_ERROR AppTask::Init() chip::Server::GetInstance().Init(initParams); // Initialize device attestation config +#ifdef CC13X2_26X2_ATTESTATION_CREDENTIALS + SetDeviceAttestationCredentialsProvider(CC13X2_26X2::GetCC13X2_26X2DacProvider()); +#else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); +#endif + #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR InitializeOTARequestor(); #endif diff --git a/examples/shell/cc13x2x7_26x2x7/main/main.cpp b/examples/shell/cc13x2x7_26x2x7/main/main.cpp index 198e5c906b3f94..884744230dfc56 100644 --- a/examples/shell/cc13x2x7_26x2x7/main/main.cpp +++ b/examples/shell/cc13x2x7_26x2x7/main/main.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -38,7 +37,7 @@ #include #include -#define TOTAL_ICALL_HEAP_SIZE (0xc800) +#define TOTAL_ICALL_HEAP_SIZE (0xc700) using namespace ::chip; using namespace ::chip::Inet; @@ -58,6 +57,17 @@ extern "C" void vApplicationStackOverflowHook(void) } } +/* Wrapper functions for using the queue registry regardless of whether it is enabled or disabled */ +extern "C" void vQueueAddToRegistryWrapper(QueueHandle_t xQueue, const char * pcQueueName) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + +extern "C" void vQueueUnregisterQueueWrapper(QueueHandle_t xQueue) +{ + /* This function is intentionally left empty as the Queue Registry is disabled */ +} + // ================================================================================ // Main Code // ================================================================================ @@ -72,8 +82,6 @@ int main(void) NVS_init(); - UART_init(); - ECDH_init(); ECDSA_init(); diff --git a/scripts/checkout_submodules.py b/scripts/checkout_submodules.py index ec4f67bc60fdf9..a401cf8bdbe3e8 100755 --- a/scripts/checkout_submodules.py +++ b/scripts/checkout_submodules.py @@ -29,7 +29,7 @@ 'android', 'bl602', 'bouffalolab', - 'cc13x2_26x2', + 'cc13xx_26xx', 'cc32xx', 'darwin', 'efr32', diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn index 68af8be17cb766..67d6b1d69ab5b6 100644 --- a/src/lib/shell/BUILD.gn +++ b/src/lib/shell/BUILD.gn @@ -92,10 +92,11 @@ static_library("shell") { "MainLoopDefault.cpp", "streamer_bouffalolab.cpp", ] - } else if (chip_device_platform == "cc13x2_26x2") { + } else if (chip_device_platform == "cc13x2_26x2" || + chip_device_platform == "cc13x4_26x4") { sources += [ "MainLoopDefault.cpp", - "streamer_cc13x2_26x2.cpp", + "streamer_cc13x4_26x4.cpp", ] } else if (chip_device_platform == "mw320") { sources += [ diff --git a/src/lib/shell/streamer_cc13x4_26x4.cpp b/src/lib/shell/streamer_cc13x4_26x4.cpp new file mode 100644 index 00000000000000..259674a96e1fb7 --- /dev/null +++ b/src/lib/shell/streamer_cc13x4_26x4.cpp @@ -0,0 +1,109 @@ +/* + * + * Copyright (c) 2022 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 + * Source implementation of an input / output stream for cc13xx_26xx targets + */ + +#include "streamer.h" +#include +#include +#include +#include + +#include "ti_drivers_config.h" + +#include + +namespace chip { +namespace Shell { + +#ifndef SHELL_STREAMER_APP_SPECIFIC + +UART2_Handle sStreamUartHandle = NULL; + +#if !MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED +extern "C" int cc13xx_26xxLogInit(void) +{ + return 0; +} + +extern "C" void cc13xx_26xxVLog(const char * msg, va_list v) +{ + if (NULL != sStreamUartHandle) + { + static char sDebugUartBuffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; + size_t ret; + + 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'; + + UART2_write(sStreamUartHandle, sDebugUartBuffer, len, NULL); + } + } +} +#endif // !MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED + +int streamer_cc13xx_26xx_init(streamer_t * streamer) +{ + UART2_Params uartParams; + + UART2_Params_init(&uartParams); + // Most params can be default because we only send data, we don't receive + uartParams.baudRate = 115200; + + sStreamUartHandle = UART2_open(CONFIG_UART_STREAMER, &uartParams); + return 0; +} + +ssize_t streamer_cc13xx_26xx_read(streamer_t * streamer, char * buf, size_t len) +{ + (void) streamer; + size_t ret; + + UART2_read(sStreamUartHandle, buf, len, &ret); + + return ret; +} + +ssize_t streamer_cc13xx_26xx_write(streamer_t * streamer, const char * buf, size_t len) +{ + (void) streamer; + return UART2_write(sStreamUartHandle, buf, len, NULL); +} + +static streamer_t streamer_cc13xx_26xx = { + .init_cb = streamer_cc13xx_26xx_init, + .read_cb = streamer_cc13xx_26xx_read, + .write_cb = streamer_cc13xx_26xx_write, +}; + +streamer_t * streamer_get() +{ + return &streamer_cc13xx_26xx; +} + +#endif //#ifndef SHELL_STREAMER_APP_SPECIFIC + +} // namespace Shell +} // namespace chip diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 013310053c0f6d..8f91f9ec2685da 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -29,7 +29,7 @@ if (lwip_platform == "") { } assert(lwip_platform == "external" || lwip_platform == "standalone" || - lwip_platform == "cc13x2_26x2" || lwip_platform == "cc32xx" || + lwip_platform == "cc13xx_26xx" || lwip_platform == "cc32xx" || lwip_platform == "silabs" || lwip_platform == "k32w0" || lwip_platform == "qpg" || lwip_platform == "mbed" || lwip_platform == "psoc6" || lwip_platform == "cyw30739" || @@ -44,7 +44,7 @@ if (lwip_platform != "external") { } } -if (lwip_platform == "cc13x2_26x2") { +if (lwip_platform == "cc13xx_26xx") { import("//build_overrides/ti_simplelink_sdk.gni") } else if (lwip_platform == "cc32xx") { import("//build_overrides/ti_simplelink_sdk.gni") @@ -180,7 +180,7 @@ if (current_os == "zephyr" || current_os == "mbed") { } public_deps = [ ":lwip_buildconfig" ] - if (lwip_platform == "cc13x2_26x2") { + if (lwip_platform == "cc13xx_26xx") { 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" ] diff --git a/src/lwip/cc13x2_26x2/arch/cc.h b/src/lwip/cc13xx_26xx/arch/cc.h similarity index 100% rename from src/lwip/cc13x2_26x2/arch/cc.h rename to src/lwip/cc13xx_26xx/arch/cc.h diff --git a/src/lwip/cc13x2_26x2/arch/perf.h b/src/lwip/cc13xx_26xx/arch/perf.h similarity index 100% rename from src/lwip/cc13x2_26x2/arch/perf.h rename to src/lwip/cc13xx_26xx/arch/perf.h diff --git a/src/lwip/cc13x2_26x2/lwipopts.h b/src/lwip/cc13xx_26xx/lwipopts.h similarity index 97% rename from src/lwip/cc13x2_26x2/lwipopts.h rename to src/lwip/cc13xx_26xx/lwipopts.h index 387232e369c3ec..925a06d2615bf8 100644 --- a/src/lwip/cc13x2_26x2/lwipopts.h +++ b/src/lwip/cc13xx_26xx/lwipopts.h @@ -77,8 +77,8 @@ #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_NEIGHBORS (1) +#define LWIP_ND6_NUM_DESTINATIONS (1) #define LWIP_ND6_NUM_PREFIXES (0) #define LWIP_ND6_NUM_ROUTERS (0) #define LWIP_ND6_MAX_MULTICAST_SOLICIT (0) @@ -110,7 +110,8 @@ #define LWIP_IPV6_NUM_ADDRESSES 5 -#define LWIP_IPV6_ND 0 +#define LWIP_IPV6_MLD 1 +#define LWIP_IPV6_ND 1 #define LWIP_ND6_QUEUEING 0 #define LWIP_MULTICAST_PING 0 diff --git a/src/lwip/cc13x2_26x2/lwippools.h b/src/lwip/cc13xx_26xx/lwippools.h similarity index 100% rename from src/lwip/cc13x2_26x2/lwippools.h rename to src/lwip/cc13xx_26xx/lwippools.h diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index b4876e13103364..8cd18955cc43d9 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -149,7 +149,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { if (chip_device_platform == "cc13x2_26x2") { defines += [ "CHIP_DEVICE_LAYER_TARGET_CC13X2_26X2=1", - "CHIP_DEVICE_LAYER_TARGET=cc13x2_26x2", + "CHIP_DEVICE_LAYER_TARGET=cc13xx_26xx/cc13x2_26x2", + ] + } else if (chip_device_platform == "cc13x4_26x4") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_CC13X4_26X4=1", + "CHIP_DEVICE_LAYER_TARGET=cc13xx_26xx/cc13x4_26x4", ] } else if (chip_device_platform == "cc32xx") { defines += [ @@ -416,7 +421,9 @@ if (chip_device_platform != "none") { ] if (chip_device_platform == "cc13x2_26x2") { - _platform_target = "cc13x2_26x2" + _platform_target = "cc13xx_26xx/cc13x2_26x2" + } else if (chip_device_platform == "cc13x4_26x4") { + _platform_target = "cc13xx_26xx/cc13x4_26x4" } else if (chip_device_platform == "cc32xx") { _platform_target = "cc32xx" } else if (chip_device_platform == "darwin") { diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp b/src/platform/cc13xx_26xx/BLEManagerImpl.cpp similarity index 99% rename from src/platform/cc13x2_26x2/BLEManagerImpl.cpp rename to src/platform/cc13xx_26xx/BLEManagerImpl.cpp index 1aa871a977b855..65c5cf0a2d9938 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp +++ b/src/platform/cc13xx_26xx/BLEManagerImpl.cpp @@ -61,8 +61,8 @@ extern "C" { // BLE Manager Debug Logs extern "C" { #ifdef BLEMGR_DBG_LOGGING -extern void cc13x2_26x2Log(const char * aFormat, ...); -#define BLEMGR_LOG(...) cc13x2_26x2Log(__VA_ARGS__); +extern void cc13xx_26xxLog(const char * aFormat, ...); +#define BLEMGR_LOG(...) cc13xx_26xxLog(__VA_ARGS__); #else #define BLEMGR_LOG(...) #endif diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13xx_26xx/CC13XX_26XXConfig.cpp similarity index 60% rename from src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp rename to src/platform/cc13xx_26xx/CC13XX_26XXConfig.cpp index 70abc0fc6f6812..c0475e0d015610 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13xx_26xx/CC13XX_26XXConfig.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -44,94 +44,95 @@ namespace Internal { /* 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 = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0001 } + +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_SerialNum = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0001 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceId = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0002 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_MfrDeviceId = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0002 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceCert = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0003 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_MfrDeviceCert = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0003 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDeviceICACerts = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0004 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_MfrDeviceICACerts = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0004 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_MfrDevicePrivateKey = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0005 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_MfrDevicePrivateKey = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0005 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_HardwareVersion = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0006 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_HardwareVersion = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0006 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ManufacturingDate = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0007 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_ManufacturingDate = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0007 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupPinCode = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0008 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_SetupPinCode = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0008 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_SetupDiscriminator = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0009 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_SetupDiscriminator = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0009 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pIterationCount = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000a } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_Spake2pIterationCount = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x000a } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pSalt = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000b } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_Spake2pSalt = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x000b } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_Spake2pVerifier = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x000c } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_Spake2pVerifier = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x000c } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LifeTimeCounter = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipFactory, .subID = 0x0010 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_LifeTimeCounter = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipFactory, .subID = 0x0010 } }; // Keys stored in the Chip-counters namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_BootCount = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000d } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_BootCount = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipCounters, .subID = 0x000d } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_TotalOperationalHours = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipCounters, .subID = 0x000f } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_TotalOperationalHours = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipCounters, .subID = 0x000f } }; // Keys stored in the Chip-config namespace -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceConfig = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0012 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_ServiceConfig = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0012 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_PairedAccountId = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0013 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_PairedAccountId = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0013 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_ServiceId = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0014 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_ServiceId = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0014 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_LastUsedEpochKeyId = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00017 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_LastUsedEpochKeyId = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x00017 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_FailSafeArmed = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00018 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_FailSafeArmed = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x00018 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_WiFiStationSecType = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x00019 } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_WiFiStationSecType = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x00019 } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_RegulatoryLocation = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001a } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_RegulatoryLocation = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0001a } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_CountryCode = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001b } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_CountryCode = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0001b } }; // itemID 0x001c is unused (used to be breadcrumb). -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_UniqueId = { - { .systemID = kCC13X2_26X2Matter_SysID, .itemID = kCC13X2_26X2Matter_ItemID_ChipConfig, .subID = 0x0001d } +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_UniqueId = { + { .systemID = kCC13XX_26XXMatter_SysID, .itemID = kCC13XX_26XXMatter_ItemID_ChipConfig, .subID = 0x0001d } }; /* Internal for the KVS interface. */ -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_key = { { .systemID = kCC13X2_26X2Matter_SysID, - .itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_key } }; -const CC13X2_26X2Config::Key CC13X2_26X2Config::kConfigKey_KVS_value = { { .systemID = kCC13X2_26X2Matter_SysID, - .itemID = kCC13X2_26X2Matter_ItemID_ChipKVS_value } }; +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_KVS_key = { { .systemID = kCC13XX_26XXMatter_SysID, + .itemID = kCC13XX_26XXMatter_ItemID_ChipKVS_key } }; +const CC13XX_26XXConfig::Key CC13XX_26XXConfig::kConfigKey_KVS_value = { { .systemID = kCC13XX_26XXMatter_SysID, + .itemID = kCC13XX_26XXMatter_ItemID_ChipKVS_value } }; /* Static local variables */ static NVINTF_nvFuncts_t sNvoctpFps = { 0 }; -CHIP_ERROR CC13X2_26X2Config::Init() +CHIP_ERROR CC13XX_26XXConfig::Init() { CHIP_ERROR err = CHIP_NO_ERROR; @@ -144,7 +145,7 @@ CHIP_ERROR CC13X2_26X2Config::Init() return err; } -CHIP_ERROR CC13X2_26X2Config::ReadConfigValue(Key key, bool & val) +CHIP_ERROR CC13XX_26XXConfig::ReadConfigValue(Key key, bool & val) { CHIP_ERROR ret; size_t ignore; @@ -152,32 +153,32 @@ CHIP_ERROR CC13X2_26X2Config::ReadConfigValue(Key key, bool & val) ret = ReadConfigValueBin(key, &localVal, sizeof(localVal), ignore); - // reference CC13X2_26X2Config::WriteConfigValue(Key key, bool val) for storage of boolean values + // reference CC13XX_26XXConfig::WriteConfigValue(Key key, bool val) for storage of boolean values val = (localVal != 0); return ret; } -CHIP_ERROR CC13X2_26X2Config::ReadConfigValue(Key key, uint32_t & val) +CHIP_ERROR CC13XX_26XXConfig::ReadConfigValue(Key key, uint32_t & val) { size_t ignore; return ReadConfigValueBin(key, (uint8_t *) &val, sizeof(val), ignore); } -CHIP_ERROR CC13X2_26X2Config::ReadConfigValue(Key key, uint64_t & val) +CHIP_ERROR CC13XX_26XXConfig::ReadConfigValue(Key key, uint64_t & val) { size_t ignore; return ReadConfigValueBin(key, (uint8_t *) &val, sizeof(val), ignore); } -CHIP_ERROR CC13X2_26X2Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +CHIP_ERROR CC13XX_26XXConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) { return ReadConfigValueBin(key, (uint8_t *) buf, bufSize, outLen); } -CHIP_ERROR CC13X2_26X2Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +CHIP_ERROR CC13XX_26XXConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) { CHIP_ERROR err = CHIP_NO_ERROR; size_t len; @@ -195,15 +196,16 @@ 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[PersistentStorageDelegate::kKeyLengthMax + 1]; NVINTF_nvProxy_t nvProxy = { 0 }; uint8_t status = NVINTF_SUCCESS; + // Store first valid sub ID that has already been found in NV to prevent re-scanning the same page + uint16_t firstSubID = 0xffff; - nvProxy.sysid = CC13X2_26X2Config::kConfigKey_KVS_key.nvID.systemID; - nvProxy.itemid = CC13X2_26X2Config::kConfigKey_KVS_key.nvID.itemID; + nvProxy.sysid = CC13XX_26XXConfig::kConfigKey_KVS_key.nvID.systemID; + nvProxy.itemid = CC13XX_26XXConfig::kConfigKey_KVS_key.nvID.itemID; nvProxy.buffer = key_scratch; nvProxy.len = sizeof(key_scratch); nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DOREAD; @@ -222,17 +224,28 @@ static uint8_t FindKVSSubID(const char * key, uint16_t & subID) subID = nvProxy.subid; break; } + if (firstSubID == 0xFFFF) + { + firstSubID = nvProxy.subid; + } + else if (firstSubID == nvProxy.subid) + { + // Scanned all of NV with no new subID found. + status = NVINTF_NOTFOUND; + 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, +CHIP_ERROR CC13XX_26XXConfig::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; + NVINTF_itemID_t val_item = CC13XX_26XXConfig::kConfigKey_KVS_value.nvID; uint16_t subID; size_t len; uint16_t read_len; @@ -269,39 +282,39 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val return err; } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValue(Key key, bool val) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValue(Key key, bool val) { uint8_t localVal = val ? 1 : 0; return WriteConfigValueBin(key, (const uint8_t *) &localVal, sizeof(localVal)); } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValue(Key key, uint32_t val) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValue(Key key, uint32_t val) { return WriteConfigValueBin(key, (const uint8_t *) &val, sizeof(val)); } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValue(Key key, uint64_t val) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValue(Key key, uint64_t val) { return WriteConfigValueBin(key, (const uint8_t *) &val, sizeof(val)); } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValueStr(Key key, const char * str) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValueStr(Key key, const char * str) { size_t strLen = strlen(str); return WriteConfigValueBin(key, (const uint8_t *) str, strLen); } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValueStr(Key key, const char * str, size_t strLen) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValueStr(Key key, const char * str, size_t strLen) { 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 CC13XX_26XXConfig::WriteKVS(const char * key, const void * value, size_t value_size) { 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; + NVINTF_itemID_t key_item = CC13XX_26XXConfig::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13XX_26XXConfig::kConfigKey_KVS_value.nvID; if (FindKVSSubID(key, subID) != NVINTF_SUCCESS) { @@ -354,7 +367,7 @@ CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, siz return err; } -CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +CHIP_ERROR CC13XX_26XXConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -364,12 +377,12 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, return err; } -CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key) +CHIP_ERROR CC13XX_26XXConfig::ClearKVS(const char * key) { CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; 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; + NVINTF_itemID_t key_item = CC13XX_26XXConfig::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13XX_26XXConfig::kConfigKey_KVS_value.nvID; if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) { @@ -396,7 +409,7 @@ CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key) return err; } -CHIP_ERROR CC13X2_26X2Config::ClearConfigValue(Key key) +CHIP_ERROR CC13XX_26XXConfig::ClearConfigValue(Key key) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -405,13 +418,13 @@ CHIP_ERROR CC13X2_26X2Config::ClearConfigValue(Key key) return err; } -bool CC13X2_26X2Config::ConfigValueExists(Key key) +bool CC13XX_26XXConfig::ConfigValueExists(Key key) { /* 0 is an invalid length for an item, getting a length of 0 means there is no item */ return (0 != sNvoctpFps.getItemLen(key.nvID)); } -CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) +CHIP_ERROR CC13XX_26XXConfig::FactoryResetConfig(void) { CHIP_ERROR err = CHIP_NO_ERROR; NVINTF_nvProxy_t nvProxy = { 0 }; @@ -423,8 +436,8 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) intptr_t key = sNvoctpFps.lockNV(); /* Setup doNext call */ - nvProxy.sysid = kCC13X2_26X2Matter_SysID; - nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipConfig; + nvProxy.sysid = kCC13XX_26XXMatter_SysID; + nvProxy.itemid = kCC13XX_26XXMatter_ItemID_ChipConfig; nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; /* Lock and wipe all items with config itemid */ @@ -436,8 +449,8 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); /* Setup doNext call */ - nvProxy.sysid = kCC13X2_26X2Matter_SysID; - nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipCounters; + nvProxy.sysid = kCC13XX_26XXMatter_SysID; + nvProxy.itemid = kCC13XX_26XXMatter_ItemID_ChipCounters; nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; /* Lock and wipe all items with counters itemid */ @@ -449,8 +462,8 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); /* Setup doNext call */ - nvProxy.sysid = kCC13X2_26X2Matter_SysID; - nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_key; + nvProxy.sysid = kCC13XX_26XXMatter_SysID; + nvProxy.itemid = kCC13XX_26XXMatter_ItemID_ChipKVS_key; nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; /* Lock and wipe all items with kvs_key itemid */ @@ -462,8 +475,8 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) VerifyOrExit(status == NVINTF_NOTFOUND, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); /* Setup doNext call */ - nvProxy.sysid = kCC13X2_26X2Matter_SysID; - nvProxy.itemid = kCC13X2_26X2Matter_ItemID_ChipKVS_value; + nvProxy.sysid = kCC13XX_26XXMatter_SysID; + nvProxy.itemid = kCC13XX_26XXMatter_ItemID_ChipKVS_value; nvProxy.flag = NVINTF_DOSTART | NVINTF_DOITMID | NVINTF_DODELETE; /* Lock and wipe all items with key_value itemid */ @@ -485,10 +498,10 @@ CHIP_ERROR CC13X2_26X2Config::FactoryResetConfig(void) return err; } -void CC13X2_26X2Config::RunConfigUnitTest() +void CC13XX_26XXConfig::RunConfigUnitTest() { // Run common unit test. - ::chip::DeviceLayer::Internal::RunConfigUnitTest(); + ::chip::DeviceLayer::Internal::RunConfigUnitTest(); } } // namespace Internal diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h b/src/platform/cc13xx_26xx/CC13XX_26XXConfig.h similarity index 89% rename from src/platform/cc13x2_26x2/CC13X2_26X2Config.h rename to src/platform/cc13xx_26xx/CC13XX_26XXConfig.h index f3e8191aeca011..2450c0f8c50544 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.h +++ b/src/platform/cc13xx_26xx/CC13XX_26XXConfig.h @@ -19,7 +19,7 @@ /** * @file * Utilities for accessing persisted device configuration on - * Texas Instruments cc13x2_26x2 SoCs. + * Texas Instruments cc13xx_26xx SoCs. */ #pragma once @@ -32,7 +32,7 @@ namespace chip { namespace DeviceLayer { namespace Internal { -class CC13X2_26X2Config +class CC13XX_26XXConfig { public: struct Key; @@ -46,13 +46,13 @@ class CC13X2_26X2Config static constexpr uint16_t kNVinf_itemid_chipKVS_key = 4; static constexpr uint16_t kNVinf_itemid_chipKVS_value = 5; - static const uint16_t kCC13X2_26X2Matter_SysID = kNvinf_sysid_chip; + static const uint16_t kCC13XX_26XXMatter_SysID = kNvinf_sysid_chip; - static const uint16_t kCC13X2_26X2Matter_ItemID_ChipConfig = kNVinf_itemid_chipConfig; - static const uint16_t kCC13X2_26X2Matter_ItemID_ChipFactory = kNVinf_itemid_chipFactory; - static const uint16_t kCC13X2_26X2Matter_ItemID_ChipCounters = kNVinf_itemid_chipCounters; - static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_key = kNVinf_itemid_chipKVS_key; - static const uint16_t kCC13X2_26X2Matter_ItemID_ChipKVS_value = kNVinf_itemid_chipKVS_value; + static const uint16_t kCC13XX_26XXMatter_ItemID_ChipConfig = kNVinf_itemid_chipConfig; + static const uint16_t kCC13XX_26XXMatter_ItemID_ChipFactory = kNVinf_itemid_chipFactory; + static const uint16_t kCC13XX_26XXMatter_ItemID_ChipCounters = kNVinf_itemid_chipCounters; + static const uint16_t kCC13XX_26XXMatter_ItemID_ChipKVS_key = kNVinf_itemid_chipKVS_key; + static const uint16_t kCC13XX_26XXMatter_ItemID_ChipKVS_value = kNVinf_itemid_chipKVS_value; // Key definitions for well-known keys. static const Key kConfigKey_SerialNum; @@ -108,14 +108,14 @@ class CC13X2_26X2Config static CHIP_ERROR ClearKVS(const char * key); }; -struct CC13X2_26X2Config::Key +struct CC13XX_26XXConfig::Key { NVINTF_itemID_t nvID; bool operator==(const Key & other) const; }; -inline bool CC13X2_26X2Config::Key::operator==(const Key & other) const +inline bool CC13XX_26XXConfig::Key::operator==(const Key & other) const { return (nvID.systemID == other.nvID.systemID && nvID.itemID == other.nvID.itemID && nvID.subID == other.nvID.subID); } diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13xx_26xx/ConfigurationManagerImpl.cpp similarity index 79% rename from src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp rename to src/platform/cc13xx_26xx/ConfigurationManagerImpl.cpp index 7d420bab1c93e2..794b6fe169ff7f 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13xx_26xx/ConfigurationManagerImpl.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include @@ -65,7 +65,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR err; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); IncreaseBootCount(); @@ -86,7 +86,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount) { - return ReadConfigValue(CC13X2_26X2Config::kConfigKey_BootCount, rebootCount); + return ReadConfigValue(CC13XX_26XXConfig::kConfigKey_BootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::IncreaseBootCount(void) @@ -94,11 +94,11 @@ CHIP_ERROR ConfigurationManagerImpl::IncreaseBootCount(void) CHIP_ERROR ret; uint32_t bootCount = 0; - ret = ReadConfigValue(CC13X2_26X2Config::kConfigKey_BootCount, bootCount); + ret = ReadConfigValue(CC13XX_26XXConfig::kConfigKey_BootCount, bootCount); if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == ret || CHIP_NO_ERROR == ret) { - ret = WriteConfigValue(CC13X2_26X2Config::kConfigKey_BootCount, bootCount + 1); + ret = WriteConfigValue(CC13XX_26XXConfig::kConfigKey_BootCount, bootCount + 1); } return ret; @@ -108,7 +108,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOp { CHIP_ERROR ret; - ret = ReadConfigValue(CC13X2_26X2Config::kConfigKey_TotalOperationalHours, totalOperationalHours); + ret = ReadConfigValue(CC13XX_26XXConfig::kConfigKey_TotalOperationalHours, totalOperationalHours); if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == ret) { @@ -121,12 +121,12 @@ CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOp CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours) { - return WriteConfigValue(CC13X2_26X2Config::kConfigKey_TotalOperationalHours, totalOperationalHours); + return WriteConfigValue(CC13XX_26XXConfig::kConfigKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2Matter_SysID, key } }; + CC13XX_26XXConfig::Key configKey{ { CC13XX_26XXConfig::kCC13XX_26XXMatter_SysID, key } }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -138,68 +138,68 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2Matter_SysID, key } }; + CC13XX_26XXConfig::Key configKey{ { CC13XX_26XXConfig::kCC13XX_26XXMatter_SysID, key } }; return WriteConfigValue(configKey, value); } CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) { - return CC13X2_26X2Config::ReadConfigValue(key, val); + return CC13XX_26XXConfig::ReadConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) { - return CC13X2_26X2Config::ReadConfigValue(key, val); + return CC13XX_26XXConfig::ReadConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) { - return CC13X2_26X2Config::ReadConfigValue(key, val); + return CC13XX_26XXConfig::ReadConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) { - return CC13X2_26X2Config::ReadConfigValueStr(key, buf, bufSize, outLen); + return CC13XX_26XXConfig::ReadConfigValueStr(key, buf, bufSize, outLen); } CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) { - return CC13X2_26X2Config::ReadConfigValueBin(key, buf, bufSize, outLen); + return CC13XX_26XXConfig::ReadConfigValueBin(key, buf, bufSize, outLen); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) { - return CC13X2_26X2Config::WriteConfigValue(key, val); + return CC13XX_26XXConfig::WriteConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) { - return CC13X2_26X2Config::WriteConfigValue(key, val); + return CC13XX_26XXConfig::WriteConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) { - return CC13X2_26X2Config::WriteConfigValue(key, val); + return CC13XX_26XXConfig::WriteConfigValue(key, val); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) { - return CC13X2_26X2Config::WriteConfigValueStr(key, str); + return CC13XX_26XXConfig::WriteConfigValueStr(key, str); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) { - return CC13X2_26X2Config::WriteConfigValueStr(key, str, strLen); + return CC13XX_26XXConfig::WriteConfigValueStr(key, str, strLen); } CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) { - return CC13X2_26X2Config::WriteConfigValueBin(key, data, dataLen); + return CC13XX_26XXConfig::WriteConfigValueBin(key, data, dataLen); } void ConfigurationManagerImpl::RunConfigUnitTest(void) { - CC13X2_26X2Config::RunConfigUnitTest(); + CC13XX_26XXConfig::RunConfigUnitTest(); } void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) @@ -208,7 +208,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = CC13X2_26X2Config::FactoryResetConfig(); + err = CC13XX_26XXConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp b/src/platform/cc13xx_26xx/ConnectivityManagerImpl.cpp similarity index 100% rename from src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp rename to src/platform/cc13xx_26xx/ConnectivityManagerImpl.cpp diff --git a/src/platform/cc13x2_26x2/DiagnosticDataProviderImpl.cpp b/src/platform/cc13xx_26xx/DiagnosticDataProviderImpl.cpp similarity index 99% rename from src/platform/cc13x2_26x2/DiagnosticDataProviderImpl.cpp rename to src/platform/cc13xx_26xx/DiagnosticDataProviderImpl.cpp index 323ca605221ae4..07eefd23ca3b9a 100644 --- a/src/platform/cc13x2_26x2/DiagnosticDataProviderImpl.cpp +++ b/src/platform/cc13xx_26xx/DiagnosticDataProviderImpl.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include diff --git a/src/platform/cc13x2_26x2/DiagnosticDataProviderImpl.h b/src/platform/cc13xx_26xx/DiagnosticDataProviderImpl.h similarity index 100% rename from src/platform/cc13x2_26x2/DiagnosticDataProviderImpl.h rename to src/platform/cc13xx_26xx/DiagnosticDataProviderImpl.h diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp b/src/platform/cc13xx_26xx/KeyValueStoreManagerImpl.cpp similarity index 89% rename from src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp rename to src/platform/cc13xx_26xx/KeyValueStoreManagerImpl.cpp index 5227b55e5e65df..b92f80085da5aa 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc13xx_26xx/KeyValueStoreManagerImpl.cpp @@ -28,7 +28,7 @@ #include -#include +#include namespace chip { namespace DeviceLayer { @@ -49,7 +49,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); } - err = CC13X2_26X2Config::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); + err = CC13XX_26XXConfig::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -62,12 +62,12 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - return CC13X2_26X2Config::WriteKVS(key, value, value_size); + return CC13XX_26XXConfig::WriteKVS(key, value, value_size); } CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) { - return CC13X2_26X2Config::ClearKVS(key); + return CC13XX_26XXConfig::ClearKVS(key); } } // namespace PersistedStorage diff --git a/src/platform/cc13x2_26x2/Logging.cpp b/src/platform/cc13xx_26xx/Logging.cpp similarity index 71% rename from src/platform/cc13x2_26x2/Logging.cpp rename to src/platform/cc13xx_26xx/Logging.cpp index 1fb240c2c10d44..b7ba49ba784dd8 100644 --- a/src/platform/cc13x2_26x2/Logging.cpp +++ b/src/platform/cc13xx_26xx/Logging.cpp @@ -11,31 +11,27 @@ #include "ti_drivers_config.h" -#include +#include #include -UART_Handle sDebugUartHandle; +UART2_Handle sDebugUartHandle; char sDebugUartBuffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; -#if MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED -extern "C" int cc13x2_26x2LogInit(void) +#if MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED +extern "C" int cc13xx_26xxLogInit(void) { - UART_Params uartParams; + UART2_Params uartParams; - UART_init(); - - UART_Params_init(&uartParams); + UART2_Params_init(&uartParams); // Most params can be default because we only send data, we don't receive uartParams.baudRate = 115200; - // unclear why the UART driver sticks in writing sometimes - uartParams.writeTimeout = 10000; // ticks - sDebugUartHandle = UART_open(CONFIG_UART_DEBUG, &uartParams); + sDebugUartHandle = UART2_open(CONFIG_UART_DEBUG, &uartParams); return 0; } -extern "C" void cc13x2_26x2VLog(const char * msg, va_list v) +extern "C" void cc13xx_26xxVLog(const char * msg, va_list v) { int ret; @@ -47,17 +43,17 @@ extern "C" void cc13x2_26x2VLog(const char * msg, va_list v) sDebugUartBuffer[len - 2] = '\r'; sDebugUartBuffer[len - 1] = '\n'; - UART_write(sDebugUartHandle, sDebugUartBuffer, len); + UART2_write(sDebugUartHandle, sDebugUartBuffer, len, NULL); } } #else /* log functins defined somewhere else */ -extern "C" int cc13x2_26x2LogInit(void); -extern "C" void cc13x2_26x2VLog(const char * msg, va_list v); +extern "C" int cc13xx_26xxLogInit(void); +extern "C" void cc13xx_26xxVLog(const char * msg, va_list v); -#endif // MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED +#endif // MATTER_CC13XX_26XX_PLATFORM_LOG_ENABLED namespace chip { namespace DeviceLayer { @@ -81,7 +77,7 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) (void) module; (void) category; - cc13x2_26x2VLog(msg, v); + cc13xx_26xxVLog(msg, v); chip::DeviceLayer::OnLogOutput(); } @@ -100,7 +96,7 @@ extern "C" void LwIPLog(const char * msg, ...) va_start(v, msg); - cc13x2_26x2VLog(msg, v); + cc13xx_26xxVLog(msg, v); chip::DeviceLayer::OnLogOutput(); va_end(v); @@ -110,13 +106,13 @@ extern "C" void LwIPLog(const char * msg, ...) /** * Platform log output function. */ -extern "C" void cc13x2_26x2Log(const char * msg, ...) +extern "C" void cc13xx_26xxLog(const char * msg, ...) { va_list v; va_start(v, msg); - cc13x2_26x2VLog(msg, v); + cc13xx_26xxVLog(msg, v); chip::DeviceLayer::OnLogOutput(); va_end(v); @@ -132,7 +128,7 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch va_start(v, aFormat); - cc13x2_26x2VLog(aFormat, v); + cc13xx_26xxVLog(aFormat, v); chip::DeviceLayer::OnLogOutput(); va_end(v); diff --git a/src/platform/cc13x2_26x2/OTAImageProcessorImpl.cpp b/src/platform/cc13xx_26xx/OTAImageProcessorImpl.cpp similarity index 100% rename from src/platform/cc13x2_26x2/OTAImageProcessorImpl.cpp rename to src/platform/cc13xx_26xx/OTAImageProcessorImpl.cpp diff --git a/src/platform/cc13x2_26x2/OTAImageProcessorImpl.h b/src/platform/cc13xx_26xx/OTAImageProcessorImpl.h similarity index 100% rename from src/platform/cc13x2_26x2/OTAImageProcessorImpl.h rename to src/platform/cc13xx_26xx/OTAImageProcessorImpl.h diff --git a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp b/src/platform/cc13xx_26xx/PlatformManagerImpl.cpp similarity index 97% rename from src/platform/cc13x2_26x2/PlatformManagerImpl.cpp rename to src/platform/cc13xx_26xx/PlatformManagerImpl.cpp index be7a427b57c52a..2cd8c01ca47a0c 100644 --- a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp +++ b/src/platform/cc13xx_26xx/PlatformManagerImpl.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -105,7 +105,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) CHIP_ERROR err; // Initialize the configuration system. - err = Internal::CC13X2_26X2Config::Init(); + err = Internal::CC13XX_26XXConfig::Init(); SuccessOrExit(err); // DMM Addition diff --git a/src/platform/cc13x2_26x2/Random.c b/src/platform/cc13xx_26xx/Random.c similarity index 100% rename from src/platform/cc13x2_26x2/Random.c rename to src/platform/cc13xx_26xx/Random.c diff --git a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp b/src/platform/cc13xx_26xx/ThreadStackManagerImpl.cpp similarity index 94% rename from src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp rename to src/platform/cc13xx_26xx/ThreadStackManagerImpl.cpp index c62fa61460f9fb..caffe8443b6bbd 100644 --- a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.cpp +++ b/src/platform/cc13xx_26xx/ThreadStackManagerImpl.cpp @@ -36,7 +36,7 @@ #include // platform folder in the TI SDK example application -#include +#include // DMM Includes #ifdef USE_DMM @@ -88,7 +88,10 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst) #endif /* OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE != 0 */ // Initialize the OpenThread platform layer - otSysInit(0, NULL); + platformAlarmInit(); + platformAlarmMicroInit(); + platformRandomInit(); + platformRadioInit(); #ifdef USE_DMM // DMM Init @@ -119,6 +122,19 @@ void ThreadStackManagerImpl::_SendProcMessage(ThreadStackManagerImpl::procQueueM SignalThreadActivityPendingFromISR(); } +extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize) +{ + return chip::Platform::MemoryCalloc(aNum, aSize); +} + +extern "C" void otPlatFree(void * aPtr) +{ + if (aPtr != nullptr) + { + chip::Platform::MemoryFree(aPtr); + } +} + void ThreadStackManagerImpl::_ProcMessage(otInstance * aInstance) { procQueueMsg procMsg; @@ -141,11 +157,6 @@ void ThreadStackManagerImpl::_ProcMessage(otInstance * aInstance) break; } - case procQueueCmd_random: { - platformRandomProcess(); - break; - } - case procQueueCmd_alarmu: { platformAlarmMicroProcess(aInstance); break; diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/BLEManagerImpl.h similarity index 99% rename from src/platform/cc13x2_26x2/BLEManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/BLEManagerImpl.h index d43ecddefba178..34c517ed1c166b 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/BLEManagerImpl.h @@ -19,7 +19,7 @@ /** * @file * Provides an implementation of the BLEManager object for the Texas - * Instruments cc13xx_cc26xx platform. + * Instruments CC13XX_26XX platform. */ #pragma once @@ -191,7 +191,7 @@ typedef struct } PasscodeData_t; /** - * Concrete implementation of the BLEManager singleton object for cc13x2_cc26x2. + * Concrete implementation of the BLEManager singleton object for CC13XX_26XX. */ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePlatformDelegate, private BleApplicationDelegate @@ -349,7 +349,7 @@ inline BLEManager & BLEMgr(void) * Returns the platform-specific implementation of the BLEManager singleton object. * * Internal components can use this to gain access to features of the BLEManager - * that are specific to the cc13x2_cc26x2 platforms. + * that are specific to the CC13XX_26XX platforms. */ inline BLEManagerImpl & BLEMgrImpl(void) { diff --git a/src/platform/cc13x2_26x2/BUILD.gn b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn similarity index 76% rename from src/platform/cc13x2_26x2/BUILD.gn rename to src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn index 85d3fde0466553..133580e80169dc 100644 --- a/src/platform/cc13x2_26x2/BUILD.gn +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn @@ -24,26 +24,25 @@ if (chip_enable_openthread) { static_library("cc13x2_26x2") { sources = [ - "../FreeRTOS/SystemTimeSupport.cpp", - "../SingletonConfigurationManager.cpp", + "../../FreeRTOS/SystemTimeSupport.cpp", + "../../SingletonConfigurationManager.cpp", + "../CC13XX_26XXConfig.cpp", + "../CC13XX_26XXConfig.h", + "../ConfigurationManagerImpl.cpp", + "../ConnectivityManagerImpl.cpp", + "../DiagnosticDataProviderImpl.cpp", + "../DiagnosticDataProviderImpl.h", + "../KeyValueStoreManagerImpl.cpp", + "../Logging.cpp", + "../PlatformManagerImpl.cpp", + "../Random.c", "BlePlatformConfig.h", - "CC13X2_26X2Config.cpp", - "CC13X2_26X2Config.h", - "CHIPDevicePlatformConfig.h", "CHIPDevicePlatformConfig.h", "CHIPDevicePlatformEvent.h", - "ConfigurationManagerImpl.cpp", - "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", - "DiagnosticDataProviderImpl.cpp", - "DiagnosticDataProviderImpl.h", "InetPlatformConfig.h", - "KeyValueStoreManagerImpl.cpp", "KeyValueStoreManagerImpl.h", - "Logging.cpp", - "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", - "Random.c", "SystemPlatformConfig.h", ] @@ -58,7 +57,7 @@ static_library("cc13x2_26x2") { if (chip_enable_ble) { sources += [ - "BLEManagerImpl.cpp", + "../BLEManagerImpl.cpp", "BLEManagerImpl.h", ] } @@ -68,8 +67,8 @@ static_library("cc13x2_26x2") { # this needs to be in the final link to place the data correctly # see ${chip_root}/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni #"oad_image_header.c", - "OTAImageProcessorImpl.cpp", - "OTAImageProcessorImpl.h", + "../OTAImageProcessorImpl.cpp", + "../OTAImageProcessorImpl.h", ] } @@ -78,6 +77,7 @@ static_library("cc13x2_26x2") { import("//build_overrides/ti_simplelink_sdk.gni") import("${ti_simplelink_sdk_build_root}/ti_simplelink_board.gni") public_deps += [ + "${chip_root}/third_party/openthread/platforms/cc13x2_26x2:libopenthread-cc13x2_cc26x2", "${chip_root}/third_party/ti_simplelink_sdk:mbedtls", "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sdk", "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", @@ -92,13 +92,13 @@ static_library("cc13x2_26x2") { } sources += [ - "../OpenThread/OpenThreadUtils.cpp", - "ThreadStackManagerImpl.cpp", + "../../OpenThread/OpenThreadUtils.cpp", + "../ThreadStackManagerImpl.cpp", "ThreadStackManagerImpl.h", ] if (chip_mdns == "platform") { - sources += [ "../OpenThread/DnssdImpl.cpp" ] + sources += [ "../../OpenThread/DnssdImpl.cpp" ] deps += [ "${chip_root}/src/lib/dnssd:platform_header" ] } } diff --git a/src/platform/cc13x2_26x2/BlePlatformConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/BlePlatformConfig.h similarity index 93% rename from src/platform/cc13x2_26x2/BlePlatformConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/BlePlatformConfig.h index a4745eb8e95f3c..8924b62d9b33c6 100644 --- a/src/platform/cc13x2_26x2/BlePlatformConfig.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/BlePlatformConfig.h @@ -19,7 +19,7 @@ /** * @file * Platform-specific configuration overrides for the CHIP BLE - * Layer for the Texas Instruments CC1352 platform. + * Layer for the Texas Instruments CC13XX_26XX platform. * * NOTE: Empty because BLE is not enabled, but build defines this file * to be included by the build configuration. diff --git a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformConfig.h similarity index 96% rename from src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformConfig.h index cc2470e9c3a7b6..13a5e6900dbb1d 100644 --- a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformConfig.h @@ -19,7 +19,7 @@ /** * @file * Platform-specific configuration overrides for the chip Device Layer - * for the Texas Instruments CC2652R7 platform. + * for the Texas Instruments CC13XX_CC26XX platform. */ #pragma once diff --git a/src/platform/cc13x2_26x2/CHIPDevicePlatformEvent.h b/src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformEvent.h similarity index 94% rename from src/platform/cc13x2_26x2/CHIPDevicePlatformEvent.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformEvent.h index ea5b2f05b78324..f647b595d02990 100644 --- a/src/platform/cc13x2_26x2/CHIPDevicePlatformEvent.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/CHIPDevicePlatformEvent.h @@ -19,7 +19,7 @@ /** * @file * Defines platform-specific event types and data for the chip - * for the Texas Instruments CC1352 platform. + * for the Texas Instruments CC13XX_26XX platform. * * NOTE: currently a bare-bones implementation to allow for building. */ diff --git a/src/platform/cc13x2_26x2/CHIPPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/CHIPPlatformConfig.h similarity index 100% rename from src/platform/cc13x2_26x2/CHIPPlatformConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/CHIPPlatformConfig.h diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/ConfigurationManagerImpl.h similarity index 97% rename from src/platform/cc13x2_26x2/ConfigurationManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/ConfigurationManagerImpl.h index 44cafee006ff55..17ec853af5e9e0 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/ConfigurationManagerImpl.h @@ -24,7 +24,7 @@ #pragma once -#include +#include #include namespace chip { @@ -33,7 +33,7 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the CC13X2_26X2 platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { public: // This returns an instance of this class. diff --git a/src/platform/cc13x2_26x2/ConnectivityManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/ConnectivityManagerImpl.h similarity index 97% rename from src/platform/cc13x2_26x2/ConnectivityManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/ConnectivityManagerImpl.h index 5abed2848f065f..44c0e764b391a7 100644 --- a/src/platform/cc13x2_26x2/ConnectivityManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/ConnectivityManagerImpl.h @@ -18,7 +18,7 @@ /** * @file * Platform-specific connectivity manager class for the Texas - * Instruments CC1352 platform. + * Instruments CC13XX_26XX platform. */ #pragma once @@ -45,7 +45,7 @@ namespace chip { namespace DeviceLayer { /** - * Concrete implementation of the ConnectivityManager singleton object for the CC13X2_26X2 platforms. + * Concrete implementation of the ConnectivityManager singleton object for the CC13XX_26XX platforms. */ class ConnectivityManagerImpl final : public ConnectivityManager, public Internal::GenericConnectivityManagerImpl, @@ -98,7 +98,7 @@ inline ConnectivityManager & ConnectivityMgr(void) * 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 CC1352 platform + * that are specific to the platform */ inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) { diff --git a/src/platform/cc13x2_26x2/FreeRTOSConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/FreeRTOSConfig.h similarity index 100% rename from src/platform/cc13x2_26x2/FreeRTOSConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/FreeRTOSConfig.h diff --git a/src/platform/cc13x2_26x2/InetPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/InetPlatformConfig.h similarity index 100% rename from src/platform/cc13x2_26x2/InetPlatformConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/InetPlatformConfig.h diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/KeyValueStoreManagerImpl.h similarity index 99% rename from src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/KeyValueStoreManagerImpl.h index bd70c08df860b6..45396e4544b7aa 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/KeyValueStoreManagerImpl.h @@ -18,7 +18,7 @@ /** * @file - * Platform-specific key value storage implementation for CC1352. + * Platform-specific key value storage implementation for CC13XX_26XX. */ #pragma once diff --git a/src/platform/cc13x2_26x2/PlatformManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/PlatformManagerImpl.h similarity index 97% rename from src/platform/cc13x2_26x2/PlatformManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/PlatformManagerImpl.h index 8275e861c4376e..0cf7ea893b6634 100644 --- a/src/platform/cc13x2_26x2/PlatformManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/PlatformManagerImpl.h @@ -30,7 +30,7 @@ namespace DeviceLayer { /** * Concrete implementation of the PlatformManager singleton object for the - * CC13X2_26X2 platform. + * CC13XX_26XX platform. */ class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS { @@ -84,7 +84,7 @@ inline PlatformManager & PlatformMgr(void) * singleton object. * * chip applications can use this to gain access to features of the - * PlatformManager that are specific to the CC1352 SoC. + * PlatformManager that are specific to the SoC. */ inline PlatformManagerImpl & PlatformMgrImpl(void) { diff --git a/src/platform/cc13x2_26x2/SystemPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x2_26x2/SystemPlatformConfig.h similarity index 100% rename from src/platform/cc13x2_26x2/SystemPlatformConfig.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/SystemPlatformConfig.h diff --git a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.h b/src/platform/cc13xx_26xx/cc13x2_26x2/ThreadStackManagerImpl.h similarity index 97% rename from src/platform/cc13x2_26x2/ThreadStackManagerImpl.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/ThreadStackManagerImpl.h index 80965d5c4469f7..c7377336a2f38f 100644 --- a/src/platform/cc13x2_26x2/ThreadStackManagerImpl.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/ThreadStackManagerImpl.h @@ -19,7 +19,7 @@ /** * @file * Provides an implementation of the ThreadStackManager object - * for the Texas Instruments CC1352 platform. + * for the Texas Instruments CC13XX_26XX platform. * * NOTE: currently a bare-bones implementation to allow for building. */ @@ -46,7 +46,7 @@ class ThreadStackManager; class ThreadStackManagerImpl; /** - * Concrete implementation of the ThreadStackManager singleton object for CC1352. + * Concrete implementation of the ThreadStackManager singleton object for CC13XX_26XX. */ class ThreadStackManagerImpl final : public ThreadStackManager, public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, @@ -78,7 +78,6 @@ class ThreadStackManagerImpl final : public ThreadStackManager, procQueueCmd_radio, procQueueCmd_tasklets, procQueueCmd_uart, - procQueueCmd_random, procQueueCmd_alarmu, }; @@ -132,7 +131,7 @@ inline ThreadStackManager & ThreadStackMgr(void) * Returns the platform-specific implementation of the ThreadStackManager singleton object. * * chip applications can use this to gain access to features of the ThreadStackManager - * that are specific to CC1352 SoC. + * that are specific to SoC. */ inline ThreadStackManagerImpl & ThreadStackMgrImpl(void) { diff --git a/src/platform/cc13x2_26x2/args.gni b/src/platform/cc13xx_26xx/cc13x2_26x2/args.gni similarity index 97% rename from src/platform/cc13x2_26x2/args.gni rename to src/platform/cc13xx_26xx/cc13x2_26x2/args.gni index 7963e911e3e648..4ff86939ff74a0 100644 --- a/src/platform/cc13x2_26x2/args.gni +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/args.gni @@ -26,7 +26,7 @@ openthread_external_mbedtls = mbedtls_target openthread_external_platform = "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" -lwip_platform = "cc13x2_26x2" +lwip_platform = "cc13xx_26xx" chip_inet_config_enable_ipv4 = false diff --git a/src/platform/cc13x2_26x2/ble_user_config.c b/src/platform/cc13xx_26xx/cc13x2_26x2/ble_user_config.c similarity index 100% rename from src/platform/cc13x2_26x2/ble_user_config.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/ble_user_config.c diff --git a/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos.lds b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos.lds new file mode 100644 index 00000000000000..c5d4aa88e6f4bf --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos.lds @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== CC26X2R1_LAUNCHXL_FREERTOS.lds ======== + * Default Linker script for the Texas Instruments CC26X2R1 + */ + + + FLASH_ROM_BUILD = 2; + FLASH_BASE = 0x00000000 ; + GPRAM_BASE = 0x11000000 ; + RAM_BASE = 0x20000000 ; + ROM_BASE = 0x10000000 ; + + FLASH_SIZE = 0x00058000 ; + GPRAM_SIZE = 0x00002000 ; + RAM_SIZE = 0x00014000 ; + ROM_SIZE = 0x00040000 ; + + RTOS_RAM_SIZE = 0x0000012C; + RESERVED_RAM_SIZE_ROM_1 = 0x00000B08; + RESERVED_RAM_SIZE_ROM_2 = 0x00000EB3; + + PAGE_SIZE = 0x2000; +RTOS_RAM_SIZE = 0x0000012C; +RESERVED_RAM_SIZE_ROM_2 = 0x00000EB3; + + + RESERVED_RAM_SIZE_AT_START = (RTOS_RAM_SIZE + RESERVED_RAM_SIZE_ROM_2); + RESERVED_RAM_SIZE_AT_END = 0; + + + RAM_START = (RAM_BASE + RESERVED_RAM_SIZE_AT_START); + + + RAM_END = (RAM_BASE + RAM_SIZE - RESERVED_RAM_SIZE_AT_END - 1); + + +/* For ROM 2 devices, the following section needs to be allocated and reserved */ + RTOS_RAM_START = RAM_BASE; + RTOS_RAM_END = (RAM_BASE + RTOS_RAM_SIZE - 1); + + FLASH_START = FLASH_BASE; + WORD_SIZE = 4; + + FLASH_MEM_ALIGN = WORD_SIZE; + + PAGE_MASK = 0xFFFFE000; + + NUM_RESERVED_FLASH_PAGES = 1; + RESERVED_FLASH_SIZE = (NUM_RESERVED_FLASH_PAGES * PAGE_SIZE); + + FLASH_END = (FLASH_BASE + FLASH_SIZE - RESERVED_FLASH_SIZE - 1); + + FLASH_LAST_PAGE_START = (FLASH_SIZE - PAGE_SIZE); + +/* +__STACK_TOP = __stack + __STACK_SIZE; + + +__UNUSED_SRAM_start__ = RAM_BASE; +__UNUSED_SRAM_end__ = RAM_BASE + RAM_SIZE; + +__UNUSED_FLASH_start__ = FLASH_BASE; +__UNUSED_FLASH_end__ = FLASH_BASE + FLASH_SIZE; +*/ + + +MEMORY +{ + FLASH (RX) : ORIGIN = FLASH_START, LENGTH = (FLASH_END - FLASH_START + 1) + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash, 40 bytes + */ + /* FLASH_CCFG (RX) : ORIGIN = FLASH_LAST_PAGE_START, LENGTH = PAGE_SIZE */ + FLASH_CCFG (RX) : ORIGIN = 0x00057fa8, LENGTH = 0x00000058 + + + RTOS_SRAM (RWX) : ORIGIN = RTOS_RAM_START, LENGTH = (RTOS_RAM_END - RTOS_RAM_START + 1) + SRAM (RWX) : ORIGIN = 0x20000000 + RESERVED_RAM_SIZE_ROM_2 + RTOS_RAM_SIZE, LENGTH = (RAM_END - RAM_START + 1) + /* GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 */ +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x0); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000 + RESERVED_RAM_SIZE_ROM_2 + RTOS_RAM_SIZE); + + .ramVecs (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* if a ROM-only symbol is present, then ROM is being used. + * Reserve memory for surgically placed module states. + */ + _rom_data_start = 0x20000100; + _rom_data_size = DEFINED(ROM_DATA_SIZE) ? 12 : DEFINED(ROM_DATA_SIZE_NO_OAD) ? 0x108 : 0; + + .rom_data_reserve (_rom_data_start): { + . += _rom_data_size; + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_1800, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20001800; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + + + /* if a ROM-only symbol is present, then ROM is being used. + * Reserve memory for surgically placed config constants. + */ + _rom_rodata_start = 0x2000; + _rom_rodata_size = DEFINED(ROM_RODATA_SIZE) ? 0 : DEFINED(ROM_RODATA_SIZE_NO_OAD) ? 0x330 : 0; + + .rom_rodata_reserve (_rom_rodata_start): { + . += _rom_rodata_size; + } > REGION_TEXT AT> REGION_TEXT + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + + + .nvs (0x52000) (NOLOAD) : AT (0x52000) ALIGN(0x2000) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)). + += 0x800; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + +} + +ENTRY(resetISR) diff --git a/src/platform/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds similarity index 97% rename from src/platform/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds rename to src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds index d470eea96a1888..7424c4c92c7f4c 100644 --- a/src/platform/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds @@ -22,6 +22,8 @@ */ STACKSIZE = 0x800; +RESERVED_RAM_SIZE_BLE_ROM = 0x00000FDF; + MEMORY { @@ -29,9 +31,9 @@ MEMORY /* FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x000affa8 */ /* FLASH_CCFG (RX) : ORIGIN = 0x000affa8, LENGTH = 0x00000058 */ FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x000ae000 - /* BLE ROM reserves RAM at the beginning of the ram image */ + /* BLE ROM reserves RAM at the beginning of the ram image, size RESERVED_RAM_SIZE_BLE_ROM */ /* SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00024000 */ - SRAM (RWX) : ORIGIN = 0x20000fdf, LENGTH = 0x00023021 + SRAM (RWX) : ORIGIN = 0x20000FDF, LENGTH = 0x00023021 GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 /* Explicitly placed off target for the storage of logging data. * The data placed here is NOT loaded onto the target device. @@ -69,9 +71,9 @@ SECTIONS { } > REGION_TEXT PROVIDE (_vtable_base_address = - DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000); + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000 + RESERVED_RAM_SIZE_BLE_ROM); - .vtable (_vtable_base_address) (NOLOAD) : { + .ramVecs (_vtable_base_address) (NOLOAD) : { KEEP (*(.ramVecs)) } > REGION_DATA diff --git a/src/platform/cc13x2_26x2/crypto/aes_alt.c b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/aes_alt.c similarity index 100% rename from src/platform/cc13x2_26x2/crypto/aes_alt.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/aes_alt.c diff --git a/src/platform/cc13x2_26x2/crypto/aes_alt.h b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/aes_alt.h similarity index 100% rename from src/platform/cc13x2_26x2/crypto/aes_alt.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/aes_alt.h diff --git a/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h similarity index 97% rename from src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h index af111ccb58a9d7..a005f6bf804905 100644 --- a/src/platform/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/cc13x2_26x2-mbedtls-config.h @@ -40,8 +40,8 @@ /* Enable Hardware Acceleration */ //#define MBEDTLS_AES_ALT -#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT -#define MBEDTLS_ECDH_GEN_PUBLIC_ALT +//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT #define MBEDTLS_ECDSA_SIGN_ALT #define MBEDTLS_ECDSA_VERIFY_ALT #define MBEDTLS_ENTROPY_HARDWARE_ALT diff --git a/src/platform/cc13x2_26x2/crypto/ecdh_alt.c b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdh_alt.c similarity index 100% rename from src/platform/cc13x2_26x2/crypto/ecdh_alt.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdh_alt.c diff --git a/src/platform/cc13x2_26x2/crypto/ecdsa_alt.c b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdsa_alt.c old mode 100755 new mode 100644 similarity index 100% rename from src/platform/cc13x2_26x2/crypto/ecdsa_alt.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdsa_alt.c diff --git a/src/platform/cc13x2_26x2/crypto/ecjpake_alt.c b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecjpake_alt.c similarity index 100% rename from src/platform/cc13x2_26x2/crypto/ecjpake_alt.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecjpake_alt.c diff --git a/src/platform/cc13x2_26x2/crypto/ecjpake_alt.h b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecjpake_alt.h similarity index 100% rename from src/platform/cc13x2_26x2/crypto/ecjpake_alt.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecjpake_alt.h diff --git a/src/platform/cc13x2_26x2/crypto/sha256_alt.c b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/sha256_alt.c similarity index 100% rename from src/platform/cc13x2_26x2/crypto/sha256_alt.c rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/sha256_alt.c diff --git a/src/platform/cc13x2_26x2/crypto/sha256_alt.h b/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/sha256_alt.h similarity index 100% rename from src/platform/cc13x2_26x2/crypto/sha256_alt.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/crypto/sha256_alt.h diff --git a/src/platform/cc13x2_26x2/openthread-core-cc13x2_26x2-config-check.h b/src/platform/cc13xx_26xx/cc13x2_26x2/openthread-core-cc13x2_26x2-config-check.h similarity index 100% rename from src/platform/cc13x2_26x2/openthread-core-cc13x2_26x2-config-check.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/openthread-core-cc13x2_26x2-config-check.h diff --git a/src/platform/cc13x2_26x2/openthread-core-cc13x2_26x2-config.h b/src/platform/cc13xx_26xx/cc13x2_26x2/openthread-core-cc13x2_26x2-config.h similarity index 100% rename from src/platform/cc13x2_26x2/openthread-core-cc13x2_26x2-config.h rename to src/platform/cc13xx_26xx/cc13x2_26x2/openthread-core-cc13x2_26x2-config.h diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/BLEManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/BLEManagerImpl.h new file mode 100644 index 00000000000000..34c517ed1c166b --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/BLEManagerImpl.h @@ -0,0 +1,368 @@ +/* + * + * 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 + * Provides an implementation of the BLEManager object for the Texas + * Instruments CC13XX_26XX platform. + */ + +#pragma once + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + +#include "FreeRTOS.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include "hal_types.h" + +#include "ti_ble_config.h" +#include "ti_drivers_config.h" + +#ifdef __cplusplus +} +#endif + +#include "chipOBleProfile.h" + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +using namespace chip::Ble; + +// Internal Events for RTOS application +#define ICALL_EVT ICALL_MSG_EVENT_ID // Event_Id_31 +#define QUEUE_EVT UTIL_QUEUE_EVENT_ID // Event_Id_30 + +// Application events +#define BLEManagerIMPL_STATE_UPDATE_EVT (0) + +// 500ms interval +#define BLEMANAGERIMPL_ADV_INT_SLOW (800) +// 100ms interval (Default) +#define BLEMANAGERIMPL_ADV_INT_FAST (160) + +#define CHIPOBLE_ADV_SIZE_NO_DEVICE_ID_INFO (4) + +#define CHIPOBLE_SCANRES_SIZE_NO_NAME (6) + +#define CHIPOBLE_ADV_DATA_MAX_SIZE (GAP_DEVICE_NAME_LEN + CHIPOBLE_SCANRES_SIZE_NO_NAME) + +#define CHIPOBLE_DEVICE_DESC_LENGTH (4) + +// How often to read current current RPA (in ms) +#define READ_RPA_EVT_PERIOD 3000 + +// 15 Minute Advertisement CHIP Timeout period +#define ADV_TIMEOUT (900000) + +#define STATE_CHANGE_EVT 0 +#define CHAR_CHANGE_EVT 1 +#define CHIPOBLE_CHAR_CHANGE_EVT 2 +#define BLEManagerIMPL_CHIPOBLE_TX_IND_EVT 3 +#define ADV_EVT 4 +#define PAIR_STATE_EVT 5 +#define PASSCODE_EVT 6 +#define READ_RPA_EVT 7 +#define SEND_PARAM_UPDATE_EVT 8 +#define BLEManagerIMPL_CHIPOBLE_CLOSE_CONN_EVT 9 +#define CONN_EVT 10 + +// For storing the active connections +#define RSSI_TRACK_CHNLS 1 // Max possible channels can be GAP_BONDINGS_MAX +#define MAX_RSSI_STORE_DEPTH 5 +#define INVALID_HANDLE 0xFFFF +#define RSSI_2M_THRSHLD -30 +#define RSSI_1M_THRSHLD -40 +#define RSSI_S2_THRSHLD -50 +#define RSSI_S8_THRSHLD -60 +#define PHY_NONE LL_PHY_NONE // No PHY set +#define AUTO_PHY_UPDATE 0xFF +// Set initial values to maximum, RX is set to max. by default(251 octets, 2120us) +// Some brand smartphone is essentially needing 251/2120, so we set them here. +#define BLEMANAGER_SUGGESTED_PDU_SIZE 251 // default is 27 octets(TX) +#define BLEMANAGER_SUGGESTED_TX_TIME 2120 // default is 328us(TX) + +typedef struct +{ + uint8_t len; // data length + void * pData; // pointer to message +} CHIPoBLEIndEvt_t; + +typedef struct +{ + uint8_t paramId; // Parameter written + uint16_t len; // data length + uint16_t connHandle; // Active connection which received the write +} CHIPoBLEProfChgEvt_t; + +// App event passed from stack modules. This type is defined by the application +// since it can queue events to itself however it wants. +typedef struct +{ + uint8_t event; // event type + void * pData; // pointer to message +} QueuedEvt_t; + +// Container to store advertising event data when passing from advertising +// callback to app event. See the respective event in GapAdvScan_Event_IDs +// in gap_advertiser.h for the type that pBuf should be cast to. +typedef struct +{ + uint32_t event; + void * pBuf; +} GapAdvEventData_t; + +// Container to store information from clock expiration using a flexible array +// since data is not always needed +typedef struct +{ + uint8_t event; + uint8_t data[]; +} ClockEventData_t; + +// List element for parameter update and PHY command status lists +typedef struct +{ + List_Elem elem; + uint16_t connHandle; +} ConnHandleEntry_t; + +// Connected device information +typedef struct +{ + uint16_t connHandle; // Connection Handle + ClockP_Struct * pUpdateClock; // pointer to clock struct + int8_t rssiArr[MAX_RSSI_STORE_DEPTH]; + uint8_t rssiCntr; + int8_t rssiAvg; + bool phyCngRq; // Set to true if PHY change request is in progress + uint8_t currPhy; + uint8_t rqPhy; + uint8_t phyRqFailCnt; // PHY change request count + bool isAutoPHYEnable; // Flag to indicate auto phy change + uint16_t mtu; + ClockEventData_t * pParamUpdateEventData; +} ConnRec_t; + +// Container to store passcode data when passing from gapbondmgr callback +// to app event. See the pfnPairStateCB_t documentation from the gapbondmgr.h +// header file for more information on each parameter. +typedef struct +{ + uint8_t state; + uint16_t connHandle; + uint8_t status; +} PairStateData_t; + +// Container to store passcode data when passing from gapbondmgr callback +// to app event. See the pfnPasscodeCB_t documentation from the gapbondmgr.h +// header file for more information on each parameter. +typedef struct +{ + uint8_t deviceAddr[B_ADDR_LEN]; + uint16_t connHandle; + uint8_t uiInputs; + uint8_t uiOutputs; + uint32_t numComparison; +} PasscodeData_t; + +/** + * Concrete implementation of the BLEManager singleton object for CC13XX_26XX. + */ +class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePlatformDelegate, private BleApplicationDelegate + +{ + // Allow the BLEManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend BLEManager; + +public: + // ===== Platform-specific members that may be accessed directly by the application. + +private: + // ===== Members that implement the BLEManager internal interface. + + CHIP_ERROR _Init(void); + void _Shutdown() {} + bool _IsAdvertisingEnabled(void); + CHIP_ERROR _SetAdvertisingEnabled(bool val); + bool _IsAdvertising(void); + CHIP_ERROR _SetAdvertisingMode(BLEAdvertisingMode mode); + CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize); + CHIP_ERROR _SetDeviceName(const char * deviceName); + uint16_t _NumConnections(void); + void _OnPlatformEvent(const ChipDeviceEvent * event); + BleLayer * _GetBleLayer(void); + + // ===== Members that implement virtual methods on BlePlatformDelegate. + + bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; + uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; + + bool SendIndication(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + + // ===== Members that implement virtual methods on BleApplicationDelegate. + + void NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) override; + + const ChipBleUUID chipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, + 0x9F, 0x9D, 0x11 } }; + const ChipBleUUID chipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, + 0x9F, 0x9D, 0x12 } }; + + friend BLEManager & BLEMgr(void); + friend BLEManagerImpl & BLEMgrImpl(void); + + static BLEManagerImpl sInstance; + + /* BLE stack task handle */ + static TaskHandle_t sBleTaskHndl; + // Entity ID globally used to check for source and/or destination of messages + static ICall_EntityID sSelfEntity; + + // Event globally used to post local events and pend on system and + // local events. + static ICall_SyncHandle sSyncEvent; + static QueueHandle_t sEventHandlerMsgQueueID; + static chipOBleProfileCBs_t CHIPoBLEProfile_CBs; + static gapBondCBs_t BLEMgr_BondMgrCBs; + + enum class Flags : uint16_t + { + kAdvertisingEnabled = 0x0001, /* App enabled CHIPoBLE advertising */ + kFastAdvertisingEnabled = 0x0002, /* App enabled Fash CHIPoBLE advertising */ + kAdvertising = 0x0004, /* TI BLE stack actively advertising */ + kBLEStackInitialized = 0x0008, /* TI BLE Stack GAP/GATT Intilization complete */ + kBLEStackAdvInitialized = 0x0010, /* TI BLE Stack Advertisement Intilization complete */ + kBLEStackGATTNameUpdate = 0x0020, /* Trigger TI BLE Stack name update, must be performed prior to adv start */ + kBLEStackGATTNameSet = 0x0040, /* Device name has been set externally*/ + kAdvertisingRefreshNeeded = 0x0080, /* Advertising settings changed and it should be restarted */ + + }; + + BitFlags mFlags; + CHIPoBLEServiceMode mServiceMode; + char mDeviceName[GAP_DEVICE_NAME_LEN]; + + ConnRec_t connList[MAX_NUM_BLE_CONNS]; + // List to store connection handles for queued param updates + List_List paramUpdateList; + + // Advertising handles + uint8_t advHandleLegacy; + // Address mode + GAP_Addr_Modes_t addrMode = DEFAULT_ADDRESS_MODE; + // Current Random Private Address + uint8_t rpa[B_ADDR_LEN] = { 0 }; + + uint8_t mAdvDatachipOBle[CHIPOBLE_ADV_DATA_MAX_SIZE]; + uint8_t mScanResDatachipOBle[CHIPOBLE_ADV_DATA_MAX_SIZE]; + + ClockP_Struct clkRpaRead; + ClockP_Struct clkAdvTimeout; + // Memory to pass RPA read event ID to clock handler + ClockEventData_t argRpaRead = { .event = READ_RPA_EVT }; + + // ===== Private BLE Stack Helper functions. + void ConfigureAdvertisements(void); + void EventHandler_init(void); + void InitPHYRSSIArray(void); + CHIP_ERROR CreateEventHandler(void); + uint8_t ProcessStackEvent(ICall_Hdr * pMsg); + void ProcessEvtHdrMsg(QueuedEvt_t * pMsg); + void ProcessGapMessage(gapEventHdr_t * pMsg); + uint8_t ProcessGATTMsg(gattMsgEvent_t * pMsg); + void ProcessAdvEvent(GapAdvEventData_t * pEventData); + CHIP_ERROR ProcessParamUpdate(uint16_t connHandle); + status_t EnqueueEvtHdrMsg(uint8_t event, void * pData); + uint8_t AddBLEConn(uint16_t connHandle); + uint8_t RemoveBLEConn(uint16_t connHandle); + uint8_t GetBLEConnIndex(uint16_t connHandle) const; + uint8_t ClearBLEConnListEntry(uint16_t connHandle); + void ClearPendingBLEParamUpdate(uint16_t connHandle); + void UpdateBLERPA(void); + + static void HandleIncomingBleConnection(Ble::BLEEndPoint * bleEP); + + /* Static helper function */ + static void EventHandler(void * arg); + static CHIP_ERROR DriveBLEState(void); + + /* Declared static to acquire function ptr */ + static void advCallback(uint32_t event, void * pBuf, uintptr_t arg); + static void ClockHandler(uintptr_t arg); + static void AdvTimeoutHandler(uintptr_t arg); + static void FastAdvTimeoutHandler(uintptr_t arg); + static void CHIPoBLEProfile_charValueChangeCB(uint8_t paramId, uint16_t len, uint16_t connHandle); + static void PasscodeCb(uint8_t * pDeviceAddr, uint16_t connHandle, uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison); + static void PairStateCb(uint16_t connHandle, uint8_t state, uint8_t status); + static void AssertHandler(uint8 assertCause, uint8 assertSubcause); +}; + +/** + * Returns a reference to the public interface of the BLEManager singleton object. + * + * Internal components should use this to access features of the BLEManager object + * that are common to all platforms. + */ +inline BLEManager & BLEMgr(void) +{ + return BLEManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the BLEManager singleton object. + * + * Internal components can use this to gain access to features of the BLEManager + * that are specific to the CC13XX_26XX platforms. + */ +inline BLEManagerImpl & BLEMgrImpl(void) +{ + return BLEManagerImpl::sInstance; +} + +inline BleLayer * BLEManagerImpl::_GetBleLayer() +{ + return this; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn new file mode 100644 index 00000000000000..8c2cac58e4abd0 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn @@ -0,0 +1,105 @@ +# 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 == "cc13x4_26x4") + +if (chip_enable_openthread) { + import("//build_overrides/openthread.gni") +} + +static_library("cc13x4_26x4") { + sources = [ + "../../FreeRTOS/SystemTimeSupport.cpp", + "../../SingletonConfigurationManager.cpp", + "../CC13XX_26XXConfig.cpp", + "../CC13XX_26XXConfig.h", + "../ConfigurationManagerImpl.cpp", + "../ConnectivityManagerImpl.cpp", + "../DiagnosticDataProviderImpl.cpp", + "../DiagnosticDataProviderImpl.h", + "../KeyValueStoreManagerImpl.cpp", + "../Logging.cpp", + "../PlatformManagerImpl.cpp", + "../Random.c", + "BlePlatformConfig.h", + "CHIPDevicePlatformConfig.h", + "CHIPDevicePlatformEvent.h", + "ConnectivityManagerImpl.h", + "InetPlatformConfig.h", + "KeyValueStoreManagerImpl.h", + "PlatformManagerImpl.h", + "SystemPlatformConfig.h", + ] + + deps = [] + + public_deps = [ + "${chip_root}/src/crypto", + "${chip_root}/src/platform:platform_base", + ] + public_configs = + [ "${chip_root}/src/lib/address_resolve:default_address_resolve_config" ] + + if (chip_enable_ble) { + sources += [ + "../BLEManagerImpl.cpp", + "BLEManagerImpl.h", + ] + } + + if (chip_enable_ota_requestor) { + sources += [ + # this needs to be in the final link to place the data correctly + # see ${chip_root}/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni + #"oad_image_header.c", + "../OTAImageProcessorImpl.cpp", + "../OTAImageProcessorImpl.h", + ] + } + + if (chip_enable_openthread) { + # needed for MTD/FTD + import("//build_overrides/ti_simplelink_sdk.gni") + import("${ti_simplelink_sdk_build_root}/ti_simplelink_board.gni") + public_deps += [ + "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4", + "${chip_root}/third_party/ti_simplelink_sdk:mbedtls", + "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sdk", + "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig", + ] + + if (chip_openthread_ftd) { + public_deps += + [ "${chip_root}/third_party/openthread/repo:libopenthread-ftd" ] + } else { + public_deps += + [ "${chip_root}/third_party/openthread/repo:libopenthread-mtd" ] + } + + sources += [ + "../../OpenThread/OpenThreadUtils.cpp", + "../ThreadStackManagerImpl.cpp", + "ThreadStackManagerImpl.h", + ] + + if (chip_mdns == "platform") { + sources += [ "../../OpenThread/DnssdImpl.cpp" ] + deps += [ "${chip_root}/src/lib/dnssd:platform_header" ] + } + } +} diff --git a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/BlePlatformConfig.h similarity index 72% rename from examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h rename to src/platform/cc13xx_26xx/cc13x4_26x4/BlePlatformConfig.h index 30f5633cc3bc7f..db305a7b4786ae 100644 --- a/examples/all-clusters-minimal-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/BlePlatformConfig.h @@ -1,8 +1,6 @@ /* * * 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. @@ -19,11 +17,11 @@ /** * @file - * Overrides to default OpenThread configuration. + * Platform-specific configuration overrides for the CHIP BLE + * Layer for the Texas Instruments CC13XX_26XX platform. * + * NOTE: Empty because BLE is not enabled, but build defines this file + * to be included by the build configuration. */ #pragma once - -// Use the TI-supplied default platform configuration for remainder -#include "openthread-core-cc13x2_26x2-config.h" diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformConfig.h new file mode 100644 index 00000000000000..72cc68906026b5 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformConfig.h @@ -0,0 +1,55 @@ +/* + * + * 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 CC13XX_CC26XX platform. + */ + +#pragma once + +// ==================== Platform Adaptations ==================== + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 + +// ========== 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 + +// ========== CHIP Platform Configuration ========= + +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (8192) + +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (7168) + +#define BLEMANAGER_EVENT_HANDLER_STACK_SIZE (924) +#define BLEMANAGER_EVENT_HANDLER_PRIORITY (2) + +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 + +// Per 5.2.5.2. Commencement Section of CHIP spec, BLE advertisement is +// disabled for Locks and Barrier Access Devices. +#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 0 +#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1 diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformEvent.h b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformEvent.h new file mode 100644 index 00000000000000..0cb1aab8301984 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPDevicePlatformEvent.h @@ -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. + */ + +/** + * @file + * Defines platform-specific event types and data for the chip + * for the Texas Instruments CC13XX_26XX platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Represents platform-specific event information + */ +struct ChipDevicePlatformEvent final +{ +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPPlatformConfig.h new file mode 100644 index 00000000000000..70d524af217635 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/CHIPPlatformConfig.h @@ -0,0 +1,69 @@ +/* + * + * Copyright (c) 2020-2022 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 CC1352 platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#pragma once + +#include + +// ==================== General Platform Adaptations ==================== + +#define CHIP_CONFIG_ABORT() abort() + +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE uint16_t +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID 1 +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 2 + +#define CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY 0x01 + +// ==================== Security Adaptations ==================== + +#define CHIP_CONFIG_SHA256_CONTEXT_SIZE (sizeof(unsigned int) * 76) + +// ==================== General Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 8 +#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS +#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 8 +#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + +#ifndef CHIP_LOG_FILTERING +#define CHIP_LOG_FILTERING 0 +#endif // CHIP_LOG_FILTERING + +#ifndef CHIP_CONFIG_MAX_INTERFACES +#define CHIP_CONFIG_MAX_INTERFACES 4 +#endif // CHIP_CONFIG_MAX_INTERFACES + +#ifndef CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS +#define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4 +#endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS + +// Limit the number of device admins to ensure enough ressources for handling them +#ifndef CHIP_CONFIG_MAX_FABRICS +#define CHIP_CONFIG_MAX_FABRICS 5 +#endif diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/ConfigurationManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/ConfigurationManagerImpl.h new file mode 100644 index 00000000000000..b16a6269818563 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/ConfigurationManagerImpl.h @@ -0,0 +1,91 @@ +/* + * + * 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 CC1352 platform. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConfigurationManager singleton object for the CC13X2_26X2 platform. + */ +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl +{ +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + + CHIP_ERROR GetRebootCount(uint32_t & rebootCount); + CHIP_ERROR IncreaseBootCount(void); + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours); + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours); + +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); +}; + +inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +/** + * Returns the platform-specific implementation of the ConfigurationManager object. + * + * Applications can use this to gain access to features of the ConfigurationManager + * that are specific to the selected platform. + */ +ConfigurationManager & ConfigurationMgrImpl(); + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/ConnectivityManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/ConnectivityManagerImpl.h new file mode 100644 index 00000000000000..517b2552d90281 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/ConnectivityManagerImpl.h @@ -0,0 +1,108 @@ +/* + * + * 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 CC13XX_26XX platform. + */ + +#pragma once + +#include +#include +#include +#if INET_CONFIG_ENABLE_TCP_ENDPOINT +#include +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#else +#include +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#else +#include +#endif +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Concrete implementation of the ConnectivityManager singleton object for the CC13XX_26XX platforms. + */ +class ConnectivityManagerImpl final : public ConnectivityManager, + public Internal::GenericConnectivityManagerImpl, + public Internal::GenericConnectivityManagerImpl_UDP, +#if INET_CONFIG_ENABLE_TCP_ENDPOINT + public Internal::GenericConnectivityManagerImpl_TCP, +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + public Internal::GenericConnectivityManagerImpl_Thread, +#else + public Internal::GenericConnectivityManagerImpl_NoThread, +#endif + public Internal::GenericConnectivityManagerImpl_NoWiFi +{ + // 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. + + CHIP_ERROR _Init(void); + void _OnPlatformEvent(const ChipDeviceEvent * event); + + // ===== Members for internal use by the following friends. + + friend ConnectivityManager & ConnectivityMgr(void); + friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); + + static ConnectivityManagerImpl sInstance; +}; + +/** + * 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 platform + */ +inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) +{ + return ConnectivityManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/FreeRTOSConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/FreeRTOSConfig.h new file mode 100644 index 00000000000000..a3e2ae6e1baf78 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/FreeRTOSConfig.h @@ -0,0 +1,249 @@ +/* + * FreeRTOS Kernel V10.0.0 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. If you wish to use our + * Amazon FreeRTOS name, please do so in a fair use way that does not cause + * confusion. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/****************************************************************************** + See http://www.freertos.org/a00110.html for an explanation of the + definitions contained in this file. +******************************************************************************/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * 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 + *----------------------------------------------------------*/ + +/* These values are generated by SysConfig */ + +/* General options */ +#define configCPU_CLOCK_HZ ((unsigned long) (48000000)) +/* FreeRTOS heap size is 0 because currently "bget" heap is the + only heap available, for both FreeRTOS and application */ +#define configTOTAL_HEAP_SIZE ((size_t)(0)) +#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 + +/* Stack sizes, all in words */ +#define configMINIMAL_STACK_SIZE ((unsigned short) (1024)) +#define configPOSIX_STACK_SIZE ((unsigned short) (1024)) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (6) +#define configTIMER_QUEUE_LENGTH (20) +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) +#define configIDLE_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) + +/* TrustZone/PSA settings */ +/* We do not set ENABLE_TRUSTZONE, as this is only for Secure Side function call support */ +#define configENABLE_TRUSTZONE 0 +#define configRUN_FREERTOS_SECURE_ONLY 1 + +/* + * 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 +/* Enable debugging features in the UI to use the queue registry or ROV features */ +#define configQUEUE_REGISTRY_SIZE 0 + +#define configASSERT(x) \ + if ((x) == 0) \ + { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) \ + ; \ + } + +/* Modifying the options below is not permitted or currently unsupported */ + +/* ARM-v8m specific settings: floating point unit is enabled, memory protection unit is disabled */ +#define configENABLE_FPU 1 +#define configENABLE_MPU 0 + +/* The CM33 port requires an additional stack size definition */ +#define configMINIMAL_SECURE_STACK_SIZE configMINIMAL_STACK_SIZE + +/* Constants related to the behaviour or the scheduler. */ +#define configTICK_RATE_HZ ((TickType_t) 100000) +#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 that describe the hardware and memory usage. */ +#define configMAX_TASK_NAME_LEN (12) +#define configRECORD_STACK_HIGH_ADDRESS 1 + +/* Required by TI driver implementations */ +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configAPPLICATION_ALLOCATED_HEAP 1 + +/* Constants that build features in or out. */ +#define configUSE_MUTEXES 1 +#define configUSE_TICKLESS_IDLE 1 +#define configUSE_APPLICATION_TASK_TAG 1 /* Needed 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 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 2 + +#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 + +#define NDK_TLS_INDEX 1 /* Reserve an index for NDK TLS */ + +#elif defined(__GNUC__) + +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1 + +#define NDK_TLS_INDEX 0 /* Reserve an index for NDK TLS */ + +/* 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 1 +#define INCLUDE_xTaskGetIdleTaskHandle 0 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTaskResumeFromISR 0 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#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 + +/* + * Interrupt priorities used by the kernel port layer itself. These are generic + * to all Cortex-M ports, and do not rely on any particular library functions. + */ +#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* + * !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! + * See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. + * + * 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. + */ +#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 + +/* + * 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 +#endif /* FREERTOS_CONFIG_H */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/InetPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/InetPlatformConfig.h new file mode 100644 index 00000000000000..a38d274ab1b62e --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/InetPlatformConfig.h @@ -0,0 +1,34 @@ +/* + * + * 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 + +// ==================== Platform Adaptations ==================== + +#ifndef INET_CONFIG_ENABLE_IPV4 +#error Inet IPv4 configuration should be configured at build generation time +#endif + +// ========== 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 diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/KeyValueStoreManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/KeyValueStoreManagerImpl.h new file mode 100644 index 00000000000000..45396e4544b7aa --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/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 CC13XX_26XX. + */ + +#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 platform. + */ +inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void) +{ + return KeyValueStoreManagerImpl::sInstance; +} + +} // namespace PersistedStorage +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/PlatformManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/PlatformManagerImpl.h new file mode 100644 index 00000000000000..3e6851ec24eeac --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/PlatformManagerImpl.h @@ -0,0 +1,94 @@ +/* + * + * 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 + * CC13XX_26XX 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. + + System::Clock::Timestamp GetStartTime() { return mStartTime; } + +private: + // ===== Methods that implement the PlatformManager abstract interface. + + CHIP_ERROR _InitChipStack(void); + void _Shutdown(void); + + // ===== Members for internal use by the following friends. + + friend PlatformManager & PlatformMgr(void); + friend PlatformManagerImpl & PlatformMgrImpl(void); + friend class Internal::BLEManagerImpl; + + System::Clock::Timestamp mStartTime = System::Clock::kZero; + + 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 SoC. + */ +inline PlatformManagerImpl & PlatformMgrImpl(void) +{ + return PlatformManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/SystemPlatformConfig.h b/src/platform/cc13xx_26xx/cc13x4_26x4/SystemPlatformConfig.h new file mode 100644 index 00000000000000..8a65078ca2e28d --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/SystemPlatformConfig.h @@ -0,0 +1,39 @@ +/* + * + * 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 + * + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +struct ChipDeviceEvent; +} // namespace DeviceLayer +} // namespace chip + +// ==================== Platform Adaptations ==================== +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent * + +// ========== Platform-specific Configuration Overrides ========= diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/ThreadStackManagerImpl.h b/src/platform/cc13xx_26xx/cc13x4_26x4/ThreadStackManagerImpl.h new file mode 100644 index 00000000000000..afabf6069cc38f --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/ThreadStackManagerImpl.h @@ -0,0 +1,141 @@ +/* + * + * 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 ThreadStackManager object + * for the Texas Instruments CC13XX_26XX platform. + * + * NOTE: currently a bare-bones implementation to allow for building. + */ + +#pragma once + +#include +#include + +#include +#include + +#include + +extern "C" void platformAlarmSignal(); +extern "C" void platformAlarmMicroSignal(); +extern "C" void platformRadioSignal(uintptr_t arg); +extern "C" void platformUartSignal(uintptr_t arg); + +namespace chip { +namespace DeviceLayer { + +class ThreadStackManager; +class ThreadStackManagerImpl; + +/** + * Concrete implementation of the ThreadStackManager singleton object for CC13XX_26XX. + */ +class ThreadStackManagerImpl final : public ThreadStackManager, + public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP, + public Internal::GenericThreadStackManagerImpl_FreeRTOS +{ + // Allow the ThreadStackManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ThreadStackManager; + + // Allow the generic implementation base classes to call helper methods on + // this class. +#ifndef DOXYGEN_SHOULD_SKIP_THIS + friend Internal::GenericThreadStackManagerImpl_OpenThread; + friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; + friend Internal::GenericThreadStackManagerImpl_FreeRTOS; +#endif + + // Allow glue functions called by OpenThread to call helper methods on this + // class. + friend void ::platformAlarmSignal(); + friend void ::platformAlarmMicroSignal(); + friend void ::platformRadioSignal(uintptr_t arg); + friend void ::platformUartSignal(uintptr_t arg); + friend void ::otTaskletsSignalPending(otInstance * otInst); + + enum procQueueCmd + { + procQueueCmd_alarm, + procQueueCmd_radio, + procQueueCmd_tasklets, + procQueueCmd_uart, + procQueueCmd_alarmu, + }; + + struct procQueueMsg + { + enum procQueueCmd cmd; + uintptr_t arg; + }; + +public: + // ===== Platform-specific members that may be accessed directly by the application. + + using ThreadStackManager::InitThreadStack; + CHIP_ERROR InitThreadStack(otInstance * otInst); + void _SendProcMessage(procQueueMsg & procMsg); + void _ProcMessage(otInstance * aInstance); + void GetExtAddress(otExtAddress & aExtAddr); + +private: + // ===== Methods that implement the ThreadStackManager abstract interface. + + CHIP_ERROR _InitThreadStack(void); + + // ===== Members for internal use by the following friends. + + friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void); + friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void); + + static ThreadStackManagerImpl sInstance; + + static bool IsInitialized(); + + // ===== Private members for use by this class only. + + ThreadStackManagerImpl() = default; + QueueHandle_t procQueue; +}; + +/** + * Returns the public interface of the ThreadStackManager singleton object. + * + * chip applications should use this to access features of the ThreadStackManager object + * that are common to all platforms. + */ +inline ThreadStackManager & ThreadStackMgr(void) +{ + return ThreadStackManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ThreadStackManager singleton object. + * + * chip applications can use this to gain access to features of the ThreadStackManager + * that are specific to SoC. + */ +inline ThreadStackManagerImpl & ThreadStackMgrImpl(void) +{ + return ThreadStackManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/args.gni b/src/platform/cc13xx_26xx/cc13x4_26x4/args.gni new file mode 100644 index 00000000000000..35c5499e2b02f1 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/args.gni @@ -0,0 +1,37 @@ +# 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 = "cc13x4_26x4" + +mbedtls_target = "${chip_root}/third_party/ti_simplelink_sdk:mbedtls" +openthread_external_mbedtls = mbedtls_target +openthread_external_platform = + "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk" + +lwip_platform = "cc13xx_26xx" + +chip_inet_config_enable_ipv4 = false + +chip_build_tests = false + +openthread_project_core_config_file = "openthread-core-cc13x4_26x4-config.h" +openthread_core_config_platform_check_file = + "openthread-core-cc13x4_26x4-config-check.h" diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/ble_user_config.c b/src/platform/cc13xx_26xx/cc13x4_26x4/ble_user_config.c new file mode 100644 index 00000000000000..7f51e3226e565a --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/ble_user_config.c @@ -0,0 +1,560 @@ +/* + * + * 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 + * This file contains user configurable variables for the BLE Application. + * + */ + +/******************************************************************************* + * INCLUDES + */ + +#include "ble_user_config.h" +#include "hal_types.h" +#ifndef FREERTOS +#include +#endif +#ifdef SYSCFG +#include "ti_ble_config.h" +#else +#include +#endif + +#ifndef CC23X0 +#include "ble_overrides.h" +#include "ti_radio_config.h" + +#include "ecc/ECCROMCC26XX.h" +#include +#include +#include +#include +#else +#include +#include +#include +#endif + +#include +#include +#include + +#ifdef FREERTOS +#define Swi_restore SwiP_restore +#define Swi_disable SwiP_disable +#include +#else +#include +#endif +#include + +#ifndef CC23X0 +#if !defined(DeviceFamily_CC26X1) +#include +#if !defined(DeviceFamily_CC13X4) +#include +#endif +#else +#include +#endif +#endif + +/******************************************************************************* + * MACROS + */ + +/******************************************************************************* + * CONSTANTS + */ + +// Tx Power +#define NUM_TX_POWER_VALUES (RF_BLE_TX_POWER_TABLE_SIZE - 1) + +#ifndef SYSCFG +// Default Tx Power Index +#if defined(CC13X2P) +#define DEFAULT_TX_POWER HCI_EXT_TX_POWER_0_DBM +#else // !CC13X2 +#define DEFAULT_TX_POWER HCI_EXT_TX_POWER_0_DBM +#endif // CC13X2 +#endif // SYSCFG + +// Override NOP +#define OVERRIDE_NOP 0xC0000001 + +/******************************************************************************* + * TYPEDEFS + */ + +/******************************************************************************* + * LOCAL VARIABLES + */ + +/********************************************************************* + * LOCAL FUNCTIONS + */ + +void driverTable_fnSpinlock(void); + +/******************************************************************************* + * GLOBAL VARIABLES + */ + +#ifndef CC23X0 +// Tx Power Table +txPwrTbl_t appTxPwrTbl = { (txPwrVal_t *) RF_BLE_txPowerTable, + NUM_TX_POWER_VALUES, // max + DEFAULT_TX_POWER }; // default +#endif +#if defined(CC13X2P) && defined(CC13X2P_2_LAUNCHXL) + +// Tx Power Backoff Values (txPwrBackoff1MPhy,txPwrBackoff2MPhy ,txPwrBackoffCoded) +const txPwrBackoffVal_t TxPowerBackoffTable[] = { + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 0 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 1 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 2 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 3 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 4 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 5 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 6 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 7 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 8 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 9 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 10 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 11 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 12 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 13 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 14 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 15 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 16 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 17 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 18 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 19 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 20 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 21 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 22 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 23 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 24 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 25 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 26 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 27 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 28 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 29 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 30 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 31 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 32 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 33 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_17_DBM_P4_9_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 34 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_18_DBM_P4_10_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 35 + { HCI_EXT_TX_POWER_P2_19_DBM, HCI_EXT_TX_POWER_P2_18_DBM_P4_10_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 36 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 37 + { HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM }, // max tx power for channel 38 + { HCI_EXT_TX_POWER_P2_14_DBM_P4_6_DBM, HCI_EXT_TX_POWER_P2_20_DBM, HCI_EXT_TX_POWER_P2_20_DBM } +}; // max tx power for channel 39 + +txPwrBackoffTbl_t appTxPwrBackoffTbl = { TxPowerBackoffTable }; + +#endif // defined(CC13X2P) && defined(CC13X2P_2_LAUNCHXL) + +// Antenna board configurations (example for a 12-antenna board) +// Maximum number of antennas +#define ANTENNA_TABLE_SIZE 12 +// BitMask of all the relevant GPIOs which needed for the antennas +#define ANTENNA_IO_MASK BV(27) | BV(28) | BV(29) | BV(30) + +// Antenna GPIO configuration (should be adapted to the antenna board design) +antennaIOEntry_t antennaTbl[ANTENNA_TABLE_SIZE] = { + 0, // antenna 0 GPIO configuration (all GPIOs in ANTENNA_IO_MASK are LOW) + BV(28), // antenna 1 + BV(29), // antenna 2 + BV(28) | BV(29), // antenna 3 + BV(30), // antenna 4 + BV(28) | BV(30), // antenna 5 + BV(27), // antenna 6 + BV(27) | BV(28), // antenna 7 + BV(27) | BV(29), // antenna 8 + BV(27) | BV(28) | BV(29), // antenna 9 + BV(27) | BV(30), // antenna 10 + BV(27) | BV(28) | BV(30) // antenna 11 +}; + +#ifdef RTLS_CTE +// Antenna properties passes to the stack +cteAntProp_t appCTEAntProp = { ANTENNA_IO_MASK, ANTENNA_TABLE_SIZE, antennaTbl }; +#endif + +#ifdef CC23X0 +ECCParams_CurveParams eccParams_NISTP256 = { .curveType = ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3, + .length = ECCParams_NISTP256_LENGTH, + .prime = ECC_NISTP256_prime.byte, + .order = ECC_NISTP256_order.byte, + .a = ECC_NISTP256_a.byte, + .b = ECC_NISTP256_b.byte, + .generatorX = ECC_NISTP256_generatorX.byte, + .generatorY = ECC_NISTP256_generatorY.byte, + .cofactor = 1 }; +#elif !defined(DeviceFamily_CC26X1) +ECCParams_CurveParams eccParams_NISTP256 = { .curveType = ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3, + .length = NISTP256_PARAM_SIZE_BYTES, + .prime = NISTP256_prime.byte, + .order = NISTP256_order.byte, + .a = NISTP256_a.byte, + .b = NISTP256_b.byte, + .generatorX = NISTP256_generator.x.byte, + .generatorY = NISTP256_generator.y.byte, + .cofactor = 1 }; +#else +ECCParams_CurveParams eccParams_NISTP256 = { .curveType = ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3, + .length = ECC_NISTP256_PARAM_LENGTH_BYTES, + .prime = ECC_NISTP256_prime.byte, + .order = ECC_NISTP256_order.byte, + .a = ECC_NISTP256_a.byte, + .b = ECC_NISTP256_b.byte, + .generatorX = ECC_NISTP256_generatorX.byte, + .generatorY = ECC_NISTP256_generatorY.byte, + .cofactor = 1 }; +#endif + +#if defined(USE_COEX) +// 2 structures generated by the sysconfig RF for coexistence configuration +extern rfCoreHal_bleCoExConfig_t coexConfig; +extern RF_CoexOverride_BLEUseCases coexConfigBle; +// from coexConfig struct we will get the coex enable and coex type (3 or 1 wire) +// from coexConfigBle struct we will get the priority and rx request per use case: +// initiator, connected, Broadcaster and Observer. +coexUseCaseConfig_t coexSysConfig = { &coexConfig, &coexConfigBle }; +#endif + +#ifdef ICALL_JT +#include + +#ifndef CC23X0 +// RF Driver API Table +rfDrvTblPtr_t rfDriverTableBLE[] = { + (uint32) RF_open, + (uint32) driverTable_fnSpinlock, // RF_close +#ifdef RF_SINGLEMODE + (uint32) RF_postCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_postCmd +#endif // RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_pendCmd +#ifdef RF_SINGLEMODE + (uint32) RF_runCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_runCmd +#endif // RF_SINGLEMODE + (uint32) RF_cancelCmd, + (uint32) RF_flushCmd, + (uint32) driverTable_fnSpinlock, // RF_yield + (uint32) RF_Params_init, + (uint32) RF_runImmediateCmd, + (uint32) RF_runDirectCmd, + (uint32) RF_ratCompare, + (uint32) driverTable_fnSpinlock, // RF_ratCapture + (uint32) RF_ratDisableChannel, + (uint32) RF_getCurrentTime, + (uint32) RF_getRssi, + (uint32) RF_getInfo, + (uint32) RF_getCmdOp, + (uint32) RF_control, + (uint32) driverTable_fnSpinlock, // RF_getTxPower + (uint32) RF_setTxPower, // RF_setTxPower + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findPowerLevel + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findValue +#ifndef RF_SINGLEMODE + (uint32) RF_scheduleCmd, + (uint32) RF_runScheduleCmd, + (uint32) driverTable_fnSpinlock, // RF_requestAccess +#endif // !RF_SINGLEMODE +}; + +cryptoDrvTblPtr_t cryptoDriverTableBLE[] = { (uint32) AESCCM_init, + (uint32) AESCCM_open, + (uint32) AESCCM_close, + (uint32) AESCCM_Params_init, + (uint32) AESCCM_Operation_init, + (uint32) AESCCM_oneStepEncrypt, + (uint32) AESCCM_oneStepDecrypt, + (uint32) AESECB_init, + (uint32) AESECB_open, + (uint32) AESECB_close, + (uint32) AESECB_Params_init, + (uint32) AESECB_Operation_init, + (uint32) AESECB_oneStepEncrypt, + (uint32) AESECB_oneStepDecrypt, + (uint32) CryptoKeyPlaintext_initKey, + (uint32) CryptoKeyPlaintext_initBlankKey }; + +// Swi APIs needed by BLE controller +rtosApiTblPtr_t rtosApiTable[] = { (uint32_t) Swi_disable, (uint32_t) Swi_restore }; +#endif +// BLE Stack Configuration Structure +const stackSpecific_t bleStackConfig = { .maxNumConns = MAX_NUM_BLE_CONNS, + .maxNumPDUs = MAX_NUM_PDU, + .maxPduSize = 0, + .maxNumPSM = L2CAP_NUM_PSM, + .maxNumCoChannels = L2CAP_NUM_CO_CHANNELS, + .maxWhiteListElems = MAX_NUM_WL_ENTRIES, + .maxResolvListElems = CFG_MAX_NUM_RL_ENTRIES, + .pfnBMAlloc = &pfnBMAlloc, + .pfnBMFree = &pfnBMFree, +#ifndef CC23X0 + .rfDriverParams.powerUpDurationMargin = RF_POWER_UP_DURATION_MARGIN, + .rfDriverParams.inactivityTimeout = RF_INACTIVITY_TIMEOUT, + .rfDriverParams.powerUpDuration = RF_POWER_UP_DURATION, + .rfDriverParams.pErrCb = &(RF_ERR_CB), +#endif + .eccParams = &eccParams_NISTP256, + .fastStateUpdateCb = NULL, + .bleStackType = 0, +#ifdef CC2652RB_LAUNCHXL + .extStackSettings = EXTENDED_STACK_SETTINGS | CC2652RB_OVERRIDE_USED, +#else + .extStackSettings = EXTENDED_STACK_SETTINGS, +#endif +#ifndef CC23X0 + .maxNumCteBuffers = MAX_NUM_CTE_BUFS, + .advReportIncChannel = ADV_RPT_INC_CHANNEL +#endif +}; + +uint16_t bleUserCfg_maxPduSize = MAX_PDU_SIZE; + +#ifdef OSAL_SNV_EXTFLASH +const extflashDrvTblPtr_t extflashDriverTable[] = { (uint32) ExtFlash_open, (uint32) ExtFlash_close, (uint32) ExtFlash_read, + (uint32) ExtFlash_write, (uint32) ExtFlash_erase }; +#endif // OSAL_SNV_EXTFLASH + +#ifndef CC23X0 +// Table for Driver can be found in icall_user_config.c +// if a driver is not to be used, then the pointer shoul dbe set to NULL, +// for this example, this is done in ble_user_config.h +const drvTblPtr_t driverTable = { + .rfDrvTbl = rfDriverTableBLE, + .eccDrvTbl = eccDriverTable, + .cryptoDrvTbl = cryptoDriverTableBLE, + .trngDrvTbl = trngDriverTable, + .rtosApiTbl = rtosApiTable, + .nvintfStructPtr = &nvintfFncStruct, +#ifdef OSAL_SNV_EXTFLASH + .extflashDrvTbl = extflashDriverTable, +#endif // OSAL_SNV_EXTFLASH +}; +#endif + +const boardConfig_t boardConfig = { +#ifndef CC23X0 + .rfFeModeBias = RF_FE_MODE_AND_BIAS, + .rfRegTbl = (regOverride_t *) pOverrides_bleCommon, + .rfRegTbl1M = (regOverride_t *) pOverrides_ble1Mbps, + .rfRegTbl2M = (regOverride_t *) pOverrides_ble2Mbps, + .rfRegTblCoded = (regOverride_t *) pOverrides_bleCoded, + .txPwrTbl = &appTxPwrTbl, +#if defined(CC13X2P) || defined(EM_CC1354P10_1_LP) +#if defined(CC13X2P_2_LAUNCHXL) + .txPwrBackoffTbl = &appTxPwrBackoffTbl, +#else + .txPwrBackoffTbl = NULL, +#endif // defined(CC13X2P_2_LAUNCHXL) +#if defined(EM_CC1354P10_1_LP) + .rfRegOverrideTxStdTblptr = NULL, + .rfRegOverrideTx20TblPtr = NULL, +#else + .rfRegOverrideTxStdTblptr = (regOverride_t *) pOverrides_bleTxStd, // Default PA + .rfRegOverrideTx20TblPtr = (regOverride_t *) pOverrides_bleTx20, // High power PA +#endif // EM_CC1354P10_1_LP +#endif // CC13X2P +#if defined(RTLS_CTE) + .rfRegOverrideCtePtr = (regOverride_t *) (pOverrides_bleCommon + BLE_STACK_OVERRIDES_OFFSET + CTE_OVERRIDES_OFFSET), + .cteAntennaPropPtr = &appCTEAntProp, +#else + .rfRegOverrideCtePtr = NULL, + .cteAntennaPropPtr = NULL, +#endif + .privOverrideOffset = BLE_STACK_OVERRIDES_OFFSET + PRIVACY_OVERRIDE_OFFSET, +#if defined(USE_COEX) + .coexUseCaseConfigPtr = &coexSysConfig, +#else + .coexUseCaseConfigPtr = NULL, +#endif +#endif +}; + +#else /* !(ICALL_JT) */ + +#ifndef CC23X0 +// RF Driver API Table +rfDrvTblPtr_t rfDriverTable[] = { + (uint32) RF_open, + (uint32) driverTable_fnSpinlock, // RF_close +#ifdef RF_SINGLEMODE + (uint32) RF_postCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_postCmd +#endif // RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_pendCmd +#ifdef RF_SINGLEMODE + (uint32) RF_runCmd, +#else // !RF_SINGLEMODE + (uint32) driverTable_fnSpinlock, // RF_runCmd +#endif // RF_SINGLEMODE + (uint32) RF_cancelCmd, + (uint32) RF_flushCmd, + (uint32) driverTable_fnSpinlock, // RF_yield + (uint32) RF_Params_init, + (uint32) RF_runImmediateCmd, + (uint32) RF_runDirectCmd, + (uint32) RF_ratCompare(uint32) driverTable_fnSpinlock, // RF_ratCapture + (uint32) driverTable_fnSpinlock, // RF_ratDisableChannel + (uint32) RF_getCurrentTime, + (uint32) RF_getRssi, + (uint32) RF_getInfo, + (uint32) RF_getCmdOp, + (uint32) RF_control, + (uint32) driverTable_fnSpinlock, // RF_getTxPower + (uint32) RF_setTxPower, // RF_setTxPower + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findPowerLevel + (uint32) driverTable_fnSpinlock, // RF_TxPowerTable_findValue +#ifndef RF_SINGLEMODE + (uint32) RF_scheduleCmd, + (uint32) RF_runScheduleCmd, + (uint32) driverTable_fnSpinlock // RF_requestAccess +#endif // !RF_SINGLEMODE +}; + +// ECC Driver API Table +eccDrvTblPtr_t eccDriverTable[] = { (uint32) ECDH_init, + (uint32) ECDH_Params_init, + (uint32) ECDH_open, + (uint32) ECDH_close, + (uint32) ECDH_OperationGeneratePublicKey_init, + (uint32) ECDH_OperationComputeSharedSecret_init, + (uint32) ECDH_generatePublicKey, + (uint32) ECDH_computeSharedSecret }; + +// Crypto Driver API Table +cryptoDrvTblPtr_t cryptoDriverTable[] = { (uint32) AESCCM_init, + (uint32) AESCCM_open, + (uint32) AESCCM_close, + (uint32) AESCCM_Params_init, + (uint32) AESCCM_Operation_init, + (uint32) AESCCM_oneStepEncrypt, + (uint32) AESCCM_oneStepDecrypt, + (uint32) AESECB_init, + (uint32) AESECB_open, + (uint32) AESECB_close, + (uint32) AESECB_Params_init, + (uint32) AESECB_Operation_init, + (uint32) AESECB_oneStepEncrypt, + (uint32) AESECB_oneStepDecrypt, + (uint32) CryptoKeyPlaintext_initKey, + (uint32) CryptoKeyPlaintext_initBlankKey }; + +trngDrvTblPtr_t trngDriverTable[] = { (uint32) TRNG_init, (uint32) TRNG_open, (uint32) TRNG_generateEntropy, (uint32) TRNG_close }; +#endif + +#endif /* ICALL_JT */ + +/******************************************************************************* + * @fn RegisterAssertCback + * + * @brief This routine registers the Application's assert handler. + * + * input parameters + * + * @param appAssertHandler - Application's assert handler. + * + * output parameters + * + * @param None. + * + * @return None. + */ +void RegisterAssertCback(assertCback_t appAssertHandler) +{ + appAssertCback = appAssertHandler; + +#ifdef EXT_HAL_ASSERT + // also set the Assert callback pointer used by halAssertHandlerExt + // Note: Normally, this pointer will be intialized by the stack, but in the + // event HAL_ASSERT is used by the Application, we initialize it + // directly here. + halAssertCback = appAssertHandler; +#endif // EXT_HAL_ASSERT + + return; +} + +/******************************************************************************* + * @fn driverTable_fnSpinLock + * + * @brief This routine is used to trap calls to unpopulated indexes of + * driver function pointer tables. + * + * input parameters + * + * @param None. + * + * output parameters + * + * @param None. + * + * @return None. + */ +void driverTable_fnSpinlock(void) +{ + volatile uint8 i = 1; + + while (i) + ; +} + +/******************************************************************************* + * @fn DefaultAssertCback + * + * @brief This is the Application default assert callback, in the event + * none is registered. + * + * input parameters + * + * @param assertCause - Assert cause as defined in hal_assert.h. + * @param assertSubcause - Optional assert subcause (see hal_assert.h). + * + * output parameters + * + * @param None. + * + * @return None. + */ +void DefaultAssertCback(uint8 assertCause, uint8 assertSubcause) +{ +#ifdef HAL_ASSERT_SPIN + driverTable_fnSpinlock(); +#endif // HAL_ASSERT_SPIN + + return; +} + +// Application Assert Callback Function Pointer +assertCback_t appAssertCback = DefaultAssertCback; + +/******************************************************************************* + */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds new file mode 100644 index 00000000000000..52e08615592fed --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds @@ -0,0 +1,259 @@ +/* + * + * Copyright (c) 2022 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 + * Linkerscript for a non-OTA Matter executable. + */ + +STACKSIZE = 0x2000; + +MEMORY +{ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00100000 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash + */ + FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : ORIGIN = 0x90000000, LENGTH = 0x40000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_LOG", LOG_DATA); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x00); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000); + + .vtable (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + /* End of executable code/data, NVS is not part of the OTA image */ + PROVIDE (_flash_end_address = .); + + /* 5 pages of NV Memory (0x800 each) offset by 1 page for BIM/CCFG */ + /*.nvs (NOLOAD) : ALIGN(0x2000) { */ + .nvs (0xFB800) (NOLOAD) : AT (0xFB800) ALIGN(0x800) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + + .log_data (COPY) : { + KEEP (*(.log_data)) + } > REGION_LOG +} + +ENTRY(resetISR) diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds new file mode 100644 index 00000000000000..83b05fb2716c79 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds @@ -0,0 +1,270 @@ +/* + * + * Copyright (c) 2022 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 + * Linkerscript for Matter executable with space reserved for the TI BIM. + */ + +STACKSIZE = 0x800; + +MEMORY +{ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0xFF800 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash + */ + /* FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 */ + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 + /* Explicitly placed off target for the storage of logging data. + * The data placed here is NOT loaded onto the target device. + * This is part of 1 GB of external memory from 0x60000000 - 0x9FFFFFFF. + * ARM memory map can be found here: + * https://developer.arm.com/documentation/ddi0337/e/memory-map/about-the-memory-map + */ + LOG_DATA (R) : ORIGIN = 0x90000000, LENGTH = 0x40000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_LOG", LOG_DATA); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + /* BIM header placed at the base of flash by default */ + PROVIDE (_img_header_base_address = + DEFINED(_img_header_base_address) ? _img_header_base_address : 0x0); + + .oad_image_header (_img_header_base_address) : AT (_img_header_base_address) { + KEEP (*(.oad_image_header)) + } > REGION_TEXT + + /* interrupt vectors shifted to accommodate BIM header */ + PROVIDE (_intvecs_base_address = + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x100); + + .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + PROVIDE (_vtable_base_address = + DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000); + + .vtable (_vtable_base_address) (NOLOAD) : { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + *(.rodata_*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + /* End of executable code/data, NVS is not part of the OTA image */ + PROVIDE (_flash_end_address = .); + + /* Two pages of NV Memory (0x800 each) offset by 1 page for BIM/CCFG */ + .nvs (0xFE800) (NOLOAD) : AT (0xFE800) ALIGN(0x2000) { + *(.nvs) + } > REGION_TEXT + + /* CCFG is supplied by the BIM project */ + /* + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + */ + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + } > REGION_STACK AT> REGION_STACK + + .log_data (COPY) : { + KEEP (*(.log_data)) + } > REGION_LOG +} + +ENTRY(resetISR) diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.c b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.c new file mode 100644 index 00000000000000..b6b790489a9916 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.c @@ -0,0 +1,133 @@ +/* + * + * 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 "aes_alt.h" +#include "mbedtls/aes.h" + +#if defined(MBEDTLS_AES_ALT) + +#include + +#include "ti_drivers_config.h" + +#include +#include + +/* + * number of active contexts, used for power on/off of the crypto core + */ +static unsigned int ref_num = 0; + +static AESECB_Handle AESECB_handle = NULL; + +void mbedtls_aes_init(mbedtls_aes_context * ctx) +{ + AESECB_Params AESECBParams; + + if (ref_num == 0) + { + AESECB_Params_init(&AESECBParams); + AESECBParams.returnBehavior = AESECB_RETURN_BEHAVIOR_POLLING; + AESECB_handle = AESECB_open(CONFIG_AESECB_1, &AESECBParams); + + // handle will be NULL if open failed, subsequent calls will fail with a generic HW error + } + ref_num++; +} + +void mbedtls_aes_free(mbedtls_aes_context * ctx) +{ + if (ref_num > 0) + { + ref_num--; + if (ref_num == 0) + { + AESECB_close(AESECB_handle); + + AESECB_handle = NULL; + } + } + + memset((void *) ctx, 0x00, sizeof(ctx)); +} + +int mbedtls_aes_setkey_enc(mbedtls_aes_context * ctx, const unsigned char * key, unsigned int keybits) +{ + int_fast16_t statusCrypto; + size_t keylen = keybits / 8U; // 8 bits in a byte + + if (keylen > sizeof(ctx->keyMaterial)) + { + return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; + } + + /* Initialize AES key */ + memcpy(ctx->keyMaterial, key, keylen); + statusCrypto = CryptoKeyPlaintext_initKey(&ctx->cryptoKey, (uint8_t *) ctx->keyMaterial, keylen); + + if (CryptoKey_STATUS_SUCCESS != statusCrypto) + { + return MBEDTLS_ERR_AES_HW_ACCEL_FAILED; + } + + return 0; +} + +int mbedtls_aes_setkey_dec(mbedtls_aes_context * ctx, const unsigned char * key, unsigned int keybits) +{ + int_fast16_t statusCrypto; + size_t keylen = keybits / 8U; // 8 bits in a byte + + if (keylen > sizeof(ctx->keyMaterial)) + { + return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; + } + + /* Initialize AES key */ + statusCrypto = CryptoKeyPlaintext_initKey(&ctx->cryptoKey, (uint8_t *) key, keylen); + + if (CryptoKey_STATUS_SUCCESS != statusCrypto) + { + return MBEDTLS_ERR_AES_HW_ACCEL_FAILED; + } + + return 0; +} + +int mbedtls_aes_crypt_ecb(mbedtls_aes_context * ctx, int mode, const unsigned char input[16], unsigned char output[16]) +{ + int statusCrypto; + AESECB_Operation operationOneStepEncrypt; + + /* run it through the authentication + encryption, pass the ccmLVal = 2 */ + AESECB_Operation_init(&operationOneStepEncrypt); + + operationOneStepEncrypt.key = &ctx->cryptoKey; + operationOneStepEncrypt.inputLength = 16; + operationOneStepEncrypt.input = (uint8_t *) input; + operationOneStepEncrypt.output = (uint8_t *) output; + + statusCrypto = AESECB_oneStepEncrypt(AESECB_handle, &operationOneStepEncrypt); + + if (CryptoKey_STATUS_SUCCESS != statusCrypto) + { + return MBEDTLS_ERR_AES_HW_ACCEL_FAILED; + } + + return 0; +} +#endif diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.h b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.h new file mode 100644 index 00000000000000..9f5ecedec39e88 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/aes_alt.h @@ -0,0 +1,45 @@ +/* + * + * 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 + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls-config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_AES_ALT) + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + CryptoKey cryptoKey; /*!< structure for the AES driver */ + uint32_t keyMaterial[16]; /*!< memory for the key bytes used by cryptoKey */ +} mbedtls_aes_context; + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_AES_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/cc13x4_26x4-mbedtls-config.h b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/cc13x4_26x4-mbedtls-config.h new file mode 100644 index 00000000000000..f1bb207c945dc0 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/cc13x4_26x4-mbedtls-config.h @@ -0,0 +1,134 @@ +/* + * + * 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 cc13x4_26x4-mbedtls-config.h.h + * + * @brief MbedTLS configuration header for CHIP + * + */ + +#ifndef CC13X4_26X4_MBEDTLS_CONFIG_H +#define CC13X4_26X4_MBEDTLS_CONFIG_H + +#include +#include + +/** + * Enable FreeRTOS threading support + */ +//#define MBEDTLS_FREERTOS +//#define MBEDTLS_THREADING_C +//#define MBEDTLS_THREADING_ALT + +/* Enable Hardware Acceleration */ + +//#define MBEDTLS_AES_ALT +//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT +//#define MBEDTLS_ECDSA_SIGN_ALT +//#define MBEDTLS_ECDSA_VERIFY_ALT +//#define MBEDTLS_ENTROPY_HARDWARE_ALT +//#define MBEDTLS_SHA256_ALT + +// Thread Joining disabled +//#define MBEDTLS_ECJPAKE_ALT +//#define MBEDTLS_ECJPAKE_C +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +//#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 + +/** + * Enable Crypto and Entropy modules + */ + +#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_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_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_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_ECDSA_DETERMINISTIC +#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_ECDHE_ECDSA_WITH_AES_128_CCM_8 + +#include "mbedtls/check_config.h" + +#endif // CC13X4_26X4_MBEDTLS_CONFIG_H diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdh_alt.c b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdh_alt.c new file mode 100644 index 00000000000000..e14c277a7194ff --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdh_alt.c @@ -0,0 +1,313 @@ +/* + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined MBEDTLS_ECDH_COMPUTE_SHARED_ALT || defined MBEDTLS_ECDH_GEN_PUBLIC_ALT + +#include + +#include +#include +#include +#include + +#include "ti_drivers_config.h" + +#include +#include +#include + +/* Parameter validation macros based on platform_util.h */ +#define ECDH_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA) +#define ECDH_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) + +#if defined MBEDTLS_ECDH_GEN_PUBLIC_ALT +/* + * Generate public key (restartable version) + */ +static int ecdh_gen_public_restartable(mbedtls_ecp_group * grp, mbedtls_mpi * d, mbedtls_ecp_point * Q, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng, + mbedtls_ecp_restart_ctx * rs_ctx) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + CryptoKey myPublicKey; + ECDH_Config config = { 0 }; + ECDH_Handle handle = NULL; + ECDH_OperationGeneratePublicKey operationGeneratePublicKey; + ECDHCC26X2_HWAttrs hwAttrs = { 0 }; + ECDHCC26X2_Object object = { 0 }; + + if (NULL == q_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDH_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + CryptoKeyPlaintext_initKey(&myPublicKey, q_buf, (plen * 2U) + 1); + + if (0 != f_rng(p_rng, d_buf, plen)) + { + ret = MBEDTLS_ERR_ECP_RANDOM_FAILED; + goto cleanup; + } + + ECDH_OperationGeneratePublicKey_init(&operationGeneratePublicKey); + operationGeneratePublicKey.myPrivateKey = &myPrivateKey; + operationGeneratePublicKey.myPublicKey = &myPublicKey; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationGeneratePublicKey.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationGeneratePublicKey.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationGeneratePublicKey.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDH_STATUS_SUCCESS == ECDH_generatePublicKey(handle, &operationGeneratePublicKey)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(d, d_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&(Q->Y), q_buf + 1 + plen, plen)); + +cleanup: + mbedtls_free(q_buf); + mbedtls_free(d_buf); + + if (NULL != handle) + { + ECDH_close(handle); + } + + return (ret); +} + +/* + * Generate public key + */ +int mbedtls_ecdh_gen_public(mbedtls_ecp_group * grp, mbedtls_mpi * d, mbedtls_ecp_point * Q, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + ECDH_VALIDATE_RET(grp != NULL); + ECDH_VALIDATE_RET(d != NULL); + ECDH_VALIDATE_RET(Q != NULL); + ECDH_VALIDATE_RET(f_rng != NULL); + return (ecdh_gen_public_restartable(grp, d, Q, f_rng, p_rng, NULL)); +} +#endif /* MBEDTLS_ECDH_GEN_PUBLIC_ALT */ + +#if defined MBEDTLS_ECDH_COMPUTE_SHARED_ALT +/* + * Compute shared secret (SEC1 3.3.1) + */ +static int ecdh_compute_shared_restartable(mbedtls_ecp_group * grp, mbedtls_mpi * z, const mbedtls_ecp_point * Q, + const mbedtls_mpi * d, int (*f_rng)(void *, unsigned char *, size_t), void * p_rng, + mbedtls_ecp_restart_ctx * rs_ctx) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + CryptoKey theirPublicKey; + CryptoKey sharedSecret; + ECDH_Config config = { 0 }; + ECDH_Handle handle = NULL; + ECDH_OperationComputeSharedSecret operationComputeSharedSecret; + ECDHCC26X2_HWAttrs hwAttrs = { 0 }; + ECDHCC26X2_Object object = { 0 }; + + if (NULL == q_buf || NULL == s_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDH_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + CryptoKeyPlaintext_initKey(&sharedSecret, s_buf, (2U * plen) + 1); + + /* The driver consumes network byte order. Copy this number and reverse them again. */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(d, d_buf, plen)); + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + + /* The driver consumes an octet string in network byte order. Copy this + * point and reverse them again. */ + q_buf[0] = 0x04; + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->Y), q_buf + 1 + plen, plen)); + CryptoKeyPlaintext_initKey(&theirPublicKey, q_buf, (2U * plen) + 1); + + ECDH_OperationComputeSharedSecret_init(&operationComputeSharedSecret); + operationComputeSharedSecret.myPrivateKey = &myPrivateKey; + operationComputeSharedSecret.theirPublicKey = &theirPublicKey; + operationComputeSharedSecret.sharedSecret = &sharedSecret; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationComputeSharedSecret.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationComputeSharedSecret.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationComputeSharedSecret.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDH_STATUS_SUCCESS == ECDH_computeSharedSecret(handle, &operationComputeSharedSecret)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(z, s_buf + 1, plen)); + +cleanup: + mbedtls_free(q_buf); + mbedtls_free(d_buf); + mbedtls_free(s_buf); + + if (NULL != handle) + { + ECDH_close(handle); + } + + return (ret); +} + +/* + * Compute shared secret (SEC1 3.3.1) + */ +int mbedtls_ecdh_compute_shared(mbedtls_ecp_group * grp, mbedtls_mpi * z, const mbedtls_ecp_point * Q, const mbedtls_mpi * d, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + ECDH_VALIDATE_RET(grp != NULL); + ECDH_VALIDATE_RET(Q != NULL); + ECDH_VALIDATE_RET(d != NULL); + ECDH_VALIDATE_RET(z != NULL); + return (ecdh_compute_shared_restartable(grp, z, Q, d, f_rng, p_rng, NULL)); +} +#endif /* MBEDTLS_ECDH_COMPUTE_SHARED_ALT */ + +#endif /* MBEDTLS_ECDH_COMPUTE_SHARED_ALT || MBEDTLS_ECDH_GEN_PUBLIC_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdsa_alt.c b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdsa_alt.c new file mode 100644 index 00000000000000..e6ab92c6b0d483 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecdsa_alt.c @@ -0,0 +1,288 @@ +/* + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined MBEDTLS_ECDSA_VERIFY_ALT || defined MBEDTLS_ECDSA_SIGN_ALT + +/* NOTE: The TI drivers consume these points and big numbers in network byte + * order. This is in contrast to the mbedtls_mpi structures which story + * these numbers and points in little endian byte order. This file uses + * the mpi functions to re-write the buffers into network byte order. + */ + +#include + +#include +#include +#include +#include + +#include "ti_drivers_config.h" + +#include +#include +#include + +#ifdef MBEDTLS_ECDSA_VERIFY_ALT + +/* + * Verify ECDSA signature of hashed message + */ +int mbedtls_ecdsa_verify(mbedtls_ecp_group * grp, const unsigned char * buf, size_t blen, const mbedtls_ecp_point * Q, + const mbedtls_mpi * r, const mbedtls_mpi * s) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * r_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * q_buf = (uint8_t *) mbedtls_calloc(1, (plen * 2U) + 1); + CryptoKey theirPublicKey; + ECDSA_Config config = { 0 }; + ECDSA_Handle handle = NULL; + ECDSA_OperationVerify operationVerify; + ECDSACC26X2_HWAttrs hwAttrs = { 0 }; + ECDSACC26X2_Object object = { 0 }; + + if (NULL == r_buf || NULL == s_buf || NULL == q_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + hwAttrs.trngIntPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDSA_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + /* The driver consumes an octet string in network byte order. Copy this + * point and reverse them again. */ + q_buf[0] = 0x04; + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->X), q_buf + 1, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&(Q->Y), q_buf + 1 + plen, plen)); + CryptoKeyPlaintext_initKey(&theirPublicKey, q_buf, (2U * plen) + 1); + + /* The driver also consumes the r and s in network byte order. Copy these + * buffers and them reverse them again */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(r, r_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(s, s_buf, plen)); + + /* prepare the operation */ + ECDSA_OperationVerify_init(&operationVerify); + operationVerify.theirPublicKey = &theirPublicKey; + operationVerify.hash = buf; + operationVerify.r = r_buf; + operationVerify.s = s_buf; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationVerify.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationVerify.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationVerify.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationVerify.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationVerify.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationVerify.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationVerify.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationVerify.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDSA_STATUS_SUCCESS == ECDSA_verify(handle, &operationVerify)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + } + +cleanup: + mbedtls_free(r_buf); + mbedtls_free(s_buf); + mbedtls_free(q_buf); + + if (NULL != handle) + { + ECDSA_close(handle); + } + + return ret; +} + +#endif /* MBEDTLS_ECDSA_VERIFY_ALT */ + +#ifdef MBEDTLS_ECDSA_SIGN_ALT + +/* + * Compute ECDSA signature of a hashed message + */ +int mbedtls_ecdsa_sign(mbedtls_ecp_group * grp, mbedtls_mpi * r, mbedtls_mpi * s, const mbedtls_mpi * d, const unsigned char * buf, + size_t blen, int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + int ret = 0; + size_t plen = grp->nbits / 8U; + uint8_t * r_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * s_buf = (uint8_t *) mbedtls_calloc(1, plen); + uint8_t * d_buf = (uint8_t *) mbedtls_calloc(1, plen); + CryptoKey myPrivateKey; + ECDSA_Config config = { 0 }; + ECDSA_Handle handle = NULL; + ECDSA_OperationSign operationSign; + ECDSACC26X2_HWAttrs hwAttrs = { 0 }; + ECDSACC26X2_Object object = { 0 }; + + if (NULL == r_buf || NULL == s_buf || NULL == d_buf) + { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + + hwAttrs.intPriority = (1 << 5); + hwAttrs.trngIntPriority = (1 << 5); + + config.object = (void *) &object; + config.hwAttrs = (void *) &hwAttrs; + + handle = ECDSA_construct(&config, NULL); + + if (NULL == handle) + { + ret = MBEDTLS_ERR_ECP_HW_ACCEL_FAILED; + goto cleanup; + } + + /* The driver consumes numbers in network byte order */ + MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(d, d_buf, plen)); + + CryptoKeyPlaintext_initKey(&myPrivateKey, d_buf, plen); + ECDSA_OperationSign_init(&operationSign); + operationSign.myPrivateKey = &myPrivateKey; + operationSign.hash = buf; + operationSign.r = r_buf; + operationSign.s = s_buf; + + /* Load the ROM curve params */ + switch (grp->id) + { + case MBEDTLS_ECP_DP_SECP224R1: + operationSign.curve = &ECCParams_NISTP224; + break; + + case MBEDTLS_ECP_DP_SECP256R1: + operationSign.curve = &ECCParams_NISTP256; + break; + + case MBEDTLS_ECP_DP_SECP384R1: + operationSign.curve = &ECCParams_NISTP384; + break; + + case MBEDTLS_ECP_DP_SECP521R1: + operationSign.curve = &ECCParams_NISTP521; + break; + + case MBEDTLS_ECP_DP_BP256R1: + operationSign.curve = &ECCParams_BrainpoolP256R1; + break; + + case MBEDTLS_ECP_DP_BP384R1: + operationSign.curve = &ECCParams_BrainpoolP384R1; + break; + + case MBEDTLS_ECP_DP_BP512R1: + operationSign.curve = &ECCParams_BrainpoolP512R1; + break; + + case MBEDTLS_ECP_DP_CURVE25519: + operationSign.curve = &ECCParams_Curve25519; + break; + + default: + /* Possible extension to load an arbitrary curve */ + ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + goto cleanup; + } + + if (ECDSA_STATUS_SUCCESS == ECDSA_sign(handle, &operationSign)) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + } + + /* The driver produces r and s in network byte order. copy into mbedtls mpi + * format. This incurs an extra byte reversal when written to ASN1. */ + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(r, r_buf, plen)); + MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(s, s_buf, plen)); + +cleanup: + mbedtls_free(r_buf); + mbedtls_free(s_buf); + mbedtls_free(d_buf); + + if (NULL != handle) + { + ECDSA_close(handle); + } + + return ret; +} +#endif /* MBEDTLS_ECDSA_SIGN_ALT */ + +#endif /* defined MBEDTLS_ECDSA_VERIFY_ALT || defined MBEDTLS_ECDSA_SIGN_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.c b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.c new file mode 100644 index 00000000000000..84b60b0f92c347 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.c @@ -0,0 +1,900 @@ +/* + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "mbedtls/ecjpake.h" + +#if defined(MBEDTLS_ECJPAKE_ALT) +#include "ecjpake_alt.h" + +#include + +#include "ti_drivers_config.h" + +#include +#include + +/* + * NOTE: On calling convention in this file. + * + * Many of the helper functions in this file take a pointer to a `uint8_t*`, + * usually called `p`. This is the current working pointer for the input or + * output buffer. They will also take a pointer to a `uint8_t`, usually called + * `end`. This is the pointer to the end of the current working buffer. The + * difference between these two pointers is calculated and used as the current + * available length of the working buffer. This is checked before anything is + * written to or read from the buffer. While values are read or written to the + * data at the pointer pointed at by `p`, the pointer pointed at by `p` is + * updated to point to the next available value. The callee updates the value + * of `p` for the caller, almost in the same fashion as strtok. + * + * Here is an example: + * ``` + * static int read_be_uint16(const uint8_t **p, + * const uint8_t *end, + * uint16_t *value) + * { + * if ((end < *p) || (end - *p < sizeof(uint16_t))) + * { + * return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + * } + * *value = ((uint16_t)(*p)[0] << 8) | (*p)[1]); + * return (0); + * } + * + * void sample_func(void) + * { + * uint8_t buffer[4] = {0x01, 0x02, 0x03, 0x04}; + * uint8_t* p = buffer + sizeof(buffer); + * uint8_t* end = buffer + sizeof(buffer); + * uint16_t value; + * + * read_be_uint16(&p, end, &value); + * // value is now 0x0102 + * // p points to buffer[2] + * read_be_uint16(&p, end, &value); + * // value is now 0x0304 + * // p points to buffer[4] (invalid) + * } + */ + +/* + * Convert a mbedtls_ecjpake_role to identifier string. + * + * depends on the value of the enumeration of mbedtls_ecjpake_role. + */ +static const char * const ecjpake_id[] = { "client", "server" }; + +#define ID_MINE (ecjpake_id[ctx->role]) +#define ID_PEER (ecjpake_id[1 - ctx->role]) + +/* + * Size of the temporary buffer for ecjpake_hash: + * 3 EC points plus their length, plus ID and its length (4 + 6 bytes) + */ +#define ECJPAKE_HASH_BUF_LEN (3 * (4 + MBEDTLS_ECP_MAX_PT_LEN) + 4 + 6) + +/** + * \breif execute the contents of this macro, save the return in + * `ret` and goto `cleanup` if it is not `0` + * + * The internal functions of this file driver are designed to return `0` on + * success. The caller is expected to have an `int ret` in the translation unit + * of the call-site, and a target `cleanup`. It is common practice to return + * `ret` in the caller. + * + * ``` + * int example_func(void) + * { + * int ret; + * ECJPAKE_ALT_CHK(some_func()); + * + * some_other_func(); + * + * cleanup: + * return ret; + * } + * ``` + * + * \param f code to execute + */ +#define ECJPAKE_ALT_CHK(f) \ + do \ + { \ + if ((ret = f) != 0) \ + goto cleanup; \ + } while (0) + +/** + * \brief writes a buffer prepended with a length byte + * + * \param p pointer to output buffer, will be changed by a successful + * call + * \param end pointer to the end of the output buffer + * \param key the CryptoKey to write + * \param bin the source to copy + * \param len the length to copy and write + * + * \return 0 if successful, + * a negative error code otherwise + * + * \retval MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * the input buffer is too small + */ +static int tls_write_binary(uint8_t ** p, const uint8_t * end, const uint8_t * bin, size_t len) +{ + if ((end < *p) || ((size_t)(end - *p) < 1 + len)) + { + return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + } + + /* write the length to the buffer */ + (*p)[0] = len; + *p += 1; + + /* write the binary data as is */ + memcpy(*p, bin, len); + *p += len; + + return (0); +} + +/** + * \brief read a binary value prepended by a length bit + * + * \param p pointer to input buffer, will be changed by a successful + * call + * \param end pointer to the end of the input buffer + * \param bin the array to fill + * \param len the size of \p bin + * + * \return 0 if successful, + * a negative error code otherwise + * + * \retval MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * the input buffer is too small + */ +static int tls_read_binary(const uint8_t ** p, const uint8_t * end, uint8_t * bin, size_t len) +{ + uint8_t data_len; + + /* length byte plus the length of the crypto key */ + if ((end < *p) || ((size_t)(end - *p) < 1 + len)) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + + /* read the length byte */ + data_len = (*p)[0]; + *p += 1; + /* check the length matches */ + if (data_len != len) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + + memcpy(bin, *p, len); + + *p += len; + + return (0); +} + +/** + * \brief writes a tls point into a CryptoKey + * + * \param p pointer to output buffer, will be changed by a successful + * call + * \param end pointer to the end of the output buffer + * \param key the CryptoKey to write + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int tls_write_crypto_key(uint8_t ** p, const uint8_t * end, CryptoKey * key) +{ + return tls_write_binary(p, end, key->u.plaintext.keyMaterial, key->u.plaintext.keyLength); +} + +/** + * \brief read a tls point into a CryptoKey + * + * \param p pointer to input buffer, will be changed by a successful + * call + * \param end pointer to the end of the input buffer + * \param key the CryptoKey to fill + * + * \return 0 if successful, + * a negative error code otherwise + * + * \retval MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * the input buffer is too small + * \retval MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE + * the point is not in uncompressed form + */ +static int tls_read_crypto_key(const uint8_t ** p, const uint8_t * end, CryptoKey * key) +{ + /* check that the point is uncompressed */ + if ((end < *p) || (end - *p < 2)) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + if ((*p)[1] != 0x04) + { + return (MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE); + } + + return tls_read_binary(p, end, key->u.plaintext.keyMaterial, key->u.plaintext.keyLength); +} + +/** + * \brief write the curve info into the buffer + * + * \param p pointer to output buffer, will be changed by a successful + * call + * \param end pointer to the end of the output buffer + * \param group_id the mbedtls group id write + * + * \return 0 if successful, + * a negative error code otherwise + * + * \retval MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * the input buffer is too small + * \retval MBEDTLS_ERR_ECP_BAD_INPUT_DATA + * the group id did not name a valid curve + */ +static int tls_write_curve_info(uint8_t ** p, const uint8_t * end, mbedtls_ecp_group_id group_id) +{ + const mbedtls_ecp_curve_info * curve_info; + + if ((end < *p) || (end - *p < 3)) + { + return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + } + + curve_info = mbedtls_ecp_curve_info_from_grp_id(group_id); + + if (NULL == curve_info) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + + /* write that we use named curves */ + (*p)[0] = MBEDTLS_ECP_TLS_NAMED_CURVE; + (*p)[1] = curve_info->tls_id >> 8; + (*p)[2] = curve_info->tls_id & 0xFF; + *p += 3; + + return (0); +} + +/** + * \brief read and verify the curve info from the buffer + * + * \param p pointer to input buffer, will be changed by a successful + * call + * \param end pointer to the end of the input buffer + * \param group_id the mbedtls group id to load to check a match + * + * \return 0 if successful, + * a negative error code otherwise + * + * \retval MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * the input buffer is too small + * \retval MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE + * the tls curve identifiers do not match + * \retval MBEDTLS_ERR_ECP_BAD_INPUT_DATA + * the curve info was not for a named curve or we do not have + * that named curve + */ +static int tls_verify_curve_info(const uint8_t ** p, const uint8_t * end, mbedtls_ecp_group_id group_id) +{ + uint16_t curve_name_id; + const mbedtls_ecp_curve_info * curve_info; + + if ((end < *p) || (end - *p < 3)) + { + return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + } + + if ((*p)[0] != MBEDTLS_ECP_TLS_NAMED_CURVE) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + curve_name_id = (((uint16_t)(*p)[1] << 8)) | (((uint16_t)(*p)[2])); + *p += 3; + + curve_info = mbedtls_ecp_curve_info_from_grp_id(group_id); + + if (NULL == curve_info) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + + if (curve_name_id != curve_info->tls_id) + { + return (MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE); + } + + return (0); +} + +/** + * \brief Fill the a point with a random function + * + * \param private_key + * key to fill with random data + * \param f_rng random number function + * \param p_rng context for the random function + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int gen_private_key(unsigned char * private_key, int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + unsigned int i; + unsigned int j = 0; + unsigned int sum = 0U; + + do + { + unsigned int * pkey = (unsigned int *) private_key; + f_rng(p_rng, private_key, NISTP256_CURVE_LENGTH_BYTES); + + /* check if private_key is equal to zero */ + for (i = 0; i < (NISTP256_CURVE_LENGTH_BYTES / sizeof(unsigned int)); i++) + { + sum |= pkey[i]; + } + j++; + } while (0U == sum && (j < 3)); + + return (0U != sum ? 0 : -1); +} + +/** + * \brief Generate the second round of keys for this node and peer + * + * \param ctx Context to use + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int ecjpake_alt_generate_round2_keys(mbedtls_ecjpake_context * ctx) +{ + ECJPAKE_OperationRoundTwoGenerateKeys roundTwoGenerateKeys; + int ret; + + if (ctx->roundTwoGenerated) + { + return (0); + } + + ECJPAKE_OperationRoundTwoGenerateKeys_init(&roundTwoGenerateKeys); + roundTwoGenerateKeys.curve = &ECCParams_NISTP256; + roundTwoGenerateKeys.myPrivateKey2 = &ctx->myPrivateCryptoKey2; + roundTwoGenerateKeys.myPublicKey1 = &ctx->myPublicCryptoKey1; + roundTwoGenerateKeys.myPublicKey2 = &ctx->myPublicCryptoKey2; + roundTwoGenerateKeys.theirPublicKey1 = &ctx->theirPublicCryptoKey1; + roundTwoGenerateKeys.theirPublicKey2 = &ctx->theirPublicCryptoKey2; + roundTwoGenerateKeys.preSharedSecret = &ctx->preSharedSecretCryptoKey; + roundTwoGenerateKeys.theirNewGenerator = &ctx->theirGeneratorKey; + roundTwoGenerateKeys.myNewGenerator = &ctx->myGeneratorKey; + roundTwoGenerateKeys.myCombinedPrivateKey = &ctx->myCombinedPrivateKey; + roundTwoGenerateKeys.myCombinedPublicKey = &ctx->myCombinedPublicKey; + roundTwoGenerateKeys.myPrivateV = &ctx->myPrivateCryptoV3; + roundTwoGenerateKeys.myPublicV = &ctx->myPublicCryptoV3; + + ECJPAKE_ALT_CHK(ECJPAKE_roundTwoGenerateKeys(ctx->handle, &roundTwoGenerateKeys)); + + ctx->roundTwoGenerated = true; + +cleanup: + return (ret); +} + +void mbedtls_ecjpake_init(mbedtls_ecjpake_context * ctx) +{ + ECJPAKE_Params params; + + if (ctx == NULL) + { + return; + } + + ctx->md_info = NULL; + ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; + + ECJPAKE_Params_init(¶ms); + + ctx->handle = ECJPAKE_open(0, ¶ms); +} + +void mbedtls_ecjpake_free(mbedtls_ecjpake_context * ctx) +{ + if (ctx == NULL) + { + return; + } + + ctx->md_info = NULL; + + ECJPAKE_close(ctx->handle); + ctx->handle = NULL; +} + +static void big_num_reverse(uint8_t * arr, size_t len) +{ + unsigned int left = 0; + unsigned int right = len - 1; + uint8_t temp; + + while (left < right) + { + temp = arr[left]; + arr[left] = arr[right]; + arr[right] = temp; + + ++left; + --right; + } +} + +/** + * \brief write a 4 byte length and binary output + * + * \param p pointer to output buffer, will be changed by a successful + * call + * \param end pointer to the end of the output buffer + * \param bin value to write + * \param len length to write + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int ecjpake_write_len_binary(uint8_t ** p, const uint8_t * end, const uint8_t * bin, size_t len) +{ + if ((end < *p) || ((size_t)(end - *p) < 4 + len)) + { + return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + } + + memcpy(*p + 4, bin, len); + + (*p)[0] = (unsigned char) ((len >> 24) & 0xFF); + (*p)[1] = (unsigned char) ((len >> 16) & 0xFF); + (*p)[2] = (unsigned char) ((len >> 8) & 0xFF); + (*p)[3] = (unsigned char) ((len) &0xFF); + + *p += 4 + len; + + return (0); +} + +/** + * \brief Create the EC-JPAKE hash for each round + * + * \param md_info message digest info to use + * \param G 1st point to digest + * \param V 2nd point to digest + * \param X 3rd point to digest + * \param id string id to digest + * \param hash output buffer for digest + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int ecjpake_hash(const mbedtls_md_info_t * md_info, CryptoKey * G, CryptoKey * V, CryptoKey * X, const char * id, + uint8_t * hash) +{ + int ret; + uint8_t buf[ECJPAKE_HASH_BUF_LEN]; + uint8_t * p = buf; + const uint8_t * end = buf + sizeof(buf); + const size_t id_len = strlen(id); + + /* + * Write 'lenG || G || lenV || V || lenX || X || lenID || ID' to the + * temporary buffer + */ + ECJPAKE_ALT_CHK(ecjpake_write_len_binary(&p, end, G->u.plaintext.keyMaterial, G->u.plaintext.keyLength)); + ECJPAKE_ALT_CHK(ecjpake_write_len_binary(&p, end, V->u.plaintext.keyMaterial, V->u.plaintext.keyLength)); + ECJPAKE_ALT_CHK(ecjpake_write_len_binary(&p, end, X->u.plaintext.keyMaterial, X->u.plaintext.keyLength)); + ECJPAKE_ALT_CHK(ecjpake_write_len_binary(&p, end, (uint8_t *) id, id_len)); + + /* + * Compute hash + * + * XXX: possible speedup by digesting the buffers directly instead of + * creating a temp buffer + */ + ECJPAKE_ALT_CHK(mbedtls_md(md_info, buf, p - buf, hash)); + +cleanup: + return (ret); +} + +/** + * \brief Read and validate the ZKP based on this public key. + * + * \param ctx Context to use + * \param generator_key + * Generator point to use + * \param public_key + * Public key use + * \param p Pointer to current place in buffer, will point to the next + * character after a successful call + * \param end Pointer to the end of the buffer + * + * \return 0 if successful, + * a negative error code otherwise + */ +static int ecjpake_zkp_read(mbedtls_ecjpake_context * ctx, CryptoKey * generator_key, CryptoKey * public_key, const uint8_t ** p, + const uint8_t * end) +{ + int ret; + CryptoKey v; + uint8_t v_material[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + uint8_t r[NISTP256_CURVE_LENGTH_BYTES]; + uint8_t hash[NISTP256_CURVE_LENGTH_BYTES]; + + ECJPAKE_OperationVerifyZKP operation_verify_zkp; + + CryptoKeyPlaintext_initKey(&v, v_material, sizeof(v_material)); + + /* read the Ephemeral public key V */ + ECJPAKE_ALT_CHK(tls_read_crypto_key(p, end, &v)); + + /* read the Schnorr signature r */ + ECJPAKE_ALT_CHK(tls_read_binary(p, end, r, sizeof(r))); + + /* calculate the hash */ + ECJPAKE_ALT_CHK(ecjpake_hash(ctx->md_info, generator_key, &v, public_key, ID_PEER, hash)); + + /* verify the r and hash based on V */ + ECJPAKE_OperationVerifyZKP_init(&operation_verify_zkp); + operation_verify_zkp.curve = &ECCParams_NISTP256; + operation_verify_zkp.theirGenerator = generator_key; + operation_verify_zkp.theirPublicKey = public_key; + operation_verify_zkp.theirPublicV = &v; + operation_verify_zkp.hash = hash; + operation_verify_zkp.r = r; + + ECJPAKE_ALT_CHK(ECJPAKE_verifyZKP(ctx->handle, &operation_verify_zkp)); + +cleanup: + return (ret); +} + +/** + * \brief Check if a CryptoKey is zero + * + * \param G CryptoKey to use + * + * \return 0 CryptoKey is not zero + * MBEDTLS_ERR_ECP_INVALID_KEY if CryptoKey is zero + */ +static int check_CryptoKey_is_zero(CryptoKey * G) +{ + unsigned int i; + /* skip beginning 0x04 byte */ + for (i = 1; i < G->u.plaintext.keyLength; i++) + { + if (G->u.plaintext.keyMaterial[i] != 0U) + { + /* the point is not all zero */ + return (0); + } + } + /* the for loop completed, they were all zero */ + return (MBEDTLS_ERR_ECP_INVALID_KEY); +} + +int mbedtls_ecjpake_setup(mbedtls_ecjpake_context * ctx, mbedtls_ecjpake_role role, mbedtls_md_type_t hash, + mbedtls_ecp_group_id curve, const uint8_t * secret, size_t len) +{ + int ret = 0; + + ctx->roundTwoGenerated = false; + ctx->role = role; + + if ((ctx->md_info = mbedtls_md_info_from_type(hash)) == NULL) + { + return (MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE); + } + + ctx->curve = curve; + + /* copy NISTP256 generator for hash functions */ + ctx->nistP256Generator[0] = 0x04; + memcpy(&(ctx->nistP256Generator[1]), ECCParams_NISTP256.generatorX, (NISTP256_CURVE_LENGTH_BYTES * 2)); + big_num_reverse(&(ctx->nistP256Generator[1]), NISTP256_CURVE_LENGTH_BYTES); + big_num_reverse(&(ctx->nistP256Generator[NISTP256_CURVE_LENGTH_BYTES + 1]), NISTP256_CURVE_LENGTH_BYTES); + CryptoKeyPlaintext_initKey(&ctx->nistP256GeneratorCryptoKey, ctx->nistP256Generator, sizeof(ctx->nistP256Generator)); + + /* Pre-shared secret */ + memcpy(ctx->preSharedSecretKeyingMaterial, secret, len); + + CryptoKeyPlaintext_initKey(&ctx->preSharedSecretCryptoKey, ctx->preSharedSecretKeyingMaterial, len); + + CryptoKeyPlaintext_initKey(&ctx->myPrivateCryptoKey1, ctx->myPrivateKeyMaterial1, sizeof(ctx->myPrivateKeyMaterial1)); + CryptoKeyPlaintext_initKey(&ctx->myPrivateCryptoKey2, ctx->myPrivateKeyMaterial2, sizeof(ctx->myPrivateKeyMaterial2)); + CryptoKeyPlaintext_initKey(&ctx->myPrivateCryptoV1, ctx->myPrivateVMaterial1, sizeof(ctx->myPrivateVMaterial1)); + CryptoKeyPlaintext_initKey(&ctx->myPrivateCryptoV2, ctx->myPrivateVMaterial2, sizeof(ctx->myPrivateVMaterial2)); + CryptoKeyPlaintext_initKey(&ctx->myPrivateCryptoV3, ctx->myPrivateVMaterial3, sizeof(ctx->myPrivateVMaterial3)); + + CryptoKeyPlaintext_initBlankKey(&ctx->myPublicCryptoKey1, ctx->myPublicKeyMaterial1, sizeof(ctx->myPublicKeyMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->myPublicCryptoKey2, ctx->myPublicKeyMaterial2, sizeof(ctx->myPublicKeyMaterial2)); + CryptoKeyPlaintext_initBlankKey(&ctx->myPublicCryptoV1, ctx->myPublicVMaterial1, sizeof(ctx->myPublicVMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->myPublicCryptoV2, ctx->myPublicVMaterial2, sizeof(ctx->myPublicVMaterial2)); + CryptoKeyPlaintext_initBlankKey(&ctx->myPublicCryptoV3, ctx->myPublicVMaterial3, sizeof(ctx->myPublicVMaterial3)); + CryptoKeyPlaintext_initBlankKey(&ctx->myCombinedPrivateKey, ctx->myCombinedPrivateKeyMaterial1, + sizeof(ctx->myCombinedPrivateKeyMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->myCombinedPublicKey, ctx->myCombinedPublicKeyMaterial1, + sizeof(ctx->myCombinedPublicKeyMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->myGeneratorKey, ctx->myGenerator, sizeof(ctx->myGenerator)); + + CryptoKeyPlaintext_initBlankKey(&ctx->theirPublicCryptoKey1, ctx->theirPublicKeyMaterial1, + sizeof(ctx->theirPublicKeyMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->theirPublicCryptoKey2, ctx->theirPublicKeyMaterial2, + sizeof(ctx->theirPublicKeyMaterial2)); + CryptoKeyPlaintext_initBlankKey(&ctx->theirCombinedPublicKey, ctx->theirCombinedPublicKeyMaterial1, + sizeof(ctx->theirCombinedPublicKeyMaterial1)); + CryptoKeyPlaintext_initBlankKey(&ctx->theirGeneratorKey, ctx->theirGenerator, sizeof(ctx->theirGenerator)); + + return (ret); +} + +int mbedtls_ecjpake_check(const mbedtls_ecjpake_context * ctx) +{ + if (ctx->md_info == NULL || ctx->curve == MBEDTLS_ECP_DP_NONE || ctx->handle == NULL) + { + return (MBEDTLS_ERR_ECP_BAD_INPUT_DATA); + } + + return (0); +} + +int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context * ctx, const unsigned char * buf, size_t len) +{ + int ret; + const unsigned char * p = buf; + const unsigned char * end = buf + len; + + /* read their combined key material (Xc or Xs) */ + ECJPAKE_ALT_CHK(tls_read_crypto_key(&p, end, &ctx->theirPublicCryptoKey1)); + + /* verify that the point is not zero */ + ECJPAKE_ALT_CHK(check_CryptoKey_is_zero(&ctx->theirPublicCryptoKey1)); + + /* verify the proof (ZKP(Xc) or ZKP(Xs)) */ + ECJPAKE_ALT_CHK(ecjpake_zkp_read(ctx, &ctx->nistP256GeneratorCryptoKey, &ctx->theirPublicCryptoKey1, &p, end)); + + /* read their combined key material (Xc or Xs) */ + ECJPAKE_ALT_CHK(tls_read_crypto_key(&p, end, &ctx->theirPublicCryptoKey2)); + + /* verify that the point is not zero */ + ECJPAKE_ALT_CHK(check_CryptoKey_is_zero(&ctx->theirPublicCryptoKey2)); + + /* verify the proof (ZKP(Xc) or ZKP(Xs)) */ + ECJPAKE_ALT_CHK(ecjpake_zkp_read(ctx, &ctx->nistP256GeneratorCryptoKey, &ctx->theirPublicCryptoKey2, &p, end)); + +cleanup: + return (ret); +} + +int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context * ctx, uint8_t * buf, size_t len, size_t * olen, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + int ret; + uint8_t * p = buf; + const uint8_t * end = buf + len; + uint8_t hash[NISTP256_CURVE_LENGTH_BYTES]; + uint8_t r[NISTP256_CURVE_LENGTH_BYTES]; + + /* Generate round one keys */ + ECJPAKE_OperationRoundOneGenerateKeys roundOneGenerateKeys; + ECJPAKE_OperationGenerateZKP operationGenerateZKP; + + /* Generate private keys */ + ECJPAKE_ALT_CHK(gen_private_key(ctx->myPrivateKeyMaterial1, f_rng, p_rng)); + ECJPAKE_ALT_CHK(gen_private_key(ctx->myPrivateKeyMaterial2, f_rng, p_rng)); + ECJPAKE_ALT_CHK(gen_private_key(ctx->myPrivateVMaterial1, f_rng, p_rng)); + ECJPAKE_ALT_CHK(gen_private_key(ctx->myPrivateVMaterial2, f_rng, p_rng)); + ECJPAKE_ALT_CHK(gen_private_key(ctx->myPrivateVMaterial3, f_rng, p_rng)); + + ECJPAKE_OperationRoundOneGenerateKeys_init(&roundOneGenerateKeys); + roundOneGenerateKeys.curve = &ECCParams_NISTP256; + roundOneGenerateKeys.myPrivateKey1 = &ctx->myPrivateCryptoKey1; + roundOneGenerateKeys.myPrivateKey2 = &ctx->myPrivateCryptoKey2; + roundOneGenerateKeys.myPublicKey1 = &ctx->myPublicCryptoKey1; + roundOneGenerateKeys.myPublicKey2 = &ctx->myPublicCryptoKey2; + roundOneGenerateKeys.myPrivateV1 = &ctx->myPrivateCryptoV1; + roundOneGenerateKeys.myPrivateV2 = &ctx->myPrivateCryptoV2; + roundOneGenerateKeys.myPublicV1 = &ctx->myPublicCryptoV1; + roundOneGenerateKeys.myPublicV2 = &ctx->myPublicCryptoV2; + + ECJPAKE_ALT_CHK(ECJPAKE_roundOneGenerateKeys(ctx->handle, &roundOneGenerateKeys)); + + /* write X1 */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myPublicCryptoKey1)); + + ECJPAKE_ALT_CHK(ecjpake_hash(ctx->md_info, &ctx->nistP256GeneratorCryptoKey, &ctx->myPublicCryptoV1, &ctx->myPublicCryptoKey1, + ID_MINE, hash)); + + /* generate round one ZKPs */ + ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP); + operationGenerateZKP.curve = &ECCParams_NISTP256; + operationGenerateZKP.myPrivateKey = &ctx->myPrivateCryptoKey1; + operationGenerateZKP.myPrivateV = &ctx->myPrivateCryptoV1; + operationGenerateZKP.hash = hash; + operationGenerateZKP.r = r; + + ECJPAKE_ALT_CHK(ECJPAKE_generateZKP(ctx->handle, &operationGenerateZKP)); + + /* write ZKP for X1 (V1 and r1) */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myPublicCryptoV1)); + + /* write r */ + ECJPAKE_ALT_CHK(tls_write_binary(&p, end, r, NISTP256_CURVE_LENGTH_BYTES)); + + ECJPAKE_ALT_CHK(ecjpake_hash(ctx->md_info, &ctx->nistP256GeneratorCryptoKey, &ctx->myPublicCryptoV2, &ctx->myPublicCryptoKey2, + ID_MINE, hash)); + + ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP); + operationGenerateZKP.curve = &ECCParams_NISTP256; + operationGenerateZKP.myPrivateKey = &ctx->myPrivateCryptoKey2; + operationGenerateZKP.myPrivateV = &ctx->myPrivateCryptoV2; + operationGenerateZKP.hash = hash; + operationGenerateZKP.r = r; + + ECJPAKE_ALT_CHK(ECJPAKE_generateZKP(ctx->handle, &operationGenerateZKP)); + + /* write X2 */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myPublicCryptoKey2)); + + /* write ZKP for X2 */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myPublicCryptoV2)); + + /* write r */ + ECJPAKE_ALT_CHK(tls_write_binary(&p, end, r, NISTP256_CURVE_LENGTH_BYTES)); + + *olen = p - buf; + +cleanup: + return (ret); +} + +int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context * ctx, const unsigned char * buf, size_t len) +{ + int ret; + const uint8_t * p = buf; + const uint8_t * end = buf + len; + + ECJPAKE_ALT_CHK(ecjpake_alt_generate_round2_keys(ctx)); + + if (ctx->role == MBEDTLS_ECJPAKE_CLIENT) + { + ECJPAKE_ALT_CHK(tls_verify_curve_info(&p, end, ctx->curve)); + } + + /* read their combined key material (Xc or Xs) */ + ECJPAKE_ALT_CHK(tls_read_crypto_key(&p, end, &ctx->theirCombinedPublicKey)); + + /* verify that the point is not zero */ + ECJPAKE_ALT_CHK(check_CryptoKey_is_zero(&ctx->theirCombinedPublicKey)); + + /* verify the proof (ZKP(Xc) or ZKP(Xs)) */ + ECJPAKE_ALT_CHK(ecjpake_zkp_read(ctx, &ctx->theirGeneratorKey, &ctx->theirCombinedPublicKey, &p, end)); + +cleanup: + return (ret); +} + +int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context * ctx, unsigned char * buf, size_t len, size_t * olen, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + int ret; + uint8_t hash[NISTP256_CURVE_LENGTH_BYTES]; + uint8_t r[NISTP256_CURVE_LENGTH_BYTES]; + uint8_t * p = buf; + const uint8_t * end = buf + len; + + ECJPAKE_OperationGenerateZKP operationGenerateZKP; + + ECJPAKE_ALT_CHK(ecjpake_alt_generate_round2_keys(ctx)); + + ECJPAKE_ALT_CHK( + ecjpake_hash(ctx->md_info, &ctx->myGeneratorKey, &ctx->myPublicCryptoV3, &ctx->myCombinedPublicKey, ID_MINE, hash)); + + ECJPAKE_OperationGenerateZKP_init(&operationGenerateZKP); + operationGenerateZKP.curve = &ECCParams_NISTP256; + operationGenerateZKP.myPrivateKey = &ctx->myCombinedPrivateKey; + operationGenerateZKP.myPrivateV = &ctx->myPrivateCryptoV3; + operationGenerateZKP.hash = hash; + operationGenerateZKP.r = r; + + ECJPAKE_ALT_CHK(ECJPAKE_generateZKP(ctx->handle, &operationGenerateZKP)); + + if (ctx->role == MBEDTLS_ECJPAKE_SERVER) + { + /* write curve info */ + ECJPAKE_ALT_CHK(tls_write_curve_info(&p, end, ctx->curve)); + } + + /* write public key X */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myCombinedPublicKey)); + + /* write ZKP for X (V and r) */ + ECJPAKE_ALT_CHK(tls_write_crypto_key(&p, end, &ctx->myPublicCryptoV3)); + + /* write r */ + ECJPAKE_ALT_CHK(tls_write_binary(&p, end, r, NISTP256_CURVE_LENGTH_BYTES)); + + *olen = p - buf; + +cleanup: + return (ret); +} + +int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context * ctx, unsigned char * buf, size_t len, size_t * olen, + int (*f_rng)(void *, unsigned char *, size_t), void * p_rng) +{ + int ret; + unsigned char md_len; + CryptoKey sharedSecretCryptoKey; + uint8_t sharedSecretKeyingMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + + ECJPAKE_OperationComputeSharedSecret computeSharedSecret; + + md_len = mbedtls_md_get_size(ctx->md_info); + if (len < md_len) + { + return (MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL); + } + + CryptoKeyPlaintext_initKey(&sharedSecretCryptoKey, sharedSecretKeyingMaterial1, sizeof(sharedSecretKeyingMaterial1)); + + /* Generate shared secret */ + ECJPAKE_OperationComputeSharedSecret_init(&computeSharedSecret); + computeSharedSecret.curve = &ECCParams_NISTP256; + computeSharedSecret.myCombinedPrivateKey = &ctx->myCombinedPrivateKey; + computeSharedSecret.theirCombinedPublicKey = &ctx->theirCombinedPublicKey; + computeSharedSecret.theirPublicKey2 = &ctx->theirPublicCryptoKey2; + computeSharedSecret.myPrivateKey2 = &ctx->myPrivateCryptoKey2; + computeSharedSecret.sharedSecret = &sharedSecretCryptoKey; + + ECJPAKE_ALT_CHK(ECJPAKE_computeSharedSecret(ctx->handle, &computeSharedSecret)); + + ECJPAKE_ALT_CHK(mbedtls_md(ctx->md_info, sharedSecretKeyingMaterial1 + 1, NISTP256_CURVE_LENGTH_BYTES, buf)); + + *olen = md_len; + +cleanup: + return (ret); +} + +#undef ID_MINE +#undef ID_PEER + +#endif /* MBEDTLS_ECJPAKE_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.h b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.h new file mode 100644 index 00000000000000..9104b1a47e0489 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/ecjpake_alt.h @@ -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. + */ + +#pragma once + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls-config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_ECJPAKE_ALT) + +#include "mbedtls/ecp.h" +#include "mbedtls/md.h" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Length of parameters for the NIST p256r1. + * + * ECJ-PAKE is only defined for p256r1 + */ +#define NISTP256_CURVE_LENGTH_BYTES (32) + +/** + * Size in bytes of the identifier at the beginning of the point format + */ +#define OCTET_STRING_OFFSET 1 + +/** + * Size in bytes of a point expressed in the TLS point format + * + * id_byte || X coord || Y coord + */ +#define NISTP256_PUBLIC_KEY_LENGTH_BYTES (OCTET_STRING_OFFSET + (NISTP256_CURVE_LENGTH_BYTES * 2)) + +/** + * EC J-PAKE context structure. + */ +typedef struct +{ + const mbedtls_md_info_t * md_info; + mbedtls_ecp_group_id curve; + mbedtls_ecjpake_role role; + int point_format; + + bool roundTwoGenerated; + /* + * XXX: possible size reduction by moving ephemeral material to round + * calculations. + */ + unsigned char myPrivateKeyMaterial1[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char myPrivateKeyMaterial2[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char myPrivateVMaterial1[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char myPrivateVMaterial2[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char myPrivateVMaterial3[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char myPublicKeyMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myPublicKeyMaterial2[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myPublicVMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myPublicVMaterial2[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myPublicVMaterial3[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myCombinedPublicKeyMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myCombinedPrivateKeyMaterial1[NISTP256_CURVE_LENGTH_BYTES]; + unsigned char nistP256Generator[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char myGenerator[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char theirPublicKeyMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char theirPublicKeyMaterial2[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char theirCombinedPublicKeyMaterial1[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char theirGenerator[NISTP256_PUBLIC_KEY_LENGTH_BYTES]; + unsigned char preSharedSecretKeyingMaterial[NISTP256_CURVE_LENGTH_BYTES]; + + CryptoKey nistP256GeneratorCryptoKey; + CryptoKey preSharedSecretCryptoKey; + CryptoKey myPrivateCryptoKey1; + CryptoKey myPrivateCryptoKey2; + CryptoKey myPrivateCryptoV1; + CryptoKey myPrivateCryptoV2; + CryptoKey myPrivateCryptoV3; + CryptoKey myCombinedPrivateKey; + CryptoKey myPublicCryptoKey1; + CryptoKey myPublicCryptoKey2; + CryptoKey myPublicCryptoV1; + CryptoKey myPublicCryptoV2; + CryptoKey myPublicCryptoV3; + CryptoKey myCombinedPublicKey; + CryptoKey myGeneratorKey; + CryptoKey theirPublicCryptoKey1; + CryptoKey theirPublicCryptoKey2; + CryptoKey theirCombinedPublicKey; + CryptoKey theirGeneratorKey; + + ECJPAKE_Handle handle; +} mbedtls_ecjpake_context; + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_ECJPAKE_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.c b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.c new file mode 100644 index 00000000000000..5adc0c8f3da9fa --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.c @@ -0,0 +1,192 @@ +/* + * + * 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. + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include + +#if defined(MBEDTLS_SHA256_ALT) + +#include + +#include +#include + +/*! + * Hardware-specific configuration attributes, may be replaced with SysConfig + * ti_drivers.h structure. + */ +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs_sha = { + .intPriority = ~0, +}; + +void mbedtls_sha256_init(mbedtls_sha256_context * ctx) +{ + SHA2_Params sha2Params; + + memset(ctx, 0, sizeof(mbedtls_sha256_context)); + SHA2_Params_init(&sha2Params); + + sha2Params.returnBehavior = SHA2_RETURN_BEHAVIOR_POLLING; + + ctx->config.object = &ctx->object; + ctx->config.hwAttrs = &sha2CC26X2HWAttrs_sha; + + ctx->hndl = SHA2_construct(&ctx->config, &sha2Params); +} + +void mbedtls_sha256_free(mbedtls_sha256_context * ctx) +{ + if (NULL == ctx) + { + return; + } + + if (ctx->hndl != NULL) + { + SHA2_close(ctx->hndl); + + memset(ctx, 0, sizeof(mbedtls_sha256_context)); + } +} + +/* + * Deviation from documentation in sha256.h. + * + * It has been noticed that some code using mbedtls does not call `init` before + * starting a SHA operation. Rather these implementations assume the `ctx` + * structure may be zero'ed out as initialization. To support this usage the + * driver instance is assumed to be uninitialized if the context's `hndl` is a + * NULL pointer. Start will initialize the driver and assign the handle to the + * context in this case. + */ +int mbedtls_sha256_starts_ret(mbedtls_sha256_context * ctx, int is224) +{ + SHA2_HashType type; + + // open the driver here because no-one called init + if (ctx->hndl == NULL) + { + SHA2_Params sha2Params; + + SHA2_Params_init(&sha2Params); + + sha2Params.returnBehavior = SHA2_RETURN_BEHAVIOR_POLLING; + + ctx->config.object = &ctx->object; + ctx->config.hwAttrs = &sha2CC26X2HWAttrs_sha; + + ctx->hndl = SHA2_construct(&ctx->config, &sha2Params); + + if (NULL == ctx->hndl) + { + return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; + } + } + else + { + SHA2_reset(ctx->hndl); + } + + if (is224) + { + type = SHA2_HASH_TYPE_224; + } + else + { + type = SHA2_HASH_TYPE_256; + } + + SHA2_setHashType(ctx->hndl, type); + + return 0; +} + +/** + * Deviation from documentation in sha256.h. + * + * It has been noticed that some code using mbedtls does not call `init` on the + * contexts being passed into this function. This seems to be done to avoid + * allocating hardware to cloned context instances. To support this use-case, + * only internal buffers to the SHA2 structure are copied without checking the + * driver handles. + */ +void mbedtls_sha256_clone(mbedtls_sha256_context * dst, const mbedtls_sha256_context * src) +{ + dst->object.hashType = src->object.hashType; + dst->object.bytesInBuffer = src->object.bytesInBuffer; + dst->object.bytesProcessed = src->object.bytesProcessed; + memcpy(dst->object.buffer, src->object.buffer, sizeof(dst->object.buffer)); + // copy the digest to support cloning after finalization has happened + memcpy(dst->object.digest, src->object.digest, sizeof(dst->object.digest)); +} + +int mbedtls_sha256_finish_ret(mbedtls_sha256_context * ctx, unsigned char output[32]) +{ + int_fast16_t result; + + result = SHA2_finalize(ctx->hndl, output); + + if (SHA2_STATUS_SUCCESS != result) + { + return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; + } + else + { + return 0; + } +} + +int mbedtls_sha256_update_ret(mbedtls_sha256_context * ctx, const unsigned char * input, size_t ilen) +{ + int_fast16_t result; + + // Process data in chunks. The driver buffers incomplete blocks internally. + result = SHA2_addData(ctx->hndl, input, ilen); + + if (SHA2_STATUS_SUCCESS != result) + { + return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; + } + else + { + return 0; + } +} + +int mbedtls_internal_sha256_process(mbedtls_sha256_context * ctx, const unsigned char data[64]) +{ + int_fast16_t result; + + // Process data in chunks. The driver buffers incomplete blocks internally. + result = SHA2_addData(ctx->hndl, data, SHA2_BLOCK_SIZE_BYTES_256); + + if (SHA2_STATUS_SUCCESS != result) + { + return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; + } + else + { + return 0; + } +} + +#endif /* MBEDTLS_SHA256_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.h b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.h new file mode 100644 index 00000000000000..75bb300398905c --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/crypto/sha256_alt.h @@ -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. + */ + +#pragma once + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls-config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_SHA256_ALT) +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct +{ + SHA2_Handle hndl; /*!< A handle that is returned by the SHA driver */ + SHA2_Config config; /*!< structure containing SHA2 driver specific implementation */ + SHA2CC26X2_Object object; /*!< Pointer to a driver specific data object */ +} mbedtls_sha256_context; + +#ifdef __cplusplus +} +#endif +#endif /* MBEDTLS_SHA256_ALT */ diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config-check.h b/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config-check.h new file mode 100644 index 00000000000000..a5fcac9459b6c4 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config-check.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT +#error "Platform cc1352 doesn't support configuration option: OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT" +#endif diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config.h b/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config.h new file mode 100644 index 00000000000000..5857675e1a309d --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/openthread-core-cc13x4_26x4-config.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#ifdef DeviceFamily_CC13X4 + +/* Number of message buffers reduced to fit into CC26x2x3 RAM */ +#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 + +#endif // DeviceFamily_CC13X4 + +#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_HEAP_EXTERNAL_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 +#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE 1 + +#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0 +#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0 +#define OPENTHREAD_CONFIG_JOINER_ENABLE 0 + +#define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS 0 +// TCP disabled until OpenThread has a GN/Ninja build for the tcplp library +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 diff --git a/src/platform/cc13x2_26x2/chipOBleProfile.c b/src/platform/cc13xx_26xx/chipOBleProfile.c similarity index 100% rename from src/platform/cc13x2_26x2/chipOBleProfile.c rename to src/platform/cc13xx_26xx/chipOBleProfile.c diff --git a/src/platform/cc13x2_26x2/chipOBleProfile.h b/src/platform/cc13xx_26xx/chipOBleProfile.h similarity index 100% rename from src/platform/cc13x2_26x2/chipOBleProfile.h rename to src/platform/cc13xx_26xx/chipOBleProfile.h diff --git a/src/platform/cc13x2_26x2/oad_image_header.c b/src/platform/cc13xx_26xx/oad_image_header.c similarity index 100% rename from src/platform/cc13x2_26x2/oad_image_header.c rename to src/platform/cc13xx_26xx/oad_image_header.c diff --git a/src/platform/device.gni b/src/platform/device.gni index 77ca207ebbe768..8b6d9787f2a051 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, cc32xx, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, cyw30739, bl602, mw320, zephyr, beken, openiotsdk, none. + # Device platform layer: cc13x2_26x2, cc13x4_26x4, cc32xx, darwin, efr32, esp32, external, freertos, linux, nrfconnect, k32w0, qpg, tizen, cyw30739, bl602, mw320, zephyr, beken, openiotsdk, none. chip_device_platform = "auto" chip_platform_target = "" @@ -50,6 +50,7 @@ declare_args() { chip_enable_openthread = chip_device_platform == "linux" || chip_device_platform == "qpg" || chip_device_platform == "cc13x2_26x2" || + chip_device_platform == "cc13x4_26x4" || chip_device_platform == "k32w0" || chip_device_platform == "tizen" || chip_device_platform == "webos" } @@ -90,7 +91,8 @@ declare_args() { chip_device_platform == "openiotsdk") { chip_mdns = "minimal" } else if (chip_device_platform == "darwin" || - chip_device_platform == "cc13x2_26x2" || current_os == "android" || + chip_device_platform == "cc13x2_26x2" || + chip_device_platform == "cc13x4_26x4" || current_os == "android" || chip_device_platform == "fake" || chip_device_platform == "tizen") { chip_mdns = "platform" @@ -115,7 +117,9 @@ if (chip_device_platform == "bl702" && chip_enable_openthread) { _chip_device_layer = "none" if (chip_device_platform == "cc13x2_26x2") { - _chip_device_layer = "cc13x2_26x2" + _chip_device_layer = "cc13xx_26xx/cc13x2_26x2" +} else if (chip_device_platform == "cc13x4_26x4") { + _chip_device_layer = "cc13xx_26xx/cc13x4_26x4" } else if (chip_device_platform == "cc32xx") { _chip_device_layer = "cc32xx" } else if (chip_device_platform == "darwin") { @@ -218,6 +222,7 @@ assert( (current_os != "freertos" && chip_device_platform == "none") || chip_device_platform == "fake" || chip_device_platform == "cc13x2_26x2" || + chip_device_platform == "cc13x4_26x4" || chip_device_platform == "cc32xx" || chip_device_platform == "darwin" || chip_device_platform == "efr32" || chip_device_platform == "esp32" || chip_device_platform == "external" || chip_device_platform == "linux" || diff --git a/third_party/openthread/ot-ti b/third_party/openthread/ot-ti new file mode 160000 index 00000000000000..8bec26bf2a882d --- /dev/null +++ b/third_party/openthread/ot-ti @@ -0,0 +1 @@ +Subproject commit 8bec26bf2a882d252a83ce4154a5c8e0031e56c0 diff --git a/third_party/openthread/platforms/cc13x2_26x2/BUILD.gn b/third_party/openthread/platforms/cc13x2_26x2/BUILD.gn new file mode 100644 index 00000000000000..476d0232fdf358 --- /dev/null +++ b/third_party/openthread/platforms/cc13x2_26x2/BUILD.gn @@ -0,0 +1,74 @@ +# 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/openthread.gni") +import("//build_overrides/ti_simplelink_sdk.gni") + +import("${ti_simplelink_sdk_build_root}/ti_simplelink_board.gni") +import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni") + +openthread_ti_root = "${chip_root}/third_party/openthread/ot-ti" + +config("openthread_cc13x2_cc26x2_config") { + include_dirs = [ + "${openthread_root}/examples/platforms", + "${openthread_root}/src/core", + "${openthread_ti_root}/src", + ] +} + +source_set("libopenthread-cc13x2_cc26x2") { + cflags = [ + "-Wno-address-of-packed-member", + "-Wno-implicit-fallthrough", + "-Wno-unused-label", + ] + public_deps = [ + "${openthread_root}/src/core:libopenthread_core_headers", + "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk", + "${ti_simplelink_sdk_build_root}:ti_simplelink_sysconfig", + ] + + configs -= [ "${build_root}/config/compiler:std_default" ] + configs += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_posix_config" ] + + #configs += [ ":${sdk_target_name}_posix_config" ] + #configs += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk_posix_config" ] + sources = [ + #"${openthread_ti_root}/src/system.c", + "${openthread_root}/examples/platforms/utils/code_utils.h", + "${openthread_root}/examples/platforms/utils/link_metrics.cpp", + "${openthread_root}/examples/platforms/utils/link_metrics.h", + "${openthread_root}/examples/platforms/utils/mac_frame.cpp", + "${openthread_root}/examples/platforms/utils/mac_frame.h", + "${openthread_ti_root}/src/alarm.c", + "${openthread_ti_root}/src/alarm_micro.c", + "${openthread_ti_root}/src/diag.c", + "${openthread_ti_root}/src/entropy.c", + "${openthread_ti_root}/src/misc.c", + "${openthread_ti_root}/src/radio.c", + "${openthread_ti_root}/src/settings.c", + ] + + public_configs = [ + ":openthread_cc13x2_cc26x2_config", + "${openthread_root}:openthread_config", + ] + if (chip_openthread_ftd) { + public_configs += [ "${openthread_root}:openthread_ftd_config" ] + } else { + public_configs += [ "${openthread_root}:openthread_mtd_config" ] + } +} diff --git a/third_party/openthread/platforms/cc13x4_26x4/BUILD.gn b/third_party/openthread/platforms/cc13x4_26x4/BUILD.gn new file mode 100644 index 00000000000000..64b0a813935f0e --- /dev/null +++ b/third_party/openthread/platforms/cc13x4_26x4/BUILD.gn @@ -0,0 +1,74 @@ +# 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/openthread.gni") +import("//build_overrides/ti_simplelink_sdk.gni") + +import("${ti_simplelink_sdk_build_root}/ti_simplelink_board.gni") +import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni") + +openthread_ti_root = "${chip_root}/third_party/openthread/ot-ti" + +config("openthread_cc13x4_cc26x4_config") { + include_dirs = [ + "${openthread_root}/examples/platforms", + "${openthread_root}/src/core", + "${openthread_ti_root}/src", + ] +} + +source_set("libopenthread-cc13x4_cc26x4") { + cflags = [ + "-Wno-address-of-packed-member", + "-Wno-implicit-fallthrough", + "-Wno-unused-label", + ] + public_deps = [ + "${openthread_root}/src/core:libopenthread_core_headers", + "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk", + "${ti_simplelink_sdk_build_root}:ti_simplelink_sysconfig", + ] + + configs -= [ "${build_root}/config/compiler:std_default" ] + configs += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_posix_config" ] + + #configs += [ ":${sdk_target_name}_posix_config" ] + #configs += [ "${ti_simplelink_sdk_build_root}:ti_simplelink_sdk_posix_config" ] + sources = [ + #"${openthread_ti_root}/src/system.c", + "${openthread_root}/examples/platforms/utils/code_utils.h", + "${openthread_root}/examples/platforms/utils/link_metrics.cpp", + "${openthread_root}/examples/platforms/utils/link_metrics.h", + "${openthread_root}/examples/platforms/utils/mac_frame.cpp", + "${openthread_root}/examples/platforms/utils/mac_frame.h", + "${openthread_ti_root}/src/alarm.c", + "${openthread_ti_root}/src/alarm_micro.c", + "${openthread_ti_root}/src/diag.c", + "${openthread_ti_root}/src/entropy.c", + "${openthread_ti_root}/src/misc.c", + "${openthread_ti_root}/src/radio.c", + "${openthread_ti_root}/src/settings.c", + ] + + public_configs = [ + ":openthread_cc13x4_cc26x4_config", + "${openthread_root}:openthread_config", + ] + if (chip_openthread_ftd) { + public_configs += [ "${openthread_root}:openthread_ftd_config" ] + } else { + public_configs += [ "${openthread_root}:openthread_mtd_config" ] + } +} diff --git a/third_party/ti_simplelink_sdk/BUILD.gn b/third_party/ti_simplelink_sdk/BUILD.gn index d0b8d79372ea31..8f6c4806d2182a 100644 --- a/third_party/ti_simplelink_sdk/BUILD.gn +++ b/third_party/ti_simplelink_sdk/BUILD.gn @@ -44,8 +44,17 @@ config("ti_simplelink_mbedtls_config") { defines = [ "MBEDTLS_CONFIG_FILE=\"cc13x2_26x2-mbedtls-config.h\"" ] include_dirs = [ - "${chip_root}/src/platform/cc13x2_26x2", - "${chip_root}/src/platform/cc13x2_26x2/crypto", + "${chip_root}/src/platform/cc13xx_26xx/", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto", + "${ti_simplelink_sdk_root}/source", + ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + defines = [ "MBEDTLS_CONFIG_FILE=\"cc13x4_26x4-mbedtls-config.h\"" ] + include_dirs = [ + "${chip_root}/src/platform/cc13xx_26xx/", + "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4", + "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/crypto", "${ti_simplelink_sdk_root}/source", ] } else if (ti_simplelink_device_family == "cc32xx") { @@ -60,11 +69,11 @@ mbedtls_target("mbedtls") { 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", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/aes_alt.c", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdh_alt.c", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecdsa_alt.c", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/ecjpake_alt.c", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/crypto/sha256_alt.c", ] } @@ -79,9 +88,17 @@ config("ti_simplelink_freertos_config") { if (ti_simplelink_device_family == "cc13x2_26x2" || ti_simplelink_device_family == "cc13x2x7_26x2x7") { include_dirs = [ - "${chip_root}/src/platform/cc13x2_26x2", + "${chip_root}/src/platform/cc13xx_26xx", + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2", "${freertos_root}/repo/portable/GCC/ARM_CM4F", ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + include_dirs = [ + "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4", + "${freertos_root}/repo/portable/GCC/ARM_CM33_NTZ", + "${freertos_root}/repo/portable/GCC/ARM_CM33_NTZ/non_secure", + "${chip_root}/src/platform/cc13xx_26xx", + ] } else if (ti_simplelink_device_family == "cc32xx") { include_dirs = [ "${chip_root}/src/platform/cc32xx", @@ -90,12 +107,25 @@ config("ti_simplelink_freertos_config") { } } +config("ti_simplelink_posix_config") { + include_dirs = [ "${ti_simplelink_sdk_root}/source/ti/posix/gcc" ] + cflags_c = [ "-std=c11" ] + cflags_cc = [ "-std=c++14" ] + cflags = [ + "-Wno-maybe-uninitialized", + "-Wno-sign-compare", + ] +} + freertos_target("freertos") { if (ti_simplelink_device_family == "cc13x2_26x2" || ti_simplelink_device_family == "cc13x2x7_26x2x7") { + sources = [ "${freertos_root}/repo/portable/GCC/ARM_CM4F/port.c" ] + } else if (ti_simplelink_device_family == "cc13x4_26x4" || + ti_simplelink_device_family == "cc13x4_26x4") { sources = [ - "${freertos_root}/repo/portable/GCC/ARM_CM4F/port.c", - #"${freertos_root}/repo/portable/MemMang/heap_4.c", + "${freertos_root}/repo/portable/GCC/ARM_CM33_NTZ/non_secure/port.c", + "${freertos_root}/repo/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c", ] } else if (ti_simplelink_device_family == "cc32xx") { sources = [ @@ -106,7 +136,8 @@ freertos_target("freertos") { public_configs = [ ":ti_simplelink_freertos_config" ] - if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + if (ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { # BLE has to have it's own heap config public_deps = [ "${chip_root}/third_party/ti_simplelink_sdk:ti_simplelink_sysconfig" ] diff --git a/third_party/ti_simplelink_sdk/run_sysconfig.py b/third_party/ti_simplelink_sdk/run_sysconfig.py index c394b59f68fa64..15d5f5dd6de1cd 100644 --- a/third_party/ti_simplelink_sdk/run_sysconfig.py +++ b/third_party/ti_simplelink_sdk/run_sysconfig.py @@ -29,4 +29,6 @@ proc_call += sys.argv[2:] # exec -subprocess.call(proc_call) +ret = subprocess.call(proc_call) + +sys.exit(ret) 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 2ee40881b23bca..79b7aa1f59a695 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 == "cc13x4_26x4") { + arm_arch = "" + arm_abi = "" + arm_cpu = "cortex-m33" + 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 = "" diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_board.gni b/third_party/ti_simplelink_sdk/ti_simplelink_board.gni index c6ae89ab2d8d43..a89d2aebc28898 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_board.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_board.gni @@ -25,13 +25,14 @@ assert(ti_simplelink_board != "", "ti_simplelink_board must be specified") # Differentiate between boards # -# | Development Kit | Device Family | SoC | | -# | ----------------- | --------------- | ---------- | ------------------- | -# | 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 | +# | Development Kit | Device Family | SoC | | +# | ----------------- | --------------- | ---------- | ------------------- | +# | 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 | +# | CC134P10_6_LAUNCHXL| cc13x4_26x4 | cc1354p10 | 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") { @@ -50,6 +51,12 @@ if (ti_simplelink_board == "CC1352R1_LAUNCHXL") { # set -DDeviceFamily_CC26X2? ti_simplelink_soc = "cc2652r1f3" ti_simplelink_bim_name = "cc2652r1lp" +} else if (ti_simplelink_board == "LP_EM_CC1354P10_6") { + ti_simplelink_device_family = "cc13x4_26x4" + ti_simplelink_soc_family = "cc13x4" + ti_simplelink_isa = "m33f" + ti_simplelink_soc = "cc1354p10" + ti_simplelink_bim_name = "cc1354p10" } else if (ti_simplelink_board == "LP_CC2652R7") { ti_simplelink_device_family = "cc13x2x7_26x2x7" ti_simplelink_soc_family = "cc26x2" diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni index 650f336c443d22..da4dff87a73460 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni @@ -47,7 +47,8 @@ template("ti_simplelink_executable") { output_base_name = get_path_info(invoker.output_name, "name") #used for OTA image creator for the cc13xx - if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + if (ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { objcopy_image_name = output_base_name + ".hex" objcopy_image_format = "ihex" } else { @@ -80,10 +81,18 @@ template("ti_simplelink_executable") { if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { if (chip_enable_ota_requestor) { sources += - [ "${chip_root}/src/platform/cc13x2_26x2/oad_image_header.c" ] - ldscript = "${chip_root}/src/platform/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds" + [ "${chip_root}/src/platform/cc13xx_26xx/oad_image_header.c" ] + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds" } else { - ldscript = "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/cc13x2x7_cc26x2x7.lds" + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos.lds" + } + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + if (chip_enable_ota_requestor) { + sources += + [ "${chip_root}/src/platform/cc13xx_26xx/oad_image_header.c" ] + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds" + } else { + ldscript = "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos.lds" } } else if (ti_simplelink_device_family == "cc32xx") { ldscript = "${ti_simplelink_sdk_root}/source/ti/boards/cc32xxsf/cc32xxsf_freertos.lds" @@ -143,7 +152,7 @@ template("ti_simplelink_executable") { if (defined(invoker.bim_hex)) { bim_hex = invoker.bim_hex } else { - bim_hex = "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/ble5stack/hexfiles/bim_offchip/Release/${ti_simplelink_bim_name}_bim_offchip.hex" + bim_hex = "${ti_simplelink_sdk_root}/examples/nortos/${ti_simplelink_board}/bim/hexfiles/bim_offchip/Release/bim_offchip.hex" } args = [ diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni index dfbdb5f841bc87..08ef9bd1c6fd8a 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni @@ -30,9 +30,12 @@ declare_args() { # Location of the TI SimpleLink SDK. if (ti_simplelink_device_family == "cc13x2_26x2" || - ti_simplelink_device_family == "cc13x2x7_26x2x7") { + ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { ti_simplelink_sdk_root = "${chip_root}/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx" + ot_cc13x2_cc26x2 = + "${chip_root}/third_party/ti_simplelink_sdk/repo_ot-cc13x2_cc26x2" } else if (ti_simplelink_device_family == "cc32xx") { ti_simplelink_sdk_root = "${chip_root}/third_party/ti_simplelink_sdk/repo_cc32xx" @@ -68,11 +71,26 @@ template("ti_sysconfig") { } if (ti_simplelink_device_family == "cc13x2_26x2") { - ldflags += [ "-nostartfiles" ] + ldflags += [ + "-nostartfiles", + "-fno-exceptions", + "-fno-unwind-tables", + ] defines += [ "DeviceFamily_CC13X2_CC26X2" ] } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { - ldflags += [ "-nostartfiles" ] + ldflags += [ + "-nostartfiles", + "-fno-exceptions", + "-fno-unwind-tables", + ] defines += [ "DeviceFamily_CC26X2X7" ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + ldflags += [ + "-nostartfiles", + "-fno-exceptions", + "-fno-unwind-tables", + ] + defines += [ "DeviceFamily_CC13X4" ] } else if (ti_simplelink_device_family == "cc32xx") { ldflags += [ "-nostartfiles" ] defines += [ "CC32XXWARE" ] @@ -148,7 +166,8 @@ template("ti_simplelink_sdk") { defines = [] if (ti_simplelink_device_family == "cc13x2_26x2" || - ti_simplelink_device_family == "cc13x2x7_26x2x7") { + ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { assert(ti_simplelink_soc_family != "", "ti_simplelink_soc_family must be specified") assert(ti_simplelink_device_family != "", @@ -185,6 +204,9 @@ template("ti_simplelink_sdk") { } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { defines += [ "DeviceFamily_CC13X2X7_CC26X2X7" ] libs += [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/driverlib/bin/gcc/driverlib.lib" ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + defines += [ "DeviceFamily_CC13X4" ] + libs += [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4/driverlib/bin/gcc/driverlib.lib" ] } if (ti_simplelink_device_family == "cc32xx") { @@ -226,6 +248,14 @@ template("ti_simplelink_sdk") { "${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 == "cc13x4_26x4") { + 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_cc13x4_cc26x4_gcc.c", + ] } else if (ti_simplelink_device_family == "cc32xx") { sources += [ "${ti_simplelink_sdk_root}/kernel/freertos/dpl/ClockP_freertos.c", @@ -282,69 +312,32 @@ template("ti_simplelink_sdk") { } 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") { + ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { + source_set("${sdk_target_name}_nvocmp") { 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", - "${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", + "-Wno-shadow", ] 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", + "${ti_simplelink_sdk_root}/source/ti/common/nv/crc.c", + "${ti_simplelink_sdk_root}/source/ti/common/nv/nvocmp.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" ] if (chip_openthread_ftd) { public_configs += @@ -360,60 +353,11 @@ template("ti_simplelink_sdk") { include_dirs = [] libs = [] - include_dirs += [ - # DMM/BLE: - "${ti_simplelink_sdk_root}/source", - - # Eclipse the SDK config header from DMM - "${chip_root}/src/platform/cc13x2_26x2", - - # CHIPoBLE Added include dirs - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/itm", - "${ti_simplelink_sdk_root}/source/ti/dmm/thread/platform", - "${ti_simplelink_sdk_root}/source/", - "${ti_simplelink_sdk_root}/source/ti/", - "${ti_simplelink_sdk_root}/source/ti/dmm/", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/", - "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/", - "${ti_simplelink_sdk_root}/source/ti/common/nv", - - "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7", - "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/inc", - "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/rf_patches", - "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/driverlib", - - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/npi/stack/", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/rcosc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/controller/cc26xx/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common/cc26xx", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/heapmgr", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common/cc26xx/", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/simple_profile", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/osal/src/inc", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/controller/cc26xx/inc/", - "${ti_simplelink_sdk_root}/source/ti/common/cc26xx", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/", - ] - defines = [ "INCLUDE_BGET_STATS", "USE_DMM", - "FLASH_ROM_BUILD", "NVOCMP_FREERTOS_MUTEX=1", "USEOT", - "ONE_BLE_LIB_SIZE_OPTIMIZATION", "ICALL_EVENTS", "ICALL_JT", "ICALL_LITE", @@ -421,16 +365,12 @@ template("ti_simplelink_sdk") { "ICALL_MAX_NUM_TASKS=3", "ICALL_STACK0_ADDR", "POWER_SAVING", - "STACK_LIBRARY", "TBM_ACTIVE_ITEMS_ONLY", "NPI_USE_UART", "NPI_FLOW_CTRL=0", "OSAL_CBTIMER_NUM_TASKS=1", "USE_ICALL", "BLE_START", - "CC26XX", - "CC26X2", - "CC26X2R1_LAUNCHXL", "FREERTOS", ] @@ -441,11 +381,131 @@ template("ti_simplelink_sdk") { "${ti_simplelink_sdk_root}/source/ti/ble5stack/libraries/cc26x2r1/StackWrapper.a", "${ti_simplelink_sdk_root}/source/ti/ble5stack/libraries/cc26x2r1/ble_r2.symbols", ] + + defines += [ + "FLASH_ROM_BUILD", + "ONE_BLE_LIB_SIZE_OPTIMIZATION", + "STACK_LIBRARY", + "CC26XX", + "CC26X2", + "CC26X2R1_LAUNCHXL", + ] + include_dirs += [ + # DMM/BLE: + "${ti_simplelink_sdk_root}/source", + + # Eclipse the SDK config header from DMM + "${chip_root}/src/platform/cc13x2_26x2", + + # CHIPoBLE Added include dirs + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/itm", + "${ti_simplelink_sdk_root}/source/ti/dmm/thread/platform", + "${ti_simplelink_sdk_root}/source/", + "${ti_simplelink_sdk_root}/source/ti/", + "${ti_simplelink_sdk_root}/source/ti/dmm/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/", + "${ti_simplelink_sdk_root}/source/ti/common/nv", + + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/inc", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/rf_patches", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7/driverlib", + + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/npi/stack/", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/rcosc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/controller/cc26xx/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/heapmgr", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/hal/src/target/_common/cc26xx/", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/simple_profile", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/osal/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/controller/cc26xx/inc/", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/", + ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + libs += [ + "${ti_simplelink_sdk_root}/source/ti/dmm/lib/gcc/m4f/libdmmlib_freertos.a", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/libraries/cc1354p10_6/OneLib.a", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/libraries/cc1354p10_6/StackWrapper.a", + ] + defines += [ + "ONE_BLE_LIB_SIZE_OPTIMIZATION", + "NVOCMP_NVPAGES=3", + "NVOCMP_NWSAMEITEM=1", + "CC13X2P", + "SYSCFG", + "CC13X4", + "CC13XX", + "EXTENDED_STACK_SETTINGS=EXTENDED_STACK_SETTINGS_DEFAULT", + ] + + include_dirs += [ + # DMM/BLE: + "${ti_simplelink_sdk_root}/source", + + # Eclipse the SDK config header from DMM + "${chip_root}/src/platform/cc13x4_26x4", + "${chip_root}/src/platform/cc13xx_26xx", + + # CHIPoBLE Added include dirs + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/itm", + "${ti_simplelink_sdk_root}/source/ti/dmm/thread/platform", + "${ti_simplelink_sdk_root}/source/", + "${ti_simplelink_sdk_root}/source/ti/", + "${ti_simplelink_sdk_root}/source/ti/dmm/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/", + "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/", + "${ti_simplelink_sdk_root}/source/ti/common/nv", + + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4/inc", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4/rf_patches", + "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4/driverlib", + + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/common/cc26xx/npi/stack/", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/common/cc26xx/rcosc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/controller/cc26xx/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/rom", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/common/cc26xx/freertos", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/src", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/hal/src/target/_common", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/hal/src/target/_common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/hal/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/heapmgr", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/profiles/dev_info", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/hal/src/target/_common/cc26xx/", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/profiles/simple_profile", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/osal/src/inc", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/controller/cc26xx/inc/", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/", + ] } cflags = [ "-Wno-conversion", "-Wno-comment", + "-Wno-shadow", "@" + rebase_path(ti_simplelink_sdk_root + "/source/ti/ble5stack/config/build_components.opt", root_build_dir), @@ -457,6 +517,7 @@ template("ti_simplelink_sdk") { source_set("${sdk_target_name}_dmm") { if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x4_26x4" || ti_simplelink_device_family == "cc13x2x7_26x2x7") { defines = [] include_dirs = [ @@ -474,28 +535,48 @@ template("ti_simplelink_sdk") { ] sources = [ + "${chip_root}/src/platform/cc13xx_26xx/chipOBleProfile.c", "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/TI_heap_wrapper.c", "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/freertos/bget.c", "${ti_simplelink_sdk_root}/source/ti/ble5stack/common/cc26xx/rcosc/rcosc_calibration.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gatt_uuid.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gattservapp_util.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/app/icall_api_lite.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_cc2650.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_user_config.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/stack/ble_user_config_stack.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info/cc26xx/devinfoservice.c", - "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom/agama_r1/rom_init.c", "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/ble_remote_display/stack/osal_icall_ble.c", "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/icall_FreeRTOS.c", "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/util.c", "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/thread/source/activity/dmm_thread_activity.c", "${ti_simplelink_sdk_root}/source/ti/dmm/dmm_priority_ble_thread.c", - - # Move this into the SDK - "${chip_root}/src/platform/cc13x2_26x2/ble_user_config.c", - "${chip_root}/src/platform/cc13x2_26x2/chipOBleProfile.c", ] + if (ti_simplelink_device_family == "cc13x2_26x2" || + ti_simplelink_device_family == "cc13x2x7_26x2x7") { + sources += [ + "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/ble_user_config.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gatt_uuid.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/host/gattservapp_util.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/app/icall_api_lite.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_cc2650.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/src/icall_user_config.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/icall/stack/ble_user_config_stack.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/profiles/dev_info/cc26xx/devinfoservice.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack/rom/agama_r1/rom_init.c", + ] + + include_dirs += [ "${chip_root}/src/platform/cc13xx_26xx/cc13x2_26x2/" ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + sources += [ + "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/ble_user_config.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/host/gatt_uuid.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/host/gattservapp_util.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/app/icall_api_lite.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/src/icall_cc2650.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/src/icall_user_config.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/icall/stack/ble_user_config_stack.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/profiles/dev_info/cc26xx/devinfoservice.c", + "${ti_simplelink_sdk_root}/source/ti/ble5stack_flash/rom/agama_r1/rom_init.c", + ] + + include_dirs += [ "${chip_root}/src/platform/cc13xx_26xx/cc13x4_26x4/" ] + } + configs -= [ "${build_root}/config/compiler:std_default" ] configs += [ ":${sdk_target_name}_posix_config" ] @@ -517,10 +598,11 @@ template("ti_simplelink_sdk") { ":${sdk_target_name}_freertos", ] if (ti_simplelink_device_family == "cc13x2_26x2" || - ti_simplelink_device_family == "cc13x2x7_26x2x7") { + ti_simplelink_device_family == "cc13x2x7_26x2x7" || + ti_simplelink_device_family == "cc13x4_26x4") { public_deps += [ ":${sdk_target_name}_dmm", - ":${sdk_target_name}_openthread_platform", + ":${sdk_target_name}_nvocmp", ] } if (defined(invoker.public_configs)) { @@ -528,3 +610,68 @@ template("ti_simplelink_sdk") { } } } + +# "${openthread_root}/src/core:libopenthread_core_headers", + +# config("${sdk_target_name}_openthread_platform_config") { +# 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", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2", +# ] +# } else if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { +# include_dirs += [ +# "${ti_simplelink_sdk_root}/source/ti/devices/cc13x2x7_cc26x2x7", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2", +# ] +# } +# } + +# 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 = [ +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/alarm.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/alarm_micro.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/diag.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/entropy.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/misc.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/radio.c", +# "${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/settings.c", +# #"${ot_cc13x2_cc26x2}/src/cc13x2_cc26x2/system.c", +# ] + +# 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" ] +# } +# }