📄 target.c
字号:
/******************************************************************************************************
** File name: target.c
** Descriptions: header file of the specific codes for LPC2200 target boards
** Every project should include a copy of this file, user may modify it as needed
********************************************************************************************************/
#define IN_TARGET
#include "config.h"
/*********************************************************************************************************
** Function name: IRQ_Exception
**
** Descriptions: interrupt exceptional handler , change it as needed
**
** input parameters: 无
** Returned value: 无
**
** Used global variables: 无
** Calling modules: 无
********************************************************************************************************/
void __irq IRQ_Exception(void)
{
while(1); // change it to your code 这一句替换为自己的代码
}
/*********************************************************************************************************
** Function name: FIQ_Exception
**
** Descriptions: Fast interrupt exceptional handler , change it as needed
**
** input parameters: 无
** Returned value: 无
**
** Used global variables: 无
** Calling modules: 无
**
********************************************************************************************************/
void FIQ_Exception(void)
{
while(1); // change it to your code 这一句替换为自己的代码
}
/*********************************************************************************************************
** Function name: TargetInit
**
** Descriptions: Initialize the target board; it is called in a necessary place, change it as
** needed
**
** input parameters: 无
** Returned value: 无
**
** Used global variables: 无
** Calling modules: 无
**
********************************************************************************************************/
void TargetInit(void)
{
/* 添加自己的代码 */
/* Add your codes here */
}
/*********************************************************************************************************
** Function name: TargetResetInit
**
** Descriptions: Initialize the target board before running the main() function; User may
** change it as needed, but may not deleted it.
**
** input parameters: 无
** Returned value: 无
**
** Used global variables: 无
** Calling modules: 无
********************************************************************************************************/
void TargetResetInit(void)
{
#ifdef __DEBUG
MEMMAP = 0x3; //remap,对0X00000008读数/取指就是从片外0x80000000单元进行操作
#endif
#ifdef __OUT_CHIP
MEMMAP = 0x3; //remap, 对0X00000008读数/取指就是从片外0x80000000单元进行操作
#endif
#ifdef __IN_CHIP
MEMMAP = 0x1; //remap, 对0X00000008读数/取指就是从片外0x00000000单元进行操作
#endif
/* 设置系统各部分时钟 */
/* Set system timers for each component,其中cclk=M*Fosc,cclk=Fcco/(2*P),M、P分别是PLLCFG的低5位,高2位*/
PLLCON = 1;
#if (Fpclk / (Fcclk / 4)) == 1
VPBDIV = 0;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
VPBDIV = 2;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
VPBDIV = 1;
#endif
#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,才能使PLLCON 和 PLLCFG更改生效*/
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0); /*判断PLLSTAT的PLOCK位是否为0,是,则表明PLL为锁定,否,则表明PLL锁定到指定频率*/
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
/* 设置存储器加速模块 */
/* Set memory accelerater module,由于LPC2210没有片内FLASH,MAM设置无效*/
MAMCR = 0;
#if Fcclk < 20000000
MAMTIM = 1; /*当改变MAM定时值时,必须先通过向MAMCR写入0关闭MAM,然后将新值写入MAMTIM。最后将需要的操作模式
的对应值(1或2)写入MAMCR,再次打开MAM。*/
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
/* 初始化VIC */
/* initialize VIC*/
VICIntEnClr = 0xffffffff; /*写1清零VICIntEnable中断使能寄存器中的对应位并禁止对应的中断请求*/
VICVectAddr = 0; /*写0将清零内部中断优先级硬件当中对应的标志*/
VICIntSelect = 0; /*写0,对应的中断请求分配为IRQ*/
/* 添加自己的代码 */
/* Add your codes here */
}
/*********************************************************************************************************
** 以下为一些与系统相关的库函数的实现
** 具体作用请参考ads的编译器与库函数手册
** 用户可以根据自己的要求修改
********************************************************************************************************/
/*********************************************************************************************************
** The implementations for some library functions
** For more details, please refer to the ADS compiler handbook and The library
** function manual
** User could change it as needed
********************************************************************************************************/
#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
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -