The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

Dependencies:   GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom

Fork of GR-PEACH_Audio_Playback_Sample by Renesas

Note

For a sample program of without LCD Board, please refer to GR-PEACH_Audio_Playback_Sample.

Introduction

The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/1050186/lcd_figure1_1.png

1.2 Pin Definitions

Table 1.1 shows the pins used in this sample code.

/media/uploads/1050186/lcd_table1_1.png

2. Sample Code Operating Environment

In order to operate this sample code, GR-PEACH, Audio Camera Shield and 7.1 inch LCD Shield must be needed. For details on Audio Camera Shield and 7.1 inch LCD Shield, please refer to the following links, respectively:

In this section, it is described that how board is configured and to control audio playback via command line and touch screen.

2.1 Operating Environment

Figure 2.1 shows the overview of the operating environment for this sample code.

/media/uploads/1050186/lcd_figure2_1.png

Figure 2.2 and 2.3 show how to configure GR-PEACH, Audio Camera Shield and 7.1 inch LCD shield when using USB0 and USB1, respectively.

/media/uploads/1050186/lcd_figure2_2.png /media/uploads/1050186/lcd_figure2_3.png

Table 2.1 lists the overview of Graphical User Interface (GUI) of this sample code.

/media/uploads/1050186/lcd_table2_1.png

2.2 List of User Operations

Table 2.2 shows the relationship among Audio Playback, Command Line and Onboard Switch.

/media/uploads/1050186/lcd_table2_2.png

3. Function Outline

Table 3.1, 3.2 and 3.3 shows the overview of functions implemented in this sample code.

/media/uploads/1050186/lcd_table3_1.png /media/uploads/1050186/lcd_table3_2.png /media/uploads/1050186/lcd_table3_3.png /media/uploads/1050186/lcd_figure3_1.png

3.1 Playback Control

This sample program supports the operation "play", "pause", "stop", "play next song" and "play previous song".

3.2 Trick Play Control

In order to enable/disable Repeat Mode, user need to type "repeat" on command line or click the corresponding icon shown in Table 2.2. By derault, Repeat Mode is enabled. When Repeat Mode is enabled, the first song is played back after the playback of the last song is finished. Otherwise, the playback is shopped when finishing to play back the last song.

3.3 How to see Song Information

The information of the song being played back can be seen by typing playinfo on command line. Table 3.4 lists the items user can see on the terminal.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How to analyze the folder structure in USB stick

In this sample code, the folder structure in USB stick is analyzed in the breadth-first order. Table 3.5 shows how the files in USB stick are numbered.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

4.1 Serial Communication Setting

With respect to the default serial communication related setting on mbed, please refer to the follwing link:
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Please set up the terminal software you would like to use on your PC in consideration of the above. For example, 9600 should be specified for the baud rate on the terminal in order to control this sample via command line.

4.2 Necessary modification when using GCC ARM Embedded

