Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions modules/openthread/platform/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ bool otPlatDiagModeGet(void)

void otPlatDiagChannelSet(uint8_t aChannel)
{
ARG_UNUSED(aChannel);
sChannel = aChannel;
platformRadioChannelSet(aChannel);
}

void otPlatDiagTxPowerSet(int8_t aTxPower)
Expand All @@ -125,8 +125,8 @@ void otPlatDiagRadioReceived(otInstance *aInstance,
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
{
if (!otPlatDiagModeGet() || (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE &&
sTransmitMode != DIAG_TRANSMIT_MODE_CARRIER)) {
if (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE &&
sTransmitMode != DIAG_TRANSMIT_MODE_CARRIER) {
return OT_ERROR_INVALID_STATE;
}

Expand Down Expand Up @@ -175,10 +175,6 @@ static otError gpio_get_spec(uint32_t gpio_idx, const struct gpio_dt_spec **spec

*spec = &gpio_spec[gpio_idx];

if (!otPlatDiagModeGet()) {
return OT_ERROR_INVALID_STATE;
}

if (!gpio_is_ready_dt(*spec)) {
return OT_ERROR_INVALID_ARGS;
}
Expand Down Expand Up @@ -326,8 +322,8 @@ static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char
return OT_ERROR_INVALID_ARGS;
}

if (!otPlatDiagModeGet() || (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE &&
sTransmitMode != DIAG_TRANSMIT_MODE_MODCARRIER)) {
if (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE &&
sTransmitMode != DIAG_TRANSMIT_MODE_MODCARRIER) {
return OT_ERROR_INVALID_STATE;
}

Expand Down Expand Up @@ -396,10 +392,6 @@ static otError processTransmit(otInstance *aInstance, uint8_t aArgsLength, char
long value;
uint32_t now;

if (!otPlatDiagModeGet()) {
return OT_ERROR_INVALID_STATE;
}

if (aArgsLength == 0) {
diag_output("transmit will send %" PRId32 " diagnostic messages with %" PRIu32
" ms interval\r\n",
Expand Down
10 changes: 10 additions & 0 deletions modules/openthread/platform/platform-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ void platformUartPanic(void);
*/
uint16_t platformRadioChannelGet(otInstance *aInstance);

#if defined(CONFIG_OPENTHREAD_DIAG)
/**
* Set channel on radio driver.
*
* @param[in] aChannel The channel that the radio driver should use for operation.
*
*/
void platformRadioChannelSet(uint8_t aChannel);
#endif /* CONFIG_OPENTHREAD_DIAG */

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
/**
* Start/stop continuous carrier wave transmission.
Expand Down
44 changes: 30 additions & 14 deletions modules/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@
return channel;
}

#if defined(CONFIG_OPENTHREAD_DIAG)
void platformRadioChannelSet(uint8_t aChannel)
{
channel = aChannel;
}
#endif

void otPlatRadioSetPanId(otInstance *aInstance, uint16_t aPanId)
{
ARG_UNUSED(aInstance);
Expand Down Expand Up @@ -742,43 +749,50 @@

otError otPlatRadioEnable(otInstance *aInstance)
{
if (!otPlatRadioIsEnabled(aInstance)) {
sState = OT_RADIO_STATE_SLEEP;
ARG_UNUSED(aInstance);

if (sState != OT_RADIO_STATE_DISABLED && sState != OT_RADIO_STATE_SLEEP) {
return OT_ERROR_INVALID_STATE;
}

sState = OT_RADIO_STATE_SLEEP;
return OT_ERROR_NONE;
}

otError otPlatRadioDisable(otInstance *aInstance)
{
if (otPlatRadioIsEnabled(aInstance)) {
sState = OT_RADIO_STATE_DISABLED;
ARG_UNUSED(aInstance);

if (sState != OT_RADIO_STATE_DISABLED && sState != OT_RADIO_STATE_SLEEP) {
return OT_ERROR_INVALID_STATE;
}

sState = OT_RADIO_STATE_DISABLED;
return OT_ERROR_NONE;
}

otError otPlatRadioSleep(otInstance *aInstance)
{
ARG_UNUSED(aInstance);

otError error = OT_ERROR_INVALID_STATE;

if (sState == OT_RADIO_STATE_SLEEP ||
sState == OT_RADIO_STATE_RECEIVE ||
sState == OT_RADIO_STATE_TRANSMIT) {
error = OT_ERROR_NONE;
radio_api->stop(radio_dev);
sState = OT_RADIO_STATE_SLEEP;
if (sState != OT_RADIO_STATE_SLEEP && sState != OT_RADIO_STATE_RECEIVE) {
return OT_ERROR_INVALID_STATE;
}

return error;
radio_api->stop(radio_dev);
sState = OT_RADIO_STATE_SLEEP;

return OT_ERROR_NONE;
}

otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
{
ARG_UNUSED(aInstance);

if (sState == OT_RADIO_STATE_DISABLED) {
return OT_ERROR_INVALID_STATE;
}

channel = aChannel;

radio_api->set_channel(radio_dev, aChannel);
Expand Down Expand Up @@ -883,8 +897,10 @@

radio_caps = radio_api->get_capabilities(radio_dev);

if ((sState == OT_RADIO_STATE_RECEIVE) || (radio_caps & IEEE802154_HW_SLEEP_TO_TX)) {
if (sState == OT_RADIO_STATE_RECEIVE ||
(sState == OT_RADIO_STATE_SLEEP &&
radio_caps & IEEE802154_HW_SLEEP_TO_TX)) {
if (run_tx_task(aInstance) == 0) {

Check notice on line 903 in modules/openthread/platform/radio.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/openthread/platform/radio.c:903 - (sState == OT_RADIO_STATE_SLEEP && - radio_caps & IEEE802154_HW_SLEEP_TO_TX)) { + (sState == OT_RADIO_STATE_SLEEP && radio_caps & IEEE802154_HW_SLEEP_TO_TX)) {
error = OT_ERROR_NONE;
}
}
Expand Down
12 changes: 11 additions & 1 deletion tests/subsys/openthread/radio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,19 @@ ZTEST(openthread_radio, test_radio_state_test)

zassert_equal(otPlatRadioSetTransmitPower(ot, power), OT_ERROR_NONE,
"Failed to set TX power.");

zassert_equal(otPlatRadioSleep(ot), OT_ERROR_NONE, "Failed to switch to sleep mode.");

zassert_equal(otPlatRadioDisable(ot), OT_ERROR_NONE, "Failed to disable radio.");

zassert_false(otPlatRadioIsEnabled(ot), "Radio reports as enabled.");

zassert_equal(otPlatRadioSleep(ot), OT_ERROR_INVALID_STATE,
"Changed to sleep regardless being disabled.");

zassert_equal(otPlatRadioReceive(ot, channel), OT_ERROR_INVALID_STATE,
"Changed to receive regardless being disabled.");

zassert_equal(otPlatRadioEnable(ot), OT_ERROR_NONE, "Enabling radio failed.");

zassert_true(otPlatRadioIsEnabled(ot), "Radio reports disabled.");
Expand All @@ -644,14 +650,17 @@ ZTEST(openthread_radio, test_radio_state_test)
zassert_equal(otPlatRadioReceive(ot, channel), OT_ERROR_NONE, "Failed to receive.");
zassert_equal(platformRadioChannelGet(ot), channel, "Channel number not remembered.");

zassert_equal(otPlatRadioDisable(ot), OT_ERROR_INVALID_STATE,
"Changed to disabled regardless being in receive state.");

zassert_true(otPlatRadioIsEnabled(ot), "Radio reports as disabled.");
zassert_equal(1, set_channel_mock_fake.call_count);
zassert_equal(channel, set_channel_mock_fake.arg1_val);
zassert_equal(1, set_txpower_mock_fake.call_count);
zassert_equal(power, set_txpower_mock_fake.arg1_val);
zassert_equal(1, start_mock_fake.call_count);
zassert_equal_ptr(radio, start_mock_fake.arg0_val, NULL);
zassert_equal(1, stop_mock_fake.call_count);
zassert_equal(2, stop_mock_fake.call_count);
zassert_equal_ptr(radio, stop_mock_fake.arg0_val, NULL);
}

Expand Down Expand Up @@ -814,6 +823,7 @@ ZTEST(openthread_radio, test_net_pkt_transmit)
"Failed to set TX power.");

set_channel_mock_fake.return_val = 0;
zassert_equal(otPlatRadioEnable(ot), OT_ERROR_NONE, "Failed to enable.");
zassert_equal(otPlatRadioReceive(ot, channel), OT_ERROR_NONE, "Failed to receive.");
zassert_equal(1, set_channel_mock_fake.call_count);
zassert_equal(channel, set_channel_mock_fake.arg1_val);
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ manifest:
revision: b735edbc739ad59156eb55bb8ce2583d74537719
path: modules/lib/open-amp
- name: openthread
revision: 2aeb8b833ba760ec29d5f340dd1ce7bcb61c5d56
revision: 3ae741f95e7dfb391dec35c48742862049eb62e8
path: modules/lib/openthread
- name: percepio
path: modules/debug/percepio
Expand Down
Loading