From 946b72a58dc21569cd173e10b96318b1c10f0728 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Nov 2015 20:46:46 +0000 Subject: [PATCH 1/3] Mask CMDSTA when waiting for a command to get accepted --- cpu/cc26xx-cc13xx/rf-core/rf-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/cpu/cc26xx-cc13xx/rf-core/rf-core.c index 45387ab42..248d66a73 100644 --- a/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/cpu/cc26xx-cc13xx/rf-core/rf-core.c @@ -159,7 +159,7 @@ rf_core_send_cmd(uint32_t cmd, uint32_t *status) HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDR) = cmd; do { - *status = HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA); + *status = HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA) & 0xFF; if(++timeout_count > 50000) { PRINTF("rf_core_send_cmd: 0x%08lx Timeout\n", cmd); if(!interrupts_disabled) { From 1ee40ef02166339a38e7fe6746f8d4c2f67f17c6 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Nov 2015 20:48:28 +0000 Subject: [PATCH 2/3] Fix the logic that detects whether a command is a Radio OP --- cpu/cc26xx-cc13xx/rf-core/rf-core.c | 14 +++++++++++--- cpu/cc26xx-cc13xx/rf-core/rf-core.h | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/cpu/cc26xx-cc13xx/rf-core/rf-core.c index 248d66a73..791fa1f53 100644 --- a/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/cpu/cc26xx-cc13xx/rf-core/rf-core.c @@ -129,10 +129,18 @@ rf_core_send_cmd(uint32_t cmd, uint32_t *status) bool interrupts_disabled; bool is_radio_op = false; - /* If cmd is 4-byte aligned, then it's a radio OP. Clear the status field */ + /* + * If cmd is 4-byte aligned, then it's either a radio OP or an immediate + * command. Clear the status field if it's a radio OP + */ if((cmd & 0x03) == 0) { - is_radio_op = true; - ((rfc_radioOp_t *)cmd)->status = RF_CORE_RADIO_OP_STATUS_IDLE; + uint32_t cmd_type; + cmd_type = ((rfc_command_t *)cmd)->commandNo & RF_CORE_COMMAND_TYPE_MASK; + if(cmd_type == RF_CORE_COMMAND_TYPE_IEEE_FG_RADIO_OP || + cmd_type == RF_CORE_COMMAND_TYPE_RADIO_OP) { + is_radio_op = true; + ((rfc_radioOp_t *)cmd)->status = RF_CORE_RADIO_OP_STATUS_IDLE; + } } /* diff --git a/cpu/cc26xx-cc13xx/rf-core/rf-core.h b/cpu/cc26xx-cc13xx/rf-core/rf-core.h index 7cf0b10e8..42c6edb90 100644 --- a/cpu/cc26xx-cc13xx/rf-core/rf-core.h +++ b/cpu/cc26xx-cc13xx/rf-core/rf-core.h @@ -218,7 +218,6 @@ typedef struct rf_core_primary_mode_s { /*---------------------------------------------------------------------------*/ /* Command Types */ #define RF_CORE_COMMAND_TYPE_MASK 0x0C00 -#define RF_CORE_COMMAND_TYPE_IMMEDIATE 0x0000 #define RF_CORE_COMMAND_TYPE_RADIO_OP 0x0800 #define RF_CORE_COMMAND_TYPE_IEEE_BG_RADIO_OP 0x0800 #define RF_CORE_COMMAND_TYPE_IEEE_FG_RADIO_OP 0x0C00 From f401c7cc607882082ef6219fe2bbf76ef9e9b034 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Nov 2015 20:48:53 +0000 Subject: [PATCH 3/3] Save new TX power setting even if the RFC is powered off. The current logic attempts to send `CMD_SET_TX_POWER` before saving the new power setting. If `CMD_SET_TX_POWER` fails the power setting will not get saved. As a result, when the RFC is powered off, all attempts to change TX power will fail. This commit changes this logic to always save the new TX setting as requested by the user. If the RFC is powered up, we apply it immediately. If it is powered down, the new setting will automatically be applied next time we send `CMD_RADIO_SETUP`. Fixes #1340 --- cpu/cc26xx-cc13xx/rf-core/ieee-mode.c | 39 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c b/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c index b5b5cf4c1..4cfeb3a3e 100644 --- a/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c +++ b/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c @@ -401,26 +401,33 @@ set_tx_power(radio_value_t power) int i; rfc_CMD_SET_TX_POWER_t cmd; - /* Send a CMD_SET_TX_POWER command to the RF */ - memset(&cmd, 0x00, sizeof(cmd)); - - cmd.commandNo = CMD_SET_TX_POWER; - + /* First, find the correct setting and save it */ for(i = OUTPUT_CONFIG_COUNT - 1; i >= 0; --i) { if(power <= output_power[i].dbm) { - cmd.txPower.IB = output_power[i].register_ib; - cmd.txPower.GC = output_power[i].register_gc; - cmd.txPower.tempCoeff = output_power[i].temp_coeff; - - if(rf_core_send_cmd((uint32_t)&cmd, &cmd_status) == RF_CORE_CMD_OK) { - /* Success: Remember the new setting */ - tx_power_current = &output_power[i]; - } else { - PRINTF("set_tx_power: CMDSTA=0x%08lx\n", cmd_status); - } - return; + tx_power_current = &output_power[i]; + break; } } + + /* + * If the core is not accessible, the new setting will be applied next + * time we send CMD_RADIO_SETUP, so we don't need to do anything further. + * If the core is accessible, we can apply the new setting immediately with + * CMD_SET_TX_POWER + */ + if(rf_core_is_accessible() == RF_CORE_NOT_ACCESSIBLE) { + return; + } + + memset(&cmd, 0x00, sizeof(cmd)); + cmd.commandNo = CMD_SET_TX_POWER; + cmd.txPower.IB = output_power[i].register_ib; + cmd.txPower.GC = output_power[i].register_gc; + cmd.txPower.tempCoeff = output_power[i].temp_coeff; + + if(rf_core_send_cmd((uint32_t)&cmd, &cmd_status) == RF_CORE_CMD_ERROR) { + PRINTF("set_tx_power: CMDSTA=0x%08lx\n", cmd_status); + } } /*---------------------------------------------------------------------------*/ static uint8_t