If you would like to use GCC ARM Embedded, you must revise the following linker script incorporated in mbed OS 5 package as follows:

  • Linker Script to be modified
    $(PROJECT_ROOT)/mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1H/device/TOOLCHAIN_GCC_ARM/RZA1H.ld

    Please note that $(PROJECT_ROOT) in the above denotes the root directory of this sample code

  • Before Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00700000
  RAM_NC (rwx) : ORIGIN = 0x20900000, LENGTH = 0x00100000
}
(snip)
  • After Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00180000
  RAM_NC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00680000
}
(snip)
Committer:
Osamu Nakamura
Date:
Tue Apr 11 12:42:10 2017 +0900
Revision:
6:a957aaa284f0
Parent:
4:2672de88a46b
Update R-BSP from rev. cbb9d60c8748 to fb9eda52224e so that this program can be compiled with IAR toolchain.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:ee40da884cfc 1 /*******************************************************************************
dkato 0:ee40da884cfc 2 * DISCLAIMER
dkato 0:ee40da884cfc 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:ee40da884cfc 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:ee40da884cfc 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:ee40da884cfc 6 * all applicable laws, including copyright laws.
dkato 0:ee40da884cfc 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:ee40da884cfc 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:ee40da884cfc 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:ee40da884cfc 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:ee40da884cfc 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:ee40da884cfc 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:ee40da884cfc 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:ee40da884cfc 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:ee40da884cfc 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:ee40da884cfc 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:ee40da884cfc 17 * and to discontinue the availability of this software. By using this software,
dkato 0:ee40da884cfc 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:ee40da884cfc 19 * following link:
dkato 0:ee40da884cfc 20 * http://www.renesas.com/disclaimer*
dkato 0:ee40da884cfc 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:ee40da884cfc 22 *******************************************************************************/
dkato 0:ee40da884cfc 23
dkato 0:ee40da884cfc 24 #include "mbed.h"
dkato 0:ee40da884cfc 25 #include "rtos.h"
dkato 0:ee40da884cfc 26 #include "misratypes.h"
dkato 0:ee40da884cfc 27 #include "r_errno.h"
dkato 0:ee40da884cfc 28 #include "decode.h"
dkato 0:ee40da884cfc 29 #include "audio_out.h"
dkato 0:ee40da884cfc 30 #include "display.h"
dkato 0:ee40da884cfc 31 #include "TLV320_RBSP.h"
dkato 0:ee40da884cfc 32
dkato 0:ee40da884cfc 33 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 34 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 35 #define MAIL_PARAM_NUM (3) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 /* aud_mail_t */
dkato 0:ee40da884cfc 38 #define MAIL_PARAM0 (0) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 39 #define MAIL_PARAM1 (1) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 40 #define MAIL_PARAM2 (2) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 41
dkato 0:ee40da884cfc 42 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 0:ee40da884cfc 43
dkato 0:ee40da884cfc 44 /* mail_id = AUD_MAILID_DATA_OUT */
dkato 0:ee40da884cfc 45 #define MAIL_DATA_OUT_CB (MAIL_PARAM0) /* Callback function */
dkato 0:ee40da884cfc 46
dkato 0:ee40da884cfc 47 /* mail_id = AUD_MAILID_ZERO_OUT : No parameter */
dkato 0:ee40da884cfc 48
dkato 0:ee40da884cfc 49 /* mail_id = AUD_MAILID_SCUX_READ_FIN */
dkato 0:ee40da884cfc 50 #define MAIL_SCUX_READ_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 51 #define MAIL_SCUX_READ_BUF_INDEX (MAIL_PARAM1) /* Index number of PCM buffer */
dkato 0:ee40da884cfc 52 #define MAIL_SCUX_READ_BYTE_NUM (MAIL_PARAM2) /* Byte number of PCM data */
dkato 0:ee40da884cfc 53
dkato 0:ee40da884cfc 54 /* mail_id = AUD_MAILID_PCM_OUT_FIN */
dkato 0:ee40da884cfc 55 #define MAIL_PCM_OUT_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 56 #define MAIL_PCM_OUT_BUF_INDEX (MAIL_PARAM1) /* Index number of PCM buffer */
dkato 0:ee40da884cfc 57
1050186 4:2672de88a46b 58 /* mail_id = AUD_MAILID_GET_AUDIO */
1050186 4:2672de88a46b 59 #define MAIL_GET_AUDIO_CB (MAIL_PARAM0) /* Callback function */
1050186 4:2672de88a46b 60 #define MAIL_GET_AUDIO_BUF (MAIL_PARAM1) /* Pointer to the display buffer array */
1050186 4:2672de88a46b 61 #define MAIL_GET_AUDIO_NUM (MAIL_PARAM2) /* Elements number of the display buffer array */
1050186 4:2672de88a46b 62
dkato 0:ee40da884cfc 63 /*--- Macro definition of PCM buffer ---*/
dkato 0:ee40da884cfc 64 #define UNIT_TIME_MS (10u) /* Unit time of PCM data processing (ms) */
dkato 0:ee40da884cfc 65 #define SEC_TO_MSEC (1000u)
dkato 0:ee40da884cfc 66
dkato 0:ee40da884cfc 67 /* Sample number per unit time (ms) */
dkato 0:ee40da884cfc 68 #define SAMPLE_PER_UNIT_MS ((UNIT_TIME_MS * DEC_OUTPUT_SAMPLE_RATE) / SEC_TO_MSEC)
dkato 0:ee40da884cfc 69
dkato 0:ee40da884cfc 70 #define OUTPUT_START_TRIGGER (3) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 71 /* to start the output of PCM data */
dkato 0:ee40da884cfc 72 #define OUTPUT_UPDATE_TRIGGER (1) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 73 /* to update the output of PCM data */
dkato 0:ee40da884cfc 74
dkato 2:d9fca8cd7f03 75 #define PCM_BUF_NUM (DEC_SCUX_READ_NUM)
dkato 0:ee40da884cfc 76 #define TOTAL_SAMPLE_NUM (SAMPLE_PER_UNIT_MS * DEC_OUTPUT_CHANNEL_NUM)
dkato 0:ee40da884cfc 77
dkato 0:ee40da884cfc 78 /*--- Macro definition of TLV320_RBSP ---*/
dkato 0:ee40da884cfc 79 #define AUDIO_POWER_MIC_OFF (0x02) /* Microphone input :OFF */
dkato 0:ee40da884cfc 80 #define AUDIO_INT_LEVEL (0x80)
dkato 0:ee40da884cfc 81 #define AUDIO_READ_NUM (0)
dkato 0:ee40da884cfc 82 #define AUDIO_WRITE_NUM (PCM_BUF_NUM)
dkato 0:ee40da884cfc 83 #define ERR_MSG_TLV320_RBSP_WRITE "\nError: TLV320_RBSP::write()\n"
dkato 0:ee40da884cfc 84
dkato 0:ee40da884cfc 85 /* 4 bytes aligned. No cache memory. */
dkato 0:ee40da884cfc 86 #define NC_BSS_SECT __attribute__((section("NC_BSS"),aligned(4)))
dkato 0:ee40da884cfc 87 #define ERR_MSG_RECV_ILLEGAL_MAIL "\nError: aud_thread function received illegal mail.\n"
dkato 0:ee40da884cfc 88
dkato 0:ee40da884cfc 89 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 90 typedef enum {
dkato 0:ee40da884cfc 91 AUD_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 92 AUD_MAILID_DATA_OUT, /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 93 AUD_MAILID_ZERO_OUT, /* Requests the output of zero data. */
dkato 0:ee40da884cfc 94 AUD_MAILID_SCUX_READ_FIN, /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 95 AUD_MAILID_PCM_OUT_FIN, /* Finished the output of data. */
1050186 4:2672de88a46b 96 AUD_MAILID_GET_AUDIO, /* Requests the audio data acquisition. */
dkato 0:ee40da884cfc 97 AUD_MAILID_NUM
dkato 0:ee40da884cfc 98 } AUD_MAIL_ID;
dkato 0:ee40da884cfc 99
dkato 0:ee40da884cfc 100 typedef struct {
dkato 0:ee40da884cfc 101 AUD_MAIL_ID mail_id;
dkato 0:ee40da884cfc 102 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 103 } aud_mail_t;
dkato 0:ee40da884cfc 104
dkato 0:ee40da884cfc 105 /*--- User defined types of audio output thread ---*/
dkato 0:ee40da884cfc 106 /* The control data of PCM buffer. */
dkato 0:ee40da884cfc 107 typedef struct {
dkato 0:ee40da884cfc 108 uint32_t pcm_buf_index; /* Index of PCM buffer array */
dkato 0:ee40da884cfc 109 uint32_t pcm_buf_remain_cnt; /* Counter of the remain elements in PCM buffer array */
dkato 0:ee40da884cfc 110 uint32_t pcm_stock_cnt; /* Counter of the stock elements in PCM buffer array */
dkato 0:ee40da884cfc 111 uint32_t output_trg_cnt; /* Number of the trigger to start the output of PCM data */
dkato 0:ee40da884cfc 112 } pcm_buf_ctrl_t;
dkato 0:ee40da884cfc 113
dkato 0:ee40da884cfc 114 static Mail<aud_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 115
dkato 0:ee40da884cfc 116 static void init_pcm_buf(pcm_buf_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 117 static bool read_scux(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id);
1050186 4:2672de88a46b 118 static bool write_audio(TLV320_RBSP * const p_audio, int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id);
dkato 0:ee40da884cfc 119 static void read_callback(void * p_data, int32_t result, void * p_app_data);
dkato 0:ee40da884cfc 120 static void pcm_out_callback(void * p_data, int32_t result, void * p_app_data);
dkato 0:ee40da884cfc 121 static bool send_mail(const AUD_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 122 const uint32_t param1, const uint32_t param2);
dkato 0:ee40da884cfc 123 static bool recv_mail(AUD_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 124 uint32_t * const p_param1, uint32_t * const p_param2);
dkato 0:ee40da884cfc 125
dkato 0:ee40da884cfc 126 void aud_thread(void const *argument)
dkato 0:ee40da884cfc 127 {
dkato 0:ee40da884cfc 128 pcm_buf_ctrl_t buf_ctrl;
dkato 0:ee40da884cfc 129 pcm_buf_ctrl_t * const p_ctrl = &buf_ctrl;
dkato 0:ee40da884cfc 130 bool scux_read_enable = false;
dkato 0:ee40da884cfc 131 AUD_MAIL_ID mail_type;
dkato 0:ee40da884cfc 132 uint32_t mail_param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 133 bool result;
dkato 0:ee40da884cfc 134 AUD_CbDataOut cb_data_out;
dkato 0:ee40da884cfc 135 uint32_t i;
dkato 0:ee40da884cfc 136 uint32_t buf_id;
dkato 0:ee40da884cfc 137 int32_t *p_buf;
dkato 0:ee40da884cfc 138 uint32_t byte_cnt;
1050186 4:2672de88a46b 139 AUD_CbAudioData cb_audio_data;
dkato 0:ee40da884cfc 140 static int32_t NC_BSS_SECT pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM];
1050186 4:2672de88a46b 141 static TLV320_RBSP audio(P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7,
1050186 4:2672de88a46b 142 P4_6, AUDIO_INT_LEVEL, AUDIO_WRITE_NUM, AUDIO_READ_NUM);
dkato 0:ee40da884cfc 143
dkato 0:ee40da884cfc 144 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 145
dkato 0:ee40da884cfc 146 /* Initializes the control data of PCM buffer. */
dkato 0:ee40da884cfc 147 init_pcm_buf(p_ctrl);
dkato 0:ee40da884cfc 148
dkato 0:ee40da884cfc 149 /* Sets the output of PCM data using TLV320_RBSP. */
dkato 0:ee40da884cfc 150 (void) audio.format(DEC_OUTPUT_BITS_PER_SAMPLE);
dkato 0:ee40da884cfc 151 (void) audio.frequency(DEC_OUTPUT_SAMPLE_RATE);
dkato 0:ee40da884cfc 152 audio.power(AUDIO_POWER_MIC_OFF);
dkato 0:ee40da884cfc 153 while (1) {
dkato 0:ee40da884cfc 154 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0],
dkato 0:ee40da884cfc 155 &mail_param[MAIL_PARAM1], &mail_param[MAIL_PARAM2]);
dkato 0:ee40da884cfc 156 if (result == true) {
dkato 0:ee40da884cfc 157 switch (mail_type) {
dkato 0:ee40da884cfc 158 case AUD_MAILID_DATA_OUT: /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 159 cb_data_out = (AUD_CbDataOut)mail_param[MAIL_DATA_OUT_CB];
dkato 0:ee40da884cfc 160 if (scux_read_enable != true) {
dkato 0:ee40da884cfc 161 scux_read_enable = true;
dkato 0:ee40da884cfc 162 result = true;
dkato 0:ee40da884cfc 163 for (i = 0; (i < p_ctrl->pcm_buf_remain_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 164 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 165 result = read_scux(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 166 }
dkato 0:ee40da884cfc 167 if (result == true) {
dkato 0:ee40da884cfc 168 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 169 }
dkato 0:ee40da884cfc 170 } else {
dkato 0:ee40da884cfc 171 result = false;
dkato 0:ee40da884cfc 172 }
dkato 0:ee40da884cfc 173 cb_data_out(result);
dkato 0:ee40da884cfc 174 break;
dkato 0:ee40da884cfc 175 case AUD_MAILID_ZERO_OUT: /* Requests the output of zero data. */
dkato 0:ee40da884cfc 176 scux_read_enable = false;
dkato 0:ee40da884cfc 177 break;
dkato 0:ee40da884cfc 178 case AUD_MAILID_SCUX_READ_FIN: /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 179 buf_id = mail_param[MAIL_SCUX_READ_BUF_INDEX];
dkato 0:ee40da884cfc 180 byte_cnt = mail_param[MAIL_SCUX_READ_BYTE_NUM];
dkato 0:ee40da884cfc 181 if ((buf_id < PCM_BUF_NUM) && (byte_cnt <= sizeof(pcm_buf[0]))) {
dkato 0:ee40da884cfc 182 if (byte_cnt < sizeof(pcm_buf[0])) {
dkato 0:ee40da884cfc 183 /* End of stream */
dkato 0:ee40da884cfc 184 /* Fills the remain area of PCM buffer with 0. */
dkato 0:ee40da884cfc 185 p_buf = &pcm_buf[buf_id][byte_cnt/sizeof(pcm_buf[0][0])];
dkato 0:ee40da884cfc 186 (void) memset(p_buf, 0, sizeof(pcm_buf[0]) - byte_cnt);
dkato 0:ee40da884cfc 187 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 188 }
dkato 0:ee40da884cfc 189 p_ctrl->pcm_stock_cnt++;
dkato 0:ee40da884cfc 190 if (p_ctrl->pcm_stock_cnt >= p_ctrl->output_trg_cnt) {
dkato 0:ee40da884cfc 191 /* Starts the output of PCM data. */
dkato 0:ee40da884cfc 192 result = true;
dkato 0:ee40da884cfc 193 for (i = 0; (i < p_ctrl->pcm_stock_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 194 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
1050186 4:2672de88a46b 195 result = write_audio(&audio, &pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 196 if (result == true) {
dkato 0:ee40da884cfc 197 p_ctrl->pcm_buf_remain_cnt--;
dkato 0:ee40da884cfc 198 }
dkato 0:ee40da884cfc 199 }
dkato 0:ee40da884cfc 200 if (result != true) {
dkato 0:ee40da884cfc 201 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 202 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 203 }
dkato 0:ee40da884cfc 204 p_ctrl->pcm_buf_index =
dkato 0:ee40da884cfc 205 (p_ctrl->pcm_buf_index + p_ctrl->pcm_stock_cnt) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 206 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 207 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 208 }
dkato 0:ee40da884cfc 209 } else {
dkato 0:ee40da884cfc 210 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 211 scux_read_enable = false;
dkato 0:ee40da884cfc 212 }
dkato 0:ee40da884cfc 213 break;
dkato 0:ee40da884cfc 214 case AUD_MAILID_PCM_OUT_FIN: /* Finished the output of data. */
dkato 0:ee40da884cfc 215 p_ctrl->pcm_buf_remain_cnt++;
dkato 0:ee40da884cfc 216 if ((int32_t)mail_param[MAIL_PCM_OUT_RESULT] == true) {
1050186 4:2672de88a46b 217 buf_id = mail_param[MAIL_PCM_OUT_BUF_INDEX];
dkato 0:ee40da884cfc 218 if (scux_read_enable == true) {
dkato 0:ee40da884cfc 219 (void) read_scux(&pcm_buf[buf_id], buf_id);
1050186 4:2672de88a46b 220 } else {
1050186 4:2672de88a46b 221 (void) memset(&pcm_buf[buf_id], 0, sizeof(pcm_buf[0]));
dkato 0:ee40da884cfc 222 }
dkato 0:ee40da884cfc 223 } else {
dkato 0:ee40da884cfc 224 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 225 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 226 }
dkato 0:ee40da884cfc 227 break;
1050186 4:2672de88a46b 228 case AUD_MAILID_GET_AUDIO:
1050186 4:2672de88a46b 229 cb_audio_data = (AUD_CbAudioData)mail_param[MAIL_GET_AUDIO_CB];
1050186 4:2672de88a46b 230 if (cb_audio_data != NULL) {
1050186 4:2672de88a46b 231 if (p_ctrl->pcm_buf_index > 0u) {
1050186 4:2672de88a46b 232 buf_id = p_ctrl->pcm_buf_index - 1u;
1050186 4:2672de88a46b 233 } else {
1050186 4:2672de88a46b 234 buf_id = PCM_BUF_NUM - 1u;
1050186 4:2672de88a46b 235 }
1050186 4:2672de88a46b 236 cb_audio_data(true, (int16_t*)mail_param[MAIL_GET_AUDIO_BUF],
1050186 4:2672de88a46b 237 mail_param[MAIL_GET_AUDIO_NUM], pcm_buf[buf_id], sizeof(pcm_buf[0])/sizeof(pcm_buf[0][0]));
1050186 4:2672de88a46b 238 }
1050186 4:2672de88a46b 239 break;
dkato 0:ee40da884cfc 240 default:
dkato 0:ee40da884cfc 241 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 242 (void) dsp_notify_print_string(ERR_MSG_RECV_ILLEGAL_MAIL);
dkato 0:ee40da884cfc 243 break;
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245 }
dkato 0:ee40da884cfc 246 }
dkato 0:ee40da884cfc 247 }
dkato 0:ee40da884cfc 248
dkato 0:ee40da884cfc 249 bool aud_req_data_out(const AUD_CbDataOut p_cb)
dkato 0:ee40da884cfc 250 {
dkato 0:ee40da884cfc 251 bool ret = false;
dkato 0:ee40da884cfc 252
dkato 0:ee40da884cfc 253 if (p_cb != NULL) {
dkato 0:ee40da884cfc 254 ret = send_mail(AUD_MAILID_DATA_OUT, (uint32_t)p_cb, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 255 }
dkato 0:ee40da884cfc 256 return ret;
dkato 0:ee40da884cfc 257 }
dkato 0:ee40da884cfc 258
dkato 0:ee40da884cfc 259 bool aud_req_zero_out(void)
dkato 0:ee40da884cfc 260 {
dkato 0:ee40da884cfc 261 bool ret = false;
dkato 0:ee40da884cfc 262
dkato 0:ee40da884cfc 263 ret = send_mail(AUD_MAILID_ZERO_OUT, MAIL_PARAM_NON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 264 return ret;
dkato 0:ee40da884cfc 265 }
dkato 0:ee40da884cfc 266
1050186 4:2672de88a46b 267 bool aud_get_audio_data(const AUD_CbAudioData p_cb, int16_t * const p_buf, const uint32_t buf_num)
dkato 0:ee40da884cfc 268 {
1050186 4:2672de88a46b 269 bool ret = false;
1050186 4:2672de88a46b 270
1050186 4:2672de88a46b 271 if ((p_cb != NULL) && (p_buf != NULL) && (buf_num > 0u)) {
1050186 4:2672de88a46b 272 ret = send_mail(AUD_MAILID_GET_AUDIO, (uint32_t)p_cb, (uint32_t)p_buf, (uint32_t)buf_num);
1050186 4:2672de88a46b 273 }
1050186 4:2672de88a46b 274 return ret;
dkato 0:ee40da884cfc 275 }
dkato 0:ee40da884cfc 276
dkato 0:ee40da884cfc 277 /** Initialises the control data of PCM buffer
dkato 0:ee40da884cfc 278 *
dkato 0:ee40da884cfc 279 * @param p_ctrl Pointer to the control data of PCM buffer.
dkato 0:ee40da884cfc 280 */
dkato 0:ee40da884cfc 281 static void init_pcm_buf(pcm_buf_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 282 {
dkato 0:ee40da884cfc 283 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 284 p_ctrl->pcm_buf_index = 0u;
dkato 0:ee40da884cfc 285 p_ctrl->pcm_buf_remain_cnt = PCM_BUF_NUM;
dkato 0:ee40da884cfc 286 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 287 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 288 }
dkato 0:ee40da884cfc 289 }
dkato 0:ee40da884cfc 290
dkato 0:ee40da884cfc 291 /** Gets PCM data from SCUX driver
dkato 0:ee40da884cfc 292 *
dkato 0:ee40da884cfc 293 * @param p_buf Pointer to PCM buffer array to store the data.
dkato 0:ee40da884cfc 294 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 295 *
dkato 0:ee40da884cfc 296 * @returns
dkato 0:ee40da884cfc 297 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 298 */
dkato 0:ee40da884cfc 299 static bool read_scux(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 300 {
dkato 0:ee40da884cfc 301 bool ret = false;
dkato 0:ee40da884cfc 302 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 303 &read_callback,
dkato 0:ee40da884cfc 304 NULL
dkato 0:ee40da884cfc 305 };
dkato 0:ee40da884cfc 306
dkato 0:ee40da884cfc 307 if ((p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 308 cb_conf.p_app_data = (void *)buf_id;
dkato 0:ee40da884cfc 309 ret = dec_scux_read(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 310 }
dkato 0:ee40da884cfc 311 return ret;
dkato 0:ee40da884cfc 312 }
dkato 0:ee40da884cfc 313
dkato 0:ee40da884cfc 314 /** Writes PCM data to TLV320_RBSP driver
dkato 0:ee40da884cfc 315 *
dkato 0:ee40da884cfc 316 * @param p_buf Pointer to PCM buffer array.
dkato 0:ee40da884cfc 317 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 318 *
dkato 0:ee40da884cfc 319 * @returns
dkato 0:ee40da884cfc 320 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 321 */
1050186 4:2672de88a46b 322 static bool write_audio(TLV320_RBSP * const p_audio, int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 323 {
dkato 0:ee40da884cfc 324 bool ret = false;
dkato 0:ee40da884cfc 325 int32_t result;
dkato 0:ee40da884cfc 326 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 327 &pcm_out_callback,
dkato 0:ee40da884cfc 328 NULL
dkato 0:ee40da884cfc 329 };
dkato 0:ee40da884cfc 330
1050186 4:2672de88a46b 331 if ((p_audio != NULL) && (p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 332 cb_conf.p_app_data = (void *)buf_id;
1050186 4:2672de88a46b 333 result = p_audio->write(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 334 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 335 ret = true;
dkato 0:ee40da884cfc 336 }
dkato 0:ee40da884cfc 337 }
dkato 0:ee40da884cfc 338 return ret;
dkato 0:ee40da884cfc 339 }
dkato 0:ee40da884cfc 340
dkato 0:ee40da884cfc 341 /** Callback function of SCUX driver
dkato 0:ee40da884cfc 342 *
dkato 0:ee40da884cfc 343 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 344 * @param result Result of the process.
dkato 0:ee40da884cfc 345 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 346 */
dkato 0:ee40da884cfc 347 static void read_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 348 {
dkato 0:ee40da884cfc 349 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 350 uint32_t read_byte;
dkato 0:ee40da884cfc 351 bool flag_result;
dkato 0:ee40da884cfc 352
dkato 0:ee40da884cfc 353 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 354 if (result > 0) {
dkato 0:ee40da884cfc 355 flag_result = true;
dkato 0:ee40da884cfc 356 read_byte = (uint32_t)result;
dkato 0:ee40da884cfc 357 } else {
dkato 0:ee40da884cfc 358 flag_result = false;
dkato 0:ee40da884cfc 359 read_byte = 0u;
dkato 0:ee40da884cfc 360 }
dkato 0:ee40da884cfc 361 (void) send_mail(AUD_MAILID_SCUX_READ_FIN, (uint32_t)flag_result, buf_id, read_byte);
dkato 0:ee40da884cfc 362 }
dkato 0:ee40da884cfc 363
dkato 0:ee40da884cfc 364 /** Callback function of TLV320_RBSP driver
dkato 0:ee40da884cfc 365 *
dkato 0:ee40da884cfc 366 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 367 * @param result Result of the process.
dkato 0:ee40da884cfc 368 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 369 */
dkato 0:ee40da884cfc 370 static void pcm_out_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 371 {
dkato 0:ee40da884cfc 372 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 373 bool flag_result;
dkato 0:ee40da884cfc 374
dkato 0:ee40da884cfc 375 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 376 if (result > 0) {
dkato 0:ee40da884cfc 377 flag_result = true;
dkato 0:ee40da884cfc 378 } else {
dkato 0:ee40da884cfc 379 flag_result = false;
dkato 0:ee40da884cfc 380 }
dkato 0:ee40da884cfc 381 (void) send_mail(AUD_MAILID_PCM_OUT_FIN, (uint32_t)flag_result, buf_id, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383
dkato 0:ee40da884cfc 384 /** Sends the mail to Decode thread
dkato 0:ee40da884cfc 385 *
dkato 0:ee40da884cfc 386 * @param mail_id Mail ID
dkato 0:ee40da884cfc 387 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 388 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 389 * @param param2 Parameter 2 of this mail
dkato 0:ee40da884cfc 390 *
dkato 0:ee40da884cfc 391 * @returns
dkato 0:ee40da884cfc 392 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 393 */
dkato 0:ee40da884cfc 394 static bool send_mail(const AUD_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 395 const uint32_t param1, const uint32_t param2)
dkato 0:ee40da884cfc 396 {
dkato 0:ee40da884cfc 397 bool ret = false;
dkato 0:ee40da884cfc 398 osStatus stat;
dkato 0:ee40da884cfc 399 aud_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 400
dkato 0:ee40da884cfc 401 if (p_mail != NULL) {
dkato 0:ee40da884cfc 402 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 403 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 404 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 405 p_mail->param[MAIL_PARAM2] = param2;
dkato 0:ee40da884cfc 406 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 407 if (stat == osOK) {
dkato 0:ee40da884cfc 408 ret = true;
dkato 0:ee40da884cfc 409 } else {
dkato 0:ee40da884cfc 410 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 411 }
dkato 0:ee40da884cfc 412 }
dkato 0:ee40da884cfc 413 return ret;
dkato 0:ee40da884cfc 414 }
dkato 0:ee40da884cfc 415
dkato 0:ee40da884cfc 416 /** Receives the mail to Decode thread
dkato 0:ee40da884cfc 417 *
dkato 0:ee40da884cfc 418 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 419 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 420 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 421 * @param p_param2 Pointer to the variable to store the parameter 2 of this mail
dkato 0:ee40da884cfc 422 *
dkato 0:ee40da884cfc 423 * @returns
dkato 0:ee40da884cfc 424 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 425 */
dkato 0:ee40da884cfc 426 static bool recv_mail(AUD_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 427 uint32_t * const p_param1, uint32_t * const p_param2)
dkato 0:ee40da884cfc 428 {
dkato 0:ee40da884cfc 429 bool ret = false;
dkato 0:ee40da884cfc 430 osEvent evt;
dkato 0:ee40da884cfc 431 aud_mail_t *p_mail;
dkato 0:ee40da884cfc 432
dkato 0:ee40da884cfc 433 if ((p_mail_id != NULL) && (p_param0 != NULL) &&
dkato 0:ee40da884cfc 434 (p_param1 != NULL) && (p_param2 != NULL)) {
dkato 0:ee40da884cfc 435 evt = mail_box.get();
dkato 0:ee40da884cfc 436 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 437 p_mail = (aud_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 438 if (p_mail != NULL) {
dkato 0:ee40da884cfc 439 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 440 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 441 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 442 *p_param2 = p_mail->param[MAIL_PARAM2];
dkato 0:ee40da884cfc 443 ret = true;
dkato 0:ee40da884cfc 444 }
dkato 0:ee40da884cfc 445 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 446 }
dkato 0:ee40da884cfc 447 }
dkato 0:ee40da884cfc 448 return ret;
dkato 0:ee40da884cfc 449 }