📄 c6x.c
字号:
#include <stdio.h>
#include <c6x.h>
#include "c6713dsk.h"
#include "dsp_usb.h"
#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 = 0x320; /* EMIF global control 0x3300*/
EMIF_CE0 = 0x30; /* EMIF CE0control */
EMIF_CE1 = 0xffffff23; /* EMIF CE1 control, 32bit async */
EMIF_CE2 = 0x00e00322; /* EMIF CE2 control 0x21320423 0x00900221*/
EMIF_CE3 = 0x23; /* EMIF CE3 control */
EMIF_SDCTRL = 0x07227000; /* EMIF SDRAM control */
EMIF_SDRP = 0x61a; /* EMIF SDRM refresh period */
EMIF_SDEXT = 0x54529; /* EMIF SDRAM extension */
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));
//mem_write(0x80000000,tmp);
printf(" The manufacture of Flash is %d!\n",tmp);
for(i=0;i<0x10;i++);
}
void WriteIsOver(void)
{
unsigned int i;
unsigned char LastToggleBit,CurrentToggleBit;
LastToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0x40;
CurrentToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0x40;
for(i = 0; ; i++)
{
LastToggleBit = CurrentToggleBit;
CurrentToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0x40;
if(LastToggleBit == CurrentToggleBit) break;
}
}
void EraseChip(void)
{
*(volatile unsigned char*)(FlashBaseAddr + Addr1_16 * 4) = 0xaa;
*(volatile unsigned char*)(FlashBaseAddr + Addr2_16 * 4) = 0x55;
*(volatile unsigned char*)(FlashBaseAddr + Addr3_16 * 4) = 0x80;
*(volatile unsigned char*)(FlashBaseAddr + Addr4_16 * 4) = 0xaa;
*(volatile unsigned char*)(FlashBaseAddr + Addr5_16 * 4) = 0x55;
*(volatile unsigned char*)(FlashBaseAddr + Addr6_16 * 4) = 0x10;
WriteIsOver();
}
void WriteByte(unsigned int Addr,unsigned char Val)
{
// int i=0;
*(volatile unsigned char*)(FlashBaseAddr + Addr1_16 * 4) = 0xaa;
// for(i=0;i<100;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr2_16 * 4) = 0x55;
// for(i=0;i<100;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr3_16 * 4) = 0xa0;
// for(i=0;i<100;i++);
*(volatile unsigned char*)(FlashBaseAddr + Addr*4) = Val;
// for(i=0;i<100;i++);
WriteIsOver();
}
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, unsigned int leds_to_light)
{
int i;
for(i=0;i<count;i++)
{
*(char *)0xb020003c=0x1;/* turn on three leds */
delay_msec(ms_period/2);
//*(unsigned volatile int *)IO_PORT = 0x2;/* turn off user leds */
//delay_msec(ms_period/2);
*(char *)0xb020003c=0x0;/* turn off user leds */
delay_msec(ms_period/2);
}
//*(unsigned volatile int *)IO_PORT = 0x0; /* turn on three leds */
}
/*-------------------------------------------------------------------------*/
/* delay_msec() - used to delay DSP by user specified time in msec */
/*-------------------------------------------------------------------------*/
void delay_msec(short msec)
{
/* assume 150 MHz CPU timer period = 4/150 MHz */
int timer_limit = (msec*9375)<<2;
int time_start;
timer0_start();
time_start = timer0_read();
while ((timer0_read()-time_start) < timer_limit);
}
/*-------------------------------------------------------------------------*/
/* 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_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_CTRL |= 0x3C0; /* start the timer */
/* enable timer0 int */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -