diff --git a/src/gsdk-pal/alarm.c b/src/gsdk-pal/alarm.c index 14cbb610..2f832202 100644 --- a/src/gsdk-pal/alarm.c +++ b/src/gsdk-pal/alarm.c @@ -32,11 +32,11 @@ * */ +#include "openthread-system.h" #include +#include #include #include -#include "openthread-system.h" -#include #include #include #include @@ -67,14 +67,12 @@ static void AlarmCallback(sl_sleeptimer_timer_handle_t *aHandle, void *aData) otSysEventSignalPending(); } -static void radioTimerExpired(struct RAIL_MultiTimer *tmr, - RAIL_Time_t expectedTimeOfEvent, - void *cbArg) +static void radioTimerExpired(struct RAIL_MultiTimer *tmr, RAIL_Time_t expectedTimeOfEvent, void *cbArg) { OT_UNUSED_VARIABLE(tmr); OT_UNUSED_VARIABLE(expectedTimeOfEvent); OT_UNUSED_VARIABLE(cbArg); - + otSysEventSignalPending(); } @@ -118,7 +116,7 @@ void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) sl_sleeptimer_stop_timer(&sl_handle); sMsAlarm = aT0 + aDt; - remaining = (int32_t)(sMsAlarm - otPlatAlarmMilliGetNow()); + remaining = (int32_t)(sMsAlarm - otPlatAlarmMilliGetNow()); sIsMsRunning = true; if (remaining <= 0) @@ -140,7 +138,7 @@ void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) uint32_t efr32AlarmPendingTime(void) { uint32_t remaining = 0; - uint32_t now = otPlatAlarmMilliGetNow(); + uint32_t now = otPlatAlarmMilliGetNow(); if (sIsMsRunning && (sMsAlarm > now)) { remaining = sMsAlarm - now; @@ -150,7 +148,7 @@ uint32_t efr32AlarmPendingTime(void) bool efr32AlarmIsRunning(otInstance *aInstance) { - return (otInstanceIsInitialized(aInstance) ? sIsMsRunning : false); + return (otInstanceIsInitialized(aInstance) ? sIsMsRunning : false); } void otPlatAlarmMilliStop(otInstance *aInstance) @@ -164,7 +162,7 @@ void otPlatAlarmMilliStop(otInstance *aInstance) void efr32AlarmProcess(otInstance *aInstance) { int32_t remaining; - bool alarmMilliFired = false; + bool alarmMilliFired = false; #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE bool alarmMicroFired = false; #endif @@ -227,20 +225,21 @@ uint32_t otPlatAlarmMicroGetNow(void) // period for the wrap-around logic to work below uint64_t otPlatTimeGet(void) { - static uint32_t timerWraps = 0U; - static uint32_t prev32TimeUs = 0U; - uint32_t now32TimeUs; - uint64_t now64TimeUs; - CORE_DECLARE_IRQ_STATE; - CORE_ENTER_CRITICAL(); - now32TimeUs = RAIL_GetTime(); - if (now32TimeUs < prev32TimeUs) { - timerWraps += 1U; - } - prev32TimeUs = now32TimeUs; - now64TimeUs = ((uint64_t)timerWraps << 32) + now32TimeUs; - CORE_EXIT_CRITICAL(); - return now64TimeUs; + static uint32_t timerWraps = 0U; + static uint32_t prev32TimeUs = 0U; + uint32_t now32TimeUs; + uint64_t now64TimeUs; + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_CRITICAL(); + now32TimeUs = RAIL_GetTime(); + if (now32TimeUs < prev32TimeUs) + { + timerWraps += 1U; + } + prev32TimeUs = now32TimeUs; + now64TimeUs = ((uint64_t)timerWraps << 32) + now32TimeUs; + CORE_EXIT_CRITICAL(); + return now64TimeUs; } void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) @@ -261,11 +260,7 @@ void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) } else { - status = RAIL_SetMultiTimer(&rail_timer, - remaining, - RAIL_TIME_DELAY, - radioTimerExpired, - NULL); + status = RAIL_SetMultiTimer(&rail_timer, remaining, RAIL_TIME_DELAY, radioTimerExpired, NULL); assert(status == RAIL_STATUS_NO_ERROR); } } diff --git a/src/gsdk-pal/board_config.h b/src/gsdk-pal/board_config.h index 86480281..70acba13 100644 --- a/src/gsdk-pal/board_config.h +++ b/src/gsdk-pal/board_config.h @@ -35,20 +35,20 @@ #ifndef __BOARD_CONFIG_H__ #define __BOARD_CONFIG_H__ -#if (!defined(RADIO_CONFIG_SUBGHZ_SUPPORT) || !RADIO_CONFIG_SUBGHZ_SUPPORT) -#define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Enable OQPSK modulation in 2.4GHz band +#if (!defined(RADIO_CONFIG_SUBGHZ_SUPPORT) || !RADIO_CONFIG_SUBGHZ_SUPPORT) +#define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Enable OQPSK modulation in 2.4GHz band #endif #ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT -#define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c +#define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c #endif #ifndef RADIO_CONFIG_ENABLE_CUSTOM_EUI_SUPPORT -#define RADIO_CONFIG_ENABLE_CUSTOM_EUI_SUPPORT 1 /// Set to 1 to enable custom EUI support (enabled by default) +#define RADIO_CONFIG_ENABLE_CUSTOM_EUI_SUPPORT 1 /// Set to 1 to enable custom EUI support (enabled by default) #endif #ifndef RADIO_CONFIG_DMP_SUPPORT -#define RADIO_CONFIG_DMP_SUPPORT 0 /// Set to 1 to enable Dynamic Multi-Protocol support in radio.c +#define RADIO_CONFIG_DMP_SUPPORT 0 /// Set to 1 to enable Dynamic Multi-Protocol support in radio.c #endif #endif // __BOARD_CONFIG_H__ diff --git a/src/gsdk-pal/crypto.c b/src/gsdk-pal/crypto.c index c2cfedb7..35240c63 100644 --- a/src/gsdk-pal/crypto.c +++ b/src/gsdk-pal/crypto.c @@ -147,7 +147,7 @@ static psa_key_persistence_t getPsaKeyPersistence(otCryptoKeyStorage aKeyPersist void otPlatCryptoInit(void) { - (void) sl_sec_man_init(); + (void)sl_sec_man_init(); } static otError extractPrivateKeyFromDer(uint8_t *aPrivateKey, const uint8_t *aDer, uint8_t aDerLen) @@ -160,14 +160,13 @@ static otError extractPrivateKeyFromDer(uint8_t *aPrivateKey, const uint8_t *aDe otEXPECT_ACTION(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0, error = OT_ERROR_FAILED); - #if (MBEDTLS_VERSION_NUMBER >= 0x03000000) - otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0, - mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE) == 0, - error = OT_ERROR_PARSE); - #else - otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0) == 0, - error = OT_ERROR_PARSE); - #endif +#if (MBEDTLS_VERSION_NUMBER >= 0x03000000) + otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0, mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE) + == 0, + error = OT_ERROR_PARSE); +#else + otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0) == 0, error = OT_ERROR_PARSE); +#endif keyPair = mbedtls_pk_ec(pk); mbedtls_mpi_write_binary(&keyPair->MBEDTLS_PRIVATE(d), aPrivateKey, SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE); @@ -176,29 +175,34 @@ static otError extractPrivateKeyFromDer(uint8_t *aPrivateKey, const uint8_t *aDe return error; } -otError otPlatCryptoImportKey(otCryptoKeyRef * aKeyId, +otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyId, otCryptoKeyType aKeyType, otCryptoKeyAlgorithm aKeyAlgorithm, int aKeyUsage, otCryptoKeyStorage aKeyPersistence, - const uint8_t * aKey, + const uint8_t *aKey, size_t aKeyLen) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; psa_status_t status; uint8_t aPrivateKey[SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE]; const uint8_t *keyToImport = aKey; size_t keySize = aKeyLen; - if (aKeyType == OT_CRYPTO_KEY_TYPE_ECDSA) { - error = extractPrivateKeyFromDer(aPrivateKey, aKey, aKeyLen); + if (aKeyType == OT_CRYPTO_KEY_TYPE_ECDSA) + { + error = extractPrivateKeyFromDer(aPrivateKey, aKey, aKeyLen); keyToImport = aPrivateKey; - keySize = SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE; + keySize = SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE; } - status = sl_sec_man_import_key(aKeyId, getPsaKeyType(aKeyType), getPsaAlgorithm(aKeyAlgorithm), - getPsaKeyUsage(aKeyUsage), getPsaKeyPersistence(aKeyPersistence), - keyToImport, keySize); + status = sl_sec_man_import_key(aKeyId, + getPsaKeyType(aKeyType), + getPsaAlgorithm(aKeyAlgorithm), + getPsaKeyUsage(aKeyUsage), + getPsaKeyPersistence(aKeyPersistence), + keyToImport, + keySize); otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -263,11 +267,12 @@ otError otPlatCryptoAesSetKey(otCryptoContext *aContext, const otCryptoKey *aKey otError otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput) { - otError error = OT_ERROR_NONE; - psa_status_t status; - otCryptoKeyRef * mKeyRef = NULL; + otError error = OT_ERROR_NONE; + psa_status_t status; + otCryptoKeyRef *mKeyRef = NULL; - otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aOutput != NULL) && (aInput != NULL)), error = OT_ERROR_INVALID_ARGS); + otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aOutput != NULL) && (aInput != NULL)), + error = OT_ERROR_INVALID_ARGS); mKeyRef = (otCryptoKeyRef *)aContext->mContext; status = sl_sec_man_aes_encrypt(*mKeyRef, PSA_ALG_ECB_NO_PADDING, aInput, aOutput); @@ -287,7 +292,7 @@ otError otPlatCryptoAesFree(otCryptoContext *aContext) // HMAC implementations otError otPlatCryptoHmacSha256Init(otCryptoContext *aContext) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext; *mMacOperation = psa_mac_operation_init(); return error; @@ -351,16 +356,17 @@ otError otPlatCryptoHmacSha256Finish(otCryptoContext *aContext, uint8_t *aBuf, s // HKDF platform implementations // As the HKDF does not actually use mbedTLS APIs but uses HMAC module, this feature is not implemented. -otError otPlatCryptoHkdfExpand(otCryptoContext * aContext, - const uint8_t * aInfo, - uint16_t aInfoLength, - uint8_t * aOutputKey, - uint16_t aOutputKeyLength) +otError otPlatCryptoHkdfExpand(otCryptoContext *aContext, + const uint8_t *aInfo, + uint16_t aInfoLength, + uint8_t *aOutputKey, + uint16_t aOutputKeyLength) { otError error = OT_ERROR_NONE; psa_status_t status; - otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aInfo != NULL) && (aOutputKey != NULL)), error = OT_ERROR_INVALID_ARGS); + otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aInfo != NULL) && (aOutputKey != NULL)), + error = OT_ERROR_INVALID_ARGS); status = sl_sec_man_key_derivation_expand(aContext->mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength); @@ -370,16 +376,17 @@ otError otPlatCryptoHkdfExpand(otCryptoContext * aContext, return error; } -otError otPlatCryptoHkdfExtract(otCryptoContext * aContext, - const uint8_t * aSalt, +otError otPlatCryptoHkdfExtract(otCryptoContext *aContext, + const uint8_t *aSalt, uint16_t aSaltLength, const otCryptoKey *aKey) { otError error = OT_ERROR_NONE; psa_status_t status; - otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aKey != NULL) && (aSalt != NULL) && (aSaltLength != 0)), - error = OT_ERROR_INVALID_ARGS); + otEXPECT_ACTION( + ((aContext != NULL) && (aContext->mContext != NULL) && (aKey != NULL) && (aSalt != NULL) && (aSaltLength != 0)), + error = OT_ERROR_INVALID_ARGS); status = sl_sec_man_key_derivation_extract(aContext->mContext, PSA_ALG_SHA_256, aKey->mKeyRef, aSalt, aSaltLength); @@ -392,9 +399,9 @@ otError otPlatCryptoHkdfExtract(otCryptoContext * aContext, // SHA256 platform implementations otError otPlatCryptoSha256Init(otCryptoContext *aContext) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS); - psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; + psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS); @@ -406,9 +413,9 @@ otError otPlatCryptoSha256Init(otCryptoContext *aContext) otError otPlatCryptoSha256Deinit(otCryptoContext *aContext) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS); - psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; + psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS); otEXPECT_ACTION((sl_sec_man_hash_deinit(ctx) == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -419,9 +426,9 @@ otError otPlatCryptoSha256Deinit(otCryptoContext *aContext) otError otPlatCryptoSha256Start(otCryptoContext *aContext) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS); - psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; + psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS); otEXPECT_ACTION((sl_sec_man_hash_start(ctx, PSA_ALG_SHA_256) == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -432,9 +439,9 @@ otError otPlatCryptoSha256Start(otCryptoContext *aContext) otError otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS); - psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; + psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; otEXPECT_ACTION(((ctx != NULL) && (aBuf != NULL)), error = OT_ERROR_INVALID_ARGS); otEXPECT_ACTION((sl_sec_man_hash_update(ctx, (uint8_t *)aBuf, aBufLength) == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -445,10 +452,10 @@ otError otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, ui otError otPlatCryptoSha256Finish(otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize) { - otError error = OT_ERROR_NONE; - size_t aHashLength = 0; + otError error = OT_ERROR_NONE; + size_t aHashLength = 0; otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS); - psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; + psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext; otEXPECT_ACTION(((ctx != NULL) && (aHash != NULL)), error = OT_ERROR_INVALID_ARGS); otEXPECT_ACTION((sl_sec_man_hash_finish(ctx, aHash, aHashSize, &aHashLength) == PSA_SUCCESS), @@ -464,12 +471,12 @@ otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef) size_t aKeyLength = 256; psa_status_t status; - status = sl_sec_man_generate_key( &aKeyRef, - PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1), - PSA_ALG_ECDSA(PSA_ALG_ANY_HASH), - (PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH), - PSA_KEY_LIFETIME_PERSISTENT, - aKeyLength); + status = sl_sec_man_generate_key(&aKeyRef, + PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1), + PSA_ALG_ECDSA(PSA_ALG_ANY_HASH), + (PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH), + PSA_KEY_LIFETIME_PERSISTENT, + aKeyLength); otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -485,13 +492,10 @@ otError otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcd uint8_t aByteArray[OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE + 1]; otEXPECT_ACTION((aPublicKey != NULL), error = OT_ERROR_INVALID_ARGS); - + // Use byte array to get the public key because PSA adds a encoding header at the beginning of the array. - //It is easier to export it to a byte array and copy only the public key to output array. - status = sl_sec_man_export_public_key( aKeyRef, - aByteArray, - sizeof(aByteArray), - &aKeyLength); + // It is easier to export it to a byte array and copy only the public key to output array. + status = sl_sec_man_export_public_key(aKeyRef, aByteArray, sizeof(aByteArray), &aKeyLength); memcpy(aPublicKey->m8, &aByteArray[1], OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE); otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -504,21 +508,21 @@ otError otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; size_t aSignatureLength; psa_status_t status; bool aIsHash = true; otEXPECT_ACTION(((aHash != NULL) && (aSignature != NULL)), error = OT_ERROR_INVALID_ARGS); - - status = sl_sec_man_sign( aKeyRef, - PSA_ALG_ECDSA(PSA_ALG_SHA_256), - aHash->m8, - sizeof(aHash->m8), - aSignature->m8, - sizeof(aSignature->m8), - &aSignatureLength, - aIsHash); + + status = sl_sec_man_sign(aKeyRef, + PSA_ALG_ECDSA(PSA_ALG_SHA_256), + aHash->m8, + sizeof(aHash->m8), + aSignature->m8, + sizeof(aSignature->m8), + &aSignatureLength, + aIsHash); otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED); @@ -530,20 +534,20 @@ otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKe const otPlatCryptoSha256Hash *aHash, const otPlatCryptoEcdsaSignature *aSignature) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; psa_status_t status; bool aIsHash = true; otEXPECT_ACTION(((aHash != NULL) && (aSignature != NULL)), error = OT_ERROR_INVALID_ARGS); - //Verify the signature. - status = sl_sec_man_verify( aKeyRef, - PSA_ALG_ECDSA(PSA_ALG_SHA_256), - aHash->m8, - sizeof(aHash->m8), - aSignature->m8, - sizeof(aSignature->m8), - aIsHash); + // Verify the signature. + status = sl_sec_man_verify(aKeyRef, + PSA_ALG_ECDSA(PSA_ALG_SHA_256), + aHash->m8, + sizeof(aHash->m8), + aSignature->m8, + sizeof(aSignature->m8), + aIsHash); otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED); diff --git a/src/gsdk-pal/diag.c b/src/gsdk-pal/diag.c index 9016e725..2b6c9283 100644 --- a/src/gsdk-pal/diag.c +++ b/src/gsdk-pal/diag.c @@ -36,20 +36,20 @@ #include #include -#include "common/code_utils.hpp" -#include "common/logging.hpp" -#include #include +#include +#include #include #include #include -#include +#include "common/code_utils.hpp" +#include "common/logging.hpp" -#include "platform-efr32.h" -#include "platform-band.h" -#include "rail_ieee802154.h" #include "diag.h" #include "em_gpio.h" +#include "platform-band.h" +#include "platform-efr32.h" +#include "rail_ieee802154.h" #include "sl_status.h" @@ -63,14 +63,15 @@ #include "sl_rail_util_ant_div.h" #endif -#define GPIO_PIN_BITMASK 0xFFFFUL -#define GPIO_PORT_BITMASK (0xFFFFUL << 16) -#define GET_GPIO_PIN(x) (x & GPIO_PIN_BITMASK) -#define GET_GPIO_PORT(x) ((x & GPIO_PORT_BITMASK) >> 16) +#define GPIO_PIN_BITMASK 0xFFFFUL +#define GPIO_PORT_BITMASK (0xFFFFUL << 16) +#define GET_GPIO_PIN(x) (x & GPIO_PIN_BITMASK) +#define GET_GPIO_PORT(x) ((x & GPIO_PORT_BITMASK) >> 16) -struct PlatformDiagCommand { - const char *mName; - otError (*mCommand)(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); +struct PlatformDiagCommand +{ + const char *mName; + otError (*mCommand)(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); }; // Diagnostics mode variables. @@ -103,10 +104,13 @@ static otError processAddressMatch(otInstance *aInstance, VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS); - if (strcmp(aArgs[0], "enable") == 0) { - error = otPlatDiagRadioAddressMatch(true); - } else if (strcmp(aArgs[0], "disable") == 0) { - error = otPlatDiagRadioAddressMatch(false); + if (strcmp(aArgs[0], "enable") == 0) + { + error = otPlatDiagRadioAddressMatch(true); + } + else if (strcmp(aArgs[0], "disable") == 0) + { + error = otPlatDiagRadioAddressMatch(false); } exit: @@ -127,10 +131,13 @@ static otError processAutoAck(otInstance *aInstance, VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS); - if (strcmp(aArgs[0], "enable") == 0) { - error = otPlatDiagRadioAutoAck(true); - } else if (strcmp(aArgs[0], "disable") == 0) { - error = otPlatDiagRadioAutoAck(false); + if (strcmp(aArgs[0], "enable") == 0) + { + error = otPlatDiagRadioAutoAck(true); + } + else if (strcmp(aArgs[0], "disable") == 0) + { + error = otPlatDiagRadioAutoAck(false); } exit: @@ -147,10 +154,10 @@ const struct PlatformDiagCommand sCommands[] = { }; otError otPlatDiagProcess(otInstance *aInstance, - uint8_t aArgsLength, - char *aArgs[], - char *aOutput, - size_t aOutputMaxLen) + uint8_t aArgsLength, + char *aArgs[], + char *aOutput, + size_t aOutputMaxLen) { otError error = OT_ERROR_INVALID_COMMAND; size_t i; @@ -159,7 +166,10 @@ otError otPlatDiagProcess(otInstance *aInstance, { if (strcmp(aArgs[0], sCommands[i].mName) == 0) { - error = sCommands[i].mCommand(aInstance, aArgsLength - 1, aArgsLength > 1 ? &aArgs[1] : NULL, aOutput, + error = sCommands[i].mCommand(aInstance, + aArgsLength - 1, + aArgsLength > 1 ? &aArgs[1] : NULL, + aOutput, aOutputMaxLen); break; } @@ -184,47 +194,48 @@ bool otPlatDiagModeGet() static RAIL_Status_t startTxStream(RAIL_StreamMode_t aMode) { - uint16_t txChannel; + uint16_t txChannel; RAIL_Status_t status; SuccessOrExit(status = RAIL_GetChannel(gRailHandle, &txChannel)); #ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT - RAIL_TxOptions_t txOptions = RAIL_TX_OPTIONS_DEFAULT; - // Translate Tx antenna diversity mode into RAIL Tx Antenna options: - // If enabled, use the currently-selected antenna, otherwise leave - // both options 0 so Tx antenna tracks Rx antenna. - if (sl_rail_util_ant_div_get_tx_antenna_mode() != SL_RAIL_UTIL_ANTENNA_MODE_DISABLED) { - txOptions |= ((sl_rail_util_ant_div_get_tx_antenna_selected() == SL_RAIL_UTIL_ANTENNA_SELECT_ANTENNA1) - ? RAIL_TX_OPTION_ANTENNA0 : RAIL_TX_OPTION_ANTENNA1); - } - - status = RAIL_StartTxStreamAlt(gRailHandle, txChannel, aMode, txOptions); -#else // !SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT - status = RAIL_StartTxStream(gRailHandle, txChannel, aMode); -#endif // SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT + RAIL_TxOptions_t txOptions = RAIL_TX_OPTIONS_DEFAULT; + // Translate Tx antenna diversity mode into RAIL Tx Antenna options: + // If enabled, use the currently-selected antenna, otherwise leave + // both options 0 so Tx antenna tracks Rx antenna. + if (sl_rail_util_ant_div_get_tx_antenna_mode() != SL_RAIL_UTIL_ANTENNA_MODE_DISABLED) + { + txOptions |= ((sl_rail_util_ant_div_get_tx_antenna_selected() == SL_RAIL_UTIL_ANTENNA_SELECT_ANTENNA1) + ? RAIL_TX_OPTION_ANTENNA0 + : RAIL_TX_OPTION_ANTENNA1); + } + + status = RAIL_StartTxStreamAlt(gRailHandle, txChannel, aMode, txOptions); +#else // !SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT + status = RAIL_StartTxStream(gRailHandle, txChannel, aMode); +#endif // SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT exit: - return status; + return status; } static RAIL_Status_t stopTxStream(void) { - RAIL_Status_t status; - uint16_t currentChannel; - RAIL_SchedulerInfo_t rxSchedulerInfo = { - .priority = RADIO_SCHEDULER_BACKGROUND_RX_PRIORITY, - }; - - SuccessOrExit(status = RAIL_StopTxStream(gRailHandle)); - // Since start transmit stream turn off the radio state, - // call the RAIL_StartRx to turn on radio - IgnoreError(RAIL_GetChannel(gRailHandle, ¤tChannel)); - assert(RAIL_StartRx(gRailHandle, currentChannel, &rxSchedulerInfo) - == RAIL_STATUS_NO_ERROR); + RAIL_Status_t status; + uint16_t currentChannel; + RAIL_SchedulerInfo_t rxSchedulerInfo = { + .priority = RADIO_SCHEDULER_BACKGROUND_RX_PRIORITY, + }; + + SuccessOrExit(status = RAIL_StopTxStream(gRailHandle)); + // Since start transmit stream turn off the radio state, + // call the RAIL_StartRx to turn on radio + IgnoreError(RAIL_GetChannel(gRailHandle, ¤tChannel)); + assert(RAIL_StartRx(gRailHandle, currentChannel, &rxSchedulerInfo) == RAIL_STATUS_NO_ERROR); exit: - return status; + return status; } otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable) @@ -233,14 +244,17 @@ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable) RAIL_Status_t status; - if (aEnable) { - otLogInfoPlat("Diag CARRIER-WAVE/Tone start"); - status = startTxStream(RAIL_STREAM_CARRIER_WAVE); - } else { - otLogInfoPlat("Diag CARRIER-WAVE/Tone stop"); - status = stopTxStream(); + if (aEnable) + { + otLogInfoPlat("Diag CARRIER-WAVE/Tone start"); + status = startTxStream(RAIL_STREAM_CARRIER_WAVE); } - return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED: OT_ERROR_NONE); + else + { + otLogInfoPlat("Diag CARRIER-WAVE/Tone stop"); + status = stopTxStream(); + } + return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE); } otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable) @@ -251,13 +265,15 @@ otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable) if (aEnable) { - otLogInfoPlat("Diag Stream PN9 start"); - status = startTxStream(RAIL_STREAM_PN9_STREAM); - } else { - otLogInfoPlat("Diag Stream stop"); - status = stopTxStream(); + otLogInfoPlat("Diag Stream PN9 start"); + status = startTxStream(RAIL_STREAM_PN9_STREAM); + } + else + { + otLogInfoPlat("Diag Stream stop"); + status = stopTxStream(); } - return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED: OT_ERROR_NONE); + return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE); } otError otPlatDiagRadioAddressMatch(bool aEnable) @@ -266,9 +282,8 @@ otError otPlatDiagRadioAddressMatch(bool aEnable) otLogInfoPlat("Diag address-match %s", aEnable ? "enable" : "disable"); - status = RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, - !aEnable); - return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED: OT_ERROR_NONE); + status = RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, !aEnable); + return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE); } otError otPlatDiagRadioAutoAck(bool aAutoAckEnabled) @@ -305,8 +320,8 @@ void otPlatDiagAlarmCallback(otInstance *aInstance) static otError getGpioPortAndPin(uint32_t aGpio, uint16_t *aPort, uint16_t *aPin) { otError error = OT_ERROR_NONE; - *aPort = GET_GPIO_PORT(aGpio); - *aPin = GET_GPIO_PIN(aGpio); + *aPort = GET_GPIO_PORT(aGpio); + *aPin = GET_GPIO_PIN(aGpio); if (*aPort > GPIO_PORT_MAX || *aPin > GPIO_PIN_MAX) { @@ -319,7 +334,7 @@ static otError getGpioPortAndPin(uint32_t aGpio, uint16_t *aPort, uint16_t *aPin otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue) { - otError error; + otError error; uint16_t port; uint16_t pin; @@ -334,13 +349,13 @@ otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue) GPIO_PinOutClear((GPIO_Port_TypeDef)port, pin); } - exit: - return error; +exit: + return error; } otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue) { - otError error; + otError error; uint16_t port; uint16_t pin; @@ -354,16 +369,15 @@ otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue) otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode) { - otError error; - uint16_t port; - uint16_t pin; + otError error; + uint16_t port; + uint16_t pin; GPIO_Mode_TypeDef mode; SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin)); mode = (aMode == OT_GPIO_MODE_INPUT) ? gpioModeInput : gpioModePushPull; - GPIO_PinModeSet((GPIO_Port_TypeDef)port, pin, mode, 0 /*out*/); exit: @@ -372,19 +386,18 @@ otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode) otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode) { - otError error; - uint16_t port; - uint16_t pin; + otError error; + uint16_t port; + uint16_t pin; GPIO_Mode_TypeDef mode; SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin)); - mode = GPIO_PinModeGet((GPIO_Port_TypeDef) port, pin); + mode = GPIO_PinModeGet((GPIO_Port_TypeDef)port, pin); *aMode = (mode == gpioModeInput) ? OT_GPIO_MODE_INPUT : OT_GPIO_MODE_OUTPUT; exit: return error; - } #endif // OPENTHREAD_CONFIG_DIAG_ENABLE diff --git a/src/gsdk-pal/entropy.c b/src/gsdk-pal/entropy.c index b2f5768e..b5c66bc0 100644 --- a/src/gsdk-pal/entropy.c +++ b/src/gsdk-pal/entropy.c @@ -34,29 +34,29 @@ #include "security_manager.h" #include +#include #include #include "utils/code_utils.h" -#include #if OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA void otPlatCryptoRandomInit(void) - { - //Security manager is initialised by OT stack, in key_manager. - //But Random manager is initialised much before this, so we - //initialise security manager here. Later initialisation by - //stack is ignored by security manager. +{ + // Security manager is initialised by OT stack, in key_manager. + // But Random manager is initialised much before this, so we + // initialise security manager here. Later initialisation by + // stack is ignored by security manager. - (void) sl_sec_man_init(); - } + (void)sl_sec_man_init(); +} - void otPlatCryptoRandomDeinit(void) - { - //Intentionally left blank, nothing to deinit - } +void otPlatCryptoRandomDeinit(void) +{ + // Intentionally left blank, nothing to deinit +} - otError otPlatCryptoRandomGet(uint8_t *aBuffer, uint16_t aSize) - { - otError error = OT_ERROR_NONE; +otError otPlatCryptoRandomGet(uint8_t *aBuffer, uint16_t aSize) +{ + otError error = OT_ERROR_NONE; psa_status_t status; status = sl_sec_man_get_random(aBuffer, aSize); @@ -65,15 +65,12 @@ void otPlatCryptoRandomInit(void) exit: return error; - } +} #else // The mbedtls_hardware_poll() function is meant for internal use by Mbed TLS // and is not declared in any external header files. We will therefore declare // it as an extern function here. -extern int mbedtls_hardware_poll(void *data, - unsigned char *output, - size_t len, - size_t *olen); +extern int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen); otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) { diff --git a/src/gsdk-pal/flash.c b/src/gsdk-pal/flash.c index d84e9d9c..8354159a 100644 --- a/src/gsdk-pal/flash.c +++ b/src/gsdk-pal/flash.c @@ -39,9 +39,9 @@ #if OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE // Use OT NV system +#include "em_msc.h" #include #include -#include "em_msc.h" #define FLASH_PAGE_NUM 2 #define FLASH_DATA_END_ADDR (FLASH_BASE + FLASH_SIZE) @@ -103,16 +103,16 @@ void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset #elif defined(SL_CATALOG_NVM3_PRESENT) // Defaults to Silabs nvm3 system +#include "nvm3_default.h" +#include #include #include "common/code_utils.hpp" #include "common/logging.hpp" -#include "nvm3_default.h" -#include -#define NVM3KEY_DOMAIN_OPENTHREAD 0x20000U +#define NVM3KEY_DOMAIN_OPENTHREAD 0x20000U #define NUM_INDEXED_SETTINGS \ OPENTHREAD_CONFIG_MLE_MAX_CHILDREN // Indexed key types are only supported for kKeyChildInfo (=='child table'). -#define ENUM_NVM3_KEY_LIST_SIZE 4 // List size used when enumerating nvm3 keys. +#define ENUM_NVM3_KEY_LIST_SIZE 4 // List size used when enumerating nvm3 keys. static otError addSetting(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); static nvm3_ObjectKey_t makeNvm3ObjKey(uint16_t otSettingsKey, int index); @@ -126,13 +126,18 @@ void otPlatSettingsInit(otInstance *aInstance, const uint16_t *aSensitiveKeys, u OT_UNUSED_VARIABLE(aSensitiveKeysLength); // Only call nmv3_open if it has not been opened yet. - if (nvm3_defaultHandle->hasBeenOpened) { + if (nvm3_defaultHandle->hasBeenOpened) + { nvmOpenedByOT = false; // OT is not allowed to close NVM - } else { + } + else + { if (mapNvm3Error(nvm3_open(nvm3_defaultHandle, nvm3_defaultInit)) != OT_ERROR_NONE) { otLogDebgPlat("Error initializing nvm3 instance"); - } else { + } + else + { nvmOpenedByOT = true; } } @@ -141,7 +146,8 @@ void otPlatSettingsInit(otInstance *aInstance, const uint16_t *aSensitiveKeys, u void otPlatSettingsDeinit(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - if (nvmOpenedByOT && nvm3_defaultHandle->hasBeenOpened) { + if (nvmOpenedByOT && nvm3_defaultHandle->hasBeenOpened) + { nvm3_close(nvm3_defaultHandle); nvmOpenedByOT = false; } @@ -167,7 +173,10 @@ otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint { // Get the next nvm3 key list. nvm3_ObjectKey_t keys[ENUM_NVM3_KEY_LIST_SIZE]; // List holds the next set of nvm3 keys. - size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle, keys, ENUM_NVM3_KEY_LIST_SIZE, nvm3Key, + size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle, + keys, + ENUM_NVM3_KEY_LIST_SIZE, + nvm3Key, makeNvm3ObjKey(aKey, NUM_INDEXED_SETTINGS)); for (size_t i = 0; i < objCnt; ++i) { @@ -252,7 +261,7 @@ otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) OT_UNUSED_VARIABLE(aInstance); - otError err; + otError err; nvm3_ObjectKey_t nvm3Key = makeNvm3ObjKey(aKey, 0); // The base nvm3 key value. bool idxFound = false; int idx = 0; @@ -261,7 +270,10 @@ otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) { // Get the next nvm3 key list. nvm3_ObjectKey_t keys[ENUM_NVM3_KEY_LIST_SIZE]; // List holds the next set of nvm3 keys. - size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle, keys, ENUM_NVM3_KEY_LIST_SIZE, nvm3Key, + size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle, + keys, + ENUM_NVM3_KEY_LIST_SIZE, + nvm3Key, makeNvm3ObjKey(aKey, NUM_INDEXED_SETTINGS)); for (size_t i = 0; i < objCnt; ++i) { @@ -375,4 +387,4 @@ static otError mapNvm3Error(Ecode_t nvm3Res) return err; } -#endif // OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE \ No newline at end of file +#endif // OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE diff --git a/src/gsdk-pal/ieee802154-packet-utils.cpp b/src/gsdk-pal/ieee802154-packet-utils.cpp index 63c1ab1f..4f716e88 100644 --- a/src/gsdk-pal/ieee802154-packet-utils.cpp +++ b/src/gsdk-pal/ieee802154-packet-utils.cpp @@ -32,27 +32,27 @@ * */ -#include "em_device.h" +#include "ieee802154-packet-utils.hpp" #include "em_chip.h" #include "em_core.h" -#include "sli_protocol_crypto.h" +#include "em_device.h" #include "sl_packet_utils.h" -#include "ieee802154-packet-utils.hpp" +#include "sli_protocol_crypto.h" #include -#include "mac/mac_frame.hpp" #include "common/code_utils.hpp" #include "common/debug.hpp" #include "crypto/aes_ccm.hpp" +#include "mac/mac_frame.hpp" using namespace ot; using namespace Crypto; -void TxSecurityProcessing::Init(uint32_t aHeaderLength, - uint32_t aPlainTextLength, - uint8_t aTagLength, - const void *aNonce, - uint8_t aNonceLength) +void TxSecurityProcessing::Init(uint32_t aHeaderLength, + uint32_t aPlainTextLength, + uint8_t aTagLength, + const void *aNonce, + uint8_t aNonceLength) { const uint8_t *nonceBytes = reinterpret_cast(aNonce); uint8_t blockLength = 0; @@ -61,7 +61,8 @@ void TxSecurityProcessing::Init(uint32_t aHeaderLength, uint8_t i; // Tag length must be even and within [kMinTagLength, kMaxTagLength] - OT_ASSERT(((aTagLength & 0x1) == 0) && (Crypto::AesCcm::kMinTagLength <= aTagLength) && (aTagLength <= Crypto::AesCcm::kMaxTagLength)); + OT_ASSERT(((aTagLength & 0x1) == 0) && (Crypto::AesCcm::kMinTagLength <= aTagLength) + && (aTagLength <= Crypto::AesCcm::kMaxTagLength)); L = 0; @@ -95,8 +96,8 @@ void TxSecurityProcessing::Init(uint32_t aHeaderLength, // setup initial block // write flags - mBlock[0] = (static_cast((aHeaderLength != 0) << 6) | static_cast(((aTagLength - 2) >> 1) << 3) | - static_cast(L - 1)); + mBlock[0] = (static_cast((aHeaderLength != 0) << 6) | static_cast(((aTagLength - 2) >> 1) << 3) + | static_cast(L - 1)); // write nonce memcpy(&mBlock[1], nonceBytes, aNonceLength); @@ -111,11 +112,7 @@ void TxSecurityProcessing::Init(uint32_t aHeaderLength, } // encrypt initial block - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mBlock, - mBlock); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock); // process header if (aHeaderLength > 0) @@ -163,11 +160,7 @@ void TxSecurityProcessing::Header(const void *aHeader, uint32_t aHeaderLength) { if (mBlockLength == sizeof(mBlock)) { - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mBlock, - mBlock); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock); mBlockLength = 0; } @@ -182,11 +175,7 @@ void TxSecurityProcessing::Header(const void *aHeader, uint32_t aHeaderLength) // process remainder if (mBlockLength != 0) { - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mBlock, - mBlock); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock); } mBlockLength = 0; @@ -213,11 +202,7 @@ void TxSecurityProcessing::Payload(void *aPlainText, void *aCipherText, uint32_t } } - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mCtr, - mCtrPad); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mCtr, mCtrPad); mCtrLength = 0; } @@ -227,11 +212,7 @@ void TxSecurityProcessing::Payload(void *aPlainText, void *aCipherText, uint32_t if (mBlockLength == sizeof(mBlock)) { - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mBlock, - mBlock); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock); mBlockLength = 0; } @@ -245,11 +226,7 @@ void TxSecurityProcessing::Payload(void *aPlainText, void *aCipherText, uint32_t { if (mBlockLength != 0) { - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mBlock, - mBlock); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock); } // reset counter @@ -263,11 +240,7 @@ void TxSecurityProcessing::Finalize(void *aTag) OT_ASSERT(mPlainTextCur == mPlainTextLength); - sli_aes_crypt_ecb_radio(true, - mKey, - kKeyBits, - mCtr, - mCtrPad); + sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mCtr, mCtrPad); for (int i = 0; i < mTagLength; i++) { @@ -281,11 +254,11 @@ void efr32PlatProcessTransmitAesCcm(otRadioFrame *aFrame, const otExtAddress *aE OT_UNUSED_VARIABLE(aFrame); OT_UNUSED_VARIABLE(aExtAddress); #else - uint32_t frameCounter = 0; - uint8_t tagLength; - uint8_t securityLevel; - uint8_t nonce[Crypto::AesCcm::kNonceSize]; - Mac::TxFrame *aTxFrame = static_cast(aFrame); + uint32_t frameCounter = 0; + uint8_t tagLength; + uint8_t securityLevel; + uint8_t nonce[Crypto::AesCcm::kNonceSize]; + Mac::TxFrame *aTxFrame = static_cast(aFrame); TxSecurityProcessing packetSecurityHandler; VerifyOrExit(aTxFrame->GetSecurityEnabled()); @@ -293,12 +266,19 @@ void efr32PlatProcessTransmitAesCcm(otRadioFrame *aFrame, const otExtAddress *aE SuccessOrExit(aTxFrame->GetSecurityLevel(securityLevel)); SuccessOrExit(aTxFrame->GetFrameCounter(frameCounter)); - Crypto::AesCcm::GenerateNonce(*static_cast(aExtAddress), frameCounter, securityLevel, nonce); + Crypto::AesCcm::GenerateNonce(*static_cast(aExtAddress), + frameCounter, + securityLevel, + nonce); tagLength = aTxFrame->GetFooterLength() - aTxFrame->GetFcsSize(); packetSecurityHandler.SetKey(aFrame->mInfo.mTxInfo.mAesKey->mKeyMaterial.mKey.m8); - packetSecurityHandler.Init(aTxFrame->GetHeaderLength(), aTxFrame->GetPayloadLength(), tagLength, nonce, sizeof(nonce)); + packetSecurityHandler.Init(aTxFrame->GetHeaderLength(), + aTxFrame->GetPayloadLength(), + tagLength, + nonce, + sizeof(nonce)); packetSecurityHandler.Header(aTxFrame->GetHeader(), aTxFrame->GetHeaderLength()); packetSecurityHandler.Payload(aTxFrame->GetPayload(), aTxFrame->GetPayload(), aTxFrame->GetPayloadLength()); packetSecurityHandler.Finalize(aTxFrame->GetFooter()); @@ -319,7 +299,7 @@ otPanId efr32GetDstPanId(otRadioFrame *aFrame) { otPanId aPanId = 0xFFFF; - if(static_cast(aFrame)->IsDstPanIdPresent()) + if (static_cast(aFrame)->IsDstPanIdPresent()) { static_cast(aFrame)->GetDstPanId(aPanId); } @@ -327,7 +307,7 @@ otPanId efr32GetDstPanId(otRadioFrame *aFrame) return aPanId; } -uint8_t* efr32GetPayload(otRadioFrame *aFrame) +uint8_t *efr32GetPayload(otRadioFrame *aFrame) { uint8_t *payload = static_cast(aFrame)->GetPayload(); return payload; diff --git a/src/gsdk-pal/ieee802154-packet-utils.hpp b/src/gsdk-pal/ieee802154-packet-utils.hpp index 164c8f68..238b856e 100644 --- a/src/gsdk-pal/ieee802154-packet-utils.hpp +++ b/src/gsdk-pal/ieee802154-packet-utils.hpp @@ -53,7 +53,7 @@ class TxSecurityProcessing enum { kBlockSize = 16, ///< AES-128 block size (bytes). - kKeyBits = 128 + kKeyBits = 128 }; /** @@ -62,7 +62,7 @@ class TxSecurityProcessing * @param[in] aKey Pointer to the AES Key to use. * */ - void SetKey(const uint8_t* aKey) { mKey = aKey; } + void SetKey(const uint8_t *aKey) { mKey = aKey; } /** * This method initializes the AES CCM computation. @@ -74,12 +74,11 @@ class TxSecurityProcessing * @param[in] aNonceLength Length of nonce in bytes. * */ - void Init( uint32_t aHeaderLength, - uint32_t aPlainTextLength, - uint8_t aTagLength, - const void *aNonce, - uint8_t aNonceLength); - + void Init(uint32_t aHeaderLength, + uint32_t aPlainTextLength, + uint8_t aTagLength, + const void *aNonce, + uint8_t aNonceLength); /** * This method processes the header. @@ -118,18 +117,18 @@ class TxSecurityProcessing void Finalize(void *aTag); private: - uint8_t mBlock[kBlockSize]; - uint8_t mCtr[kBlockSize]; - uint8_t mCtrPad[kBlockSize]; - const uint8_t* mKey; - uint32_t mHeaderLength; - uint32_t mHeaderCur; - uint32_t mPlainTextLength; - uint32_t mPlainTextCur; - uint16_t mBlockLength; - uint16_t mCtrLength; - uint8_t mNonceLength; - uint8_t mTagLength; + uint8_t mBlock[kBlockSize]; + uint8_t mCtr[kBlockSize]; + uint8_t mCtrPad[kBlockSize]; + const uint8_t *mKey; + uint32_t mHeaderLength; + uint32_t mHeaderCur; + uint32_t mPlainTextLength; + uint32_t mPlainTextCur; + uint16_t mBlockLength; + uint16_t mCtrLength; + uint8_t mNonceLength; + uint8_t mTagLength; }; /** @@ -137,4 +136,4 @@ class TxSecurityProcessing * */ -#endif // IEEE802154_PACKET_UTILS_HPP_ \ No newline at end of file +#endif // IEEE802154_PACKET_UTILS_HPP_ diff --git a/src/gsdk-pal/ieee802154mac.h b/src/gsdk-pal/ieee802154mac.h index ba34227f..4bbf6dc8 100644 --- a/src/gsdk-pal/ieee802154mac.h +++ b/src/gsdk-pal/ieee802154mac.h @@ -35,127 +35,128 @@ #ifndef __IEEE802154IEEE802154_H__ #define __IEEE802154IEEE802154_H__ -#define IEEE802154_MIN_LENGTH 4 // Technically, a version 2 packet / ACK - // can be 4 bytes with seq# suppression -#define IEEE802154_MAX_LENGTH 127 -#define IEEE802154_MIN_DATA_LENGTH 5 +#define IEEE802154_MIN_LENGTH \ + 4 // Technically, a version 2 packet / ACK + // can be 4 bytes with seq# suppression +#define IEEE802154_MAX_LENGTH 127 +#define IEEE802154_MIN_DATA_LENGTH 5 // FCF + DSN + dest PANID + dest addr + src PANID + src addr (without security header) -#define IEEE802154_MAX_MHR_LENGTH (2 + 1 + 2 + 8 + 2 + 8) +#define IEEE802154_MAX_MHR_LENGTH (2 + 1 + 2 + 8 + 2 + 8) -#define IEEE802154_DSN_OFFSET 2 -#define IEEE802154_FCF_OFFSET 0 +#define IEEE802154_DSN_OFFSET 2 +#define IEEE802154_FCF_OFFSET 0 //------------------------------------------------------------------------ // 802.15.4 Frame Control Field definitions for Beacon, Ack, Data, Command -#define IEEE802154_FRAME_TYPE_BEACON ((uint16_t)0x0000U) // Beacon -#define IEEE802154_FRAME_TYPE_DATA ((uint16_t)0x0001U) // Data -#define IEEE802154_FRAME_TYPE_ACK ((uint16_t)0x0002U) // ACK -#define IEEE802154_FRAME_TYPE_COMMAND ((uint16_t)0x0003U) // Command -#define IEEE802154_FRAME_TYPE_CONTROL IEEE802154_FRAME_TYPE_COMMAND // (synonym) +#define IEEE802154_FRAME_TYPE_BEACON ((uint16_t)0x0000U) // Beacon +#define IEEE802154_FRAME_TYPE_DATA ((uint16_t)0x0001U) // Data +#define IEEE802154_FRAME_TYPE_ACK ((uint16_t)0x0002U) // ACK +#define IEEE802154_FRAME_TYPE_COMMAND ((uint16_t)0x0003U) // Command +#define IEEE802154_FRAME_TYPE_CONTROL IEEE802154_FRAME_TYPE_COMMAND // (synonym) // 802.15.4E-2012 introduced MultiPurpose with different Frame Control Field // layout described in the MultiPurpose section below. -#define IEEE802154_FRAME_TYPE_MULTIPURPOSE ((uint16_t)0x0005U) // MultiPurpose -#define IEEE802154_FRAME_TYPE_RESERVED_1 ((uint16_t)0x0004U) -#define IEEE802154_FRAME_TYPE_RESERVED_2 ((uint16_t)0x0006U) -#define IEEE802154_FRAME_TYPE_RESERVED_3 ((uint16_t)0x0007U) -#define IEEE802154_FRAME_TYPE_MASK ((uint16_t)0x0007U) // Bits 0..2 +#define IEEE802154_FRAME_TYPE_MULTIPURPOSE ((uint16_t)0x0005U) // MultiPurpose +#define IEEE802154_FRAME_TYPE_RESERVED_1 ((uint16_t)0x0004U) +#define IEEE802154_FRAME_TYPE_RESERVED_2 ((uint16_t)0x0006U) +#define IEEE802154_FRAME_TYPE_RESERVED_3 ((uint16_t)0x0007U) +#define IEEE802154_FRAME_TYPE_MASK ((uint16_t)0x0007U) // Bits 0..2 // Use a reserved flag internally to check whether outgoing enh-ACK was secure -#define IEEE802154_SECURED_OUTGOING_ENHANCED_ACK IEEE802154_FRAME_TYPE_RESERVED_1 +#define IEEE802154_SECURED_OUTGOING_ENHANCED_ACK IEEE802154_FRAME_TYPE_RESERVED_1 -#define IEEE802154_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0008U) // Bit 3 -#define IEEE802154_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0010U) // Bit 4 -#define IEEE802154_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x0020U) // Bit 5 -#define IEEE802154_FRAME_FLAG_INTRA_PAN ((uint16_t)0x0040U) // Bit 6 +#define IEEE802154_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0008U) // Bit 3 +#define IEEE802154_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0010U) // Bit 4 +#define IEEE802154_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x0020U) // Bit 5 +#define IEEE802154_FRAME_FLAG_INTRA_PAN ((uint16_t)0x0040U) // Bit 6 // 802.15.4-2006 renamed the Intra-Pan flag PanId-Compression -#define IEEE802154_FRAME_FLAG_PANID_COMPRESSION IEEE802154_FRAME_FLAG_INTRA_PAN -#define IEEE802154_FRAME_FLAG_RESERVED ((uint16_t)0x0080U) // Bit 7 reserved +#define IEEE802154_FRAME_FLAG_PANID_COMPRESSION IEEE802154_FRAME_FLAG_INTRA_PAN +#define IEEE802154_FRAME_FLAG_RESERVED ((uint16_t)0x0080U) // Bit 7 reserved // Use the reserved flag internally to check whether frame pending bit was set in outgoing ACK -#define IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK IEEE802154_FRAME_FLAG_RESERVED +#define IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK IEEE802154_FRAME_FLAG_RESERVED // 802.15.4E-2012 introduced these flags for Frame Version 2 frames // which are reserved bit positions in earlier Frame Version frames: -#define IEEE802154_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0100U) // Bit 8 -#define IEEE802154_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x0200U) // Bit 9 - -#define IEEE802154_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0C00U) // Bits 10..11 -#define IEEE802154_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0 -#define IEEE802154_FRAME_DESTINATION_MODE_RESERVED ((uint16_t)0x0400U) // Mode 1 -#define IEEE802154_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0800U) // Mode 2 -#define IEEE802154_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0C00U) // Mode 3 +#define IEEE802154_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0100U) // Bit 8 +#define IEEE802154_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x0200U) // Bit 9 + +#define IEEE802154_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0C00U) // Bits 10..11 +#define IEEE802154_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0 +#define IEEE802154_FRAME_DESTINATION_MODE_RESERVED ((uint16_t)0x0400U) // Mode 1 +#define IEEE802154_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0800U) // Mode 2 +#define IEEE802154_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0C00U) // Mode 3 // 802.15.4e-2012 only (not adopted into 802.15.4-2015) -#define IEEE802154_FRAME_DESTINATION_MODE_BYTE IEEE802154_FRAME_DESTINATION_MODE_RESERVED +#define IEEE802154_FRAME_DESTINATION_MODE_BYTE IEEE802154_FRAME_DESTINATION_MODE_RESERVED -#define IEEE802154_FRAME_VERSION_MASK ((uint16_t)0x3000U) // Bits 12..13 -#define IEEE802154_FRAME_VERSION_2003 ((uint16_t)0x0000U) // Version 0 -#define IEEE802154_FRAME_VERSION_2006 ((uint16_t)0x1000U) // Version 1 +#define IEEE802154_FRAME_VERSION_MASK ((uint16_t)0x3000U) // Bits 12..13 +#define IEEE802154_FRAME_VERSION_2003 ((uint16_t)0x0000U) // Version 0 +#define IEEE802154_FRAME_VERSION_2006 ((uint16_t)0x1000U) // Version 1 // In 802.15.4-2015, Version 2 is just called "IEEE STD 802.15.4" // which can be rather confusing. It was introduced in 802.15.4E-2012. -#define IEEE802154_FRAME_VERSION_2012 ((uint16_t)0x2000U) // Version 2 -#define IEEE802154_FRAME_VERSION_2015 ((uint16_t)0x2000U) // Version 2 -#define IEEE802154_FRAME_VERSION_RESERVED ((uint16_t)0x3000U) // Version 3 - -#define IEEE802154_FRAME_SOURCE_MODE_MASK ((uint16_t)0xC000U) // Bits 14..15 -#define IEEE802154_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0 -#define IEEE802154_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x4000U) // Mode 1 -#define IEEE802154_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x8000U) // Mode 2 -#define IEEE802154_FRAME_SOURCE_MODE_LONG ((uint16_t)0xC000U) // Mode 3 +#define IEEE802154_FRAME_VERSION_2012 ((uint16_t)0x2000U) // Version 2 +#define IEEE802154_FRAME_VERSION_2015 ((uint16_t)0x2000U) // Version 2 +#define IEEE802154_FRAME_VERSION_RESERVED ((uint16_t)0x3000U) // Version 3 + +#define IEEE802154_FRAME_SOURCE_MODE_MASK ((uint16_t)0xC000U) // Bits 14..15 +#define IEEE802154_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0 +#define IEEE802154_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x4000U) // Mode 1 +#define IEEE802154_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x8000U) // Mode 2 +#define IEEE802154_FRAME_SOURCE_MODE_LONG ((uint16_t)0xC000U) // Mode 3 // 802.15.4e-2012 only (not adopted into 802.15.4-2015) -#define IEEE802154_FRAME_SOURCE_MODE_BYTE IEEE802154_FRAME_SOURCE_MODE_RESERVED +#define IEEE802154_FRAME_SOURCE_MODE_BYTE IEEE802154_FRAME_SOURCE_MODE_RESERVED //------------------------------------------------------------------------ // 802.15.4E-2012 Frame Control Field definitions for MultiPurpose -#define IEEE802154_MP_FRAME_TYPE_MASK IEEE802154_FRAME_TYPE_MASK // Bits 0..2 -#define IEEE802154_MP_FRAME_TYPE_MULTIPURPOSE IEEE802154_FRAME_TYPE_MULTIPURPOSE +#define IEEE802154_MP_FRAME_TYPE_MASK IEEE802154_FRAME_TYPE_MASK // Bits 0..2 +#define IEEE802154_MP_FRAME_TYPE_MULTIPURPOSE IEEE802154_FRAME_TYPE_MULTIPURPOSE -#define IEEE802154_MP_FRAME_FLAG_LONG_FCF ((uint16_t)0x0008U) // Bit 3 +#define IEEE802154_MP_FRAME_FLAG_LONG_FCF ((uint16_t)0x0008U) // Bit 3 -#define IEEE802154_MP_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0030U) // Bits 4..5 -#define IEEE802154_MP_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0 +#define IEEE802154_MP_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0030U) // Bits 4..5 +#define IEEE802154_MP_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0 #define IEEE802154_MP_FRAME_DESTINATION_MODE_RESERVED ((uint16_t)0x0010U) // Mode 1 -#define IEEE802154_MP_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0020U) // Mode 2 -#define IEEE802154_MP_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0030U) // Mode 3 +#define IEEE802154_MP_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0020U) // Mode 2 +#define IEEE802154_MP_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0030U) // Mode 3 // 802.15.4e-2012 only (not adopted into 802.15.4-2015) -#define IEEE802154_MP_FRAME_DESTINATION_MODE_BYTE IEEE802154_MP_FRAME_DESTINATION_MODE_RESERVED +#define IEEE802154_MP_FRAME_DESTINATION_MODE_BYTE IEEE802154_MP_FRAME_DESTINATION_MODE_RESERVED -#define IEEE802154_MP_FRAME_SOURCE_MODE_MASK ((uint16_t)0x00C0U) // Bits 6..7 -#define IEEE802154_MP_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0 -#define IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x0040U) // Mode 1 -#define IEEE802154_MP_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x0080U) // Mode 2 -#define IEEE802154_MP_FRAME_SOURCE_MODE_LONG ((uint16_t)0x00C0U) // Mode 3 +#define IEEE802154_MP_FRAME_SOURCE_MODE_MASK ((uint16_t)0x00C0U) // Bits 6..7 +#define IEEE802154_MP_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0 +#define IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x0040U) // Mode 1 +#define IEEE802154_MP_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x0080U) // Mode 2 +#define IEEE802154_MP_FRAME_SOURCE_MODE_LONG ((uint16_t)0x00C0U) // Mode 3 // 802.15.4e-2012 only (not adopted into 802.15.4-2015) -#define IEEE802154_MP_FRAME_SOURCE_MODE_BYTE IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED +#define IEEE802154_MP_FRAME_SOURCE_MODE_BYTE IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED -#define IEEE802154_MP_FRAME_FLAG_PANID_PRESENT ((uint16_t)0x0100U) // Bit 8 -#define IEEE802154_MP_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0200U) // Bit 9 -#define IEEE802154_MP_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0400U) // Bit 10 -#define IEEE802154_MP_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0800U) // Bit 11 +#define IEEE802154_MP_FRAME_FLAG_PANID_PRESENT ((uint16_t)0x0100U) // Bit 8 +#define IEEE802154_MP_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0200U) // Bit 9 +#define IEEE802154_MP_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0400U) // Bit 10 +#define IEEE802154_MP_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0800U) // Bit 11 -#define IEEE802154_MP_FRAME_VERSION_MASK IEEE802154_FRAME_VERSION_MASK // Bits 12..13 -#define IEEE802154_MP_FRAME_VERSION_2012 ((uint16_t)0x0000U) // Zeroed out -#define IEEE802154_MP_FRAME_VERSION_2015 ((uint16_t)0x0000U) // Zeroed out +#define IEEE802154_MP_FRAME_VERSION_MASK IEEE802154_FRAME_VERSION_MASK // Bits 12..13 +#define IEEE802154_MP_FRAME_VERSION_2012 ((uint16_t)0x0000U) // Zeroed out +#define IEEE802154_MP_FRAME_VERSION_2015 ((uint16_t)0x0000U) // Zeroed out // All other MultiPurpose Frame Versions are reserved -#define IEEE802154_MP_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x4000U) // Bit 14 -#define IEEE802154_MP_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x8000U) // Bit 15 +#define IEEE802154_MP_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x4000U) // Bit 14 +#define IEEE802154_MP_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x8000U) // Bit 15 //------------------------------------------------------------------------ // Information Elements fields -#define IEEE802154_KEYID_MODE_0 ((uint8_t)0x0000U) -#define IEEE802154_KEYID_MODE_0_SIZE 0 +#define IEEE802154_KEYID_MODE_0 ((uint8_t)0x0000U) +#define IEEE802154_KEYID_MODE_0_SIZE 0 -#define IEEE802154_KEYID_MODE_1 ((uint8_t)0x0008U) -#define IEEE802154_KEYID_MODE_1_SIZE 0 +#define IEEE802154_KEYID_MODE_1 ((uint8_t)0x0008U) +#define IEEE802154_KEYID_MODE_1_SIZE 0 -#define IEEE802154_KEYID_MODE_2 ((uint8_t)0x0010U) -#define IEEE802154_KEYID_MODE_2_SIZE 4 +#define IEEE802154_KEYID_MODE_2 ((uint8_t)0x0010U) +#define IEEE802154_KEYID_MODE_2_SIZE 4 -#define IEEE802154_KEYID_MODE_3 ((uint8_t)0x0018U) -#define IEEE802154_KEYID_MODE_3_SIZE 8 +#define IEEE802154_KEYID_MODE_3 ((uint8_t)0x0018U) +#define IEEE802154_KEYID_MODE_3_SIZE 8 -#define IEEE802154_KEYID_MODE_MASK ((uint8_t)0x0018U) +#define IEEE802154_KEYID_MODE_MASK ((uint8_t)0x0018U) //------------------------------------------------------------------------ // Information Elements fields @@ -171,21 +172,21 @@ // IE is seen. #define IEEE802154_FRAME_HEADER_INFO_ELEMENT_LENGTH_MASK 0x007F // bits 0-6 -#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_ID_MASK 0x7F80 // bits 7-14 -#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15 +#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_ID_MASK 0x7F80 // bits 7-14 +#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15 #define IEEE802154_FRAME_HEADER_INFO_ELEMENT_ID_SHIFT 7 -#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_LENGTH_MASK 0x07FF // bits 0 -10 -#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_GROUP_ID_MASK 0x7800 // bits 11-14 -#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15 +#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_LENGTH_MASK 0x07FF // bits 0 -10 +#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_GROUP_ID_MASK 0x7800 // bits 11-14 +#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15 -#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_ID_SHIFT 11 +#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_ID_SHIFT 11 // This "type" field indicates header vs. payload IE. However there is // also a Header IE List terminator which would imply the IE list // that follows is only payload IEs. -#define IEEE802154_FRAME_INFO_ELEMENT_TYPE_MASK 0x8000 +#define IEEE802154_FRAME_INFO_ELEMENT_TYPE_MASK 0x8000 // Header Termination ID 1 is used when there are Payload IEs that follow. // Header Termination ID 2 is used when there are no Payload IEs and the diff --git a/src/gsdk-pal/iostream_uart.c b/src/gsdk-pal/iostream_uart.c index 9b806f48..0f12980d 100644 --- a/src/gsdk-pal/iostream_uart.c +++ b/src/gsdk-pal/iostream_uart.c @@ -37,9 +37,9 @@ #include "sl_component_catalog.h" #endif // SL_COMPONENT_CATALOG_PRESENT +#include "openthread-system.h" #include #include -#include "openthread-system.h" #include "utils/code_utils.h" #include "utils/uart.h" @@ -53,30 +53,31 @@ #define RECEIVE_BUFFER_SIZE 128 -static uint8_t sReceiveBuffer[RECEIVE_BUFFER_SIZE]; -static const uint8_t * sTransmitBuffer = NULL; -static volatile uint16_t sTransmitLength = 0; +static uint8_t sReceiveBuffer[RECEIVE_BUFFER_SIZE]; +static const uint8_t *sTransmitBuffer = NULL; +static volatile uint16_t sTransmitLength = 0; #ifdef SL_CATALOG_KERNEL_PRESENT -static unsigned int sGpioIntContext = 0; +static unsigned int sGpioIntContext = 0; static void gpioSerialWakeupCallback(uint8_t interrupt_no, void *context) { - unsigned int *pin = (unsigned int *)context; + unsigned int *pin = (unsigned int *)context; - (void)interrupt_no; + (void)interrupt_no; - if (*pin == SL_IOSTREAM_USART_VCOM_RX_PIN) { - otSysEventSignalPending(); - } + if (*pin == SL_IOSTREAM_USART_VCOM_RX_PIN) + { + otSysEventSignalPending(); + } } #endif // SL_CATALOG_KERNEL_PRESENT static void processReceive(void) { sl_status_t status; - size_t bytes_read = 0; + size_t bytes_read = 0; memset(sReceiveBuffer, 0, RECEIVE_BUFFER_SIZE); #ifdef SL_CATALOG_KERNEL_PRESENT @@ -86,7 +87,8 @@ static void processReceive(void) status = sl_iostream_read(sl_iostream_vcom_handle, &sReceiveBuffer, sizeof(sReceiveBuffer), &bytes_read); - if (status == SL_STATUS_OK) { + if (status == SL_STATUS_OK) + { otPlatUartReceived(sReceiveBuffer, bytes_read); } } @@ -125,12 +127,10 @@ otError otPlatUartEnable(void) otEXPECT_ACTION(intNo != INTERRUPT_UNAVAILABLE, error = OT_ERROR_FAILED); - GPIO_ExtIntConfig(SL_IOSTREAM_USART_VCOM_RX_PORT, - SL_IOSTREAM_USART_VCOM_RX_PIN, - intNo, false, true, true); + GPIO_ExtIntConfig(SL_IOSTREAM_USART_VCOM_RX_PORT, SL_IOSTREAM_USART_VCOM_RX_PIN, intNo, false, true, true); #endif -exit: +exit: return error; } @@ -148,7 +148,7 @@ OT_TOOL_WEAK void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; sl_status_t status; otEXPECT_ACTION(sTransmitBuffer == NULL, error = OT_ERROR_BUSY); @@ -157,7 +157,8 @@ otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) sTransmitLength = aBufLength; status = sl_iostream_write(sl_iostream_vcom_handle, (uint8_t *)sTransmitBuffer, sTransmitLength); - if (status == SL_STATUS_OK) { + if (status == SL_STATUS_OK) + { sTransmitLength = 0; } otSysEventSignalPending(); diff --git a/src/gsdk-pal/memory.c b/src/gsdk-pal/memory.c index 7f3cfc2e..a92dab6d 100644 --- a/src/gsdk-pal/memory.c +++ b/src/gsdk-pal/memory.c @@ -26,8 +26,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include "platform-efr32.h" +#include #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE #include diff --git a/src/gsdk-pal/misc.c b/src/gsdk-pal/misc.c index 2ed83555..17abc238 100644 --- a/src/gsdk-pal/misc.c +++ b/src/gsdk-pal/misc.c @@ -59,7 +59,7 @@ otPlatResetReason otPlatGetResetReason(otInstance *aInstance) otPlatResetReason reason = OT_PLAT_RESET_REASON_UNKNOWN; - #if defined(_EMU_RSTCAUSE_MASK) +#if defined(_EMU_RSTCAUSE_MASK) if (sResetCause & EMU_RSTCAUSE_POR) { reason = OT_PLAT_RESET_REASON_POWER_ON; @@ -80,14 +80,14 @@ otPlatResetReason otPlatGetResetReason(otInstance *aInstance) { reason = OT_PLAT_RESET_REASON_FAULT; } - else if ((sResetCause & EMU_RSTCAUSE_AVDDBOD) || (sResetCause & EMU_RSTCAUSE_DECBOD) || - (sResetCause & EMU_RSTCAUSE_DVDDBOD) || (sResetCause & EMU_RSTCAUSE_DVDDLEBOD) || - (sResetCause & EMU_RSTCAUSE_EM4)) + else if ((sResetCause & EMU_RSTCAUSE_AVDDBOD) || (sResetCause & EMU_RSTCAUSE_DECBOD) + || (sResetCause & EMU_RSTCAUSE_DVDDBOD) || (sResetCause & EMU_RSTCAUSE_DVDDLEBOD) + || (sResetCause & EMU_RSTCAUSE_EM4)) { reason = OT_PLAT_RESET_REASON_OTHER; } - #endif - #if defined(_RMU_RSTCAUSE_MASK) +#endif +#if defined(_RMU_RSTCAUSE_MASK) if (sResetCause & RMU_RSTCAUSE_PORST) { reason = OT_PLAT_RESET_REASON_POWER_ON; @@ -108,12 +108,12 @@ otPlatResetReason otPlatGetResetReason(otInstance *aInstance) { reason = OT_PLAT_RESET_REASON_FAULT; } - else if ((sResetCause & RMU_RSTCAUSE_AVDDBOD) || (sResetCause & RMU_RSTCAUSE_DECBOD) || - (sResetCause & RMU_RSTCAUSE_DVDDBOD) || (sResetCause & RMU_RSTCAUSE_EM4RST)) + else if ((sResetCause & RMU_RSTCAUSE_AVDDBOD) || (sResetCause & RMU_RSTCAUSE_DECBOD) + || (sResetCause & RMU_RSTCAUSE_DVDDBOD) || (sResetCause & RMU_RSTCAUSE_EM4RST)) { reason = OT_PLAT_RESET_REASON_OTHER; } - #endif +#endif return reason; } diff --git a/src/gsdk-pal/openthread-core-efr32-config-check.h b/src/gsdk-pal/openthread-core-efr32-config-check.h index 25e13ee8..fd9abbe8 100644 --- a/src/gsdk-pal/openthread-core-efr32-config-check.h +++ b/src/gsdk-pal/openthread-core-efr32-config-check.h @@ -41,8 +41,10 @@ #endif #endif -#if !defined(RADIO_CONFIG_915MHZ_OQPSK_SUPPORT) && !defined(RADIO_CONFIG_SUBGHZ_SUPPORT) && !defined(RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT) -#error "One of the following must be defined: RADIO_CONFIG_915MHZ_OQPSK_SUPPORT, RADIO_CONFIG_SUBGHZ_SUPPORT or RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT" +#if !defined(RADIO_CONFIG_915MHZ_OQPSK_SUPPORT) && !defined(RADIO_CONFIG_SUBGHZ_SUPPORT) \ + && !defined(RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT) +#error \ + "One of the following must be defined: RADIO_CONFIG_915MHZ_OQPSK_SUPPORT, RADIO_CONFIG_SUBGHZ_SUPPORT or RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT" #endif #endif /* OPENTHREAD_CORE_EFR32_CONFIG_CHECK_H_ */ diff --git a/src/gsdk-pal/openthread-core-efr32-config.h b/src/gsdk-pal/openthread-core-efr32-config.h index 5f94dbe5..86083504 100644 --- a/src/gsdk-pal/openthread-core-efr32-config.h +++ b/src/gsdk-pal/openthread-core-efr32-config.h @@ -44,13 +44,13 @@ #endif // Use (user defined) application config file to define OpenThread configurations -#ifdef SL_OPENTHREAD_APPLICATION_CONFIG_FILE +#ifdef SL_OPENTHREAD_APPLICATION_CONFIG_FILE #include SL_OPENTHREAD_APPLICATION_CONFIG_FILE #endif // Use (pre-defined) stack features config file available for applications built // with Simplicity Studio -#ifdef SL_OPENTHREAD_STACK_FEATURES_CONFIG_FILE +#ifdef SL_OPENTHREAD_STACK_FEATURES_CONFIG_FILE #include SL_OPENTHREAD_STACK_FEATURES_CONFIG_FILE #endif @@ -118,7 +118,7 @@ * */ #ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE -#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE 23 +#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE 23 #endif /** @@ -128,7 +128,7 @@ * */ #ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN -#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN 0 +#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN 0 #endif /** @@ -138,7 +138,7 @@ * */ #ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX -#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX 24 +#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX 24 #endif /** @@ -148,7 +148,7 @@ * */ #ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK -#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK 0x1ffffff +#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK 0x1ffffff #endif /** @@ -221,9 +221,9 @@ */ #ifndef OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD #if RADIO_CONFIG_SUBGHZ_SUPPORT - #define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 256 +#define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 256 #else - #define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 192 +#define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 192 #endif #endif @@ -272,7 +272,8 @@ * */ #ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_RADIO && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)) +#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE \ + (OPENTHREAD_RADIO && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)) #endif /** @@ -287,12 +288,12 @@ #endif /** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE - * - * Define to 1 to enable software reception target time logic. - * RCPs only. - * - */ + * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE + * + * Define to 1 to enable software reception target time logic. + * RCPs only. + * + */ #ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE #define OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE 0 #endif @@ -331,11 +332,11 @@ #endif /** - * @def OPENTHREAD_CONFIG_TCP_ENABLE - * - * Define as 1 to enable TCPlp (low power TCP defined in Thread spec). - * - */ + * @def OPENTHREAD_CONFIG_TCP_ENABLE + * + * Define as 1 to enable TCPlp (low power TCP defined in Thread spec). + * + */ #ifndef OPENTHREAD_CONFIG_TCP_ENABLE #define OPENTHREAD_CONFIG_TCP_ENABLE 0 #endif @@ -394,14 +395,14 @@ #endif /** -* @def OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET -* -* This is the offset in ITS where the persistent keys are stored. -* For Silabs OT applications, this needs to be in the range of -* 0x20000 to 0x2ffff. -* -*/ -#define OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET 0x20000 + * @def OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET + * + * This is the offset in ITS where the persistent keys are stored. + * For Silabs OT applications, this needs to be in the range of + * 0x20000 to 0x2ffff. + * + */ +#define OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET 0x20000 /** * @def OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE @@ -417,18 +418,18 @@ #endif /** - * @def OPENTHREAD_CONFIG_CRYPTO_LIB - * - * Selects the crypto backend library for OpenThread. - * - * There are several options available, but we enable PSA if key references are - * available. Otherwise, mbedTLS is used as default (see src/core/config/crypto.h) - * - * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_MBEDTLS - * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PSA - * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PLATFORM - * - */ + * @def OPENTHREAD_CONFIG_CRYPTO_LIB + * + * Selects the crypto backend library for OpenThread. + * + * There are several options available, but we enable PSA if key references are + * available. Otherwise, mbedTLS is used as default (see src/core/config/crypto.h) + * + * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_MBEDTLS + * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PSA + * - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PLATFORM + * + */ #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE #define OPENTHREAD_CONFIG_CRYPTO_LIB OPENTHREAD_CONFIG_CRYPTO_LIB_PSA #endif @@ -444,25 +445,25 @@ */ #ifndef SL_OPENTHREAD_CSL_TX_UNCERTAINTY #if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - # define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 175 +#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 175 #elif OPENTHREAD_FTD - // Approx. ~128 us. for single CCA + some additional tx uncertainty in testing - #define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 20 +// Approx. ~128 us. for single CCA + some additional tx uncertainty in testing +#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 20 #else - // Approx. ~128 us. for single CCA - // - // Note: Our SSEDs "schedule" transmissions to their parent in order to know - // exactly when in the future the data packets go out so they can calculate - // the accurate CSL phase to send to their parent. - // - // The receive windows on the SSEDs scale with this value, so increasing this - // uncertainty to account for full CCA/CSMA with 0..7 backoffs - // (see RAIL_CSMA_CONFIG_802_15_4_2003_2p4_GHz_OQPSK_CSMA) will mean that the - // receive windows can get very long (~ 5ms.) - // - // We have updated SSEDs to use a single CCA (RAIL_CSMA_CONFIG_SINGLE_CCA) - // instead. If they are in very busy channels, CSL won't be reliable anyway. - #define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 12 +// Approx. ~128 us. for single CCA +// +// Note: Our SSEDs "schedule" transmissions to their parent in order to know +// exactly when in the future the data packets go out so they can calculate +// the accurate CSL phase to send to their parent. +// +// The receive windows on the SSEDs scale with this value, so increasing this +// uncertainty to account for full CCA/CSMA with 0..7 backoffs +// (see RAIL_CSMA_CONFIG_802_15_4_2003_2p4_GHz_OQPSK_CSMA) will mean that the +// receive windows can get very long (~ 5ms.) +// +// We have updated SSEDs to use a single CCA (RAIL_CSMA_CONFIG_SINGLE_CCA) +// instead. If they are in very busy channels, CSL won't be reliable anyway. +#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 12 #endif #endif @@ -475,7 +476,7 @@ * */ #ifndef SL_OPENTHREAD_HFXO_ACCURACY - #define SL_OPENTHREAD_HFXO_ACCURACY SL_DEVICE_INIT_HFXO_PRECISION +#define SL_OPENTHREAD_HFXO_ACCURACY SL_DEVICE_INIT_HFXO_PRECISION #endif /** @@ -486,11 +487,11 @@ * @note Platforms may optimize this value based on operational conditions (i.e.: temperature). */ #ifndef SL_OPENTHREAD_LFXO_ACCURACY - #if defined(HARDWARE_BOARD_HAS_LFXO) - #define SL_OPENTHREAD_LFXO_ACCURACY SL_DEVICE_INIT_LFXO_PRECISION - #else - #define SL_OPENTHREAD_LFXO_ACCURACY 0 - #endif +#if defined(HARDWARE_BOARD_HAS_LFXO) +#define SL_OPENTHREAD_LFXO_ACCURACY SL_DEVICE_INIT_LFXO_PRECISION +#else +#define SL_OPENTHREAD_LFXO_ACCURACY 0 +#endif #endif /** @@ -520,7 +521,7 @@ * */ #ifndef SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE -#define SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE 32 +#define SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE 32 #endif #endif // OPENTHREAD_CORE_EFR32_CONFIG_H_ diff --git a/src/gsdk-pal/platform-band.h b/src/gsdk-pal/platform-band.h index 4f8ababa..7c1e316a 100644 --- a/src/gsdk-pal/platform-band.h +++ b/src/gsdk-pal/platform-band.h @@ -60,7 +60,8 @@ typedef struct efr32CommonConfig #if RADIO_CONFIG_DMP_SUPPORT RAILSched_Config_t mRailSchedState; #endif - union { + union + { // Used to align this buffer as needed RAIL_FIFO_ALIGNMENT_TYPE align[RAIL_TX_FIFO_SIZE / RAIL_FIFO_ALIGNMENT]; uint8_t fifo[RAIL_TX_FIFO_SIZE]; // must be 2 power between 64 and 4096, and bigger than OT_RADIO_FRAME_MAX_SIZE diff --git a/src/gsdk-pal/platform-efr32.h b/src/gsdk-pal/platform-efr32.h index e1d7ee59..d2f316a5 100644 --- a/src/gsdk-pal/platform-efr32.h +++ b/src/gsdk-pal/platform-efr32.h @@ -51,7 +51,7 @@ extern otInstance *sInstance; // Global reference to rail handle #ifndef SL_CATALOG_RAIL_MULTIPLEXER_PRESENT -#define gRailHandle emPhyRailHandle // use gRailHandle in the OpenThread PAL. +#define gRailHandle emPhyRailHandle // use gRailHandle in the OpenThread PAL. #endif extern RAIL_Handle_t gRailHandle; // coex needs the emPhyRailHandle symbol. diff --git a/src/gsdk-pal/radio_extension.c b/src/gsdk-pal/radio_extension.c index f555ae7f..0b503518 100644 --- a/src/gsdk-pal/radio_extension.c +++ b/src/gsdk-pal/radio_extension.c @@ -32,9 +32,9 @@ * */ +#include #include #include -#include #include "radio_extension.h" @@ -45,8 +45,8 @@ #ifndef SL_CATALOG_OT_SIMULATION_PRESENT #ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT -#include "coexistence.h" #include "coexistence-802154.h" +#include "coexistence.h" #endif // SL_CATALOG_RAIL_UTIL_COEX_PRESENT #ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT @@ -362,8 +362,8 @@ otError otPlatRadioExtensionGetRequestPwmArgs(uint8_t *aPwmReq, uint8_t *aPwmDut VerifyOrExit(aPwmPeriodHalfMs != NULL, error = OT_ERROR_INVALID_ARGS); p = sl_rail_util_coex_get_request_pwm_args(); VerifyOrExit(p != NULL, error = OT_ERROR_FAILED); - *aPwmReq = p->req; - *aPwmDutyCycle = p->dutyCycle; + *aPwmReq = p->req; + *aPwmDutyCycle = p->dutyCycle; *aPwmPeriodHalfMs = p->periodHalfMs; #else OT_UNUSED_VARIABLE(aPwmReq); @@ -381,10 +381,7 @@ otError otPlatRadioExtensionSetRequestPwmArgs(uint8_t aPwmReq, uint8_t aPwmDutyC otError error = OT_ERROR_NONE; #ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT - sl_status_t status = sl_rail_util_coex_set_request_pwm(aPwmReq, - NULL, - aPwmDutyCycle, - aPwmPeriodHalfMs); + sl_status_t status = sl_rail_util_coex_set_request_pwm(aPwmReq, NULL, aPwmDutyCycle, aPwmPeriodHalfMs); VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED); #else OT_UNUSED_VARIABLE(aPwmReq); @@ -399,7 +396,7 @@ otError otPlatRadioExtensionSetRequestPwmArgs(uint8_t aPwmReq, uint8_t aPwmDutyC #if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT) && SL_OPENTHREAD_COEX_COUNTER_ENABLE extern uint32_t efr32RadioCoexCounters[SL_RAIL_UTIL_COEX_EVENT_COUNT]; -extern void efr32RadioClearCoexCounters(void); +extern void efr32RadioClearCoexCounters(void); #endif otError otPlatRadioExtensionClearCoexCounters(void) @@ -424,8 +421,9 @@ otError otPlatRadioExtensionGetCoexCounters(uint8_t aNumEntries, uint32_t aCoexC VerifyOrExit(aCoexCounters != NULL, error = OT_ERROR_INVALID_ARGS); _Static_assert((uint8_t)OT_PLAT_RADIO_EXTENSION_COEX_EVENT_COUNT == (uint8_t)SL_RAIL_UTIL_COEX_EVENT_COUNT, "Coex counter mismatch. OT_PLAT_RADIO_EXTENSION_COEX_EVENT_COUNT != SL_RAIL_UTIL_COEX_EVENT_COUNT"); - #define COPY_COEX_COUNTER(counter) \ - aCoexCounters[OT_PLAT_RADIO_EXTENSION_COEX_EVENT_##counter] = efr32RadioCoexCounters[SL_RAIL_UTIL_COEX_EVENT_##counter] +#define COPY_COEX_COUNTER(counter) \ + aCoexCounters[OT_PLAT_RADIO_EXTENSION_COEX_EVENT_##counter] = \ + efr32RadioCoexCounters[SL_RAIL_UTIL_COEX_EVENT_##counter] COPY_COEX_COUNTER(LO_PRI_REQUESTED); COPY_COEX_COUNTER(HI_PRI_REQUESTED); COPY_COEX_COUNTER(LO_PRI_DENIED); @@ -461,7 +459,7 @@ otError otPlatRadioExtensionSetRadioHoldoff(bool aEnabled) #ifdef SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT extern RAIL_IEEE802154_PtiRadioConfig_t efr32GetPtiRadioConfig(void); -extern RAIL_Status_t efr32RadioSetCcaMode(uint8_t aMode); +extern RAIL_Status_t efr32RadioSetCcaMode(uint8_t aMode); otError otPlatRadioExtensionGetPtiRadioConfig(uint16_t *radioConfig) { @@ -486,7 +484,7 @@ otError otPlatRadioExtensionSetCcaMode(uint8_t aMode) return error; } #endif // SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT - + #ifdef SL_CATALOG_OPENTHREAD_EFR32_EXT_PRESENT extern otError efr32GetRadioCounters(efr32RadioCounters *aRadioCounters); extern otError efr32ClearRadioCounters(void); diff --git a/src/gsdk-pal/sl_openthread.h b/src/gsdk-pal/sl_openthread.h index d9b3da42..19ebfa98 100644 --- a/src/gsdk-pal/sl_openthread.h +++ b/src/gsdk-pal/sl_openthread.h @@ -20,4 +20,4 @@ void sl_openthread_init(); -#endif //__SL_OPENTHREAD_H__ \ No newline at end of file +#endif //__SL_OPENTHREAD_H__ diff --git a/src/gsdk-pal/sl_packet_utils.h b/src/gsdk-pal/sl_packet_utils.h index 33681bd1..24bba3fa 100644 --- a/src/gsdk-pal/sl_packet_utils.h +++ b/src/gsdk-pal/sl_packet_utils.h @@ -78,7 +78,7 @@ otPanId efr32GetDstPanId(otRadioFrame *aFrame); * * @retval Pointer to start of 802.15.4 payload. */ -uint8_t* efr32GetPayload(otRadioFrame *aFrame); +uint8_t *efr32GetPayload(otRadioFrame *aFrame); #ifdef __cplusplus } // extern "C" diff --git a/src/gsdk-pal/sl_rcp_gp_interface.c b/src/gsdk-pal/sl_rcp_gp_interface.c index 7f0a0edb..3965cee2 100644 --- a/src/gsdk-pal/sl_rcp_gp_interface.c +++ b/src/gsdk-pal/sl_rcp_gp_interface.c @@ -15,16 +15,16 @@ * ******************************************************************************/ -#include -#include "rail_ieee802154.h" -#include "ieee802154mac.h" -#include -#include "common/logging.hpp" -#include "sl_status.h" #include "sl_rcp_gp_interface.h" -#include "sl_rcp_gp_interface_config.h" +#include "ieee802154mac.h" +#include "rail_ieee802154.h" #include "sl_packet_utils.h" +#include "sl_rcp_gp_interface_config.h" +#include "sl_status.h" +#include #include +#include +#include "common/logging.hpp" // This implements mechanism to buffer outgoing Channel Configuration (0xF3) and // Commissioning Reply (0xF0) GPDF commands on the RCP to sent out on request @@ -41,7 +41,7 @@ #define GP_MIN_DATA_FRAME_LENGTH 14 #define GP_ADDRESSING_MODE_SRC_ID 0 -#define GP_ADDRESSING_MODE_EUI64 2 +#define GP_ADDRESSING_MODE_EUI64 2 #define GP_NWK_PROTOCOL_VERSION_CHECK(nwkFc) (((nwkFc >> 2) & 0x0F) == 3) #define GP_NWK_FRAME_TYPE_MAINTENANCE_WITHOUT_EXTD_FC(nwkFc) ((nwkFc & 0xC3) == 0x01) @@ -56,18 +56,18 @@ #define GP_COMMISSIONINGING_CMD_ID 0xE0 #define GP_COMMISSIONING_REPLY_CMD_ID 0xF0 -#define GP_EXND_FC_INDEX 1 +#define GP_EXND_FC_INDEX 1 #define GP_COMMAND_INDEX_FOR_MAINT_FRAME 1 -#define GP_SRC_ID_INDEX_WITH_APP_MODE_0 2 -#define GP_APP_EP_INDEX_WITH_APP_MODE_1 2 +#define GP_SRC_ID_INDEX_WITH_APP_MODE_0 2 +#define GP_APP_EP_INDEX_WITH_APP_MODE_1 2 #define GP_COMMAND_INDEX_WITH_APP_MODE_1 3 #define GP_COMMAND_INDEX_WITH_APP_MODE_0 6 #define BUFFERED_PSDU_GP_SRC_ID_INDEX_WITH_APP_MODE_0 9 #define BUFFERED_PSDU_GP_APP_EP_INDEX_WITH_APP_MODE_1 9 -static volatile sl_gp_state_t gp_state = SL_GP_STATE_INIT; -static volatile uint64_t gpStateTimeOut; +static volatile sl_gp_state_t gp_state = SL_GP_STATE_INIT; +static volatile uint64_t gpStateTimeOut; sl_gp_state_t sl_gp_intf_get_state(void) { @@ -76,47 +76,46 @@ sl_gp_state_t sl_gp_intf_get_state(void) void efr32GpProcess(void) { - - switch(gp_state) + switch (gp_state) + { + case SL_GP_STATE_INIT: + { + gp_state = SL_GP_STATE_IDLE; + otLogDebgPlat("GP RCP INTF: GP Frame init!!"); + } + break; + case SL_GP_STATE_SEND_RESPONSE: { - case SL_GP_STATE_INIT: + if (otPlatTimeGet() >= gpStateTimeOut) { + // Get the tx frame and send it without csma. + otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(NULL); + aTxFrame->mInfo.mTxInfo.mCsmaCaEnabled = false; + aTxFrame->mInfo.mTxInfo.mMaxCsmaBackoffs = 0; + // On successful transmit, this will call the transmit complete callback for the GP packet, + // and go up to the CGP Send Handler and eventually the green power client. + otPlatRadioTransmit(NULL, aTxFrame); + gp_state = SL_GP_STATE_IDLE; - otLogDebgPlat("GP RCP INTF: GP Frame init!!"); + otLogDebgPlat("GP RCP INTF: Sending Response!!"); } - break; - case SL_GP_STATE_SEND_RESPONSE: - { - if(otPlatTimeGet() >= gpStateTimeOut) - { - // Get the tx frame and send it without csma. - otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(NULL); - aTxFrame->mInfo.mTxInfo.mCsmaCaEnabled = false; - aTxFrame->mInfo.mTxInfo.mMaxCsmaBackoffs = 0; - // On successful transmit, this will call the transmit complete callback for the GP packet, - // and go up to the CGP Send Handler and eventually the green power client. - otPlatRadioTransmit(NULL, aTxFrame); - - gp_state = SL_GP_STATE_IDLE; - otLogDebgPlat("GP RCP INTF: Sending Response!!"); - } - } - break; - case SL_GP_STATE_WAITING_FOR_PKT: - { - if(otPlatTimeGet() >= gpStateTimeOut) - { - // This is a timeout call for the case when the GPD did not poll the response with in 5 seconds. - otPlatRadioTxDone(NULL, otPlatRadioGetTransmitBuffer(NULL), NULL, OT_ERROR_ABORT); - gp_state = SL_GP_STATE_IDLE; - } - } - break; - default: + } + break; + case SL_GP_STATE_WAITING_FOR_PKT: + { + if (otPlatTimeGet() >= gpStateTimeOut) { - // For all other states don't do anything + // This is a timeout call for the case when the GPD did not poll the response with in 5 seconds. + otPlatRadioTxDone(NULL, otPlatRadioGetTransmitBuffer(NULL), NULL, OT_ERROR_ABORT); + gp_state = SL_GP_STATE_IDLE; } - break; + } + break; + default: + { + // For all other states don't do anything + } + break; } } @@ -124,14 +123,14 @@ void sl_gp_intf_buffer_pkt(otRadioFrame *aFrame) { OT_UNUSED_VARIABLE(aFrame); gpStateTimeOut = otPlatTimeGet() + GP_TX_MAX_TIMEOUT_IN_MICRO_SECONDS; - gp_state = SL_GP_STATE_WAITING_FOR_PKT; + gp_state = SL_GP_STATE_WAITING_FOR_PKT; otLogDebgPlat("GP RCP INTF: buffered!!"); } bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) { - bool isGpPkt = false; - uint8_t *gpFrameStartIndex = efr32GetPayload(aFrame); + bool isGpPkt = false; + uint8_t *gpFrameStartIndex = efr32GetPayload(aFrame); // A Typical MAC Frame with GP NWK Frame in it // MAC Frame : [<---------------MAC Header------------->||<------------------------------------NWK Frame----------------------------------->] @@ -142,59 +141,62 @@ bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) uint8_t fc = *gpFrameStartIndex; - otLogDebgPlat("GP RCP INTF : (%s) PL Index = %d Channel = %d Length = %d FC = %0X", isRxFrame? "Rx":"Tx",(gpFrameStartIndex - aFrame->mPsdu), aFrame->mChannel, aFrame->mLength,fc); + otLogDebgPlat("GP RCP INTF : (%s) PL Index = %d Channel = %d Length = %d FC = %0X", + isRxFrame ? "Rx" : "Tx", + (gpFrameStartIndex - aFrame->mPsdu), + aFrame->mChannel, + aFrame->mLength, + fc); // The basic Identification of a GPDF Frame : The minimum GPDF length need to be 10 in this case for any direction // with network layer FC containing the Protocol Version field as 3. - if (aFrame->mLength >= GP_MIN_MAINTENANCE_FRAME_LENGTH - && GP_NWK_PROTOCOL_VERSION_CHECK(fc)) + if (aFrame->mLength >= GP_MIN_MAINTENANCE_FRAME_LENGTH && GP_NWK_PROTOCOL_VERSION_CHECK(fc)) { - otLogDebgPlat("GP RCP INTF : (%s) Length and Version Matched",isRxFrame? "Rx":"Tx"); - // For GP Maintenance Frame type without extended FC, the FC is exactly same for both RX and TX directions with auto commissioning bit = 0, - // does not have a ExtFC field, only the command Id (which is the next byte in frame) indicates the direction. + otLogDebgPlat("GP RCP INTF : (%s) Length and Version Matched", isRxFrame ? "Rx" : "Tx"); + // For GP Maintenance Frame type without extended FC, the FC is exactly same for both RX and TX directions with + // auto commissioning bit = 0, does not have a ExtFC field, only the command Id (which is the next byte in + // frame) indicates the direction. if (GP_NWK_FRAME_TYPE_MAINTENANCE_WITHOUT_EXTD_FC(fc)) { - otLogDebgPlat("GP RCP INTF : (%s) Maintenance Frame match",isRxFrame? "Rx":"Tx"); + otLogDebgPlat("GP RCP INTF : (%s) Maintenance Frame match", isRxFrame ? "Rx" : "Tx"); uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_FOR_MAINT_FRAME); - if (cmdId == GP_CHANNEL_REQUEST_CMD_ID - && isRxFrame) + if (cmdId == GP_CHANNEL_REQUEST_CMD_ID && isRxFrame) { // Send out the buffered frame - isGpPkt = true; - gp_state = SL_GP_STATE_SEND_RESPONSE; + isGpPkt = true; + gp_state = SL_GP_STATE_SEND_RESPONSE; gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS; - otLogDebgPlat("GP RCP INTF : (%s) Received GP_CHANNEL_REQUEST_CMD_ID - Send the Channel configuration",isRxFrame? "Rx":"Tx"); + otLogDebgPlat("GP RCP INTF : (%s) Received GP_CHANNEL_REQUEST_CMD_ID - Send the Channel configuration", + isRxFrame ? "Rx" : "Tx"); } - else if (cmdId == GP_CHANNEL_CONFIGURATION_CMD_ID - && !isRxFrame) + else if (cmdId == GP_CHANNEL_CONFIGURATION_CMD_ID && !isRxFrame) { // Buffer the frame isGpPkt = true; - otLogDebgPlat("GP RCP INTF : (%s) Buffer GP_CHANNEL_CONFIGURATION_CMD_ID command",isRxFrame? "Rx":"Tx"); + otLogDebgPlat("GP RCP INTF : (%s) Buffer GP_CHANNEL_CONFIGURATION_CMD_ID command", + isRxFrame ? "Rx" : "Tx"); } } - else if (GP_NWK_FRAME_TYPE_DATA_WITH_EXTD_FC(fc) // Data frame with EXT FC present, extract the App Id, SrcId, direction and command Id - && aFrame->mLength >= GP_MIN_DATA_FRAME_LENGTH) // Minimum Data frame length with extended header and address + else if (GP_NWK_FRAME_TYPE_DATA_WITH_EXTD_FC( + fc) // Data frame with EXT FC present, extract the App Id, SrcId, direction and command Id + && aFrame->mLength + >= GP_MIN_DATA_FRAME_LENGTH) // Minimum Data frame length with extended header and address { uint8_t extFc = *(gpFrameStartIndex + GP_EXND_FC_INDEX); // Process only unsecured commissioning frames for Tx/Rx with correct direction and RxAfterTx fields - if ((!isRxFrame - && GP_NWK_UNSECURED_TX_DATA_FRAME(extFc)) - || (isRxFrame - && GP_NWK_UNSECURED_RX_DATA_FRAME(extFc))) + if ((!isRxFrame && GP_NWK_UNSECURED_TX_DATA_FRAME(extFc)) + || (isRxFrame && GP_NWK_UNSECURED_RX_DATA_FRAME(extFc))) { if (GP_NWK_ADDRESSING_APP_ID(extFc) == GP_ADDRESSING_MODE_SRC_ID) { uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_WITH_APP_MODE_0); - if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID - && !isRxFrame) + if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID && !isRxFrame) { // Buffer the frame isGpPkt = true; } - else if (cmdId == GP_COMMISSIONINGING_CMD_ID - && isRxFrame) + else if (cmdId == GP_COMMISSIONINGING_CMD_ID && isRxFrame) { otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(NULL); // Match the gpd src Id ? @@ -203,7 +205,7 @@ bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) sizeof(uint32_t))) { // Send out the buffered frame - gp_state = SL_GP_STATE_SEND_RESPONSE; + gp_state = SL_GP_STATE_SEND_RESPONSE; gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS; } } @@ -211,14 +213,12 @@ bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) else if (GP_NWK_ADDRESSING_APP_ID(extFc) == GP_ADDRESSING_MODE_EUI64) { uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_WITH_APP_MODE_1); - if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID - && !isRxFrame) + if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID && !isRxFrame) { // Buffer the frame isGpPkt = true; } - else if (cmdId == GP_COMMISSIONINGING_CMD_ID - && isRxFrame) + else if (cmdId == GP_COMMISSIONINGING_CMD_ID && isRxFrame) { otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(NULL); // Check the eui64 and app endpoint to send out the buffer packet. @@ -226,11 +226,14 @@ bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) otMacAddress aDstAddress; otMacFrameGetDstAddr(aTxFrame, &aDstAddress); otMacFrameGetSrcAddr(aFrame, &aSrcAddress); - if ( !memcmp(&(aDstAddress.mAddress.mExtAddress), &(aSrcAddress.mAddress.mExtAddress), sizeof(otExtAddress)) - && (gpFrameStartIndex[GP_APP_EP_INDEX_WITH_APP_MODE_1] == (aTxFrame->mPsdu)[BUFFERED_PSDU_GP_APP_EP_INDEX_WITH_APP_MODE_1])) + if (!memcmp(&(aDstAddress.mAddress.mExtAddress), + &(aSrcAddress.mAddress.mExtAddress), + sizeof(otExtAddress)) + && (gpFrameStartIndex[GP_APP_EP_INDEX_WITH_APP_MODE_1] + == (aTxFrame->mPsdu)[BUFFERED_PSDU_GP_APP_EP_INDEX_WITH_APP_MODE_1])) { - isGpPkt = true; - gp_state = SL_GP_STATE_SEND_RESPONSE; + isGpPkt = true; + gp_state = SL_GP_STATE_SEND_RESPONSE; gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS; } } @@ -238,7 +241,7 @@ bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame, bool isRxFrame) } } } - if(isGpPkt) + if (isGpPkt) { otLogDebgPlat("GP RCP INTF: GP filter passed!!"); } diff --git a/src/gsdk-pal/sl_rcp_gp_interface.h b/src/gsdk-pal/sl_rcp_gp_interface.h index 14d38665..f103936b 100644 --- a/src/gsdk-pal/sl_rcp_gp_interface.h +++ b/src/gsdk-pal/sl_rcp_gp_interface.h @@ -19,7 +19,8 @@ #define SL_RCP_GP_INTERFACE_H_ #include "utils/mac_frame.h" // GP state-machine states -typedef enum { +typedef enum +{ SL_GP_STATE_INIT, SL_GP_STATE_IDLE, SL_GP_STATE_WAITING_FOR_PKT, @@ -58,4 +59,4 @@ sl_gp_state_t sl_gp_intf_get_state(void); * */ void efr32GpProcess(void); -#endif \ No newline at end of file +#endif diff --git a/src/gsdk-pal/sleep.c b/src/gsdk-pal/sleep.c index 660eac23..a2ba4e3b 100644 --- a/src/gsdk-pal/sleep.c +++ b/src/gsdk-pal/sleep.c @@ -33,18 +33,18 @@ * */ -#define CURRENT_MODULE_NAME "OPENTHREAD" +#define CURRENT_MODULE_NAME "OPENTHREAD" -#include -#include -#include #include "sleep.h" #include "em_core.h" -#include "sl_component_catalog.h" #include "platform-efr32.h" +#include "sl_component_catalog.h" +#include +#include +#include #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - #include "sl_power_manager.h" +#include "sl_power_manager.h" #endif // SL_CATALOG_POWER_MANAGER_PRESENT // Power manager transition events of interest. @@ -61,8 +61,7 @@ #if (defined(SL_CATALOG_POWER_MANAGER_PRESENT) && !defined(SL_CATALOG_KERNEL_PRESENT)) -static void energy_mode_transition_callback(sl_power_manager_em_t from, - sl_power_manager_em_t to); +static void energy_mode_transition_callback(sl_power_manager_em_t from, sl_power_manager_em_t to); //------------------------------------------------------------------------------ // Static and extern variables @@ -70,8 +69,8 @@ static void energy_mode_transition_callback(sl_power_manager_em_t from, static bool em1_requirement_set = false; static sl_power_manager_em_transition_event_handle_t pm_handle; -static sl_power_manager_em_transition_event_info_t pm_event_info = -{ POWER_MANAGER_EVENTS_OF_INTEREST, energy_mode_transition_callback }; +static sl_power_manager_em_transition_event_info_t pm_event_info = {POWER_MANAGER_EVENTS_OF_INTEREST, + energy_mode_transition_callback}; #endif // SL_CATALOG_POWER_MANAGER_PRESENT && !SL_CATALOG_KERNEL_PRESENT @@ -85,17 +84,17 @@ void sl_ot_sleep_init(void) #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #ifndef SL_CATALOG_KERNEL_PRESENT - sl_power_manager_subscribe_em_transition_event(&pm_handle, &pm_event_info); + sl_power_manager_subscribe_em_transition_event(&pm_handle, &pm_event_info); #endif - // Ensure EM2 is the lowest low power mode - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM2); + // Ensure EM2 is the lowest low power mode + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM2); - // Set initial power requirement to EM1 - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); + // Set initial power requirement to EM1 + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); #ifndef SL_CATALOG_KERNEL_PRESENT - em1_requirement_set = true; + em1_requirement_set = true; #endif #endif // SL_CATALOG_POWER_MANAGER_PRESENT @@ -111,64 +110,75 @@ __WEAK bool efr32AllowSleepCallback(void) // This is invoked only the bare metal case. bool sl_ot_is_ok_to_sleep(void) { - // If the application does not permit sleep, we don't sleep. - if (!efr32AllowSleepCallback()) { - return false; - } - - uint32_t duration_ms = 0; - - CORE_ATOMIC_IRQ_DISABLE(); - - // If the stack says we can nap, it means that no tasks are pending. We may - // either sleep (EM2) or idle (EM1) for some amount of time. Otherwise, - // we can't sleep/idle at all. - if (!otTaskletsArePending(sInstance)) { - // Compute sleep/idle duration. we will never sleep/idle longer than the - // duration to our next event. - duration_ms = efr32AlarmPendingTime(); - - // If the sleep duration is below our minimum threshold, we dont bother sleeping. - // If so, we can try to idle instead. - if (efr32AlarmIsRunning(sInstance) && (duration_ms < OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS)) { - if (!em1_requirement_set) { - // Prevent the system from entering em2 - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); - em1_requirement_set = true; - } - } else { - if (em1_requirement_set) { - // Allow the system to enter em2 - sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); - em1_requirement_set = false; - } + // If the application does not permit sleep, we don't sleep. + if (!efr32AllowSleepCallback()) + { + return false; + } + + uint32_t duration_ms = 0; + + CORE_ATOMIC_IRQ_DISABLE(); + + // If the stack says we can nap, it means that no tasks are pending. We may + // either sleep (EM2) or idle (EM1) for some amount of time. Otherwise, + // we can't sleep/idle at all. + if (!otTaskletsArePending(sInstance)) + { + // Compute sleep/idle duration. we will never sleep/idle longer than the + // duration to our next event. + duration_ms = efr32AlarmPendingTime(); + + // If the sleep duration is below our minimum threshold, we dont bother sleeping. + // If so, we can try to idle instead. + if (efr32AlarmIsRunning(sInstance) && (duration_ms < OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS)) + { + if (!em1_requirement_set) + { + // Prevent the system from entering em2 + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); + em1_requirement_set = true; + } + } + else + { + if (em1_requirement_set) + { + // Allow the system to enter em2 + sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); + em1_requirement_set = false; + } + } } - } else { - if (!em1_requirement_set) { - // Prevent the system from entering em2 - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); - em1_requirement_set = true; + else + { + if (!em1_requirement_set) + { + // Prevent the system from entering em2 + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); + em1_requirement_set = true; + } } - } - CORE_ATOMIC_IRQ_ENABLE(); + CORE_ATOMIC_IRQ_ENABLE(); - // We dont need to start a separate timer to wake us up, as the alarm code already sets one. - return (efr32AlarmIsRunning(sInstance) ? (duration_ms != 0) : true); + // We dont need to start a separate timer to wake us up, as the alarm code already sets one. + return (efr32AlarmIsRunning(sInstance) ? (duration_ms != 0) : true); } //------------------------------------------------------------------------------ // Static functions -static void energy_mode_transition_callback(sl_power_manager_em_t from, - sl_power_manager_em_t to) +static void energy_mode_transition_callback(sl_power_manager_em_t from, sl_power_manager_em_t to) { - if (from == SL_POWER_MANAGER_EM2) { // Leaving EM2 - // emberStackPowerUp(); // TO DO: Do we need to take care of any state? - } else if (to == SL_POWER_MANAGER_EM2) { // Going to EM2 - // emberStackPowerDown(); // TO DO: Do we need to take care of any state? - } + if (from == SL_POWER_MANAGER_EM2) + { // Leaving EM2 + // emberStackPowerUp(); // TO DO: Do we need to take care of any state? + } + else if (to == SL_POWER_MANAGER_EM2) + { // Going to EM2 + // emberStackPowerDown(); // TO DO: Do we need to take care of any state? + } } #endif // SL_CATALOG_POWER_MANAGER_PRESENT && !SL_CATALOG_KERNEL_PRESENT - diff --git a/src/gsdk-pal/soft_source_match_table.c b/src/gsdk-pal/soft_source_match_table.c index 0f3f112e..dd1864fc 100644 --- a/src/gsdk-pal/soft_source_match_table.c +++ b/src/gsdk-pal/soft_source_match_table.c @@ -108,8 +108,11 @@ static void printShortEntryTable(uint8_t iid) otLogDebgPlat("================================|============|==========="); for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM; i++) { - otLogDebgPlat("ShortEntry[panIndex=%d][entry=%d] | %d | 0x%04x", panIndex, i, - srcMatchShortEntry[panIndex][i].allocated, srcMatchShortEntry[panIndex][i].checksum); + otLogDebgPlat("ShortEntry[panIndex=%d][entry=%d] | %d | 0x%04x", + panIndex, + i, + srcMatchShortEntry[panIndex][i].allocated, + srcMatchShortEntry[panIndex][i].checksum); } otLogDebgPlat("================================|============|==========="); } @@ -274,8 +277,11 @@ static void printExtEntryTable(uint8_t iid) otLogDebgPlat("==============================|============|==========="); for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM; i++) { - otLogDebgPlat("ExtEntry[panIndex=%d][entry=%d] | %d | 0x%04x", panIndex, i, - srcMatchExtEntry[panIndex][i].allocated, srcMatchExtEntry[panIndex][i].checksum); + otLogDebgPlat("ExtEntry[panIndex=%d][entry=%d] | %d | 0x%04x", + panIndex, + i, + srcMatchExtEntry[panIndex][i].allocated, + srcMatchExtEntry[panIndex][i].checksum); } otLogDebgPlat("==============================|============|==========="); } diff --git a/src/gsdk-pal/spidrv_usart.c b/src/gsdk-pal/spidrv_usart.c index 56acc378..ffb5923c 100644 --- a/src/gsdk-pal/spidrv_usart.c +++ b/src/gsdk-pal/spidrv_usart.c @@ -36,12 +36,12 @@ #include "sl_component_catalog.h" #endif // SL_COMPONENT_CATALOG_PRESENT +#include #include #include -#include -#include "em_core.h" #include "em_cmu.h" +#include "em_core.h" #include "em_gpio.h" #include "em_ldma.h" @@ -55,18 +55,20 @@ #include "sl_ncp_spidrv_usart_config.h" #include "error.h" -#include "spi-slave.h" #include "openthread-system.h" -#include "utils/code_utils.h" #include "platform-efr32.h" +#include "spi-slave.h" +#include "utils/code_utils.h" // DEFINES -#define MAX_DMA_DESCRIPTOR_TRANSFER_COUNT ((_LDMA_CH_CTRL_XFERCNT_MASK >> _LDMA_CH_CTRL_XFERCNT_SHIFT) + 1U) +#define MAX_DMA_DESCRIPTOR_TRANSFER_COUNT ((_LDMA_CH_CTRL_XFERCNT_MASK >> _LDMA_CH_CTRL_XFERCNT_SHIFT) + 1U) -#define SL_OT_SPIDRV_SPI_CONCAT_PASTER(first, second, third) first ## second ## third +#define SL_OT_SPIDRV_SPI_CONCAT_PASTER(first, second, third) first##second##third -#define SL_OT_SPIDRV_SPI_LDMA_RX_PERIPH_TRIGGER(periph_nbr) SL_OT_SPIDRV_SPI_CONCAT_PASTER(ldmaPeripheralSignal_USART, periph_nbr, _RXDATAV) -#define SL_OT_SPIDRV_SPI_LDMA_TX_PERIPH_TRIGGER(periph_nbr) SL_OT_SPIDRV_SPI_CONCAT_PASTER(ldmaPeripheralSignal_USART, periph_nbr, _TXBL) +#define SL_OT_SPIDRV_SPI_LDMA_RX_PERIPH_TRIGGER(periph_nbr) \ + SL_OT_SPIDRV_SPI_CONCAT_PASTER(ldmaPeripheralSignal_USART, periph_nbr, _RXDATAV) +#define SL_OT_SPIDRV_SPI_LDMA_TX_PERIPH_TRIGGER(periph_nbr) \ + SL_OT_SPIDRV_SPI_CONCAT_PASTER(ldmaPeripheralSignal_USART, periph_nbr, _TXBL) // MEMBER VARIABLES static volatile bool should_process_transaction = false; @@ -77,15 +79,15 @@ static volatile bool transaction_active; static LDMA_TransferCfg_t rx_dma_transfer_config; static LDMA_TransferCfg_t tx_dma_transfer_config; -static uint8_t default_tx_value; +static uint8_t default_tx_value; static volatile LDMA_Descriptor_t tx_descriptor[2]; static volatile LDMA_Descriptor_t rx_descriptor; // TRANSACTION EVENT'S CALLBACK static volatile otPlatSpiSlaveTransactionCompleteCallback complete_callback; -static volatile otPlatSpiSlaveTransactionProcessCallback process_callback; -static volatile void *context; +static volatile otPlatSpiSlaveTransactionProcessCallback process_callback; +static volatile void *context; // SPI Peripheral static volatile SPIDRV_HandleData_t sl_spidrv_handle_data; @@ -93,268 +95,334 @@ static volatile SPIDRV_HandleData_t sl_spidrv_handle_data; static void rcp_spidrv_set_host_request(void) { #if defined(SL_NCP_SPIDRV_USART_HOST_INT_PORT) && defined(SL_NCP_SPIDRV_USART_HOST_INT_PIN) - GPIO_PinOutClear(SL_NCP_SPIDRV_USART_HOST_INT_PORT, - SL_NCP_SPIDRV_USART_HOST_INT_PIN); + GPIO_PinOutClear(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN); #else - int empty = 0; - (void)empty; + int empty = 0; + (void)empty; #endif } static void rcp_spidrv_deassert_host_request(void) { #if defined(SL_NCP_SPIDRV_USART_HOST_INT_PORT) && defined(SL_NCP_SPIDRV_USART_HOST_INT_PIN) - GPIO_PinOutSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN); + GPIO_PinOutSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN); #else - int empty = 0; - (void)empty; + int empty = 0; + (void)empty; #endif } static void rcp_spidrv_spi_transaction_end_interrupt(uint8_t intNo) { - if (intNo == SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO) - { - transaction_active = true; - return; - } else if (intNo == SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO) { - // Must be done before calling the "complete_callback" since - // this callback will use otPlatSpiSlavePrepareTransaction who - // would not setup the buffers if a transaction is ongoing. - transaction_active = false; - rcp_spidrv_deassert_host_request(); - } + if (intNo == SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO) + { + transaction_active = true; + return; + } + else if (intNo == SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO) + { + // Must be done before calling the "complete_callback" since + // this callback will use otPlatSpiSlavePrepareTransaction who + // would not setup the buffers if a transaction is ongoing. + transaction_active = false; + rcp_spidrv_deassert_host_request(); + } - uint32_t tx_transaction_size = 0U; + uint32_t tx_transaction_size = 0U; - LDMA_StopTransfer(sl_spidrv_handle_data.txDMACh); + LDMA_StopTransfer(sl_spidrv_handle_data.txDMACh); - uint32_t tx_dma_channel_nb = sl_spidrv_handle_data.txDMACh; + uint32_t tx_dma_channel_nb = sl_spidrv_handle_data.txDMACh; - // Use the current loader DMA transfer struct to asses the number of transfered bytes. - uint32_t tx_dma_channel_remaining_xfercnt = (LDMA->CH[tx_dma_channel_nb].CTRL & _LDMA_CH_CTRL_XFERCNT_MASK) >> _LDMA_CH_CTRL_XFERCNT_SHIFT; - tx_dma_channel_remaining_xfercnt += 1U; - tx_dma_channel_remaining_xfercnt += (sl_spidrv_handle_data.peripheral.usartPort->STATUS & _USART_STATUS_TXBUFCNT_MASK) >> _USART_STATUS_TXBUFCNT_SHIFT; + // Use the current loader DMA transfer struct to asses the number of transfered bytes. + uint32_t tx_dma_channel_remaining_xfercnt = + (LDMA->CH[tx_dma_channel_nb].CTRL & _LDMA_CH_CTRL_XFERCNT_MASK) >> _LDMA_CH_CTRL_XFERCNT_SHIFT; + tx_dma_channel_remaining_xfercnt += 1U; + tx_dma_channel_remaining_xfercnt += + (sl_spidrv_handle_data.peripheral.usartPort->STATUS & _USART_STATUS_TXBUFCNT_MASK) + >> _USART_STATUS_TXBUFCNT_SHIFT; - uint32_t current_tx_descritor_link = (LDMA->CH[tx_dma_channel_nb].LINK & _LDMA_CH_LINK_LINK_MASK) >> _LDMA_CH_LINK_LINK_SHIFT; + uint32_t current_tx_descritor_link = + (LDMA->CH[tx_dma_channel_nb].LINK & _LDMA_CH_LINK_LINK_MASK) >> _LDMA_CH_LINK_LINK_SHIFT; - uint8_t *old_tx_buffer = (uint8_t*) tx_descriptor[0].xfer.srcAddr; - uint16_t old_tx_buffer_size = tx_descriptor[0].xfer.xferCnt + 1U; + uint8_t *old_tx_buffer = (uint8_t *)tx_descriptor[0].xfer.srcAddr; + uint16_t old_tx_buffer_size = tx_descriptor[0].xfer.xferCnt + 1U; - uint8_t *old_rx_buffer = (uint8_t*) rx_descriptor.xfer.dstAddr; - uint16_t old_rx_buffer_size = rx_descriptor.xfer.xferCnt + 1U; + uint8_t *old_rx_buffer = (uint8_t *)rx_descriptor.xfer.dstAddr; + uint16_t old_rx_buffer_size = rx_descriptor.xfer.xferCnt + 1U; - if (current_tx_descritor_link == 0U) { - // Since the link bit is not set in the tx dma channel descriptor the second tx descriptor was loaded. - tx_transaction_size = tx_descriptor[0].xfer.xferCnt + 1U; - tx_transaction_size += (tx_descriptor[1].xfer.xferCnt + 1U) - tx_dma_channel_remaining_xfercnt; - } else { - tx_transaction_size = (tx_descriptor[0].xfer.xferCnt - tx_dma_channel_remaining_xfercnt) + 1U; - } + if (current_tx_descritor_link == 0U) + { + // Since the link bit is not set in the tx dma channel descriptor the second tx descriptor was loaded. + tx_transaction_size = tx_descriptor[0].xfer.xferCnt + 1U; + tx_transaction_size += (tx_descriptor[1].xfer.xferCnt + 1U) - tx_dma_channel_remaining_xfercnt; + } + else + { + tx_transaction_size = (tx_descriptor[0].xfer.xferCnt - tx_dma_channel_remaining_xfercnt) + 1U; + } - // call's otPlatSpiSlavePrepareTransaction in the background, the DMA buffer's will be ready after this call. - if (complete_callback((void*) context, (uint8_t*) old_tx_buffer, old_tx_buffer_size, (uint8_t*) old_rx_buffer, old_rx_buffer_size, tx_transaction_size)) { - otSysEventSignalPending(); - should_process_transaction = true; - } + // call's otPlatSpiSlavePrepareTransaction in the background, the DMA buffer's will be ready after this call. + if (complete_callback((void *)context, + (uint8_t *)old_tx_buffer, + old_tx_buffer_size, + (uint8_t *)old_rx_buffer, + old_rx_buffer_size, + tx_transaction_size)) + { + otSysEventSignalPending(); + should_process_transaction = true; + } } -otError otPlatSpiSlaveEnable(otPlatSpiSlaveTransactionCompleteCallback aCompleteCallback, otPlatSpiSlaveTransactionProcessCallback aProcessCallback, void *aContext) +otError otPlatSpiSlaveEnable(otPlatSpiSlaveTransactionCompleteCallback aCompleteCallback, + otPlatSpiSlaveTransactionProcessCallback aProcessCallback, + void *aContext) { - CORE_DECLARE_IRQ_STATE; - otError error = OT_ERROR_NONE; + CORE_DECLARE_IRQ_STATE; + otError error = OT_ERROR_NONE; - // If driver was already configured, an error is returned. - otEXPECT_ACTION(complete_callback == NULL, error = OT_ERROR_ALREADY); - otEXPECT_ACTION(process_callback == NULL, error = OT_ERROR_ALREADY); - otEXPECT_ACTION(context == NULL, error = OT_ERROR_ALREADY); + // If driver was already configured, an error is returned. + otEXPECT_ACTION(complete_callback == NULL, error = OT_ERROR_ALREADY); + otEXPECT_ACTION(process_callback == NULL, error = OT_ERROR_ALREADY); + otEXPECT_ACTION(context == NULL, error = OT_ERROR_ALREADY); - CMU_ClockEnable(cmuClock_GPIO, true); + CMU_ClockEnable(cmuClock_GPIO, true); - SPIDRV_Init_t init_data = (SPIDRV_Init_t) - { - SL_NCP_SPIDRV_USART_PERIPHERAL, ///< The USART used for SPI. + SPIDRV_Init_t init_data = (SPIDRV_Init_t) + { + SL_NCP_SPIDRV_USART_PERIPHERAL, ///< The USART used for SPI. #if defined(_USART_ROUTELOC0_MASK) - SL_NCP_SPIDRV_USART_TX_LOC, ///< A location number for the SPI Tx pin. - SL_NCP_SPIDRV_USART_RX_LOC, ///< A location number for the SPI Rx pin. - SL_NCP_SPIDRV_USART_CLK_LOC, ///< A location number for the SPI Clk pin. - SL_NCP_SPIDRV_USART_CS_LOC, ///< A location number for the SPI Cs pin. + SL_NCP_SPIDRV_USART_TX_LOC, ///< A location number for the SPI Tx pin. + SL_NCP_SPIDRV_USART_RX_LOC, ///< A location number for the SPI Rx pin. + SL_NCP_SPIDRV_USART_CLK_LOC, ///< A location number for the SPI Clk pin. + SL_NCP_SPIDRV_USART_CS_LOC, ///< A location number for the SPI Cs pin. #elif defined(_GPIO_USART_ROUTEEN_MASK) - SL_NCP_SPIDRV_USART_TX_PORT, ///< Tx port. - SL_NCP_SPIDRV_USART_RX_PORT, ///< Rx port. - SL_NCP_SPIDRV_USART_CLK_PORT, ///< Clock port. - SL_NCP_SPIDRV_USART_CS_PORT, ///< Chip select port. - SL_NCP_SPIDRV_USART_TX_PIN, ///< Tx pin. - SL_NCP_SPIDRV_USART_RX_PIN, ///< Rx pin. - SL_NCP_SPIDRV_USART_CLK_PIN, ///< Clock pin. - SL_NCP_SPIDRV_USART_CS_PIN, ///< Chip select pin. + SL_NCP_SPIDRV_USART_TX_PORT, ///< Tx port. + SL_NCP_SPIDRV_USART_RX_PORT, ///< Rx port. + SL_NCP_SPIDRV_USART_CLK_PORT, ///< Clock port. + SL_NCP_SPIDRV_USART_CS_PORT, ///< Chip select port. + SL_NCP_SPIDRV_USART_TX_PIN, ///< Tx pin. + SL_NCP_SPIDRV_USART_RX_PIN, ///< Rx pin. + SL_NCP_SPIDRV_USART_CLK_PIN, ///< Clock pin. + SL_NCP_SPIDRV_USART_CS_PIN, ///< Chip select pin. #endif - 0U, ///< An SPI bitrate. - 8, ///< An SPI framelength, valid numbers are 4..16 - 0, ///< The value to transmit when using SPI receive API functions. - spidrvSlave, ///< An SPI type, slave. - SL_NCP_SPIDRV_USART_BIT_ORDER, ///< A bit order on the SPI bus, MSB or LSB first. - SL_NCP_SPIDRV_USART_CLOCK_MODE, ///< SPI mode, CLKPOL/CLKPHASE setting. - spidrvCsControlAuto, ///< A select master mode chip select (CS) control scheme. - spidrvSlaveStartImmediate, ///< A slave mode transfer start scheme. - }; - - otEXPECT_ACTION(SPIDRV_Init((SPIDRV_HandleData_t *)&sl_spidrv_handle_data, &init_data) == ECODE_EMDRV_SPIDRV_OK, error = OT_ERROR_FAILED); - - // Client callback functions. - complete_callback = aCompleteCallback; - process_callback = aProcessCallback; - context = aContext; - - // Client complete callback request foreground processing. - should_process_transaction = false; - - // SPI transaction status. - transaction_active = false; - - // TX default value. - default_tx_value = 0xFFU; - - // DMA transfer structures. - rx_dma_transfer_config = (LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL(SL_OT_SPIDRV_SPI_LDMA_RX_PERIPH_TRIGGER(SL_NCP_SPIDRV_USART_PERIPHERAL_NO)); - tx_dma_transfer_config = (LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL(SL_OT_SPIDRV_SPI_LDMA_TX_PERIPH_TRIGGER(SL_NCP_SPIDRV_USART_PERIPHERAL_NO)); - - rx_descriptor = (LDMA_Descriptor_t)LDMA_DESCRIPTOR_SINGLE_P2M_BYTE(&(sl_spidrv_handle_data.peripheral.usartPort->RXDATA), NULL, 1U); - rx_descriptor.xfer.doneIfs = 0U; - - tx_descriptor[0] = (LDMA_Descriptor_t)LDMA_DESCRIPTOR_LINKREL_M2P_BYTE(&default_tx_value, &(sl_spidrv_handle_data.peripheral.usartPort->TXDATA), 1, 1); - tx_descriptor[0].xfer.doneIfs = 0U; + 0U, ///< An SPI bitrate. + 8, ///< An SPI framelength, valid numbers are 4..16 + 0, ///< The value to transmit when using SPI receive API functions. + spidrvSlave, ///< An SPI type, slave. + SL_NCP_SPIDRV_USART_BIT_ORDER, ///< A bit order on the SPI bus, MSB or LSB first. + SL_NCP_SPIDRV_USART_CLOCK_MODE, ///< SPI mode, CLKPOL/CLKPHASE setting. + spidrvCsControlAuto, ///< A select master mode chip select (CS) control scheme. + spidrvSlaveStartImmediate, ///< A slave mode transfer start scheme. + }; + + otEXPECT_ACTION(SPIDRV_Init((SPIDRV_HandleData_t *)&sl_spidrv_handle_data, &init_data) == ECODE_EMDRV_SPIDRV_OK, + error = OT_ERROR_FAILED); + + // Client callback functions. + complete_callback = aCompleteCallback; + process_callback = aProcessCallback; + context = aContext; + + // Client complete callback request foreground processing. + should_process_transaction = false; - tx_descriptor[1] = (LDMA_Descriptor_t)LDMA_DESCRIPTOR_SINGLE_M2P_BYTE(&default_tx_value, &(sl_spidrv_handle_data.peripheral.usartPort->TXDATA), MAX_DMA_DESCRIPTOR_TRANSFER_COUNT); - tx_descriptor[1].xfer.srcInc = ldmaCtrlSrcIncNone; - tx_descriptor[1].xfer.doneIfs = 0U; + // SPI transaction status. + transaction_active = false; - // Configuring Host INT line. Active low + // TX default value. + default_tx_value = 0xFFU; + + // DMA transfer structures. + rx_dma_transfer_config = (LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL( + SL_OT_SPIDRV_SPI_LDMA_RX_PERIPH_TRIGGER(SL_NCP_SPIDRV_USART_PERIPHERAL_NO)); + tx_dma_transfer_config = (LDMA_TransferCfg_t)LDMA_TRANSFER_CFG_PERIPHERAL( + SL_OT_SPIDRV_SPI_LDMA_TX_PERIPH_TRIGGER(SL_NCP_SPIDRV_USART_PERIPHERAL_NO)); + + rx_descriptor = + (LDMA_Descriptor_t)LDMA_DESCRIPTOR_SINGLE_P2M_BYTE(&(sl_spidrv_handle_data.peripheral.usartPort->RXDATA), + NULL, + 1U); + rx_descriptor.xfer.doneIfs = 0U; + + tx_descriptor[0] = + (LDMA_Descriptor_t)LDMA_DESCRIPTOR_LINKREL_M2P_BYTE(&default_tx_value, + &(sl_spidrv_handle_data.peripheral.usartPort->TXDATA), + 1, + 1); + tx_descriptor[0].xfer.doneIfs = 0U; + + tx_descriptor[1] = + (LDMA_Descriptor_t)LDMA_DESCRIPTOR_SINGLE_M2P_BYTE(&default_tx_value, + &(sl_spidrv_handle_data.peripheral.usartPort->TXDATA), + MAX_DMA_DESCRIPTOR_TRANSFER_COUNT); + tx_descriptor[1].xfer.srcInc = ldmaCtrlSrcIncNone; + tx_descriptor[1].xfer.doneIfs = 0U; + + // Configuring Host INT line. Active low #if defined(SL_NCP_SPIDRV_USART_HOST_INT_PORT) && defined(SL_NCP_SPIDRV_USART_HOST_INT_PIN) - GPIO_PinModeSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN, gpioModePushPull, 1U); + GPIO_PinModeSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN, gpioModePushPull, 1U); #endif - GPIOINT_Init(); + GPIOINT_Init(); - GPIO_PinModeSet(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, gpioModeInputPullFilter, 1); + GPIO_PinModeSet(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, gpioModeInputPullFilter, 1); - CORE_ENTER_ATOMIC(); + CORE_ENTER_ATOMIC(); - // Initialization during transaction is not supported. - otEXPECT_ACTION(GPIO_PinInGet(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN) != 0U, error = OT_ERROR_FAILED); + // Initialization during transaction is not supported. + otEXPECT_ACTION(GPIO_PinInGet(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN) != 0U, + error = OT_ERROR_FAILED); - GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, true, false, true); - GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, false, true, true); + GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, + SL_NCP_SPIDRV_USART_CS_PIN, + SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, + true, + false, + true); + GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, + SL_NCP_SPIDRV_USART_CS_PIN, + SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, + false, + true, + true); - GPIOINT_CallbackRegister(SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, rcp_spidrv_spi_transaction_end_interrupt); - GPIOINT_CallbackRegister(SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, rcp_spidrv_spi_transaction_end_interrupt); + GPIOINT_CallbackRegister(SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, rcp_spidrv_spi_transaction_end_interrupt); + GPIOINT_CallbackRegister(SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, rcp_spidrv_spi_transaction_end_interrupt); - // Clear the usart RX/TX FIFO before configuring the dma transfers. - sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARTX | USART_CMD_CLEARRX; + // Clear the usart RX/TX FIFO before configuring the dma transfers. + sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARTX | USART_CMD_CLEARRX; - // Load the default value descriptor. - LDMA_StartTransfer(sl_spidrv_handle_data.txDMACh, (LDMA_TransferCfg_t*) &tx_dma_transfer_config, (LDMA_Descriptor_t*) &tx_descriptor[1]); + // Load the default value descriptor. + LDMA_StartTransfer(sl_spidrv_handle_data.txDMACh, + (LDMA_TransferCfg_t *)&tx_dma_transfer_config, + (LDMA_Descriptor_t *)&tx_descriptor[1]); #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); #endif - CORE_EXIT_ATOMIC(); + CORE_EXIT_ATOMIC(); - exit: - return error; +exit: + return error; } void otPlatSpiSlaveDisable(void) { - CORE_DECLARE_IRQ_STATE; - CORE_ENTER_ATOMIC(); - - // Disable CS GPIO IRQ. - GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, true, false, false); - GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, SL_NCP_SPIDRV_USART_CS_PIN, SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, false, true, false); - - GPIOINT_CallbackUnRegister(SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO); - GPIOINT_CallbackUnRegister(SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO); - - CORE_EXIT_ATOMIC(); - - // Stop any reception DMA transfers. - LDMA_StopTransfer(sl_spidrv_handle_data.txDMACh); - LDMA_StopTransfer(sl_spidrv_handle_data.rxDMACh); - - // Host INT line. - rcp_spidrv_deassert_host_request(); + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_ATOMIC(); + + // Disable CS GPIO IRQ. + GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, + SL_NCP_SPIDRV_USART_CS_PIN, + SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO, + true, + false, + false); + GPIO_ExtIntConfig(SL_NCP_SPIDRV_USART_CS_PORT, + SL_NCP_SPIDRV_USART_CS_PIN, + SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO, + false, + true, + false); + + GPIOINT_CallbackUnRegister(SL_NCP_SPIDRV_USART_CS_RISING_EDGE_INT_NO); + GPIOINT_CallbackUnRegister(SL_NCP_SPIDRV_USART_CS_FALLING_EDGE_INT_NO); + + CORE_EXIT_ATOMIC(); + + // Stop any reception DMA transfers. + LDMA_StopTransfer(sl_spidrv_handle_data.txDMACh); + LDMA_StopTransfer(sl_spidrv_handle_data.rxDMACh); + + // Host INT line. + rcp_spidrv_deassert_host_request(); #if defined(SL_NCP_SPIDRV_USART_HOST_INT_PORT) && defined(SL_NCP_SPIDRV_USART_HOST_INT_PIN) - GPIO_PinModeSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN, gpioModeInput, 0U); + GPIO_PinModeSet(SL_NCP_SPIDRV_USART_HOST_INT_PORT, SL_NCP_SPIDRV_USART_HOST_INT_PIN, gpioModeInput, 0U); #endif #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); + sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); #endif - should_process_transaction = false; - transaction_active = false; + should_process_transaction = false; + transaction_active = false; - complete_callback = NULL; - process_callback = NULL; - context = NULL; + complete_callback = NULL; + process_callback = NULL; + context = NULL; } -otError otPlatSpiSlavePrepareTransaction(uint8_t *aOutputBuf, uint16_t aOutputBufLen, uint8_t *aInputBuf, uint16_t aInputBufLen, bool aRequestTransactionFlag) +otError otPlatSpiSlavePrepareTransaction(uint8_t *aOutputBuf, + uint16_t aOutputBufLen, + uint8_t *aInputBuf, + uint16_t aInputBufLen, + bool aRequestTransactionFlag) { - CORE_DECLARE_IRQ_STATE; - CORE_ENTER_ATOMIC(); + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_ATOMIC(); - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; - otEXPECT_ACTION(!transaction_active, error = OT_ERROR_BUSY); - otEXPECT_ACTION(aOutputBufLen <= MAX_DMA_DESCRIPTOR_TRANSFER_COUNT, error = OT_ERROR_FAILED); - otEXPECT_ACTION(aInputBufLen <= MAX_DMA_DESCRIPTOR_TRANSFER_COUNT, error = OT_ERROR_FAILED); + otEXPECT_ACTION(!transaction_active, error = OT_ERROR_BUSY); + otEXPECT_ACTION(aOutputBufLen <= MAX_DMA_DESCRIPTOR_TRANSFER_COUNT, error = OT_ERROR_FAILED); + otEXPECT_ACTION(aInputBufLen <= MAX_DMA_DESCRIPTOR_TRANSFER_COUNT, error = OT_ERROR_FAILED); - uint32_t tx_dma_channel_number = sl_spidrv_handle_data.txDMACh; - uint32_t rx_dma_channel_number = sl_spidrv_handle_data.rxDMACh; + uint32_t tx_dma_channel_number = sl_spidrv_handle_data.txDMACh; + uint32_t rx_dma_channel_number = sl_spidrv_handle_data.rxDMACh; - if (aInputBuf != NULL) { - LDMA_StopTransfer(rx_dma_channel_number); - sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARRX; + if (aInputBuf != NULL) + { + LDMA_StopTransfer(rx_dma_channel_number); + sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARRX; - rx_descriptor.xfer.xferCnt = aInputBufLen - 1U; - rx_descriptor.xfer.dstAddr = (uint32_t) aInputBuf; + rx_descriptor.xfer.xferCnt = aInputBufLen - 1U; + rx_descriptor.xfer.dstAddr = (uint32_t)aInputBuf; - LDMA_StartTransfer(rx_dma_channel_number, (LDMA_TransferCfg_t*) &rx_dma_transfer_config, (LDMA_Descriptor_t*) &rx_descriptor); - } + LDMA_StartTransfer(rx_dma_channel_number, + (LDMA_TransferCfg_t *)&rx_dma_transfer_config, + (LDMA_Descriptor_t *)&rx_descriptor); + } - if (aOutputBuf != NULL) { - LDMA_StopTransfer(tx_dma_channel_number); - sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARTX; + if (aOutputBuf != NULL) + { + LDMA_StopTransfer(tx_dma_channel_number); + sl_spidrv_handle_data.peripheral.usartPort->CMD = USART_CMD_CLEARTX; - tx_descriptor[0].xfer.xferCnt = aOutputBufLen - 1U; - tx_descriptor[0].xfer.srcAddr = (uint32_t) aOutputBuf; + tx_descriptor[0].xfer.xferCnt = aOutputBufLen - 1U; + tx_descriptor[0].xfer.srcAddr = (uint32_t)aOutputBuf; - LDMA_StartTransfer(tx_dma_channel_number, (LDMA_TransferCfg_t*) &tx_dma_transfer_config, (LDMA_Descriptor_t*) &(tx_descriptor[0])); - } + LDMA_StartTransfer(tx_dma_channel_number, + (LDMA_TransferCfg_t *)&tx_dma_transfer_config, + (LDMA_Descriptor_t *)&(tx_descriptor[0])); + } - if (aRequestTransactionFlag) { - rcp_spidrv_set_host_request(); - } else { - rcp_spidrv_deassert_host_request(); - } + if (aRequestTransactionFlag) + { + rcp_spidrv_set_host_request(); + } + else + { + rcp_spidrv_deassert_host_request(); + } - exit: +exit: - CORE_EXIT_ATOMIC(); - return error; + CORE_EXIT_ATOMIC(); + return error; } void efr32SpiProcess(void) { - if (should_process_transaction) - { - if (context) { - process_callback((void*) context); + if (should_process_transaction) + { + if (context) + { + process_callback((void *)context); + } + + should_process_transaction = false; } - - should_process_transaction = false; - } } diff --git a/src/gsdk-pal/system.c b/src/gsdk-pal/system.c index fc1e71bf..02d44bf8 100644 --- a/src/gsdk-pal/system.c +++ b/src/gsdk-pal/system.c @@ -35,8 +35,8 @@ #include #include -#include #include "openthread-system.h" +#include #include "utils/uart.h" #include "common/logging.hpp" diff --git a/src/gsdk-pal/uartdrv_uart.c b/src/gsdk-pal/uartdrv_uart.c index 3d247711..d881642e 100644 --- a/src/gsdk-pal/uartdrv_uart.c +++ b/src/gsdk-pal/uartdrv_uart.c @@ -32,42 +32,42 @@ * */ - #ifdef SL_COMPONENT_CATALOG_PRESENT #include "sl_component_catalog.h" #endif // SL_COMPONENT_CATALOG_PRESENT -#include -#include +#include "em_core.h" #include "openthread-system.h" +#include "sl_uartdrv_instances.h" +#include "sl_uartdrv_usart_vcom_config.h" +#include "uartdrv.h" #include +#include +#include #include "utils/code_utils.h" #include "utils/uart.h" -#include "em_core.h" -#include "uartdrv.h" -#include "sl_uartdrv_instances.h" -#include "sl_uartdrv_usart_vcom_config.h" #include "ecode.h" -#include "sl_sleeptimer.h" -#include "sl_status.h" -#include "platform-efr32.h" #include "em_gpio.h" #include "gpiointerrupt.h" +#include "platform-efr32.h" +#include "sl_sleeptimer.h" +#include "sl_status.h" #ifdef SL_CATALOG_KERNEL_PRESENT -static unsigned int sGpioIntContext = 0; +static unsigned int sGpioIntContext = 0; static void gpioSerialWakeupCallback(uint8_t interrupt_no, void *context) { - unsigned int *pin = (unsigned int *)context; + unsigned int *pin = (unsigned int *)context; - (void)interrupt_no; + (void)interrupt_no; - if (*pin == SL_UARTDRV_USART_VCOM_RX_PIN) { - otSysEventSignalPending(); - } + if (*pin == SL_UARTDRV_USART_VCOM_RX_PIN) + { + otSysEventSignalPending(); + } } #endif // SL_CATALOG_KERNEL_PRESENT @@ -79,10 +79,10 @@ enum // In order to reduce the probability of data loss due to disabled interrupts, we use // two duplicate receive buffers so we can always have one "active" receive request. #define RECEIVE_BUFFER_SIZE 128 -static uint8_t sReceiveBuffer1[RECEIVE_BUFFER_SIZE]; -static uint8_t sReceiveBuffer2[RECEIVE_BUFFER_SIZE]; -static uint8_t lastCount = 0; -static volatile bool sTxComplete = false; +static uint8_t sReceiveBuffer1[RECEIVE_BUFFER_SIZE]; +static uint8_t sReceiveBuffer2[RECEIVE_BUFFER_SIZE]; +static uint8_t lastCount = 0; +static volatile bool sTxComplete = false; typedef struct ReceiveFifo_t { @@ -108,7 +108,7 @@ static void receiveDone(UARTDRV_Handle_t aHandle, Ecode_t aStatus, uint8_t *aDat { memcpy(sReceiveFifo.mBuffer + sReceiveFifo.mTail, aData + lastCount, aCount - lastCount); sReceiveFifo.mTail = (sReceiveFifo.mTail + aCount - lastCount) % kReceiveFifoSize; - lastCount = 0; + lastCount = 0; } UARTDRV_Receive(aHandle, aData, aCount, receiveDone); @@ -129,17 +129,14 @@ static void transmitDone(UARTDRV_Handle_t aHandle, Ecode_t aStatus, uint8_t *aDa static void processReceive(void) { - uint8_t *aData; + uint8_t *aData; UARTDRV_Count_t aCount, remaining; - CORE_ATOMIC_SECTION( - UARTDRV_GetReceiveStatus(sl_uartdrv_usart_vcom_handle, &aData, &aCount, &remaining); - if (aCount > lastCount) - { - memcpy(sReceiveFifo.mBuffer + sReceiveFifo.mTail, aData + lastCount, aCount - lastCount); - sReceiveFifo.mTail = (sReceiveFifo.mTail + aCount - lastCount) % kReceiveFifoSize; - lastCount = aCount; - } - ) + CORE_ATOMIC_SECTION(UARTDRV_GetReceiveStatus(sl_uartdrv_usart_vcom_handle, &aData, &aCount, &remaining); + if (aCount > lastCount) { + memcpy(sReceiveFifo.mBuffer + sReceiveFifo.mTail, aData + lastCount, aCount - lastCount); + sReceiveFifo.mTail = (sReceiveFifo.mTail + aCount - lastCount) % kReceiveFifoSize; + lastCount = aCount; + }) // Copy tail to prevent multiple reads uint16_t tail = sReceiveFifo.mTail; @@ -183,7 +180,7 @@ void efr32UartProcess(void) otError otPlatUartEnable(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; #ifdef SL_CATALOG_KERNEL_PRESENT unsigned int intNo; @@ -193,18 +190,16 @@ otError otPlatUartEnable(void) sGpioIntContext = SL_UARTDRV_USART_VCOM_RX_PIN; intNo = GPIOINT_CallbackRegisterExt(SL_UARTDRV_USART_VCOM_RX_PIN, gpioSerialWakeupCallback, &sGpioIntContext); - otEXPECT_ACTION(intNo != INTERRUPT_UNAVAILABLE, error = OT_ERROR_FAILED); - GPIO_ExtIntConfig(SL_UARTDRV_USART_VCOM_RX_PORT, - SL_UARTDRV_USART_VCOM_RX_PIN, - intNo, false, true, true); + GPIO_ExtIntConfig(SL_UARTDRV_USART_VCOM_RX_PORT, SL_UARTDRV_USART_VCOM_RX_PIN, intNo, false, true, true); #endif sReceiveFifo.mHead = 0; sReceiveFifo.mTail = 0; - // When one receive request is completed, the other buffer is used for a separate receive request, issued immediately. + // When one receive request is completed, the other buffer is used for a separate receive request, issued + // immediately. UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, sReceiveBuffer1, RECEIVE_BUFFER_SIZE, receiveDone); UARTDRV_Receive(sl_uartdrv_usart_vcom_handle, sReceiveBuffer2, RECEIVE_BUFFER_SIZE, receiveDone); @@ -222,7 +217,7 @@ otError otPlatUartDisable(void) static void flushTimeoutAlarmCallback(sl_sleeptimer_timer_handle_t *aHandle, void *aData) { OT_UNUSED_VARIABLE(aHandle); - *(bool*)aData = true; + *(bool *)aData = true; } otError otPlatUartFlush(void) @@ -233,8 +228,11 @@ otError otPlatUartFlush(void) sl_sleeptimer_timer_handle_t flushTimer; // Start flush timeout timer - status = sl_sleeptimer_start_timer_ms(&flushTimer, OPENTHREAD_CONFIG_EFR32_UART_TX_FLUSH_TIMEOUT_MS, - flushTimeoutAlarmCallback, (void*)&flushTimedOut, 0, + status = sl_sleeptimer_start_timer_ms(&flushTimer, + OPENTHREAD_CONFIG_EFR32_UART_TX_FLUSH_TIMEOUT_MS, + flushTimeoutAlarmCallback, + (void *)&flushTimedOut, + 0, SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG); otEXPECT_ACTION(status == SL_STATUS_OK, error = OT_ERROR_FAILED); @@ -247,9 +245,9 @@ otError otPlatUartFlush(void) { // Check both peripheral status and queue depth transmitQueueDepth = UARTDRV_GetTransmitDepth(sl_uartdrv_usart_vcom_handle); - uartIdle = (UARTDRV_GetPeripheralStatus(sl_uartdrv_usart_vcom_handle) - & (UARTDRV_STATUS_TXIDLE | UARTDRV_STATUS_TXC)); - uartFullyFlushed = uartIdle && (transmitQueueDepth == 0); + uartIdle = + (UARTDRV_GetPeripheralStatus(sl_uartdrv_usart_vcom_handle) & (UARTDRV_STATUS_TXIDLE | UARTDRV_STATUS_TXC)); + uartFullyFlushed = uartIdle && (transmitQueueDepth == 0); } while (!uartFullyFlushed && !flushTimedOut); sl_sleeptimer_stop_timer(&flushTimer);