tmedicci opened a new pull request, #18376: URL: https://github.com/apache/nuttx/pull/18376
## Summary <!-- This field should contain a summary of the changes. It will be pre-filled with the commit's message and descriptions. Adjust it accordingly --> * sched/mqueue: Enable receiving messages on an interrupt handler The internal implementation of `file_mq_receive` did not allow receiving a message from an interrupt handler. Although it is not possible to wait for a message in an interrupt context, it is perfectly possible to retrieve already-existing messages from the message queue. This commit modifies file_mq_timedreceive_internal to enable checking the message list and, if no messages exist, it returns immediately. This enables receiving any existing messages in an interrupt context. ## Impact <!-- Please fill the following sections with YES/NO and provide a brief explanation --> Impact on user: Yes. It allows receiving existing messages in an interrupt context. Impact on build: No. Impact on hardware: No. Impact on documentation: No. Impact on security: No. Impact on compatibility: No. ## Testing It can be tested with a simple testing application available at [tmedicci's nuttx-apps (branch `test/mqueue_isr`)](https://github.com/tmedicci/incubator-nuttx-apps/tree/test/mqueue_isr) with an ESP32-S3 device. This application receives a message during an interrupt handler with a software-triggered interrupt and checks its content. Additionally, it tries to receive a nonexistent message, ensuring that it won't block the ISR (returning immediately with the proper error code). Please note, however, that this application clearly violates kernel/userspace boundaries, so it won't be submitted upstream (it was specifically written for this implementation). ### Building After setting the alternative `nuttx-apps` repository, build the following firmware based on `esp32s3-devkit:nsh`: ``` make -j distclean && ./tools/configure.sh -S esp32s3-devkit:nsh && kconfig-tweak --enable CONFIG_TESTING_MQUEUE_ISR && kconfig-merge -m .config ../esp-nuttx-ci/configs/build && make olddefconfig -s -j && make -j bootloader && make flash EXTRAFLAGS="-Wno-cpp -DDISABLE_GIT_DEPTH" ESPTOOL_PORT=/dev/ttyUSB0 ESPTOOL_BINDIR=./ -s -j$(nproc) && picocom -b 115200 /dev/ttyUSB0 ``` ### Running - It can be flashed to a ESP32-S3: - Or, it can run on [QEMU](https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32s3/index.html#using-qemu) with: ``` qemu-system-xtensa -nographic -machine esp32s3 -global driver=esp32s3.gpio,property=strap_mode,value=0x04 -drive file=nuttx.merged.bin,if=mtd,format=raw ``` Run `nsh> mqueue_isr`. ### Results ``` nsh> mqueue_isr ============================================ mqueue_isr: Message Queue ISR Test ============================================ Testing file_mq_timedreceive_internal from ISR context. This test validates that mq_receive works correctly when called from an interrupt handler on ESP32-S3. [SETUP] Message queue '/mqueue_isr_test' opened (fd=3) [SETUP] Message sent to queue: "Hello from task!" (len=17, prio=1) [SETUP] Software interrupt configured (cpuint=2) [SETUP] ISR attached and enabled [ACTION] Triggering software interrupt... ============================================ Test Results ============================================ ISR executed: YES Test 1: mq_receive with available message Expected: success (ret > 0) Got: ret=17, errno=0 (Unknown error 0) Message: content OK Result: PASS Test 2: mq_receive on empty queue from ISR Expected: ret=-1, errno=EAGAIN (11) Got: ret=-1, errno=11 (Unknown error 11) Result: PASS ============================================ Overall: ALL TESTS PASSED ============================================ nsh> ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
