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

Dependencies:   GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom

Fork of GR-PEACH_Audio_Playback_Sample by Renesas

Note

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

Introduction

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

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/1050186/lcd_figure1_1.png

1.2 Pin Definitions

Table 1.1 shows the pins used in this sample code.

/media/uploads/1050186/lcd_table1_1.png

2. Sample Code Operating Environment

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

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

2.1 Operating Environment

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

/media/uploads/1050186/lcd_figure2_1.png

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

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

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

/media/uploads/1050186/lcd_table2_1.png

2.2 List of User Operations

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

/media/uploads/1050186/lcd_table2_2.png

3. Function Outline

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

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

3.1 Playback Control

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

3.2 Trick Play Control

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

3.3 How to see Song Information

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

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How to analyze the folder structure in USB stick

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

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

4.1 Serial Communication Setting

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

4.2 Necessary modification when using GCC ARM Embedded

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

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

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

  • Before Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

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

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00180000
  RAM_NC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00680000
}
(snip)
Committer:
dkato
Date:
Thu Nov 05 02:46:24 2015 +0000
Revision:
2:d9fca8cd7f03
Parent:
1:315326ec910b
Child:
4:2672de88a46b
The output frequency was changed to 96kHz. The help command was added.

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