@@ -92,10 +92,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL);
92
92
#endif
93
93
94
94
enum nrf5_pending_events {
95
- PENDING_EVENT_FRAME_TO_SEND , /* There is a tx frame to send */
96
95
PENDING_EVENT_FRAME_RECEIVED , /* Radio has received new frame */
97
96
PENDING_EVENT_RX_FAILED , /* The RX failed */
98
- PENDING_EVENT_TX_STARTED , /* Radio has started transmitting */
99
97
PENDING_EVENT_TX_DONE , /* Radio transmission finished */
100
98
PENDING_EVENT_DETECT_ENERGY , /* Requested to start Energy Detection procedure */
101
99
PENDING_EVENT_DETECT_ENERGY_DONE , /* Energy Detection finished */
@@ -575,6 +573,9 @@ static void openthread_handle_received_frame(otInstance *instance, struct nrf5_r
575
573
recv_frame .mInfo .mRxInfo .mTimestamp = rx_frame -> time ;
576
574
recv_frame .mInfo .mRxInfo .mAckedWithSecEnhAck = rx_frame -> ack_seb ;
577
575
576
+ LOG_DBG ("RX %p len: %u, ch: %u, rssi: %d" , (void * )recv_frame .mPsdu , recv_frame .mLength ,
577
+ recv_frame .mChannel , recv_frame .mInfo .mRxInfo .mRssi );
578
+
578
579
if (IS_ENABLED (CONFIG_OPENTHREAD_DIAG ) && otPlatDiagModeGet ()) {
579
580
otPlatDiagRadioReceiveDone (instance , & recv_frame , OT_ERROR_NONE );
580
581
} else {
@@ -688,20 +689,18 @@ static void handle_rx_failed(otInstance *aInstance)
688
689
}
689
690
}
690
691
691
- static void handle_frame_to_send (otInstance * aInstance )
692
+ static otError transmit_frame (otInstance * aInstance )
692
693
{
693
- bool ret = false ;
694
+ bool result = true ;
694
695
695
696
ARG_UNUSED (aInstance );
696
697
697
698
if (nrf5_data .tx .frame .mLength > MAX_PACKET_SIZE ) {
698
699
LOG_ERR ("Payload (with FCS) too large: %d" , nrf5_data .tx .frame .mLength );
699
- nrf5_data .tx .result = OT_ERROR_ABORT ;
700
- set_pending_event (PENDING_EVENT_TX_DONE );
701
- return ;
700
+ return OT_ERROR_INVALID_ARGS ;
702
701
}
703
702
704
- LOG_DBG ("%p (%u) " , nrf5_data .tx .frame .mPsdu , nrf5_data .tx .frame .mLength );
703
+ LOG_DBG ("TX %p len: %u " , ( void * ) nrf5_data .tx .frame .mPsdu , nrf5_data .tx .frame .mLength );
705
704
706
705
nrf5_data .tx .psdu [0 ] = nrf5_data .tx .frame .mLength ;
707
706
@@ -720,33 +719,29 @@ static void handle_frame_to_send(otInstance *aInstance)
720
719
721
720
if ((nrf5_data .capabilities & OT_RADIO_CAPS_TRANSMIT_TIMING ) &&
722
721
(nrf5_data .tx .frame .mInfo .mTxInfo .mTxDelay != 0 )) {
723
- ret = nrf5_tx_at (& nrf5_data .tx .frame , nrf5_data .tx .psdu );
722
+ if (!nrf5_tx_at (& nrf5_data .tx .frame , nrf5_data .tx .psdu )) {
723
+ LOG_ERR ("TX at failed" );
724
+ return OT_ERROR_INVALID_STATE ;
725
+ }
724
726
} else if (nrf5_data .tx .frame .mInfo .mTxInfo .mCsmaCaEnabled ) {
725
727
if (nrf5_data .capabilities & OT_RADIO_CAPS_CSMA_BACKOFF ) {
726
- ret = nrf5_tx_csma_ca (& nrf5_data .tx .frame , nrf5_data .tx .psdu );
728
+ result = nrf5_tx_csma_ca (& nrf5_data .tx .frame , nrf5_data .tx .psdu );
727
729
} else {
728
- ret = nrf5_tx (& nrf5_data .tx .frame , nrf5_data .tx .psdu , true);
730
+ result = nrf5_tx (& nrf5_data .tx .frame , nrf5_data .tx .psdu , true);
729
731
}
730
732
} else {
731
- ret = nrf5_tx (& nrf5_data .tx .frame , nrf5_data .tx .psdu , false);
733
+ result = nrf5_tx (& nrf5_data .tx .frame , nrf5_data .tx .psdu , false);
732
734
}
733
735
734
- if (!ret ) {
735
- LOG_ERR ("Cannot send frame" );
736
- nrf5_data .tx .result = OT_ERROR_ABORT ;
736
+ otPlatRadioTxStarted (aInstance , & nrf5_data .tx .frame );
737
+
738
+ if (!result ) {
739
+ LOG_ERR ("TX failed" );
740
+ nrf5_data .tx .result = OT_ERROR_CHANNEL_ACCESS_FAILURE ;
737
741
set_pending_event (PENDING_EVENT_TX_DONE );
738
- return ;
739
742
}
740
743
741
- set_pending_event (PENDING_EVENT_TX_STARTED );
742
-
743
- LOG_DBG ("Sending frame (ch:%d, txpower:%d)" , nrf_802154_channel_get (),
744
- nrf_802154_tx_power_get ());
745
- }
746
-
747
- static void handle_tx_started (otInstance * aInstance )
748
- {
749
- otPlatRadioTxStarted (aInstance , & nrf5_data .tx .frame );
744
+ return OT_ERROR_NONE ;
750
745
}
751
746
752
747
static void handle_tx_done (otInstance * aInstance )
@@ -800,16 +795,6 @@ void platformRadioProcess(otInstance *aInstance)
800
795
handle_rx_failed (aInstance );
801
796
}
802
797
803
- if (is_pending_event_set (PENDING_EVENT_FRAME_TO_SEND )) {
804
- reset_pending_event (PENDING_EVENT_FRAME_TO_SEND );
805
- handle_frame_to_send (aInstance );
806
- }
807
-
808
- if (is_pending_event_set (PENDING_EVENT_TX_STARTED )) {
809
- reset_pending_event (PENDING_EVENT_TX_STARTED );
810
- handle_tx_started (aInstance );
811
- }
812
-
813
798
if (is_pending_event_set (PENDING_EVENT_TX_DONE )) {
814
799
reset_pending_event (PENDING_EVENT_TX_DONE );
815
800
handle_tx_done (aInstance );
@@ -1220,8 +1205,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
1220
1205
1221
1206
if (nrf5_data .state == OT_RADIO_STATE_RECEIVE || nrf5_data .state == OT_RADIO_STATE_SLEEP ) {
1222
1207
nrf5_data .state = OT_RADIO_STATE_TRANSMIT ;
1223
- error = OT_ERROR_NONE ;
1224
- set_pending_event (PENDING_EVENT_FRAME_TO_SEND );
1208
+ error = transmit_frame (aInstance );
1225
1209
}
1226
1210
1227
1211
return error ;
@@ -1746,16 +1730,15 @@ void nrf_802154_transmitted_raw(uint8_t *frame, const nrf_802154_transmit_done_m
1746
1730
static otError nrf5_tx_error_to_ot_error (nrf_802154_tx_error_t error )
1747
1731
{
1748
1732
switch (error ) {
1749
- case NRF_802154_TX_ERROR_NO_MEM :
1750
- return OT_ERROR_NO_BUFS ;
1751
1733
case NRF_802154_TX_ERROR_BUSY_CHANNEL :
1734
+ case NRF_802154_TX_ERROR_TIMESLOT_ENDED :
1735
+ case NRF_802154_TX_ERROR_TIMESLOT_DENIED :
1752
1736
return OT_ERROR_CHANNEL_ACCESS_FAILURE ;
1753
1737
case NRF_802154_TX_ERROR_INVALID_ACK :
1738
+ case NRF_802154_TX_ERROR_NO_MEM :
1754
1739
case NRF_802154_TX_ERROR_NO_ACK :
1755
1740
return OT_ERROR_NO_ACK ;
1756
1741
case NRF_802154_TX_ERROR_ABORTED :
1757
- case NRF_802154_TX_ERROR_TIMESLOT_DENIED :
1758
- case NRF_802154_TX_ERROR_TIMESLOT_ENDED :
1759
1742
default :
1760
1743
return OT_ERROR_ABORT ;
1761
1744
}
@@ -1766,9 +1749,10 @@ void nrf_802154_transmit_failed(uint8_t *frame, nrf_802154_tx_error_t error,
1766
1749
{
1767
1750
ARG_UNUSED (frame );
1768
1751
1769
- LOG_DBG ("nrf_802154_transmit_failed: %u" , error );
1770
-
1771
1752
nrf5_data .tx .result = nrf5_tx_error_to_ot_error (error );
1753
+
1754
+ LOG_DBG ("nrf_802154_transmit_failed: %u, tx result: %u" , error , nrf5_data .tx .result );
1755
+
1772
1756
update_tx_frame_info (& nrf5_data .tx .frame , metadata );
1773
1757
1774
1758
set_pending_event (PENDING_EVENT_TX_DONE );
0 commit comments