From 33b079893edcca535fbb170e76b78a803fb14ad9 Mon Sep 17 00:00:00 2001 From: Seth Rickard Date: Thu, 11 May 2017 22:15:06 -0700 Subject: [PATCH] implement radio stub functions and catch up on technical debt (#1763) --- examples/platforms/cc2650/crypto/sha256_alt.c | 15 ++++- examples/platforms/cc2650/platform.c | 17 +++++- examples/platforms/cc2650/radio.c | 61 +++++++++++++++++-- examples/platforms/cc2650/random.c | 15 ----- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/examples/platforms/cc2650/crypto/sha256_alt.c b/examples/platforms/cc2650/crypto/sha256_alt.c index df51bb949..1f3e794bc 100644 --- a/examples/platforms/cc2650/crypto/sha256_alt.c +++ b/examples/platforms/cc2650/crypto/sha256_alt.c @@ -85,6 +85,8 @@ void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *inp SHA256_execute(ctx, (uint8_t *)input, (uint32_t)ilen); } +char *workaround_cc2650_rom; + /** * documented in sha256_alt.h */ @@ -94,10 +96,19 @@ void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32] * Allocate an extra 64 bytes on the stack to make sure we have buffer * room. This could be optomized out if you never call this function with * a call stack shorter than 16 words, approx. 8 stack frames. + * + * The simple description is this: + * If the stack pointer is within 64bytes of the end of RAM + * the bug exposes it self. + * If the stack pointer is more then 64bytes from end of RAM + * There is no bug... + * Solution: + * Make a 64byte buffer on the stack.. + * And force the compiler to think it requires this buffer. */ - __asm("sub sp, #0x40 "); + char buffer[ 64 ]; + workaround_cc2650_rom = &buffer[0]; SHA256_output(ctx, (uint8_t *)output); - __asm("add sp, #0x40 "); return; } diff --git a/examples/platforms/cc2650/platform.c b/examples/platforms/cc2650/platform.c index b036f704e..b98bc315a 100644 --- a/examples/platforms/cc2650/platform.c +++ b/examples/platforms/cc2650/platform.c @@ -26,10 +26,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include "platform-cc2650.h" -otInstance *sInstance; +extern const char __ccfg[]; + +const char *dummy_ccfg_ref = ((const char *)(&(__ccfg[0]))); /** * Function documented in platform-cc2650.h @@ -38,6 +41,16 @@ void PlatformInit(int argc, char *argv[]) { (void) argc; (void) argv; + + while (dummy_ccfg_ref == NULL) + { + /* + * This provides a code reference to the customer configuration + * area of the flash, otherwise the data is skipped by the + * linker and not put into the final flash image. + */ + } + cc2650AlarmInit(); cc2650RandomInit(); cc2650RadioInit(); @@ -48,8 +61,6 @@ void PlatformInit(int argc, char *argv[]) */ void PlatformProcessDrivers(otInstance *aInstance) { - sInstance = aInstance; - // should sleep and wait for interrupts here cc2650UartProcess(); diff --git a/examples/platforms/cc2650/radio.c b/examples/platforms/cc2650/radio.c index fb273696d..0e7e3641b 100644 --- a/examples/platforms/cc2650/radio.c +++ b/examples/platforms/cc2650/radio.c @@ -1219,11 +1219,28 @@ exit: return error; } +/** + * Function documented in platform/radio.h + */ void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) { - // TODO: Create a proper implementation for this driver. + unsigned int i; + output_config_t const *powerCfg = &(rgOutputPower[0]); (void)aInstance; - (void)aPower; + + for (i = 1; i < OUTPUT_CONFIG_COUNT; i++) + { + if (rgOutputPower[i].dbm >= aPower) + { + powerCfg = &(rgOutputPower[i]); + } + else + { + break; + } + } + + sCurrentOutputPower = powerCfg; } /** @@ -1513,7 +1530,25 @@ exit: void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance) { (void)aInstance; - // TODO - This function needs to be implemented + + if (sReceiveCmd.status == ACTIVE || sReceiveCmd.status == IEEE_SUSPENDED) + { + unsigned int i; + + for (i = 0; i < CC2650_SHORTADD_SRC_MATCH_NUM; i++) + { + /* we have a running or backgrounded rx command */ + otEXPECT(rfCoreModifySourceMatchEntry(i, SHORT_ADDRESS, false) == CMDSTA_Done); + } + } + else + { + /* we are not running, so we can erase them ourselves */ + memset((void *)&sSrcMatchShortData, 0, sizeof(sSrcMatchShortData)); + } + +exit: + return; } /** @@ -1522,7 +1557,25 @@ void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance) void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance) { (void)aInstance; - // TODO - This function needs to be implemented + + if (sReceiveCmd.status == ACTIVE || sReceiveCmd.status == IEEE_SUSPENDED) + { + unsigned int i; + + for (i = 0; i < CC2650_EXTADD_SRC_MATCH_NUM; i++) + { + /* we have a running or backgrounded rx command */ + otEXPECT(rfCoreModifySourceMatchEntry(i, EXT_ADDRESS, false) == CMDSTA_Done); + } + } + else + { + /* we are not running, so we can erase them ourselves */ + memset((void *)&sSrcMatchExtData, 0, sizeof(sSrcMatchExtData)); + } + +exit: + return; } /** diff --git a/examples/platforms/cc2650/random.c b/examples/platforms/cc2650/random.c index 6ab612456..962fe38f1 100644 --- a/examples/platforms/cc2650/random.c +++ b/examples/platforms/cc2650/random.c @@ -135,18 +135,3 @@ exit: return error; } -/** - * Entropy function for the entropy pool in mbedtls. - * - * Function defined in mbedtls/entropy_poll.h . - */ -int mbedtls_hardware_poll(void *data, unsigned char *aOutput, size_t aLen, size_t *oLen) -{ - ThreadError error; - - (void)data; - error = TRNGPoll(aOutput, aLen); - *oLen = aLen; - - return error; -}