Add apps/examples/i2schar that will eventually use the I2C character drvier to verify I2S
This commit is contained in:
parent
ffed849881
commit
1129c10a27
@ -733,3 +733,5 @@
|
||||
* apps/system/nxplayer: Play thread stack size is now configurable. All
|
||||
NxPlayer threads now have names assigned via pthread_setname_np().
|
||||
From Ken Pettit (2013-11-10).
|
||||
* apps/examples/i2schar: The beginning of an I2C test based on the I2C
|
||||
character driver (2013-11-10).
|
@ -19,6 +19,7 @@ source "$APPSDIR/examples/json/Kconfig"
|
||||
source "$APPSDIR/examples/hidkbd/Kconfig"
|
||||
source "$APPSDIR/examples/keypadtest/Kconfig"
|
||||
source "$APPSDIR/examples/igmp/Kconfig"
|
||||
source "$APPSDIR/examples/i2schar/Kconfig"
|
||||
source "$APPSDIR/examples/lcdrw/Kconfig"
|
||||
source "$APPSDIR/examples/mm/Kconfig"
|
||||
source "$APPSDIR/examples/modbus/Kconfig"
|
||||
|
@ -94,6 +94,10 @@ ifeq ($(CONFIG_EXAMPLES_IGMP),y)
|
||||
CONFIGURED_APPS += examples/igmp
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_I2SCHAR),y)
|
||||
CONFIGURED_APPS += examples/i2schar
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_JSON),y)
|
||||
CONFIGURED_APPS += examples/json
|
||||
endif
|
||||
|
@ -38,8 +38,8 @@
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = adc buttons can cc3000 cxxtest dhcpd discover elf flash_test
|
||||
SUBDIRS += ftpc ftpd hello helloxx hidkbd igmp json keypadtest lcdrw
|
||||
SUBDIRS += mm modbus mount mtdpart nettest nrf24l01_term nsh null nx
|
||||
SUBDIRS += ftpc ftpd hello helloxx hidkbd igmp i2schar json keypadtest
|
||||
SUBDIRS += lcdrw mm modbus mount mtdpart nettest nrf24l01_term nsh null nx
|
||||
SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest
|
||||
SUBDIRS += pashello pipe poll posix_spawn pwm qencoder random relays rgmp
|
||||
SUBDIRS += romfs sendmail serloop slcd smart smart_test tcpecho telnetd
|
||||
@ -54,10 +54,10 @@ CNTXTDIRS = pwm
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += adc can cc3000 cxxtest dhcpd discover flash_test ftpd
|
||||
CNTXTDIRS += hello helloxx json keypadtestmodbus lcdrw mtdpart nettest
|
||||
CNTXTDIRS += nx nxhello nximage nxlines nxtext nrf24l01_term ostest random
|
||||
CNTXTDIRS += relays qencoder slcd smart_test tcpecho telnetd tiff
|
||||
CNTXTDIRS += touchscreen usbterm watchdog wgetjson
|
||||
CNTXTDIRS += hello helloxx i2schar json keypadtestmodbus lcdrw mtdpart
|
||||
CNTXTDIRS += nettest nx nxhello nximage nxlines nxtext nrf24l01_term
|
||||
CNTXTDIRS += ostest random relays qencoder slcd smart_test tcpecho telnetd
|
||||
CNTXTDIRS += tiff touchscreen usbterm watchdog wgetjson
|
||||
endif
|
||||
|
||||
all: nothing
|
||||
|
@ -480,7 +480,6 @@ examples/hidkbd
|
||||
able and control ASCII characters will be provided to the user.
|
||||
Requires CONFIG_HIDKBD_ENCODED && CONFIG_LIB_KBDCODEC
|
||||
|
||||
endif
|
||||
examples/igmp
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
@ -501,6 +500,53 @@ examples/igmp
|
||||
* CONFIG_EXAMPLES_UIPLIB
|
||||
The UIP library is needed
|
||||
|
||||
examples/adc
|
||||
^^^^^^^^^^^^
|
||||
|
||||
A mindlessly simple test of an I2C driver. It reads an write garbage data to the
|
||||
I2C transmitter and/or received as fast possible.
|
||||
|
||||
This test depends on these specific I2S/AUDIO/NSH configurations settings (your
|
||||
specific I2S settings might require additional settings).
|
||||
|
||||
CONFIG_I2S - Enabled I2S support
|
||||
CONFIG_AUDIO - Enabled audio support
|
||||
CONFIG_AUDIO_DEVICES - Enable audio device support
|
||||
CONFIG_AUDIO_I2SCHAR = Enabled support for the I2S character device
|
||||
CONFIG_NSH_BUILTIN_APPS - Build the I2S test as an NSH built-in function.
|
||||
Default: Built as a standalone problem
|
||||
|
||||
Specific configuration options for this example include:
|
||||
|
||||
CONFIG_EXAMPLES_I2SCHAR - Enables the I2C test
|
||||
CONFIG_EXAMPLES_I2SCHAR_DEVPATH - The default path to the ADC device.
|
||||
Default: /dev/i2schar0
|
||||
CONFIG_EXAMPLES_I2SCHAR_TX - This should be set if the I2S device supports
|
||||
a transmitter.
|
||||
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS - This is the default number of audio
|
||||
buffers to send before the TX transfers terminate. When both TX and
|
||||
RX transfers terminate, the task exits (and, if an NSH builtin, the
|
||||
i2schar command returns). This number can be changed from the NSH
|
||||
command line.
|
||||
CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE - This is the stack size to use when
|
||||
starting the transmitter thread. Default 1536.
|
||||
CONFIG_EXAMPLES_I2SCHAR_RX - This should be set if the I2S device supports
|
||||
a transmitter.
|
||||
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS - This is the default number of audio
|
||||
buffers to receive before the RX transfers terminate. When both TX and
|
||||
RX transfers terminate, the task exits (and, if an NSH builtin, the
|
||||
i2schar command returns). This number can be changed from the NSH
|
||||
command line.
|
||||
CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE - This is the stack size to use when
|
||||
starting the receiver thread. Default 1536.
|
||||
CONFIG_EXAMPLES_I2SCHAR_BUFSIZE - The size of the data payload in one
|
||||
audio buffer. Applies to both TX and RX audio buffers.
|
||||
CONFIG_EXAMPLES_I2SCHAR_DEVINIT - Define if architecture-specific I2S
|
||||
device initialize is available. If defined, the the platform specific
|
||||
code must provide a function i2schar_devinit() that will be called
|
||||
each time that this test executes. Not available in the kernel build
|
||||
mode.
|
||||
|
||||
examples/json
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
|
11
examples/i2schar/.gitignore
vendored
Normal file
11
examples/i2schar/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
88
examples/i2schar/Kconfig
Normal file
88
examples/i2schar/Kconfig
Normal file
@ -0,0 +1,88 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config EXAMPLES_I2SCHAR
|
||||
bool "I2S character driver test"
|
||||
default n
|
||||
depends on I2S && AUDIO && AUDIO_DEVICES && AUDIO_I2SCHAR
|
||||
---help---
|
||||
Enable the I2S character driver test
|
||||
|
||||
if EXAMPLES_I2SCHAR
|
||||
|
||||
config EXAMPLES_I2SCHAR_DEVPATH
|
||||
string "I2S character device path"
|
||||
default "/dev/i2schar0"
|
||||
---help---
|
||||
The default path to the I2S character device. Default: /dev/i2schar0
|
||||
|
||||
config EXAMPLES_I2SCHAR_TX
|
||||
bool "Use I2S transmitter"
|
||||
default n
|
||||
---help---
|
||||
This should be set if the I2S device supports a transmitter.
|
||||
|
||||
if EXAMPLES_I2SCHAR_TX
|
||||
|
||||
config EXAMPLES_I2SCHAR_TXBUFFERS
|
||||
int "Number of TX buffers"
|
||||
default 4
|
||||
---help---
|
||||
This is the default number of audio buffers to send before the TX
|
||||
transfers terminate. When both TX and RX transfers terminate, the
|
||||
task exits (and, if an NSH builtin, the i2schar command returns).
|
||||
This number can be changed from the NSH command line.
|
||||
|
||||
config EXAMPLES_I2SCHAR_TXSTACKSIZE
|
||||
int "Transmitter thread stack size"
|
||||
default 1536
|
||||
---help---
|
||||
This is the stack size to use when starting the transmitter thread.
|
||||
|
||||
endif # EXAMPLES_I2SCHAR_TX
|
||||
|
||||
config EXAMPLES_I2SCHAR_RX
|
||||
bool "Use I2S receiver"
|
||||
default n
|
||||
---help---
|
||||
This should be set if the I2S device supports a receiver.
|
||||
|
||||
if EXAMPLES_I2SCHAR_RX
|
||||
|
||||
config EXAMPLES_I2SCHAR_RXBUFFERS
|
||||
int "Number of RX buffers"
|
||||
default 4
|
||||
---help---
|
||||
This is the default number of audio buffers to receive before the RX
|
||||
transfers terminate. When both TX and RX transfers terminate, the
|
||||
task exits (and, if an NSH builtin, the i2schar command returns).
|
||||
This number can be changed from the NSH command line.
|
||||
|
||||
config EXAMPLES_I2SCHAR_RXSTACKSIZE
|
||||
int "Receiver thread stack size"
|
||||
default 1536
|
||||
---help---
|
||||
This is the stack size to use when starting the receiver thread.
|
||||
|
||||
endif # EXAMPLES_I2SCHAR_RX
|
||||
|
||||
config EXAMPLES_I2SCHAR_BUFSIZE
|
||||
int "Audio payload size"
|
||||
default 256
|
||||
---help---
|
||||
The size of the data payload in one audio buffer in bytes. Applies
|
||||
to both TX and RX audio buffers.
|
||||
|
||||
config EXAMPLES_I2SCHAR_DEVINIT
|
||||
bool "Architecture-specific device initialization"
|
||||
default 256
|
||||
depends on !NUTTX_KERNEL
|
||||
---help---
|
||||
Define if architecture-specific I2S device initialize is available.
|
||||
If defined, the the platform specific code must provide a function
|
||||
i2schar_devinit() that will be called each time that this test
|
||||
executes. Not available in the kernel build mode.
|
||||
|
||||
endif
|
115
examples/i2schar/Makefile
Normal file
115
examples/i2schar/Makefile
Normal file
@ -0,0 +1,115 @@
|
||||
############################################################################
|
||||
# apps/examples/i2schar/Makefile
|
||||
#
|
||||
# Copyright (C) 2013 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# I2S character driver test
|
||||
|
||||
ASRCS =
|
||||
CSRCS = i2schar_main.c
|
||||
ifeq ($(CONFIG_EXAMPLES_I2SCHAR_TX),y)
|
||||
CSRCS += i2schar_transmitter.c
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_I2SCHAR_RX),y)
|
||||
CSRCS += i2schar_receiver.c
|
||||
endif
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
BIN = ..\..\libapps$(LIBEXT)
|
||||
else
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = ..\\..\\libapps$(LIBEXT)
|
||||
else
|
||||
BIN = ../../libapps$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Touchscreen built-in application info
|
||||
|
||||
APPNAME = i2schar
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: context clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
@touch .built
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
177
examples/i2schar/i2schar.h
Normal file
177
examples/i2schar/i2schar.h
Normal file
@ -0,0 +1,177 @@
|
||||
/****************************************************************************
|
||||
* examples/examples/i2schar/i2schar.h
|
||||
*
|
||||
* Copyright (C) 2013 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_I2SCHAR_I2SCHAR_H
|
||||
#define __APPS_EXAMPLES_I2SCHAR_I2SCHAR_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <pthread.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* CONFIG_NSH_BUILTIN_APPS - Build the I2SCHAR test as an NSH built-in
|
||||
* function. Default: Built as a standalone problem
|
||||
* CONFIG_EXAMPLES_I2SCHAR_DEVPATH - The default path to the I2S character
|
||||
* device. Default: /dev/i2schar0
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_AUDIO_I2SCHAR
|
||||
# error "I2S character device support is not enabled (CONFIG_AUDIO_I2SCHAR)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_I2SCHAR_DEVPATH
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_DEVPATH "/dev/is2char0"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
# ifndef CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS 4
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE 1536
|
||||
# endif
|
||||
#else
|
||||
# undef CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
# ifndef CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS 4
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE 1536
|
||||
# endif
|
||||
#else
|
||||
# undef CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS
|
||||
# define CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_I2SCHAR_BUFSIZE
|
||||
# efine CONFIG_EXAMPLES_I2SCHAR_BUFSIZE 256
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# define msgflush() fflush(stdout)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
# define msgflush() fflush(stdout)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct i2schar_state_s
|
||||
{
|
||||
bool initialized;
|
||||
FAR char *devpath;
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
int txcount;
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
int rxcount;
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
extern struct i2schar_state_s g_i2schar;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_devinit()
|
||||
*
|
||||
* Description:
|
||||
* Perform architecuture-specific initialization of the I2s hardware and
|
||||
* registration of the I2S character driver CHAR hardware. If
|
||||
* CONFIG_EXAMPLES_I2SCHAR_DEVINIT is defined, then board-specific logic
|
||||
* must provide this function.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_DEVINIT
|
||||
int i2schar_devinit(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_transmitter()
|
||||
*
|
||||
* Description:
|
||||
* This is the entry point for the transmitter thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
pthread_addr_t i2schar_transmitter(pthread_addr_t arg);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_receiver()
|
||||
*
|
||||
* Description:
|
||||
* This is the entry point for the receiver thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
pthread_addr_t i2schar_receiver(pthread_addr_t arg);
|
||||
#endif
|
||||
|
||||
#endif /* __APPS_EXAMPLES_I2SCHAR_I2SCHAR_H */
|
344
examples/i2schar/i2schar_main.c
Normal file
344
examples/i2schar/i2schar_main.c
Normal file
@ -0,0 +1,344 @@
|
||||
/****************************************************************************
|
||||
* examples/i2schar/i2schar_main.c
|
||||
*
|
||||
* Copyright (C) 2011-2012 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 <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "i2schar.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
struct i2schar_state_s g_i2schar;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_devpath
|
||||
****************************************************************************/
|
||||
|
||||
static void i2schar_devpath(FAR struct i2schar_state_s *i2schar,
|
||||
FAR const char *devpath)
|
||||
{
|
||||
/* Get rid of any old device path */
|
||||
|
||||
if (i2schar->devpath)
|
||||
{
|
||||
free(i2schar->devpath);
|
||||
}
|
||||
|
||||
/* Then set-up the new device path by copying the string */
|
||||
|
||||
i2schar->devpath = strdup(devpath);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_help
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static void i2schar_help(FAR struct i2schar_state_s *i2schar)
|
||||
{
|
||||
message("Usage: i2schar [OPTIONS]\n");
|
||||
message("\nArguments are \"sticky\". For example, once the I2C character device is\n");
|
||||
message("specified, that device will be re-used until it is changed.\n");
|
||||
message("\n\"sticky\" OPTIONS include:\n");
|
||||
message(" [-p devpath] selects the I2C character device path. "
|
||||
"Default: %s Current: %s\n",
|
||||
CONFIG_EXAMPLES_I2SCHAR_DEVPATH, g_i2schar.devpath ? g_i2schar.devpath : "NONE");
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
message(" [-t count] selects the number of audio buffers to send. "
|
||||
"Default: %d Current: %d\n",
|
||||
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS, i2schar->txcount);
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
message(" [-r count] selects the number of audio buffers to receive. "
|
||||
"Default: %d Current: %d\n",
|
||||
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS, i2schar->txcount);
|
||||
#endif
|
||||
message(" [-h] shows this message and exits\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_string
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static int arg_string(FAR char **arg, FAR char **value)
|
||||
{
|
||||
FAR char *ptr = *arg;
|
||||
|
||||
if (ptr[2] == '\0')
|
||||
{
|
||||
*value = arg[1];
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*value = &ptr[2];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arg_decimal
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static int arg_decimal(FAR char **arg, FAR long *value)
|
||||
{
|
||||
FAR char *string;
|
||||
int ret;
|
||||
|
||||
ret = arg_string(arg, &string);
|
||||
*value = strtol(string, NULL, 10);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: parse_args
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static void parse_args(FAR struct i2schar_state_s *i2schar, int argc, FAR char **argv)
|
||||
{
|
||||
FAR char *ptr;
|
||||
FAR char *str;
|
||||
long value;
|
||||
int index;
|
||||
int nargs;
|
||||
|
||||
for (index = 1; index < argc; )
|
||||
{
|
||||
ptr = argv[index];
|
||||
if (ptr[0] != '-')
|
||||
{
|
||||
message("Invalid options format: %s\n", ptr);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
switch (ptr[1])
|
||||
{
|
||||
case 'p':
|
||||
nargs = arg_string(&argv[index], &str);
|
||||
i2schar_devpath(i2schar, str);
|
||||
index += nargs;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
nargs = arg_decimal(&argv[index], &value);
|
||||
if (value < 0)
|
||||
{
|
||||
message("Count must be non-negative: %ld\n", value);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
i2schar->rxcount = (uint32_t)value;
|
||||
index += nargs;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
nargs = arg_decimal(&argv[index], &value);
|
||||
if (value < 0)
|
||||
{
|
||||
message("Count must be non-negative: %ld\n", value);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
i2schar->txcount = (uint32_t)value;
|
||||
index += nargs;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
i2schar_help(i2schar);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
message("Unsupported option: %s\n", ptr);
|
||||
i2schar_help(i2schar);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_main
|
||||
****************************************************************************/
|
||||
|
||||
int i2schar_main(int argc, char *argv[])
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
pthread_addr_t result;
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
pthread_t transmitter;
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
pthread_t receiver;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
/* Check if we have initialized */
|
||||
|
||||
if (!g_i2schar.initialized)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_DEVINIT
|
||||
/* Initialization of the I2C character device is performed by logic
|
||||
* external to this test.
|
||||
*/
|
||||
|
||||
message("i2schar_main: Initializing external I2C character device\n");
|
||||
ret = i2schar_devinit();
|
||||
if (ret != OK)
|
||||
{
|
||||
message("i2schar_main: i2schar_devinit failed: %d\n", ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the default values */
|
||||
|
||||
i2schar_devpath(&g_i2schar, CONFIG_EXAMPLES_I2SCHAR_DEVPATH);
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
g_i2schar.txcount = CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS;
|
||||
#else
|
||||
g_i2schar.rxcount = CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS;
|
||||
#endif
|
||||
|
||||
g_i2schar.initialized = true;
|
||||
}
|
||||
|
||||
/* Parse the command line */
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
parse_args(&g_i2schar, argc, argv);
|
||||
#endif
|
||||
|
||||
sched_lock();
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
/* Start the transmitter thread */
|
||||
|
||||
message("i2schar_main: Start transmitter thread\n");
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE);
|
||||
|
||||
ret = pthread_create(&transmitter, &attr, i2schar_transmitter, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("i2schar_main: ERROR: failed to Start transmitter thread: %d\n", ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
/* Start the receiver thread */
|
||||
|
||||
message("i2schar_main: Start receiver thread\n");
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE);
|
||||
|
||||
ret = pthread_create(&receiver, &attr, i2schar_receiver, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("i2schar_main: ERROR: failed to Start receiver thread: %d\n", ret);
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
message("i2schar_main: Waiting for the transmitter thread\n");
|
||||
(void)pthread_join(transmitter, &result);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
message("i2schar_main: Waiting for the transmitter thread\n");
|
||||
ret = pthread_join(transmitter, &result);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("i2schar_main: ERROR: pthread_join failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
message("i2schar_main: Waiting for the receiver thread\n");
|
||||
ret = pthread_join(receiver, &result);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("i2schar_main: ERROR: pthread_join failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
174
examples/i2schar/i2schar_receiver.c
Normal file
174
examples/i2schar/i2schar_receiver.c
Normal file
@ -0,0 +1,174 @@
|
||||
/****************************************************************************
|
||||
* examples/i2schar/i2schar_receiver.c
|
||||
*
|
||||
* Copyright (C) 2013 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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/audio/audio.h>
|
||||
|
||||
#include "i2schar.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_RX
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_receiver()
|
||||
*
|
||||
* Description:
|
||||
* This is the entry point for the receiver thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pthread_addr_t i2schar_receiver(pthread_addr_t arg)
|
||||
{
|
||||
FAR struct ap_buffer_s *apb;
|
||||
struct audio_buf_desc_s desc;
|
||||
int bufsize;
|
||||
int nread;
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
/* Open the I2C character device */
|
||||
|
||||
fd = open(g_i2schar.devpath, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
message("i2schar_receiver: ERROR: failed to open %s: %d\n",
|
||||
g_i2schar.devpath, errcode);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/* Loop for the requested number of times */
|
||||
|
||||
for (i = 0; i < CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS; i++)
|
||||
{
|
||||
/* Allocate an audio buffer of the configured size */
|
||||
|
||||
desc.numbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE;
|
||||
desc.u.ppBuffer = &apb;
|
||||
|
||||
bufsize = apb_alloc(&desc);
|
||||
if (bufsize < 0)
|
||||
{
|
||||
message("i2schar_receiver: ERROR: failed to allocate buffer %d: %d\n",
|
||||
i+1, bufsize);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/* Then receifve into the buffer */
|
||||
|
||||
do
|
||||
{
|
||||
/* Flush any output before reading */
|
||||
|
||||
msgflush();
|
||||
|
||||
/* Read the buffer to the I2S character driver */
|
||||
|
||||
nread = read(fd, apb, bufsize);
|
||||
if (nread < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
if (errcode != EINTR)
|
||||
{
|
||||
message("i2schar_receiver: ERROR: read failed: %d\n",
|
||||
errcode);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
else if (nread != bufsize)
|
||||
{
|
||||
message("i2schar_receiver: ERROR: partial read: %d\n",
|
||||
nread);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
message("i2schar_receiver: Received buffer %d\n", i+1);
|
||||
}
|
||||
}
|
||||
while (nread != bufsize);
|
||||
|
||||
/* Make sure that the transmitter thread has a chance to run */
|
||||
|
||||
pthread_yield();
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EXAMPLES_I2SCHAR_RX */
|
184
examples/i2schar/i2schar_transmitter.c
Normal file
184
examples/i2schar/i2schar_transmitter.c
Normal file
@ -0,0 +1,184 @@
|
||||
/****************************************************************************
|
||||
* examples/i2schar/i2schar_transmitter.c
|
||||
*
|
||||
* Copyright (C) 2013 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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/audio/audio.h>
|
||||
|
||||
#include "i2schar.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_I2SCHAR_TX
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_transmitter()
|
||||
*
|
||||
* Description:
|
||||
* This is the entry point for the transmitter thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pthread_addr_t i2schar_transmitter(pthread_addr_t arg)
|
||||
{
|
||||
FAR struct ap_buffer_s *apb;
|
||||
struct audio_buf_desc_s desc;
|
||||
uint8_t crap;
|
||||
uint8_t *ptr;
|
||||
int bufsize;
|
||||
int nwritten;
|
||||
int fd;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
/* Open the I2C character device */
|
||||
|
||||
fd = open(g_i2schar.devpath, O_WRONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
message("i2schar_transmitter: ERROR: failed to open %s: %d\n",
|
||||
g_i2schar.devpath, errcode);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/* Loop for the requested number of times */
|
||||
|
||||
for (i = 0, crap = 0; i < CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS; i++)
|
||||
{
|
||||
/* Allocate an audio buffer of the configured size */
|
||||
|
||||
desc.numbytes = CONFIG_EXAMPLES_I2SCHAR_BUFSIZE;
|
||||
desc.u.ppBuffer = &apb;
|
||||
|
||||
bufsize = apb_alloc(&desc);
|
||||
if (bufsize < 0)
|
||||
{
|
||||
message("i2schar_transmitter: ERROR: failed to allocate buffer %d: %d\n",
|
||||
i+1, bufsize);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
/* Fill the audio buffer with crap */
|
||||
|
||||
for (j = 0, ptr = apb->samp; j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++)
|
||||
{
|
||||
*ptr++ = crap++;
|
||||
}
|
||||
|
||||
/* Then send the buffer */
|
||||
|
||||
do
|
||||
{
|
||||
/* Flush any output before writing */
|
||||
|
||||
msgflush();
|
||||
|
||||
/* Write the buffer to the I2S character driver */
|
||||
|
||||
nwritten = write(fd, apb, bufsize);
|
||||
if (nwritten < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
if (errcode != EINTR)
|
||||
{
|
||||
message("i2schar_transmitter: ERROR: write failed: %d\n",
|
||||
errcode);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
else if (nwritten != bufsize)
|
||||
{
|
||||
message("i2schar_transmitter: ERROR: partial write: %d\n",
|
||||
nwritten);
|
||||
close(fd);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
message("i2schar_transmitter: Send buffer %d\n", i+1);
|
||||
}
|
||||
}
|
||||
while (nwritten != bufsize);
|
||||
|
||||
/* Make sure that the receiver thread has a chance to run */
|
||||
|
||||
pthread_yield();
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EXAMPLES_I2SCHAR_TX */
|
Loading…
Reference in New Issue
Block a user