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

📄 target.c

📁 LPC2366低功耗测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:


/*********************************************************************************************************
** Function name:			Timer0Init
**
** Descriptions:			Initialize the Time0
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:wangbiao
** Modified date:2007/11/22
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void Timer0Init(void)
{
    
    uint32  pclk_freq;
    uint32  rld_cnts;

    T0IR = 0xffffffff;                                                            /* VIC timer #0 Initialization                              */

    pclk_freq     =   BSP_CPU_PclkFreq(PCLK_TIMER0);            /* Get the peripheral clock frequency                       */

    rld_cnts      =   pclk_freq / OS_TICKS_PER_SEC;             /* Calculate the # of counts necessary for the OS ticker    */

    T0TCR         =  (1 << 1);                                  /* Disable and reset counter 0 and the prescale counter 0   */
    T0TCR         =   0;                                        /* Clear the reset bit                                      */
    T0PC          =   0;                                        /* Prescaler is set to no division                          */

    T0MR0         =   rld_cnts;
    T0MCR         =   3;                                        /* Interrupt on MR0 (reset TC), stop TC                     */

    T0CCR         =   0;                                        /* Capture is disabled.                                     */
    T0EMR         =   0;                                        /* No external match output.                                */
    T0TCR         =   1;
 }
 
/****************************************************************************************************

*名称:RTCIni()
*功能:初始化实时时钟

*****************************************************************************************************/

void RTCIni(void)
{
	//uint32  pclk_freq;	
	RTC_ILR =0X03;
	//pclk_freq     =   BSP_CPU_PclkFreq(PCLK_RTC);
	//RTC_PREINT = pclk_freq/32768-1;                        //设置基准时钟分频器
	//RTC_PREFRAC = pclk_freq - (pclk_freq/32768)*32768;
	
	RTC_YEAR = 2007;                                       //初始化年,月,日
	RTC_MONTH= 12;
	RTC_DOM  = 29;
	RTC_HOUR=10;
	RTC_MIN=0;
	RTC_SEC=0;
	
	//RTC_CIIR = 0x01;                                       //是指秒值得增量产生一次中断?
	RTC_AMR = 0XFE;
	
	RTC_CCR  = 0x11;                                        //启动RTC
}
/*********************************************************************************************************
** Function name:			VICInit
**
** Descriptions:			Initialize the Interrupt Vevtor Controller
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:             wangbiao
** Modified date:           2007/09/07
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/*****************************************************************************************
中断优先级排序: 脉冲中EINT1(1)  TIME0中断(系统时钟) (0)   UART0,1,2,3中断(2\3\4\5)  CAN中断() 
 键盘中断EINT0 (8)  I2C中断(9)  USB中断EINT2(10)   RTC中断(11)  按键唤醒中断EINT3(12)
******************************************************************************************/

        void VICInit(void)
{
   //在下面添加相关中断声明
    extern void Timer0_Handler(void);
    extern void EINT1_Handler(void);
	extern void RTC_Handler(void);
	
	
	
	
	
	
    VICIntEnClr = 0xffffffff;
    
	VICIntSelect &= ~(1 << VIC_TIMER0);                         /* Configure the timer interrupt as an IRQ source           */
    VICVectAddr4  =  (uint32)Timer0_Handler;           /* Set the vector address                                   */
    VICIntEnable  =  (1 << VIC_TIMER0);                         /* Enable the timer interrupt source                        */

    
    //在下面添加相关中断配置代码
    
    //PULSE中断
   
   
   
   //UART INT 
   
    
    
    //CAN INT
    
    //键盘中断EINT1 (8)
    
    VICIntSelect &= ~(1 << VIC_EINT1);  
    VICVectAddr15 = (uint32)EINT1_Handler;
    INTWAKE = 1<<1;	                    	// 允许外部中断1唤醒掉电的CPU
    EXTINT = 1<<1;					    	// 清除EINT1中断标志
    VICIntEnable = (1 << 15 ); 
    
    
    //键盘中断EINT0 (8)
   //VICIntSelect &= ~(1 << VIC_EINT0);  
  //VICVectAddr0 = (uint32)EINT0_Handler;
   // VICVectCntl0 = (0x20 |(1 << 14));
   // VICIntEnable = (1 << 14 ); 
    
    
     //I2C中断
     
     
    //USB INT
  
    
    //RTC INT
    VICIntSelect &= ~(1 << VIC_RTC);                         /* Configure the timer interrupt as an IRQ source           */
    VICVectAddr13  =  (uint32)RTC_Handler;           // Set the vector address  
    INTWAKE = 1<<15;	                    	// 允许RTC唤醒掉电的CPU                                */
    VICIntEnable  =  (1 << VIC_RTC);
    //EINT3 INT (按键唤醒中断)
   
    
 }

