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

📄 target.c

📁 USB测试程序
💻 C
字号:
/****************************************Copyright (c)**************************************************

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

#define IN_TARGET
#include "config.h"


/*********************************************************************************************************
** Function name:			IRQ_Exception
********************************************************************************************************/

void __irq IRQ_Exception(void)
{
    while(1);                   //  change it to your code 这一句替换为自己的代码
}


/*********************************************************************************************************
** Function name:			FIQ_Exception
********************************************************************************************************/

void FIQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}


/*********************************************************************************************************
** Function name:			PLL_Config
********************************************************************************************************/

void  PLL_Init (void)
{
    uint32  m;
    uint32  n;
    uint32  cClkDiv;
    uint32  usbClkDiv;

    m           =       11;        			// PLL Multiplier = 12, MSEL bits = 12 - 1 = 11
    n           =        0;        			// PLL Divider    =  1, NSEL bits =  1 - 1 =  0
    cClkDiv     =        5;        			// Configure the  ARM Core clock div to 6. CCLKSEL =  6 - 1
    usbClkDiv   =        5;        			// Configure the USB clock divider to 6, USBSEL  = 6 - 1

    if ((PLLSTAT & (1 << 25)) > 0)     		// If the PLL is already running
    {
        PLLCON  &= ~(1 << 1);          		// Disconnect the PLL
        PLLFEED  =    0xAA;            		// PLL register update sequence, 0xAA, 0x55
        PLLFEED  =    0x55;
    }
    
    PLLCON     &= ~(1 << 0);     			// Disable the PLL
    PLLFEED     =     0xAA;      			// PLL register update sequence, 0xAA, 0x55
    PLLFEED     =     0x55;
    
    SCS         &= ~(1 << 4);     			// OscRang = 0, Main Osc is between 1 and 20 Mhz
	SCS         |=  (1 << 5);     			// OscEn = 1, Enable the main oscillator
    while ((SCS &  (1 << 6)) == 0); 		// Wait until OSCSTAT is set (Main OSC ready to be used)
    
    CLKSRCSEL   =  (1 << 0);	    		// Select main OSC, 12MHz, as the PLL clock source
    
    PLLCON      = 		1;     	 			// Enable the PLL
    PLLCFG      =  (m << 0) | (n << 16);    // Configure the PLL multiplier and divider
    PLLFEED     =     0xAA;      			// PLL register update sequence, 0xAA, 0x55
    PLLFEED     =     0x55;

    CCLKCFG     =   cClkDiv;       			// Configure the ARM Core Processor clock divider
    USBCLKCFG   =   usbClkDiv;     			// Configure the USB clock divider

	while ((PLLSTAT & (1 << 26)) == 0);		// Wait for PLOCK to become set
    PLLCON      = 		3;					// Connect the PLL. The PLL is now the active clock source
    PLLFEED     =     0xAA;      			// PLL register update sequence, 0xAA, 0x55
    PLLFEED     =     0x55;
    while ((PLLSTAT & (1 << 25)) == 0) ;   	// Wait PLLC, the PLL connect status bit to become set
}



void  VIC_Init (void)
{
    VICIntEnClr = 0xFFFFFFFF; 
    VICVectAddr = 0;                          // Acknowlege any pending VIC interrupt
    VICProtection = 0;                        // Allow VIC register access in User of 	Priviledged modes
}


void TargetInit(void)
{
   	bell_init();

	VIC_Init();
    uart0_init(115200);
    usb_init();
}


void TargetResetInit(void)
{

    MEMMAP = 0x01;							// 从内部flash启动
    PLL_Init ();
    PCLKSEL0=0;								// Fpclk全部设为 Fcclk/4
    PCLKSEL1=0;
}

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