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:
Tue Oct 20 10:22:12 2015 +0000
Revision:
1:315326ec910b
Parent:
0:ee40da884cfc
Child:
2:d9fca8cd7f03
Supports revision 5 of "FATFileSystem.lib".
;

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