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"
Osamu Nakamura 6:df19c3e787ca 26 #include "FATFileSystem.h"
dkato 0:ee40da884cfc 27 #include "USBHostMSD.h"
dkato 0:ee40da884cfc 28
dkato 0:ee40da884cfc 29 #include "system.h"
dkato 0:ee40da884cfc 30 #include "sys_scan_folder.h"
dkato 0:ee40da884cfc 31 #include "decode.h"
dkato 0:ee40da884cfc 32 #include "display.h"
dkato 0:ee40da884cfc 33
dkato 0:ee40da884cfc 34 #if defined(TARGET_RZ_A1H)
dkato 0:ee40da884cfc 35 #include "usb_host_setting.h"
dkato 0:ee40da884cfc 36 #else
dkato 0:ee40da884cfc 37 #define USB_HOST_CH (0)
dkato 0:ee40da884cfc 38 #endif
dkato 0:ee40da884cfc 39
dkato 0:ee40da884cfc 40 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 41 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 42 #define MAIL_PARAM_NUM (3) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 43
dkato 0:ee40da884cfc 44 /* sys_mail_t */
dkato 0:ee40da884cfc 45 #define MAIL_PARAM0 (0) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 46 #define MAIL_PARAM1 (1) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 47 #define MAIL_PARAM2 (2) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 48
dkato 0:ee40da884cfc 49 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 0:ee40da884cfc 50
dkato 0:ee40da884cfc 51 /* mail_id = SYS_MAILID_KEYCODE */
dkato 0:ee40da884cfc 52 #define MAIL_KEYCODE_CODE (MAIL_PARAM0) /* Key code */
dkato 0:ee40da884cfc 53
dkato 0:ee40da884cfc 54 /* mail_id = SYS_MAILID_PLAY_TIME */
dkato 0:ee40da884cfc 55 #define MAIL_PLAYTIME_STAT (MAIL_PARAM0) /* Playback status */
dkato 0:ee40da884cfc 56 #define MAIL_PLAYTIME_TIME (MAIL_PARAM1) /* Playback time */
dkato 0:ee40da884cfc 57 #define MAIL_PLAYTIME_TOTAL (MAIL_PARAM2) /* Total playback time */
dkato 0:ee40da884cfc 58
dkato 0:ee40da884cfc 59 /* mail_id = SYS_MAILID_DEC_OPEN_FIN */
dkato 0:ee40da884cfc 60 #define MAIL_DECOPEN_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 61 #define MAIL_DECOPEN_FREQ (MAIL_PARAM1) /* Sampling rate in Hz of FLAC file */
dkato 0:ee40da884cfc 62 #define MAIL_DECOPEN_CH (MAIL_PARAM2) /* Number of channel */
dkato 0:ee40da884cfc 63
dkato 0:ee40da884cfc 64 #define RECV_MAIL_TIMEOUT_MS (10)
dkato 0:ee40da884cfc 65
dkato 0:ee40da884cfc 66 #define USB1_WAIT_TIME_MS (5)
dkato 0:ee40da884cfc 67 #define TRACK_ID_MIN (0u)
dkato 0:ee40da884cfc 68 #define TRACK_ID_ERR (0xFFFFFFFFu)
dkato 0:ee40da884cfc 69
dkato 0:ee40da884cfc 70 #define PRINT_MSG_USB_CONNECT "USB connection was detected."
dkato 0:ee40da884cfc 71 #define PRINT_MSG_OPEN_ERR "Could not play this file."
dkato 0:ee40da884cfc 72 #define PRINT_MSG_DECODE_ERR "This file format is not supported."
dkato 0:ee40da884cfc 73
dkato 0:ee40da884cfc 74 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 75 typedef enum {
dkato 0:ee40da884cfc 76 SYS_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 77 SYS_MAILID_KEYCODE, /* Notifies main thread of key code. */
dkato 0:ee40da884cfc 78 SYS_MAILID_PLAY_TIME, /* Notifies main thread of playback time. */
dkato 0:ee40da884cfc 79 SYS_MAILID_DEC_OPEN_FIN, /* Finished the opening process of Decode Thread. */
dkato 0:ee40da884cfc 80 SYS_MAILID_DEC_CLOSE_FIN, /* Finished the closing process of Decode Thread. */
dkato 0:ee40da884cfc 81 SYS_MAILID_NUM
dkato 0:ee40da884cfc 82 } SYS_MAIL_ID;
dkato 0:ee40da884cfc 83
dkato 0:ee40da884cfc 84 typedef struct {
dkato 0:ee40da884cfc 85 SYS_MAIL_ID mail_id;
dkato 0:ee40da884cfc 86 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 87 } sys_mail_t;
dkato 0:ee40da884cfc 88
dkato 0:ee40da884cfc 89 /*--- User defined types of main thread ---*/
dkato 0:ee40da884cfc 90 /* Status of main thread */
dkato 0:ee40da884cfc 91 typedef enum {
dkato 0:ee40da884cfc 92 SYS_ST_WAIT_USB_CONNECT = 0,/* Wait the USB connection */
dkato 0:ee40da884cfc 93 SYS_ST_STOP, /* Stop the playback */
dkato 0:ee40da884cfc 94 SYS_ST_PLAY_PREPARE, /* Preparation of the playback */
dkato 0:ee40da884cfc 95 SYS_ST_PLAY_PREPARE_REQ, /* Holds the stop request until completion */
dkato 0:ee40da884cfc 96 /* of the playback preparation */
dkato 0:ee40da884cfc 97 SYS_ST_PLAY, /* Play */
dkato 0:ee40da884cfc 98 SYS_ST_PAUSE, /* Pause */
dkato 0:ee40da884cfc 99 SYS_ST_STOP_PREPARE, /* Preparation of the stop */
dkato 0:ee40da884cfc 100 SYS_ST_STOP_PREPARE_REQ, /* Holds the playback request until completion */
dkato 0:ee40da884cfc 101 /* of the stop preparation */
dkato 0:ee40da884cfc 102 SYS_ST_NUM
dkato 0:ee40da884cfc 103 } SYS_STATE;
dkato 0:ee40da884cfc 104
dkato 0:ee40da884cfc 105 /* Event of the state transition */
dkato 0:ee40da884cfc 106 typedef enum {
dkato 0:ee40da884cfc 107 SYS_EV_NON = 0,
dkato 0:ee40da884cfc 108 /* Notification of pushed key. */
dkato 0:ee40da884cfc 109 SYS_EV_KEY_STOP, /* "STOP" key */
dkato 0:ee40da884cfc 110 SYS_EV_KEY_PLAY_PAUSE, /* "PLAY/PAUSE" key */
dkato 0:ee40da884cfc 111 SYS_EV_KEY_NEXT, /* "NEXT" key */
dkato 0:ee40da884cfc 112 SYS_EV_KEY_PREV, /* "PREV" key */
dkato 0:ee40da884cfc 113 SYS_EV_KEY_PLAYINFO, /* "PLAYINFO" key */
dkato 0:ee40da884cfc 114 SYS_EV_KEY_REPEAT, /* "REPEAT" key */
dkato 2:d9fca8cd7f03 115 SYS_EV_KEY_HELP, /* "HELP" key */
dkato 0:ee40da884cfc 116 /* Notification of decoder process */
dkato 0:ee40da884cfc 117 SYS_EV_DEC_OPEN_COMP, /* Finished the opening process */
dkato 0:ee40da884cfc 118 SYS_EV_DEC_OPEN_COMP_ERR, /* Finished the opening process (An error occured)*/
dkato 0:ee40da884cfc 119 SYS_EV_DEC_CLOSE_COMP, /* Finished the closing process */
dkato 0:ee40da884cfc 120 /* Notification of the playback status */
dkato 0:ee40da884cfc 121 SYS_EV_STAT_STOP, /* Stop */
dkato 0:ee40da884cfc 122 SYS_EV_STAT_PLAY, /* Play */
dkato 0:ee40da884cfc 123 SYS_EV_STAT_PAUSE, /* Pause */
dkato 0:ee40da884cfc 124 /* Notification of USB connection */
dkato 0:ee40da884cfc 125 SYS_EV_USB_CONNECT, /* Connect */
dkato 0:ee40da884cfc 126 SYS_EV_USB_DISCONNECT, /* Disconnect */
dkato 0:ee40da884cfc 127 SYS_EV_NUM
dkato 0:ee40da884cfc 128 } SYS_EVENT;
dkato 0:ee40da884cfc 129
dkato 0:ee40da884cfc 130 /* Control data of USB memory */
dkato 0:ee40da884cfc 131 typedef struct {
dkato 0:ee40da884cfc 132 bool usb_flag_detach;/* Detected the disconnection of USB memory */
dkato 0:ee40da884cfc 133 } usb_ctrl_t;
dkato 0:ee40da884cfc 134
dkato 0:ee40da884cfc 135 /* The playback information of the playback file */
dkato 0:ee40da884cfc 136 typedef struct {
dkato 0:ee40da884cfc 137 SYS_PlayStat play_stat; /* Playback status */
dkato 0:ee40da884cfc 138 bool repeat_mode; /* Repeat mode */
dkato 0:ee40da884cfc 139 uint32_t track_id; /* Number of the selected track */
dkato 0:ee40da884cfc 140 uint32_t open_track_id; /* Number of the track during the open processing */
dkato 0:ee40da884cfc 141 FILE *p_file_handle; /* Handle of the track */
dkato 0:ee40da884cfc 142 uint32_t play_time; /* Playback start time */
dkato 0:ee40da884cfc 143 uint32_t total_time; /* Total playback time */
dkato 0:ee40da884cfc 144 uint32_t sample_rate; /* Sampling rate in Hz of FLAC file */
dkato 0:ee40da884cfc 145 uint32_t channel_num; /* Number of channel */
dkato 0:ee40da884cfc 146 } play_info_t;
dkato 0:ee40da884cfc 147
dkato 0:ee40da884cfc 148 /* Control data of main thread */
dkato 0:ee40da884cfc 149 typedef struct {
dkato 0:ee40da884cfc 150 usb_ctrl_t usb_ctrl;
dkato 0:ee40da884cfc 151 fid_scan_folder_t scan_data;
dkato 0:ee40da884cfc 152 play_info_t play_info;
dkato 0:ee40da884cfc 153 } sys_ctrl_t;
dkato 0:ee40da884cfc 154
dkato 0:ee40da884cfc 155 static Mail<sys_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 156
dkato 0:ee40da884cfc 157 static void open_callback(const bool result, const uint32_t sample_freq,
dkato 0:ee40da884cfc 158 const uint32_t channel_num);
dkato 0:ee40da884cfc 159 static void close_callback(void);
dkato 0:ee40da884cfc 160 static void init_ctrl_data(sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 161 static SYS_EVENT decode_mail(play_info_t * const p_info,
dkato 0:ee40da884cfc 162 const fid_scan_folder_t * const p_data, const SYS_MAIL_ID mail_id,
dkato 0:ee40da884cfc 163 const uint32_t * const p_param);
dkato 0:ee40da884cfc 164 static SYS_EVENT check_usb_event(const SYS_STATE stat,
Osamu Nakamura 6:df19c3e787ca 165 const usb_ctrl_t * const p_ctrl, USBHostMSD * const p_msd,
Osamu Nakamura 6:df19c3e787ca 166 FATFileSystem * const p_fs);
dkato 0:ee40da884cfc 167 static SYS_STATE state_trans_proc(const SYS_STATE stat,
dkato 0:ee40da884cfc 168 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 169 static SYS_STATE state_trans_proc(const SYS_STATE stat,
dkato 0:ee40da884cfc 170 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 171 static SYS_STATE state_proc_wait_usb_connect(const SYS_STATE stat,
dkato 0:ee40da884cfc 172 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 173 static SYS_STATE state_proc_stop(const SYS_STATE stat,
dkato 0:ee40da884cfc 174 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 175 static SYS_STATE state_proc_play_prepare(const SYS_STATE stat,
dkato 0:ee40da884cfc 176 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 177 static SYS_STATE state_proc_play_prepare_req(const SYS_STATE stat,
dkato 0:ee40da884cfc 178 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 179 static SYS_STATE state_proc_play_pause(const SYS_STATE stat,
dkato 0:ee40da884cfc 180 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 181 static SYS_STATE state_proc_stop_prepare(const SYS_STATE stat,
dkato 0:ee40da884cfc 182 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 183 static SYS_STATE state_proc_stop_prepare_req(const SYS_STATE stat,
dkato 0:ee40da884cfc 184 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 185 static bool exe_scan_folder_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 186 fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 187 static bool exe_open_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 188 fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 189 static bool exe_play_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 190 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 191 static bool exe_pause_on_proc(void);
dkato 0:ee40da884cfc 192 static bool exe_pause_off_proc(void);
dkato 0:ee40da884cfc 193 static bool exe_stop_proc(void);
dkato 0:ee40da884cfc 194 static bool exe_close_proc(void);
dkato 0:ee40da884cfc 195 static void exe_end_proc(play_info_t * const p_info);
dkato 0:ee40da884cfc 196 static bool is_track_changed(const play_info_t * const p_info);
dkato 0:ee40da884cfc 197 static void change_repeat_mode(play_info_t * const p_info);
dkato 0:ee40da884cfc 198 static bool change_next_track(play_info_t * const p_info,
dkato 0:ee40da884cfc 199 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 200 static bool change_prev_track(play_info_t * const p_info,
dkato 0:ee40da884cfc 201 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 202 static void print_play_time(const play_info_t * const p_info);
dkato 0:ee40da884cfc 203 static void print_play_info(const play_info_t * const p_info);
dkato 0:ee40da884cfc 204 static void print_file_name(const play_info_t * const p_info,
dkato 0:ee40da884cfc 205 const fid_scan_folder_t * const p_data);
dkato 2:d9fca8cd7f03 206 static void print_help_info(void);
dkato 0:ee40da884cfc 207 static uint32_t convert_track_id(const uint32_t trk_id);
dkato 0:ee40da884cfc 208 static bool send_mail(const SYS_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 209 const uint32_t param1, const uint32_t param2);
dkato 0:ee40da884cfc 210 static bool recv_mail(SYS_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 211 uint32_t * const p_param1, uint32_t * const p_param2);
dkato 0:ee40da884cfc 212
dkato 0:ee40da884cfc 213 void system_main(void)
dkato 0:ee40da884cfc 214 {
dkato 0:ee40da884cfc 215 SYS_STATE sys_stat;
dkato 0:ee40da884cfc 216 SYS_EVENT sys_ev;
dkato 0:ee40da884cfc 217 bool result;
dkato 0:ee40da884cfc 218 SYS_MAIL_ID mail_type;
dkato 0:ee40da884cfc 219 uint32_t mail_param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 220 static sys_ctrl_t sys_ctrl;
Osamu Nakamura 6:df19c3e787ca 221 static FATFileSystem fs(SYS_USB_MOUNT_NAME);
Osamu Nakamura 6:df19c3e787ca 222 static USBHostMSD msd;
dkato 0:ee40da884cfc 223 #if (USB_HOST_CH == 1) /* Audio Shield USB1 */
dkato 0:ee40da884cfc 224 static DigitalOut usb1en(P3_8);
dkato 0:ee40da884cfc 225
dkato 0:ee40da884cfc 226 /* Audio Shield USB1 enable */
dkato 0:ee40da884cfc 227 usb1en.write(1); /* Outputs high level */
dkato 0:ee40da884cfc 228 Thread::wait(USB1_WAIT_TIME_MS);
dkato 0:ee40da884cfc 229 usb1en.write(0); /* Outputs low level */
dkato 0:ee40da884cfc 230 #endif /* USB_HOST_CH */
dkato 0:ee40da884cfc 231
dkato 0:ee40da884cfc 232 /* Initializes the control data of main thread. */
dkato 0:ee40da884cfc 233 init_ctrl_data(&sys_ctrl);
dkato 0:ee40da884cfc 234 sys_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 235 while (1) {
Osamu Nakamura 6:df19c3e787ca 236 sys_ev = check_usb_event(sys_stat, &sys_ctrl.usb_ctrl, &msd, &fs);
dkato 0:ee40da884cfc 237 if (sys_ev == SYS_EV_NON) {
dkato 0:ee40da884cfc 238 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0],
dkato 0:ee40da884cfc 239 &mail_param[MAIL_PARAM1], &mail_param[MAIL_PARAM2]);
dkato 0:ee40da884cfc 240 if (result == true) {
dkato 0:ee40da884cfc 241 sys_ev = decode_mail(&sys_ctrl.play_info,
dkato 0:ee40da884cfc 242 &sys_ctrl.scan_data, mail_type, mail_param);
dkato 0:ee40da884cfc 243 }
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245 if (sys_ev != SYS_EV_NON) {
dkato 0:ee40da884cfc 246 sys_stat = state_trans_proc(sys_stat, sys_ev, &sys_ctrl);
dkato 0:ee40da884cfc 247 }
dkato 0:ee40da884cfc 248 }
dkato 0:ee40da884cfc 249 }
dkato 0:ee40da884cfc 250
dkato 0:ee40da884cfc 251 bool sys_notify_key_input(const SYS_KeyCode key_code)
dkato 0:ee40da884cfc 252 {
dkato 0:ee40da884cfc 253 bool ret = false;
dkato 0:ee40da884cfc 254
dkato 0:ee40da884cfc 255 ret = send_mail(SYS_MAILID_KEYCODE, (uint32_t)key_code, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 256
dkato 0:ee40da884cfc 257 return ret;
dkato 0:ee40da884cfc 258 }
dkato 0:ee40da884cfc 259
dkato 0:ee40da884cfc 260 bool sys_notify_play_time(const SYS_PlayStat play_stat,
dkato 0:ee40da884cfc 261 const uint32_t play_time, const uint32_t total_time)
dkato 0:ee40da884cfc 262 {
dkato 0:ee40da884cfc 263 bool ret = false;
dkato 0:ee40da884cfc 264
dkato 0:ee40da884cfc 265 ret = send_mail(SYS_MAILID_PLAY_TIME, (uint32_t)play_stat, play_time, total_time);
dkato 0:ee40da884cfc 266
dkato 0:ee40da884cfc 267 return ret;
dkato 0:ee40da884cfc 268 }
dkato 0:ee40da884cfc 269
dkato 0:ee40da884cfc 270 /** Callback function of Decode Thread
dkato 0:ee40da884cfc 271 *
dkato 0:ee40da884cfc 272 * @param result Result of the process.
dkato 0:ee40da884cfc 273 * @param sample_freq Sampling rate in Hz of FLAC file.
dkato 0:ee40da884cfc 274 * @param channel_num Number of channel.
dkato 0:ee40da884cfc 275 */
dkato 0:ee40da884cfc 276 static void open_callback(const bool result, const uint32_t sample_freq,
dkato 0:ee40da884cfc 277 const uint32_t channel_num)
dkato 0:ee40da884cfc 278 {
dkato 0:ee40da884cfc 279 (void) send_mail(SYS_MAILID_DEC_OPEN_FIN, (uint32_t)result, sample_freq, channel_num);
dkato 0:ee40da884cfc 280 }
dkato 0:ee40da884cfc 281
dkato 0:ee40da884cfc 282 /** Callback function of Decode Thread
dkato 0:ee40da884cfc 283 *
dkato 0:ee40da884cfc 284 */
dkato 0:ee40da884cfc 285 static void close_callback(void)
dkato 0:ee40da884cfc 286 {
dkato 0:ee40da884cfc 287 (void) send_mail(SYS_MAILID_DEC_CLOSE_FIN, MAIL_PARAM_NON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 288 }
dkato 0:ee40da884cfc 289
dkato 0:ee40da884cfc 290 /** Initialises the control data of main thread
dkato 0:ee40da884cfc 291 *
dkato 0:ee40da884cfc 292 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 293 */
dkato 0:ee40da884cfc 294 static void init_ctrl_data(sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 295 {
dkato 0:ee40da884cfc 296 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 297 /* Initialises the control data of USB memory. */
dkato 0:ee40da884cfc 298 p_ctrl->usb_ctrl.usb_flag_detach = false;
dkato 0:ee40da884cfc 299 /* Initialises the information of folder scan. */
dkato 0:ee40da884cfc 300 fid_init(&p_ctrl->scan_data);
dkato 0:ee40da884cfc 301 /* Initialises the playback information of the playback file */
dkato 0:ee40da884cfc 302 p_ctrl->play_info.play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 303 p_ctrl->play_info.repeat_mode = true;
dkato 0:ee40da884cfc 304 p_ctrl->play_info.track_id = TRACK_ID_MIN;
dkato 0:ee40da884cfc 305 p_ctrl->play_info.open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 306 p_ctrl->play_info.p_file_handle = NULL;
dkato 0:ee40da884cfc 307 p_ctrl->play_info.play_time = 0u;
dkato 0:ee40da884cfc 308 p_ctrl->play_info.total_time = 0u;
dkato 0:ee40da884cfc 309 p_ctrl->play_info.sample_rate = 0u;
dkato 0:ee40da884cfc 310 p_ctrl->play_info.channel_num = 0u;
dkato 0:ee40da884cfc 311 }
dkato 0:ee40da884cfc 312 }
dkato 0:ee40da884cfc 313
dkato 0:ee40da884cfc 314 /** Converts the code of SYS_MAIL_ID into the code of SYS_EVENT
dkato 0:ee40da884cfc 315 *
dkato 0:ee40da884cfc 316 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 317 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 318 * @param mail_id The event code of SYS_MAIL_ID
dkato 0:ee40da884cfc 319 * @param p_param Pointer to the parameter of the mail
dkato 0:ee40da884cfc 320 *
dkato 0:ee40da884cfc 321 * @returns
dkato 0:ee40da884cfc 322 * The event code of SYS_EVENT
dkato 0:ee40da884cfc 323 */
dkato 0:ee40da884cfc 324 static SYS_EVENT decode_mail(play_info_t * const p_info,
dkato 0:ee40da884cfc 325 const fid_scan_folder_t * const p_data, const SYS_MAIL_ID mail_id,
dkato 0:ee40da884cfc 326 const uint32_t * const p_param)
dkato 0:ee40da884cfc 327 {
dkato 0:ee40da884cfc 328 SYS_EVENT ret = SYS_EV_NON;
dkato 0:ee40da884cfc 329
dkato 0:ee40da884cfc 330 if ((p_info != NULL) && (p_data != NULL) && (p_param != NULL)) {
dkato 0:ee40da884cfc 331 switch (mail_id) {
dkato 0:ee40da884cfc 332 case SYS_MAILID_KEYCODE:
dkato 0:ee40da884cfc 333 switch (p_param[MAIL_KEYCODE_CODE]) {
dkato 0:ee40da884cfc 334 case SYS_KEYCODE_STOP:
dkato 0:ee40da884cfc 335 ret = SYS_EV_KEY_STOP;
dkato 0:ee40da884cfc 336 break;
dkato 0:ee40da884cfc 337 case SYS_KEYCODE_PLAYPAUSE:
dkato 0:ee40da884cfc 338 ret = SYS_EV_KEY_PLAY_PAUSE;
dkato 0:ee40da884cfc 339 break;
dkato 0:ee40da884cfc 340 case SYS_KEYCODE_NEXT:
dkato 0:ee40da884cfc 341 ret = SYS_EV_KEY_NEXT;
dkato 0:ee40da884cfc 342 break;
dkato 0:ee40da884cfc 343 case SYS_KEYCODE_PREV:
dkato 0:ee40da884cfc 344 ret = SYS_EV_KEY_PREV;
dkato 0:ee40da884cfc 345 break;
dkato 0:ee40da884cfc 346 case SYS_KEYCODE_PLAYINFO:
dkato 0:ee40da884cfc 347 ret = SYS_EV_KEY_PLAYINFO;
dkato 0:ee40da884cfc 348 break;
dkato 2:d9fca8cd7f03 349 case SYS_KEYCODE_REPEAT:
dkato 0:ee40da884cfc 350 ret = SYS_EV_KEY_REPEAT;
dkato 0:ee40da884cfc 351 break;
dkato 2:d9fca8cd7f03 352 case SYS_KEYCODE_HELP:
dkato 2:d9fca8cd7f03 353 ret = SYS_EV_KEY_HELP;
dkato 2:d9fca8cd7f03 354 break;
dkato 0:ee40da884cfc 355 default:
dkato 0:ee40da884cfc 356 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 357 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 358 break;
dkato 0:ee40da884cfc 359 }
dkato 0:ee40da884cfc 360 break;
dkato 0:ee40da884cfc 361 case SYS_MAILID_PLAY_TIME:
dkato 0:ee40da884cfc 362 switch (p_param[MAIL_PLAYTIME_STAT]) {
dkato 0:ee40da884cfc 363 case SYS_PLAYSTAT_STOP:
dkato 0:ee40da884cfc 364 ret = SYS_EV_STAT_STOP;
dkato 0:ee40da884cfc 365 break;
dkato 0:ee40da884cfc 366 case SYS_PLAYSTAT_PLAY:
dkato 0:ee40da884cfc 367 ret = SYS_EV_STAT_PLAY;
dkato 0:ee40da884cfc 368 break;
dkato 0:ee40da884cfc 369 case SYS_PLAYSTAT_PAUSE:
dkato 0:ee40da884cfc 370 ret = SYS_EV_STAT_PAUSE;
dkato 0:ee40da884cfc 371 break;
dkato 0:ee40da884cfc 372 default:
dkato 0:ee40da884cfc 373 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 374 break;
dkato 0:ee40da884cfc 375 }
dkato 0:ee40da884cfc 376 /* Is the playback status correct? */
dkato 0:ee40da884cfc 377 if (ret != SYS_EV_NON) {
dkato 0:ee40da884cfc 378 p_info->play_stat = (SYS_PlayStat)p_param[MAIL_PLAYTIME_STAT];
dkato 0:ee40da884cfc 379 p_info->play_time = p_param[MAIL_PLAYTIME_TIME];
dkato 0:ee40da884cfc 380 p_info->total_time = p_param[MAIL_PLAYTIME_TOTAL];
dkato 0:ee40da884cfc 381 } else {
dkato 0:ee40da884cfc 382 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 383 p_info->play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 384 p_info->play_time = 0u;
dkato 0:ee40da884cfc 385 p_info->total_time = 0u;
dkato 0:ee40da884cfc 386 }
dkato 0:ee40da884cfc 387 break;
dkato 0:ee40da884cfc 388 case SYS_MAILID_DEC_OPEN_FIN:
dkato 0:ee40da884cfc 389 if ((int32_t)p_param[MAIL_DECOPEN_RESULT] == true) {
dkato 0:ee40da884cfc 390 ret = SYS_EV_DEC_OPEN_COMP;
dkato 0:ee40da884cfc 391 p_info->sample_rate = p_param[MAIL_DECOPEN_FREQ];
dkato 0:ee40da884cfc 392 p_info->channel_num = p_param[MAIL_DECOPEN_CH];
dkato 0:ee40da884cfc 393 } else {
dkato 0:ee40da884cfc 394 /* The opening of the decoder was failure. */
dkato 0:ee40da884cfc 395 ret = SYS_EV_DEC_OPEN_COMP_ERR;
dkato 0:ee40da884cfc 396 p_info->sample_rate = 0u;
dkato 0:ee40da884cfc 397 p_info->channel_num = 0u;
dkato 0:ee40da884cfc 398 /* Tries to open the next file. */
dkato 0:ee40da884cfc 399 print_play_time(p_info);
dkato 0:ee40da884cfc 400 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 401 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 402 }
dkato 0:ee40da884cfc 403 break;
dkato 0:ee40da884cfc 404 case SYS_MAILID_DEC_CLOSE_FIN:
dkato 0:ee40da884cfc 405 ret = SYS_EV_DEC_CLOSE_COMP;
dkato 0:ee40da884cfc 406 p_info->play_time = 0u;
dkato 0:ee40da884cfc 407 p_info->total_time = 0u;
dkato 0:ee40da884cfc 408 break;
dkato 0:ee40da884cfc 409 default:
dkato 0:ee40da884cfc 410 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 411 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 412 break;
dkato 0:ee40da884cfc 413 }
dkato 0:ee40da884cfc 414 }
dkato 0:ee40da884cfc 415 return ret;
dkato 0:ee40da884cfc 416 }
dkato 0:ee40da884cfc 417
dkato 0:ee40da884cfc 418 /** Checks the event of USB connection
dkato 0:ee40da884cfc 419 *
dkato 0:ee40da884cfc 420 * @param stat Status of main thread
dkato 0:ee40da884cfc 421 * @param p_ctrl Pointer to the control data of USB memory
dkato 0:ee40da884cfc 422 * @param p_msd Pointer to the class object of USBHostMSD
Osamu Nakamura 6:df19c3e787ca 423 * @param P_fs Pointer to the class oblect of FATFileSystem
dkato 0:ee40da884cfc 424 *
dkato 0:ee40da884cfc 425 * @returns
dkato 0:ee40da884cfc 426 * The event code of SYS_EVENT
dkato 0:ee40da884cfc 427 */
dkato 0:ee40da884cfc 428 static SYS_EVENT check_usb_event(const SYS_STATE stat,
Osamu Nakamura 6:df19c3e787ca 429 const usb_ctrl_t * const p_ctrl,
Osamu Nakamura 6:df19c3e787ca 430 USBHostMSD * const p_msd, FATFileSystem * const p_fs)
dkato 0:ee40da884cfc 431 {
dkato 0:ee40da884cfc 432 SYS_EVENT ret = SYS_EV_NON;
Osamu Nakamura 6:df19c3e787ca 433 int iRet;
dkato 0:ee40da884cfc 434 bool result;
dkato 0:ee40da884cfc 435
dkato 0:ee40da884cfc 436 if ((p_ctrl != NULL) && (p_msd != NULL)) {
dkato 0:ee40da884cfc 437 if (stat == SYS_ST_WAIT_USB_CONNECT) {
dkato 0:ee40da884cfc 438 /* Mounts the FAT filesystem again. */
dkato 0:ee40da884cfc 439 /* Because the connecting USB memory is changed. */
dkato 0:ee40da884cfc 440 result = p_msd->connect();
dkato 0:ee40da884cfc 441 if (result == true) {
Osamu Nakamura 6:df19c3e787ca 442 iRet = p_fs->unmount();
Osamu Nakamura 6:df19c3e787ca 443 iRet = p_fs->mount(p_msd);
dkato 0:ee40da884cfc 444 ret = SYS_EV_USB_CONNECT;
dkato 0:ee40da884cfc 445 }
dkato 0:ee40da884cfc 446 } else if (p_ctrl->usb_flag_detach != true) {
dkato 0:ee40da884cfc 447 result = p_msd->connected();
dkato 0:ee40da884cfc 448 if (result != true) {
dkato 0:ee40da884cfc 449 ret = SYS_EV_USB_DISCONNECT;
dkato 0:ee40da884cfc 450 }
dkato 0:ee40da884cfc 451 } else {
dkato 0:ee40da884cfc 452 /* DO NOTHING */
dkato 0:ee40da884cfc 453 }
dkato 0:ee40da884cfc 454 }
dkato 0:ee40da884cfc 455 return ret;
dkato 0:ee40da884cfc 456 }
dkato 0:ee40da884cfc 457
dkato 0:ee40da884cfc 458 /** Executes the state transition processing
dkato 0:ee40da884cfc 459 *
dkato 0:ee40da884cfc 460 * @param stat Status of main thread
dkato 0:ee40da884cfc 461 * @param event Event code of main thread
dkato 0:ee40da884cfc 462 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 463 *
dkato 0:ee40da884cfc 464 * @returns
dkato 0:ee40da884cfc 465 * Next status of main thread
dkato 0:ee40da884cfc 466 */
dkato 0:ee40da884cfc 467 static SYS_STATE state_trans_proc(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 468 {
dkato 0:ee40da884cfc 469 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 470
dkato 0:ee40da884cfc 471 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 472 /* State transition processing */
dkato 0:ee40da884cfc 473 switch (stat) {
dkato 0:ee40da884cfc 474 case SYS_ST_WAIT_USB_CONNECT: /* Wait the USB connection */
dkato 0:ee40da884cfc 475 next_stat = state_proc_wait_usb_connect(stat, event, p_ctrl);
dkato 0:ee40da884cfc 476 break;
dkato 0:ee40da884cfc 477 case SYS_ST_STOP: /* Stop the playback */
dkato 0:ee40da884cfc 478 next_stat = state_proc_stop(stat, event, p_ctrl);
dkato 0:ee40da884cfc 479 break;
dkato 0:ee40da884cfc 480 case SYS_ST_PLAY_PREPARE: /* Preparation of the playback */
dkato 0:ee40da884cfc 481 next_stat = state_proc_play_prepare(stat, event, p_ctrl);
dkato 0:ee40da884cfc 482 break;
dkato 0:ee40da884cfc 483 case SYS_ST_PLAY_PREPARE_REQ: /* Holds the stop request until completion */
dkato 0:ee40da884cfc 484 /* of the playback preparation */
dkato 0:ee40da884cfc 485 next_stat = state_proc_play_prepare_req(stat, event, p_ctrl);
dkato 0:ee40da884cfc 486 break;
dkato 0:ee40da884cfc 487 case SYS_ST_PLAY: /* Play */
dkato 0:ee40da884cfc 488 case SYS_ST_PAUSE: /* Pause */
dkato 0:ee40da884cfc 489 next_stat = state_proc_play_pause(stat, event, p_ctrl);
dkato 0:ee40da884cfc 490 break;
dkato 0:ee40da884cfc 491 case SYS_ST_STOP_PREPARE: /* Preparation of the stop */
dkato 0:ee40da884cfc 492 next_stat = state_proc_stop_prepare(stat, event, p_ctrl);
dkato 0:ee40da884cfc 493 break;
dkato 0:ee40da884cfc 494 case SYS_ST_STOP_PREPARE_REQ: /* Holds the playback request until completion */
dkato 0:ee40da884cfc 495 /* of the stop preparation */
dkato 0:ee40da884cfc 496 next_stat = state_proc_stop_prepare_req(stat, event, p_ctrl);
dkato 0:ee40da884cfc 497 break;
dkato 0:ee40da884cfc 498 default:
dkato 0:ee40da884cfc 499 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 500 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 501 break;
dkato 0:ee40da884cfc 502 }
dkato 0:ee40da884cfc 503 }
dkato 0:ee40da884cfc 504 return next_stat;
dkato 0:ee40da884cfc 505 }
dkato 0:ee40da884cfc 506
dkato 0:ee40da884cfc 507 /** Executes the state transition processing in the state of SYS_ST_WAIT_USB_CONNECT.
dkato 0:ee40da884cfc 508 *
dkato 0:ee40da884cfc 509 * @param stat Status of main thread
dkato 0:ee40da884cfc 510 * @param event Event code of main thread
dkato 0:ee40da884cfc 511 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 512 *
dkato 0:ee40da884cfc 513 * @returns
dkato 0:ee40da884cfc 514 * Next status of main thread
dkato 0:ee40da884cfc 515 */
dkato 0:ee40da884cfc 516 static SYS_STATE state_proc_wait_usb_connect(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 517 {
dkato 0:ee40da884cfc 518 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 519
dkato 0:ee40da884cfc 520 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 521 if (event == SYS_EV_USB_CONNECT) {
dkato 0:ee40da884cfc 522 p_ctrl->usb_ctrl.usb_flag_detach = false;
dkato 0:ee40da884cfc 523 (void) exe_scan_folder_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 524 (void) dsp_notify_print_string(PRINT_MSG_USB_CONNECT);
dkato 0:ee40da884cfc 525 next_stat = SYS_ST_STOP;
dkato 2:d9fca8cd7f03 526 } else if (event == SYS_EV_KEY_HELP) {
dkato 2:d9fca8cd7f03 527 print_help_info();
dkato 0:ee40da884cfc 528 } else {
dkato 0:ee40da884cfc 529 /* DO NOTHING */
dkato 0:ee40da884cfc 530 }
dkato 0:ee40da884cfc 531 }
dkato 0:ee40da884cfc 532 return next_stat;
dkato 0:ee40da884cfc 533 }
dkato 0:ee40da884cfc 534
dkato 0:ee40da884cfc 535 /** Executes the state transition processing in the state of SYS_ST_STOP.
dkato 0:ee40da884cfc 536 *
dkato 0:ee40da884cfc 537 * @param stat Status of main thread
dkato 0:ee40da884cfc 538 * @param event Event code of main thread
dkato 0:ee40da884cfc 539 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 540 *
dkato 0:ee40da884cfc 541 * @returns
dkato 0:ee40da884cfc 542 * Next status of main thread
dkato 0:ee40da884cfc 543 */
dkato 0:ee40da884cfc 544 static SYS_STATE state_proc_stop(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 545 {
dkato 0:ee40da884cfc 546 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 547 bool result;
dkato 0:ee40da884cfc 548
dkato 0:ee40da884cfc 549 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 550 switch (event) {
dkato 0:ee40da884cfc 551 case SYS_EV_KEY_PLAY_PAUSE:
dkato 0:ee40da884cfc 552 print_file_name(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 553 result = exe_open_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 554 if (result == true) {
dkato 0:ee40da884cfc 555 next_stat = SYS_ST_PLAY_PREPARE;
dkato 0:ee40da884cfc 556 }
dkato 0:ee40da884cfc 557 break;
dkato 0:ee40da884cfc 558 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 559 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 560 break;
dkato 2:d9fca8cd7f03 561 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 562 print_help_info();
dkato 2:d9fca8cd7f03 563 break;
dkato 0:ee40da884cfc 564 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 565 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 566 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 567 break;
dkato 0:ee40da884cfc 568 default:
dkato 0:ee40da884cfc 569 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 570 next_stat = stat;
dkato 0:ee40da884cfc 571 break;
dkato 0:ee40da884cfc 572 }
dkato 0:ee40da884cfc 573 }
dkato 0:ee40da884cfc 574 return next_stat;
dkato 0:ee40da884cfc 575 }
dkato 0:ee40da884cfc 576
dkato 0:ee40da884cfc 577 /** Executes the state transition processing in the state of SYS_ST_PLAY_PREPARE.
dkato 0:ee40da884cfc 578 *
dkato 0:ee40da884cfc 579 * @param stat Status of main thread
dkato 0:ee40da884cfc 580 * @param event Event code of main thread
dkato 0:ee40da884cfc 581 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 582 *
dkato 0:ee40da884cfc 583 * @returns
dkato 0:ee40da884cfc 584 * Next status of main thread
dkato 0:ee40da884cfc 585 */
dkato 0:ee40da884cfc 586 static SYS_STATE state_proc_play_prepare(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 587 {
dkato 0:ee40da884cfc 588 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 589 bool result;
dkato 0:ee40da884cfc 590
dkato 0:ee40da884cfc 591 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 592 switch (event) {
dkato 0:ee40da884cfc 593 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 594 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 595 break;
dkato 0:ee40da884cfc 596 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 597 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 598 if (result != true) {
dkato 0:ee40da884cfc 599 /* Selected track was out of the playback range. */
dkato 0:ee40da884cfc 600 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 601 }
dkato 0:ee40da884cfc 602 break;
dkato 0:ee40da884cfc 603 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 604 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 605 if (result != true) {
dkato 0:ee40da884cfc 606 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 607 }
dkato 0:ee40da884cfc 608 break;
dkato 0:ee40da884cfc 609 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 610 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 611 break;
dkato 2:d9fca8cd7f03 612 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 613 print_help_info();
dkato 2:d9fca8cd7f03 614 break;
dkato 0:ee40da884cfc 615 case SYS_EV_DEC_OPEN_COMP:
dkato 0:ee40da884cfc 616 result = is_track_changed(&p_ctrl->play_info);
dkato 0:ee40da884cfc 617 if (result == true) {
dkato 0:ee40da884cfc 618 /* Track was changed during the waiting of callback. */
dkato 0:ee40da884cfc 619 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 620 result = exe_close_proc();
dkato 0:ee40da884cfc 621 if (result == true) {
dkato 0:ee40da884cfc 622 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 623 } else {
dkato 0:ee40da884cfc 624 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 625 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 626 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 627 }
dkato 0:ee40da884cfc 628 } else {
dkato 0:ee40da884cfc 629 print_play_info(&p_ctrl->play_info);
dkato 0:ee40da884cfc 630 result = exe_play_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 631 if (result == true) {
dkato 0:ee40da884cfc 632 next_stat = SYS_ST_PLAY;
dkato 0:ee40da884cfc 633 } else {
dkato 0:ee40da884cfc 634 result = exe_close_proc();
dkato 0:ee40da884cfc 635 if (result == true) {
dkato 0:ee40da884cfc 636 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 637 } else {
dkato 0:ee40da884cfc 638 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 639 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 640 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 641 }
dkato 0:ee40da884cfc 642 }
dkato 0:ee40da884cfc 643 }
dkato 0:ee40da884cfc 644 break;
dkato 0:ee40da884cfc 645 case SYS_EV_DEC_OPEN_COMP_ERR:
dkato 0:ee40da884cfc 646 /* Output error message to PC */
dkato 0:ee40da884cfc 647 (void) dsp_notify_print_string(PRINT_MSG_DECODE_ERR);
dkato 0:ee40da884cfc 648 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 649 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 650 break;
dkato 0:ee40da884cfc 651 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 652 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 653 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 654 break;
dkato 0:ee40da884cfc 655 default:
dkato 0:ee40da884cfc 656 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 657 next_stat = stat;
dkato 0:ee40da884cfc 658 break;
dkato 0:ee40da884cfc 659 }
dkato 0:ee40da884cfc 660 }
dkato 0:ee40da884cfc 661 return next_stat;
dkato 0:ee40da884cfc 662 }
dkato 0:ee40da884cfc 663
dkato 0:ee40da884cfc 664 /** Executes the state transition processing in the state of SYS_ST_PLAY_PREPARE_REQ.
dkato 0:ee40da884cfc 665 *
dkato 0:ee40da884cfc 666 * @param stat Status of main thread
dkato 0:ee40da884cfc 667 * @param event Event code of main thread
dkato 0:ee40da884cfc 668 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 669 *
dkato 0:ee40da884cfc 670 * @returns
dkato 0:ee40da884cfc 671 * Next status of main thread
dkato 0:ee40da884cfc 672 */
dkato 0:ee40da884cfc 673 static SYS_STATE state_proc_play_prepare_req(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 674 {
dkato 0:ee40da884cfc 675 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 676 bool result;
dkato 0:ee40da884cfc 677
dkato 0:ee40da884cfc 678 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 679 switch (event) {
dkato 0:ee40da884cfc 680 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 681 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 682 break;
dkato 2:d9fca8cd7f03 683 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 684 print_help_info();
dkato 2:d9fca8cd7f03 685 break;
dkato 0:ee40da884cfc 686 case SYS_EV_DEC_OPEN_COMP:
dkato 0:ee40da884cfc 687 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 688 result = exe_close_proc();
dkato 0:ee40da884cfc 689 if (result == true) {
dkato 0:ee40da884cfc 690 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 691 } else {
dkato 0:ee40da884cfc 692 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 693 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 694 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 695 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 696 } else {
dkato 0:ee40da884cfc 697 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 698 }
dkato 0:ee40da884cfc 699 }
dkato 0:ee40da884cfc 700 break;
dkato 0:ee40da884cfc 701 case SYS_EV_DEC_OPEN_COMP_ERR:
dkato 0:ee40da884cfc 702 /* Output error message to PC */
dkato 0:ee40da884cfc 703 (void) dsp_notify_print_string(PRINT_MSG_DECODE_ERR);
dkato 0:ee40da884cfc 704 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 705 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 706 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 707 } else {
dkato 0:ee40da884cfc 708 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 709 }
dkato 0:ee40da884cfc 710 break;
dkato 0:ee40da884cfc 711 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 712 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 713 break;
dkato 0:ee40da884cfc 714 default:
dkato 0:ee40da884cfc 715 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 716 next_stat = stat;
dkato 0:ee40da884cfc 717 break;
dkato 0:ee40da884cfc 718 }
dkato 0:ee40da884cfc 719 }
dkato 0:ee40da884cfc 720 return next_stat;
dkato 0:ee40da884cfc 721 }
dkato 0:ee40da884cfc 722
dkato 0:ee40da884cfc 723 /** Executes the state transition processing in the state of SYS_ST_PLAY / SYS_ST_PAUSE.
dkato 0:ee40da884cfc 724 *
dkato 0:ee40da884cfc 725 * @param stat Status of main thread
dkato 0:ee40da884cfc 726 * @param event Event code of main thread
dkato 0:ee40da884cfc 727 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 728 *
dkato 0:ee40da884cfc 729 * @returns
dkato 0:ee40da884cfc 730 * Next status of main thread
dkato 0:ee40da884cfc 731 */
dkato 0:ee40da884cfc 732 static SYS_STATE state_proc_play_pause(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 733 {
dkato 0:ee40da884cfc 734 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 735 bool result;
dkato 0:ee40da884cfc 736
dkato 0:ee40da884cfc 737 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 738 switch (event) {
dkato 0:ee40da884cfc 739 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 740 result = exe_stop_proc();
dkato 0:ee40da884cfc 741 if (result == true) {
dkato 0:ee40da884cfc 742 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 743 }
dkato 0:ee40da884cfc 744 break;
dkato 0:ee40da884cfc 745 case SYS_EV_KEY_PLAY_PAUSE:
dkato 0:ee40da884cfc 746 if (stat == SYS_ST_PLAY) {
dkato 0:ee40da884cfc 747 (void) exe_pause_on_proc();
dkato 0:ee40da884cfc 748 } else {
dkato 0:ee40da884cfc 749 (void) exe_pause_off_proc();
dkato 0:ee40da884cfc 750 }
dkato 0:ee40da884cfc 751 break;
dkato 0:ee40da884cfc 752 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 753 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 754 result = exe_stop_proc();
dkato 0:ee40da884cfc 755 if (result == true) {
dkato 0:ee40da884cfc 756 if (event == SYS_EV_KEY_PREV) {
dkato 0:ee40da884cfc 757 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 758 } else {
dkato 0:ee40da884cfc 759 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 760 }
dkato 0:ee40da884cfc 761 if (result == true) {
dkato 0:ee40da884cfc 762 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 763 } else {
dkato 0:ee40da884cfc 764 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 765 }
dkato 0:ee40da884cfc 766 }
dkato 0:ee40da884cfc 767 break;
dkato 0:ee40da884cfc 768 case SYS_EV_KEY_PLAYINFO:
dkato 0:ee40da884cfc 769 print_play_info(&p_ctrl->play_info);
dkato 0:ee40da884cfc 770 break;
dkato 0:ee40da884cfc 771 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 772 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 773 break;
dkato 2:d9fca8cd7f03 774 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 775 print_help_info();
dkato 2:d9fca8cd7f03 776 break;
dkato 0:ee40da884cfc 777 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 778 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 779 result = exe_close_proc();
dkato 0:ee40da884cfc 780 if (result == true) {
dkato 0:ee40da884cfc 781 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 782 if (result == true) {
dkato 0:ee40da884cfc 783 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 784 } else {
dkato 0:ee40da884cfc 785 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 786 }
dkato 0:ee40da884cfc 787 } else {
dkato 0:ee40da884cfc 788 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 789 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 790 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 791 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 792 } else {
dkato 0:ee40da884cfc 793 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 794 }
dkato 0:ee40da884cfc 795 }
dkato 0:ee40da884cfc 796 break;
dkato 0:ee40da884cfc 797 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 798 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 799 next_stat = SYS_ST_PLAY;
dkato 0:ee40da884cfc 800 break;
dkato 0:ee40da884cfc 801 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 802 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 803 next_stat = SYS_ST_PAUSE;
dkato 0:ee40da884cfc 804 break;
dkato 0:ee40da884cfc 805 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 806 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 807 result = exe_stop_proc();
dkato 0:ee40da884cfc 808 if (result == true) {
dkato 0:ee40da884cfc 809 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 810 } else {
dkato 0:ee40da884cfc 811 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 812 /* In this case, main thread wait the notification of the stop status. */
dkato 0:ee40da884cfc 813 /* An error will occur by the disconnection of USB memory. */
dkato 0:ee40da884cfc 814 }
dkato 0:ee40da884cfc 815 break;
dkato 0:ee40da884cfc 816 default:
dkato 0:ee40da884cfc 817 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 818 next_stat = stat;
dkato 0:ee40da884cfc 819 break;
dkato 0:ee40da884cfc 820 }
dkato 0:ee40da884cfc 821 }
dkato 0:ee40da884cfc 822 return next_stat;
dkato 0:ee40da884cfc 823 }
dkato 0:ee40da884cfc 824
dkato 0:ee40da884cfc 825 /** Executes the state transition processing in the state of SYS_ST_STOP_PREPARE.
dkato 0:ee40da884cfc 826 *
dkato 0:ee40da884cfc 827 * @param stat Status of main thread
dkato 0:ee40da884cfc 828 * @param event Event code of main thread
dkato 0:ee40da884cfc 829 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 830 *
dkato 0:ee40da884cfc 831 * @returns
dkato 0:ee40da884cfc 832 * Next status of main thread
dkato 0:ee40da884cfc 833 */
dkato 0:ee40da884cfc 834 static SYS_STATE state_proc_stop_prepare(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 835 {
dkato 0:ee40da884cfc 836 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 837 bool result;
dkato 0:ee40da884cfc 838
dkato 0:ee40da884cfc 839 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 840 switch (event) {
dkato 0:ee40da884cfc 841 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 842 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 843 break;
dkato 2:d9fca8cd7f03 844 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 845 print_help_info();
dkato 2:d9fca8cd7f03 846 break;
dkato 0:ee40da884cfc 847 case SYS_EV_DEC_CLOSE_COMP:
dkato 0:ee40da884cfc 848 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 849 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 850 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 851 } else {
dkato 0:ee40da884cfc 852 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 853 }
dkato 0:ee40da884cfc 854 break;
dkato 0:ee40da884cfc 855 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 856 result = exe_close_proc();
dkato 0:ee40da884cfc 857 if (result != true) {
dkato 0:ee40da884cfc 858 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 859 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 860 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 861 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 862 } else {
dkato 0:ee40da884cfc 863 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 864 }
dkato 0:ee40da884cfc 865 }
dkato 0:ee40da884cfc 866 break;
dkato 0:ee40da884cfc 867 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 868 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 869 break;
dkato 0:ee40da884cfc 870 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 871 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 872 break;
dkato 0:ee40da884cfc 873 default:
dkato 0:ee40da884cfc 874 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 875 next_stat = stat;
dkato 0:ee40da884cfc 876 break;
dkato 0:ee40da884cfc 877 }
dkato 0:ee40da884cfc 878 }
dkato 0:ee40da884cfc 879 return next_stat;
dkato 0:ee40da884cfc 880 }
dkato 0:ee40da884cfc 881
dkato 0:ee40da884cfc 882 /** Executes the state transition processing in the state of SYS_ST_STOP_PREPARE_REQ.
dkato 0:ee40da884cfc 883 *
dkato 0:ee40da884cfc 884 * @param stat Status of main thread
dkato 0:ee40da884cfc 885 * @param event Event code of main thread
dkato 0:ee40da884cfc 886 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 887 *
dkato 0:ee40da884cfc 888 * @returns
dkato 0:ee40da884cfc 889 * Next status of main thread
dkato 0:ee40da884cfc 890 */
dkato 0:ee40da884cfc 891 static SYS_STATE state_proc_stop_prepare_req(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 892 {
dkato 0:ee40da884cfc 893 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 894 bool result;
dkato 0:ee40da884cfc 895
dkato 0:ee40da884cfc 896 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 897 switch (event) {
dkato 0:ee40da884cfc 898 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 899 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 900 break;
dkato 0:ee40da884cfc 901 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 902 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 903 if (result != true) {
dkato 0:ee40da884cfc 904 /* Selected track was out of the playback range. */
dkato 0:ee40da884cfc 905 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 906 }
dkato 0:ee40da884cfc 907 break;
dkato 0:ee40da884cfc 908 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 909 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 910 if (result != true) {
dkato 0:ee40da884cfc 911 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 912 }
dkato 0:ee40da884cfc 913 break;
dkato 0:ee40da884cfc 914 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 915 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 916 break;
dkato 2:d9fca8cd7f03 917 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 918 print_help_info();
dkato 2:d9fca8cd7f03 919 break;
dkato 0:ee40da884cfc 920 case SYS_EV_DEC_CLOSE_COMP:
dkato 0:ee40da884cfc 921 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 922 print_file_name(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 923 result = exe_open_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 924 if (result == true) {
dkato 0:ee40da884cfc 925 next_stat = SYS_ST_PLAY_PREPARE;
dkato 0:ee40da884cfc 926 } else {
dkato 0:ee40da884cfc 927 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 928 }
dkato 0:ee40da884cfc 929 break;
dkato 0:ee40da884cfc 930 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 931 result = exe_close_proc();
dkato 0:ee40da884cfc 932 if (result != true) {
dkato 0:ee40da884cfc 933 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 934 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 935 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 936 }
dkato 0:ee40da884cfc 937 break;
dkato 0:ee40da884cfc 938 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 939 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 940 break;
dkato 0:ee40da884cfc 941 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 942 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 943 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 944 break;
dkato 0:ee40da884cfc 945 default:
dkato 0:ee40da884cfc 946 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 947 next_stat = stat;
dkato 0:ee40da884cfc 948 break;
dkato 0:ee40da884cfc 949 }
dkato 0:ee40da884cfc 950 }
dkato 0:ee40da884cfc 951 return next_stat;
dkato 0:ee40da884cfc 952 }
dkato 0:ee40da884cfc 953
dkato 0:ee40da884cfc 954 /** Executes the scan of the folder structure
dkato 0:ee40da884cfc 955 *
dkato 0:ee40da884cfc 956 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 957 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 958 *
dkato 0:ee40da884cfc 959 * @returns
dkato 0:ee40da884cfc 960 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 961 */
dkato 0:ee40da884cfc 962 static bool exe_scan_folder_proc(play_info_t * const p_info, fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 963 {
dkato 0:ee40da884cfc 964 bool ret = false;
dkato 0:ee40da884cfc 965
dkato 0:ee40da884cfc 966 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 967 (void) fid_scan_folder_struct(p_data);
dkato 0:ee40da884cfc 968 p_info->track_id = TRACK_ID_MIN;
dkato 0:ee40da884cfc 969 ret = true;
dkato 0:ee40da884cfc 970 }
dkato 0:ee40da884cfc 971 return ret;
dkato 0:ee40da884cfc 972 }
dkato 0:ee40da884cfc 973
dkato 0:ee40da884cfc 974 /** Executes the opening process
dkato 0:ee40da884cfc 975 *
dkato 0:ee40da884cfc 976 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 977 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 978 *
dkato 0:ee40da884cfc 979 * @returns
dkato 0:ee40da884cfc 980 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 981 */
dkato 0:ee40da884cfc 982 static bool exe_open_proc(play_info_t * const p_info, fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 983 {
dkato 0:ee40da884cfc 984 bool ret = false;
dkato 0:ee40da884cfc 985 bool result;
dkato 0:ee40da884cfc 986 FILE *fp;
dkato 0:ee40da884cfc 987 uint32_t total_trk;
dkato 0:ee40da884cfc 988
dkato 0:ee40da884cfc 989 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 990 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 991 if (p_info->track_id < total_trk) {
dkato 0:ee40da884cfc 992 fp = fid_open_track(p_data, p_info->track_id);
dkato 0:ee40da884cfc 993 if (fp != NULL) {
dkato 0:ee40da884cfc 994 result = dec_open(fp, &open_callback);
dkato 0:ee40da884cfc 995 if (result == true) {
dkato 0:ee40da884cfc 996 /* Executes fid_close_track() in exe_end_proc(). */
dkato 0:ee40da884cfc 997 p_info->p_file_handle = fp;
dkato 0:ee40da884cfc 998 p_info->open_track_id = p_info->track_id;
dkato 0:ee40da884cfc 999 ret = true;
dkato 0:ee40da884cfc 1000 } else {
dkato 0:ee40da884cfc 1001 /* The opening of the decoder was failure. */
dkato 0:ee40da884cfc 1002 fid_close_track(fp);
dkato 0:ee40da884cfc 1003 p_info->p_file_handle = NULL;
dkato 0:ee40da884cfc 1004 }
dkato 0:ee40da884cfc 1005 }
dkato 0:ee40da884cfc 1006 if (ret != true) {
dkato 0:ee40da884cfc 1007 print_play_time(p_info);
dkato 0:ee40da884cfc 1008 (void) dsp_notify_print_string(PRINT_MSG_OPEN_ERR);
dkato 0:ee40da884cfc 1009 /* Tries to open the next file. */
dkato 0:ee40da884cfc 1010 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1011 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 1012 }
dkato 0:ee40da884cfc 1013 }
dkato 0:ee40da884cfc 1014 }
dkato 0:ee40da884cfc 1015 return ret;
dkato 0:ee40da884cfc 1016 }
dkato 0:ee40da884cfc 1017
dkato 0:ee40da884cfc 1018 /** Executes the starting process of the playback
dkato 0:ee40da884cfc 1019 *
dkato 0:ee40da884cfc 1020 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1021 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1022 *
dkato 0:ee40da884cfc 1023 * @returns
dkato 0:ee40da884cfc 1024 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1025 */
dkato 0:ee40da884cfc 1026 static bool exe_play_proc(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1027 {
dkato 0:ee40da884cfc 1028 bool ret = false;
dkato 0:ee40da884cfc 1029 bool result;
dkato 0:ee40da884cfc 1030
dkato 0:ee40da884cfc 1031 if (p_info != NULL) {
dkato 0:ee40da884cfc 1032 result = dec_play();
dkato 0:ee40da884cfc 1033 if (result == true) {
dkato 0:ee40da884cfc 1034 ret = true;
dkato 0:ee40da884cfc 1035 } else {
dkato 0:ee40da884cfc 1036 /* The starting of the playback was failure. */
dkato 0:ee40da884cfc 1037 print_play_time(p_info);
dkato 0:ee40da884cfc 1038 /* Tries to open the next file. */
dkato 0:ee40da884cfc 1039 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1040 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 1041 }
dkato 0:ee40da884cfc 1042 }
dkato 0:ee40da884cfc 1043 return ret;
dkato 0:ee40da884cfc 1044 }
dkato 0:ee40da884cfc 1045
dkato 0:ee40da884cfc 1046 /** Executes the starting process of the pause
dkato 0:ee40da884cfc 1047 *
dkato 0:ee40da884cfc 1048 * @returns
dkato 0:ee40da884cfc 1049 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1050 */
dkato 0:ee40da884cfc 1051 static bool exe_pause_on_proc(void)
dkato 0:ee40da884cfc 1052 {
dkato 0:ee40da884cfc 1053 bool ret;
dkato 0:ee40da884cfc 1054
dkato 0:ee40da884cfc 1055 ret = dec_pause_on();
dkato 0:ee40da884cfc 1056 return ret;
dkato 0:ee40da884cfc 1057 }
dkato 0:ee40da884cfc 1058
dkato 0:ee40da884cfc 1059 /** Executes the cancel process of the pause
dkato 0:ee40da884cfc 1060 *
dkato 0:ee40da884cfc 1061 * @returns
dkato 0:ee40da884cfc 1062 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1063 */
dkato 0:ee40da884cfc 1064 static bool exe_pause_off_proc(void)
dkato 0:ee40da884cfc 1065 {
dkato 0:ee40da884cfc 1066 bool ret;
dkato 0:ee40da884cfc 1067
dkato 0:ee40da884cfc 1068 ret = dec_pause_off();
dkato 0:ee40da884cfc 1069 return ret;
dkato 0:ee40da884cfc 1070 }
dkato 0:ee40da884cfc 1071
dkato 0:ee40da884cfc 1072 /** Executes the stop process of the playback
dkato 0:ee40da884cfc 1073 *
dkato 0:ee40da884cfc 1074 * @returns
dkato 0:ee40da884cfc 1075 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1076 */
dkato 0:ee40da884cfc 1077 static bool exe_stop_proc(void)
dkato 0:ee40da884cfc 1078 {
dkato 0:ee40da884cfc 1079 bool ret;
dkato 0:ee40da884cfc 1080
dkato 0:ee40da884cfc 1081 ret = dec_stop();
dkato 0:ee40da884cfc 1082 return ret;
dkato 0:ee40da884cfc 1083 }
dkato 0:ee40da884cfc 1084
dkato 0:ee40da884cfc 1085 /** Executes the closing process
dkato 0:ee40da884cfc 1086 *
dkato 0:ee40da884cfc 1087 * @returns
dkato 0:ee40da884cfc 1088 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1089 */
dkato 0:ee40da884cfc 1090 static bool exe_close_proc(void)
dkato 0:ee40da884cfc 1091 {
dkato 0:ee40da884cfc 1092 bool ret;
dkato 0:ee40da884cfc 1093
dkato 0:ee40da884cfc 1094 ret = dec_close(&close_callback);
dkato 0:ee40da884cfc 1095 return ret;
dkato 0:ee40da884cfc 1096 }
dkato 0:ee40da884cfc 1097
dkato 0:ee40da884cfc 1098 /** Executes the end process
dkato 0:ee40da884cfc 1099 *
dkato 0:ee40da884cfc 1100 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1101 */
dkato 0:ee40da884cfc 1102 static void exe_end_proc(play_info_t * const p_info)
dkato 0:ee40da884cfc 1103 {
dkato 0:ee40da884cfc 1104 if (p_info != NULL) {
dkato 0:ee40da884cfc 1105 fid_close_track(p_info->p_file_handle);
dkato 0:ee40da884cfc 1106 p_info->p_file_handle = NULL;
dkato 0:ee40da884cfc 1107 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1108 }
dkato 0:ee40da884cfc 1109 }
dkato 0:ee40da884cfc 1110
dkato 0:ee40da884cfc 1111 /** Checks the track change
dkato 0:ee40da884cfc 1112 *
dkato 0:ee40da884cfc 1113 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1114 *
dkato 0:ee40da884cfc 1115 * @returns
dkato 0:ee40da884cfc 1116 * Results of check.
dkato 0:ee40da884cfc 1117 */
dkato 0:ee40da884cfc 1118 static bool is_track_changed(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1119 {
dkato 0:ee40da884cfc 1120 bool ret = false;
dkato 0:ee40da884cfc 1121
dkato 0:ee40da884cfc 1122 if (p_info != NULL) {
dkato 0:ee40da884cfc 1123 if (p_info->track_id != p_info->open_track_id) {
dkato 0:ee40da884cfc 1124 ret = true;
dkato 0:ee40da884cfc 1125 }
dkato 0:ee40da884cfc 1126 }
dkato 0:ee40da884cfc 1127 return ret;
dkato 0:ee40da884cfc 1128 }
dkato 0:ee40da884cfc 1129
dkato 0:ee40da884cfc 1130 /** Changes the repeat mode
dkato 0:ee40da884cfc 1131 *
dkato 0:ee40da884cfc 1132 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1133 */
dkato 0:ee40da884cfc 1134 static void change_repeat_mode(play_info_t * const p_info)
dkato 0:ee40da884cfc 1135 {
dkato 0:ee40da884cfc 1136 if (p_info != NULL) {
dkato 0:ee40da884cfc 1137 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1138 p_info->repeat_mode = false;
dkato 0:ee40da884cfc 1139 } else {
dkato 0:ee40da884cfc 1140 p_info->repeat_mode = true;
dkato 0:ee40da884cfc 1141 }
dkato 0:ee40da884cfc 1142 (void) dsp_notify_play_mode(p_info->repeat_mode);
dkato 0:ee40da884cfc 1143 }
dkato 0:ee40da884cfc 1144 }
dkato 0:ee40da884cfc 1145
dkato 0:ee40da884cfc 1146 /** Changes the next track
dkato 0:ee40da884cfc 1147 *
dkato 0:ee40da884cfc 1148 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1149 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1150 *
dkato 0:ee40da884cfc 1151 * @returns
dkato 0:ee40da884cfc 1152 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1153 */
dkato 0:ee40da884cfc 1154 static bool change_next_track(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1155 {
dkato 0:ee40da884cfc 1156 bool ret = false;
dkato 0:ee40da884cfc 1157 uint32_t next_trk;
dkato 0:ee40da884cfc 1158 uint32_t total_trk;
dkato 0:ee40da884cfc 1159
dkato 0:ee40da884cfc 1160 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1161 next_trk = p_info->track_id + 1u;
dkato 0:ee40da884cfc 1162 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1163 if (next_trk < total_trk) {
dkato 0:ee40da884cfc 1164 ret = true;
dkato 0:ee40da884cfc 1165 } else {
dkato 0:ee40da884cfc 1166 next_trk = 0;
dkato 0:ee40da884cfc 1167 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1168 ret = true;
dkato 0:ee40da884cfc 1169 }
dkato 0:ee40da884cfc 1170 }
dkato 0:ee40da884cfc 1171 p_info->track_id = next_trk;
dkato 0:ee40da884cfc 1172 }
dkato 0:ee40da884cfc 1173 return ret;
dkato 0:ee40da884cfc 1174 }
dkato 0:ee40da884cfc 1175
dkato 0:ee40da884cfc 1176 /** Changes the previous track
dkato 0:ee40da884cfc 1177 *
dkato 0:ee40da884cfc 1178 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1179 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1180 *
dkato 0:ee40da884cfc 1181 * @returns
dkato 0:ee40da884cfc 1182 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1183 */
dkato 0:ee40da884cfc 1184 static bool change_prev_track(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1185 {
dkato 0:ee40da884cfc 1186 bool ret = false;
dkato 0:ee40da884cfc 1187 uint32_t prev_trk;
dkato 0:ee40da884cfc 1188 uint32_t total_trk;
dkato 0:ee40da884cfc 1189
dkato 0:ee40da884cfc 1190 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1191 prev_trk = p_info->track_id - 1u;
dkato 0:ee40da884cfc 1192 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1193 if (prev_trk < total_trk) {
dkato 0:ee40da884cfc 1194 ret = true;
dkato 0:ee40da884cfc 1195 } else {
dkato 0:ee40da884cfc 1196 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1197 if (total_trk > 0u) {
dkato 0:ee40da884cfc 1198 ret = true;
dkato 0:ee40da884cfc 1199 prev_trk = total_trk - 1u;
dkato 0:ee40da884cfc 1200 } else {
dkato 0:ee40da884cfc 1201 prev_trk = 0u;
dkato 0:ee40da884cfc 1202 }
dkato 0:ee40da884cfc 1203 } else {
dkato 0:ee40da884cfc 1204 prev_trk = 0u;
dkato 0:ee40da884cfc 1205 }
dkato 0:ee40da884cfc 1206 }
dkato 0:ee40da884cfc 1207 p_info->track_id = prev_trk;
dkato 0:ee40da884cfc 1208 }
dkato 0:ee40da884cfc 1209 return ret;
dkato 0:ee40da884cfc 1210 }
dkato 0:ee40da884cfc 1211 /** Prints the playback information of the playback file
dkato 0:ee40da884cfc 1212 *
dkato 0:ee40da884cfc 1213 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1214 */
dkato 0:ee40da884cfc 1215 static void print_play_info(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1216 {
dkato 0:ee40da884cfc 1217 uint32_t trk_id;
dkato 0:ee40da884cfc 1218
dkato 0:ee40da884cfc 1219 if (p_info != NULL) {
dkato 0:ee40da884cfc 1220 trk_id = convert_track_id(p_info->track_id);
dkato 0:ee40da884cfc 1221 (void) dsp_notify_play_info(trk_id, p_info->sample_rate, p_info->channel_num);
dkato 0:ee40da884cfc 1222 }
dkato 0:ee40da884cfc 1223 }
dkato 0:ee40da884cfc 1224
dkato 0:ee40da884cfc 1225 /** Prints the information of the playback time
dkato 0:ee40da884cfc 1226 *
dkato 0:ee40da884cfc 1227 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1228 */
dkato 0:ee40da884cfc 1229 static void print_play_time(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1230 {
dkato 0:ee40da884cfc 1231 uint32_t trk_id;
dkato 0:ee40da884cfc 1232
dkato 0:ee40da884cfc 1233 if (p_info != NULL) {
dkato 0:ee40da884cfc 1234 trk_id = convert_track_id(p_info->track_id);
dkato 0:ee40da884cfc 1235 (void) dsp_notify_play_time(p_info->play_stat, trk_id,
dkato 0:ee40da884cfc 1236 p_info->play_time, p_info->total_time);
dkato 0:ee40da884cfc 1237 }
dkato 0:ee40da884cfc 1238 }
dkato 0:ee40da884cfc 1239
dkato 0:ee40da884cfc 1240 /** Prints the file name of the playback file
dkato 0:ee40da884cfc 1241 *
dkato 0:ee40da884cfc 1242 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1243 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1244 */
dkato 0:ee40da884cfc 1245 static void print_file_name(const play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1246 {
dkato 0:ee40da884cfc 1247 const char_t *p_path;
dkato 0:ee40da884cfc 1248 uint32_t trk_id;
dkato 0:ee40da884cfc 1249 uint32_t trk_total;
dkato 0:ee40da884cfc 1250
dkato 0:ee40da884cfc 1251 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1252 trk_id = p_info->track_id;
dkato 0:ee40da884cfc 1253 trk_total = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1254 if (trk_id < trk_total) {
dkato 0:ee40da884cfc 1255 p_path = fid_get_track_name(p_data, trk_id);
dkato 0:ee40da884cfc 1256 (void) dsp_notify_file_name(p_path);
dkato 0:ee40da884cfc 1257 }
dkato 0:ee40da884cfc 1258 }
dkato 0:ee40da884cfc 1259 }
dkato 0:ee40da884cfc 1260
dkato 2:d9fca8cd7f03 1261 /** Prints the command help information
dkato 2:d9fca8cd7f03 1262 *
dkato 2:d9fca8cd7f03 1263 */
dkato 2:d9fca8cd7f03 1264 static void print_help_info(void)
dkato 2:d9fca8cd7f03 1265 {
dkato 2:d9fca8cd7f03 1266 (void) dsp_req_help();
dkato 2:d9fca8cd7f03 1267 }
dkato 2:d9fca8cd7f03 1268
dkato 0:ee40da884cfc 1269 /** Converts the track ID of main thread into the track ID of display thread
dkato 0:ee40da884cfc 1270 *
dkato 0:ee40da884cfc 1271 * @param trk_id Track ID of main thread
dkato 0:ee40da884cfc 1272 *
dkato 0:ee40da884cfc 1273 * @returns
dkato 0:ee40da884cfc 1274 * Track ID of display thread
dkato 0:ee40da884cfc 1275 */
dkato 0:ee40da884cfc 1276 static uint32_t convert_track_id(const uint32_t trk_id)
dkato 0:ee40da884cfc 1277 {
dkato 0:ee40da884cfc 1278 uint32_t ret = 0u;
dkato 0:ee40da884cfc 1279
dkato 0:ee40da884cfc 1280 /* Track ID of main thread begins with 0. */
dkato 0:ee40da884cfc 1281 /* Converts the track ID of main thread into the track ID */
dkato 0:ee40da884cfc 1282 /* of the display thread beginning with 1. */
dkato 0:ee40da884cfc 1283 if (trk_id < SYS_MAX_TRACK_NUM) {
dkato 0:ee40da884cfc 1284 ret = trk_id + 1u;
dkato 0:ee40da884cfc 1285 }
dkato 0:ee40da884cfc 1286 return ret;
dkato 0:ee40da884cfc 1287 }
dkato 0:ee40da884cfc 1288
dkato 0:ee40da884cfc 1289 /** Sends the mail to main thread
dkato 0:ee40da884cfc 1290 *
dkato 0:ee40da884cfc 1291 * @param mail_id Mail ID
dkato 0:ee40da884cfc 1292 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 1293 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 1294 * @param param2 Parameter 2 of this mail
dkato 0:ee40da884cfc 1295 *
dkato 0:ee40da884cfc 1296 * @returns
dkato 0:ee40da884cfc 1297 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1298 */
dkato 0:ee40da884cfc 1299 static bool send_mail(const SYS_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 1300 const uint32_t param1, const uint32_t param2)
dkato 0:ee40da884cfc 1301 {
dkato 0:ee40da884cfc 1302 bool ret = false;
dkato 0:ee40da884cfc 1303 osStatus stat;
dkato 0:ee40da884cfc 1304 sys_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 1305
dkato 0:ee40da884cfc 1306 if (p_mail != NULL) {
dkato 0:ee40da884cfc 1307 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 1308 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 1309 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 1310 p_mail->param[MAIL_PARAM2] = param2;
dkato 0:ee40da884cfc 1311 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 1312 if (stat == osOK) {
dkato 0:ee40da884cfc 1313 ret = true;
dkato 0:ee40da884cfc 1314 } else {
dkato 0:ee40da884cfc 1315 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 1316 }
dkato 0:ee40da884cfc 1317 }
dkato 0:ee40da884cfc 1318 return ret;
dkato 0:ee40da884cfc 1319 }
dkato 0:ee40da884cfc 1320
dkato 0:ee40da884cfc 1321 /** Receives the mail to main thread
dkato 0:ee40da884cfc 1322 *
dkato 0:ee40da884cfc 1323 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 1324 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 1325 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 1326 * @param p_param2 Pointer to the variable to store the parameter 2 of this mail
dkato 0:ee40da884cfc 1327 *
dkato 0:ee40da884cfc 1328 * @returns
dkato 0:ee40da884cfc 1329 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1330 */
dkato 0:ee40da884cfc 1331 static bool recv_mail(SYS_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 1332 uint32_t * const p_param1, uint32_t * const p_param2)
dkato 0:ee40da884cfc 1333 {
dkato 0:ee40da884cfc 1334 bool ret = false;
dkato 0:ee40da884cfc 1335 osEvent evt;
dkato 0:ee40da884cfc 1336 sys_mail_t *p_mail;
dkato 0:ee40da884cfc 1337
dkato 0:ee40da884cfc 1338 if ((p_mail_id != NULL) && (p_param0 != NULL) &&
dkato 0:ee40da884cfc 1339 (p_param1 != NULL) && (p_param2 != NULL)) {
dkato 0:ee40da884cfc 1340 evt = mail_box.get(RECV_MAIL_TIMEOUT_MS);
dkato 0:ee40da884cfc 1341 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 1342 p_mail = (sys_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 1343 if (p_mail != NULL) {
dkato 0:ee40da884cfc 1344 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 1345 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 1346 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 1347 *p_param2 = p_mail->param[MAIL_PARAM2];
dkato 0:ee40da884cfc 1348 ret = true;
dkato 0:ee40da884cfc 1349 }
dkato 0:ee40da884cfc 1350 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 1351 }
dkato 0:ee40da884cfc 1352 }
dkato 0:ee40da884cfc 1353 return ret;
dkato 0:ee40da884cfc 1354 }