?? target.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: target.c
** Last modified Date: 2004-09-17
** Last Version: 1.0
** Descriptions: header file of the specific codes for LPC2100 target boards
** Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-02-02
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: Chenmingji
** Modified date: 2004-09-17
** Version: 1.01
** Descriptions: Renewed the template, added more compiler supports
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#define IN_TARGET
#include "config.h"
/*********************************************************************************************************
** Function name: SetISR
**
** 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 SetISR(unsigned int Channel, unsigned int PRI, unsigned int Function)
{
(&VICVectAddr0)[Channel] = Function;
(&VICVectPri0)[Channel] = PRI;
VICIntEnable = 1 << Channel;
}
/*********************************************************************************************************
** 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: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
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: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
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: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Timer0Init(void)
{
T0CTCR = 0x00; //timer0 work in timer mode
T0TCR = 0x02; //stop timer0
T0IR = 0xffffffff; //Clean all timer0 interrupt flag
T0TC = 0;
T0MCR = 0x03;
T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
T0TCR = 0x01;
}
/*********************************************************************************************************
** 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: 李仲生
** Modified date: 2007/01/16
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void VICInit(void)
{
VICIntEnClr = 0xffffffff;
SetISR(4, 4, (unsigned int)Timer0_Exception);
// VICVectAddr4 = (uint32)Timer0_Exception;
// VICVectPri4 = 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: 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: 2007/01/16
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void InitialiseUART0(uint32 bps)
{
uint16 Fdiv;
PINSEL0 = (PINSEL0 & 0xffffff0f) | 0x50; /* 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: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by: 李仲生
** Modified date: 2007/01/16
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void TargetResetInit(void)
{
#ifdef __DEBUG_RAM
MEMMAP = 0x2; // remap
#endif
#ifdef __DEBUG_FLASH
MEMMAP = 0x1; // remap
#endif
#ifdef __IN_CHIP
MEMMAP = 0x1; // remap
#endif
SCS = (SCS & 0x04)|0x20; // Enable the main OSC,,1MHz~20MHz
while((SCS & 0x40) == 0 ); // Wait until main OSC is usable
if ( PLLSTAT & (1 << 25) ) // if the PLL was connected
{
PLLCON = 0x01;
PLLFEED = 0xAA; // disconnect the PLL
PLLFEED = 0x55;
PLLCON = 0x00;
PLLFEED = 0xAA; // disable the PLL
PLLFEED = 0x55;
}
else if ( PLLSTAT & (1 << 24) ) // if the PLL was enabled // 如果PLL已被使能,則先禁止PLL
{
PLLCON = 0x00;
PLLFEED = 0xAA; // disable the PLL
PLLFEED = 0x55;
}
CLKSRCSEL = 0x01; // select main OSC as the PLL clock source
PLLCON = 1; // Enable but disconnect the PLL
PLLCFG = (((PLL_NValue-1) << 16)|(PLL_MValue-1) ); // set the PLLCFG
PLLFEED = 0xAA; // Enable PLL
PLLFEED = 0x55;
while (((PLLSTAT & (1 << 24)) == 0)); // Wait until the PLL is usable
CCLKCFG = (Fcco/Fcclk - 1); // set the CCLKCFG
PLLCON = 3; // connect the PLL
PLLFEED = 0xAA;
PLLFEED = 0x55;
while (((PLLSTAT & (3 << 25))!= (3 << 25))); // Wait until the PLL is connected and locked
#if USE_USB
PCONP |= 0x80000000; // Turn On the USB PCLK
USBCLKCFG = (Fcco/Fusbclk - 1);
#endif
// Set system timers for each component
#if (Fpclk / (Fcclk / 4)) == 1
PCLKSEL0 = 0x00000000; // PCLK is 1/4 CCLK
PCLKSEL1 = 0x00000000;
#else
#if (Fpclk / (Fcclk / 4)) == 2
PCLKSEL0 = 0xAAAAAAAA; // PCLK is 1/2 CCLK
PCLKSEL1 = 0xAAAAAAAA;
#else
PCLKSEL0 = 0x55555555; // PCLK is the same as CCLK
PCLKSEL1 = 0x55555555;
#endif
#endif
/* 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 VIC*/
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
/* Add your codes here */
InitialiseUART0(115200); //Initialize the uart0
return;
}
/*********************************************************************************************************
** 以下為一些與系統相關的庫函數的實現
** 具體作用請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)
void _ttywrch(int ch)
{
ch = ch;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -