Merged in masayuki2009/nuttx.apps/i2sloop_test (pull request #137)

apps/examples/i2sloop: Add i2sloop application

This application can be used to test I2S loopback

  nsh> i2sloop &

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Masayuki Ishikawa 2018-06-06 12:45:51 +00:00 committed by Gregory Nutt
parent 1b4d17d9c0
commit 0123480851
5 changed files with 267 additions and 0 deletions

11
examples/i2sloop/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
/Make.dep
/.depend
/.built
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src

11
examples/i2sloop/Kconfig Normal file
View File

@ -0,0 +1,11 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_I2SLOOP
bool "I2S loopback test"
default n
depends on I2S && AUDIO && DRIVERS_AUDIO && AUDIO_I2SCHAR
---help---
Enable the I2S loopback test

View File

@ -0,0 +1,39 @@
############################################################################
# apps/examples/i2sloop/Make.defs
# Adds selected applications to apps/ build
#
# Copyright 2018 Sony Video & Sound Products Inc.
# Author: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
#
# 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.
#
############################################################################
ifeq ($(CONFIG_EXAMPLES_I2SLOOP),y)
CONFIGURED_APPS += examples/i2sloop
endif

53
examples/i2sloop/Makefile Normal file
View File

@ -0,0 +1,53 @@
############################################################################
# apps/examples/i2sloop/Makefile
#
# Copyright 2018 Sony Video & Sound Products Inc.
# Author: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
#
# 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.
#
############################################################################
-include $(TOPDIR)/Make.defs
# I2S character driver test
ASRCS =
CSRCS =
MAINSRC = i2sloop_main.c
CONFIG_XYZ_PROGNAME ?= i2sloop$(EXEEXT)
PROGNAME = $(CONFIG_XYZ_PROGNAME)
# Touchscreen built-in application info
APPNAME = i2sloop
PRIORITY = 140
STACKSIZE = 2048
include $(APPDIR)/Application.mk

View File

@ -0,0 +1,153 @@
/****************************************************************************
* examples/i2sloop/i2sloop_main.c
*
* Copyright 2018 Sony Video & Sound Products Inc.
* Author: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
*
* 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 <nuttx/audio/audio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
/****************************************************************************
* Private Data
****************************************************************************/
static bool g_i2sloop_running;
/****************************************************************************
* Private Functions
****************************************************************************/
static void _signal_handler(int number)
{
g_i2sloop_running = false;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: i2sloop_main
****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
#else
int i2sloop_main(int argc, char *argv[])
#endif
{
FAR struct ap_buffer_s *apb;
struct audio_buf_desc_s desc;
ssize_t bufsize;
int ret;
int fd;
int opt;
int ch;
int freq;
ch = 1;
freq = 16000;
while ((opt = getopt(argc, argv, "c:f:")) != -1)
{
switch (opt)
{
case 'c':
ch = atoi(optarg);
break;
case 'f':
freq = atoi(optarg);
break;
}
}
/* Open the I2S character device */
fd = open("/dev/i2schar0", O_RDWR);
ASSERT(0 < fd);
/* Setup sample freq for i2s */
struct audio_caps_desc_s cap_desc;
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
cap_desc.caps.ac_type = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_INPUT;
cap_desc.caps.ac_controls.w = freq;
cap_desc.caps.ac_channels = ch;
cap_desc.caps.ac_format.hw = AUDIO_FMT_PCM;
ioctl(fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
/* Allocate an audio buffer */
desc.numbytes = 1024;
desc.u.ppBuffer = &apb;
ret = apb_alloc(&desc);
ASSERT(ret == sizeof(desc));
signal(1, _signal_handler);
g_i2sloop_running = true;
while (g_i2sloop_running)
{
bufsize = sizeof(struct ap_buffer_s) + apb->nmaxbytes;
ret = read(fd, apb, bufsize);
if (0 < ret)
{
apb->nbytes = apb->nmaxbytes;
bufsize = sizeof(struct ap_buffer_s) + apb->nbytes;
ret = write(fd, apb, bufsize);
}
}
apb_free(apb);
close(fd);
return EXIT_SUCCESS;
}