diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07bd362f2..637816daf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,6 +103,7 @@ jobs: run: | export PATH=/tmp/${{ matrix.gcc_extract_dir }}/bin:$PATH script/test qpg6105 + script/test qpg6200 gcc-arm-none-linux-gnueabihf: name: gcc-arm-none-linux-gnueabihf-${{ matrix.gcc_ver }} diff --git a/CMakeLists.txt b/CMakeLists.txt index c766445d4..977b18ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,10 +32,12 @@ project(ot-qorvo VERSION 0.1.0) set(QORVO_PLATFORM_VALUES "gp712" "qpg6105" + "qpg6200" "qpg7015m" ) set(QORVO_MBEDTLS_USED "qpg6105" + "qpg6200" ) set_property(CACHE QORVO_PLATFORM PROPERTY STRINGS ${QORVO_PLATFORM_VALUES}) diff --git a/README.md b/README.md index b6ea99a12..c9b949794 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,11 @@ # OpenThread on Qorvo Example -This repo contains example platform drivers for [Qorvo GP712][gp712], [Qorvo QPG6105][qpg6105] and [Qorvo QPG7015M][qpg7015m]. +This repo contains example platform drivers for [Qorvo GP712][gp712], [Qorvo QPG6105][qpg6105], [Qorvo QPG6200L][qpg6200] and [Qorvo QPG7015M][qpg7015m]. [gp712]: https://www.qorvo.com/products/p/GP712 [qpg6105]: https://www.qorvo.com/products/p/QPG6105 +[qpg6200]: https://www.qorvo.com/products/p/QPG6200L [qpg7015m]: https://www.qorvo.com/products/p/QPG7015M To learn more about building and running the examples please check the [documentation](https://github.com/Qorvo/qpg-openthread/blob/master/README.md) diff --git a/script/build b/script/build index c50368416..7e359b763 100755 --- a/script/build +++ b/script/build @@ -31,7 +31,7 @@ set -euxo pipefail OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET:-} -QORVO_PLATFORMS=(gp712 qpg6105 qpg7015m) +QORVO_PLATFORMS=(gp712 qpg6105 qpg6200 qpg7015m) readonly QORVO_PLATFORMS OT_SRCDIR="$(pwd)" @@ -93,7 +93,7 @@ main() options+=("-DCMAKE_TOOLCHAIN_FILE=src/${platform}/arm-linux-gnueabihf.cmake") build -DQORVO_PLATFORM="${platform}" "${options[@]}" "${cmdline_options[@]}" ;; - qpg6105) + qpg6105 | qpg6200) OT_CMAKE_NINJA_TARGET=("ot-cli-ftd" "ot-cli-mtd") options+=("-DCMAKE_TOOLCHAIN_FILE=src/${platform}/arm-none-eabi.cmake") build -DQORVO_PLATFORM="${platform}" "${options[@]}" "${cmdline_options[@]}" @@ -101,7 +101,7 @@ main() esac case "${platform}" in - qpg6105) + qpg6105 | qpg6200) find "${builddir}/bin" -type f -executable -not -name '*.*' -not -name "${platform}-*" -not -name "*-test-*" \ -execdir sh -c 'x="$1"; arm-none-eabi-objcopy -O ihex "$1" "$2-$(basename ${x}).hex"' _ {} "${platform}" \; ;; diff --git a/script/test b/script/test index f294ea7f2..37879b810 100755 --- a/script/test +++ b/script/test @@ -29,7 +29,7 @@ set -euxo pipefail -QORVO_PLATFORMS=(gp712 qpg6105 qpg7015m) +QORVO_PLATFORMS=(gp712 qpg6105 qpg6200 qpg7015m) readonly QORVO_PLATFORMS OT_BUILDDIR="$(pwd)/build" diff --git a/src/qpg6105/crypto/common-mbedtls-config.h b/src/qpg6105/crypto/common-mbedtls-config.h index 1ca84002c..6913c1358 100644 --- a/src/qpg6105/crypto/common-mbedtls-config.h +++ b/src/qpg6105/crypto/common-mbedtls-config.h @@ -73,6 +73,8 @@ OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #define MBEDTLS_SSL_COOKIE_C #define MBEDTLS_SSL_SRV_C +#elif OPENTHREAD_CONFIG_JOINER_ENABLE +#define MBEDTLS_SSL_COOKIE_C #endif #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE diff --git a/src/qpg6200/CMakeLists.txt b/src/qpg6200/CMakeLists.txt new file mode 100755 index 000000000..961dab2f3 --- /dev/null +++ b/src/qpg6200/CMakeLists.txt @@ -0,0 +1,137 @@ +# +# Copyright (c) 2024, 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. +# + +target_compile_definitions(ot-config INTERFACE + "MBEDTLS_CONFIG_FILE=\"${SDK_DIR}/${QORVO_PLATFORM}/inc/${QORVO_PLATFORM}-mbedtls-config.h\"" +) + +list(APPEND OT_PUBLIC_INCLUDES + "${CMAKE_CURRENT_SOURCE_DIR}/crypto" +) + +set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) + +set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) + +set(PLATFORM_SOURCES + alarm.c + diag.c + entropy.c + logging.c + misc.c + platform.c + radio.c + settings.c + syscalls_stubs.c + uart.c +) + +add_library(${PLATFORM_TARGET_FTD} + STATIC + ${PLATFORM_SOURCES} +) + +set_target_properties(${PLATFORM_TARGET_FTD} + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 20 +) + +target_link_libraries(${PLATFORM_TARGET_FTD} + PRIVATE + -lc # Required to rearrange linking order to pick up syscalls stubs for libc + -Wl,--start-group + ${PLATFORM_DRIVER_FTD} + ot-config + -Wl,--end-group + PUBLIC + -T${SDK_DIR}/${QORVO_PLATFORM}/ld/${QORVO_PLATFORM}.ld + -nostdlib + -Wl,--gc-sections + -Wl,-Map=$.map,--cref +) + +target_compile_definitions(${PLATFORM_TARGET_FTD} + PUBLIC + ${OT_PLATFORM_DEFINES} +) + +target_compile_options(${PLATFORM_TARGET_FTD} + PRIVATE + ${OT_CFLAGS} +) + +target_include_directories(${PLATFORM_TARGET_FTD} + PRIVATE + ${OT_PUBLIC_INCLUDES} + ${OPENTHREAD_DIR}/examples/platforms +) + +add_library(${PLATFORM_TARGET_MTD} + STATIC + ${PLATFORM_SOURCES} +) + +set_target_properties(${PLATFORM_TARGET_MTD} + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 20 +) + +target_link_libraries(${PLATFORM_TARGET_MTD} + PRIVATE + -lc # Required to rearrange linking order to pick up syscalls stubs for libc + -Wl,--start-group + ${PLATFORM_DRIVER_MTD} + ot-config + -Wl,--end-group + PUBLIC + -T${SDK_DIR}/${QORVO_PLATFORM}/ld/${QORVO_PLATFORM}.ld + -nostdlib + -Wl,--gc-sections + -Wl,-Map=$.map,--cref +) + +target_compile_definitions(${PLATFORM_TARGET_MTD} + PUBLIC + ${OT_PLATFORM_DEFINES} +) + +target_compile_options(${PLATFORM_TARGET_MTD} + PRIVATE + ${OT_CFLAGS} +) + +target_include_directories(${PLATFORM_TARGET_MTD} + PRIVATE + ${OT_PUBLIC_INCLUDES} + ${OPENTHREAD_DIR}/examples/platforms +) + +target_include_directories(ot-config INTERFACE ${OT_PUBLIC_INCLUDES}) +target_compile_definitions(ot-config INTERFACE ${OT_PLATFORM_DEFINES}) diff --git a/src/qpg6200/alarm.c b/src/qpg6200/alarm.c new file mode 100644 index 000000000..9a455bb90 --- /dev/null +++ b/src/qpg6200/alarm.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file implements the OpenThread platform abstraction for the alarm. + * + */ + +#include +#include + +#include "alarm_qorvo.h" +#include +#include +#include + +uint32_t otPlatAlarmMilliGetNow(void) +{ + return qorvoAlarmGetTimeMs(); +} + +static void qorvoAlarmMilliFired(void *aInstance) +{ + otPlatAlarmMilliFired((otInstance *)aInstance); +} + +void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +{ + OT_UNUSED_VARIABLE(t0); + + qorvoAlarmStop((qorvoAlarmCallback_t)qorvoAlarmMilliFired, aInstance); + qorvoAlarmMilliStart(dt, qorvoAlarmMilliFired, aInstance); +} + +void otPlatAlarmMilliStop(otInstance *aInstance) +{ + qorvoAlarmStop((qorvoAlarmCallback_t)qorvoAlarmMilliFired, aInstance); +} + +uint32_t otPlatAlarmMicroGetNow(void) +{ + return qorvoAlarmGetTimeUs(); +} + +static void qorvoAlarmMicroFired(void *aInstance) +{ + otPlatAlarmMicroFired((otInstance *)aInstance); +} + +void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) +{ + OT_UNUSED_VARIABLE(t0); + + qorvoAlarmStop((qorvoAlarmCallback_t)qorvoAlarmMicroFired, aInstance); + qorvoAlarmMicroStart(dt, qorvoAlarmMicroFired, aInstance); +} + +void otPlatAlarmMicroStop(otInstance *aInstance) +{ + qorvoAlarmStop((qorvoAlarmCallback_t)qorvoAlarmMicroFired, aInstance); +} diff --git a/src/qpg6200/alarm_qorvo.h b/src/qpg6200/alarm_qorvo.h new file mode 100755 index 000000000..c26a82b4a --- /dev/null +++ b/src/qpg6200/alarm_qorvo.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the Alarm functions from the Qorvo library. + * + */ + +#ifndef ALARM_QORVO_H_ +#define ALARM_QORVO_H_ + +#include +#include +#include +#include + +typedef void (*qorvoAlarmCallback_t)(void *); + +/** + * This function initializes the alarm service used by OpenThread. + * + */ +void qorvoAlarmInit(void); + +/** + * This function retrieves the current host time in milliseconds. + * + * @param[out] The current time in ms. + * + */ +uint32_t qorvoAlarmGetTimeMs(void); + +/** + * This function retrieves the current host time in microseconds. + * + * @param[out] The current time in us. + * + */ +uint32_t qorvoAlarmGetTimeUs(void); + +/** + * This function schedules a callback after a relative amount of time. + * + * @param[in] rel_time The relative time in ms. + * @param[in] callback A callback function which will be called. + * @param[in] arg A context pointer which will be passed as an argument to the callback. + * + */ +void qorvoAlarmMilliStart(uint32_t rel_time, qorvoAlarmCallback_t callback, void *arg); + +/** + * This function schedules a callback after a relative amount of time. + * + * @param[in] rel_time The relative time in us. + * @param[in] callback A callback function which will be called. + * @param[in] arg A context pointer which will be passed as an argument to the callback. + * + */ +void qorvoAlarmMicroStart(uint32_t rel_time, qorvoAlarmCallback_t callback, void *arg); + +/** + * This function unschedules the callback. + * + * @param[in] callback A callback function which will be removed from the list. + * @param[in] arg A context pointer which will be passed as an argument to the callback. + * + */ +bool qorvoAlarmStop(qorvoAlarmCallback_t callback, void *arg); + +#endif // ALARM_QORVO_H_ diff --git a/src/qpg6200/arm-none-eabi.cmake b/src/qpg6200/arm-none-eabi.cmake new file mode 100755 index 000000000..9d0a8a0d1 --- /dev/null +++ b/src/qpg6200/arm-none-eabi.cmake @@ -0,0 +1,41 @@ +# +# Copyright (c) 2024, 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. +# + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ARM) + +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_CXX_COMPILER arm-none-eabi-g++) +set(CMAKE_ASM_COMPILER arm-none-eabi-as) +set(CMAKE_RANLIB arm-none-eabi-ranlib) + +set(COMMON_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -fdata-sections -ffunction-sections") +set(CMAKE_C_FLAGS_INIT "${COMMON_C_FLAGS} -std=gnu99") +set(CMAKE_CXX_FLAGS_INIT "${COMMON_C_FLAGS} -fno-exceptions -fno-rtti") +set(CMAKE_ASM_FLAGS_INIT "${COMMON_C_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS_INIT "${COMMON_C_FLAGS} -specs=nano.specs -specs=nosys.specs") diff --git a/src/qpg6200/crypto/common-mbedtls-config.h b/src/qpg6200/crypto/common-mbedtls-config.h new file mode 100644 index 000000000..45975718e --- /dev/null +++ b/src/qpg6200/crypto/common-mbedtls-config.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2017-2024, Qorvo Inc + * + * This software is owned by Qorvo Inc + * and protected under applicable copyright laws. + * It is delivered under the terms of the license + * and is intended and supplied for use solely and + * exclusively with products manufactured by + * Qorvo Inc. + * + * + * THIS SOFTWARE IS PROVIDED IN AN "AS IS" + * CONDITION. NO WARRANTIES, WHETHER EXPRESS, + * IMPLIED OR STATUTORY, INCLUDING, BUT NOT + * LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * QORVO INC. SHALL NOT, IN ANY + * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, + * INCIDENTAL OR CONSEQUENTIAL DAMAGES, + * FOR ANY REASON WHATSOEVER. + * + * + */ + +#pragma once + +#include "qorvo-mbedtls-config.h" + +#include +#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf + +#define MBEDTLS_AES_C +#define MBEDTLS_AES_ROM_TABLES +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_ASN1_WRITE_C +#define MBEDTLS_BIGNUM_C +#define MBEDTLS_CCM_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CMAC_C +#define MBEDTLS_CTR_DRBG_C +#define MBEDTLS_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_PLATFORM_C +#define MBEDTLS_PLATFORM_MEMORY +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_SHA224_C +#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_DTLS +#define MBEDTLS_SSL_PROTO_TLS1_2 +#define MBEDTLS_SSL_TLS_C +#define MBEDTLS_TRNG_C + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || \ + OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_SSL_COOKIE_C +#define MBEDTLS_SSL_SRV_C +#elif OPENTHREAD_CONFIG_JOINER_ENABLE +#define MBEDTLS_SSL_COOKIE_C +#endif + +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#endif + +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_TCP_ENABLE +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#endif + +#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#define MBEDTLS_BASE64_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_ECDSA_C +#define MBEDTLS_OID_C +#define MBEDTLS_PEM_PARSE_C +#define MBEDTLS_X509_USE_C +#define MBEDTLS_X509_CRT_PARSE_C +#endif + +#if OPENTHREAD_CONFIG_ECDSA_ENABLE +#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_PK_WRITE_C +#endif + +#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_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */ + +#include +#define MBEDTLS_PLATFORM_STD_CALLOC calloc +#define MBEDTLS_PLATFORM_STD_FREE free + +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */ +#else +#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maximmum fragment length in bytes */ +#endif + +#define MBEDTLS_SSL_IN_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN +#define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN + +// Matter specific +#define MBEDTLS_ERROR_STRERROR_DUMMY +#define MBEDTLS_HKDF_C +#define MBEDTLS_PEM_WRITE_C +#define MBEDTLS_PKCS5_C +#define MBEDTLS_X509_CSR_WRITE_C +#define MBEDTLS_X509_CREATE_C +#define MBEDTLS_X509_REMOVE_INFO + +// OpenThread specific +#if OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE +#define MBEDTLS_ECJPAKE_C +#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 +#endif + +// Others +#define MBEDTLS_DEPRECATED_REMOVED + +// MBEDTLS_SSL_PROTO_TLS1_2 requires at least one MBEDTLS_KEY_EXCHANGE_XXX algorithm +#if (!defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \ + !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)) +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#endif + +// Fixes wunifdef in ssl.h +#define MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 + +// Were set at one point, but don't seem to be necessary +// #define MBEDTLS_ECDH_LEGACY_CONTEXT +// #define MBEDTLS_CIPHER_MODE_CTR diff --git a/src/qpg6200/crypto/qorvo-mbedtls-config.h b/src/qpg6200/crypto/qorvo-mbedtls-config.h new file mode 100644 index 000000000..fe8e6fff2 --- /dev/null +++ b/src/qpg6200/crypto/qorvo-mbedtls-config.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017-2024, Qorvo Inc + * + * This software is owned by Qorvo Inc + * and protected under applicable copyright laws. + * It is delivered under the terms of the license + * and is intended and supplied for use solely and + * exclusively with products manufactured by + * Qorvo Inc. + * + * + * THIS SOFTWARE IS PROVIDED IN AN "AS IS" + * CONDITION. NO WARRANTIES, WHETHER EXPRESS, + * IMPLIED OR STATUTORY, INCLUDING, BUT NOT + * LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * QORVO INC. SHALL NOT, IN ANY + * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, + * INCIDENTAL OR CONSEQUENTIAL DAMAGES, + * FOR ANY REASON WHATSOEVER. + * + * + */ + +#pragma once + +#ifdef QORVO_MBEDTLS_DEBUG +#ifndef MBEDTLS_DEBUG_C +#define MBEDTLS_DEBUG_C +#endif // MBEDTLS_DEBUG_C +#endif // QORVO_MBEDTLS_DEBUG + +// Enables secured CoAP, not used by Thread nor Matter +#ifndef OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0 +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE + +// Required for SRP client and server and thus in Thread 1.2 and Matter +#ifndef OPENTHREAD_CONFIG_ECDSA_ENABLE +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#endif // OPENTHREAD_CONFIG_ECDSA_ENABLE + +// Enables the optional Thread Commissioner feature +#ifndef OPENTHREAD_CONFIG_COMMISSIONER_ENABLE +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0 +#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE + +// Enables TCP, Mandatory for Thread Components, optional for Thread Products +#ifndef OPENTHREAD_CONFIG_TCP_ENABLE +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 +#endif // OPENTHREAD_CONFIG_TCP_ENABLE + +// Enables the Thread Joiner role, Mandatory for Thread Components, optional for Thread Products +#ifndef OPENTHREAD_CONFIG_JOINER_ENABLE +#define OPENTHREAD_CONFIG_JOINER_ENABLE 0 +#endif // OPENTHREAD_CONFIG_JOINER_ENABLE + +// Enables the Thread Border Agent functionality, Mandatory on Border Routers +#ifndef OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE +#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 +#endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE diff --git a/src/qpg6200/crypto/qpg6200-mbedtls-config.h b/src/qpg6200/crypto/qpg6200-mbedtls-config.h new file mode 100644 index 000000000..3e5fc93fe --- /dev/null +++ b/src/qpg6200/crypto/qpg6200-mbedtls-config.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024, Qorvo Inc + * + * This software is owned by Qorvo Inc + * and protected under applicable copyright laws. + * It is delivered under the terms of the license + * and is intended and supplied for use solely and + * exclusively with products manufactured by + * Qorvo Inc. + * + * + * THIS SOFTWARE IS PROVIDED IN AN "AS IS" + * CONDITION. NO WARRANTIES, WHETHER EXPRESS, + * IMPLIED OR STATUTORY, INCLUDING, BUT NOT + * LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * QORVO INC. SHALL NOT, IN ANY + * CIRCUMSTANCES, BE LIABLE FOR SPECIAL, + * INCIDENTAL OR CONSEQUENTIAL DAMAGES, + * FOR ANY REASON WHATSOEVER. + * + * + */ + +#pragma once + +#include "common-mbedtls-config.h" + +#define MBEDTLS_CCM_ALT +#define MBEDTLS_ECDSA_VERIFY_ALT +#define MBEDTLS_ECDSA_SIGN_ALT +#define MBEDTLS_ECP_ALT +#define MBEDTLS_SHA256_ALT + +#define MBEDTLS_ENTROPY_HARDWARE_ALT + +#ifdef MBEDTLS_MPI_MAX_SIZE +#undef MBEDTLS_MPI_MAX_SIZE +#endif +#define MBEDTLS_MPI_MAX_SIZE 64 /**< Maximum number of bytes for usable MPIs. */ +#undef MBEDTLS_ECP_WINDOW_SIZE +#undef MBEDTLS_ECP_FIXED_POINT_OPTIM + +#ifdef PSA_CRYPTO_IMPLEMENTED +#define MBEDTLS_PSA_CRYPTO_C +#endif diff --git a/src/qpg6200/diag.c b/src/qpg6200/diag.c new file mode 100755 index 000000000..6131d6191 --- /dev/null +++ b/src/qpg6200/diag.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#if OPENTHREAD_CONFIG_DIAG_ENABLE + +/** + * Diagnostics mode variables. + * + */ +static bool sDiagMode = false; + +void otPlatDiagModeSet(bool aMode) +{ + sDiagMode = aMode; +} + +bool otPlatDiagModeGet() +{ + return sDiagMode; +} + +void otPlatDiagChannelSet(uint8_t aChannel) +{ + OT_UNUSED_VARIABLE(aChannel); +} + +void otPlatDiagTxPowerSet(int8_t aTxPower) +{ + OT_UNUSED_VARIABLE(aTxPower); +} + +void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aFrame); + OT_UNUSED_VARIABLE(aError); +} + +void otPlatDiagAlarmCallback(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + +void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aCallback); + OT_UNUSED_VARIABLE(aContext); +} + +#endif // OPENTHREAD_CONFIG_DIAG_ENABLE diff --git a/src/qpg6200/entropy.c b/src/qpg6200/entropy.c new file mode 100755 index 000000000..02443c7b7 --- /dev/null +++ b/src/qpg6200/entropy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file implements an entropy source. + * + */ + +#include + +#include "assert.h" +#include "random_qorvo.h" +#include +#include + +otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) +{ + otError error = OT_ERROR_NONE; + assert(aOutputLength < 256); + + qorvoRandomGet((uint8_t *)aOutput, (uint8_t)aOutputLength); + return error; +} diff --git a/src/qpg6200/logging.c b/src/qpg6200/logging.c new file mode 100755 index 000000000..2bc44acc6 --- /dev/null +++ b/src/qpg6200/logging.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "openthread-core-config.h" + +#include "platform_qorvo.h" + +#include +#include +#include + +#include + +#include "uart_qorvo.h" +#include "utils/code_utils.h" + +#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) +void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) +{ + va_list args; + va_start(args, aFormat); + qorvoUartLog(aLogLevel, aLogRegion, aFormat, args); + va_end(args); +} +#endif diff --git a/src/qpg6200/misc.c b/src/qpg6200/misc.c new file mode 100755 index 000000000..0b5db0242 --- /dev/null +++ b/src/qpg6200/misc.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "misc_qorvo.h" +#include +#include + +void otPlatReset(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + qorvoPlatReset(); +} + +otPlatResetReason otPlatGetResetReason(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + // TODO: Write me! + return OT_PLAT_RESET_REASON_POWER_ON; +} + +void otPlatAssertFail(const char *aFilename, int aLineNumber) +{ + qorvoPlatAssertFail(aFilename, aLineNumber); +} + +void otPlatWakeHost(void) +{ + // TODO: implement an operation to wake the host from sleep state. +} diff --git a/src/qpg6200/misc_qorvo.h b/src/qpg6200/misc_qorvo.h new file mode 100755 index 000000000..0fd819cf6 --- /dev/null +++ b/src/qpg6200/misc_qorvo.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the misc functions from the Qorvo library. + * + */ + +#ifndef MISC_QORVO_H_ +#define MISC_QORVO_H_ + +#include +#include + +void qorvoPlatReset(void); +void qorvoPlatAssertFail(const char *aFilename, int aLineNumber); + +#endif // MISC_QORVO_H_ diff --git a/src/qpg6200/openthread-core-qpg6200-config-check.h b/src/qpg6200/openthread-core-qpg6200-config-check.h new file mode 100755 index 000000000..2173ed6a4 --- /dev/null +++ b/src/qpg6200/openthread-core-qpg6200-config-check.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, 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. + */ + +#ifndef OPENTHREAD_CORE_QPG6200_CONFIG_CHECK_H_ +#define OPENTHREAD_CORE_QPG6200_CONFIG_CHECK_H_ + +#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE +#error "Platform qpg6200 doesn't support configuration option: OPENTHREAD_CONFIG_TIME_SYNC_ENABLE" +#endif + +#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT +#error "Platform qpg6200 doesn't support configuration option: OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT" +#endif + +#endif /* OPENTHREAD_CORE_QPG6200_CONFIG_CHECK_H_ */ diff --git a/src/qpg6200/openthread-core-qpg6200-config.h b/src/qpg6200/openthread-core-qpg6200-config.h new file mode 100755 index 000000000..dd4f9f0d7 --- /dev/null +++ b/src/qpg6200/openthread-core-qpg6200-config.h @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes QPG6200 compile-time configuration constants for OpenThread. + */ + +#ifndef OPENTHREAD_CORE_QPG6200_CONFIG_H_ +#define OPENTHREAD_CORE_QPG6200_CONFIG_H_ + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_INFO + * + * The platform-specific string to insert into the OpenThread version string. + * + */ +#define OPENTHREAD_CONFIG_PLATFORM_INFO "QPG6200" + +/** + * @def OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE + * + * Define to 1 if you want to enable the csl receiver feature (for Thread >= 1.2 only) + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +#define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE + * + * Define to 1 if you want to enable the csl receiver feature (for Thread >= 1.2 only) + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE +#define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD + * + * Reception scheduling and ramp up time needed for the CSL receiver to be ready, in units of microseconds. + * + */ +#if defined(OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE) +#define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 1150 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT + * + * The assert is managed by platform defined logic when this flag is set. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT +#define OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_DIAG_ENABLE + * + * Define as 1 to enable the diag feature. + * + */ +#ifndef OPENTHREAD_CONFIG_DIAG_ENABLE +#define OPENTHREAD_CONFIG_DIAG_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE + * + * This is required for the CSL receiver feature + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE +#endif + +#if defined(OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE) && defined(DEBUG) +#define OPENTHREAD_CONFIG_MAC_CSL_DEBUG_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE + * + * Enable the Link Metrics subject feature (for Thread >= 1.2 only) + * A Thread Router has to be able to be a Link Metrics Subject + * + */ +#ifndef OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE + * + * Enable the Link Metrics subject feature (for Thread >= 1.2 only) + * + */ +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) + +/** + * @def OPENTHREAD_CONFIG_DUA_ENABLE + * + * Enable the DUA feature (for Thread >= 1.2 only) + * + */ +#define OPENTHREAD_CONFIG_DUA_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) + +/** + * @def OPENTHREAD_CONFIG_MLR_ENABLE + * + * Enable the Multicast Listener Registration feature (MLR) (for Thread >= 1.2 only) + * + */ +#ifndef OPENTHREAD_CONFIG_MLR_ENABLE +#define OPENTHREAD_CONFIG_MLR_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE + * + * Enable the Service Registry Proxy client (for Thread >= 1.3 only) + * It also requires support for ECDSA + * + */ +#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE +#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3) +#endif + +#if defined(OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE) || defined(OPENTHREAD_CONFIG_SRP_SERVER_ENABLE) +#if !defined(OPENTHREAD_CONFIG_ECDSA_ENABLE) || !OPENTHREAD_CONFIG_ECDSA_ENABLE +#undef OPENTHREAD_CONFIG_ECDSA_ENABLE +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#endif +#endif + +/** + * @def OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE + * + * Define the default mode (enabled or disabled) of auto-start mode. + * + * This config is applicable only when `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled. + * + */ +#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE +#define OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE \ + ((OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3) && OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE) +#endif + +/** + * @def OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE + * + * Enable the Domain Name Service client (for Thread >= 1.3 only) + * + */ +#ifndef OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE +#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_3) +#endif + +/** + * @def OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD + * + * The maximum number of supported IPv6 address registrations per child. + * + */ +#ifndef OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD +#define OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD 6 +#endif + +/** + * @def OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER + * + * The maximum number of IPv6 address registrations for MTD. + * + */ +#ifndef OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER +#define OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER (OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD) +#endif + +#endif // OPENTHREAD_CORE_QPG6200_CONFIG_H_ diff --git a/src/qpg6200/platform.c b/src/qpg6200/platform.c new file mode 100755 index 000000000..185f9ab74 --- /dev/null +++ b/src/qpg6200/platform.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * @brief + * This file includes the platform-specific initializers. + */ + +#include "alarm_qorvo.h" +#include "platform_qorvo.h" +#include "radio_qorvo.h" +#include "random_qorvo.h" +#include "uart_qorvo.h" +#include +#include + +#include "utils/uart.h" + +#include "stdio.h" +#include "stdlib.h" + +static otInstance *localInstance = NULL; + +uint8_t qorvoPlatGotoSleepCheck(void) +{ + if (localInstance) + { + return !otTaskletsArePending(localInstance); + } + else + { + return true; + } +} + +void otSysInit(int argc, char *argv[]) +{ + OT_UNUSED_VARIABLE(argc); + OT_UNUSED_VARIABLE(argv); + qorvoPlatInit((qorvoPlatGotoSleepCheckCallback_t)qorvoPlatGotoSleepCheck); + qorvoUartInit(); + qorvoAlarmInit(); + qorvoRandomInit(); + qorvoRadioInit(); +} + +bool otSysPseudoResetWasRequested(void) +{ + return false; +} + +void otSysProcessDrivers(otInstance *aInstance) +{ + if (localInstance == NULL) + { + // local copy in case we need to perform a callback. + localInstance = aInstance; + } + + // Do not sleep until attached to network to handle UART CLI + qorvoPlatMainLoop(!otTaskletsArePending(aInstance) && + (otThreadGetDeviceRole(aInstance) != OT_DEVICE_ROLE_DETACHED) && + (otThreadGetDeviceRole(aInstance) != OT_DEVICE_ROLE_DISABLED)); +} diff --git a/src/qpg6200/platform_qorvo.h b/src/qpg6200/platform_qorvo.h new file mode 100755 index 000000000..1c1746cb7 --- /dev/null +++ b/src/qpg6200/platform_qorvo.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the platform-specific initializers. + * + */ + +#ifndef PLATFORM_QORVO_H_ +#define PLATFORM_QORVO_H_ + +#include +#include + +typedef uint8_t (*qorvoPlatGotoSleepCheckCallback_t)(void); + +/** + * This function initializes the platform. + * + * @param[in] gotoSleepCheckCallback The callback which needs to return if sleep is allowed. + * + */ +void qorvoPlatInit(qorvoPlatGotoSleepCheckCallback_t gotoSleepCheckCallback); + +/** + * This function runs the main loop of the platform once. + * + * @param[in] canGoToSleep Indicates if the platform can got to sleep. + * + */ +void qorvoPlatMainLoop(bool canGoToSleep); + +#endif // PLATFORM_QORVO_H_ diff --git a/src/qpg6200/radio.c b/src/qpg6200/radio.c new file mode 100644 index 000000000..567b85025 --- /dev/null +++ b/src/qpg6200/radio.c @@ -0,0 +1,635 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file implements the OpenThread platform abstraction for radio communication. + * + */ + +#include + +#include +#include + +#include "utils/code_utils.h" + +#include "radio_qorvo.h" + +enum +{ + QPG_RECEIVE_SENSITIVITY = -100, // [dBm] + QPG_CSL_ACCURACY = 50, // [ppm] + QPG_CSL_CLOCK_UNCERTAINTY = 1, // [10us] +}; + +enum +{ + IEEE802154_ACK_LENGTH = 5, + IEEE802154_FRAME_TYPE_ACK = 0x2, + IEEE802154_FRAME_PENDING = 1 << 4, + IEEE802154_DSN_OFFSET = 2, +}; + +extern otRadioFrame sTransmitFrame; + +static otRadioState sState; +static otInstance *pQorvoInstance; + +typedef struct otCachedSettings_s +{ + uint16_t panid; +} otCachedSettings_t; + +static otCachedSettings_t otCachedSettings; + +/* Upper layer relies on txpower could be set before receive, but MAC have per-channel config for it. + Store txpower until channel set in Receive(). */ +#define PENDING_TX_POWER_NONE (-1) +static int8_t pendingTxPower = PENDING_TX_POWER_NONE; + +static uint8_t sScanstate = 0; +static int8_t sLastReceivedPower = 127; + +otRadioCaps otPlatRadioGetCaps(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioGetCaps(); +} + +const char *otPlatRadioGetVersionString(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return "OPENTHREAD/Qorvo/0.0"; +} + +int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return QPG_RECEIVE_SENSITIVITY; +} + +void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioGetIeeeEui64(aIeeeEui64); +} + +void otPlatRadioSetPanId(otInstance *aInstance, otPanId aPanId) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetPanId((uint16_t)aPanId); + otCachedSettings.panid = aPanId; +} + +void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *address) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetExtendedAddress(address->m8); +} + +void otPlatRadioSetShortAddress(otInstance *aInstance, otShortAddress aShortAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetShortAddress((uint16_t)aShortAddress); +} + +otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) +{ + OT_UNUSED_VARIABLE(aInstance); + + otError result; + + if (aPower == NULL) + { + return OT_ERROR_INVALID_ARGS; + } + + if ((sState == OT_RADIO_STATE_DISABLED) || (sScanstate != 0)) + { + *aPower = (pendingTxPower == PENDING_TX_POWER_NONE) ? 0 : pendingTxPower; + return OT_ERROR_NONE; + } + + result = qorvoRadioGetTransmitPower(aPower); + + if (result == OT_ERROR_INVALID_STATE) + { + // Channel was not set, so txpower is ambigious + *aPower = (pendingTxPower == PENDING_TX_POWER_NONE) ? 0 : pendingTxPower; + return OT_ERROR_NONE; + } + + return result; +} + +otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) +{ + OT_UNUSED_VARIABLE(aInstance); + + otError result; + + if ((sState == OT_RADIO_STATE_DISABLED) || (sScanstate != 0)) + { + pendingTxPower = aPower; + return OT_ERROR_NONE; + } + + result = qorvoRadioSetTransmitPower(aPower); + + if (result == OT_ERROR_INVALID_STATE) + { + // Channel was not set, so txpower is ambigious + pendingTxPower = aPower; + result = OT_ERROR_NONE; + } + + return result; +} + +otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aThreshold) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aThreshold); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aThreshold); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioGetFemLnaGain(otInstance *aInstance, int8_t *aGain) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aGain); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioSetFemLnaGain(otInstance *aInstance, int8_t aGain) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aGain); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +bool otPlatRadioGetPromiscuous(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioGetPromiscuous(); +} + +void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetPromiscuous(aEnable); +} + +void otPlatRadioSetMacKey(otInstance *aInstance, + uint8_t aKeyIdMode, + uint8_t aKeyId, + const otMacKeyMaterial *aPrevKey, + const otMacKeyMaterial *aCurrKey, + const otMacKeyMaterial *aNextKey, + otRadioKeyType aKeyType) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetMacKey(aKeyIdMode, aKeyId, aPrevKey->mKeyMaterial.mKey.m8, aCurrKey->mKeyMaterial.mKey.m8, + aNextKey->mKeyMaterial.mKey.m8, aKeyType); +} + +void otPlatRadioSetMacFrameCounter(otInstance *aInstance, uint32_t aMacFrameCounter) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioSetMacFrameCounter(aMacFrameCounter); +} + +uint64_t otPlatRadioGetNow(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioGetNow(); +} + +uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return 0; +} + +otError otPlatRadioEnable(otInstance *aInstance) +{ + pQorvoInstance = aInstance; + memset(&otCachedSettings, 0x00, sizeof(otCachedSettings_t)); + + if (!otPlatRadioIsEnabled(aInstance)) + { + sState = OT_RADIO_STATE_SLEEP; + } + + return OT_ERROR_NONE; +} + +otError otPlatRadioDisable(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + otEXPECT(otPlatRadioIsEnabled(aInstance)); + + if (sState == OT_RADIO_STATE_RECEIVE) + { + qorvoRadioSetRxOnWhenIdle(false); + } + + sState = OT_RADIO_STATE_DISABLED; + +exit: + return OT_ERROR_NONE; +} + +bool otPlatRadioIsEnabled(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return (sState != OT_RADIO_STATE_DISABLED); +} + +otError otPlatRadioSleep(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + otError error = OT_ERROR_INVALID_STATE; + + if (sState == OT_RADIO_STATE_RECEIVE || sState == OT_RADIO_STATE_SLEEP) + { + qorvoRadioSetRxOnWhenIdle(false); + error = OT_ERROR_NONE; + sState = OT_RADIO_STATE_SLEEP; + } + return error; +} + +otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) +{ + otError error = OT_ERROR_INVALID_STATE; + + pQorvoInstance = aInstance; + + if ((sState != OT_RADIO_STATE_DISABLED) && (sScanstate == 0)) + { + qorvoRadioSetCurrentChannel(aChannel); + if (pendingTxPower != PENDING_TX_POWER_NONE) + { + qorvoRadioSetTransmitPower(pendingTxPower); + pendingTxPower = PENDING_TX_POWER_NONE; + } + error = OT_ERROR_NONE; + } + + if (sState == OT_RADIO_STATE_SLEEP) + { + qorvoRadioSetRxOnWhenIdle(true); + error = OT_ERROR_NONE; + sState = OT_RADIO_STATE_RECEIVE; + } + + return error; +} + +otError otPlatRadioReceiveAt(otInstance *aInstance, uint8_t aChannel, uint32_t aStart, uint32_t aDuration) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioReceiveAt(aChannel, aStart, aDuration); +} + +void cbQorvoRadioReceiveDone(otRadioFrame *aFrame, otError aError) +{ + if (aError == OT_ERROR_NONE) + { + sLastReceivedPower = aFrame->mInfo.mRxInfo.mRssi; + } + + otPlatRadioReceiveDone(pQorvoInstance, aFrame, aError); +} + +void cbQorvoDiagRadioReceiveDone(otRadioFrame *aFrame, otError aError) +{ + otPlatDiagRadioReceiveDone(pQorvoInstance, aFrame, aError); +} + +otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return &sTransmitFrame; +} + +otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) +{ + otError err = OT_ERROR_NONE; + + pQorvoInstance = aInstance; + + otEXPECT_ACTION(sState != OT_RADIO_STATE_DISABLED, err = OT_ERROR_INVALID_STATE); + + err = qorvoRadioTransmit(aFrame); + +exit: + return err; +} + +void cbQorvoRadioTxStarted(otRadioFrame *aFrame) +{ + otPlatRadioTxStarted(pQorvoInstance, aFrame); +} + +void cbQorvoRadioTransmitDone_AckFrame(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError) +{ + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? aAckFrame : NULL, aError); +} + +void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError aError) +{ + // TODO: pass received ACK frame instead of generating one. + otRadioFrame ackFrame; + uint8_t psdu[IEEE802154_ACK_LENGTH]; + + ackFrame.mPsdu = psdu; + ackFrame.mLength = IEEE802154_ACK_LENGTH; + ackFrame.mPsdu[0] = IEEE802154_FRAME_TYPE_ACK; + + if (aFramePending) + { + ackFrame.mPsdu[0] |= IEEE802154_FRAME_PENDING; + } + + ackFrame.mPsdu[1] = 0; + ackFrame.mPsdu[2] = aFrame->mPsdu[IEEE802154_DSN_OFFSET]; + + otPlatRadioTxDone(pQorvoInstance, aFrame, (aError == OT_ERROR_NONE) ? &ackFrame : NULL, aError); +} + +void cbQorvoDiagRadioTransmitDone(otRadioFrame *aFrame, otError aError) +{ + otPlatDiagRadioTransmitDone(pQorvoInstance, aFrame, aError); +} + +int8_t otPlatRadioGetRssi(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return sLastReceivedPower; +} + +otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration) +{ + OT_UNUSED_VARIABLE(aInstance); + + sScanstate = 1; + return qorvoRadioEnergyScan(aScanChannel, aScanDuration); +} + +void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi) +{ + sScanstate = 0; + otPlatRadioEnergyScanDone(pQorvoInstance, aEnergyScanMaxRssi); +} + +void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioEnableSrcMatch(aEnable); +} + +otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, otShortAddress aShortAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioAddSrcMatchShortEntry((uint16_t)aShortAddress, otCachedSettings.panid); +} + +otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioAddSrcMatchExtEntry(aExtAddress->m8, otCachedSettings.panid); +} + +otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, otShortAddress aShortAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioClearSrcMatchShortEntry((uint16_t)aShortAddress, otCachedSettings.panid); +} + +otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioClearSrcMatchExtEntry(aExtAddress->m8, otCachedSettings.panid); +} + +void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + /* clear both short and extended addresses here */ + qorvoRadioClearSrcMatchEntries(); +} + +void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + /* not implemented */ + /* assumes clearing of short and extended entries is done simultaniously by the openthread stack */ +} +uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return 0x03fff800; +} + +uint32_t otPlatRadioGetPreferredChannelMask(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return 0x03fff800; +} + +otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aEnabled); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +bool otPlatRadioIsCoexEnabled(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return false; +} + +otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aCoexMetrics); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioEnableCsl(otInstance *aInstance, + uint32_t aCslPeriod, + otShortAddress aShortAddr, + const otExtAddress *aExtAddr) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioEnableCsl(aCslPeriod, (uint16_t)aShortAddr, aExtAddr->m8); +} + +void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTime) +{ + OT_UNUSED_VARIABLE(aInstance); + + qorvoRadioUpdateCslSampleTime(aCslSampleTime); +} + +uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return QPG_CSL_ACCURACY; +} + +uint8_t otPlatRadioGetCslUncertainty(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return QPG_CSL_CLOCK_UNCERTAINTY; +} + +otError otPlatRadioSetChannelMaxTransmitPower(otInstance *aInstance, uint8_t aChannel, int8_t aMaxPower) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aChannel); + OT_UNUSED_VARIABLE(aMaxPower); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioSetRegion(otInstance *aInstance, uint16_t aRegionCode) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aRegionCode); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioGetRegion(otInstance *aInstance, uint16_t *aRegionCode) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aRegionCode); + + return OT_ERROR_NOT_IMPLEMENTED; +} + +otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, + otLinkMetrics aLinkMetrics, + otShortAddress aShortAddress, + const otExtAddress *aExtAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + + return qorvoRadioConfigureEnhAckProbing(aLinkMetrics, (uint16_t)aShortAddress, aExtAddress->m8); +} + +#if QORVO_RCP || QORVO_FTD +#include + +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo) +{ + if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED) + { + qorvoRadioHandleChildRemoved(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + else if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED) + { + qorvoRadioHandleChildAdded(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + // We don't care about the other events +} + +#if QORVO_FTD +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + otThreadRegisterNeighborTableCallback(pQorvoInstance, (aEnable) ? qorvoNeighbourTableChanged : NULL); +} +#else +extern void rcpRegisterNeighborTableCallback(bool aEnable); + +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + rcpRegisterNeighborTableCallback(aEnable); +} + +OT_TOOL_WEAK void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +OT_TOOL_WEAK void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +#endif // QORVO_FTD +#else +OT_TOOL_WEAK void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ +} +#endif // QORVO_RCP || QORVO_FTD diff --git a/src/qpg6200/radio_qorvo.h b/src/qpg6200/radio_qorvo.h new file mode 100644 index 000000000..098032ee2 --- /dev/null +++ b/src/qpg6200/radio_qorvo.h @@ -0,0 +1,398 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the radio functions from the Qorvo library. + * + */ + +#ifndef RADIO_QORVO_H_ +#define RADIO_QORVO_H_ + +#include +#include + +#include +#include +#include + +/** + * This function initializes the radio. + * + */ +void qorvoRadioInit(void); + +/** + * This function resets the radio. + * + */ +void qorvoRadioReset(void); + +/** + * This function processes event to/from the radio. + * + */ +void qorvoRadioProcess(void); + +/** + * This function starts an ED scan. + * + * @param[in] aScanChannel The channel which needs to be scanned. + * @param[in] aScanDuration The amount of time in ms which needs to be scanned. + * + */ +otError qorvoRadioEnergyScan(uint8_t aScanChannel, uint16_t aScanDuration); + +/** + * This function sets the current channel. + * + * @param[in] channel The channel index. + * + */ +void qorvoRadioSetCurrentChannel(uint8_t channel); + +/** + * This function sets the idle behaviour of the radio. + * + * @param[in] rxOnWhenIdle If true, the radio remains on which not transmitting. + * + */ +void qorvoRadioSetRxOnWhenIdle(bool rxOnWhenIdle); + +/** + * This function retrieves the MAC address of the radio. + * + * @param[out] aIeeeEui64 The MAC address of the radio. + * + */ +void qorvoRadioGetIeeeEui64(uint8_t *aIeeeEui64); + +/** + * This function transmits a frame. + * + * @param[in] aFrame The frame which needs to be transmitted. + * + */ +otError qorvoRadioTransmit(otRadioFrame *aFrame); + +/** + * This function sets the PanId. + * + * @param[in] panid The panId. + * + */ +void qorvoRadioSetPanId(uint16_t panid); + +/** + * This function sets the short address. + * + * @param[in] address The short address. + * + */ +void qorvoRadioSetShortAddress(uint16_t address); + +/** + * This function sets the extended address. + * + * @param[in] address The extended address. + * + */ +void qorvoRadioSetExtendedAddress(const uint8_t *address); + +/** + * This function enables source address matching for indirect transmit. + * + * @param[in] aEnable if True will enable source address matching, false will disable. + * + */ +void qorvoRadioEnableSrcMatch(bool aEnable); + +/** + * This function clears all entries from the source address match list. + * + */ +void qorvoRadioClearSrcMatchEntries(void); + +/** + * This function adds an short address plus panid to the source address match list. + * + * @param[in] aShortAddress The short address which should be added. + * @param[in] panid The panid. + * + */ +otError qorvoRadioAddSrcMatchShortEntry(uint16_t aShortAddress, uint16_t panid); + +/** + * This function adds an extended address plus panid to the source address match list. + * + * @param[in] aExtAddress The extended address which should be added. + * @param[in] panid The panid. + * + */ +otError qorvoRadioAddSrcMatchExtEntry(const uint8_t *aExtAddress, uint16_t panid); + +/** + * This function removes an short address plus panid from the source address match list. + * + * @param[in] aShortAddress The short address which should be removed. + * @param[in] panid The panid. + * + */ +otError qorvoRadioClearSrcMatchShortEntry(uint16_t aShortAddress, uint16_t panid); + +/** + * This function removes an extended address plus panid from the source address match list. + * + * @param[in] aExtAddress The extended address which should be removed. + * @param[in] panid The panid. + * + */ +otError qorvoRadioClearSrcMatchExtEntry(const uint8_t *aExtAddress, uint16_t panid); + +/** + * This function gets the transmit power for current channel + * + * @param[out] aPower The transmit power + * + */ +otError qorvoRadioGetTransmitPower(int8_t *aPower); + +/** + * This function sets the transmit power for current channel + * + * @param[in] aPower The transmit power + * + */ +otError qorvoRadioSetTransmitPower(int8_t aPower); + +/** + * Get the status of promiscuous mode. + * + * @retval TRUE Promiscuous mode is enabled. + * @retval FALSE Promiscuous mode is disabled. + * + */ +bool qorvoRadioGetPromiscuous(void); + +/** + * Enable or disable promiscuous mode. + * + * @param[in] aEnable TRUE to enable or FALSE to disable promiscuous mode. + * + */ +void qorvoRadioSetPromiscuous(bool aEnable); + +/** + * Update MAC keys and key index + * + * This function is used when radio provides OT_RADIO_CAPS_TRANSMIT_SEC capability. + * + * @param[in] aKeyIdMode The key ID mode. + * @param[in] aKeyId Current MAC key index. + * @param[in] aPrevKey A pointer to the previous MAC key. + * @param[in] aCurrKey A pointer to the current MAC key. + * @param[in] aNextKey A pointer to the next MAC key. + * @param[in] aKeyType Key Type used. + * + */ +void qorvoRadioSetMacKey(uint8_t aKeyIdMode, + uint8_t aKeyId, + const uint8_t *aPrevKey, + const uint8_t *aCurrKey, + const uint8_t *aNextKey, + uint8_t aKeyType); + +/** + * This method sets the current MAC frame counter value. + * + * This function is used when radio provides `OT_RADIO_CAPS_TRANSMIT_SEC` capability. + * + * @param[in] aMacFrameCounter The MAC frame counter value. + * + */ +void qorvoRadioSetMacFrameCounter(uint32_t aMacFrameCounter); + +/** + * Enable or disable CSL receiver. + * + * @param[in] aCslPeriod CSL period, 0 for disabling CSL. + * @param[in] aShortAddr The short source address of CSL receiver's peer. + * @param[in] aExtAddr The extended source address of CSL receiver's peer. + * + * @note Platforms should use CSL peer addresses to include CSL IE when generating enhanced acks. + * + * @retval kErrorNotImplemented Radio driver doesn't support CSL. + * @retval kErrorFailed Other platform specific errors. + * @retval kErrorNone Successfully enabled or disabled CSL. + * + */ +otError qorvoRadioEnableCsl(uint32_t aCslPeriod, uint16_t aShortAddr, const uint8_t *aExtAddr); + +/** + * Update CSL sample time in radio driver. + * + * Sample time is stored in radio driver as a copy to calculate phase when sending ACK with CSL IE. + * + * @param[in] aCslSampleTime The latest sample time. + * + */ +void qorvoRadioUpdateCslSampleTime(uint32_t aCslSampleTime); + +/** + * Enable/disable or update Enhanced-ACK Based Probing in radio for a specific Initiator. + * + * After Enhanced-ACK Based Probing is configured by a specific Probing Initiator, the Enhanced-ACK sent to that + * node should include Vendor-Specific IE containing Link Metrics data. This method informs the radio to start/stop to + * collect Link Metrics data and include Vendor-Specific IE that containing the data in Enhanced-ACK sent to that + * Probing Initiator. + * + * @param[in] aLinkMetrics This parameter specifies what metrics to query. Per spec 4.11.3.4.4.6, at most 2 metrics + * can be specified. The probing would be disabled if @p `aLinkMetrics` is bitwise 0. + * @param[in] aShortAddr The short address of the Probing Initiator. + * @param[in] aExtAddr The extended source address of the Probing Initiator. @p aExtAddr MUST NOT be `NULL`. + * + * @retval OT_ERROR_NONE Successfully configured the Enhanced-ACK Based Probing. + * @retval OT_ERROR_INVALID_ARGS @p aExtAddress is `NULL`. + * @retval OT_ERROR_NOT_FOUND The Initiator indicated by @p aShortAddress is not found when trying to clear. + * @retval OT_ERROR_NO_BUFS No more Initiator can be supported. + * + */ +otError qorvoRadioConfigureEnhAckProbing(otLinkMetrics aLinkMetrics, + uint16_t aShortAddress, + const uint8_t *aExtAddress); + +/** + * Get the current estimated time (in microseconds) of the radio chip. + * + * This microsecond timer must be a free-running timer. The timer must continue to advance with microsecond precision + * even when the radio is in the sleep state. + * + * @returns The current time in microseconds. UINT64_MAX when platform does not support or radio time is not ready. + * + */ +uint64_t qorvoRadioGetNow(void); + +/** + * Schedule a radio reception window at a specific time and duration. + * + * @param[in] aChannel The radio channel on which to receive. + * @param[in] aStart The receive window start time, in microseconds. + * @param[in] aDuration The receive window duration, in microseconds + * + * @retval OT_ERROR_NONE Successfully scheduled receive window. + * @retval OT_ERROR_FAILED The receive window could not be scheduled. + */ +otError qorvoRadioReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuration); + +/** + * Retrieve the radio capabilities of the radio + * + * @returns caps The radio capabilities as described in include/openthread/platform/radio.h + */ +otRadioCaps qorvoRadioGetCaps(void); + +/** + * Register the NeighbourTable callback with the openthread stack. + * + */ +void qorvoRegisterNeighbourTableCallback(bool enable); + +/** + * Callback to notify the radio which Neighbour was added removed + * + */ +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo); + +/** + * This function is called when OpenThread adds a Child to the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress); + +/** + * This function is called when OpenThread removes a Child from the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress); + +/** + * This callback is called when the energy scan is finished. + * + * @param[in] aEnergyScanMaxRssi The amount of energy detected during the ED scan. + * + */ +void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi); + +/** + * This callback is called after a transmission is completed (and if required an ACK is received). + * + * @param[in] aFrame The packet which was transmitted. + * @param[in] aFramePending Indicates if the FP bit was set in the ACK frame or not. + * @param[in] aError Indicates if an error occurred during transmission. + * + */ +void cbQorvoRadioTransmitDone(otRadioFrame *aFrame, bool aFramePending, otError aError); + +/** + * This callback is called after a transmission is completed (and if required an ACK is received). + * + * @param[in] aFrame The packet which was transmitted. + * @param[in] aAckFrame The complete 802.15.4-2015 enhanced ack frame. + * @param[in] aError Indicates if an error occurred during transmission. + * + */ +void cbQorvoRadioTransmitDone_AckFrame(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError); + +/** + * This callback is called after a frame is received. + * + * @param[in] aFrame The packet which was received. + * @param[in] aError Any error which occurred during reception of the packet. + * + */ +void cbQorvoRadioReceiveDone(otRadioFrame *aFrame, otError aError); + +/** + * This callback is called to notify OpenThread that the transmission has started. + * + * @note This function should be called by the same thread that executes all of the other OpenThread code. It should + * not be called by ISR or any other task. + * + * @param[in] aFrame A pointer to the frame that is being transmitted. + * + */ +void cbQorvoRadioTxStarted(otRadioFrame *aFrame); + +#endif // RADIO_QORVO_H_ diff --git a/src/qpg6200/random_qorvo.h b/src/qpg6200/random_qorvo.h new file mode 100755 index 000000000..35792b796 --- /dev/null +++ b/src/qpg6200/random_qorvo.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the random functions from the Qorvo library. + * + */ + +#ifndef RANDOM_QORVO_H_ +#define RANDOM_QORVO_H_ + +#include +#include + +/** + * This function initializes the random number service used by OpenThread. + * + */ +void qorvoRandomInit(void); + +/** + * This function returns an array of random numbers. + * + * @param[out] aOutput Pointer to an array which will be filled with random data. + * @param[in] aOutputLength number of bytes which will be written into the array. + * + */ +void qorvoRandomGet(uint8_t *aOutput, uint8_t aOutputLength); + +#endif // RANDOM_QORVO_H_ diff --git a/src/qpg6200/settings.c b/src/qpg6200/settings.c new file mode 100755 index 000000000..eaff1e6d9 --- /dev/null +++ b/src/qpg6200/settings.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file implements the OpenThread platform abstraction for non-volatile storage of settings. + * + */ + +#include + +#include +#include "openthread/platform/settings.h" + +#include +#include + +#include "settings_qorvo.h" + +#if !OPENTHREAD_SETTINGS_RAM + +/***************************************************************************** + * Public Function Definitions + *****************************************************************************/ + +// settings API +void otPlatSettingsInit(otInstance *aInstance, const uint16_t *aSensitiveKeys, uint16_t aSensitiveKeysLength) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aSensitiveKeys); + OT_UNUSED_VARIABLE(aSensitiveKeysLength); + qorvoSettingsInit(); +} + +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + +otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) +{ + otError error = OT_ERROR_NOT_FOUND; + OT_UNUSED_VARIABLE(aInstance); + + /* we only support multiple entries for the ChildInfo */ + /* Note: removed the assert, since the settings types are protected now */ + // assert((aIndex == 0) || (aKey == ot::Settings::kKeyChildInfo)); + + error = qorvoSettingsGet(aKey, aIndex, aValue, aValueLength); + + if (error == OT_ERROR_NOT_FOUND) + { + if (aValue != NULL) + { + *aValueLength = 0; + } + } + + return error; +} + +static otError PlatformSettingsAdd(otInstance *aInstance, + uint16_t aKey, + bool aIndex0, + const uint8_t *aValue, + uint16_t aValueLength) +{ + otError error = OT_ERROR_NONE; + OT_UNUSED_VARIABLE(aInstance); + + error = qorvoSettingsAdd(aKey, aIndex0, aValue, aValueLength); + + return error; +} + +otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) +{ + return PlatformSettingsAdd(aInstance, aKey, true, aValue, aValueLength); +} + +otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) +{ + return PlatformSettingsAdd(aInstance, aKey, false, aValue, aValueLength); +} + +otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) +{ + otError error = OT_ERROR_NOT_FOUND; + OT_UNUSED_VARIABLE(aInstance); + + /* Existence of @aKey is done in @qorvoSettingsDelete */ + error = qorvoSettingsDelete(aKey, aIndex); + + return error; +} + +void otPlatSettingsWipe(otInstance *aInstance) +{ + qorvoSettingsWipe(); + otPlatSettingsInit(aInstance, NULL, 0); +} + +#endif /* OPENTHREAD_SETTINGS_RAM */ diff --git a/src/qpg6200/settings_qorvo.h b/src/qpg6200/settings_qorvo.h new file mode 100755 index 000000000..eea601494 --- /dev/null +++ b/src/qpg6200/settings_qorvo.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the settings functions from the Qorvo library. + * + */ + +#ifndef SETTINGS_QORVO_H_ +#define SETTINGS_QORVO_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void qorvoSettingsInit(void); + +otError qorvoSettingsGet(uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength); + +otError qorvoSettingsAdd(uint16_t aKey, bool aIndex0, const uint8_t *aValue, uint16_t aValueLength); + +otError qorvoSettingsDelete(uint16_t aKey, int aIndex); + +void qorvoSettingsWipe(void); + +#ifdef __cplusplus +} +#endif + +#endif // SETTINGS_QORVO_H_ diff --git a/src/qpg6200/syscalls_stubs.c b/src/qpg6200/syscalls_stubs.c new file mode 100644 index 000000000..20f427493 --- /dev/null +++ b/src/qpg6200/syscalls_stubs.c @@ -0,0 +1,214 @@ +/* + * + * Copyright (c) 2024 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. + */ + +/* + This file is only used to implement weak syscall stubs + that gcc-arm-none-eabi 12.2.1 expect to link when using Libc + (newlib/libc_nano) +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int _open(const char *pathname, int flags, int mode); +int _close(int file); +int _fstat(int file, struct stat *st); +int _isatty(int file); +int _lseek(int file, int ptr, int dir); +int _read(int file, char *ptr, int len); +int _write(int file, const char *ptr, int len); + +/************************************************************************** + * @brief + * Open a file. + * + * @param[in] file + * File you want to open. + * + * @return + * Returns -1 since there is not logic here to open file. + **************************************************************************/ +int __attribute__((weak)) _open(const char *pathname, int flags, int mode) +{ + (void)pathname; + (void)flags; + (void)mode; + return -1; +} + +/************************************************************************** + * @brief + * Close a file. + * + * @param[in] file + * File you want to close. + * + * @return + * Returns 0 when the file is closed. + **************************************************************************/ +int __attribute__((weak)) _close(int file) +{ + (void)file; + return 0; +} + +/************************************************************************** + * @brief Exit the program. + * @param[in] status The value to return to the parent process as the + * exit status (not used). + **************************************************************************/ +void __attribute__((weak)) _exit(int status) +{ + (void)status; + while (true) + { + } /* Hang here forever... */ +} + +/************************************************************************* + * @brief + * Status of an open file. + * + * @param[in] file + * Check status for this file. + * + * @param[in] st + * Status information. + * + * @return + * Returns 0 when st_mode is set to character special. + ************************************************************************/ +int __attribute__((weak)) _fstat(int file, struct stat *st) +{ + (void)file; + (void)st; + return 0; +} + +/************************************************************************** + * @brief Get process ID. + *************************************************************************/ +int __attribute__((weak)) _getpid(void) +{ + return 1; +} + +/************************************************************************** + * @brief + * Query whether output stream is a terminal. + * + * @param[in] file + * Descriptor for the file. + * + * @return + * Returns 1 when query is done. + **************************************************************************/ +int __attribute__((weak)) _isatty(int file) +{ + (void)file; + return 1; +} + +/************************************************************************** + * @brief Send signal to process. + * @param[in] pid Process id (not used). + * @param[in] sig Signal to send (not used). + *************************************************************************/ +int __attribute__((weak)) _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + return -1; +} + +/************************************************************************** + * @brief + * Set position in a file. + * + * @param[in] file + * Descriptor for the file. + * + * @param[in] ptr + * Poiter to the argument offset. + * + * @param[in] dir + * Directory whence. + * + * @return + * Returns 0 when position is set. + *************************************************************************/ +int __attribute__((weak)) _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +/************************************************************************** + * @brief + * Read from a file. + * + * @param[in] file + * Descriptor for the file you want to read from. + * + * @param[in] ptr + * Pointer to the chacaters that are beeing read. + * + * @param[in] len + * Number of characters to be read. + * + * @return + * Number of characters that have been read. + *************************************************************************/ +int __attribute__((weak)) _read(int file, char *ptr, int len) +{ + (void)file; + (void)ptr; + (void)len; + return 0; +} + +/************************************************************************** + * @brief + * Write to a file. + * + * @param[in] file + * Descriptor for the file you want to write to. + * + * @param[in] ptr + * Pointer to the text you want to write + * + * @param[in] len + * Number of characters to be written. + * + * @return + * Number of characters that have been written. + **************************************************************************/ +int __attribute__((weak)) _write(int file, const char *ptr, int len) +{ + (void)file; + (void)ptr; + + return len; +} diff --git a/src/qpg6200/uart.c b/src/qpg6200/uart.c new file mode 100755 index 000000000..27eadb50c --- /dev/null +++ b/src/qpg6200/uart.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file implements the OpenThread platform abstraction for UART communication. + * + */ + +#include "uart_qorvo.h" + +/* work-around to avoid access to openthread-config.h */ +/* Define to 1 if stdbool.h conforms to C99. */ +#define HAVE_STDBOOL_H 1 +/* Define to 1 if the system has the type `_Bool'. */ +#define HAVE__BOOL 1 + +#include "common/code_utils.hpp" +#include "utils/uart.h" + +otError otPlatUartEnable(void) +{ + otError error = OT_ERROR_NONE; + qorvoUartInit(); + return error; +} + +otError otPlatUartDisable(void) +{ + otError error = OT_ERROR_NONE; + qorvoUartDeInit(); + return error; +} + +otError otPlatUartFlush(void) +{ + return qorvoUartFlush(); +} + +otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) +{ + otError error = OT_ERROR_NONE; + qorvoUartSendOutput(aBuf, aBufLength); + return error; +} + +void qorvoUartSendInput(uint8_t *buffer, uint16_t length) +{ + otPlatUartReceived(buffer, length); +} + +void cbQorvoUartTxDone(void) +{ + otPlatUartSendDone(); +} + +OT_TOOL_WEAK void otPlatUartSendDone(void) +{ +} + +OT_TOOL_WEAK void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) +{ + OT_UNUSED_VARIABLE(aBuf); + OT_UNUSED_VARIABLE(aBufLength); +} diff --git a/src/qpg6200/uart_qorvo.h b/src/qpg6200/uart_qorvo.h new file mode 100755 index 000000000..8d39a4b04 --- /dev/null +++ b/src/qpg6200/uart_qorvo.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024, 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. + */ + +/** + * @file + * This file includes the declarations of the uart functions from the Qorvo library. + * + */ + +#ifndef _UART_QORVO_H_ +#define _UART_QORVO_H_ + +#include +#include +#include +#include + +/** + * This function enables the UART driver. + * + */ +void qorvoUartInit(void); + +/** + * This function disables the UART driver. + * + */ +void qorvoUartDeInit(void); + +/** + * Callback function which will be called when uart transmission is done. + * + */ +void cbQorvoUartTxDone(void); + +/** + * Callback function which will be called when uart data is received. + * + * @param[in] aBuf A pointer to an array of received bytes. + * @param[in] aBufLength The number of bytes received from the uart. + * + */ +void qorvoUartSendInput(uint8_t *aBuf, uint16_t aBufLength); + +/** + * Function which transmits data via the uart. + * + * @param[out] aBuf A pointer to an array of bytes which need to be transmitted. + * @param[in] aBufLength The number of bytes to be transmitted via the uart. + * + */ +void qorvoUartSendOutput(const uint8_t *aBuf, uint16_t aBufLength); + +/** + * Function which transmits logging via the qorvo platform. + * + * @param[in] aLogLevel The severity level of logging. + * @param[in] aLogRegion The code region where the logging originated from. + * @param[in] aFormat The format strings. + * @param[in] varargs The arguments for the format string. + * + */ +void qorvoUartLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...); + +/** + * Flush the outgoing transmit buffer and wait for the data to be sent. + * This is called when the CLI UART interface has a full buffer but still + * wishes to send more data. + * + * @retval OT_ERROR_NONE Flush succeeded, we can proceed to write more + * data to the buffer. + * + * @retval OT_ERROR_NOT_IMPLEMENTED Driver does not support synchronous flush. + * @retval OT_ERROR_INVALID_STATE Driver has no data to flush. + */ +otError qorvoUartFlush(void); +#endif // _UART_QORVO_H_ diff --git a/third_party/Qorvo/repo b/third_party/Qorvo/repo index 05e094431..494bc2850 160000 --- a/third_party/Qorvo/repo +++ b/third_party/Qorvo/repo @@ -1 +1 @@ -Subproject commit 05e094431c4eab7eafea85a566660be6ed318cd7 +Subproject commit 494bc2850803b9351bf92166521e8b9f6f6e3995