summaryrefslogtreecommitdiff
path: root/nuttx/configs
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-23 10:12:32 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-23 10:12:32 -0600
commita21d23eca9cb5321a98b0d0e2c21e0c71a029bcf (patch)
treed312bfae6da7ee6cd38681361a0f388e0104fc2f /nuttx/configs
parent4d28fb87602303f98eb520f63a058b690c722a7b (diff)
downloadpx4-nuttx-a21d23eca9cb5321a98b0d0e2c21e0c71a029bcf.tar.gz
px4-nuttx-a21d23eca9cb5321a98b0d0e2c21e0c71a029bcf.tar.bz2
px4-nuttx-a21d23eca9cb5321a98b0d0e2c21e0c71a029bcf.zip
Audio: Add a NULL audio device that can be used to simply unit-level testing of audio decoders
Diffstat (limited to 'nuttx/configs')
-rw-r--r--nuttx/configs/sama5d4-ek/src/Makefile4
-rw-r--r--nuttx/configs/sama5d4-ek/src/sam_audio_null.c168
-rw-r--r--nuttx/configs/sama5d4-ek/src/sam_nsh.c12
-rw-r--r--nuttx/configs/sama5d4-ek/src/sam_wm8904.c2
-rw-r--r--nuttx/configs/sama5d4-ek/src/sama5d4-ek.h39
5 files changed, 222 insertions, 3 deletions
diff --git a/nuttx/configs/sama5d4-ek/src/Makefile b/nuttx/configs/sama5d4-ek/src/Makefile
index 0f29ff922..821edb49a 100644
--- a/nuttx/configs/sama5d4-ek/src/Makefile
+++ b/nuttx/configs/sama5d4-ek/src/Makefile
@@ -84,6 +84,10 @@ endif
endif
endif
+ifeq ($(CONFIG_AUDIO_NULL),y)
+CSRCS += sam_audio_null.c
+endif
+
ifeq ($(CONFIG_SAMA5_HSMCI0),y)
CSRCS += sam_hsmci.c
else
diff --git a/nuttx/configs/sama5d4-ek/src/sam_audio_null.c b/nuttx/configs/sama5d4-ek/src/sam_audio_null.c
new file mode 100644
index 000000000..ec9f53b5f
--- /dev/null
+++ b/nuttx/configs/sama5d4-ek/src/sam_audio_null.c
@@ -0,0 +1,168 @@
+/************************************************************************************
+ * configs/sama5d4-ek/src/sam_audio_null.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <debug.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/pcm.h>
+#include <nuttx/audio/audio_null.h>
+
+#include "sama5d4-ek.h"
+
+#ifdef HAVE_AUDIO_NULL
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_audio_null_initialize
+ *
+ * Description:
+ * Set up to use the NULL audio device for PCM unit-level testing.
+ *
+ * Input Parameters:
+ * minor - The input device minor number
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int sam_audio_null_initialize(int minor)
+{
+ FAR struct audio_lowerhalf_s *nullaudio;
+ FAR struct audio_lowerhalf_s *pcm;
+ static bool initialized = false;
+ char devname[12];
+ int ret;
+
+ auddbg("minor %d\n", minor);
+ DEBUGASSERT(minor >= 0 && minor <= 25);
+
+ /* Have we already initialized? Since we never uninitialize we must prevent
+ * multiple initializations. This is necessary, for example, when the
+ * touchscreen example is used as a built-in application in NSH and can be
+ * called numerous time. It will attempt to initialize each time.
+ */
+
+ if (!initialized)
+ {
+ /* Get a null audio interface
+ */
+
+ nullaudio = audio_null_initialize();
+ if (!nullaudio)
+ {
+ auddbg("Failed to get the NULL audio interface\n");
+ ret = -ENODEV;
+ goto errout;
+ }
+
+ /* No we can embed the null audio interface into a PCM decoder
+ * instance so that we will have a PCM front end for the NULL
+ * audio driver.
+ */
+
+ pcm = pcm_decode_initialize(nullaudio);
+ if (!pcm)
+ {
+ auddbg("ERROR: Failed create the PCM decoder\n");
+ ret = -ENODEV;
+ goto errout_with_nullaudio;
+ }
+
+ /* Create a device name */
+
+ snprintf(devname, 12, "pcm%d", minor);
+
+ /* Finally, we can register the PCM/NULL audio device. */
+
+ ret = audio_register(devname, pcm);
+ if (ret < 0)
+ {
+ auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret);
+ goto errout_with_pcm;
+ }
+
+ /* Now we are initialized */
+
+ initialized = true;
+ }
+
+ return OK;
+
+ /* Error exits. Unfortunately there is no mechanism in place now to
+ * recover resources from most errors on initialization failures.
+ */
+
+errout_with_nullaudio:
+errout_with_pcm:
+errout:
+ return ret;
+}
+
+#endif /* HAVE_AUDIO_NULL */
diff --git a/nuttx/configs/sama5d4-ek/src/sam_nsh.c b/nuttx/configs/sama5d4-ek/src/sam_nsh.c
index 76ccb2824..1c44d273c 100644
--- a/nuttx/configs/sama5d4-ek/src/sam_nsh.c
+++ b/nuttx/configs/sama5d4-ek/src/sam_nsh.c
@@ -158,7 +158,7 @@ int nsh_archinitialize(void)
#endif
#ifdef HAVE_WM8904
- /* Start the USB Monitor */
+ /* Configure WM8904 audio */
ret = sam_wm8904_initialize(0);
if (ret != OK)
@@ -167,6 +167,16 @@ int nsh_archinitialize(void)
}
#endif
+#ifdef HAVE_AUDIO_NULL
+ /* Configure the NULL audio device */
+
+ ret = sam_audio_null_initialize(0);
+ if (ret != OK)
+ {
+ message("ERROR: Failed to initialize the NULL audio device: %d\n", ret);
+ }
+#endif
+
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.
diff --git a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
index d10fa38f9..388bf499a 100644
--- a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
+++ b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
@@ -334,7 +334,7 @@ int sam_wm8904_initialize(int minor)
return OK;
/* Error exits. Unfortunately there is no mechanism in place now to
- * recover from most errors on initialization failures.
+ * recover resources from most errors on initialization failures.
*/
errout_with_pcm:
diff --git a/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h b/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h
index 5e6a71d94..bb9a20130 100644
--- a/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h
+++ b/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h
@@ -65,6 +65,7 @@
#define HAVE_NETWORK 1
#define HAVE_MAXTOUCH 1
#define HAVE_WM8904 1
+#define HAVE_AUDIO_NULL 1
/* HSMCI */
/* Can't support MMC/SD if the card interface(s) are not enable */
@@ -317,7 +318,7 @@
#endif
/* Audio */
-/* Default configuration values */
+/* PCM/WM8904 driver */
#ifndef CONFIG_AUDIO_WM8904
# undef HAVE_WM8904
@@ -351,6 +352,23 @@
# endif
#endif
+/* PCM/null driver */
+
+#ifndef CONFIG_AUDIO_NULL
+# undef HAVE_AUDIO_NULL
+#endif
+
+#ifdef HAVE_WM8904
+# undef HAVE_AUDIO_NULL
+#endif
+
+#ifdef HAVE_AUDIO_NULL
+# ifndef CONFIG_AUDIO_FORMAT_PCM
+# warning CONFIG_AUDIO_FORMAT_PCM is required for audio support
+# undef HAVE_AUDIO_NULL
+# endif
+#endif
+
/* LEDs *****************************************************************************/
/* There are 3 LEDs on the SAMA5D4-EK:
*
@@ -925,6 +943,25 @@ int nsh_archinitialize(void);
int sam_wm8904_initialize(int minor);
#endif /* HAVE_WM8904 */
+/****************************************************************************
+ * Name: sam_audio_null_initialize
+ *
+ * Description:
+ * Set up to use the NULL audio device for PCM unit-level testing.
+ *
+ * Input Parameters:
+ * minor - The input device minor number
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+#ifdef HAVE_AUDIO_NULL
+int sam_audio_null_initialize(int minor);
+#endif /* HAVE_AUDIO_NULL */
+
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_SAMA5D4_EK_SRC_SAMA5D4_EK_H */