PIPE doesn't work under ISR?

I'm using Windows 11, WSL2, VSCode extension, NCS v2.

I am trying to use a Pipe from an ISR and I appear to be crashing the system as a result.

ASSERTION FAIL @ WEST_TOPDIR/zephyr/kernel/include/ksched.h:253
[00:00:13.145,355] <err> os: esf_dump: r0/a1:  0x00000004  r1/a2:  0x000000fd  r2/a3:  0x00000000
[00:00:13.286,437] <err> os: esf_dump: r3/a4:  0x2001b52d r12/ip:  0x00000000 r14/lr:  0x00055b09
[00:00:13.427,490] <err> os: esf_dump:  xpsr:  0x61000038
[00:00:13.526,794] <err> os: esf_dump: Faulting instruction address (r15/pc): 0x00062d10
[00:00:13.658,386] <err> os: z_fatal_error: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:13.793,182] <err> os: z_fatal_error: Fault during interrupt handling

[00:00:13.912,292] <err> os: z_fatal_error: Current thread: 0x20005ad0 (idle)

The assertion seems to be saying that this point in the code shouldn't be run when in an ISR.

The code seems to be getting to that point from the k_pipe_put.  Notably I am calling this with K_NO_WAIT as the timeout parameter (but not sure I see how that's even affecting the issue from the code).

// the pipe put leads to here:

int z_impl_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write,
		     size_t *bytes_written, size_t min_xfer,
		      k_timeout_t timeout)
{
...
	z_sched_lock();
...
}


// which leads to here, where the assertion hits:

static inline void z_sched_lock(void)
{
	__ASSERT(!arch_is_in_isr(), "");
	__ASSERT(_current->base.sched_locked != 1U, "");

	--_current->base.sched_locked;

	compiler_barrier();
}

The documentation for PIPE seem to state clearly that ISRs can put data into a pipe provided K_NO_WAIT is used as the timeout parameter.

https://docs.zephyrproject.org/latest/kernel/services/index.html#data-passing

[5] ISRS can send and/or receive only when passing K_NO_WAIT as the timeout argument.

https://docs.zephyrproject.org/latest/kernel/services/data_passing/pipes.html

"The kernel does allow for an ISR to flush a pipe from an ISR. It also allows it to send/receive data to/from one provided it does not attempt to wait for space/data."

Am I misunderstanding something?

Notably, I see a github zephyr issue rasied in 2019 and last touched on 2021 saying that ISRs cannot put data into a Pipe (link here: https://github.com/zephyrproject-rtos/zephyr/issues/19874).

So, can ISRs put data into a Pipe?  If not, what is the right way to copy data out from an ISR such that I can wake up a blocking thread waiting on that data?  Or some alternative?

Thanks.

Parents Reply Children
Related