Skip to content

Instantly share code, notes, and snippets.

@sjlongland
Created November 24, 2017 09:02
Show Gist options
  • Save sjlongland/192f74feb04cbce7c5929c91021f2cfa to your computer and use it in GitHub Desktop.
Save sjlongland/192f74feb04cbce7c5929c91021f2cfa to your computer and use it in GitHub Desktop.
OpenThread CC2538 TX issue, possible fix
stuartl@vk4msl-ws ~/vrt/projects/widesky/hub/hal $ diff -u third_party/openthread/examples/platforms/cc2538/radio.c src/radio.c
--- third_party/openthread/examples/platforms/cc2538/radio.c 2017-08-01 12:48:31.466864595 +1000
+++ src/radio.c 2017-11-24 18:56:04.074493486 +1000
@@ -73,23 +73,20 @@
uint8_t mTxPowerReg;
} TxPowerTable;
-// The transmit power table, the values are from SmartRF Studio 2.4.0
+// The transmit power table, the values are from application note 130
static const TxPowerTable sTxPowerTable[] =
{
- { 7, 0xFF },
- { 5, 0xED },
- { 3, 0xD5 },
- { 1, 0xC5 },
- { 0, 0xB6 },
- { -1, 0xB0 },
- { -3, 0xA1 },
- { -5, 0x91 },
- { -7, 0x88 },
- { -9, 0x72 },
- { -11, 0x62 },
- { -13, 0x58 },
- { -15, 0x42 },
- { -24, 0x00 },
+ { 22, 0xFF }, /* 22.0dBm =~ 158.5mW */
+ { 21, 0xD5 }, /* 20.9dBm =~ 123.0mW */
+ { 20, 0xC5 }, /* 20.1dBm =~ 102.3mW */
+ { 19, 0xB0 }, /* 19.0dBm =~ 79.4mW */
+ { 18, 0xA1 }, /* 17.8dBm =~ 60.3mW */
+ { 16, 0x91 }, /* 16.4dBm =~ 43.7mW */
+ { 15, 0x88 }, /* 14.9dBm =~ 30.9mW */
+ { 13, 0x72 }, /* 13.0dBm =~ 20.0mW */
+ { 11, 0x62 }, /* 11.0dBm =~ 12.6mW */
+ { 10, 0x58 }, /* 9.5dBm =~ 8.9mW */
+ { 8, 0x42 }, /* 7.5dBm =~ 5.6mW */
};
static otRadioFrame sTransmitFrame;
@@ -105,6 +102,8 @@
static otRadioState sState = OT_RADIO_STATE_DISABLED;
static bool sIsReceiverEnabled = false;
+#define RFCORE_XREG_FSMSTAT0 0x40088648
+
void enableReceiver(void)
{
if (!sIsReceiverEnabled)
@@ -340,6 +339,14 @@
sState = OT_RADIO_STATE_TRANSMIT;
sTransmitError = OT_ERROR_NONE;
+ while ((HWREG(RFCORE_XREG_FSMSTAT0) & 0x3f) == 0x11) {
+ /* We're in RX overrun, flush buffer */
+ otLogCritPlat(sInstance, "RX buffer overrun, aborting TX (FSMSTAT1=0x%08x)",
+ HWREG(RFCORE_XREG_FSMSTAT1));
+ HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX;
+ HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX;
+ }
+
while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
// flush txfifo
@@ -358,7 +365,33 @@
setChannel(aFrame->mChannel);
setTxPower(aFrame->mPower);
- while ((HWREG(RFCORE_XREG_FSMSTAT1) & 1) == 0);
+#ifdef RADIO_TIMEOUT
+ i = RADIO_TIMEOUT;
+#endif
+ while ((HWREG(RFCORE_XREG_FSMSTAT1) & 1) == 0) {
+#ifdef RADIO_TIMEOUT
+ if (!i) {
+ otLogCritPlat(sInstance,
+ "Transmitter is stuck!!! FSMSTAT0=0x%08x FSMSTAT1=0x%08x",
+ HWREG(RFCORE_XREG_FSMSTAT0), HWREG(RFCORE_XREG_FSMSTAT1));
+ i = RADIO_TIMEOUT;
+ } else {
+ i--;
+ }
+#endif
+
+ switch (HWREG(RFCORE_XREG_FSMSTAT0) & 0x3f) {
+ case 0x11:
+ /* We're in RX overrun, flush buffer and abort */
+ otLogCritPlat(sInstance, "RX buffer overrun, aborting TX (FSMSTAT1=0x%08x)",
+ HWREG(RFCORE_XREG_FSMSTAT1));
+ HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX;
+ HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX;
+ return OT_ERROR_FAILED;
+ default:
+ break;
+ }
+ }
// wait for valid rssi
while ((HWREG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) == 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment