Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTIC incompatibility #21

Open
TomSievers opened this issue Jan 31, 2024 · 3 comments
Open

RTIC incompatibility #21

TomSievers opened this issue Jan 31, 2024 · 3 comments

Comments

@TomSievers
Copy link

I've been trying to use this library with RTIC and ran into an issue.

The issue resides in using the modem in an RTIC task with a priority > 0. I created a repo with a two runnable examples at https://github.com/TomSievers/rtic-nrf-modem. One example shows that the modem can be used with RTIC, the other shows it not working in an interrupt context.

When initializing the modem at priority > 0 it will fail with the NRF error code of -116 (NRF_ETIMEDOUT). If the modem is succesfully initialized and afterwards one tries to bind a UdpSocket it fails with NRF error code of -1 (NRF_EPERM).

Maybe these functions are designed in a way where they will not work from an interrupt context.

I will look into trying this with the libmodem_log instead of the default libmodem to get more info into why it fails.

@diondokter
Copy link
Owner

Hi, yeah it might be a C library issue. Not sure. The C library does want to know whether the microcontroller is in interrupt context.

Also, make sure the interrupt that drives the modem has a higher priority than the interrupt with which you interact with the modem

@TomSievers
Copy link
Author

I have set the IPC prio to the maximum of RTIC which is the maximum interrupt priority.

I tried changing the function nrf_modem_os_is_in_isr to just return false instead of checking if a interrupt is active. With this change it works, but I don't know what kind of impact this has on the C library and it's inner workings. I will ask Nordic if this can be done safely.

@diondokter
Copy link
Owner

It's there for a reason though...

I think the issue might be here:

nrf-modem/src/ffi.rs

Lines 457 to 459 in f9d4a24

if nrfxlib_sys::nrf_modem_os_is_in_isr() {
timeout = nrfxlib_sys::NRF_MODEM_OS_NO_WAIT as i32;
}

I think the modem library has a pretty strict idea of its execution. It's either in an interrupt or not. All normal usage is in thread mode and all interrupts are of the same priority.

Not sure what the best way to support RTIC with this is though...
I'm not sure there's a way to do it that doesn't lead to data races...

It might just be that you cannot use the modem apis from an interrupt.

In RTIC that still can be done if you define a software task at prio 0. Those are not run as interrupts but in thread mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants