9010e72dbe93001d1048ca0b878feed2

来自「在开发FPGA上比较有用」· 代码 · 共 710 行 · 第 1/2 页

TXT
710
字号
#include <stdio.h>
#include <io.h>
#include <system.h>
#include <alt_types.h>
#include <string.h>
#include <stdlib.h>
#include <sd_controller.h>
#include <sys/alt_irq.h>
#include <sys/alt_dma.h>
#include "fast_dma.h"
#include <altera_avalon_dma_regs.h>
#define  AUDIO_BUFF_SIZE 0x6000

unsigned int *audioBuff=(unsigned int *)(SDRAM_BASE+0x200000);
unsigned int *audioBuff1=(unsigned int *)(SDRAM_BASE+0x206000);
unsigned int *audioBuff2=(unsigned int *)(SDRAM_BASE+0x212000);
unsigned int *audioBuff3=(unsigned int *)(SDRAM_BASE+0x218000);
unsigned int *audioBuff4=(unsigned int *)(SDRAM_BASE+0x224000);
unsigned int *audioBuff5=(unsigned int *)(SDRAM_BASE+0x360000);
unsigned int *audioBuff6=(unsigned int *)(SDRAM_BASE+0x500000);
//unsigned int *audioBuff7=(unsigned int *)(SDRAM_BASE+0x300000);
int flagaic=0; 
FILE * hostfile;
int voicelong;
int AUDIO_BUFF_SIZE2;
int AUDIO_BUFF_SIZE1;

extern void *dma_base;
extern int gControl_bits;

unsigned int infifo_count;
/*******************************************************
以下为音频部分
负责人:曹汉超
********************************************************/

/*********************************************
函数名:audio_irq
功  能:音频中断处理函数
输  入:context:相关内容指针,中断号
返  回: 
备  注:
      读取音频外设数据,并回放写入到音频外设中
**********************************************/

void audio_irq(void *context,alt_u32 interrupt)
{
  unsigned int fifo_status;
  unsigned int len;
  
  fifo_status=IORD(FREEDEV_AIC23_0_BASE,0x03);
  infifo_count=IORD(FREEDEV_AIC23_0_BASE,0x04);

  if(fifo_status & 0x04)
    len=512;
  else 
    len=infifo_count;
    
  // 启动DMA传输
  IOWR_ALTERA_AVALON_DMA_LENGTH(dma_base,len);
  IOWR_ALTERA_AVALON_DMA_CONTROL(dma_base, gControl_bits|ALTERA_AVALON_DMA_CONTROL_GO_MSK); 
  
}


/*************************************************
*函数名:aic23_warning_play
*参数:文件名
*功能:播放警告
/************************************************/
void aic23_warning_play(int num)
{
            if(num == 3001){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/welcomeinit.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x12500;
           }else if(num == 3002){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/initfinish.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x7500;
           }else if(num == 3003){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/menuintroduce.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x50000;
           }else if(num == 3004){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/sendmehome.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x10000;
           }else if(num == 3005){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/IamOK.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x7500;
           }else if(num == 3006){
              hostfile = fopen("/dev/sd_controller_inst/Input_Files/reachsafe.dat", "r");
              AUDIO_BUFF_SIZE2 = 0x7500;
           }else if(num == 3007){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/Ontheway.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x7500;
           }else if(num == 3008){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/help_mic_intro.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x52000;
           }else if(num == 3009){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/input_error.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x10000;
           }else if(num == 3010){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/normal_mode_mic.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x12500;
           }else if(num == 3011){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/failgps.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x10000;
           }else if(num == 3012){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/faild_diantai.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x10000;
           }else if(num == 3013){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/mp3.dat", "r");
             AUDIO_BUFF_SIZE2 = 0x10000;
           }else if(num == 3015){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_50m.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3016){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_100cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3017){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_150cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3018){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_200cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3019){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_250cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3020){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_050cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3021){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhangAiWu_350cm.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3022){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/time_y2008.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3023){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/time_mSep.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3024){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/time_d19.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3025){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/time_d20.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           }else if(num == 3026){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/time_d25.dat", "w");
            // AUDIO_BUFF_SIZE2 = 0x20000;
           } else if(num == 3027){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/diantai_menu.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x52000;
           }else if(num == 3028){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/4road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3029){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/3road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3030){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/2road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3031){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/1road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3032){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/change_mode.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3033){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/notchange_mode.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3034){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/east.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3035){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/west.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3036){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/north.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3037){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/south.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3038){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/diantai_chose_destanation.dat","r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x22500;
           }else if(num == 3039){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/queding_fasong.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3040){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/qingxuanzecaozuo.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3041){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/45road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3042){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/408road.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3043){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/clock_.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }else if(num == 3044){
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/clock_.dat", "r");
            // AUDIO_BUFF_SIZE2 = 0x20000;
            AUDIO_BUFF_SIZE2 = 0x6000;
           }
}





