From 5f76ff996bb5308cdafbe02aeb021a01112a39ae Mon Sep 17 00:00:00 2001 From: Ryan Kurte Date: Fri, 6 Oct 2017 15:17:31 +1300 Subject: [PATCH 1/3] Threaded wrapper for rail driver on EFR32 platforms Updated NanostackRfPhyEfr32 with a receive queue. Cleaned up debug messages, re-added to non-threaded calls. Removed debug print override Removed tr_debug override Removed normal-operation prints that could have timing implications if enabled Removed dead NVIC code (and a couple of dead log outputs) --- .../TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp | 198 ++++++++++++++++-- 1 file changed, 176 insertions(+), 22 deletions(-) diff --git a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp index 875abbb48a7..5b9805bf0a9 100644 --- a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp +++ b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include "NanostackRfPhyEfr32.h" +#include "mbed.h" #include "ns_types.h" #include "platform/arm_hal_interrupt.h" #include "nanostack/platform/arm_hal_phy.h" @@ -23,6 +24,38 @@ #include "mbed-trace/mbed_trace.h" #define TRACE_GROUP "SLRF" +#ifndef RF_THREAD_STACK_SIZE +#define RF_THREAD_STACK_SIZE 1024 +#endif + +#ifndef RF_QUEUE_SIZE +#define RF_QUEUE_SIZE 8 +#endif + +enum RFThreadSignal { + SL_RX_DONE = (1 << 1), + SL_TX_DONE = (1 << 2), + SL_TX_ERR = (1 << 3), + SL_TX_TIMEOUT = (1 << 4), + SL_ACK_RECV = (1 << 5), + SL_ACK_TIMEOUT = (1 << 6), + SL_TXFIFO_ERR = (1 << 7), + SL_RXFIFO_ERR = (1 << 8), + SL_CAL_REQ = (1 << 9), + SL_RSSI_DONE = (1 << 10), + SL_QUEUE_FULL = (1 << 11), + + SL_ACK_PEND = (1 << 31), +}; + +static void rf_thread_loop(const void *arg); +static osThreadDef(rf_thread_loop, osPriorityRealtime, RF_THREAD_STACK_SIZE); +static osThreadId rf_thread_id; + +static volatile void* rx_queue[8]; +static volatile size_t rx_queue_head; +static volatile size_t rx_queue_tail; + /* Silicon Labs headers */ extern "C" { #include "rail/rail.h" @@ -64,10 +97,11 @@ typedef enum { static const RAIL_CsmaConfig_t csma_config = RAIL_CSMA_CONFIG_802_15_4_2003_2p4_GHz_OQPSK_CSMA; -#if defined(TARGET_EFR32MG1) +#if defined(TARGET_EFR32MG1) || defined(TARGET_EFR32FG1) #include "ieee802154_subg_efr32xg1_configurator_out.h" #include "ieee802154_efr32xg1_configurator_out.h" -#elif defined(TARGET_EFR32MG12) +#elif defined(TARGET_EFR32MG12) || defined(TARGET_EFR32FG12) +#include "ieee802154_efr32xg12_configurator_out.h" #include "ieee802154_efr32xg12_configurator_out.h" #else #error "Not a valid target." @@ -152,6 +186,76 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h /* Local function prototypes */ static bool rail_checkAndSwitchChannel(uint8_t channel); +static void rf_thread_loop(const void *arg) +{ + tr_debug("rf_thread_loop: starting (id: %d)\n", rf_thread_id); + for (;;) { + osEvent event = osSignalWait(0, osWaitForever); + + if (event.status != osEventSignal) { + continue; + } + + platform_enter_critical(); + + if (event.value.signals & SL_RX_DONE) { + while(rx_queue_tail != rx_queue_head) { + void* handle = (void*) rx_queue[rx_queue_tail]; + RAIL_RxPacketInfo_t* info = (RAIL_RxPacketInfo_t*) memoryPtrFromHandle(handle); + device_driver.phy_rx_cb( + info->dataPtr + 1, + info->dataLength - 1, + info->appendedInfo.lqi, + info->appendedInfo.rssiLatch, + rf_radio_driver_id); + + memoryFree(handle); + rx_queue[rx_queue_tail] = NULL; + + rx_queue_tail = (rx_queue_tail + 1) % RF_QUEUE_SIZE; + } + + } else if (event.value.signals & SL_TX_DONE) { + device_driver.phy_tx_done_cb(rf_radio_driver_id, + current_tx_handle, + PHY_LINK_TX_SUCCESS, + 1, + 1); + } else if (event.value.signals & SL_ACK_RECV) { + device_driver.phy_tx_done_cb( rf_radio_driver_id, + current_tx_handle, + (event.value.signals & SL_ACK_PEND) ? PHY_LINK_TX_DONE_PENDING : PHY_LINK_TX_DONE, + 1, + 1); + } else if (event.value.signals & SL_ACK_TIMEOUT) { + waiting_for_ack = false; + device_driver.phy_tx_done_cb(rf_radio_driver_id, + current_tx_handle, + PHY_LINK_TX_FAIL, + 1, + 1); + } else if(event.value.signals & SL_TX_ERR) { + device_driver.phy_tx_done_cb( rf_radio_driver_id, + current_tx_handle, + PHY_LINK_CCA_FAIL, + 8, + 1); + } else if(event.value.signals & SL_CAL_REQ) { + tr_debug("rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n"); + } else if(event.value.signals & SL_RXFIFO_ERR) { + tr_debug("rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n"); + } else if(event.value.signals & SL_TXFIFO_ERR) { + tr_debug("rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n"); + } else if(event.value.signals & SL_QUEUE_FULL) { + tr_debug("rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n"); + } else { + tr_debug("rf_thread_loop unhandled event status: %d value: %d\n", event.status, event.value.signals); + } + + platform_exit_critical(); + } +} + /*============ CODE =========*/ /* @@ -168,6 +272,8 @@ static int8_t rf_device_register(void) return -1; } + tr_debug("rf_device_register: entry\n"); + #if MBED_CONF_SL_RAIL_BAND == 2400 RADIO_PA_Init((RADIO_PAInit_t*)&paInit2p4); #elif (MBED_CONF_SL_RAIL_BAND == 915) || (MBED_CONF_SL_RAIL_BAND == 868) @@ -254,6 +360,12 @@ static int8_t rf_device_register(void) radio_state = RADIO_INITING; } +#ifdef MBED_CONF_RTOS_PRESENT + rx_queue_head = 0; + rx_queue_tail = 0; + rf_thread_id = osThreadCreate(osThread(rf_thread_loop), NULL); +#endif + return rf_radio_driver_id; } @@ -288,26 +400,26 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h switch(radio_state) { case RADIO_UNINIT: - tr_debug("Radio uninit\n"); + tr_debug("rf_start_cca: Radio uninit\n"); return -1; case RADIO_INITING: - tr_debug("Radio initing\n"); + tr_debug("rf_start_cca: Radio initing\n"); return -1; case RADIO_CALIBRATION: - tr_debug("Radio calibrating\n"); + tr_debug("rf_start_cca: Radio calibrating\n"); return -1; case RADIO_TX: - tr_debug("Radio in TX mode\n"); + tr_debug("rf_start_cca: Radio in TX mode\n"); return -1; case RADIO_IDLE: case RADIO_RX: // If we're still waiting for an ACK, don't mess up the internal state if(waiting_for_ack || RAIL_RfStateGet() == RAIL_RF_STATE_TX) { if((RAIL_GetTime() - last_tx) < 30000) { - tr_debug("Still waiting on previous ACK\n"); + tr_debug("rf_start_cca: Still waiting on previous ACK\n"); return -1; } else { - tr_debug("TXerr\n"); + tr_debug("rf_start_cca: TXerr\n"); } } @@ -325,7 +437,7 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h txOpt.waitForAck = false; } - //tr_debug("Called TX, len %d, chan %d, ack %d\n", data_length, channel, waiting_for_ack ? 1 : 0); + tr_debug("rf_start_cca: Called TX, len %d, chan %d, ack %d\n", data_length, channel, waiting_for_ack ? 1 : 0); if(RAIL_TxStartWithOptions(channel, &txOpt, &RAIL_CcaCsma, (RAIL_CsmaConfig_t*) &csma_config) == 0) { //Save packet number and sequence @@ -378,7 +490,7 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_ break; /* Enable wireless interface ED scan mode */ case PHY_INTERFACE_RX_ENERGY_STATE: - tr_debug("Energy det req\n"); + tr_debug("rf_interface_state_control: Energy det req\n"); // TODO: implement energy detection break; /* Enable RX in promiscuous mode (aka no address filtering) */ @@ -435,12 +547,15 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt /* Read status of the link */ case PHY_EXTENSION_READ_LINK_STATUS: // TODO: return accurate value here - tr_debug("Trying to read link status\n"); + tr_debug("rf_extension: Trying to read link status\n"); break; /* Convert between LQI and RSSI */ case PHY_EXTENSION_CONVERT_SIGNAL_INFO: // TODO: return accurate value here - tr_debug("Trying to read signal info\n"); + tr_debug("rf_extension: Trying to read signal info\n"); + break; + case PHY_EXTENSION_ACCEPT_ANY_BEACON: + tr_debug("rf_extension: Trying to accept any beacon\n"); break; } return 0; @@ -468,7 +583,7 @@ static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address case PHY_MAC_64BIT: /* Store MAC in MSB order */ memcpy(MAC_address, address_ptr, 8); - tr_debug("MACw "); + tr_debug("rf_address_write: MACw "); for(unsigned int i = 0; i < sizeof(MAC_address); i ++) { tr_debug("%02x:", MAC_address[i]); } @@ -483,13 +598,11 @@ static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address /*Set 16-bit address*/ case PHY_MAC_16BIT: short_address = address_ptr[0] << 8 | address_ptr[1]; - tr_debug("Filter EUI16 %04x\n", short_address); RAIL_IEEE802154_SetShortAddress(short_address); break; /*Set PAN Id*/ case PHY_MAC_PANID: PAN_address = address_ptr[0] << 8 | address_ptr[1]; - tr_debug("Filter PAN %04x\n", PAN_address); RAIL_IEEE802154_SetPanId(PAN_address); break; } @@ -618,7 +731,11 @@ void RAILCb_TxRadioStatus(uint8_t status) { status == RAIL_TX_CONFIG_TX_ABORTED || status == RAIL_TX_CONFIG_TX_BLOCKED) { waiting_for_ack = false; - device_driver.phy_tx_done_cb( rf_radio_driver_id, +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_TX_ERR); + } +#else + device_driver.phy_tx_done_cb(rf_radio_driver_id, current_tx_handle, PHY_LINK_CCA_FAIL, 8, @@ -626,6 +743,7 @@ void RAILCb_TxRadioStatus(uint8_t status) { } else { tr_debug("Packet TX error %d\n", status); } +#endif } radio_state = RADIO_RX; } @@ -648,7 +766,6 @@ void RAILCb_RxRadioStatus(uint8_t status) { case RAIL_RX_CONFIG_ADDRESS_FILTERED: break; default: - tr_debug("RXE %d\n", status); break; } } @@ -663,7 +780,11 @@ void RAILCb_RxRadioStatus(uint8_t status) { */ void RAILCb_CalNeeded(void) { // TODO: Implement on-the-fly recalibration +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_CAL_REQ); +#else tr_debug("!!!! Calling for calibration\n"); +#endif } /** @@ -691,6 +812,9 @@ void RAILCb_TimerExpired(void) { * callback. */ void RAILCb_TxPacketSent(RAIL_TxPacketInfo_t *txPacketInfo) { +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_TX_DONE); +#else if(device_driver.phy_tx_done_cb != NULL) { device_driver.phy_tx_done_cb( rf_radio_driver_id, current_tx_handle, @@ -700,6 +824,7 @@ void RAILCb_TxPacketSent(RAIL_TxPacketInfo_t *txPacketInfo) { 1, 1); } +#endif last_tx = RAIL_GetTime(); radio_state = RADIO_RX; } @@ -731,12 +856,16 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) { /* Save the pending bit */ last_ack_pending_bit = (rxPacketInfo->dataPtr[1] & (1 << 4)) != 0; /* Tell the stack we got an ACK */ - //tr_debug("rACK\n"); +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_ACK_RECV | SL_ACK_PEND); +#else + tr_debug("rACK\n"); device_driver.phy_tx_done_cb( rf_radio_driver_id, current_tx_handle, last_ack_pending_bit ? PHY_LINK_TX_DONE_PENDING : PHY_LINK_TX_DONE, 1, 1); +#endif } else { /* Figure out whether we want to not ACK this packet */ @@ -752,14 +881,24 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) { RAIL_AutoAckCancelAck(); } - //tr_debug("rPKT %d\n", rxPacketInfo->dataLength); /* Feed the received packet into the stack */ +#ifdef MBED_CONF_RTOS_PRESENT + if (((rx_queue_head + 1) % RF_QUEUE_SIZE) != rx_queue_tail) { + memoryTakeReference(rxPacketHandle); + rx_queue[rx_queue_head] = rxPacketHandle; + rx_queue_head = (rx_queue_head + 1) % RF_QUEUE_SIZE; + osSignalSet(rf_thread_id, SL_RX_DONE); + } else { + osSignalSet(rf_thread_id, SL_QUEUE_FULL); + } +#else + tr_debug("rPKT %d\n", rxPacketInfo->dataLength); device_driver.phy_rx_cb(rxPacketInfo->dataPtr + 1, rxPacketInfo->dataLength - 1, - //TODO: take a new RAIL release that exposes LQI, or have LQI as function of RSSI - 255, + rxPacketInfo->appendedInfo.lqi, rxPacketInfo->appendedInfo.rssiLatch, rf_radio_driver_id); +#endif } } } @@ -792,13 +931,16 @@ void RAILCb_IEEE802154_DataRequestCommand(RAIL_IEEE802154_Address_t *address) { */ void RAILCb_RxAckTimeout(void) { if(waiting_for_ack) { - tr_debug("nACK\n"); waiting_for_ack = false; +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_ACK_TIMEOUT); +#else device_driver.phy_tx_done_cb( rf_radio_driver_id, current_tx_handle, PHY_LINK_TX_FAIL, 1, 1); +#endif } } @@ -849,7 +991,11 @@ static bool rail_checkAndSwitchChannel(uint8_t newChannel) { * time of the callback dispatch. */ void RAILCb_RxFifoAlmostFull(uint16_t bytesAvailable) { +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_RXFIFO_ERR); +#else tr_debug("RX near full (%d)\n", bytesAvailable); +#endif } /** @@ -871,7 +1017,11 @@ void RAILCb_RxFifoAlmostFull(uint16_t bytesAvailable) { * callback dispatch. */ void RAILCb_TxFifoAlmostEmpty(uint16_t spaceAvailable) { +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_TXFIFO_ERR); +#else tr_debug("TX near empty (%d)\n", spaceAvailable); +#endif } /** @@ -886,5 +1036,9 @@ void RAILCb_TxFifoAlmostEmpty(uint16_t spaceAvailable) { * get the result. */ void RAILCb_RssiAverageDone(int16_t avgRssi) { +#ifdef MBED_CONF_RTOS_PRESENT + osSignalSet(rf_thread_id, SL_RSSI_DONE); +#else tr_debug("RSSI done (%d)\n", avgRssi); +#endif } \ No newline at end of file From c64c7b862492ba727674e211f3c6c4a94a2ad2e0 Mon Sep 17 00:00:00 2001 From: Ryan Kurte Date: Thu, 12 Oct 2017 10:15:12 +1300 Subject: [PATCH 2/3] Added critical section around rf_start_cca --- .../targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp index 5b9805bf0a9..117ccdf3064 100644 --- a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp +++ b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp @@ -211,7 +211,6 @@ static void rf_thread_loop(const void *arg) memoryFree(handle); rx_queue[rx_queue_tail] = NULL; - rx_queue_tail = (rx_queue_tail + 1) % RF_QUEUE_SIZE; } @@ -423,6 +422,8 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h } } + platform_enter_critical(); + data_ptr[0] = data_length + 2; RAIL_RfIdleExt(RAIL_IDLE_ABORT , true); RAIL_TxDataLoad(&txData); @@ -443,15 +444,18 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h //Save packet number and sequence current_tx_handle = tx_handle; current_tx_sequence = data_ptr[3]; + platform_exit_critical(); return 0; } else { RAIL_RfIdle(); RAIL_RxStart(channel); radio_state = RADIO_RX; + platform_exit_critical(); return -1; } } //Should never get here... + platform_exit_critical(); return -1; } From 37a38d08ea7d704bf45c600481246d2e3e40d538 Mon Sep 17 00:00:00 2001 From: Ryan Kurte Date: Wed, 1 Nov 2017 11:02:08 +1300 Subject: [PATCH 3/3] Swapped to macro definition for debug prints --- .../TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp | 76 ++++++++++++------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp index 117ccdf3064..3b91b01aa66 100644 --- a/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp +++ b/features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp @@ -14,24 +14,39 @@ * limitations under the License. */ #include "NanostackRfPhyEfr32.h" + +#include + #include "mbed.h" #include "ns_types.h" #include "platform/arm_hal_interrupt.h" #include "nanostack/platform/arm_hal_phy.h" #include "mbed_toolchain.h" -#include #include "mbed-trace/mbed_trace.h" #define TRACE_GROUP "SLRF" +/* Enable debug printing with SL_RADIO_DEBUG, override debug printer with SL_DEBUG_PRINT. */ +#ifdef SL_RADIO_DEBUG +#ifndef SL_DEBUG_PRINT +#define SL_DEBUG_PRINT(...) tr_debug(__VA_ARGS__) +#endif +#else +#define SL_DEBUG_PRINT(...) +#endif + +/* RF_THREAD_STACK_SIZE defines tack size for the RF adaptor thread */ #ifndef RF_THREAD_STACK_SIZE #define RF_THREAD_STACK_SIZE 1024 #endif +/* RF_QUEUE_SIZE defines queue size for incoming messages */ #ifndef RF_QUEUE_SIZE #define RF_QUEUE_SIZE 8 #endif + +/* RFThreadSignal used to signal from interrupts to the adaptor thread */ enum RFThreadSignal { SL_RX_DONE = (1 << 1), SL_TX_DONE = (1 << 2), @@ -45,13 +60,16 @@ enum RFThreadSignal { SL_RSSI_DONE = (1 << 10), SL_QUEUE_FULL = (1 << 11), + // ACK pend flag can be signalled in addition to RX_DONE SL_ACK_PEND = (1 << 31), }; +/* Adaptor thread definitions */ static void rf_thread_loop(const void *arg); static osThreadDef(rf_thread_loop, osPriorityRealtime, RF_THREAD_STACK_SIZE); static osThreadId rf_thread_id; +/* Queue for passing messages from interrupt to adaptor thread */ static volatile void* rx_queue[8]; static volatile size_t rx_queue_head; static volatile size_t rx_queue_tail; @@ -188,7 +206,7 @@ static bool rail_checkAndSwitchChannel(uint8_t channel); static void rf_thread_loop(const void *arg) { - tr_debug("rf_thread_loop: starting (id: %d)\n", rf_thread_id); + SL_DEBUG_PRINT("rf_thread_loop: starting (id: %d)\n", rf_thread_id); for (;;) { osEvent event = osSignalWait(0, osWaitForever); @@ -240,15 +258,15 @@ static void rf_thread_loop(const void *arg) 8, 1); } else if(event.value.signals & SL_CAL_REQ) { - tr_debug("rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n"); + SL_DEBUG_PRINT("rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n"); } else if(event.value.signals & SL_RXFIFO_ERR) { - tr_debug("rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n"); + SL_DEBUG_PRINT("rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n"); } else if(event.value.signals & SL_TXFIFO_ERR) { - tr_debug("rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n"); + SL_DEBUG_PRINT("rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n"); } else if(event.value.signals & SL_QUEUE_FULL) { - tr_debug("rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n"); + SL_DEBUG_PRINT("rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n"); } else { - tr_debug("rf_thread_loop unhandled event status: %d value: %d\n", event.status, event.value.signals); + SL_DEBUG_PRINT("rf_thread_loop unhandled event status: %d value: %d\n", event.status, event.value.signals); } platform_exit_critical(); @@ -271,7 +289,7 @@ static int8_t rf_device_register(void) return -1; } - tr_debug("rf_device_register: entry\n"); + SL_DEBUG_PRINT("rf_device_register: entry\n"); #if MBED_CONF_SL_RAIL_BAND == 2400 RADIO_PA_Init((RADIO_PAInit_t*)&paInit2p4); @@ -399,26 +417,26 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h switch(radio_state) { case RADIO_UNINIT: - tr_debug("rf_start_cca: Radio uninit\n"); + SL_DEBUG_PRINT("rf_start_cca: Radio uninit\n"); return -1; case RADIO_INITING: - tr_debug("rf_start_cca: Radio initing\n"); + SL_DEBUG_PRINT("rf_start_cca: Radio initing\n"); return -1; case RADIO_CALIBRATION: - tr_debug("rf_start_cca: Radio calibrating\n"); + SL_DEBUG_PRINT("rf_start_cca: Radio calibrating\n"); return -1; case RADIO_TX: - tr_debug("rf_start_cca: Radio in TX mode\n"); + SL_DEBUG_PRINT("rf_start_cca: Radio in TX mode\n"); return -1; case RADIO_IDLE: case RADIO_RX: // If we're still waiting for an ACK, don't mess up the internal state if(waiting_for_ack || RAIL_RfStateGet() == RAIL_RF_STATE_TX) { if((RAIL_GetTime() - last_tx) < 30000) { - tr_debug("rf_start_cca: Still waiting on previous ACK\n"); + SL_DEBUG_PRINT("rf_start_cca: Still waiting on previous ACK\n"); return -1; } else { - tr_debug("rf_start_cca: TXerr\n"); + SL_DEBUG_PRINT("rf_start_cca: TXerr\n"); } } @@ -438,7 +456,7 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h txOpt.waitForAck = false; } - tr_debug("rf_start_cca: Called TX, len %d, chan %d, ack %d\n", data_length, channel, waiting_for_ack ? 1 : 0); + SL_DEBUG_PRINT("rf_start_cca: Called TX, len %d, chan %d, ack %d\n", data_length, channel, waiting_for_ack ? 1 : 0); if(RAIL_TxStartWithOptions(channel, &txOpt, &RAIL_CcaCsma, (RAIL_CsmaConfig_t*) &csma_config) == 0) { //Save packet number and sequence @@ -494,7 +512,7 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_ break; /* Enable wireless interface ED scan mode */ case PHY_INTERFACE_RX_ENERGY_STATE: - tr_debug("rf_interface_state_control: Energy det req\n"); + SL_DEBUG_PRINT("rf_interface_state_control: Energy det req\n"); // TODO: implement energy detection break; /* Enable RX in promiscuous mode (aka no address filtering) */ @@ -551,15 +569,15 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt /* Read status of the link */ case PHY_EXTENSION_READ_LINK_STATUS: // TODO: return accurate value here - tr_debug("rf_extension: Trying to read link status\n"); + SL_DEBUG_PRINT("rf_extension: Trying to read link status\n"); break; /* Convert between LQI and RSSI */ case PHY_EXTENSION_CONVERT_SIGNAL_INFO: // TODO: return accurate value here - tr_debug("rf_extension: Trying to read signal info\n"); + SL_DEBUG_PRINT("rf_extension: Trying to read signal info\n"); break; case PHY_EXTENSION_ACCEPT_ANY_BEACON: - tr_debug("rf_extension: Trying to accept any beacon\n"); + SL_DEBUG_PRINT("rf_extension: Trying to accept any beacon\n"); break; } return 0; @@ -587,11 +605,11 @@ static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address case PHY_MAC_64BIT: /* Store MAC in MSB order */ memcpy(MAC_address, address_ptr, 8); - tr_debug("rf_address_write: MACw "); + SL_DEBUG_PRINT("rf_address_write: MACw "); for(unsigned int i = 0; i < sizeof(MAC_address); i ++) { - tr_debug("%02x:", MAC_address[i]); + SL_DEBUG_PRINT("%02x:", MAC_address[i]); } - tr_debug("\n"); + SL_DEBUG_PRINT("\n"); /* Pass MAC to the RF driver in LSB order */ uint8_t MAC_reversed[8]; for(unsigned int i = 0; i < sizeof(MAC_address); i ++) { @@ -745,7 +763,7 @@ void RAILCb_TxRadioStatus(uint8_t status) { 8, 1); } else { - tr_debug("Packet TX error %d\n", status); + SL_DEBUG_PRINT("Packet TX error %d\n", status); } #endif } @@ -787,7 +805,7 @@ void RAILCb_CalNeeded(void) { #ifdef MBED_CONF_RTOS_PRESENT osSignalSet(rf_thread_id, SL_CAL_REQ); #else - tr_debug("!!!! Calling for calibration\n"); + SL_DEBUG_PRINT("!!!! Calling for calibration\n"); #endif } @@ -863,7 +881,7 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) { #ifdef MBED_CONF_RTOS_PRESENT osSignalSet(rf_thread_id, SL_ACK_RECV | SL_ACK_PEND); #else - tr_debug("rACK\n"); + SL_DEBUG_PRINT("rACK\n"); device_driver.phy_tx_done_cb( rf_radio_driver_id, current_tx_handle, last_ack_pending_bit ? PHY_LINK_TX_DONE_PENDING : PHY_LINK_TX_DONE, @@ -896,7 +914,7 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) { osSignalSet(rf_thread_id, SL_QUEUE_FULL); } #else - tr_debug("rPKT %d\n", rxPacketInfo->dataLength); + SL_DEBUG_PRINT("rPKT %d\n", rxPacketInfo->dataLength); device_driver.phy_rx_cb(rxPacketInfo->dataPtr + 1, rxPacketInfo->dataLength - 1, rxPacketInfo->appendedInfo.lqi, @@ -998,7 +1016,7 @@ void RAILCb_RxFifoAlmostFull(uint16_t bytesAvailable) { #ifdef MBED_CONF_RTOS_PRESENT osSignalSet(rf_thread_id, SL_RXFIFO_ERR); #else - tr_debug("RX near full (%d)\n", bytesAvailable); + SL_DEBUG_PRINT("RX near full (%d)\n", bytesAvailable); #endif } @@ -1024,7 +1042,7 @@ void RAILCb_TxFifoAlmostEmpty(uint16_t spaceAvailable) { #ifdef MBED_CONF_RTOS_PRESENT osSignalSet(rf_thread_id, SL_TXFIFO_ERR); #else - tr_debug("TX near empty (%d)\n", spaceAvailable); + SL_DEBUG_PRINT("TX near empty (%d)\n", spaceAvailable); #endif } @@ -1043,6 +1061,6 @@ void RAILCb_RssiAverageDone(int16_t avgRssi) { #ifdef MBED_CONF_RTOS_PRESENT osSignalSet(rf_thread_id, SL_RSSI_DONE); #else - tr_debug("RSSI done (%d)\n", avgRssi); + SL_DEBUG_PRINT("RSSI done (%d)\n", avgRssi); #endif } \ No newline at end of file