Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: R_BSP TLV320_RBSP USBHost_custom
display.cpp
00001 /******************************************************************************* 00002 * DISCLAIMER 00003 * This software is supplied by Renesas Electronics Corporation and is only 00004 * intended for use with Renesas products. No other uses are authorized. This 00005 * software is owned by Renesas Electronics Corporation and is protected under 00006 * all applicable laws, including copyright laws. 00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING 00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT 00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. 00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR 00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE 00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00016 * Renesas reserves the right, without notice, to make changes to this software 00017 * and to discontinue the availability of this software. By using this software, 00018 * you agree to the additional terms and conditions found by accessing the 00019 * following link: 00020 * http://www.renesas.com/disclaimer* 00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. 00022 *******************************************************************************/ 00023 00024 #include "mbed.h" 00025 #include "rtos.h" 00026 #include "misratypes.h" 00027 #include "display.h" 00028 #include "disp_term.h" 00029 00030 /*--- Macro definition of mbed-rtos mail ---*/ 00031 #define MAIL_QUEUE_SIZE (12) /* Queue size */ 00032 #define MAIL_PARAM_NUM (64) /* Elements number of mail parameter array */ 00033 00034 /* dsp_mail_t */ 00035 /* mail_id = DSP_MAILID_CYCLE_IND : No parameter */ 00036 00037 /* mail_id = DSP_MAILID_CMD_STR */ 00038 #define MAIL_CMDSTR_FIN_FLG (0) /* Completion status of the input by the command-line */ 00039 #define MAIL_CMDSTR_STR_START (1) /* Start position of input string by the command-line */ 00040 #define MAIL_CMDSTR_STR_SIZE (DSP_CMD_INPT_STR_MAX_LEN) 00041 /* Size of input string by the command-line */ 00042 00043 /* mail_id = DSP_MAILID_PRINT_STR */ 00044 #define MAIL_DISPSTR_STR_START (0) /* Start position of display string */ 00045 #define MAIL_DISPSTR_STR_SIZE (DSP_DISP_STR_MAX_LEN) /* Size of display string */ 00046 00047 /* mail_id = DSP_MAILID_PLAY_TIME */ 00048 #define MAIL_PLAYTIME_STAT (0) /* Playback status */ 00049 #define MAIL_PLAYTIME_TRACK_L (1) /* Track number */ 00050 #define MAIL_PLAYTIME_TRACK_H (2) /* Track number */ 00051 #define MAIL_PLAYTIME_PLAYTIME_L (3) /* Playback time */ 00052 #define MAIL_PLAYTIME_PLAYTIME_M (4) /* Playback time */ 00053 #define MAIL_PLAYTIME_PLAYTIME_H (5) /* Playback time */ 00054 #define MAIL_PLAYTIME_TOTALTIME_L (6) /* Total playback time */ 00055 #define MAIL_PLAYTIME_TOTALTIME_M (7) /* Total playback time */ 00056 #define MAIL_PLAYTIME_TOTALTIME_H (8) /* Total playback time */ 00057 00058 /* mail_id = DSP_MAILID_PLAY_INFO */ 00059 #define MAIL_PLAYINFO_TRACK_L (0) /* Track number */ 00060 #define MAIL_PLAYINFO_TRACK_H (1) /* Track number */ 00061 #define MAIL_PLAYINFO_SAMPFREQ_L (2) /* Sampling frequency */ 00062 #define MAIL_PLAYINFO_SAMPFREQ_M (3) /* Sampling frequency */ 00063 #define MAIL_PLAYINFO_SAMPFREQ_H (4) /* Sampling frequency */ 00064 #define MAIL_PLAYINFO_CHANNEL (5) /* Channel structure */ 00065 00066 /* mail_id = DSP_MAILID_PLAY_MODE */ 00067 #define MAIL_PLAYMODE_REPEAT (0) /* Repeat mode */ 00068 00069 /* mail_id = DSP_MAILID_FILE_NAME */ 00070 #define MAIL_FILENAME_STR_START (0) /* Start position of file name string */ 00071 #define MAIL_FILENAME_STR_SIZE (64) /* Size of file name string */ 00072 00073 /* mail_id = DSP_MAILID_HELP */ 00074 #define MAIL_HELP_PARAM (0) /* No mail parameter to be used */ 00075 00076 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */ 00077 00078 #define BYTE_SHIFT (8u) 00079 #define WORD_SHIFT (16u) 00080 00081 /*--- User defined types of mbed-rtos mail ---*/ 00082 typedef struct { 00083 DSP_MAIL_ID mail_id; 00084 uint8_t param[MAIL_PARAM_NUM]; 00085 } dsp_mail_t; 00086 00087 /* Control data of display thread */ 00088 typedef struct { 00089 dsp_com_ctrl_t com; /* Common data */ 00090 dsp_trm_ctrl_t trm; /* Terminal output module only */ 00091 dsp_tft_ctrl_t tft; /* TFT module only */ 00092 } dsp_ctrl_t; 00093 00094 static Mail<dsp_mail_t, MAIL_QUEUE_SIZE> mail_box; 00095 00096 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl); 00097 static bool send_mail(const dsp_mail_t * const p_data); 00098 static bool recv_mail(dsp_mail_t * const p_data); 00099 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl); 00100 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl); 00101 00102 void dsp_thread(void const *argument) 00103 { 00104 dsp_mail_t recv_data; 00105 bool result; 00106 static dsp_ctrl_t dsp_ctrl; 00107 00108 UNUSED_ARG(argument); 00109 00110 init_ctrl_data(&dsp_ctrl); 00111 dsp_init_term(); 00112 while (1) { 00113 result = recv_mail(&recv_data); 00114 if (result == true) { 00115 result = decode_mail(&recv_data, &dsp_ctrl); 00116 if (result == true) { 00117 /* Executes main function of terminal output module */ 00118 dsp_output_term(recv_data.mail_id, &dsp_ctrl.com, &dsp_ctrl.trm); 00119 /* Clears the one shot data */ 00120 clear_one_shot_data(&dsp_ctrl); 00121 } 00122 } 00123 } 00124 } 00125 00126 bool dsp_notify_play_time(const SYS_PlayStat play_stat, const uint32_t file_no, 00127 const uint32_t play_time, const uint32_t total_time) 00128 { 00129 bool ret; 00130 dsp_mail_t data; 00131 00132 data.mail_id = DSP_MAILID_PLAY_TIME; 00133 data.param[MAIL_PLAYTIME_STAT] = (uint8_t)play_stat; 00134 data.param[MAIL_PLAYTIME_TRACK_L] = (uint8_t)file_no; 00135 data.param[MAIL_PLAYTIME_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT); 00136 data.param[MAIL_PLAYTIME_PLAYTIME_L] = (uint8_t)play_time; 00137 data.param[MAIL_PLAYTIME_PLAYTIME_M] = (uint8_t)(play_time >> BYTE_SHIFT); 00138 data.param[MAIL_PLAYTIME_PLAYTIME_H] = (uint8_t)(play_time >> WORD_SHIFT); 00139 data.param[MAIL_PLAYTIME_TOTALTIME_L] = (uint8_t)total_time; 00140 data.param[MAIL_PLAYTIME_TOTALTIME_M] = (uint8_t)(total_time >> BYTE_SHIFT); 00141 data.param[MAIL_PLAYTIME_TOTALTIME_H] = (uint8_t)(total_time >> WORD_SHIFT); 00142 ret = send_mail(&data); 00143 00144 return ret; 00145 } 00146 00147 bool dsp_notify_play_info(const uint32_t file_no, 00148 const uint32_t sample_freq, const uint32_t channel_num) 00149 { 00150 bool ret; 00151 dsp_mail_t data; 00152 00153 data.mail_id = DSP_MAILID_PLAY_INFO; 00154 data.param[MAIL_PLAYINFO_TRACK_L] = (uint8_t)file_no; 00155 data.param[MAIL_PLAYINFO_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT); 00156 data.param[MAIL_PLAYINFO_SAMPFREQ_L] = (uint8_t)sample_freq; 00157 data.param[MAIL_PLAYINFO_SAMPFREQ_M] = (uint8_t)(sample_freq >> BYTE_SHIFT); 00158 data.param[MAIL_PLAYINFO_SAMPFREQ_H] = (uint8_t)(sample_freq >> WORD_SHIFT); 00159 data.param[MAIL_PLAYINFO_CHANNEL] = (uint8_t)channel_num; 00160 ret = send_mail(&data); 00161 00162 return ret; 00163 } 00164 00165 bool dsp_notify_play_mode(const bool rep_mode) 00166 { 00167 bool ret; 00168 dsp_mail_t data; 00169 00170 data.mail_id = DSP_MAILID_PLAY_MODE; 00171 data.param[MAIL_PLAYMODE_REPEAT] = (uint8_t)rep_mode; 00172 ret = send_mail(&data); 00173 00174 return ret; 00175 } 00176 00177 bool dsp_notify_file_name(const char_t * const p_str) 00178 { 00179 bool ret = false; 00180 dsp_mail_t data; 00181 00182 if (p_str != NULL) { 00183 data.mail_id = DSP_MAILID_FILE_NAME; 00184 (void) memcpy(&data.param[MAIL_FILENAME_STR_START], p_str, MAIL_FILENAME_STR_SIZE); 00185 data.param[(MAIL_FILENAME_STR_START + MAIL_FILENAME_STR_SIZE) - 1] = '\0'; 00186 ret = send_mail(&data); 00187 } 00188 00189 return ret; 00190 } 00191 00192 bool dsp_notify_print_string(const char_t * const p_str) 00193 { 00194 bool ret = false; 00195 dsp_mail_t data; 00196 00197 if (p_str != NULL) { 00198 data.mail_id = DSP_MAILID_PRINT_STR; 00199 (void) memcpy(&data.param[MAIL_DISPSTR_STR_START], p_str, MAIL_DISPSTR_STR_SIZE); 00200 data.param[(MAIL_DISPSTR_STR_START + MAIL_DISPSTR_STR_SIZE) - 1] = '\0'; 00201 ret = send_mail(&data); 00202 } 00203 00204 return ret; 00205 } 00206 00207 bool dsp_notify_input_string(const char_t * const p_str, const bool flag_fin) 00208 { 00209 bool ret = false; 00210 dsp_mail_t data; 00211 00212 if (p_str != NULL) { 00213 data.mail_id = DSP_MAILID_CMD_STR; 00214 data.param[MAIL_CMDSTR_FIN_FLG] = (uint8_t)flag_fin; 00215 (void) memcpy(&data.param[MAIL_CMDSTR_STR_START], p_str, MAIL_CMDSTR_STR_SIZE); 00216 data.param[(MAIL_CMDSTR_STR_START + MAIL_CMDSTR_STR_SIZE) - 1] = '\0'; 00217 ret = send_mail(&data); 00218 } 00219 00220 return ret; 00221 } 00222 00223 bool dsp_req_help(void) 00224 { 00225 bool ret = false; 00226 dsp_mail_t data; 00227 00228 data.mail_id = DSP_MAILID_HELP; 00229 data.param[MAIL_HELP_PARAM] = (uint8_t)MAIL_PARAM_NON; 00230 ret = send_mail(&data); 00231 return ret; 00232 } 00233 00234 /** initialises the control data of the display module 00235 * 00236 * @param p_ctrl Pointer to control data of display module. 00237 */ 00238 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl) 00239 { 00240 if (p_ctrl != NULL) { 00241 /* Initialises the common data of the display module. */ 00242 p_ctrl->com.disp_mode = 0u; 00243 p_ctrl->com.play_stat = SYS_PLAYSTAT_STOP; 00244 p_ctrl->com.track_id = 0u; 00245 p_ctrl->com.play_time = 0u; 00246 p_ctrl->com.total_time = 0u; 00247 p_ctrl->com.samp_freq = 0u; 00248 p_ctrl->com.channel = 0u; 00249 p_ctrl->com.repeat_mode = false; 00250 p_ctrl->com.file_name[0] = '\0'; 00251 p_ctrl->com.dspl_str[0] = '\0'; 00252 00253 /* Initialises the data of the terminal output module. */ 00254 p_ctrl->trm.edge_fin_inpt = false; 00255 p_ctrl->trm.inpt_str[0] = '\0'; 00256 00257 /* Does not initialize the data of TFT module. */ 00258 /* Initial values are different by the display mode. */ 00259 /* Therefore the data of TFT module is initialized by tft_init_proc function. */ 00260 } 00261 } 00262 00263 /** Sends the mail to main thread 00264 * 00265 * @param p_data Pointer to the structure of the data 00266 * 00267 * @returns 00268 * Results of process. true is success. false is failure. 00269 */ 00270 static bool send_mail(const dsp_mail_t * const p_data) 00271 { 00272 bool ret = false; 00273 osStatus stat; 00274 dsp_mail_t *p_mail; 00275 00276 if (p_data != NULL) { 00277 p_mail = mail_box.alloc(); 00278 if (p_mail != NULL) { 00279 *p_mail = *p_data; 00280 stat = mail_box.put(p_mail); 00281 if (stat == osOK) { 00282 ret = true; 00283 } else { 00284 (void) mail_box.free(p_mail); 00285 } 00286 } 00287 } 00288 return ret; 00289 } 00290 00291 /** Receives the mail to main thread 00292 * 00293 * @param p_data Pointer to the structure of the data 00294 * 00295 * @returns 00296 * Results of process. true is success. false is failure. 00297 */ 00298 static bool recv_mail(dsp_mail_t * const p_data) 00299 { 00300 bool ret = false; 00301 osEvent evt; 00302 dsp_mail_t *p_mail; 00303 00304 if (p_data != NULL) { 00305 evt = mail_box.get(); 00306 if (evt.status == osEventMail) { 00307 p_mail = (dsp_mail_t *)evt.value.p; 00308 if (p_mail != NULL) { 00309 *p_data = *p_mail; 00310 ret = true; 00311 } 00312 (void) mail_box.free(p_mail); 00313 } 00314 } 00315 return ret; 00316 } 00317 00318 /** Decodes the display thread mail 00319 * 00320 * @param p_mail Pointer to the structure of the data 00321 * @param p_ctrl Pointer to control data of display module. 00322 * 00323 * @returns 00324 * Results of process. true is success. false is failure. 00325 */ 00326 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl) 00327 { 00328 bool ret = false; 00329 00330 if ((p_mail != NULL) && (p_ctrl != NULL)) { 00331 /* Decodes the received mail */ 00332 switch(p_mail->mail_id) { 00333 case DSP_MAILID_CYCLE_IND: /* Cyclic notice */ 00334 ret = true; 00335 break; 00336 case DSP_MAILID_CMD_STR: /* Input character string by the command-line */ 00337 ret = true; 00338 if ((int32_t)p_mail->param[MAIL_CMDSTR_FIN_FLG] == true) { 00339 p_ctrl->trm.edge_fin_inpt = true; 00340 } else { 00341 p_ctrl->trm.edge_fin_inpt = false; 00342 } 00343 (void) memcpy(&p_ctrl->trm.inpt_str[0], 00344 &p_mail->param[MAIL_CMDSTR_STR_START], 00345 sizeof(p_ctrl->trm.inpt_str)); 00346 p_ctrl->trm.inpt_str[DSP_CMD_INPT_STR_MAX_LEN - 1] = '\0'; 00347 break; 00348 case DSP_MAILID_PRINT_STR: /* Character string for the status indication */ 00349 ret = true; 00350 (void) memcpy(&p_ctrl->com.dspl_str[0], 00351 &p_mail->param[MAIL_DISPSTR_STR_START], 00352 sizeof(p_ctrl->com.dspl_str)); 00353 p_ctrl->com.dspl_str[DSP_DISP_STR_MAX_LEN - 1] = '\0'; 00354 break; 00355 case DSP_MAILID_PLAY_TIME: /* Playback time */ 00356 ret = true; 00357 p_ctrl->com.play_stat = (SYS_PlayStat)p_mail->param[MAIL_PLAYTIME_STAT]; 00358 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_H] << BYTE_SHIFT) | 00359 (uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_L]); 00360 p_ctrl->com.play_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_H] << WORD_SHIFT) | 00361 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_M] << BYTE_SHIFT) | 00362 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_L])); 00363 p_ctrl->com.total_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_H] << WORD_SHIFT) | 00364 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_M] << BYTE_SHIFT) | 00365 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_L])); 00366 break; 00367 case DSP_MAILID_PLAY_INFO: /* Music information */ 00368 ret = true; 00369 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_H] << BYTE_SHIFT) | 00370 (uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_L]); 00371 p_ctrl->com.samp_freq = (((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_H] << WORD_SHIFT) | 00372 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_M] << BYTE_SHIFT) | 00373 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_L])); 00374 p_ctrl->com.channel = p_mail->param[MAIL_PLAYINFO_CHANNEL]; 00375 break; 00376 case DSP_MAILID_PLAY_MODE: /* Repeat mode */ 00377 ret = true; 00378 if ((int32_t)p_mail->param[MAIL_PLAYMODE_REPEAT] == true) { 00379 p_ctrl->com.repeat_mode = true; 00380 } else { 00381 p_ctrl->com.repeat_mode = false; 00382 } 00383 break; 00384 case DSP_MAILID_FILE_NAME: /* File name */ 00385 ret = true; 00386 (void) memcpy(&p_ctrl->com.file_name[0], 00387 &p_mail->param[MAIL_FILENAME_STR_START], 00388 sizeof(p_ctrl->com.file_name)); 00389 p_ctrl->com.file_name[DSP_DISP_STR_MAX_LEN - 1] = '\0'; 00390 break; 00391 case DSP_MAILID_HELP: /* Help information */ 00392 ret = true; 00393 break; 00394 default: 00395 /* Unexpected cases : mail id was illegal. */ 00396 ret = false; 00397 break; 00398 } 00399 } 00400 return ret; 00401 } 00402 00403 /** Clears the one shot data in the control data of display module 00404 * 00405 * @param p_ctrl Pointer to control data of display module. 00406 */ 00407 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl) 00408 { 00409 if (p_ctrl != NULL) { 00410 if (p_ctrl->trm.edge_fin_inpt == true) { 00411 /* Clears data of input character string. */ 00412 p_ctrl->trm.edge_fin_inpt = false; 00413 p_ctrl->trm.inpt_str[0] = '\0'; 00414 } 00415 } 00416 return; 00417 }
Generated on Tue Jul 12 2022 22:07:08 by
1.7.2