📄 target.c
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.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 LPC2200 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: sysDelayNS
* Descriptions: 长软件延时
* input parameters: idly 延时参数,值越大,延时越久
* output parameters: none
* Returned value: none
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void sysDelayNS(INT32U uiDly)
{
INT32U i;
for(; uiDly > 0; uiDly--){
for(i = 0; i < 5000; i++);
}
}
/*********************************************************************************************************
** Function name: Timer0_Exception
**
** Descriptions: Timer0 interrupt service function
**
** input parameters: None
** output parameters: None
** Returned value: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void Timer0_Exception (void)
{
T0IR = 0x01;
VICVectAddr = 0; /* 通知中断控制器中断结束 */
OSTimeTick();
}
/*********************************************************************************************************
** Function name: Timer0Init
**
** Descriptions: Initialize the Time0
**
** input parameters: None
** output parameters: None
** Returned value: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void Timer0Init (void)
{
T0IR = 0xffffffff;
T0TCR = 0x03;
T0TC = 0;
T0MCR = 0x03;
T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
T0TCR = 0x01;
vicIrqFuncSet(4,0,(INT32U)Timer0_Exception);
}
/*********************************************************************************************************
** Function name: UART0Init
**
** Descriptions: Initialize the UART0
**
** input parameters: bps
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void UART0Init (uint32 bps)
{
uint16 Fdiv;
PCONP |= 1<<3; /* 在PCONP中启动UART*/
PINSEL0 = (PINSEL0 & 0xffffff0f)|(1<<4)|(1<<6); /* 选择管脚P0.2、P0.3为UART0 */
U0LCR = 0x80; /* 允许访问分频因子寄存器 */
Fdiv = (Fpclk / 16) / bps; /* 设置波特率 */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; /* 禁止访问分频因子寄存器 */
/* 同时设置UART工作模式为8位字符长度,1个停止位,无奇偶校验位 */
U0IER = 0x00; /* 禁止中断 */
U0FCR = 0x81; /* 使能FIFO,接收缓冲区的触发点为8个字节 */
}
/*********************************************************************************************************
** Function name: UART0_SendByte
**
** Descriptions: Send the data
**
** input parameters: data
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void UART0_SendByte (uint8 data)
{
U0THR = data; /* 发送数据*/
while ((U0LSR & 0X40) == 0); /* 等待数据发送完毕*/
}
/*********************************************************************************************************
** Function name: UART0_SendByte
**
** Descriptions: Send the data
**
** input parameters: data
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void UART0_SendStr (char *str)
{
while (1) {
if (*str == '\0') {/* 遇到结束符,退出*/
break;
}
UART0_SendByte(*str++);
}
}
/*********************************************************************************************************
** Function name: TargetInit
**
** Descriptions: Initialize the target board; it is called in a necessary place, change it as
** needed
**
** input parameters: None
** output parameters: None
** Returned value: None
**
** Created by: Chenmingji
** Created Date: 2004/02/02
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void TargetInit (void)
{
OS_ENTER_CRITICAL();
srand((INT32U) TargetInit);
Timer0Init();
UART0Init(9600); /* UART0初始化 */
OS_EXIT_CRITICAL();
}
/*********************************************************************************************************
** Function name: SDRAMInit
** Descriptions: 初始化SDRAM
** input parameters: none
** output parameters: none
**
** Created by: zhangzheng
** Created Date: 2007.12.10
**-------------------------------------------------------------------------------------------------------
** Modified by: zhanghuping
** Modified date: 2008.04.25
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void SDRAMInit( void )
{
uint32 i, dummy ;
/*
* 使能SDRAM总线连接
*/
PINSEL4 = 0x50000000;
PINSEL5 = 0x05050555;
PINSEL6 |= 0x55555555;
PINSEL8 |= 0x55555555;
PINSEL9 |= 0x50555555;
EMCControl = 0x00000001; /* Disable Address mirror */
/*
* 设置SDRAM访问时序.
*/
EMCDynamictRP = 1;
EMCDynamictRAS = 3;
EMCDynamictSREX = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -