automount.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /****************************************************************************
  2. * include/nuttx/audio/automount.h
  3. *
  4. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H
  36. #define __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <stdint.h>
  41. #include <stdbool.h>
  42. #include <nuttx/irq.h>
  43. #ifdef CONFIG_FS_AUTOMOUNTER
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. /* Configuration ************************************************************
  48. * Automounter configuration
  49. * CONFIG_FS_AUTOMOUNTER - Enables automount support
  50. *
  51. * Prerequisites:
  52. * CONFIG_SCHED_WORKQUEUE - Work queue support is required
  53. * And others that would only matter if you are working in a very minimal
  54. * configuration.
  55. */
  56. /* Helper macros ************************************************************/
  57. #define AUTOMOUNT_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg))
  58. #define AUTOMOUNT_DETACH(s) ((s)->attach(s,NULL,NULL))
  59. #define AUTOMOUNT_ENABLE(s) ((s)->enable(s,true))
  60. #define AUTOMOUNT_DISABLE(s) ((s)->enable(s,false))
  61. #define AUTOMOUNT_INSERTED(s) ((s)->inserted(s))
  62. /****************************************************************************
  63. * Public Types
  64. ****************************************************************************/
  65. /* This is the type of the automount media change handler. The lower level
  66. * code will intercept the interrupt and provide the upper level with the
  67. * private data that was provided when the interrupt was attached and will
  68. * also provide an indication if the media was inserted or removed.
  69. */
  70. struct automount_lower_s; /* Forward reference. Defined below */
  71. typedef CODE int
  72. (*automount_handler_t)(FAR const struct automount_lower_s *lower,
  73. FAR void *arg, bool inserted);
  74. /* A reference to a structure of this type must be passed to the FS
  75. * automounter. This structure provides information about the volume to be
  76. * mounted and provides board-specific hooks.
  77. *
  78. * Memory for this structure is provided by the caller. It is not copied
  79. * by the automounter and is presumed to persist while the automounter
  80. * is active.
  81. */
  82. struct automount_lower_s
  83. {
  84. /* Volume characterization */
  85. FAR const char *fstype; /* Type of file system */
  86. FAR const char *blockdev; /* Path to the block device */
  87. FAR const char *mountpoint; /* Location to mount the volume */
  88. /* Debounce delay in system clock ticks. Automount operation will not
  89. * be performed until the insertion/removal state has been unchanges
  90. * for this duration.
  91. */
  92. uint32_t ddelay;
  93. /* Unmount delay time in system clock ticks. If a volume has open
  94. * references at the time that the media is removed, then we will be
  95. * unable to unmount it. In that case, hopefully, the clients of the
  96. * mount will eventually fail with file access errors and eventually close
  97. * their references. So, at some time later, it should be possible to
  98. * unmount the volume. This delay specifies the time between umount
  99. * retries.
  100. */
  101. uint32_t udelay;
  102. /* Interrupt related operations all hidden behind callbacks to isolate the
  103. * automounter from differences in interrupt handling by varying boards
  104. * and MCUs. Board interrupts should be configured both insertion and
  105. * removal of the media can be detected.
  106. *
  107. * attach - Attach or detach the media change interrupt handler to the
  108. * board level interrupt
  109. * enable - Enable or disable the media change interrupt
  110. */
  111. CODE int (*attach)(FAR const struct automount_lower_s *lower,
  112. automount_handler_t isr, FAR void *arg);
  113. CODE void (*enable)(FAR const struct automount_lower_s *lower,
  114. bool enable);
  115. CODE bool (*inserted)(FAR const struct automount_lower_s *lower);
  116. };
  117. /****************************************************************************
  118. * Public Data
  119. ****************************************************************************/
  120. #ifdef __cplusplus
  121. #define EXTERN extern "C"
  122. extern "C"
  123. {
  124. #else
  125. #define EXTERN extern
  126. #endif
  127. /****************************************************************************
  128. * Public Function Prototypes
  129. ****************************************************************************/
  130. /****************************************************************************
  131. * Name: automount_initialize
  132. *
  133. * Description:
  134. * Configure the automounter.
  135. *
  136. * Input Parameters:
  137. * lower - Persistent board configuration data
  138. *
  139. * Returned Value:
  140. * A void* handle. The only use for this handle is with automount_uninitialize().
  141. * NULL is returned on any failure.
  142. *
  143. ****************************************************************************/
  144. FAR void *automount_initialize(FAR const struct automount_lower_s *lower);
  145. /****************************************************************************
  146. * Name: automount_uninitialize
  147. *
  148. * Description:
  149. * Stop the automounter and free resources that it used. NOTE that the
  150. * mount is left in its last state mounted/unmounted state.
  151. *
  152. * Input Parameters:
  153. * handle - The value previously returned by automount_initialize();
  154. *
  155. * Returned Value:
  156. * None
  157. *
  158. ****************************************************************************/
  159. void automount_uninitialize(FAR void *handle);
  160. #undef EXTERN
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif /* CONFIG_FS_AUTOMOUNTER */
  165. #endif /* __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H */