The "GR-PEACH_Audio_Playback_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:   R_BSP TLV320_RBSP USBHost_custom

Note

For a sample program of with LCD Board,
please refer to GR-PEACH_Audio_Playback_7InchLCD_Sample.

Introduction

The "GR-PEACH_Audio_Playback_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/dkato/audioplayback_figure1_1x.png

1.2 Pin Definitions

Table 1.1 shows the pins that this sample code are to use.

/media/uploads/dkato/audioplayback_table1_1.png

2. Sample Code Operating Environment

This sample code runs in GR-PEACH + the Audio/Camera shield for the GR-PEACH environment. This section explains the functions of the ports that are used by this sample code.

2.1 Operating Environment

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

/media/uploads/dkato/audioplayback_figure2_1.png /media/uploads/1050186/figure2_2.png /media/uploads/dkato/audioplayback_figure2_3.png

2.2 List of User Operations

A list of user operations on the command line, TFT touch keys, and switch key that the user can perform for this sample code is shown in. Table 2.1.

/media/uploads/dkato/audioplayback_table2_1x.png

3. Function Outline

The functions of this sample code are summarized in Table 3.1 to Table 3.3.

/media/uploads/dkato/audioplayback_table3_1.png /media/uploads/dkato/audioplayback_table3_2.png /media/uploads/dkato/audioplayback_table3_3.png /media/uploads/dkato/audioplayback_figure3_1.png

3.1 Playback Control

The playback control that the sample code supports include play, pause, stop, skip to next, and skip to previous.

3.2 Trick Play Control

Manipulating "Repeat" alternates between "Repeat mode On" and "Repeat mode Off". The default mode is "Repeat mode On". When the repeat mode is on, the playback of the first song starts after the playback of the last song is finished. When the repeat mode is off, the sample code enters the stopped state after the playback of the last song is finished.

3.3 Acquisition of the Song Information

The information of the song being played is obtained by operating the "Play info" during the playback of the song. Table 3.4 lists the items of information that can be obtained by the "Play info" operation.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How the Folder Structure is Analyzed

The sample coded analyzes the folder structure in the breadth-first search order. The order in which files are numbered is illustrated in Table 3.5. The sample code does not sort the files by file or folder name.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Committer:
Osamu Nakamura
Date:
Fri Mar 31 14:00:23 2017 +0900
Revision:
6:df19c3e787ca
Parent:
5:c140dcdc2d45
Introduced mbedOS 5 instead of mbedOS 2 (classic)

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
dkato 0:ee40da884cfc 58 /*--- Macro definition of PCM buffer ---*/
dkato 0:ee40da884cfc 59 #define UNIT_TIME_MS (10u) /* Unit time of PCM data processing (ms) */
dkato 0:ee40da884cfc 60 #define SEC_TO_MSEC (1000u)
dkato 0:ee40da884cfc 61
dkato 0:ee40da884cfc 62 /* Sample number per unit time (ms) */
dkato 0:ee40da884cfc 63 #define SAMPLE_PER_UNIT_MS ((UNIT_TIME_MS * DEC_OUTPUT_SAMPLE_RATE) / SEC_TO_MSEC)
dkato 0:ee40da884cfc 64
dkato 0:ee40da884cfc 65 #define OUTPUT_START_TRIGGER (3) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 66 /* to start the output of PCM data */
dkato 0:ee40da884cfc 67 #define OUTPUT_UPDATE_TRIGGER (1) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 68 /* to update the output of PCM data */
dkato 0:ee40da884cfc 69
dkato 2:d9fca8cd7f03 70 #define PCM_BUF_NUM (DEC_SCUX_READ_NUM)
dkato 0:ee40da884cfc 71 #define TOTAL_SAMPLE_NUM (SAMPLE_PER_UNIT_MS * DEC_OUTPUT_CHANNEL_NUM)
dkato 0:ee40da884cfc 72
dkato 0:ee40da884cfc 73 /*--- Macro definition of TLV320_RBSP ---*/
dkato 0:ee40da884cfc 74 #define AUDIO_POWER_MIC_OFF (0x02) /* Microphone input :OFF */
dkato 0:ee40da884cfc 75 #define AUDIO_INT_LEVEL (0x80)
dkato 0:ee40da884cfc 76 #define AUDIO_READ_NUM (0)
dkato 0:ee40da884cfc 77 #define AUDIO_WRITE_NUM (PCM_BUF_NUM)
dkato 0:ee40da884cfc 78 #define ERR_MSG_TLV320_RBSP_WRITE "\nError: TLV320_RBSP::write()\n"
dkato 0:ee40da884cfc 79
dkato 0:ee40da884cfc 80 /* 4 bytes aligned. No cache memory. */
dkato 5:c140dcdc2d45 81 #if defined(__ICCARM__)
dkato 5:c140dcdc2d45 82 #define NC_BSS_SECT @ ".mirrorram"
dkato 5:c140dcdc2d45 83 #else
dkato 0:ee40da884cfc 84 #define NC_BSS_SECT __attribute__((section("NC_BSS"),aligned(4)))
dkato 4:521ca1d224d2 85 #endif
dkato 0:ee40da884cfc 86 #define ERR_MSG_RECV_ILLEGAL_MAIL "\nError: aud_thread function received illegal mail.\n"
dkato 0:ee40da884cfc 87
dkato 0:ee40da884cfc 88 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 89 typedef enum {
dkato 0:ee40da884cfc 90 AUD_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 91 AUD_MAILID_DATA_OUT, /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 92 AUD_MAILID_ZERO_OUT, /* Requests the output of zero data. */
dkato 0:ee40da884cfc 93 AUD_MAILID_SCUX_READ_FIN, /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 94 AUD_MAILID_PCM_OUT_FIN, /* Finished the output of data. */
dkato 0:ee40da884cfc 95 AUD_MAILID_NUM
dkato 0:ee40da884cfc 96 } AUD_MAIL_ID;
dkato 0:ee40da884cfc 97
dkato 0:ee40da884cfc 98 typedef struct {
dkato 0:ee40da884cfc 99 AUD_MAIL_ID mail_id;
dkato 0:ee40da884cfc 100 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 101 } aud_mail_t;
dkato 0:ee40da884cfc 102
dkato 0:ee40da884cfc 103 /*--- User defined types of audio output thread ---*/
dkato 0:ee40da884cfc 104 /* The control data of PCM buffer. */
dkato 0:ee40da884cfc 105 typedef struct {
dkato 0:ee40da884cfc 106 uint32_t pcm_buf_index; /* Index of PCM buffer array */
dkato 0:ee40da884cfc 107 uint32_t pcm_buf_remain_cnt; /* Counter of the remain elements in PCM buffer array */
dkato 0:ee40da884cfc 108 uint32_t pcm_stock_cnt; /* Counter of the stock elements in PCM buffer array */
dkato 0:ee40da884cfc 109 uint32_t output_trg_cnt; /* Number of the trigger to start the output of PCM data */
dkato 0:ee40da884cfc 110 } pcm_buf_ctrl_t;
dkato 0:ee40da884cfc 111
dkato 0:ee40da884cfc 112 static Mail<aud_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 113 static TLV320_RBSP audio(P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7,
dkato 0:ee40da884cfc 114 P4_6, AUDIO_INT_LEVEL, AUDIO_WRITE_NUM, AUDIO_READ_NUM);
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);
dkato 0:ee40da884cfc 118 static bool write_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;
dkato 4:521ca1d224d2 139 #if defined(__ICCARM__)
dkato 5:c140dcdc2d45 140 static int32_t pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM] NC_BSS_SECT;
dkato 4:521ca1d224d2 141 #else
dkato 0:ee40da884cfc 142 static int32_t NC_BSS_SECT pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM];
dkato 4:521ca1d224d2 143 #endif
dkato 0:ee40da884cfc 144
dkato 0:ee40da884cfc 145 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 146
dkato 0:ee40da884cfc 147 /* Initializes the control data of PCM buffer. */
dkato 0:ee40da884cfc 148 init_pcm_buf(p_ctrl);
dkato 0:ee40da884cfc 149
dkato 0:ee40da884cfc 150 /* Sets the output of PCM data using TLV320_RBSP. */
dkato 0:ee40da884cfc 151 (void) audio.format(DEC_OUTPUT_BITS_PER_SAMPLE);
dkato 0:ee40da884cfc 152 (void) audio.frequency(DEC_OUTPUT_SAMPLE_RATE);
dkato 0:ee40da884cfc 153 audio.power(AUDIO_POWER_MIC_OFF);
dkato 0:ee40da884cfc 154 while (1) {
dkato 0:ee40da884cfc 155 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0],
dkato 0:ee40da884cfc 156 &mail_param[MAIL_PARAM1], &mail_param[MAIL_PARAM2]);
dkato 0:ee40da884cfc 157 if (result == true) {
dkato 0:ee40da884cfc 158 switch (mail_type) {
dkato 0:ee40da884cfc 159 case AUD_MAILID_DATA_OUT: /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 160 cb_data_out = (AUD_CbDataOut)mail_param[MAIL_DATA_OUT_CB];
dkato 0:ee40da884cfc 161 if (scux_read_enable != true) {
dkato 0:ee40da884cfc 162 scux_read_enable = true;
dkato 0:ee40da884cfc 163 result = true;
dkato 0:ee40da884cfc 164 for (i = 0; (i < p_ctrl->pcm_buf_remain_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 165 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 166 result = read_scux(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 167 }
dkato 0:ee40da884cfc 168 if (result == true) {
dkato 0:ee40da884cfc 169 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 170 }
dkato 0:ee40da884cfc 171 } else {
dkato 0:ee40da884cfc 172 result = false;
dkato 0:ee40da884cfc 173 }
dkato 0:ee40da884cfc 174 cb_data_out(result);
dkato 0:ee40da884cfc 175 break;
dkato 0:ee40da884cfc 176 case AUD_MAILID_ZERO_OUT: /* Requests the output of zero data. */
dkato 0:ee40da884cfc 177 scux_read_enable = false;
dkato 0:ee40da884cfc 178 break;
dkato 0:ee40da884cfc 179 case AUD_MAILID_SCUX_READ_FIN: /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 180 buf_id = mail_param[MAIL_SCUX_READ_BUF_INDEX];
dkato 0:ee40da884cfc 181 byte_cnt = mail_param[MAIL_SCUX_READ_BYTE_NUM];
dkato 0:ee40da884cfc 182 if ((buf_id < PCM_BUF_NUM) && (byte_cnt <= sizeof(pcm_buf[0]))) {
dkato 0:ee40da884cfc 183 if (byte_cnt < sizeof(pcm_buf[0])) {
dkato 0:ee40da884cfc 184 /* End of stream */
dkato 0:ee40da884cfc 185 /* Fills the remain area of PCM buffer with 0. */
dkato 0:ee40da884cfc 186 p_buf = &pcm_buf[buf_id][byte_cnt/sizeof(pcm_buf[0][0])];
dkato 0:ee40da884cfc 187 (void) memset(p_buf, 0, sizeof(pcm_buf[0]) - byte_cnt);
dkato 0:ee40da884cfc 188 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 189 }
dkato 0:ee40da884cfc 190 p_ctrl->pcm_stock_cnt++;
dkato 0:ee40da884cfc 191 if (p_ctrl->pcm_stock_cnt >= p_ctrl->output_trg_cnt) {
dkato 0:ee40da884cfc 192 /* Starts the output of PCM data. */
dkato 0:ee40da884cfc 193 result = true;
dkato 0:ee40da884cfc 194 for (i = 0; (i < p_ctrl->pcm_stock_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 195 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 196 result = write_audio(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 197 if (result == true) {
dkato 0:ee40da884cfc 198 p_ctrl->pcm_buf_remain_cnt--;
dkato 0:ee40da884cfc 199 }
dkato 0:ee40da884cfc 200 }
dkato 0:ee40da884cfc 201 if (result != true) {
dkato 0:ee40da884cfc 202 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 203 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 204 }
dkato 0:ee40da884cfc 205 p_ctrl->pcm_buf_index =
dkato 0:ee40da884cfc 206 (p_ctrl->pcm_buf_index + p_ctrl->pcm_stock_cnt) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 207 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 208 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 209 }
dkato 0:ee40da884cfc 210 } else {
dkato 0:ee40da884cfc 211 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 212 scux_read_enable = false;
dkato 0:ee40da884cfc 213 }
dkato 0:ee40da884cfc 214 break;
dkato 0:ee40da884cfc 215 case AUD_MAILID_PCM_OUT_FIN: /* Finished the output of data. */
dkato 0:ee40da884cfc 216 p_ctrl->pcm_buf_remain_cnt++;
dkato 0:ee40da884cfc 217 if ((int32_t)mail_param[MAIL_PCM_OUT_RESULT] == true) {
dkato 0:ee40da884cfc 218 if (scux_read_enable == true) {
dkato 0:ee40da884cfc 219 buf_id = mail_param[MAIL_PCM_OUT_BUF_INDEX];
dkato 0:ee40da884cfc 220 (void) read_scux(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 221 }
dkato 0:ee40da884cfc 222 } else {
dkato 0:ee40da884cfc 223 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 224 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 225 }
dkato 0:ee40da884cfc 226 break;
dkato 0:ee40da884cfc 227 default:
dkato 0:ee40da884cfc 228 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 229 (void) dsp_notify_print_string(ERR_MSG_RECV_ILLEGAL_MAIL);
dkato 0:ee40da884cfc 230 break;
dkato 0:ee40da884cfc 231 }
dkato 0:ee40da884cfc 232 }
dkato 0:ee40da884cfc 233 }
dkato 0:ee40da884cfc 234 }
dkato 0:ee40da884cfc 235
dkato 0:ee40da884cfc 236 bool aud_req_data_out(const AUD_CbDataOut p_cb)
dkato 0:ee40da884cfc 237 {
dkato 0:ee40da884cfc 238 bool ret = false;
dkato 0:ee40da884cfc 239
dkato 0:ee40da884cfc 240 if (p_cb != NULL) {
dkato 0:ee40da884cfc 241 ret = send_mail(AUD_MAILID_DATA_OUT, (uint32_t)p_cb, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 242 }
dkato 0:ee40da884cfc 243 return ret;
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245
dkato 0:ee40da884cfc 246 bool aud_req_zero_out(void)
dkato 0:ee40da884cfc 247 {
dkato 0:ee40da884cfc 248 bool ret = false;
dkato 0:ee40da884cfc 249
dkato 0:ee40da884cfc 250 ret = send_mail(AUD_MAILID_ZERO_OUT, MAIL_PARAM_NON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 251 return ret;
dkato 0:ee40da884cfc 252 }
dkato 0:ee40da884cfc 253
dkato 0:ee40da884cfc 254 bool aud_get_audio_data(const AUD_CbAudioData p_cb, uint16_t * const p_buf)
dkato 0:ee40da884cfc 255 {
dkato 0:ee40da884cfc 256 UNUSED_ARG(p_cb);
dkato 0:ee40da884cfc 257 UNUSED_ARG(p_buf);
dkato 0:ee40da884cfc 258 return true;
dkato 0:ee40da884cfc 259 }
dkato 0:ee40da884cfc 260
dkato 0:ee40da884cfc 261 /** Initialises the control data of PCM buffer
dkato 0:ee40da884cfc 262 *
dkato 0:ee40da884cfc 263 * @param p_ctrl Pointer to the control data of PCM buffer.
dkato 0:ee40da884cfc 264 */
dkato 0:ee40da884cfc 265 static void init_pcm_buf(pcm_buf_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 266 {
dkato 0:ee40da884cfc 267 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 268 p_ctrl->pcm_buf_index = 0u;
dkato 0:ee40da884cfc 269 p_ctrl->pcm_buf_remain_cnt = PCM_BUF_NUM;
dkato 0:ee40da884cfc 270 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 271 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 272 }
dkato 0:ee40da884cfc 273 }
dkato 0:ee40da884cfc 274
dkato 0:ee40da884cfc 275 /** Gets PCM data from SCUX driver
dkato 0:ee40da884cfc 276 *
dkato 0:ee40da884cfc 277 * @param p_buf Pointer to PCM buffer array to store the data.
dkato 0:ee40da884cfc 278 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 279 *
dkato 0:ee40da884cfc 280 * @returns
dkato 0:ee40da884cfc 281 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 282 */
dkato 0:ee40da884cfc 283 static bool read_scux(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 284 {
dkato 0:ee40da884cfc 285 bool ret = false;
dkato 0:ee40da884cfc 286 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 287 &read_callback,
dkato 0:ee40da884cfc 288 NULL
dkato 0:ee40da884cfc 289 };
dkato 0:ee40da884cfc 290
dkato 0:ee40da884cfc 291 if ((p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 292 cb_conf.p_app_data = (void *)buf_id;
dkato 0:ee40da884cfc 293 ret = dec_scux_read(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 294 }
dkato 0:ee40da884cfc 295 return ret;
dkato 0:ee40da884cfc 296 }
dkato 0:ee40da884cfc 297
dkato 0:ee40da884cfc 298 /** Writes PCM data to TLV320_RBSP driver
dkato 0:ee40da884cfc 299 *
dkato 0:ee40da884cfc 300 * @param p_buf Pointer to PCM buffer array.
dkato 0:ee40da884cfc 301 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 302 *
dkato 0:ee40da884cfc 303 * @returns
dkato 0:ee40da884cfc 304 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 305 */
dkato 0:ee40da884cfc 306 static bool write_audio(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 307 {
dkato 0:ee40da884cfc 308 bool ret = false;
dkato 0:ee40da884cfc 309 int32_t result;
dkato 0:ee40da884cfc 310 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 311 &pcm_out_callback,
dkato 0:ee40da884cfc 312 NULL
dkato 0:ee40da884cfc 313 };
dkato 0:ee40da884cfc 314
dkato 0:ee40da884cfc 315 if ((p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 316 cb_conf.p_app_data = (void *)buf_id;
dkato 0:ee40da884cfc 317 result = audio.write(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 318 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 319 ret = true;
dkato 0:ee40da884cfc 320 }
dkato 0:ee40da884cfc 321 }
dkato 0:ee40da884cfc 322 return ret;
dkato 0:ee40da884cfc 323 }
dkato 0:ee40da884cfc 324
dkato 0:ee40da884cfc 325 /** Callback function of SCUX driver
dkato 0:ee40da884cfc 326 *
dkato 0:ee40da884cfc 327 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 328 * @param result Result of the process.
dkato 0:ee40da884cfc 329 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 330 */
dkato 0:ee40da884cfc 331 static void read_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 332 {
dkato 0:ee40da884cfc 333 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 334 uint32_t read_byte;
dkato 0:ee40da884cfc 335 bool flag_result;
dkato 0:ee40da884cfc 336
dkato 0:ee40da884cfc 337 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 338 if (result > 0) {
dkato 0:ee40da884cfc 339 flag_result = true;
dkato 0:ee40da884cfc 340 read_byte = (uint32_t)result;
dkato 0:ee40da884cfc 341 } else {
dkato 0:ee40da884cfc 342 flag_result = false;
dkato 0:ee40da884cfc 343 read_byte = 0u;
dkato 0:ee40da884cfc 344 }
dkato 0:ee40da884cfc 345 (void) send_mail(AUD_MAILID_SCUX_READ_FIN, (uint32_t)flag_result, buf_id, read_byte);
dkato 0:ee40da884cfc 346 }
dkato 0:ee40da884cfc 347
dkato 0:ee40da884cfc 348 /** Callback function of TLV320_RBSP driver
dkato 0:ee40da884cfc 349 *
dkato 0:ee40da884cfc 350 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 351 * @param result Result of the process.
dkato 0:ee40da884cfc 352 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 353 */
dkato 0:ee40da884cfc 354 static void pcm_out_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 355 {
dkato 0:ee40da884cfc 356 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 357 bool flag_result;
dkato 0:ee40da884cfc 358
dkato 0:ee40da884cfc 359 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 360 if (result > 0) {
dkato 0:ee40da884cfc 361 flag_result = true;
dkato 0:ee40da884cfc 362 } else {
dkato 0:ee40da884cfc 363 flag_result = false;
dkato 0:ee40da884cfc 364 }
dkato 0:ee40da884cfc 365 (void) send_mail(AUD_MAILID_PCM_OUT_FIN, (uint32_t)flag_result, buf_id, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 366 }
dkato 0:ee40da884cfc 367
dkato 0:ee40da884cfc 368 /** Sends the mail to Decode thread
dkato 0:ee40da884cfc 369 *
dkato 0:ee40da884cfc 370 * @param mail_id Mail ID
dkato 0:ee40da884cfc 371 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 372 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 373 * @param param2 Parameter 2 of this mail
dkato 0:ee40da884cfc 374 *
dkato 0:ee40da884cfc 375 * @returns
dkato 0:ee40da884cfc 376 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 377 */
dkato 0:ee40da884cfc 378 static bool send_mail(const AUD_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 379 const uint32_t param1, const uint32_t param2)
dkato 0:ee40da884cfc 380 {
dkato 0:ee40da884cfc 381 bool ret = false;
dkato 0:ee40da884cfc 382 osStatus stat;
dkato 0:ee40da884cfc 383 aud_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 384
dkato 0:ee40da884cfc 385 if (p_mail != NULL) {
dkato 0:ee40da884cfc 386 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 387 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 388 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 389 p_mail->param[MAIL_PARAM2] = param2;
dkato 0:ee40da884cfc 390 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 391 if (stat == osOK) {
dkato 0:ee40da884cfc 392 ret = true;
dkato 0:ee40da884cfc 393 } else {
dkato 0:ee40da884cfc 394 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 395 }
dkato 0:ee40da884cfc 396 }
dkato 0:ee40da884cfc 397 return ret;
dkato 0:ee40da884cfc 398 }
dkato 0:ee40da884cfc 399
dkato 0:ee40da884cfc 400 /** Receives the mail to Decode thread
dkato 0:ee40da884cfc 401 *
dkato 0:ee40da884cfc 402 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 403 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 404 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 405 * @param p_param2 Pointer to the variable to store the parameter 2 of this mail
dkato 0:ee40da884cfc 406 *
dkato 0:ee40da884cfc 407 * @returns
dkato 0:ee40da884cfc 408 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 409 */
dkato 0:ee40da884cfc 410 static bool recv_mail(AUD_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 411 uint32_t * const p_param1, uint32_t * const p_param2)
dkato 0:ee40da884cfc 412 {
dkato 0:ee40da884cfc 413 bool ret = false;
dkato 0:ee40da884cfc 414 osEvent evt;
dkato 0:ee40da884cfc 415 aud_mail_t *p_mail;
dkato 0:ee40da884cfc 416
dkato 0:ee40da884cfc 417 if ((p_mail_id != NULL) && (p_param0 != NULL) &&
dkato 0:ee40da884cfc 418 (p_param1 != NULL) && (p_param2 != NULL)) {
dkato 0:ee40da884cfc 419 evt = mail_box.get();
dkato 0:ee40da884cfc 420 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 421 p_mail = (aud_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 422 if (p_mail != NULL) {
dkato 0:ee40da884cfc 423 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 424 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 425 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 426 *p_param2 = p_mail->param[MAIL_PARAM2];
dkato 0:ee40da884cfc 427 ret = true;
dkato 0:ee40da884cfc 428 }
dkato 0:ee40da884cfc 429 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 430 }
dkato 0:ee40da884cfc 431 }
dkato 0:ee40da884cfc 432 return ret;
dkato 0:ee40da884cfc 433 }