Sound Generator Sample

Dependencies:   Sound_Generator

Fork of Sound_Generator_Sample by GR-PEACH_producer_meeting

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.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) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 /******************************************************************************
00025 Includes   <System Includes> , "Project Includes"
00026 ******************************************************************************/
00027 #include <stdio.h>
00028 #include <stdint.h>
00029 #include "mbed.h"
00030 extern "C"{
00031 #include    "iodefine.h"
00032 #include    "devdrv_sdg.h"
00033 }
00034 #include    "score.h"
00035 #include    "piano4int.h"
00036 
00037 
00038 /******************************************************************************
00039 Typedef definitions
00040 ******************************************************************************/
00041 
00042 
00043 /******************************************************************************
00044 Macro definitions
00045 ******************************************************************************/
00046 
00047 
00048 /******************************************************************************
00049 Imported global variables and functions (from other files)
00050 ******************************************************************************/
00051 
00052 
00053 /******************************************************************************
00054 Exported global variables and functions (to be accessed by other files)
00055 ******************************************************************************/
00056 extern "C" {
00057     void Sample_OSTM0_Interrupt(void);
00058 };
00059 
00060 static void sound_LED (uint32_t channel, uint32_t value);
00061 
00062 
00063 /******************************************************************************
00064 Private global variables and functions
00065 ******************************************************************************/
00066 Ticker      LEDTicker;
00067 DigitalOut  LED(LED1);
00068 DigitalOut  SoundLED(LED2);
00069 
00070 static const int8_t score1[] = {
00071     SCORE1
00072 };
00073 
00074 static const int8_t score3[] = {
00075     SCORE3
00076 };
00077 
00078 
00079 /******************************************************************************
00080 * Function Name: main
00081 * Description  : Displays the sample program information on the terminal
00082 *              : connected with the CPU board by the UART, and executes initial
00083 *              : setting for the PORT connected with the LEDs on the board.
00084 *              : Executes initial setting for the OSTM channel 0, and sets the
00085 *              : timer counter so that the OSTM0 interrupt occurs every 500ms.
00086 * Arguments    : none
00087 * Return Value : 0
00088 ******************************************************************************/
00089 int main(void)
00090 {
00091     static const int8_t *scores[SDG_CH_TOTAL] = {
00092         /*DEVDRV_CH_0*/ NULL,
00093         /*DEVDRV_CH_1*/ score1,
00094         /*DEVDRV_CH_2*/ NULL,
00095         /*DEVDRV_CH_3*/ score3
00096     };
00097     /* ==== Setup the I/O without buffering ==== */
00098     printf("\nRZ/A1H CPU Board Sample Program. Ver.1.00\n");
00099     printf("RZ/A1H Sound Generator Sample Program. Ver.0.01\n");
00100     printf("Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.\n");
00101     printf("\n");
00102 
00103     LED = 0;
00104     LEDTicker.attach(&Sample_OSTM0_Interrupt, 0.2);
00105 
00106     /* ==== Receive command, activate sample software ==== */
00107     while (true) {
00108         /* start playing scores */
00109         piano4int_start (scores, sound_LED);
00110 
00111         while (piano4int_status()) {
00112             /* wait 10ms */
00113             wait_us(10.0 * 1000.0);
00114         }
00115         /* stop playing scores */
00116         piano4int_stop(false);
00117         /* wait 5 seconds */
00118         wait(5.0);
00119     }
00120     return 0;
00121 }
00122 
00123 /******************************************************************************
00124 * Function Name: Sample_OSTM0_Interrupt
00125 * Description  : This function is executed when the OSTM0 interrupt is received.
00126 *              : In this sample code, the processing to blink the LEDs on the
00127 *              : CPU board every 500ms is executed.
00128 * Arguments    : none
00129 * Return Value : none
00130 ******************************************************************************/
00131 void Sample_OSTM0_Interrupt(void)
00132 {
00133     /* ==== LED blink ==== */
00134     LED = LED ^ 1;
00135 }
00136 
00137 /******************************************************************************
00138 * End of Function Sample_OSTM0_Interrupt
00139 ******************************************************************************/
00140 
00141 /******************************************************************************
00142 * Function Name: sound_LED
00143 * Description  : This function is used for callback function.
00144 * Arguments    : uint32_t channel : SDG channel (0, 1, 2 or 3)
00145 *              : uint32_t value   : Syncronization Marker ID
00146 * Return Value : none
00147 ******************************************************************************/
00148 static void sound_LED (uint32_t channel, uint32_t value)
00149 {
00150     /* ==== LED blink ==== */
00151     SoundLED = SoundLED ^ 1;
00152 }
00153 
00154 /* End of File */