/*************************************************
*函数名:aic23_station_play
*参数:文件名
*功能:播放站名
/************************************************/
void aic23_station_play(int num)
{
     // char filename[]="/dev/sd_controller_inst/Input_Files/welcomeinit.dat";
           AUDIO_BUFF_SIZE2 = 0x6000;
           if(num == 2001)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/DaChaiShi.dat", "r");
            //  hostfile = fopen("filename", "r");
           else if(num == 2002)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/DongMen.dat", "r");
           else if(num == 2003)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/DongNanChengJiao.dat", "r");
           else if(num == 2004)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/DuanLvMen.dat", "r");
           else if(num == 2005)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/HePingMen.dat", "r");
           else if(num == 2006)
              hostfile = fopen("/dev/sd_controller_inst/Input_Files/JiaoDaDianNaoCheng.dat", "r");
           else if(num == 2007)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/JiaoDaShangChang.dat", "r");
           else if(num == 2008)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/LiJiaCun.dat", "r");
           else if(num == 2009)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/LuJiaCun.dat", "r");
           else if(num == 2010)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/NanGuoMen.dat", "r");
           else if(num == 2011)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/NanMen.dat", "r");
           else if(num == 2012)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/NanShaoMen.dat", "r");
           else if(num == 2013)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/SaiGeDianNaoCheng.dat", "r");
           
           else if(num == 2014)//
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ShaPoCun.dat", "r");//
           else if(num == 2015)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ShaPo.dat", "r");
           else if(num == 2016)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/XingQingGongYuan.dat", "r");
           else if(num == 2017)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ZhongLou.dat", "r");
           else if(num == 2018)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/WuJingYiYuan.dat", "r");
           else if(num == 2019)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/TieYiJvYiYuan.dat", "r");
           else if(num == 2020)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/TaiYiLu.dat", "r");
           else if(num == 2021)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/WaYaoXiaoQv.dat", "r");
           else if(num == 2022)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/WenYiLu.dat", "r");
           else if(num == 2023)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/ahead.dat", "r");
           else if(num == 2024)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/right.dat", "r");
           else if(num == 2025)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/left.dat", "r");
           else if(num == 2026)
             hostfile = fopen("/dev/sd_controller_inst/Input_Files/stop.dat", "r");
}
/*************************************************
*函数名:aic23_play
*参数:文件名
*功能:播放
/************************************************/
void aic23_play(int num)
{
    int i;
 //   FILE * hostfile;
    unsigned int v1;
    int flag=1;
    char ch;
    /*hostfile = fopen("/dev/sd_controller_inst/Input_Files/silence_init.dat", "r");
        for(i=0;i<0x56000;)
              {
                  IOWR(FREEDEV_AIC23_0_BASE,0x07,audioBuff[i]);
                  i++;
               }*/
        if(num<2000)
         {
           if(num == 1001)
           {
              for(i=0;i<AUDIO_BUFF_SIZE;)
              {
                //读音频外设状态
                v1=IORD(FREEDEV_AIC23_0_BASE,0x03);
                // 输出FIFO不为满
                if(!(v1 & 0x01))
               {
                  IOWR(FREEDEV_AIC23_0_BASE,0x07,audioBuff[i]);
                  i++;
               }
       //    hostfile = fopen("/dev/sd_controller_inst/Input_Files/ahead16.dat", "r");
              }
           }else if(num == 1002)
             {
               for(i=0;i<AUDIO_BUFF_SIZE;)
              {
              //读音频外设状态
               v1=IORD(FREEDEV_AIC23_0_BASE,0x03);
              // 输出FIFO不为满
               if(!(v1 & 0x01))
               {
                 IOWR(FREEDEV_AIC23_0_BASE,0x07,audioBuff1[i]);
                  i++;
               }
             //  hostfile = fopen("/dev/sd_controller_inst/Input_Files/left16.dat", "r");
             }
          }else if(num == 1003){
             for(i=0;i<AUDIO_BUFF_SIZE;)
            {
              //读音频外设状态
             v1=IORD(FREEDEV_AIC23_0_BASE,0x03);
              // 输出FIFO不为满
             if(!(v1 & 0x01))
             {
               IOWR(FREEDEV_AIC23_0_BASE,0x07,audioBuff2[i]);
               i++;
             }
         //  hostfile = fopen("/dev/sd_controller_inst/Input_Files/right16.dat", "r");
           }
             }else if(num == 1004){
             for(i=0;i<AUDIO_BUFF_SIZE;)
           {
              //读音频外设状态

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?