⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6416test.c

📁 DSP的集成开发
💻 C
字号:
/*%####################################################################
/%名称:    6416测试程序
/%作用:    测试6416led正常工作         
/%语言:c
/%版本:1.0
/%历史版本:无
/%copyright:马晓东 HEU 804 LAB
/%date:	2007/05/05
/%修改:CJF
/%日期:2007/09/024
/%####################################################################*/

/***********定义头文件************/
#include <stdio.h>
#include <stdlib.h>
#include <std.h>
#include <time.h>
#include "timer.h"
#include "mcbsp.h"
#include "emifa.h"
#include "intr.h"
#include "regs.h"
#include "emifb.h"
#include "hpi64x.h"
#include "gpio64x.h"
#include "timer2_64x.h"
#include "6416test.h"


/********************初始化函数声明************/
void intr_initial();
void mcbsp0_initial();
//void mcbsp1_initial();
void timer0_initial();
//void timer1_initial();
void timer2_initial();
void emifa_initial();
void emifb_initial();
void is82c52_initial();//bce3
void HPIslaver_initial();
void dualram_initial();//ace3


/********************其它数据函数声明************/
void delay(unsigned int delay_num);


//片内数据RAM 
#define HPI_RADDR   0x000F0000                //HPI口下传命令字起始地址
#define HPI_TADDR   0x000F0100                //HPI口上传命令字起始地址
#define HPI_TADDR_LEN    0x30                 //HPI口上传命令空间大小

				

#define SDRAM_RDATA_ADDR   	0x000F5000


unsigned char 	intr4_flag=0;//中断4响应标志
unsigned char	i82c52_data=0;

short data_table[10]={0,0,0,0,0,0,0,0,0,0};




/*************** main ****************/
void main()
{
	//int i;
		
	INTR_GLOBAL_DISABLE();
	intr_initial();
	delay(1000);
	emifa_initial();
	delay(1000);
	emifb_initial();
	delay(1000);
	is82c52_initial();
	delay(1000);
	GPIO_ALL_DISABLE();
	delay(1000);
	timer2_initial();
	delay(1000);
	
	
	/* write a string to stdout */
//	printf( "All initial operation is done.\n");
	
	
	/*clkout6 output test opration--1/6 cpu clock,default*/
	//RESET_BIT(EMIFA_GCTRL_ADDR,CLK6EN);
	//SET_BIT(EMIFA_GCTRL_ADDR,CLK6EN);//cpu 6分频输出测试
	
	
	/*clkout4 output test opration--1/4 cpu clock,default*/
//	RESET_BIT(EMIFA_GCTRL_ADDR,CLK4EN);
	//SET_BIT(EMIFA_GCTRL_ADDR,CLK4EN);//cpu 4分频输出测试
	
		
	/* GPIO test opration */

	/*GP1EN_ENABLE();
	GPGC_GP0_GPIOMODE();
	GP1DIR_OUTPUT();
	GPxVAL_SET(1);
	//GP1EN_DISABLE();
	//while(1)
	//{
	GPxVAL_SET(1);
	delay(10);
	GPxVAL_RESET(1);
	delay(10);
	//}*/
	//printf( "GPIO1 test operation is done.\n");
	
	
	/* timer2 test opration */
	/*TIMER2_CLK_INTERNAL();
	TIMER2_TOUT_ENABLE();
	TIMER2_TOUT_ASSERT();
	//TIMER2_MODE_SELECT(1);
	TIMER2_START();
	TIMER2_TOUT_DISABLE();
	TIMER2_TOUT_NEGATE();
	//printf( "timer2 test operation is done.\n");*/
	
				
	/* interrupt4 test operation*/
	GP4EN_ENABLE();
	GP1DIR_INPUT();
	GPGC_GPINT0_PASSMODE();
	INTR_GLOBAL_ENABLE();
	INTR_ENABLE(4);
	//INTR_ENABLE(5);
	//INTR_ENABLE(6);
	printf( "interrupt 4 has been opened.\n");
//	while(1){}
	
	
	/* emifb test operation*/	
	//emifb时钟输出测试
	//SET_BIT(EMIFB_GCTRL_ADDR,16);//EK2 enable 
	
	/*82c52测试	
	while(1)
	{
	IS82C52_TBR_W=0xbb;
	//i82c52_data=IS82C52_TBR_W;
	delay(100000);
	}*/
	
	
	
	

	while(1){}



}


