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 36 #ifndef __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H 37 #define __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H 38 39 /**************************************************************************** 40 * Included Files 41 ****************************************************************************/ 42 43 #include "stdint.h" 44 45 46 #ifdef __cplusplus 47 #if __cplusplus 48 extern "C" { 49 #endif /* __cplusplus */ 50 #endif /* __cplusplus */ 51 52 /**************************************************************************** 53 * Pre-processor Definitions 54 ****************************************************************************/ 55 /* Configuration ************************************************************ 56 * Automounter configuration 57 * CONFIG_FS_AUTOMOUNTER - Enables automount support 58 * 59 * Prequisites: 60 * CONFIG_SCHED_WORKQUEUE - Work queue support is required 61 * And others that would only matter if you are working in a very minimal 62 * configuration. 63 */ 64 65 /* Helper macros ************************************************************/ 66 67 #define AUTOMOUNT_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg)) 68 #define AUTOMOUNT_DETACH(s) ((s)->attach(s,NULL,NULL)) 69 #define AUTOMOUNT_ENABLE(s) ((s)->enable(s,true)) 70 #define AUTOMOUNT_DISABLE(s) ((s)->enable(s,false)) 71 #define AUTOMOUNT_INSERTED(s) ((s)->inserted(s)) 72 73 /**************************************************************************** 74 * Public Types 75 ****************************************************************************/ 76 /* This is the type of the automount media change handler. The lower level 77 * code will intercept the interrupt and provide the upper level with the 78 * private data that was provided when the interrupt was attached and will 79 * also provide an indication if the media was inserted or removed. 80 */ 81 82 struct automount_lower_s; /* Forward reference. Defined below */ 83 84 typedef CODE int 85 (*automount_handler_t)(FAR const struct automount_lower_s *lower, 86 FAR void *arg, bool inserted); 87 88 /* A reference to a structure of this type must be passed to the FS 89 * automounter. This structure provides information about the volume to be 90 * mounted and provides board-specific hooks. 91 * 92 * Memory for this structure is provided by the caller. It is not copied 93 * by the automounter and is presumed to persist while the automounter 94 * is active. 95 */ 96 97 struct automount_lower_s 98 { 99 /* Volume characterization */ 100 101 FAR const char *fstype; /* Type of file system */ 102 FAR const char *blockdev; /* Path to the block device */ 103 FAR const char *mountpoint; /* Location to mount the volume */ 104 105 /* Debounce delay in system clock ticks. Automount operation will not 106 * be performed until the insertion/removal state has been unchanges 107 * for this duration. 108 */ 109 110 uint32_t ddelay; 111 112 /* Unmount delay time in system clock ticks. If a volume has open 113 * references at the time that the media is removed, then we will be 114 * unable to unmount it. In that case, hopefully, the clients of the 115 * mount will eventually fail with file access errors and eventually close 116 * their references. So, at some time later, it should be possible to 117 * unmount the volume. This delay specifies the time between umount 118 * retries. 119 */ 120 121 uint32_t udelay; 122 123 /* Interrupt related operations all hidden behind callbacks to isolate the 124 * automounter from differences in interrupt handling by varying boards 125 * and MCUs. Board interrupts should be configured both insertion and 126 * removal of the media can be detected. 127 * 128 * attach - Attach or detach the media change interrupt handler to the 129 * board level interrupt 130 * enable - Enable or disable the media change interrupt 131 */ 132 133 CODE int (*attach)(FAR const struct automount_lower_s *lower, 134 automount_handler_t isr, FAR void *arg); 135 CODE void (*enable)(FAR const struct automount_lower_s *lower, 136 bool enable); 137 CODE bool (*inserted)(FAR const struct automount_lower_s *lower); 138 }; 139 140 /**************************************************************************** 141 * Public Data 142 ****************************************************************************/ 143 144 #ifdef __cplusplus 145 #define EXTERN extern "C" 146 extern "C" 147 { 148 #else 149 #define EXTERN extern 150 #endif 151 152 /**************************************************************************** 153 * Public Function Prototypes 154 ****************************************************************************/ 155 156 /**************************************************************************** 157 * Name: automount_initialize 158 * 159 * Description: 160 * Configure the automounter. 161 * 162 * Input Parameters: 163 * lower - Persistent board configuration data 164 * 165 * Returned Value: 166 * A void* handle. The only use for this handle is with automount_uninitialize(). 167 * NULL is returned on any failure. 168 * 169 ****************************************************************************/ 170 171 FAR void *automount_initialize(FAR const struct automount_lower_s *lower); 172 173 /**************************************************************************** 174 * Name: automount_uninitialize 175 * 176 * Description: 177 * Stop the automounter and free resources that it used. NOTE that the 178 * mount is left in its last state mounted/unmounted state. 179 * 180 * Input Parameters: 181 * handle - The value previously returned by automount_initialize(); 182 * 183 * Returned Value: 184 * None 185 * 186 ****************************************************************************/ 187 188 void automount_uninitialize(FAR void *handle); 189 190 #undef EXTERN 191 #ifdef __cplusplus 192 } 193 #endif 194 #ifdef __cplusplus 195 #if __cplusplus 196 } 197 #endif /* __cplusplus */ 198 #endif /* __cplusplus */ 199 200 #endif /* __INCLUDE_NUTTX_AUDIO_AUTOMOUNT_H */ 201