/*********************************************************************************************************
** 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:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void TargetInit(void)
{
    OS_ENTER_CRITICAL();
    srand((uint32) TargetInit);
    VICInit();
    Timer0Init();
    OS_EXIT_CRITICAL();
}

/*********************************************************************************************************
** Function name:			InitialiseUART0
**
** Descriptions:			Initialize the Uart0
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

        void InitialiseUART0(uint32 bps)
{  	
    uint32 Fdiv;
    uint32  pclk_freq;


    pclk_freq     =   BSP_CPU_PclkFreq(PCLK_UART0);            /* Get the peripheral clock frequency                       */

    PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05;    /* Select the pins for Uart 选择管脚为UART0 */

    U0LCR = 0x80;                               /* Enable to access the frequenc regecter 允许访问分频因子寄存器 */
    Fdiv = (pclk_freq / 16) / bps;                  /* Set the baudrate设置波特率 */
    U0DLM = Fdiv / 256;							
	U0DLL = Fdiv % 256;						
    U0LCR = 0x03;                               /* Disable to access the frequenc regecter 禁止访问分频因子寄存器 */
                                                /* set to 8,1,n 且设置为8,1,n */
	U0IER = 0x00;                               /* Disable interrupt禁止中断 */
    U0FCR = 0x00;                               /* initial FIFO 初始化FIFO */
} 

/*********************************************************************************************************
** Function name:			TargetResetInit
**
** Descriptions:			Initialize the target 
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:    wangbiao
** Modified date:  2007/11/20
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void TargetResetInit(void)
{

	uint32	Fcclk;
#ifdef __DEBUG    
    MEMMAP = 0x3;                   //remap
#endif

#ifdef __OUT_CHIP    
    MEMMAP = 0x3;                   //remap
#endif

#ifdef __IN_CHIP    
    MEMMAP = 0x1;                   //remap
#endif

//    PINSEL0 = (PINSEL0 & 0xFFFF0000) | 0x05 | 0x50;

/* 设置系统各部分时钟 */
/* Set system timers for each component */


//PLL INIT

	PLL_Init();
	
	Fcclk =  BSP_CPU_ClkFreq ();

/* 设置存储器加速模块 */
/* Set memory accelerater module*/
    MAMCR = 0;													/* Disable MAM functionality */

    if (Fcclk < 20000000) {                                  /* Compare current clock frequency with MAM modes           */
        MAMTIM = 1;                                             /* Set MAM fetch cycles to 1 processor clock in duration    */
    }

    if (Fcclk < 40000000) {
        MAMTIM = 2;                                             /* Set MAM fetch cycles to 2 processor clock in duration    */
    }

    if (Fcclk >= 40000000) {
        MAMTIM = 3;                                             /* Set MAM fetch cycles to 3 processor clock in duration    */
    }

    MAMCR = 2;                                                  /* Enable full MAM functionality                            */

/* 设置串行口 */
/* initialize UART*/
    InitialiseUART0(115200);

/* 设置实时时钟 */
/* initialize RTC*/

#if 0
    CCR = 1;
    PREINT = Fpclk / 32768 - 1;
    PREFRAC = Fpclk - (Fpclk / 32768) * 32768;
    YEAR = 2003;
    MONTH = 6;
    DOM = 2;
#endif
	/*EXTINT的中断触发方式采取默认方式,如果需要修改请在下面添加EXTMODE、EXTPOLAR初始化程序*/
	PINSEL4  = 0x01<<22;
    EXTMODE= EXTMODE & 0x0d;
    EXTPOLAR= EXTPOLAR & 0x0d;
	
	
	
/* initialize VIC*/
    VICIntEnClr = 0xffffffff;
    VICVectAddr = 0;
    VICIntSelect = 0;
    T0IR = 0xffffffff;
    T0TCR = 0X02;
}





/*********************************************************************************************************
**                  以下为一些与系统相关的库函数的实现
**                  具体作用请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 + -