/********************************************************************************/
/**                            初始化中断寄存器子函数                          **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: intr_initial()
** 功能描述: 中断寄存器初始化
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
void intr_initial()
{
	INTR_GLOBAL_DISABLE();
    INTR_MAP_RESET();
    INTR_EXT_POLARITY(XIP4,1);//INT4下降沿有效
    INTR_EXT_POLARITY(XIP5,0);//INT5上升沿有效
    INTR_EXT_POLARITY(XIP6,0);//INT6上升沿有效
    	
	delay(100);
	//中断禁止
  	INTR_DISABLE(1);                                           //NMIE=0
  	INTR_DISABLE(2);                                           //IE2=0
  	INTR_DISABLE(3);                                           //IE3=0
 	INTR_DISABLE(4);                                           //IE4=0 //RESET_REG_BIT(IER,4);
 	INTR_DISABLE(5);                                           //IE5=0 
 	INTR_DISABLE(6);                                           //IE6=0 
 	INTR_DISABLE(7);                                           //IE7=0 
  	INTR_DISABLE(8);                                           //IE8=0 
  	INTR_DISABLE(9);                                           //IE9=0
  	INTR_DISABLE(10);                                          //IE10=0 
  	INTR_DISABLE(11);                                          //IE11=0    
  	INTR_DISABLE(12);                                          //IE12=0  
  	INTR_DISABLE(13);                                          //IE13=0
  	INTR_DISABLE(14);                                          //IE14=0 
  	INTR_DISABLE(15);                                          //IE15=0 
    //IER=0;//
    //清除局部中断标志
  	INTR_CLR_FLAG(1);                                          //IF1=0
  	INTR_CLR_FLAG(2);                                          //IF2=0
  	INTR_CLR_FLAG(3);                                          //IF3=0
  	INTR_CLR_FLAG(4);                                          //IF4=0
  	INTR_CLR_FLAG(5);                                          //IF5=0
  	INTR_CLR_FLAG(6);                                          //IF6=0
 	INTR_CLR_FLAG(7);                                          //IF7=0
  	INTR_CLR_FLAG(8);                                          //IF8=0
  	INTR_CLR_FLAG(9);                                          //IF9=0
  	INTR_CLR_FLAG(10);                                         //IF10=0
  	INTR_CLR_FLAG(11);                                         //IF11=0
  	INTR_CLR_FLAG(12);                                         //IF12=0
  	INTR_CLR_FLAG(13);                                         //IF13=0
  	INTR_CLR_FLAG(14);                                         //IF14=0
  	INTR_CLR_FLAG(15);                                         //IF15=0 
	//中断使能
  	INTR_ENABLE(1);                                            //NMIE=1 //SET_REG_BIT(IER,1);
    delay(1000);
}

/********************************************************************************/
/**                           初始化EMIFA口寄存器子函数                        **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: emifa_initial()
** 功能描述: 
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
/*************初始化EMIFA口********************/
void emifa_initial()
{	
	emifa_init(0x000026E0,//CLK6EN_DISABLE,CLK4EN_DISABLE,EK1EN_0,EK1HZ_0
						 //HOLDA_0,HOLD_1,ARDY_1,BUSREQ_1,BRMODE_1,EK2EN_0
						 //EK2HZ_0,EK2RATE_10 
              0x10910420,//ace0
              0x10910420,//ace1,FPGA,32位异步,read(1,4,0)write(1,2,1)
              0x10910420,
              0x00400220,//read(0,2,0);write(0,1,0)
              0x54C96000,
 	          0x0000061A
 	          
              ); 
    delay(100);
}


/*************初始化EMIFB口********************/
void emifb_initial()
{
	emifb_init(0x00002EE0,//EK2RATE_01(1/4emif_clk),EK2EN_0,EK2HZ_0,BRMODE_1
						  //HOLDA_0,HOLD_1,ARDY_1,BUSREQ_1,EK1EN_0,EK1HZ_HZ					  
              0x23715513,//bce0,flash160,16位异步,read(1/21/3),write(2/13/3)
              0x23715523,//bce1,flash040,8位异步,read(1,4,0)write(1,2,1)
              0xfffa1e13,//bce2,HPIhost,16位异步
              0x20920201,
              0x05111000,//
 	          0x0000061A//
 	          ); 
    delay(100);

}



