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

📄 target.c

📁 这是一个本人编写修改的一个汇编ARM启动代码其中有一部分是用C写的
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               ZhaiHai Creawor Development Co.,LTD.
**                                 http://www.creawor.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:		target.c
** Last modified Date:	2004-11-01
** Last Version:	1.0
** 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:	    None
** Returned value:	    None
**         
** Used global variables:   None
** Calling modules:	    None
**
** Created by:	            Xuzhiping
** Created Date:	    2004/11/02
**------------------------------------------------------------------------------------------------------*/
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:	  None
** Returned value:	  None
**         
** Used global variables: None
** Calling modules:	  None
**
** Created by:		  Xuzhiping
** Created Date:	  2004/11/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------*/
/********************************************************************************************************/ 
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:	  None
** Returned value:	  None
**         
** Used global variables: None
** Calling modules:	  None
**
** Created by:		  xuzhiping
** Created Date:	  2004/11/02
**--------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------
***************************************************************************************************/
void TargetInit(void)
{
    /* 添加自己的代码 */
    /* Add your codes here */
}
/***************************************************************************************************
** Function name:	  TargetResetInit
**
** Descriptions:	  在运行main()函数之前初始化目标板; 如需要用户可以修改代码,当不能删除
**                        Initialize the target board before running the main() function; User
**                        may change it as needed, but may not deleted it.
** input parameters:	  None
** Returned value:	  None
**         
** Used global variables: None
** Calling modules:	  None
** Created by:		  xuzhiping
** Created Date:	  2004/11/02
**/
/*===================================================================================*/
/*                                 存储器映射控制                                    */
/*===================================================================================*/
void TargetResetInit(void)
{
  PCON  = 0X0;          // 关闭空闲模式和掉电模式
  PCONP = 0X800;        // 关闭所有外设,只打开外部存储器接口(EMC)
  #ifdef __DEBUG    
     MEMMAP = 0x3;      //remap 如是调试状态,用户外部存储器模式,
     //BCFG0  = 0X010000400; //16位配置存储器0速度最快,0X20000400 32位配置速度最快
  #endif                //中断向量从外部存储器重新映射

  #ifdef __OUT_CHIP    
     MEMMAP = 0x3;      //remap 如从片外运行,用户外部存储器模式,
  #endif                //中断向量从外部存储器重新映射

  #ifdef __IN_CHIP    
     MEMMAP = 0x1;      //remap 如从片内运行程序,用户Flash模式,
  #endif                //中断向量不重新映射
/*==============================================================================================*/
/*             Set system timers for each component 设置系统各部分时钟                          */
/*==============================================================================================*/
     PLLCON = 1;                   //PLL允许激活 PLLCON寄存器的第一位
  #if (Fpclk / (Fcclk / 4)) == 1   //VPB总线时钟位处理器时钟的1/4 
     VPBDIV = 0;                   //Fpclk = Fosc * 4 / 4
  #endif
  
  #if (Fpclk / (Fcclk / 5)) == 1   //VPB总线时钟位处理器时钟的1/4 
     VPBDIV = 0;                   //Fpclk = Fosc * 5 / 5
  #endif

  #if (Fpclk / (Fcclk / 4)) == 2   //VPB总线时钟位处理器时钟的1/2
     VPBDIV = 2;
  #endif
  #if (Fpclk / (Fcclk / 5)) == 2  //VPB总线时钟位处理器时钟的1/2
     VPBDIV = 2;
  #endif
  #if (Fpclk / (Fcclk / 4)) == 4   //VPB总线时钟位处理器时钟相同
     VPBDIV = 1;
  #endif
  #if (Fpclk / (Fcclk / 5)) == 4   //VPB总线时钟位处理器时钟相同 
     VPBDIV = 1;
  #endif
/*=============================================================================================*/
/*                               设置PLLCFG寄存器的M、P值                                      */
/*=============================================================================================*/
  #if (Fcco / Fcclk) == 2  
     PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5); 
  #endif

  #if (Fcco / Fcclk) == 4   
     PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5); //M=(Fcclk / Fosc) - 1) P=2 << 5 Fcclk=44     
  #endif
  #if (Fcco / Fcclk) == 4                      // Fcco = Fcclk * 2 * p ,  Fcclk = Fosc * 5
     PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5); //M=(Fcclk / Fosc) - 1) P=2 << 5 Fcclk=55.296
  #endif
  #if (Fcco / Fcclk) == 8                      
     PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5); //M=(Fcclk / Fosc) - 1) P=4 << 5 Fcclk=33.1776
  #endif

  #if (Fcco / Fcclk) == 16
     PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
  #endif

     PLLFEED = 0xaa;
     PLLFEED = 0x55;
     while((PLLSTAT & (1 << 10)) == 0);
     PLLCON = 3;
     PLLFEED = 0xaa;
     PLLFEED = 0x55;
/*====================================================================================*/    
/*                 Set memory accelerater module 设置存储器加速模块                   */
/*====================================================================================*/
     MAMCR = 0;              //存储器加速器模块控制寄存器,设置为禁止
  #if Fcclk < 20000000
     MAMTIM = 1;             //存储器加速器定时控制寄存器,取指周期为1个CPU时钟(cclk)
  #else
  #if Fcclk < 40000000
     MAMTIM = 2;             //取指周期为2个CPU时钟(cclk)
  #else
     MAMTIM = 3;             //取指周期为3个CPU时钟(cclk)
  #endif
  #endif
     MAMCR = 2;              //存储器加速器模块控制寄存器,设置为MAM功能完全允许
/*====================================================================================*/    
/*                         initialize VIC 初始化VIC                                   */
/*====================================================================================*/
  VICIntEnClr = 0xffffffff;
  VICVectAddr = 0;
  VICIntSelect = 0;

    /* 添加自己的代码 */
    /* Add your codes here */
}
/*====================================================================================*
**  以下为一些与系统相关的库函数的实现,具体作用请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
********************************************************************************************************/

⌨️ 快捷键说明

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