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:
2:d9fca8cd7f03
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 "display.h"
dkato 0:ee40da884cfc 28 #include "disp_term.h"
dkato 0:ee40da884cfc 29
dkato 0:ee40da884cfc 30 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 31 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 32 #define MAIL_PARAM_NUM (64) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 33
dkato 0:ee40da884cfc 34 /* dsp_mail_t */
dkato 0:ee40da884cfc 35 /* mail_id = DSP_MAILID_CYCLE_IND : No parameter */
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 /* mail_id = DSP_MAILID_CMD_STR */
dkato 0:ee40da884cfc 38 #define MAIL_CMDSTR_FIN_FLG (0) /* Completion status of the input by the command-line */
dkato 0:ee40da884cfc 39 #define MAIL_CMDSTR_STR_START (1) /* Start position of input string by the command-line */
dkato 0:ee40da884cfc 40 #define MAIL_CMDSTR_STR_SIZE (DSP_CMD_INPT_STR_MAX_LEN)
dkato 0:ee40da884cfc 41 /* Size of input string by the command-line */
dkato 0:ee40da884cfc 42
dkato 0:ee40da884cfc 43 /* mail_id = DSP_MAILID_PRINT_STR */
dkato 0:ee40da884cfc 44 #define MAIL_DISPSTR_STR_START (0) /* Start position of display string */
dkato 0:ee40da884cfc 45 #define MAIL_DISPSTR_STR_SIZE (DSP_DISP_STR_MAX_LEN) /* Size of display string */
dkato 0:ee40da884cfc 46
dkato 0:ee40da884cfc 47 /* mail_id = DSP_MAILID_PLAY_TIME */
dkato 0:ee40da884cfc 48 #define MAIL_PLAYTIME_STAT (0) /* Playback status */
dkato 0:ee40da884cfc 49 #define MAIL_PLAYTIME_TRACK_L (1) /* Track number */
dkato 0:ee40da884cfc 50 #define MAIL_PLAYTIME_TRACK_H (2) /* Track number */
dkato 0:ee40da884cfc 51 #define MAIL_PLAYTIME_PLAYTIME_L (3) /* Playback time */
dkato 0:ee40da884cfc 52 #define MAIL_PLAYTIME_PLAYTIME_M (4) /* Playback time */
dkato 0:ee40da884cfc 53 #define MAIL_PLAYTIME_PLAYTIME_H (5) /* Playback time */
dkato 0:ee40da884cfc 54 #define MAIL_PLAYTIME_TOTALTIME_L (6) /* Total playback time */
dkato 0:ee40da884cfc 55 #define MAIL_PLAYTIME_TOTALTIME_M (7) /* Total playback time */
dkato 0:ee40da884cfc 56 #define MAIL_PLAYTIME_TOTALTIME_H (8) /* Total playback time */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /* mail_id = DSP_MAILID_PLAY_INFO */
dkato 0:ee40da884cfc 59 #define MAIL_PLAYINFO_TRACK_L (0) /* Track number */
dkato 0:ee40da884cfc 60 #define MAIL_PLAYINFO_TRACK_H (1) /* Track number */
dkato 0:ee40da884cfc 61 #define MAIL_PLAYINFO_SAMPFREQ_L (2) /* Sampling frequency */
dkato 0:ee40da884cfc 62 #define MAIL_PLAYINFO_SAMPFREQ_M (3) /* Sampling frequency */
dkato 0:ee40da884cfc 63 #define MAIL_PLAYINFO_SAMPFREQ_H (4) /* Sampling frequency */
dkato 0:ee40da884cfc 64 #define MAIL_PLAYINFO_CHANNEL (5) /* Channel structure */
dkato 0:ee40da884cfc 65
dkato 0:ee40da884cfc 66 /* mail_id = DSP_MAILID_PLAY_MODE */
dkato 0:ee40da884cfc 67 #define MAIL_PLAYMODE_REPEAT (0) /* Repeat mode */
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 /* mail_id = DSP_MAILID_FILE_NAME */
dkato 0:ee40da884cfc 70 #define MAIL_FILENAME_STR_START (0) /* Start position of file name string */
dkato 0:ee40da884cfc 71 #define MAIL_FILENAME_STR_SIZE (64) /* Size of file name string */
dkato 0:ee40da884cfc 72
dkato 2:d9fca8cd7f03 73 /* mail_id = DSP_MAILID_HELP */
dkato 2:d9fca8cd7f03 74 #define MAIL_HELP_PARAM (0) /* No mail parameter to be used */
dkato 2:d9fca8cd7f03 75
dkato 2:d9fca8cd7f03 76 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 2:d9fca8cd7f03 77
dkato 0:ee40da884cfc 78 #define BYTE_SHIFT (8u)
dkato 0:ee40da884cfc 79 #define WORD_SHIFT (16u)
dkato 0:ee40da884cfc 80
dkato 0:ee40da884cfc 81 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 82 typedef struct {
dkato 0:ee40da884cfc 83 DSP_MAIL_ID mail_id;
dkato 0:ee40da884cfc 84 uint8_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 85 } dsp_mail_t;
dkato 0:ee40da884cfc 86
dkato 0:ee40da884cfc 87 /* Control data of display thread */
dkato 0:ee40da884cfc 88 typedef struct {
dkato 0:ee40da884cfc 89 dsp_com_ctrl_t com; /* Common data */
dkato 0:ee40da884cfc 90 dsp_trm_ctrl_t trm; /* Terminal output module only */
dkato 0:ee40da884cfc 91 dsp_tft_ctrl_t tft; /* TFT module only */
dkato 0:ee40da884cfc 92 } dsp_ctrl_t;
dkato 0:ee40da884cfc 93
dkato 0:ee40da884cfc 94 static Mail<dsp_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 95
dkato 0:ee40da884cfc 96 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 97 static bool send_mail(const dsp_mail_t * const p_data);
dkato 0:ee40da884cfc 98 static bool recv_mail(dsp_mail_t * const p_data);
dkato 0:ee40da884cfc 99 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 100 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 101
dkato 0:ee40da884cfc 102 void dsp_thread(void const *argument)
dkato 0:ee40da884cfc 103 {
dkato 0:ee40da884cfc 104 dsp_mail_t recv_data;
dkato 0:ee40da884cfc 105 bool result;
dkato 0:ee40da884cfc 106 static dsp_ctrl_t dsp_ctrl;
dkato 0:ee40da884cfc 107
dkato 0:ee40da884cfc 108 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 109
dkato 0:ee40da884cfc 110 init_ctrl_data(&dsp_ctrl);
dkato 0:ee40da884cfc 111 dsp_init_term();
dkato 0:ee40da884cfc 112 while (1) {
dkato 0:ee40da884cfc 113 result = recv_mail(&recv_data);
dkato 0:ee40da884cfc 114 if (result == true) {
dkato 0:ee40da884cfc 115 result = decode_mail(&recv_data, &dsp_ctrl);
dkato 0:ee40da884cfc 116 if (result == true) {
dkato 0:ee40da884cfc 117 /* Executes main function of terminal output module */
dkato 0:ee40da884cfc 118 dsp_output_term(recv_data.mail_id, &dsp_ctrl.com, &dsp_ctrl.trm);
dkato 0:ee40da884cfc 119 /* Clears the one shot data */
dkato 0:ee40da884cfc 120 clear_one_shot_data(&dsp_ctrl);
dkato 0:ee40da884cfc 121 }
dkato 0:ee40da884cfc 122 }
dkato 0:ee40da884cfc 123 }
dkato 0:ee40da884cfc 124 }
dkato 0:ee40da884cfc 125
dkato 0:ee40da884cfc 126 bool dsp_notify_play_time(const SYS_PlayStat play_stat, const uint32_t file_no,
dkato 0:ee40da884cfc 127 const uint32_t play_time, const uint32_t total_time)
dkato 0:ee40da884cfc 128 {
dkato 0:ee40da884cfc 129 bool ret;
dkato 0:ee40da884cfc 130 dsp_mail_t data;
dkato 0:ee40da884cfc 131
dkato 0:ee40da884cfc 132 data.mail_id = DSP_MAILID_PLAY_TIME;
dkato 0:ee40da884cfc 133 data.param[MAIL_PLAYTIME_STAT] = (uint8_t)play_stat;
dkato 0:ee40da884cfc 134 data.param[MAIL_PLAYTIME_TRACK_L] = (uint8_t)file_no;
dkato 0:ee40da884cfc 135 data.param[MAIL_PLAYTIME_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT);
dkato 0:ee40da884cfc 136 data.param[MAIL_PLAYTIME_PLAYTIME_L] = (uint8_t)play_time;
dkato 0:ee40da884cfc 137 data.param[MAIL_PLAYTIME_PLAYTIME_M] = (uint8_t)(play_time >> BYTE_SHIFT);
dkato 0:ee40da884cfc 138 data.param[MAIL_PLAYTIME_PLAYTIME_H] = (uint8_t)(play_time >> WORD_SHIFT);
dkato 0:ee40da884cfc 139 data.param[MAIL_PLAYTIME_TOTALTIME_L] = (uint8_t)total_time;
dkato 0:ee40da884cfc 140 data.param[MAIL_PLAYTIME_TOTALTIME_M] = (uint8_t)(total_time >> BYTE_SHIFT);
dkato 0:ee40da884cfc 141 data.param[MAIL_PLAYTIME_TOTALTIME_H] = (uint8_t)(total_time >> WORD_SHIFT);
dkato 0:ee40da884cfc 142 ret = send_mail(&data);
dkato 0:ee40da884cfc 143
dkato 0:ee40da884cfc 144 return ret;
dkato 0:ee40da884cfc 145 }
dkato 0:ee40da884cfc 146
dkato 0:ee40da884cfc 147 bool dsp_notify_play_info(const uint32_t file_no,
dkato 0:ee40da884cfc 148 const uint32_t sample_freq, const uint32_t channel_num)
dkato 0:ee40da884cfc 149 {
dkato 0:ee40da884cfc 150 bool ret;
dkato 0:ee40da884cfc 151 dsp_mail_t data;
dkato 0:ee40da884cfc 152
dkato 0:ee40da884cfc 153 data.mail_id = DSP_MAILID_PLAY_INFO;
dkato 0:ee40da884cfc 154 data.param[MAIL_PLAYINFO_TRACK_L] = (uint8_t)file_no;
dkato 0:ee40da884cfc 155 data.param[MAIL_PLAYINFO_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT);
dkato 0:ee40da884cfc 156 data.param[MAIL_PLAYINFO_SAMPFREQ_L] = (uint8_t)sample_freq;
dkato 0:ee40da884cfc 157 data.param[MAIL_PLAYINFO_SAMPFREQ_M] = (uint8_t)(sample_freq >> BYTE_SHIFT);
dkato 0:ee40da884cfc 158 data.param[MAIL_PLAYINFO_SAMPFREQ_H] = (uint8_t)(sample_freq >> WORD_SHIFT);
dkato 0:ee40da884cfc 159 data.param[MAIL_PLAYINFO_CHANNEL] = (uint8_t)channel_num;
dkato 0:ee40da884cfc 160 ret = send_mail(&data);
dkato 0:ee40da884cfc 161
dkato 0:ee40da884cfc 162 return ret;
dkato 0:ee40da884cfc 163 }
dkato 0:ee40da884cfc 164
dkato 0:ee40da884cfc 165 bool dsp_notify_play_mode(const bool rep_mode)
dkato 0:ee40da884cfc 166 {
dkato 0:ee40da884cfc 167 bool ret;
dkato 0:ee40da884cfc 168 dsp_mail_t data;
dkato 0:ee40da884cfc 169
dkato 0:ee40da884cfc 170 data.mail_id = DSP_MAILID_PLAY_MODE;
dkato 0:ee40da884cfc 171 data.param[MAIL_PLAYMODE_REPEAT] = (uint8_t)rep_mode;
dkato 0:ee40da884cfc 172 ret = send_mail(&data);
dkato 0:ee40da884cfc 173
dkato 0:ee40da884cfc 174 return ret;
dkato 0:ee40da884cfc 175 }
dkato 0:ee40da884cfc 176
dkato 0:ee40da884cfc 177 bool dsp_notify_file_name(const char_t * const p_str)
dkato 0:ee40da884cfc 178 {
dkato 0:ee40da884cfc 179 bool ret = false;
dkato 0:ee40da884cfc 180 dsp_mail_t data;
dkato 0:ee40da884cfc 181
dkato 0:ee40da884cfc 182 if (p_str != NULL) {
dkato 0:ee40da884cfc 183 data.mail_id = DSP_MAILID_FILE_NAME;
dkato 0:ee40da884cfc 184 (void) memcpy(&data.param[MAIL_FILENAME_STR_START], p_str, MAIL_FILENAME_STR_SIZE);
dkato 0:ee40da884cfc 185 data.param[(MAIL_FILENAME_STR_START + MAIL_FILENAME_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 186 ret = send_mail(&data);
dkato 0:ee40da884cfc 187 }
dkato 0:ee40da884cfc 188
dkato 0:ee40da884cfc 189 return ret;
dkato 0:ee40da884cfc 190 }
dkato 0:ee40da884cfc 191
dkato 0:ee40da884cfc 192 bool dsp_notify_print_string(const char_t * const p_str)
dkato 0:ee40da884cfc 193 {
dkato 0:ee40da884cfc 194 bool ret = false;
dkato 0:ee40da884cfc 195 dsp_mail_t data;
dkato 0:ee40da884cfc 196
dkato 0:ee40da884cfc 197 if (p_str != NULL) {
dkato 0:ee40da884cfc 198 data.mail_id = DSP_MAILID_PRINT_STR;
dkato 0:ee40da884cfc 199 (void) memcpy(&data.param[MAIL_DISPSTR_STR_START], p_str, MAIL_DISPSTR_STR_SIZE);
dkato 0:ee40da884cfc 200 data.param[(MAIL_DISPSTR_STR_START + MAIL_DISPSTR_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 201 ret = send_mail(&data);
dkato 0:ee40da884cfc 202 }
dkato 0:ee40da884cfc 203
dkato 0:ee40da884cfc 204 return ret;
dkato 0:ee40da884cfc 205 }
dkato 0:ee40da884cfc 206
dkato 0:ee40da884cfc 207 bool dsp_notify_input_string(const char_t * const p_str, const bool flag_fin)
dkato 0:ee40da884cfc 208 {
dkato 0:ee40da884cfc 209 bool ret = false;
dkato 0:ee40da884cfc 210 dsp_mail_t data;
dkato 0:ee40da884cfc 211
dkato 0:ee40da884cfc 212 if (p_str != NULL) {
dkato 0:ee40da884cfc 213 data.mail_id = DSP_MAILID_CMD_STR;
dkato 0:ee40da884cfc 214 data.param[MAIL_CMDSTR_FIN_FLG] = (uint8_t)flag_fin;
dkato 0:ee40da884cfc 215 (void) memcpy(&data.param[MAIL_CMDSTR_STR_START], p_str, MAIL_CMDSTR_STR_SIZE);
dkato 0:ee40da884cfc 216 data.param[(MAIL_CMDSTR_STR_START + MAIL_CMDSTR_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 217 ret = send_mail(&data);
dkato 0:ee40da884cfc 218 }
dkato 0:ee40da884cfc 219
dkato 0:ee40da884cfc 220 return ret;
dkato 0:ee40da884cfc 221 }
dkato 0:ee40da884cfc 222
dkato 2:d9fca8cd7f03 223 bool dsp_req_help(void)
dkato 2:d9fca8cd7f03 224 {
dkato 2:d9fca8cd7f03 225 bool ret = false;
dkato 2:d9fca8cd7f03 226 dsp_mail_t data;
dkato 2:d9fca8cd7f03 227
dkato 2:d9fca8cd7f03 228 data.mail_id = DSP_MAILID_HELP;
dkato 2:d9fca8cd7f03 229 data.param[MAIL_HELP_PARAM] = (uint8_t)MAIL_PARAM_NON;
dkato 2:d9fca8cd7f03 230 ret = send_mail(&data);
dkato 2:d9fca8cd7f03 231 return ret;
dkato 2:d9fca8cd7f03 232 }
dkato 2:d9fca8cd7f03 233
dkato 0:ee40da884cfc 234 /** initialises the control data of the display module
dkato 0:ee40da884cfc 235 *
dkato 0:ee40da884cfc 236 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 237 */
dkato 0:ee40da884cfc 238 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 239 {
dkato 0:ee40da884cfc 240 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 241 /* Initialises the common data of the display module. */
dkato 0:ee40da884cfc 242 p_ctrl->com.disp_mode = 0u;
dkato 0:ee40da884cfc 243 p_ctrl->com.play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 244 p_ctrl->com.track_id = 0u;
dkato 0:ee40da884cfc 245 p_ctrl->com.play_time = 0u;
dkato 0:ee40da884cfc 246 p_ctrl->com.total_time = 0u;
dkato 0:ee40da884cfc 247 p_ctrl->com.samp_freq = 0u;
dkato 0:ee40da884cfc 248 p_ctrl->com.channel = 0u;
dkato 0:ee40da884cfc 249 p_ctrl->com.repeat_mode = false;
dkato 0:ee40da884cfc 250 p_ctrl->com.file_name[0] = '\0';
dkato 0:ee40da884cfc 251 p_ctrl->com.dspl_str[0] = '\0';
dkato 0:ee40da884cfc 252
dkato 0:ee40da884cfc 253 /* Initialises the data of the terminal output module. */
dkato 0:ee40da884cfc 254 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 255 p_ctrl->trm.inpt_str[0] = '\0';
dkato 0:ee40da884cfc 256
dkato 0:ee40da884cfc 257 /* Does not initialize the data of TFT module. */
dkato 0:ee40da884cfc 258 /* Initial values are different by the display mode. */
dkato 0:ee40da884cfc 259 /* Therefore the data of TFT module is initialized by tft_init_proc function. */
dkato 0:ee40da884cfc 260 }
dkato 0:ee40da884cfc 261 }
dkato 0:ee40da884cfc 262
dkato 0:ee40da884cfc 263 /** Sends the mail to main thread
dkato 0:ee40da884cfc 264 *
dkato 0:ee40da884cfc 265 * @param p_data Pointer to the structure of the data
dkato 0:ee40da884cfc 266 *
dkato 0:ee40da884cfc 267 * @returns
dkato 0:ee40da884cfc 268 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 269 */
dkato 0:ee40da884cfc 270 static bool send_mail(const dsp_mail_t * const p_data)
dkato 0:ee40da884cfc 271 {
dkato 0:ee40da884cfc 272 bool ret = false;
dkato 0:ee40da884cfc 273 osStatus stat;
dkato 0:ee40da884cfc 274 dsp_mail_t *p_mail;
dkato 0:ee40da884cfc 275
dkato 0:ee40da884cfc 276 if (p_data != NULL) {
dkato 0:ee40da884cfc 277 p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 278 if (p_mail != NULL) {
dkato 0:ee40da884cfc 279 *p_mail = *p_data;
dkato 0:ee40da884cfc 280 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 281 if (stat == osOK) {
dkato 0:ee40da884cfc 282 ret = true;
dkato 0:ee40da884cfc 283 } else {
dkato 0:ee40da884cfc 284 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 285 }
dkato 0:ee40da884cfc 286 }
dkato 0:ee40da884cfc 287 }
dkato 0:ee40da884cfc 288 return ret;
dkato 0:ee40da884cfc 289 }
dkato 0:ee40da884cfc 290
dkato 0:ee40da884cfc 291 /** Receives the mail to main thread
dkato 0:ee40da884cfc 292 *
dkato 0:ee40da884cfc 293 * @param p_data Pointer to the structure of the data
dkato 0:ee40da884cfc 294 *
dkato 0:ee40da884cfc 295 * @returns
dkato 0:ee40da884cfc 296 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 297 */
dkato 0:ee40da884cfc 298 static bool recv_mail(dsp_mail_t * const p_data)
dkato 0:ee40da884cfc 299 {
dkato 0:ee40da884cfc 300 bool ret = false;
dkato 0:ee40da884cfc 301 osEvent evt;
dkato 0:ee40da884cfc 302 dsp_mail_t *p_mail;
dkato 0:ee40da884cfc 303
dkato 0:ee40da884cfc 304 if (p_data != NULL) {
dkato 0:ee40da884cfc 305 evt = mail_box.get();
dkato 0:ee40da884cfc 306 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 307 p_mail = (dsp_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 308 if (p_mail != NULL) {
dkato 0:ee40da884cfc 309 *p_data = *p_mail;
dkato 0:ee40da884cfc 310 ret = true;
dkato 0:ee40da884cfc 311 }
dkato 0:ee40da884cfc 312 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 313 }
dkato 0:ee40da884cfc 314 }
dkato 0:ee40da884cfc 315 return ret;
dkato 0:ee40da884cfc 316 }
dkato 0:ee40da884cfc 317
dkato 0:ee40da884cfc 318 /** Decodes the display thread mail
dkato 0:ee40da884cfc 319 *
dkato 0:ee40da884cfc 320 * @param p_mail Pointer to the structure of the data
dkato 0:ee40da884cfc 321 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 322 *
dkato 0:ee40da884cfc 323 * @returns
dkato 0:ee40da884cfc 324 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 325 */
dkato 0:ee40da884cfc 326 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 327 {
dkato 0:ee40da884cfc 328 bool ret = false;
dkato 0:ee40da884cfc 329
dkato 0:ee40da884cfc 330 if ((p_mail != NULL) && (p_ctrl != NULL)) {
dkato 0:ee40da884cfc 331 /* Decodes the received mail */
dkato 0:ee40da884cfc 332 switch(p_mail->mail_id) {
dkato 0:ee40da884cfc 333 case DSP_MAILID_CYCLE_IND: /* Cyclic notice */
dkato 0:ee40da884cfc 334 ret = true;
dkato 0:ee40da884cfc 335 break;
dkato 0:ee40da884cfc 336 case DSP_MAILID_CMD_STR: /* Input character string by the command-line */
dkato 0:ee40da884cfc 337 ret = true;
dkato 0:ee40da884cfc 338 if ((int32_t)p_mail->param[MAIL_CMDSTR_FIN_FLG] == true) {
dkato 0:ee40da884cfc 339 p_ctrl->trm.edge_fin_inpt = true;
dkato 0:ee40da884cfc 340 } else {
dkato 0:ee40da884cfc 341 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 342 }
dkato 0:ee40da884cfc 343 (void) memcpy(&p_ctrl->trm.inpt_str[0],
dkato 0:ee40da884cfc 344 &p_mail->param[MAIL_CMDSTR_STR_START],
dkato 0:ee40da884cfc 345 sizeof(p_ctrl->trm.inpt_str));
dkato 0:ee40da884cfc 346 p_ctrl->trm.inpt_str[DSP_CMD_INPT_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 347 break;
dkato 0:ee40da884cfc 348 case DSP_MAILID_PRINT_STR: /* Character string for the status indication */
dkato 0:ee40da884cfc 349 ret = true;
dkato 0:ee40da884cfc 350 (void) memcpy(&p_ctrl->com.dspl_str[0],
dkato 0:ee40da884cfc 351 &p_mail->param[MAIL_DISPSTR_STR_START],
dkato 0:ee40da884cfc 352 sizeof(p_ctrl->com.dspl_str));
dkato 0:ee40da884cfc 353 p_ctrl->com.dspl_str[DSP_DISP_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 354 break;
dkato 0:ee40da884cfc 355 case DSP_MAILID_PLAY_TIME: /* Playback time */
dkato 0:ee40da884cfc 356 ret = true;
dkato 0:ee40da884cfc 357 p_ctrl->com.play_stat = (SYS_PlayStat)p_mail->param[MAIL_PLAYTIME_STAT];
dkato 0:ee40da884cfc 358 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_H] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 359 (uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_L]);
dkato 0:ee40da884cfc 360 p_ctrl->com.play_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 361 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 362 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_L]));
dkato 0:ee40da884cfc 363 p_ctrl->com.total_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 364 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 365 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_L]));
dkato 0:ee40da884cfc 366 break;
dkato 0:ee40da884cfc 367 case DSP_MAILID_PLAY_INFO: /* Music information */
dkato 0:ee40da884cfc 368 ret = true;
dkato 0:ee40da884cfc 369 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_H] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 370 (uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_L]);
dkato 0:ee40da884cfc 371 p_ctrl->com.samp_freq = (((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 372 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 373 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_L]));
dkato 0:ee40da884cfc 374 p_ctrl->com.channel = p_mail->param[MAIL_PLAYINFO_CHANNEL];
dkato 0:ee40da884cfc 375 break;
dkato 0:ee40da884cfc 376 case DSP_MAILID_PLAY_MODE: /* Repeat mode */
dkato 0:ee40da884cfc 377 ret = true;
dkato 0:ee40da884cfc 378 if ((int32_t)p_mail->param[MAIL_PLAYMODE_REPEAT] == true) {
dkato 0:ee40da884cfc 379 p_ctrl->com.repeat_mode = true;
dkato 0:ee40da884cfc 380 } else {
dkato 0:ee40da884cfc 381 p_ctrl->com.repeat_mode = false;
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383 break;
dkato 0:ee40da884cfc 384 case DSP_MAILID_FILE_NAME: /* File name */
dkato 0:ee40da884cfc 385 ret = true;
dkato 0:ee40da884cfc 386 (void) memcpy(&p_ctrl->com.file_name[0],
dkato 0:ee40da884cfc 387 &p_mail->param[MAIL_FILENAME_STR_START],
dkato 0:ee40da884cfc 388 sizeof(p_ctrl->com.file_name));
dkato 0:ee40da884cfc 389 p_ctrl->com.file_name[DSP_DISP_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 390 break;
dkato 2:d9fca8cd7f03 391 case DSP_MAILID_HELP: /* Help information */
dkato 2:d9fca8cd7f03 392 ret = true;
dkato 2:d9fca8cd7f03 393 break;
dkato 0:ee40da884cfc 394 default:
dkato 0:ee40da884cfc 395 /* Unexpected cases : mail id was illegal. */
dkato 0:ee40da884cfc 396 ret = false;
dkato 0:ee40da884cfc 397 break;
dkato 0:ee40da884cfc 398 }
dkato 0:ee40da884cfc 399 }
dkato 0:ee40da884cfc 400 return ret;
dkato 0:ee40da884cfc 401 }
dkato 0:ee40da884cfc 402
dkato 0:ee40da884cfc 403 /** Clears the one shot data in the control data of display module
dkato 0:ee40da884cfc 404 *
dkato 0:ee40da884cfc 405 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 406 */
dkato 0:ee40da884cfc 407 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 408 {
dkato 0:ee40da884cfc 409 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 410 if (p_ctrl->trm.edge_fin_inpt == true) {
dkato 0:ee40da884cfc 411 /* Clears data of input character string. */
dkato 0:ee40da884cfc 412 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 413 p_ctrl->trm.inpt_str[0] = '\0';
dkato 0:ee40da884cfc 414 }
dkato 0:ee40da884cfc 415 }
dkato 0:ee40da884cfc 416 return;
dkato 0:ee40da884cfc 417 }