/********************************************************************************/
/**                           初始化Mcbsp0寄存器子函数                        **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: mcbsp0_initial()
** 功能描述: 
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
/*************初始化Mcbsp0********************/
void mcbsp0_init()
{
	mcbsp_init(	mcbsp_port_0,
            	0x00000000,//spcr_ctrl
            	0x00000000,//rcr_ctrl
            	0x000100a0,//xcr_ctrl
            	0x20252020,//srgr_ctrl
            	0x00000000,//mcr_ctrl 
            	0x00000000,//rcer_ctrl
            	0x00000000,//xcer_ctrl 
            	0x00000b00);//pcr_ctrl
    SET_BIT((unsigned int *)(MCBSP_SPCR_ADDR(mcbsp_port_0)),GRST);//设置SPCR的/GRST=1        
	delay(100);
	SET_BIT((unsigned int *)(MCBSP_SPCR_ADDR(mcbsp_port_0)),RRST);//设置SPCR的/RRST=1
	SET_BIT((unsigned int *)(MCBSP_SPCR_ADDR(mcbsp_port_0)),XRST);//设置SPCR的/XRST=1
	SET_BIT((unsigned int *)(MCBSP_SPCR_ADDR(mcbsp_port_0)),FRST);//设置SPCR的/FRST=1
	delay(100);

}



/********************************************************************************/
/**                           初始化Timer0寄存器子函数                        **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: timer0_initial()
** 功能描述: 初始化定时器0
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
/*************初始化Timer0********************/
void timer0_initial()
{
  TIMER_RESET(0);                                       
  TIMER0_CTRL=0x00000693;          //FUNC=1,INVOUT=1,DATOUT=1,/HLD=1,CLKSRC=1,INVINP=1
  TIMER0_PERIOD=0x000000D0;                                
  TIMER0_COUNTER=0x00000001;                                
  TIMER_STOP(0);
}

/********************************************************************************/
/**                           初始化Timer2寄存器子函数                        **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: timer2_initial()
** 功能描述: 初始化定时器2
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
/*************初始化Timer2********************/
void timer2_initial()
{
  TIMER2_RESET();                                          
  TIMER2_CTRL=0x00000613;            //FUNC=1,INVOUT=1,DATOUT=1,/HLD=1,CLKSRC=1,INVINP=1
  TIMER2_PERIOD=0x000000D0;                              
  TIMER2_COUNTER=0x00000001;                             
  TIMER2_STOP();
}

/************初始化82c52的寄存器**************/
void is82c52_initial()
{
	IS82C52_UCR_W=0x3c;
    delay(1000);
    IS82C52_BRSR_W=0xfd;
    delay(1000);
	IS82C52_MCR_W=0x20;
	delay(1000);
    
}

/************初始化HPI 控制寄存器**************/
void HPIslaver_initial()
{
	unsigned int ini_var1;
	HPI_RESET_DSPINT();                 //清除主机发送的HPI口中断标志 
	for(ini_var1=0;ini_var1<256;ini_var1++)      //HPI命令空间初始化
 	 {
  		  *(int *)(HPI_RADDR+ini_var1*4)=0;
 	 }
}




/********************************************************************************/
/**                            外部中断4处理子函数                             **/
/********************************************************************************/
/*********************************************************************************
** 函数名称: interrupt void extn_int4()
** 功能描述: 
** 输   入: 无
** 输   出: 无
** 全局变量: 
** 调用模块: 无
** 作   者: mxd
** 日   期: 2007/05/05
**---------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**---------------------------------------------------------------------------------
***********************************************************************************/
interrupt void extn_int4()
{ 
	INTR_GLOBAL_DISABLE();
	intr4_flag=1;
	fprintf(stdout,"******中断4响应******\n");
	INTR_GLOBAL_ENABLE();
}

/***************延时子程序***********/
void delay(unsigned int delay_num)
{
	unsigned int i;
	for(i = 0; i < delay_num; i ++)
	{
		
	}
}	


⌨️ 快捷键说明

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