Skip to content

Commit 4ca493a

Browse files
committed
move tx
Signed-off-by: Adrian Gielniewski <[email protected]>
1 parent cd1467a commit 4ca493a

File tree

1 file changed

+27
-43
lines changed

1 file changed

+27
-43
lines changed

modules/openthread/platform/radio_nrf5.c

+27-43
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL);
9292
#endif
9393

9494
enum nrf5_pending_events {
95-
PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */
9695
PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */
9796
PENDING_EVENT_RX_FAILED, /* The RX failed */
98-
PENDING_EVENT_TX_STARTED, /* Radio has started transmitting */
9997
PENDING_EVENT_TX_DONE, /* Radio transmission finished */
10098
PENDING_EVENT_DETECT_ENERGY, /* Requested to start Energy Detection procedure */
10199
PENDING_EVENT_DETECT_ENERGY_DONE, /* Energy Detection finished */
@@ -575,6 +573,9 @@ static void openthread_handle_received_frame(otInstance *instance, struct nrf5_r
575573
recv_frame.mInfo.mRxInfo.mTimestamp = rx_frame->time;
576574
recv_frame.mInfo.mRxInfo.mAckedWithSecEnhAck = rx_frame->ack_seb;
577575

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+
578579
if (IS_ENABLED(CONFIG_OPENTHREAD_DIAG) && otPlatDiagModeGet()) {
579580
otPlatDiagRadioReceiveDone(instance, &recv_frame, OT_ERROR_NONE);
580581
} else {
@@ -688,20 +689,18 @@ static void handle_rx_failed(otInstance *aInstance)
688689
}
689690
}
690691

691-
static void handle_frame_to_send(otInstance *aInstance)
692+
static otError transmit_frame(otInstance *aInstance)
692693
{
693-
bool ret = false;
694+
bool result = true;
694695

695696
ARG_UNUSED(aInstance);
696697

697698
if (nrf5_data.tx.frame.mLength > MAX_PACKET_SIZE) {
698699
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;
702701
}
703702

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);
705704

706705
nrf5_data.tx.psdu[0] = nrf5_data.tx.frame.mLength;
707706

@@ -720,33 +719,29 @@ static void handle_frame_to_send(otInstance *aInstance)
720719

721720
if ((nrf5_data.capabilities & OT_RADIO_CAPS_TRANSMIT_TIMING) &&
722721
(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+
}
724726
} else if (nrf5_data.tx.frame.mInfo.mTxInfo.mCsmaCaEnabled) {
725727
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);
727729
} 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);
729731
}
730732
} 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);
732734
}
733735

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;
737741
set_pending_event(PENDING_EVENT_TX_DONE);
738-
return;
739742
}
740743

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;
750745
}
751746

752747
static void handle_tx_done(otInstance *aInstance)
@@ -800,16 +795,6 @@ void platformRadioProcess(otInstance *aInstance)
800795
handle_rx_failed(aInstance);
801796
}
802797

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-
813798
if (is_pending_event_set(PENDING_EVENT_TX_DONE)) {
814799
reset_pending_event(PENDING_EVENT_TX_DONE);
815800
handle_tx_done(aInstance);
@@ -1220,8 +1205,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
12201205

12211206
if (nrf5_data.state == OT_RADIO_STATE_RECEIVE || nrf5_data.state == OT_RADIO_STATE_SLEEP) {
12221207
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);
12251209
}
12261210

12271211
return error;
@@ -1746,16 +1730,15 @@ void nrf_802154_transmitted_raw(uint8_t *frame, const nrf_802154_transmit_done_m
17461730
static otError nrf5_tx_error_to_ot_error(nrf_802154_tx_error_t error)
17471731
{
17481732
switch (error) {
1749-
case NRF_802154_TX_ERROR_NO_MEM:
1750-
return OT_ERROR_NO_BUFS;
17511733
case NRF_802154_TX_ERROR_BUSY_CHANNEL:
1734+
case NRF_802154_TX_ERROR_TIMESLOT_ENDED:
1735+
case NRF_802154_TX_ERROR_TIMESLOT_DENIED:
17521736
return OT_ERROR_CHANNEL_ACCESS_FAILURE;
17531737
case NRF_802154_TX_ERROR_INVALID_ACK:
1738+
case NRF_802154_TX_ERROR_NO_MEM:
17541739
case NRF_802154_TX_ERROR_NO_ACK:
17551740
return OT_ERROR_NO_ACK;
17561741
case NRF_802154_TX_ERROR_ABORTED:
1757-
case NRF_802154_TX_ERROR_TIMESLOT_DENIED:
1758-
case NRF_802154_TX_ERROR_TIMESLOT_ENDED:
17591742
default:
17601743
return OT_ERROR_ABORT;
17611744
}
@@ -1766,9 +1749,10 @@ void nrf_802154_transmit_failed(uint8_t *frame, nrf_802154_tx_error_t error,
17661749
{
17671750
ARG_UNUSED(frame);
17681751

1769-
LOG_DBG("nrf_802154_transmit_failed: %u", error);
1770-
17711752
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+
17721756
update_tx_frame_info(&nrf5_data.tx.frame, metadata);
17731757

17741758
set_pending_event(PENDING_EVENT_TX_DONE);

0 commit comments

Comments
 (0)