14
14
* limitations under the License.
15
15
*/
16
16
#include " NanostackRfPhyEfr32.h"
17
+
18
+ #include < string.h>
19
+
17
20
#include " mbed.h"
18
21
#include " ns_types.h"
19
22
#include " platform/arm_hal_interrupt.h"
20
23
#include " nanostack/platform/arm_hal_phy.h"
21
24
#include " mbed_toolchain.h"
22
- #include < string.h>
23
25
24
26
#include " mbed-trace/mbed_trace.h"
25
27
#define TRACE_GROUP " SLRF"
26
28
29
+ /* Enable debug printing with SL_RADIO_DEBUG, override debug printer with SL_DEBUG_PRINT. */
30
+ #ifdef SL_RADIO_DEBUG
31
+ #ifndef SL_DEBUG_PRINT
32
+ #define SL_DEBUG_PRINT (...) tr_debug(__VA_ARGS__)
33
+ #endif
34
+ #else
35
+ #define SL_DEBUG_PRINT (...)
36
+ #endif
37
+
38
+ /* RF_THREAD_STACK_SIZE defines tack size for the RF adaptor thread */
27
39
#ifndef RF_THREAD_STACK_SIZE
28
40
#define RF_THREAD_STACK_SIZE 1024
29
41
#endif
30
42
43
+ /* RF_QUEUE_SIZE defines queue size for incoming messages */
31
44
#ifndef RF_QUEUE_SIZE
32
45
#define RF_QUEUE_SIZE 8
33
46
#endif
34
47
48
+
49
+ /* RFThreadSignal used to signal from interrupts to the adaptor thread */
35
50
enum RFThreadSignal {
36
51
SL_RX_DONE = (1 << 1 ),
37
52
SL_TX_DONE = (1 << 2 ),
@@ -45,13 +60,16 @@ enum RFThreadSignal {
45
60
SL_RSSI_DONE = (1 << 10 ),
46
61
SL_QUEUE_FULL = (1 << 11 ),
47
62
63
+ // ACK pend flag can be signalled in addition to RX_DONE
48
64
SL_ACK_PEND = (1 << 31 ),
49
65
};
50
66
67
+ /* Adaptor thread definitions */
51
68
static void rf_thread_loop (const void *arg);
52
69
static osThreadDef (rf_thread_loop, osPriorityRealtime, RF_THREAD_STACK_SIZE);
53
70
static osThreadId rf_thread_id;
54
71
72
+ /* Queue for passing messages from interrupt to adaptor thread */
55
73
static volatile void * rx_queue[8 ];
56
74
static volatile size_t rx_queue_head;
57
75
static volatile size_t rx_queue_tail;
@@ -188,7 +206,7 @@ static bool rail_checkAndSwitchChannel(uint8_t channel);
188
206
189
207
static void rf_thread_loop (const void *arg)
190
208
{
191
- tr_debug (" rf_thread_loop: starting (id: %d)\n " , rf_thread_id);
209
+ SL_DEBUG_PRINT (" rf_thread_loop: starting (id: %d)\n " , rf_thread_id);
192
210
for (;;) {
193
211
osEvent event = osSignalWait (0 , osWaitForever);
194
212
@@ -240,15 +258,15 @@ static void rf_thread_loop(const void *arg)
240
258
8 ,
241
259
1 );
242
260
} else if (event.value .signals & SL_CAL_REQ) {
243
- tr_debug (" rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n " );
261
+ SL_DEBUG_PRINT (" rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n " );
244
262
} else if (event.value .signals & SL_RXFIFO_ERR) {
245
- tr_debug (" rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n " );
263
+ SL_DEBUG_PRINT (" rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n " );
246
264
} else if (event.value .signals & SL_TXFIFO_ERR) {
247
- tr_debug (" rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n " );
265
+ SL_DEBUG_PRINT (" rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n " );
248
266
} else if (event.value .signals & SL_QUEUE_FULL) {
249
- tr_debug (" rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n " );
267
+ SL_DEBUG_PRINT (" rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n " );
250
268
} else {
251
- tr_debug (" rf_thread_loop unhandled event status: %d value: %d\n " , event.status , event.value .signals );
269
+ SL_DEBUG_PRINT (" rf_thread_loop unhandled event status: %d value: %d\n " , event.status , event.value .signals );
252
270
}
253
271
254
272
platform_exit_critical ();
@@ -271,7 +289,7 @@ static int8_t rf_device_register(void)
271
289
return -1 ;
272
290
}
273
291
274
- tr_debug (" rf_device_register: entry\n " );
292
+ SL_DEBUG_PRINT (" rf_device_register: entry\n " );
275
293
276
294
#if MBED_CONF_SL_RAIL_BAND == 2400
277
295
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
399
417
400
418
switch (radio_state) {
401
419
case RADIO_UNINIT:
402
- tr_debug (" rf_start_cca: Radio uninit\n " );
420
+ SL_DEBUG_PRINT (" rf_start_cca: Radio uninit\n " );
403
421
return -1 ;
404
422
case RADIO_INITING:
405
- tr_debug (" rf_start_cca: Radio initing\n " );
423
+ SL_DEBUG_PRINT (" rf_start_cca: Radio initing\n " );
406
424
return -1 ;
407
425
case RADIO_CALIBRATION:
408
- tr_debug (" rf_start_cca: Radio calibrating\n " );
426
+ SL_DEBUG_PRINT (" rf_start_cca: Radio calibrating\n " );
409
427
return -1 ;
410
428
case RADIO_TX:
411
- tr_debug (" rf_start_cca: Radio in TX mode\n " );
429
+ SL_DEBUG_PRINT (" rf_start_cca: Radio in TX mode\n " );
412
430
return -1 ;
413
431
case RADIO_IDLE:
414
432
case RADIO_RX:
415
433
// If we're still waiting for an ACK, don't mess up the internal state
416
434
if (waiting_for_ack || RAIL_RfStateGet () == RAIL_RF_STATE_TX) {
417
435
if ((RAIL_GetTime () - last_tx) < 30000 ) {
418
- tr_debug (" rf_start_cca: Still waiting on previous ACK\n " );
436
+ SL_DEBUG_PRINT (" rf_start_cca: Still waiting on previous ACK\n " );
419
437
return -1 ;
420
438
} else {
421
- tr_debug (" rf_start_cca: TXerr\n " );
439
+ SL_DEBUG_PRINT (" rf_start_cca: TXerr\n " );
422
440
}
423
441
}
424
442
@@ -438,7 +456,7 @@ static int8_t rf_start_cca(uint8_t *data_ptr, uint16_t data_length, uint8_t tx_h
438
456
txOpt.waitForAck = false ;
439
457
}
440
458
441
- tr_debug (" rf_start_cca: Called TX, len %d, chan %d, ack %d\n " , data_length, channel, waiting_for_ack ? 1 : 0 );
459
+ SL_DEBUG_PRINT (" rf_start_cca: Called TX, len %d, chan %d, ack %d\n " , data_length, channel, waiting_for_ack ? 1 : 0 );
442
460
443
461
if (RAIL_TxStartWithOptions (channel, &txOpt, &RAIL_CcaCsma, (RAIL_CsmaConfig_t*) &csma_config) == 0 ) {
444
462
// Save packet number and sequence
@@ -494,7 +512,7 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
494
512
break ;
495
513
/* Enable wireless interface ED scan mode */
496
514
case PHY_INTERFACE_RX_ENERGY_STATE:
497
- tr_debug (" rf_interface_state_control: Energy det req\n " );
515
+ SL_DEBUG_PRINT (" rf_interface_state_control: Energy det req\n " );
498
516
// TODO: implement energy detection
499
517
break ;
500
518
/* 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
551
569
/* Read status of the link */
552
570
case PHY_EXTENSION_READ_LINK_STATUS:
553
571
// TODO: return accurate value here
554
- tr_debug (" rf_extension: Trying to read link status\n " );
572
+ SL_DEBUG_PRINT (" rf_extension: Trying to read link status\n " );
555
573
break ;
556
574
/* Convert between LQI and RSSI */
557
575
case PHY_EXTENSION_CONVERT_SIGNAL_INFO:
558
576
// TODO: return accurate value here
559
- tr_debug (" rf_extension: Trying to read signal info\n " );
577
+ SL_DEBUG_PRINT (" rf_extension: Trying to read signal info\n " );
560
578
break ;
561
579
case PHY_EXTENSION_ACCEPT_ANY_BEACON:
562
- tr_debug (" rf_extension: Trying to accept any beacon\n " );
580
+ SL_DEBUG_PRINT (" rf_extension: Trying to accept any beacon\n " );
563
581
break ;
564
582
}
565
583
return 0 ;
@@ -587,11 +605,11 @@ static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address
587
605
case PHY_MAC_64BIT:
588
606
/* Store MAC in MSB order */
589
607
memcpy (MAC_address, address_ptr, 8 );
590
- tr_debug (" rf_address_write: MACw " );
608
+ SL_DEBUG_PRINT (" rf_address_write: MACw " );
591
609
for (unsigned int i = 0 ; i < sizeof (MAC_address); i ++) {
592
- tr_debug (" %02x:" , MAC_address[i]);
610
+ SL_DEBUG_PRINT (" %02x:" , MAC_address[i]);
593
611
}
594
- tr_debug (" \n " );
612
+ SL_DEBUG_PRINT (" \n " );
595
613
/* Pass MAC to the RF driver in LSB order */
596
614
uint8_t MAC_reversed[8 ];
597
615
for (unsigned int i = 0 ; i < sizeof (MAC_address); i ++) {
@@ -745,7 +763,7 @@ void RAILCb_TxRadioStatus(uint8_t status) {
745
763
8 ,
746
764
1 );
747
765
} else {
748
- tr_debug (" Packet TX error %d\n " , status);
766
+ SL_DEBUG_PRINT (" Packet TX error %d\n " , status);
749
767
}
750
768
#endif
751
769
}
@@ -787,7 +805,7 @@ void RAILCb_CalNeeded(void) {
787
805
#ifdef MBED_CONF_RTOS_PRESENT
788
806
osSignalSet (rf_thread_id, SL_CAL_REQ);
789
807
#else
790
- tr_debug (" !!!! Calling for calibration\n " );
808
+ SL_DEBUG_PRINT (" !!!! Calling for calibration\n " );
791
809
#endif
792
810
}
793
811
@@ -863,7 +881,7 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) {
863
881
#ifdef MBED_CONF_RTOS_PRESENT
864
882
osSignalSet (rf_thread_id, SL_ACK_RECV | SL_ACK_PEND);
865
883
#else
866
- tr_debug (" rACK\n " );
884
+ SL_DEBUG_PRINT (" rACK\n " );
867
885
device_driver.phy_tx_done_cb ( rf_radio_driver_id,
868
886
current_tx_handle,
869
887
last_ack_pending_bit ? PHY_LINK_TX_DONE_PENDING : PHY_LINK_TX_DONE,
@@ -896,7 +914,7 @@ void RAILCb_RxPacketReceived(void *rxPacketHandle) {
896
914
osSignalSet (rf_thread_id, SL_QUEUE_FULL);
897
915
}
898
916
#else
899
- tr_debug (" rPKT %d\n " , rxPacketInfo->dataLength );
917
+ SL_DEBUG_PRINT (" rPKT %d\n " , rxPacketInfo->dataLength );
900
918
device_driver.phy_rx_cb (rxPacketInfo->dataPtr + 1 ,
901
919
rxPacketInfo->dataLength - 1 ,
902
920
rxPacketInfo->appendedInfo .lqi ,
@@ -998,7 +1016,7 @@ void RAILCb_RxFifoAlmostFull(uint16_t bytesAvailable) {
998
1016
#ifdef MBED_CONF_RTOS_PRESENT
999
1017
osSignalSet (rf_thread_id, SL_RXFIFO_ERR);
1000
1018
#else
1001
- tr_debug (" RX near full (%d)\n " , bytesAvailable);
1019
+ SL_DEBUG_PRINT (" RX near full (%d)\n " , bytesAvailable);
1002
1020
#endif
1003
1021
}
1004
1022
@@ -1024,7 +1042,7 @@ void RAILCb_TxFifoAlmostEmpty(uint16_t spaceAvailable) {
1024
1042
#ifdef MBED_CONF_RTOS_PRESENT
1025
1043
osSignalSet (rf_thread_id, SL_TXFIFO_ERR);
1026
1044
#else
1027
- tr_debug (" TX near empty (%d)\n " , spaceAvailable);
1045
+ SL_DEBUG_PRINT (" TX near empty (%d)\n " , spaceAvailable);
1028
1046
#endif
1029
1047
}
1030
1048
@@ -1043,6 +1061,6 @@ void RAILCb_RssiAverageDone(int16_t avgRssi) {
1043
1061
#ifdef MBED_CONF_RTOS_PRESENT
1044
1062
osSignalSet (rf_thread_id, SL_RSSI_DONE);
1045
1063
#else
1046
- tr_debug (" RSSI done (%d)\n " , avgRssi);
1064
+ SL_DEBUG_PRINT (" RSSI done (%d)\n " , avgRssi);
1047
1065
#endif
1048
1066
}
0 commit comments