From 98dea576fdc88a5f7eaf16512e0b680291d57d39 Mon Sep 17 00:00:00 2001 From: nikita-s-wrk Date: Sat, 23 Jan 2021 00:58:33 +0300 Subject: [PATCH] [platform] addition of QPG7015M/GP712 RCP build (#6110) - Addition of RCP build for QPG7015M and GP712 Qorvo platforms - Addition required RCP API to glue code --- examples/Makefile-gp712 | 19 ++-- examples/Makefile-qpg7015m | 19 ++-- examples/platforms/gp712/Makefile.am | 2 +- examples/platforms/gp712/Makefile.platform.am | 4 +- examples/platforms/gp712/README.md | 2 +- examples/platforms/gp712/diag.c | 2 +- examples/platforms/gp712/entropy.c | 60 ------------ examples/platforms/gp712/flash.c | 2 +- examples/platforms/gp712/logging.c | 1 - .../gp712/openthread-core-gp712-config.h | 80 ++++++++++++++++ examples/platforms/gp712/platform_qorvo.h | 1 - examples/platforms/gp712/radio.c | 62 +++++++++++-- examples/platforms/gp712/system.c | 2 +- examples/platforms/gp712/uart-posix.c | 92 +++++++++++++++---- .../platforms/qpg6095/Makefile.platform.am | 5 +- examples/platforms/qpg6095/diag.c | 2 +- .../qpg6095/openthread-core-qpg6095-config.h | 8 -- examples/platforms/qpg6095/platform.c | 2 +- examples/platforms/qpg6095/platform_qorvo.h | 2 +- examples/platforms/qpg6095/radio.c | 59 ++++++++++-- examples/platforms/qpg6095/settings.cpp | 1 + .../platforms/qpg6100/Makefile.platform.am | 3 +- .../qpg6100/openthread-core-qpg6100-config.h | 8 -- examples/platforms/qpg7015m/Makefile.am | 2 +- .../platforms/qpg7015m/Makefile.platform.am | 4 +- examples/platforms/qpg7015m/README.md | 71 ++++++++++++++ .../openthread-core-qpg7015m-config.h | 80 ++++++++++++++++ 27 files changed, 451 insertions(+), 144 deletions(-) create mode 100644 examples/platforms/qpg7015m/README.md mode change 100755 => 100644 examples/platforms/qpg7015m/openthread-core-qpg7015m-config.h diff --git a/examples/Makefile-gp712 b/examples/Makefile-gp712 index a36918d47..d14efa956 100644 --- a/examples/Makefile-gp712 +++ b/examples/Makefile-gp712 @@ -47,12 +47,17 @@ OBJCOPY = $(CROSS_COMPILE)objcopy BuildJobs ?= 9 -configure_OPTIONS += \ - --disable-tools \ - --enable-cli \ - --enable-ftd \ - --enable-mtd \ - --with-examples=$(PREFIX_LC) \ +configure_OPTIONS = \ + --disable-tools \ + --enable-cli \ + --enable-ftd \ + --enable-mtd \ + --enable-ncp \ + --enable-cli-app \ + --enable-radio-only \ + --with-ncp-vendor-hook-source=no \ + --with-ncp-bus=uart \ + --with-examples=$(PREFIX_LC) \ $(NULL) ifeq ($(CLI_LOGGING),1) @@ -100,7 +105,7 @@ LDFLAGS += \ -Wl,--gc-sections \ -Wl,-Map=$(PREFIX_LC).map \ -lrt \ - -lpthread \ + -pthread \ $(NULL) ECHO := @echo diff --git a/examples/Makefile-qpg7015m b/examples/Makefile-qpg7015m index fa8200479..41d459b18 100755 --- a/examples/Makefile-qpg7015m +++ b/examples/Makefile-qpg7015m @@ -47,12 +47,17 @@ OBJCOPY = $(CROSS_COMPILE)objcopy BuildJobs ?= 9 -configure_OPTIONS += \ - --disable-tools \ - --enable-cli \ - --enable-ftd \ - --enable-mtd \ - --with-examples=$(PREFIX_LC) \ +configure_OPTIONS = \ + --disable-tools \ + --enable-cli \ + --enable-ftd \ + --enable-mtd \ + --enable-ncp \ + --enable-cli-app \ + --enable-radio-only \ + --with-ncp-vendor-hook-source=no \ + --with-ncp-bus=uart \ + --with-examples=$(PREFIX_LC) \ $(NULL) ifeq ($(CLI_LOGGING),1) @@ -100,7 +105,7 @@ LDFLAGS += \ -Wl,--gc-sections \ -Wl,-Map=$(PREFIX_LC).map \ -lrt \ - -lpthread \ + -pthread \ $(NULL) ECHO := @echo diff --git a/examples/platforms/gp712/Makefile.am b/examples/platforms/gp712/Makefile.am index 6e1421701..706870aa1 100644 --- a/examples/platforms/gp712/Makefile.am +++ b/examples/platforms/gp712/Makefile.am @@ -40,7 +40,7 @@ libopenthread_gp712_a_CPPFLAGS = \ -I$(top_srcdir)/examples/platforms \ -I$(top_srcdir)/examples/platforms/gp712 \ -lrt \ - -lpthread \ + -pthread \ $(NULL) PLATFORM_SOURCES = \ diff --git a/examples/platforms/gp712/Makefile.platform.am b/examples/platforms/gp712/Makefile.platform.am index 5e6e70635..7dc695807 100644 --- a/examples/platforms/gp712/Makefile.platform.am +++ b/examples/platforms/gp712/Makefile.platform.am @@ -37,10 +37,10 @@ if OPENTHREAD_ENABLE_FTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/gp712/libQorvoGP712_ftd.a \ $(NULL) -endif # OPENTHREAD_ENABLE_FTD +else # OPENTHREAD_ENABLE_FTD if OPENTHREAD_ENABLE_MTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/gp712/libQorvoGP712_mtd.a \ $(NULL) endif # OPENTHREAD_ENABLE_MTD - +endif \ No newline at end of file diff --git a/examples/platforms/gp712/README.md b/examples/platforms/gp712/README.md index f8d3aec00..47d6731f6 100644 --- a/examples/platforms/gp712/README.md +++ b/examples/platforms/gp712/README.md @@ -4,7 +4,7 @@ This directory contains example platform drivers for Qorvo gp712 on RPi. ## Toolchain -This example use the GNU GCC toolchain on the Raspberry Pi. To build on the Pi: +This example uses the GNU GCC toolchain on the Raspberry Pi. To build on the Pi: 1. Download the repo to the Pi 2. go to the subfolder in the openthread repo: third_party/nlbuild-autotools/repo/tools/packages and enter this command: diff --git a/examples/platforms/gp712/diag.c b/examples/platforms/gp712/diag.c index 3b71917e4..e79c2f260 100644 --- a/examples/platforms/gp712/diag.c +++ b/examples/platforms/gp712/diag.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/examples/platforms/gp712/entropy.c b/examples/platforms/gp712/entropy.c index 11e11ca78..bf25db5dc 100644 --- a/examples/platforms/gp712/entropy.c +++ b/examples/platforms/gp712/entropy.c @@ -41,53 +41,14 @@ #include "utils/code_utils.h" -#if __SANITIZE_ADDRESS__ != 0 - -static uint32_t sState = 1; - -#endif // __SANITIZE_ADDRESS__ - void qorvoRandomInit(void) { -#if __SANITIZE_ADDRESS__ != 0 - - sState = (uint32_t)time(NULL); - -#endif // __SANITIZE_ADDRESS__ } -#if __SANITIZE_ADDRESS__ != 0 - -static uint32_t randomUint32Get(void) -{ - uint32_t mlcg, p, q; - uint64_t tmpstate; - - tmpstate = (uint64_t)33614 * (uint64_t)sState; - q = tmpstate & 0xffffffff; - q = q >> 1; - p = tmpstate >> 32; - mlcg = p + q; - - if (mlcg & 0x80000000) - { - mlcg &= 0x7fffffff; - mlcg++; - } - - sState = mlcg; - - return mlcg; -} - -#endif // __SANITIZE_ADDRESS__ - otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) { otError error = OT_ERROR_NONE; -#if __SANITIZE_ADDRESS__ == 0 - FILE * file = NULL; size_t readLength; @@ -106,26 +67,5 @@ exit: fclose(file); } -#else // __SANITIZE_ADDRESS__ - - /* - * THE IMPLEMENTATION BELOW IS NOT COMPLIANT WITH THE THREAD SPECIFICATION. - * - * Address Sanitizer triggers test failures when reading random - * values from /dev/urandom. The pseudo-random number generator - * implementation below is only used to enable continuous - * integration checks with Address Sanitizer enabled. - */ - otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); - - for (uint16_t length = 0; length < aOutputLength; length++) - { - aOutput[length] = (uint8_t)randomUint32Get(); - } - -exit: - -#endif // __SANITIZE_ADDRESS__ - return error; } diff --git a/examples/platforms/gp712/flash.c b/examples/platforms/gp712/flash.c index 9cfe79a9f..fc5f10163 100644 --- a/examples/platforms/gp712/flash.c +++ b/examples/platforms/gp712/flash.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include static int sFlashFd = -1; diff --git a/examples/platforms/gp712/logging.c b/examples/platforms/gp712/logging.c index d10ba9ad5..1b15a795f 100644 --- a/examples/platforms/gp712/logging.c +++ b/examples/platforms/gp712/logging.c @@ -28,7 +28,6 @@ #include "platform_qorvo.h" #include -#include #include #include diff --git a/examples/platforms/gp712/openthread-core-gp712-config.h b/examples/platforms/gp712/openthread-core-gp712-config.h index 10025acfc..87c96332c 100644 --- a/examples/platforms/gp712/openthread-core-gp712-config.h +++ b/examples/platforms/gp712/openthread-core-gp712-config.h @@ -53,4 +53,84 @@ */ #define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1 +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE + * + * Define to 1 if you want to enable software ACK timeout logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE + * + * Define to 1 if you want to enable software retransmission logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE + * + * Define to 1 if you want to enable software CSMA-CA backoff logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE + * + * Define to 1 if you want to enable software transmission security logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE + * + * Define to 1 to enable software transmission target time logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_DIAG_ENABLE + * + * Define as 1 to enable the diag feature. + * + */ +#ifndef OPENTHREAD_CONFIG_DIAG_ENABLE +#define OPENTHREAD_CONFIG_DIAG_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_NCP_SPI_ENABLE + * + * Define as 1 to enable SPI NCP interface. + * + */ +#ifndef OPENTHREAD_CONFIG_NCP_SPI_ENABLE +#define OPENTHREAD_CONFIG_NCP_SPI_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_NCP_UART_ENABLE + * + * Define as 1 to enable UART NCP interface. + * + */ +#ifndef OPENTHREAD_CONFIG_NCP_UART_ENABLE +#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1 +#endif + #endif // OPENTHREAD_CORE_GP712_CONFIG_H_ diff --git a/examples/platforms/gp712/platform_qorvo.h b/examples/platforms/gp712/platform_qorvo.h index 915fcc6b2..af657b87a 100644 --- a/examples/platforms/gp712/platform_qorvo.h +++ b/examples/platforms/gp712/platform_qorvo.h @@ -36,7 +36,6 @@ #define PLATFORM_QORVO_H_ #include -#include #include #include diff --git a/examples/platforms/gp712/radio.c b/examples/platforms/gp712/radio.c index cc346e1c4..23fb1df08 100644 --- a/examples/platforms/gp712/radio.c +++ b/examples/platforms/gp712/radio.c @@ -77,6 +77,11 @@ typedef struct otCachedSettings_s 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; @@ -150,13 +155,15 @@ otError otPlatRadioSleep(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - if (sState == OT_RADIO_STATE_RECEIVE) + 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 OT_ERROR_NONE; + return error; } otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) @@ -168,6 +175,11 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) 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; } @@ -183,8 +195,7 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket) { - otError err = OT_ERROR_NONE; - + otError err = OT_ERROR_NONE; pQorvoInstance = aInstance; otEXPECT_ACTION(sState != OT_RADIO_STATE_DISABLED, err = OT_ERROR_INVALID_STATE); @@ -328,23 +339,54 @@ void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi) otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) { OT_UNUSED_VARIABLE(aInstance); - if ((sState == OT_RADIO_STATE_DISABLED) || (sScanstate != 0)) + + otError result; + + if (aPower == NULL) { - return OT_ERROR_INVALID_STATE; + return OT_ERROR_INVALID_ARGS; } - return qorvoRadioGetTransmitPower(aPower); + 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)) { - return OT_ERROR_INVALID_STATE; + pendingTxPower = aPower; + return OT_ERROR_NONE; } - return qorvoRadioSetTransmitPower(aPower); + 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) diff --git a/examples/platforms/gp712/system.c b/examples/platforms/gp712/system.c index ebbfbe392..175b8fdcf 100644 --- a/examples/platforms/gp712/system.c +++ b/examples/platforms/gp712/system.c @@ -54,7 +54,7 @@ otInstance *localInstance = NULL; int gArgumentsCount = 0; char **gArguments = NULL; -bool qorvoPlatGotoSleepCheck(void) +uint8_t qorvoPlatGotoSleepCheck(void) { bool canGotoSleep = false; diff --git a/examples/platforms/gp712/uart-posix.c b/examples/platforms/gp712/uart-posix.c index db1c50885..e0b2c10e3 100644 --- a/examples/platforms/gp712/uart-posix.c +++ b/examples/platforms/gp712/uart-posix.c @@ -25,6 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#define _XOPEN_SOURCE 500 #include "alarm_qorvo.h" #include "platform_qorvo.h" @@ -189,14 +190,11 @@ otError otPlatUartEnable(void) otEXPECT_ACTION(tcsetattr(s_out_fd, TCSANOW, &termios) == 0, perror("tcsetattr"); error = OT_ERROR_GENERIC); } + return error; + exit: - - if (error != OT_ERROR_NONE) - { - close(s_in_fd); - close(s_out_fd); - } - + close(s_in_fd); + close(s_out_fd); return error; } @@ -219,13 +217,70 @@ otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) s_write_buffer = aBuf; s_write_length = aBufLength; + qorvoAlarmScheduleEventArg(0, platformDummy, (void *)&s_in_fd); + exit: return error; } +void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd) +{ + if (aReadFdSet != NULL) + { + FD_SET(s_in_fd, aReadFdSet); + + if (aErrorFdSet != NULL) + { + FD_SET(s_in_fd, aErrorFdSet); + } + + if (aMaxFd != NULL && *aMaxFd < s_in_fd) + { + *aMaxFd = s_in_fd; + } + } + + if ((aWriteFdSet != NULL) && (s_write_length > 0)) + { + FD_SET(s_out_fd, aWriteFdSet); + + if (aErrorFdSet != NULL) + { + FD_SET(s_out_fd, aErrorFdSet); + } + + if (aMaxFd != NULL && *aMaxFd < s_out_fd) + { + *aMaxFd = s_out_fd; + } + } +} + otError otPlatUartFlush(void) { - return OT_ERROR_NOT_IMPLEMENTED; + otError error = OT_ERROR_NONE; + ssize_t count; + + otEXPECT_ACTION(s_write_buffer != NULL && s_write_length > 0, error = OT_ERROR_INVALID_STATE); + + while ((count = write(s_out_fd, s_write_buffer, s_write_length)) > 0 && (s_write_length -= count) > 0) + { + s_write_buffer += count; + } + + if (count != -1) + { + assert(s_write_length == 0); + s_write_buffer = NULL; + } + else + { + perror("write(UART)"); + exit(EXIT_FAILURE); + } + +exit: + return error; } void platformUartProcess(void) @@ -270,7 +325,6 @@ void platformUartProcess(void) perror("read"); exit(EXIT_FAILURE); } - otPlatUartReceived(s_receive_buffer, (uint16_t)rval); } @@ -278,19 +332,21 @@ void platformUartProcess(void) { rval = write(s_out_fd, s_write_buffer, s_write_length); - if (rval <= 0) + if (rval >= 0) + { + s_write_buffer += (uint16_t)rval; + s_write_length -= (uint16_t)rval; + + if (s_write_length == 0) + { + otPlatUartSendDone(); + } + } + else if (errno != EINTR) { perror("write"); exit(EXIT_FAILURE); } - - s_write_buffer += (uint16_t)rval; - s_write_length -= (uint16_t)rval; - - if (s_write_length == 0) - { - otPlatUartSendDone(); - } } } } diff --git a/examples/platforms/qpg6095/Makefile.platform.am b/examples/platforms/qpg6095/Makefile.platform.am index 0d12d9c6b..9230e7ec4 100644 --- a/examples/platforms/qpg6095/Makefile.platform.am +++ b/examples/platforms/qpg6095/Makefile.platform.am @@ -37,13 +37,14 @@ if OPENTHREAD_ENABLE_FTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg6095/libQorvoQPG6095_ftd.a \ $(NULL) -endif # OPENTHREAD_ENABLE_FTD +else # OPENTHREAD_ENABLE_FTD if OPENTHREAD_ENABLE_MTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg6095/libQorvoQPG6095_mtd.a \ $(NULL) endif # OPENTHREAD_ENABLE_MTD +endif + LDFLAGS_COMMON += \ -T $(top_srcdir)/examples/platforms/qpg6095/qpg6095.ld \ $(NULL) - diff --git a/examples/platforms/qpg6095/diag.c b/examples/platforms/qpg6095/diag.c index 3b71917e4..e79c2f260 100644 --- a/examples/platforms/qpg6095/diag.c +++ b/examples/platforms/qpg6095/diag.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/examples/platforms/qpg6095/openthread-core-qpg6095-config.h b/examples/platforms/qpg6095/openthread-core-qpg6095-config.h index 03720cebf..e6e644b50 100644 --- a/examples/platforms/qpg6095/openthread-core-qpg6095-config.h +++ b/examples/platforms/qpg6095/openthread-core-qpg6095-config.h @@ -50,12 +50,4 @@ */ #define OPENTHREAD_CONFIG_PLATFORM_INFO "QPG6095" -/** - * @def OPENTHREAD_CONFIG_NCP_UART_ENABLE - * - * Define to 1 to enable NCP UART support. - * - */ -#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1 - #endif // OPENTHREAD_CORE_QPG6095_CONFIG_H_ diff --git a/examples/platforms/qpg6095/platform.c b/examples/platforms/qpg6095/platform.c index e0a87267a..e00c17c25 100644 --- a/examples/platforms/qpg6095/platform.c +++ b/examples/platforms/qpg6095/platform.c @@ -49,7 +49,7 @@ static otInstance *localInstance = NULL; extern void flash_jump_gpJumpTables_GetRomVersion(void); #endif // QORVO_USE_ROM -bool qorvoPlatGotoSleepCheck(void) +uint8_t qorvoPlatGotoSleepCheck(void) { if (localInstance) { diff --git a/examples/platforms/qpg6095/platform_qorvo.h b/examples/platforms/qpg6095/platform_qorvo.h index 1afb17321..85eb3808f 100644 --- a/examples/platforms/qpg6095/platform_qorvo.h +++ b/examples/platforms/qpg6095/platform_qorvo.h @@ -38,7 +38,7 @@ #include #include -typedef bool (*qorvoPlatGotoSleepCheckCallback_t)(void); +typedef uint8_t (*qorvoPlatGotoSleepCheckCallback_t)(void); /** * This function initializes the platform. diff --git a/examples/platforms/qpg6095/radio.c b/examples/platforms/qpg6095/radio.c index d73272d3b..873588a2e 100644 --- a/examples/platforms/qpg6095/radio.c +++ b/examples/platforms/qpg6095/radio.c @@ -77,6 +77,11 @@ typedef struct otCachedSettings_s 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; @@ -150,13 +155,15 @@ otError otPlatRadioSleep(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - if (sState == OT_RADIO_STATE_RECEIVE) + 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 OT_ERROR_NONE; + return error; } otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) @@ -168,6 +175,11 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) 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; } @@ -328,23 +340,54 @@ void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi) otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) { OT_UNUSED_VARIABLE(aInstance); - if ((sState == OT_RADIO_STATE_DISABLED) || (sScanstate != 0)) + + otError result; + + if (aPower == NULL) { - return OT_ERROR_INVALID_STATE; + return OT_ERROR_INVALID_ARGS; } - return qorvoRadioGetTransmitPower(aPower); + 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)) { - return OT_ERROR_INVALID_STATE; + pendingTxPower = aPower; + return OT_ERROR_NONE; } - return qorvoRadioSetTransmitPower(aPower); + 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) diff --git a/examples/platforms/qpg6095/settings.cpp b/examples/platforms/qpg6095/settings.cpp index a6e4e4459..6dff98db1 100644 --- a/examples/platforms/qpg6095/settings.cpp +++ b/examples/platforms/qpg6095/settings.cpp @@ -38,6 +38,7 @@ #include "openthread/platform/settings.h" #include +#include #include "settings_qorvo.h" diff --git a/examples/platforms/qpg6100/Makefile.platform.am b/examples/platforms/qpg6100/Makefile.platform.am index a93fd6d31..52656bcc4 100644 --- a/examples/platforms/qpg6100/Makefile.platform.am +++ b/examples/platforms/qpg6100/Makefile.platform.am @@ -42,12 +42,13 @@ if OPENTHREAD_ENABLE_FTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg6100/libQorvoQPG6100_ftd.a \ $(NULL) -endif # OPENTHREAD_ENABLE_FTD +else # OPENTHREAD_ENABLE_FTD if OPENTHREAD_ENABLE_MTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg6100/libQorvoQPG6100_mtd.a \ $(NULL) endif # OPENTHREAD_ENABLE_MTD +endif LDFLAGS_COMMON += \ -T $(top_srcdir)/examples/platforms/qpg6100/qpg6100.ld \ $(NULL) diff --git a/examples/platforms/qpg6100/openthread-core-qpg6100-config.h b/examples/platforms/qpg6100/openthread-core-qpg6100-config.h index 3dcf8732d..be3b33ba3 100644 --- a/examples/platforms/qpg6100/openthread-core-qpg6100-config.h +++ b/examples/platforms/qpg6100/openthread-core-qpg6100-config.h @@ -50,12 +50,4 @@ */ #define OPENTHREAD_CONFIG_PLATFORM_INFO "QPG6100" -/** - * @def OPENTHREAD_CONFIG_NCP_UART_ENABLE - * - * Define to 1 to enable NCP UART support. - * - */ -#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1 - #endif // OPENTHREAD_CORE_QPG6100_CONFIG_H_ diff --git a/examples/platforms/qpg7015m/Makefile.am b/examples/platforms/qpg7015m/Makefile.am index 51caf80e1..613e498a5 100755 --- a/examples/platforms/qpg7015m/Makefile.am +++ b/examples/platforms/qpg7015m/Makefile.am @@ -40,7 +40,7 @@ libopenthread_qpg7015m_a_CPPFLAGS = \ -I$(top_srcdir)/examples/platforms \ -I$(top_srcdir)/examples/platforms/qpg7015m \ -lrt \ - -lpthread \ + -pthread \ $(NULL) PLATFORM_SOURCES = \ diff --git a/examples/platforms/qpg7015m/Makefile.platform.am b/examples/platforms/qpg7015m/Makefile.platform.am index e3ceff4a9..9aa489707 100755 --- a/examples/platforms/qpg7015m/Makefile.platform.am +++ b/examples/platforms/qpg7015m/Makefile.platform.am @@ -37,10 +37,10 @@ if OPENTHREAD_ENABLE_FTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg7015m/libQorvoQPG7015M_ftd.a \ $(NULL) -endif # OPENTHREAD_ENABLE_FTD +else # OPENTHREAD_ENABLE_FTD if OPENTHREAD_ENABLE_MTD LDADD_COMMON += \ $(top_srcdir)/third_party/Qorvo/repo/qpg7015m/libQorvoQPG7015M_mtd.a \ $(NULL) endif # OPENTHREAD_ENABLE_MTD - +endif diff --git a/examples/platforms/qpg7015m/README.md b/examples/platforms/qpg7015m/README.md new file mode 100644 index 000000000..87aa1d543 --- /dev/null +++ b/examples/platforms/qpg7015m/README.md @@ -0,0 +1,71 @@ +# OpenThread on Qorvo qpg7015m Example + +This directory contains example platform drivers for Qorvo qpg7015m on RPi. + +## Toolchain + +This example uses the GNU GCC toolchain on the Raspberry Pi. To build on the Pi: + +1. Download the repo to the Pi +2. go to the subfolder in the openthread repo: third_party/nlbuild-autotools/repo/tools/packages and enter this command: + +```bash +$ sudo /bin/bash build +``` + +Note that you may need to install additional packages to make this build work, depending on your actual RPi OS version. The build process will complain if additional packages are required. + +## Build Examples + +```bash +$ cd +$ ./script/bootstrap +$ ./bootstrap +$ REFERENCE_DEVICE=1 CLI_LOGGING=1 COMMISSIONER=1 JOINER=1 DHCP6_CLIENT=1 DHCP6_SERVER=1 BORDER_ROUTER=1 make -f examples/Makefile-qpg7015m +``` + +After a successful build, the `elf` files are found in `/output/qpg7015m/bin`. + +Building a variant which interfaces via a tcp socket is also possible. Replace the uart-posix.c with uart-socket.c in the Makefile.am from examples/platforms/qpg7015m/Makefile.am and rebuild. Now it should be possible to open a telnet to socket 9190 of the raspberry pi from a remote PC. This also easier testing with the official Thread Test Harness. + +## + +## Interact + +1. Spawn the process: + +```bash +$ cd /output/qpg7015m/bin +$ ./qpg7015m-ot-cli-ftd +``` + +2. Type `help` for list of commands. + +```bash +> help +help +channel +childtimeout +contextreusedelay +extaddr +extpanid +ipaddr +keysequence +leaderweight +masterkey +mode +netdata register +networkidtimeout +networkname +panid +ping +prefix +releaserouterid +rloc16 +route +routerupgradethreshold +scan +start +state +stop +``` diff --git a/examples/platforms/qpg7015m/openthread-core-qpg7015m-config.h b/examples/platforms/qpg7015m/openthread-core-qpg7015m-config.h old mode 100755 new mode 100644 index 9eac255c1..711edaf81 --- a/examples/platforms/qpg7015m/openthread-core-qpg7015m-config.h +++ b/examples/platforms/qpg7015m/openthread-core-qpg7015m-config.h @@ -53,4 +53,84 @@ */ #define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1 +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE + * + * Define to 1 if you want to enable software ACK timeout logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE + * + * Define to 1 if you want to enable software retransmission logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE + * + * Define to 1 if you want to enable software CSMA-CA backoff logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE + * + * Define to 1 if you want to enable software transmission security logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE + * + * Define to 1 to enable software transmission target time logic. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) +#endif + +/** + * @def OPENTHREAD_CONFIG_DIAG_ENABLE + * + * Define as 1 to enable the diag feature. + * + */ +#ifndef OPENTHREAD_CONFIG_DIAG_ENABLE +#define OPENTHREAD_CONFIG_DIAG_ENABLE 1 +#endif + +/** + * @def OPENTHREAD_CONFIG_NCP_SPI_ENABLE + * + * Define as 1 to enable SPI NCP interface. + * + */ +#ifndef OPENTHREAD_CONFIG_NCP_SPI_ENABLE +#define OPENTHREAD_CONFIG_NCP_SPI_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_NCP_UART_ENABLE + * + * Define as 1 to enable UART NCP interface. + * + */ +#ifndef OPENTHREAD_CONFIG_NCP_UART_ENABLE +#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1 +#endif + #endif // OPENTHREAD_CORE_QPG7015M_CONFIG_H_