diff --git a/examples/Makefile-cc2538 b/examples/Makefile-cc2538 index 7bcd64dd1..0b8abe6d8 100644 --- a/examples/Makefile-cc2538 +++ b/examples/Makefile-cc2538 @@ -113,6 +113,10 @@ ifneq ($(CC2538_RECEIVE_SENSITIVITY),) COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY=$(CC2538_RECEIVE_SENSITIVITY) endif +ifneq ($(CC2538_RSSI_OFFSET),) +COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2538_RSSI_OFFSET=$(CC2538_RSSI_OFFSET) +endif + CPPFLAGS += \ $(COMMONCFLAGS) \ $(target_CPPFLAGS) \ diff --git a/examples/platforms/cc2538/README.md b/examples/platforms/cc2538/README.md index 64c6d31ae..77675576a 100644 --- a/examples/platforms/cc2538/README.md +++ b/examples/platforms/cc2538/README.md @@ -72,6 +72,9 @@ Additional settings can be customised: * `CC2538_RECEIVE_SENSITIVITY`: If you have tied the HGM pin to a power rail, this allows you to calibrate the RSSI values according to the new receive sensitivity. This has no effect if `CC2592_USE_HGM=1` (the default). +* `CC2538_RSSI_OFFSET`: If you have tied the HGM pin to a power rail, this allows + you to calibrate the RSSI values according to the new RSSI offset. This has no + effect if `CC2592_USE_HGM=1` (the default). ## Flash Binaries diff --git a/examples/platforms/cc2538/openthread-core-cc2538-config.h b/examples/platforms/cc2538/openthread-core-cc2538-config.h index 2e08d1b8f..5a468261b 100644 --- a/examples/platforms/cc2538/openthread-core-cc2538-config.h +++ b/examples/platforms/cc2538/openthread-core-cc2538-config.h @@ -184,6 +184,22 @@ #define OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY -88 #endif +/** + * @def OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET + * + * Set the CC2538 RSSI offset. This calibrates the RSSI readings received from + * the CC2538 radio module to give a reading in dBm. + * + * For a standard CC2538 (no front-end), the RSSI offset is 73. + * + * For a CC2592 hard-wired in high-gain mode, an offset of 85 should be used; + * or for low-gain mode, 81. If `OPENTHREAD_CONFIG_CC2592_USE_HGM` is 0, then + * this calibrates the RSSI value accordingly. + */ +#ifndef OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET +#define OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET 73 +#endif + /** * @def OPENTHREAD_CONFIG_CC2592_HGM_PORT * diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c index 31bb10e82..884433a3e 100644 --- a/examples/platforms/cc2538/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -101,17 +101,21 @@ enum enum { - CC2538_RSSI_OFFSET = 73, - CC2538_CRC_BIT_MASK = 0x80, - CC2538_LQI_BIT_MASK = 0x7f, + CC2538_RSSI_OFFSET = OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET, + // TI AN130 (SWRA447) Table 4 (bottom of page 3) + CC2592_RSSI_OFFSET_HGM = 85, + CC2592_RSSI_OFFSET_LGM = 81, + CC2538_CRC_BIT_MASK = 0x80, + CC2538_LQI_BIT_MASK = 0x7f, }; // All values in dBm enum { - CC2538_RECEIVE_SENSITIVITY = OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY, - CC2592_RECEIVE_SENSITIVITY_LGM = -81, - CC2592_RECEIVE_SENSITIVITY_HGM = -85, + CC2538_RECEIVE_SENSITIVITY = OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY, + // TI AN130 (SWRA447) Table 3 (middle of page 3) + CC2592_RECEIVE_SENSITIVITY_LGM = -99, + CC2592_RECEIVE_SENSITIVITY_HGM = -101, }; typedef struct TxPowerTable @@ -613,6 +617,22 @@ bool otPlatRadioGetPromiscuous(otInstance *aInstance) return (HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0; } +static int8_t cc2538RadioGetRssiOffset(void) +{ +#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM + if (cc2538RadioGetHgm()) + { + return CC2592_RSSI_OFFSET_HGM; + } + else + { + return CC2592_RSSI_OFFSET_LGM; + } +#else // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM + return CC2538_RSSI_OFFSET; +#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM +} + void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) { OT_UNUSED_VARIABLE(aInstance); @@ -655,7 +675,7 @@ void readFrame(otInstance *aInstance) sReceiveFrame.mPsdu[i] = HWREG(RFCORE_SFR_RFDATA); } - sReceiveFrame.mInfo.mRxInfo.mRssi = (int8_t)HWREG(RFCORE_SFR_RFDATA) - CC2538_RSSI_OFFSET; + sReceiveFrame.mInfo.mRxInfo.mRssi = (int8_t)HWREG(RFCORE_SFR_RFDATA) - cc2538RadioGetRssiOffset(); crcCorr = HWREG(RFCORE_SFR_RFDATA); if (crcCorr & CC2538_CRC_BIT_MASK)