/****************************************Copyright (c)**************************************************
** 源享教育 嵌入式高端人才的成长摇篮
** www.yxarm.net
**
**
**----------------------------------------文件信息------------------------------------------------------
** 文件名: TargetInit.c
** 编写人: 刘凯
** 修改时间: 2007-10-5
** 描述: 目标板的初始化设置文件,启动代码的一部分
** 根据需要,用户可以自己修改
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define IN_TARGET
#include "whole.h"
/*********************************************************************************************************
** 函数名称: FIQ_Exception
** 编写人:
** 功能描述: 快速中断处理函数,根据需要修改
** 入口参数:
** 返回参数:
********************************************************************************************************/
void FIQ_Exception(void)
{
while(1); // 这一句替换为自己的代码
}
/*********************************************************************************************************
** 函数名称: TargetInit
** 编写人:
** 功能描述: 实验板(箱)的初始化配置函数,你可根据需要修改
** 入口参数:
** 返回参数:
********************************************************************************************************/
void TargetInit(void)
{
//-----------------初始化系统时钟-------------------
PLLCON = 1; //PLL使能
/*根据Fpclk和Fcclk的设置(在whole.h头文件里定义了),配置VPBDIV寄存器*/
#if (Fpclk / (Fcclk / 4)) == 1
VPBDIV = 0;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
VPBDIV = 2;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
VPBDIV = 1;
#endif
/*根据Fcco和Fcclk的设置(在whole.h头文件里定义了),配置PLLCFG寄存器*/
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55; //两个连续的PLLFEED写操作,确定以上的配置生效
// while((PLLSTAT & (1 << 10)) == 0); //等待PLL锁定,否则一直等
PLLCON = 3; //PLL使能,并且PLL连接
PLLFEED = 0xaa;
PLLFEED = 0x55;
//-----------------初始化存储器系统-------------------
BCFG0 = 0x1000ffef; //外部存储器Bank0~Bank3控制器设置,配置成最慢的外部总线速度
BCFG1 = 0x1000ffef;
BCFG2 = 0x2000ffef;
BCFG3 = 0x2000ffef;
MEMMAP = 0x3; //存储器映射控制,选择用户外部存储器模式
MAMCR = 0; //存储器加速模块
#if Fcclk < 20000000
MAMTIM = 1;
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
//-----------------初始化VIC中断系统-------------------
VICIntEnClr = 0xffffffff; //关闭所有中断,并且中断地址清0
VICVectAddr = 0;
VICIntSelect = 0;
//-----------------配置引脚功能------------------------
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
PINSEL2 = 0x0fe14914; //PINSEL2寄存器设置
//-----------------其他初始化--------------------------
IO1DIR=IO1DIR | (1<<24);
IO1SET=IO1SET | (1<<24);
//添加自己的初始化代码
}
/*********************************************************************************************************
** 以下为一些与系统相关的库函数的实现
** 具体作用请ads的参考编译器与库函数手册
** 用户可以根据自己的要求修改
********************************************************************************************************/
#include "rt_sys.h"
#include "stdio.h"
//#pragma import(__use_no_semihosting_swi)
//#pragma import(__use_two_region_memory)
int __rt_div0(int a)
{
a = a;
return 0;
}
int fputc(int ch,FILE *f)
{
ch = ch;
f = f;
return 0;
}
int fgetc(FILE *f)
{
f = f;
return 0;
}
int _sys_close(FILEHANDLE fh)
{
fh = fh;
return 0;
}
int _sys_write(FILEHANDLE fh, const unsigned char * buf,
unsigned len, int mode)
{
fh = fh;
buf = buf;
len =len;
mode = mode;
return 0;
}
int _sys_read(FILEHANDLE fh, unsigned char * buf,
unsigned len, int mode)
{
fh = fh;
buf = buf;
len =len;
mode = mode;
return 0;
}
void _ttywrch(int ch)
{
ch = ch;
}
int _sys_istty(FILEHANDLE fh)
{
fh = fh;
return 0;
}
int _sys_seek(FILEHANDLE fh, long pos)
{
fh = fh;
return 0;
}
int _sys_ensure(FILEHANDLE fh)
{
fh = fh;
return 0;
}
long _sys_flen(FILEHANDLE fh)
{
fh = fh;
return 0;
}
int _sys_tmpnam(char * name, int sig, unsigned maxlen)
{
name = name;
sig = sig;
maxlen = maxlen;
return 0;
}
void _sys_exit(int returncode)
{
returncode = returncode;
}
char *_sys_command_string(char * cmd, int len)
{
cmd = cmd;
len = len;
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/