Currently board-specific logic supports detection of when a card is inserted or removed via a mechanical GPIO pin on the physical SD slot.  That notification is used by the SDIO-based card driver to check for a valid card insertion/removal.

For the case of the automounter with an SD card, the notification comes from a lower half driver described in include/nuttx/fs/automount.h.  For the case of the SD card, this notification probably derives from that insertion/removal event.

That is not very useful, however, because the automounter does not depend on the SD card slot but could be set up for any removal media (such as a USB flash drive).

I think it seems reasonable to add work queue-based, subscriber notifications (see included/nuttx/wqueue.h).  The automounter could then "broadcast" such a notification when a file system is mounted or unmounted.  Such a notification could solve half of your problem.

The other half of the problem is that the work queue notification is usable only within the OS and not by applications.  So perhaps some time driver would also be needed to register to receive notifications, catch the notifications, and signal an application.

It is worth noting that the USB mass storage host driver already uses a work-queue notification when USB flash drives are connected.  See arm/kinetis/freedom-k28f/src/k28_usbhshost.c and drivers/usbhost/usbhost_storage.c.  That latter file implements its only automounter outside of fs_automount.c.  It would be good if those were consolidated.

On 1/10/2021 6:29 AM, Fotis Panagiotopoulos wrote:
Hi everyone,

I am working on a NuttX application that will run on a board that has a
user-accessible SD card.

The user may insert or remove the card during runtime, so I am using the
NuttX automounter.
The automounter works nicely, mounting and unmounting the card when it is
inserted/removed.

However, I am looking for a way to inform the rest of the system about the
(un)mount event.

This is needed because:
1. If the SD card is present during system boot, the application
initialization has to wait for it to be properly mounted before proceeding.
2. If the card is inserted during the system operation, the application has
to read some files from the card, once inserted.

Unfortunately, I cannot see any proper way to achieve this.
Any suggestions?

Reply via email to