📄 c6x.c
字号:
#include <stdio.h>
#include <c6x.h>
#include "c6713dsk.h"
#include "dsp_usb.h"
extern unsigned int errorI,u,error,u1;
extern unsigned int setpoint,DDS_TappingV;
#define C6713PYP
void mem_write(int *Address,int tmp_data);
void Sys_Initialize()/*系统初始化函数*/
{
CSR=0x100; /* disable all interrupts */
IER=1; /* disable all interrupts except NMI */
ICR=0xffff; /* clear all pending interrupts */
EMIF_GCR = 0x00003078;
EMIF_CE1 = 0xffffff23;
//EMIF_CE2 = 0x10A1C212;
EMIF_CE2 = 0x10A1ff17; //ybh modify
EMIF_CE3 = 0x33d34f21;
//SDRAM SIGNAL SETTING
EMIF_CE0 = 0x90;
EMIF_SDCTRL = 0x07227000;
EMIF_SDRP = 0x61a;
EMIF_SDEXT = 0x54529;
CSR=0x101; /* enable all interrupts */
IER=0x4043; /* enable timer0 and external interrupt6 */
}
void ReadFlash_ID(void)
{
int i,tmp;
//*((volatile unsigned char*)FlashBaseAddr) = 0xf0;//reset flash
for(i=0;i<0x10;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr1_16 * 4) = 0xaa;
for(i=0;i<0x10;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr2_16 * 4) = 0x55;
for(i=0;i<0x10;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr3_16 * 4) = 0x90;
for(i=0;i<0x100;i++);
tmp = (*(volatile unsigned char*)(FlashBaseAddr));
printf(" The manufacture of Flash is %d!\n",tmp);
for(i=0;i<0x10;i++);
}
int mem_read(int *Address)
{
int Value;
Value=*(Address);
return Value;
}
void mem_write(int *Address,int tmp_data)
{
*(Address)=tmp_data;
}
/*-------------------------------------------------------------------------*/
/* mem_test() - used to test internal SRAM and external SDRAM */
/*-------------------------------------------------------------------------*/
int mem_test (int pattern, int start_address, int size_in_word )
{
int i;
int temp;
int error = 0;
int *mem_ptr = (int *)start_address;
for(i=0;i<size_in_word;i++) /* write pattern to the memory */
{
*mem_ptr++ = pattern;
}
mem_ptr = (int *)start_address;
for(i=0;i<size_in_word;i++) /* read data back from memory */
{
temp = *mem_ptr++;
if ( temp != pattern )
{
error++;
}
}
return error;
}
/*-------------------------------------------------------------------------*/
/* mem_test_alt() - used to test internal SRAM and external SDRAM */
/*-------------------------------------------------------------------------*/
int mem_test_alt (int pattern, int start_address, int size_in_word )
{
int i;
int temp_read,temp_expected;
int error = 0;
int *mem_ptr = (int *)start_address;
for(i=0;i<size_in_word;i++) /* write pattern to the memory */
{
if(i%2)
*mem_ptr++ = ~pattern; /* flip alternating bits */
else
*mem_ptr++ = pattern;
}
mem_ptr = (int *)start_address;
for(i=0;i<size_in_word;i++) /* read data back from memory */
{
temp_read = *mem_ptr++;
if(i%2)
{
temp_expected = ~pattern; /* flip alternating bits */
}
else
{
temp_expected = pattern;
}
#ifdef C6713PYP
temp_read = temp_read & 0xFFFF;
temp_expected = temp_expected & 0xFFFF;
#endif
if ( temp_read != temp_expected )
{
error++;
}
}
return error;
}
/*-------------------------------------------------------------------------*/
/* led_blink() - used to blink all the LEDS on the DSK */
/*-------------------------------------------------------------------------*/
void led_blink(int count, int ms_period)
{
int i;
for (i=0;i<count;i++)
{
*(unsigned volatile int *)IO_PORT = 0x7;/* turn on three leds */
delay_msec(ms_period/2);
*(unsigned volatile int *)IO_PORT = 0x0;/* turn off user leds */
delay_msec(ms_period/2);
// *(unsigned volatile int *)IO_PORT = 0x1;/* turn off user leds */
// *(unsigned volatile int *)IO_PORT = 0x2;/* turn off user leds */
// *(unsigned volatile int *)IO_PORT = 0x3;/* turn off user leds */
// *(unsigned volatile int *)IO_PORT = 0x4;/* turn off user leds */
//delay_msec(ms_period/2);
}
*(unsigned volatile int *)IO_PORT = 0x0; /* turn on three leds */
}
void delay_msec(short msec)
{
/* assume 150 MHz CPU timer period = 4/150 MHz */ //现在系统时钟是50M,现在是200M
int count =msec*12500*4;
int start;
*(unsigned volatile int *)TIMER0_CTRL=0;
*(unsigned volatile int *)TIMER0_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_PRD |= 0xffffffff;/* set for 32 bit cnt*/
*(unsigned volatile int *)TIMER0_COUNT=0; //使计数值清零
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0;
start=*(unsigned volatile int *)TIMER0_COUNT;
while(*(unsigned volatile int *)TIMER0_COUNT-start<count);
}
void delay_usec(int usec)
{
int count=usec*25/2*4;
int start;
*(unsigned volatile int *)TIMER0_CTRL=0;
*(unsigned volatile int *)TIMER0_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_PRD |= 0xffffffff;/* set for 32 bit cnt*/
*(unsigned volatile int *)TIMER0_COUNT=0; //使计数值清零
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0; /* start the timer */
start=*(unsigned volatile int *)TIMER0_COUNT;
while(*(unsigned volatile int *)TIMER0_COUNT-start<count);
}
void delay_CNT(unsigned int count)
{
int start;
*(unsigned volatile int *)TIMER0_CTRL=0; //使计数器状态清空
*(unsigned volatile int *)TIMER0_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_PRD |= 0xffffffff;/* set for 32 bit cnt*/
*(unsigned volatile int *)TIMER0_COUNT=0; //使计数值清零
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0; /* start the timer */
start=*(unsigned volatile int *)TIMER0_COUNT;
while(*(unsigned volatile int *)TIMER0_COUNT-start<count);
}
/*-------------------------------------------------------------------------*/
/* timer0_read() - used to read TIMER0 count */
/*-------------------------------------------------------------------------*/
int timer0_read()
{
int i;
i = *(unsigned volatile int *)TIMER0_COUNT;
return i;
}
/*-------------------------------------------------------------------------*/
/* timer0_start() - used to start TIMER0 */
/*-------------------------------------------------------------------------*/
void timer0_start()
{
*(unsigned volatile int *)TIMER0_CTRL &= 0xff3f; /* hold the timer */
*(unsigned volatile int *)TIMER0_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_PRD |= 0xffffffff;/* set for 32 bit cnt*/
*(unsigned volatile int *)TIMER0_COUNT=0;
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0; /* start the timer */
}
/*-------------------------------------------------------------------------*/
/* timer0_init() - used to initialize TIMER0 */
/*-------------------------------------------------------------------------*/
void timer0_init()
{
*(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;/* hold the timer */
*(unsigned volatile int *)TIMER0_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_PRD = 0x20; /* set for a short period*/
*(unsigned volatile int *)TIMER0_COUNT=0;
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0; /* start the timer */
/* enable timer0 int */
}
void timer1_start()
{
*(unsigned volatile int *)TIMER1_CTRL &= 0xff3f;/* hold the timer */
*(unsigned volatile int *)TIMER1_CTRL |= 0x200; /* use CPU CLK/4 */
*(unsigned volatile int *)TIMER1_PRD = 0xFFFFFFFF; /* set for a short period*/
*(unsigned volatile int *)TIMER1_COUNT=0;
*(unsigned volatile int *)TIMER1_CTRL |= 0x3C0; /* start the timer */
/* enable timer1 int */
}
int timer1_read()
{
int i;
i = *(unsigned volatile int *)TIMER1_COUNT;
return i;
}
void timer1_stop()
{
*(unsigned volatile int *)TIMER1_CTRL=0;
*(unsigned volatile int *)TIMER1_PRD = 0xFFFFFFFF;
*(unsigned volatile int *)TIMER1_COUNT=0;
}
//////////////////////////////////////////////////////////
void time_delay(int aaa)
{
int iiii;
for (iiii=0;iiii<aaa;iiii++)
{}
}
void motor_up()
{
time_delay(100);
*(unsigned volatile int *)HVA_LOW = 0x00;
time_delay(100);
*(unsigned volatile int *)HVA_LOW = 0x10;
}
void motor_down()
{
time_delay(100);
*(unsigned volatile int *)HVA_LOW = 0x20;
time_delay(100);
*(unsigned volatile int *)HVA_LOW = 0x30;
}
unsigned short Read_ADC(unsigned int a)
{
switch(a)
{
case AD_Control:
*(unsigned volatile int *)AD_Control=0x0;
while((*(unsigned volatile int *)AD_State)&0x01){}
return *(unsigned volatile int *)AD_Control;
case AD_Image:
*(unsigned volatile int *)AD_Image=0x0;
while((*(unsigned volatile int *)AD_State)&0x02){}
return *(unsigned volatile int *)AD_Image;
case AD_Adc:
*(unsigned volatile int *)AD_Adc=0x0;
while((*(unsigned volatile int *)AD_State)&0x04){}
return *(unsigned volatile int *)AD_Adc;
default:
break;
}
return(0);
}
////////////////////////////////////////////////////
unsigned int DDS_data(unsigned int d,unsigned int c)
{
int a,b,i;
b=d&0xff000000;
b=b>>24;
c=c<<12;
b=b|c|0x0300;
a=b>>8;
*(unsigned volatile int *)S_DDS_CLK=0x3;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
a=b;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
//----------------------------------------------
b=d&0x00ff0000;
b=b>>16;
b=b|c|0x0200;
a=b>>8;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
a=b;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
//----------------------------------------------
b=d&0x0000ff00;
b=b>>8;
b=b|c|0x0100;
a=b>>8;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
a=b;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
//----------------------------------------------
b=d&0x000000ff;
b=b|c|0x0000;
a=b>>8;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
a=b;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=a;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(100);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(100);
a=a<<1;
}
//----------------------------------------------
*(unsigned volatile int *)S_DDS_CLK=0x3;
return(0);
}
/////////////////////////////////////////////////
unsigned int DDS_command(unsigned int a)
{
int b,i;
*(unsigned volatile int *)S_DDS_CLK=0x3;
b=a>>8;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=b;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(10);
b=b<<1;
}
b=a;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=b;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(10);
b=b<<1;
}
*(unsigned volatile int *)S_DDS_CLK=0x3;
return 0;
}
unsigned int DDS_data1(unsigned int data,unsigned int cmd,unsigned int addr)
{
int aa,bb,i;
bb=data&0xff;
cmd=cmd<<12;
addr=addr<<8;
bb=bb|cmd|addr;
aa=bb>>8;
*(unsigned volatile int *)S_DDS_CLK=0x3;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=aa;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(10);
aa=aa<<1;
}
aa=bb&0xff;
for(i=0;i<=7;i++)
{
*(unsigned volatile int *)S_DDS_DATA=aa;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x01;
time_delay(10);
*(unsigned volatile int *)S_DDS_CLK=0x00;
time_delay(10);
aa=aa<<1;
}
*(unsigned volatile int *)S_DDS_CLK=0x3;
return 0;
}
//----------------------------------------------
unsigned int stepmotordown(unsigned int data)
{
int i,b;
int a[8]={0x0a,0x08,0x09,0x01,0x05,0x04,0x06,0x02};
for(i=0;i<=data;i++)
{
b=i%8;
*(unsigned volatile int *)HVA_LOW=a[b];
time_delay(30000);
}
return 0;
}
unsigned int stepmotorup(unsigned int data)
{
int i,b;
int a[8]={0x02,0x06,0x04,0x05,0x01,0x09,0x08,0x0a};
for(i=0;i<=data;i++)
{
b=i%8;
*(unsigned volatile int *)HVA_LOW=a[b];
time_delay(30000);
}
return 0;
}
void OneStep(unsigned char bForB)
{
static int i=0;
static int a[8]={0x02,0x06,0x04,0x05,0x01,0x09,0x08,0x0a};
if(i<0)i=7;
if(i>=8)i=0;
*(unsigned volatile int *)HVA_LOW=a[i];
time_delay(10000);
if(bForB==1)i++;
else i--;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -