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

📄 target.c

📁 ucos 在smartarm2200上的移植
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                                       SDT  TeTong1       
**
**--------------File Info-------------------------------------------------------------------------------
** Created by:			ZengFan
** Created date:		2009/03/30
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/

#define IN_TARGET

#include  "Includes.h"

/*********************************************************************************************************
** Function name:			OS_CPU_ExceptHndlr
**
** Descriptions:			exceptional handler , change it as needed
**
** input parameters:		except_id
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				ZengFan
** Created Date:			          
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

void  OS_CPU_ExceptHndlr (INT32U  except_id)
{
    CPU_FNCT_VOID   pfnct;


    if ((except_id == OS_CPU_ARM_EXCEPT_IRQ) ||(except_id == OS_CPU_ARM_EXCEPT_FIQ))
        
     {
        pfnct = (CPU_FNCT_VOID)VICVectAddr;                         /* Read the interrupt vector from the VIC                   */
        
        if (pfnct != (CPU_FNCT_VOID)0)                              /* Make sure we don't have a NULL pointer                   */
        {                                                           
          (*pfnct)();                                               /* Execute the ISR for the interrupting device              */
        }
     }
}


/*********************************************************************************************************
** 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:				Chenmingji
** Created Date:			          
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void 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:				Chenmingji
** Created Date:		 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void FIQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}
/*********************************************************************************************************
** Function name:			Timer0_Exception
**
** Descriptions:			Timer0 interrupt service function
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:		 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void Timer0_Exception(void)
{
    T0IR = 0x01;
    VICVectAddr = 0;            //interrupt close 通知中断控制器中断结束
    OSTimeTick();
}

/*********************************************************************************************************
** 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:			 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void Timer0Init(void)
{
    T0IR = 0xffffffff;
    T0TC = 0;
    T0TCR = 0x01;
    T0MCR = 0x03;
    T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
 }

/*********************************************************************************************************
** 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:	 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**
** Descriptions:            当中断发生时,不管是FIQ、IRQ、还是非向量IRQ,这三种的中断服务程序的地址都是存
**                          放在寄存器VICVectAddr,这点与AT91SAM7X256不一样
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void VICInit(void)
{
    VICIntEnClr = 0xffffffff;
    VICDefVectAddr = (uint32)IRQ_Exception;                     // 这是非向量IRQ

    VICVectAddr0 = (uint32)Timer0_Exception;                    // 这是向量IRQ
    VICVectCntl0 = (0x20 | 0x04);
    VICIntEnable = 1 << 4;
 }

/*********************************************************************************************************
** 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:		 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void TargetInit(void)
{

    #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
        OS_CPU_SR  cpu_sr = 0;
    #endif
    
    OS_ENTER_CRITICAL();
    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:		 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

        void InitialiseUART0(uint32 bps)
{  	
    uint16 Fdiv;
    
    PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05;    /* Select the pins for Uart 选择管脚为UART0 */

    U0LCR = 0x80;                               /* Enable to access the frequenc regecter 允许访问分频因子寄存器 */
    Fdiv = (Fpclk / 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:		 
**-------------------------------------------------------------------------------------------------------
** Modified by:             ZengFan
** Modified date:           2009/03/26
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void TargetResetInit(void)
{
#ifdef __DEBUG    
    MEMMAP = 0x3;                   //remap,详见用户手册(中文版)32页
#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 */
    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 = 0x55;
    while((PLLSTAT & (1 << 10)) == 0);
    PLLCON = 3;
    PLLFEED = 0xaa;
    PLLFEED = 0x55;

/* 设置存储器加速模块 */
/* Set memory accelerater module*/
    MAMCR = 0;
#if Fcclk < 20000000
    MAMTIM = 1;
#else
#if Fcclk < 40000000
    MAMTIM = 2;
#else
    MAMTIM = 3;
#endif
#endif
    MAMCR = 2;

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

/* 设置实时时钟 */
/* initialize RTC*/
    CCR = 1;
    PREINT = Fpclk / 32768 - 1;
    PREFRAC = Fpclk - (Fpclk / 32768) * 32768;
    YEAR = 2003;
    MONTH = 6;
    DOM = 2;
/* 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 + -