Add new framework for the PCM decoder. It is now a 'front end' for lower-level drivers like the WM8904 that performs the PCM decoding from end

This commit is contained in:
Gregory Nutt
2014-07-22 11:54:13 -06:00
parent 8548c64915
commit a4dcd690bb
9 changed files with 720 additions and 85 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ VPATH = .
# the appropriate paths to the VPATH variable # the appropriate paths to the VPATH variable
ifeq ($(CONFIG_AUDIO_FORMAT_PCM),y) ifeq ($(CONFIG_AUDIO_FORMAT_PCM),y)
CSRCS += pcm.c CSRCS += pcm_decode.c
endif endif
AOBJS = $(ASRCS:.S=$(OBJEXT)) AOBJS = $(ASRCS:.S=$(OBJEXT))
+1 -1
View File
@@ -21,7 +21,7 @@ layer for specific lower-half audio device drivers.
drivers/audio subdirectory. For each attached audio device, there drivers/audio subdirectory. For each attached audio device, there
will be an instance of this upper-half driver bound to the will be an instance of this upper-half driver bound to the
instance of the lower half driver context. instance of the lower half driver context.
pcm.c - Routines to manage PCM / WAV type data. Currently just a placeholder. pcm_decode.c - Routines to decode PCM / WAV type data.
README - This file! README - This file!
Portions of the the audio system interface have application interfaces. Those Portions of the the audio system interface have application interfaces. Those
+564
View File
File diff suppressed because it is too large Load Diff
+19 -4
View File
@@ -243,11 +243,26 @@
#define PIO_SSC0_TD PIO_SSC0_TD_2 #define PIO_SSC0_TD PIO_SSC0_TD_2
/* PCK0 is provided to the WM8904 audio CODEC via PB26 */ /* PCK2 is provides the MCLK to the WM8904 audio CODEC via PB10 */
#ifdef CONFIG_AUDIO_WM8904 #define PIO_PMC_PCK2 PIO_PMC_PCK2_1
# define PIO_PMC_PCK0 PIO_PMC_PCK0_1
#endif /* PCK0 and PCK1 are not currently used, but the PCK logic wants these definitions
* anyway. The assignments here are arbitrary and will not be used (at least not
* until we implement ISI of HDMI).
*
* PIO_PMC_PCK0_1: PB26 is used by I2S with the WM8904 (AUDIO_RK0_PB26)
* PIO_PMC_PCK0_2: PD8 is the HDMI MCLK (HDMI_MCK_PD8)
* PIO_PMC_PCK0_3: PA24 is used for the LCD backlight (LCD_PWM_PA24)
*
* PIO_PMC_PCK1_1: PD31 goes to the expansion interface and is not used on-board
* (EXP_PD31).
* PIO_PMC_PCK1_2: PC24 is used for ISI data (ISI_D5)
* PIO_PMC_PCK1_3: PC4 is ISI_MCK_PC4, MCI0_CK_PC4, EXP_PC4
*/
#define PIO_PMC_PCK0 PIO_PMC_PCK0_2
#define PIO_PMC_PCK1 PIO_PMC_PCK1_1
/************************************************************************************ /************************************************************************************
* Assembly Language Macros * Assembly Language Macros
+17 -7
View File
@@ -87,7 +87,7 @@
int nsh_archinitialize(void) int nsh_archinitialize(void)
{ {
#if defined(HAVE_NAND) || defined(HAVE_AT25) || defined(HAVE_HSMCI) || \ #if defined(HAVE_NAND) || defined(HAVE_AT25) || defined(HAVE_HSMCI) || \
defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) || defined(HAVE_WM8904)
int ret; int ret;
#endif #endif
@@ -98,7 +98,6 @@ int nsh_archinitialize(void)
if (ret < 0) if (ret < 0)
{ {
message("ERROR: sam_nand_automount failed: %d\n", ret); message("ERROR: sam_nand_automount failed: %d\n", ret);
return ret;
} }
#endif #endif
@@ -109,7 +108,6 @@ int nsh_archinitialize(void)
if (ret < 0) if (ret < 0)
{ {
message("ERROR: sam_at25_automount failed: %d\n", ret); message("ERROR: sam_at25_automount failed: %d\n", ret);
return ret;
} }
#endif #endif
@@ -122,7 +120,6 @@ int nsh_archinitialize(void)
{ {
message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
HSMCI0_SLOTNO, HSMCI0_MINOR, ret); HSMCI0_SLOTNO, HSMCI0_MINOR, ret);
return ret;
} }
#endif #endif
@@ -134,7 +131,6 @@ int nsh_archinitialize(void)
{ {
message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
HSMCI1_SLOTNO, HSMCI1_MINOR, ret); HSMCI1_SLOTNO, HSMCI1_MINOR, ret);
return ret;
} }
#endif #endif
#endif #endif
@@ -148,7 +144,6 @@ int nsh_archinitialize(void)
if (ret != OK) if (ret != OK)
{ {
message("ERROR: Failed to initialize USB host: %d\n", ret); message("ERROR: Failed to initialize USB host: %d\n", ret);
return ret;
} }
#endif #endif
@@ -158,9 +153,24 @@ int nsh_archinitialize(void)
ret = usbmonitor_start(0, NULL); ret = usbmonitor_start(0, NULL);
if (ret != OK) if (ret != OK)
{ {
message("nsh_archinitialize: Start USB monitor: %d\n", ret); message("ERROR: Failed to start the USB monitor: %d\n", ret);
} }
#endif #endif
#ifdef HAVE_WM8904
/* Start the USB Monitor */
ret = sam_wm8904_initialize(0);
if (ret != OK)
{
message("ERROR: Failed to initialize WM8904 audio: %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.
*/
return OK; return OK;
} }
+32 -14
View File
@@ -48,6 +48,7 @@
#include <nuttx/i2c.h> #include <nuttx/i2c.h>
#include <nuttx/audio/i2s.h> #include <nuttx/audio/i2s.h>
#include <nuttx/audio/wm8904.h> #include <nuttx/audio/wm8904.h>
#include <nuttx/audio/pcm_decode.h>
#include <arch/board/board.h> #include <arch/board/board.h>
@@ -220,11 +221,12 @@ static int wm8904_interrupt(int irq, FAR void *context)
int sam_wm8904_initialize(int minor) int sam_wm8904_initialize(int minor)
{ {
FAR struct audio_lowerhalf_s *audio; FAR struct audio_lowerhalf_s *wm8904;
FAR struct audio_lowerhalf_s *pcm;
FAR struct i2c_dev_s *i2c; FAR struct i2c_dev_s *i2c;
FAR struct i2s_dev_s *i2s; FAR struct i2s_dev_s *i2s;
static bool initialized = false; static bool initialized = false;
char devname[8]; char devname[12];
int ret; int ret;
auddbg("minor %d\n", minor); auddbg("minor %d\n", minor);
@@ -266,21 +268,20 @@ int sam_wm8904_initialize(int minor)
* MW8904 which will return an audio interface. * MW8904 which will return an audio interface.
*/ */
audio = wm8904_initialize(i2c, i2s, &g_mxtinfo.lower, minor); wm8904 = wm8904_initialize(i2c, i2s, &g_mxtinfo.lower);
if (!audio) if (!wm8904)
{ {
auddbg("Failed to initialize the WM8904\n"); auddbg("Failed to initialize the WM8904\n");
ret = -ENODEV; ret = -ENODEV;
goto errout_with_i2s; goto errout_with_i2s;
} }
/* Configure the DAC master clock. This clock is provided by PCK0 (PB26) /* Configure the DAC master clock. This clock is provided by PCK2 (PB10)
* that is connected to the WM8904 BCLK/GPIO4 and also drives the SSC * that is connected to the WM8904 MCLK.
* TK0 input clock.
*/ */
sam_sckc_enable(true); sam_sckc_enable(true);
(void)sam_pck_configure(PCK0, PCKSRC_SCK, BOARD_SLOWCLK_FREQUENCY); (void)sam_pck_configure(PCK2, PCKSRC_SCK, BOARD_SLOWCLK_FREQUENCY);
/* Enable the DAC master clock */ /* Enable the DAC master clock */
@@ -292,21 +293,37 @@ int sam_wm8904_initialize(int minor)
ret = irq_attach(IRQ_INT_WM8904, wm8904_interrupt); ret = irq_attach(IRQ_INT_WM8904, wm8904_interrupt);
if (ret < 0) if (ret < 0)
{ {
auddbg("ERROR: Failed to register WM8904 device: %d\n", ret); auddbg("ERROR: Failed to attach WM8904 interrupt: %d\n", ret);
goto errout_with_audio; goto errout_with_audio;
} }
/* No we can embed the WM8904/I2C/I2S conglomerate into a PCM decoder
* instance so that we will have a PCM front end for the the WM8904
* driver.
*/
pcm = pcm_decode_initialize(wm8904);
if (!pcm)
{
auddbg("ERROR: Failed create the PCM decoder\n");
ret = -ENODEV;
goto errout_with_irq;
}
/* Create a device name */ /* Create a device name */
snprintf(devname, 8, "wm8904%c", 'a' + minor); snprintf(devname, 12, "pcm%d", minor);
/* Register the WM8904 audio device */ /* Finally, we can register the PCM/WM8904/I2C/I2S audio device.
*
* Is anyone young enough to remember Rube Goldberg?
*/
ret = audio_register(devname, audio); ret = audio_register(devname, pcm);
if (ret < 0) if (ret < 0)
{ {
auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret); auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret);
goto errout_with_irq; goto errout_with_pcm;
} }
/* Now we are initialized */ /* Now we are initialized */
@@ -317,9 +334,10 @@ int sam_wm8904_initialize(int minor)
return OK; return OK;
/* Error exits. Unfortunately there is no mechanism in place now to /* Error exits. Unfortunately there is no mechanism in place now to
* recover errors on initialization failures. * recover from most errors on initialization failures.
*/ */
errout_with_pcm:
errout_with_irq: errout_with_irq:
irq_detach(IRQ_INT_WM8904); irq_detach(IRQ_INT_WM8904);
errout_with_audio: errout_with_audio:
+5
View File
@@ -334,6 +334,11 @@
# undef HAVE_WM8904 # undef HAVE_WM8904
# endif # endif
# ifndef CONFIG_AUDIO_FORMAT_PCM
# warning CONFIG_AUDIO_FORMAT_PCM is required for audio support
# undef HAVE_WM8904
# endif
# ifndef CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY # ifndef CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY
# warning Defaulting to maximum WM8904 I2C frequency # warning Defaulting to maximum WM8904 I2C frequency
# define CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY 400000 # define CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY 400000
+6 -7
View File
@@ -375,8 +375,7 @@ struct audio_msg_s
} u; } u;
}; };
/* Structure defining the built-in sounds */
/* Strucure defining the built-in sounds */
#ifdef CONFIG_AUDIO_BUILTIN_SOUNDS #ifdef CONFIG_AUDIO_BUILTIN_SOUNDS
struct audio_sound_s struct audio_sound_s
@@ -390,7 +389,7 @@ struct audio_sound_s
#endif #endif
/* Structure for allocating, freeing and enqueuing audio pipeline /* Structure for allocating, freeing and enqueueing audio pipeline
* buffers via the AUDIOIOC_ALLOCBUFFER, AUDIOIOC_FREEBUFFER, * buffers via the AUDIOIOC_ALLOCBUFFER, AUDIOIOC_FREEBUFFER,
* and AUDIOIOC_ENQUEUEBUFFER ioctls. * and AUDIOIOC_ENQUEUEBUFFER ioctls.
*/ */
@@ -404,7 +403,7 @@ struct audio_buf_desc_s
union union
{ {
FAR struct ap_buffer_s *pBuffer; /* Buffer to free / enqueue */ FAR struct ap_buffer_s *pBuffer; /* Buffer to free / enqueue */
FAR struct ap_buffer_s **ppBuffer; /* Pointer to receive alloced buffer */ FAR struct ap_buffer_s **ppBuffer; /* Pointer to receive allocated buffer */
} u; } u;
}; };
@@ -467,7 +466,7 @@ struct audio_ops_s
/* Start audio streaming in the configured mode. For input and synthesis /* Start audio streaming in the configured mode. For input and synthesis
* devices, this means it should begin sending streaming audio data. For output * devices, this means it should begin sending streaming audio data. For output
* or processing type device, it means it should begin processing of any enqueued * or processing type device, it means it should begin processing of any enqueued
* Audio Pipline Buffers. * Audio Pipeline Buffers.
*/ */
#ifdef CONFIG_AUDIO_MULTI_SESSION #ifdef CONFIG_AUDIO_MULTI_SESSION
@@ -568,7 +567,7 @@ struct audio_ops_s
*/ */
#ifdef CONFIG_AUDIO_MULTI_SESSION #ifdef CONFIG_AUDIO_MULTI_SESSION
CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev, FAR void **psession ); CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev, FAR void **psession);
#else #else
CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev); CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev);
#endif #endif
@@ -576,7 +575,7 @@ struct audio_ops_s
/* Release a session. */ /* Release a session. */
#ifdef CONFIG_AUDIO_MULTI_SESSION #ifdef CONFIG_AUDIO_MULTI_SESSION
CODE int (*release)(FAR struct audio_lowerhalf_s *dev, FAR void *session ); CODE int (*release)(FAR struct audio_lowerhalf_s *dev, FAR void *session);
#else #else
CODE int (*release)(FAR struct audio_lowerhalf_s *dev); CODE int (*release)(FAR struct audio_lowerhalf_s *dev);
#endif #endif
@@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* audio/pcm.c * include/nuttx/audio/pcm_decode.h
* *
* Copyright (C) 2013 Ken Pettit. All rights reserved. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Ken Pettit <pettitkd@gmail.com> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -33,62 +33,86 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H
#define __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <semaphore.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h> #include <nuttx/irq.h>
#include <nuttx/audio/audio.h>
#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM) #ifdef CONFIG_AUDIO_FORMAT_PCM
/**************************************************************************** /****************************************************************************
* Preprocessor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************
/* Configuration ************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: audio_pcm_init
*
* Initialized the Audio PCM library.
* *
* CONFIG_AUDIO_FORMAT_PCM - Enabled PCM support
*/
/* Pre-requisites */
#ifndef CONFIG_AUDIO
# error CONFIG_AUDIO is required for PCM support
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
# error CONFIG_SCHED_WORKQUEUE is required by the PCM driver
#endif
/* Default configuration values */
/****************************************************************************
* Public Types
****************************************************************************/ ****************************************************************************/
int audio_pcm_initialize(void) /****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{ {
/* Initialze the Audio PCM routines */ #else
#define EXTERN extern
#endif
return OK; /****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: pcm_decode_initialize
*
* Description:
* Initialize the PCM device. The PCM device accepts and contains a
* low-level audio DAC-type device. It then returns a new audio lower
* half interface at adds a PCM decoding from end to the low-level
* audio device
*
* Input Parameters:
* dev - A reference to the low-level audio DAC-type device to contain.
*
* Returned Value:
* On success, a new audio device instance is returned that wraps the
* low-level device and provides a PCM decoding front end. NULL is
* returned on failure.
*
****************************************************************************/
FAR struct audio_lowerhalf_s *
pcm_decode_initialize(FAR struct audio_lowerhalf_s *dev);
#undef EXTERN
#ifdef __cplusplus
} }
#endif
#endif /* CONFIG_AUDIO && CONFIG_AUDIO_FORMAT_PCM */ #endif /* CONFIG_AUDIO_FORMAT_PCM */
#endif /* __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H */