GR-MANGO sample using mbed-os library from my repository.

Dependencies:   mbed-http

Committer:
RyoheiHagimoto
Date:
Mon Oct 12 02:25:49 2020 +0000
Revision:
0:b4c1e32627f2
replaced mbed-os library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:b4c1e32627f2 1 /*******************************************************************************
RyoheiHagimoto 0:b4c1e32627f2 2 * DISCLAIMER
RyoheiHagimoto 0:b4c1e32627f2 3 * This software is supplied by Renesas Electronics Corporation and is only
RyoheiHagimoto 0:b4c1e32627f2 4 * intended for use with Renesas products. No other uses are authorized. This
RyoheiHagimoto 0:b4c1e32627f2 5 * software is owned by Renesas Electronics Corporation and is protected under
RyoheiHagimoto 0:b4c1e32627f2 6 * all applicable laws, including copyright laws.
RyoheiHagimoto 0:b4c1e32627f2 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
RyoheiHagimoto 0:b4c1e32627f2 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
RyoheiHagimoto 0:b4c1e32627f2 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
RyoheiHagimoto 0:b4c1e32627f2 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
RyoheiHagimoto 0:b4c1e32627f2 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
RyoheiHagimoto 0:b4c1e32627f2 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
RyoheiHagimoto 0:b4c1e32627f2 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
RyoheiHagimoto 0:b4c1e32627f2 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
RyoheiHagimoto 0:b4c1e32627f2 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
RyoheiHagimoto 0:b4c1e32627f2 16 * Renesas reserves the right, without notice, to make changes to this software
RyoheiHagimoto 0:b4c1e32627f2 17 * and to discontinue the availability of this software. By using this software,
RyoheiHagimoto 0:b4c1e32627f2 18 * you agree to the additional terms and conditions found by accessing the
RyoheiHagimoto 0:b4c1e32627f2 19 * following link:
RyoheiHagimoto 0:b4c1e32627f2 20 * http://www.renesas.com/disclaimer
RyoheiHagimoto 0:b4c1e32627f2 21 *
RyoheiHagimoto 0:b4c1e32627f2 22 * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved.
RyoheiHagimoto 0:b4c1e32627f2 23 *******************************************************************************/
RyoheiHagimoto 0:b4c1e32627f2 24 #include "sample_select.h"
RyoheiHagimoto 0:b4c1e32627f2 25
RyoheiHagimoto 0:b4c1e32627f2 26 #if (SAMPLE_PROGRAM_NO == 3)
RyoheiHagimoto 0:b4c1e32627f2 27 // SAMPLE_PROGRAM_NO 3 : SPDIF loop back sample
RyoheiHagimoto 0:b4c1e32627f2 28 //
RyoheiHagimoto 0:b4c1e32627f2 29 // The input sound is output as it is.
RyoheiHagimoto 0:b4c1e32627f2 30 // In case of SAMPLE_PROGRAM_NO=3 :
RyoheiHagimoto 0:b4c1e32627f2 31 // Since TARGET_RZ_A2M_EVB has no connector and no suitable AUDIO_CLK has been entered, only pseudo-evaluation is executed.
RyoheiHagimoto 0:b4c1e32627f2 32 // - Please connect PC_5 and PC_4 when evaluating.
RyoheiHagimoto 0:b4c1e32627f2 33 // - Since AUDIO_CLK on the board is 11.2896 MHz, it operates at half the actual speed.
RyoheiHagimoto 0:b4c1e32627f2 34 // - The AUDIO_CLK frequency required is 512 times as large as the sample frequency for audio data.
RyoheiHagimoto 0:b4c1e32627f2 35 // (fs=44.1kHz : AUDIO_CLK=22.5792MHz, fs=48kHz : AUDIO_CLK=24.5760MHz)
RyoheiHagimoto 0:b4c1e32627f2 36
RyoheiHagimoto 0:b4c1e32627f2 37 #if !defined(TARGET_RZ_A2M_EVB)
RyoheiHagimoto 0:b4c1e32627f2 38 #error "SPDIF is not supported."
RyoheiHagimoto 0:b4c1e32627f2 39 #endif
RyoheiHagimoto 0:b4c1e32627f2 40
RyoheiHagimoto 0:b4c1e32627f2 41 #include "mbed.h"
RyoheiHagimoto 0:b4c1e32627f2 42 #include "SPDIF_RBSP.h"
RyoheiHagimoto 0:b4c1e32627f2 43
RyoheiHagimoto 0:b4c1e32627f2 44 #define WRITE_BUFF_NUM (8)
RyoheiHagimoto 0:b4c1e32627f2 45 #define READ_BUFF_NUM (8)
RyoheiHagimoto 0:b4c1e32627f2 46 #define MAIL_QUEUE_SIZE (WRITE_BUFF_NUM + READ_BUFF_NUM + 1)
RyoheiHagimoto 0:b4c1e32627f2 47 #define INFO_TYPE_WRITE_END (0)
RyoheiHagimoto 0:b4c1e32627f2 48 #define INFO_TYPE_READ_END (1)
RyoheiHagimoto 0:b4c1e32627f2 49
RyoheiHagimoto 0:b4c1e32627f2 50 #define AUDIO_BUFF_SIZE (192 * 2 * 10) // 1 block * 2ch * 10
RyoheiHagimoto 0:b4c1e32627f2 51 SPDIF_RBSP audio(P6_4, PC_5, PC_4, false, 0x80, WRITE_BUFF_NUM, READ_BUFF_NUM);
RyoheiHagimoto 0:b4c1e32627f2 52
RyoheiHagimoto 0:b4c1e32627f2 53 typedef struct {
RyoheiHagimoto 0:b4c1e32627f2 54 uint32_t info_type;
RyoheiHagimoto 0:b4c1e32627f2 55 void * p_data;
RyoheiHagimoto 0:b4c1e32627f2 56 int32_t result;
RyoheiHagimoto 0:b4c1e32627f2 57 } mail_t;
RyoheiHagimoto 0:b4c1e32627f2 58 Mail<mail_t, MAIL_QUEUE_SIZE> mail_box;
RyoheiHagimoto 0:b4c1e32627f2 59
RyoheiHagimoto 0:b4c1e32627f2 60 //32 bytes aligned! No cache memory
RyoheiHagimoto 0:b4c1e32627f2 61 static uint8_t audio_read_buff[READ_BUFF_NUM][AUDIO_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(32)));
RyoheiHagimoto 0:b4c1e32627f2 62
RyoheiHagimoto 0:b4c1e32627f2 63 static void callback_audio(void * p_data, int32_t result, void * p_app_data) {
RyoheiHagimoto 0:b4c1e32627f2 64 mail_t *mail = mail_box.alloc();
RyoheiHagimoto 0:b4c1e32627f2 65
RyoheiHagimoto 0:b4c1e32627f2 66 if (mail == NULL) {
RyoheiHagimoto 0:b4c1e32627f2 67 printf("error mail alloc\r\n");
RyoheiHagimoto 0:b4c1e32627f2 68 } else {
RyoheiHagimoto 0:b4c1e32627f2 69 mail->info_type = (uint32_t)p_app_data;
RyoheiHagimoto 0:b4c1e32627f2 70 mail->p_data = p_data;
RyoheiHagimoto 0:b4c1e32627f2 71 mail->result = result;
RyoheiHagimoto 0:b4c1e32627f2 72 mail_box.put(mail);
RyoheiHagimoto 0:b4c1e32627f2 73 }
RyoheiHagimoto 0:b4c1e32627f2 74 }
RyoheiHagimoto 0:b4c1e32627f2 75
RyoheiHagimoto 0:b4c1e32627f2 76 int main() {
RyoheiHagimoto 0:b4c1e32627f2 77 rbsp_data_conf_t audio_write_conf = {&callback_audio, (void *)INFO_TYPE_WRITE_END};
RyoheiHagimoto 0:b4c1e32627f2 78 rbsp_data_conf_t audio_read_conf = {&callback_audio, (void *)INFO_TYPE_READ_END};
RyoheiHagimoto 0:b4c1e32627f2 79
RyoheiHagimoto 0:b4c1e32627f2 80 // Read buffer setting
RyoheiHagimoto 0:b4c1e32627f2 81 for (int i = 0; i < READ_BUFF_NUM; i++) {
RyoheiHagimoto 0:b4c1e32627f2 82 if (audio.read(audio_read_buff[i], AUDIO_BUFF_SIZE, &audio_read_conf) < 0) {
RyoheiHagimoto 0:b4c1e32627f2 83 printf("read error\r\n");
RyoheiHagimoto 0:b4c1e32627f2 84 }
RyoheiHagimoto 0:b4c1e32627f2 85 }
RyoheiHagimoto 0:b4c1e32627f2 86
RyoheiHagimoto 0:b4c1e32627f2 87 while (1) {
RyoheiHagimoto 0:b4c1e32627f2 88 osEvent evt = mail_box.get();
RyoheiHagimoto 0:b4c1e32627f2 89 if (evt.status == osEventMail) {
RyoheiHagimoto 0:b4c1e32627f2 90 mail_t *mail = (mail_t *)evt.value.p;
RyoheiHagimoto 0:b4c1e32627f2 91
RyoheiHagimoto 0:b4c1e32627f2 92 if ((mail->info_type == INFO_TYPE_READ_END) && (mail->result > 0)) {
RyoheiHagimoto 0:b4c1e32627f2 93 audio.write(mail->p_data, mail->result, &audio_write_conf);
RyoheiHagimoto 0:b4c1e32627f2 94 } else {
RyoheiHagimoto 0:b4c1e32627f2 95 audio.read(mail->p_data, AUDIO_BUFF_SIZE, &audio_read_conf); // Resetting read buffer
RyoheiHagimoto 0:b4c1e32627f2 96 }
RyoheiHagimoto 0:b4c1e32627f2 97 mail_box.free(mail);
RyoheiHagimoto 0:b4c1e32627f2 98 }
RyoheiHagimoto 0:b4c1e32627f2 99 }
RyoheiHagimoto 0:b4c1e32627f2 100 }
RyoheiHagimoto 0:b4c1e32627f2 101
RyoheiHagimoto 0:b4c1e32627f2 102 #endif