📄 syslib.c
字号:
/* sysLib.c - Samsung SBC ARM7 system-dependent routines */
/* Copyright 1984-2002 Wind River Systems, Inc. */
#include "copyright_wrs.h"
#include "smartarm.h"
/*
modification history
--------------------
01o,29jul04,a_m BSP定制 for 精英arm7开发板
01k,26mar02,m_h rename glbEnetAddr to sysSngks32cMacAddr
01j,17jan02,m_h fix cache issues and diab build warnings
01i,27sep01,m_h base MAC address on user DIP setting, Big Endian Support
01h,23jul01,m_h builds in UNIX
01g,17jul01,g_h add visionWARE 2.00 support
01f,11jul01,g_h disable cache in sysToMonitor()
01e,10jul01,g_h add INCLUDE_LCD & INCLUDE_LED & INCLUDE_NETWORK macros
01d,09jul01,g_h add #include "sbcCksum.c" instead of the makefile
01c,26apr01,m_h convert tabs to spaces for readability
01b,25apr01,m_h add comments to cache functions
01a,12apr01,m_h created from snds100 template.
*/
/*
DESCRIPTION
This library provides board-specific routines for the WindRiver SBC ARM7
Ver 1.0 Development Board BSP for the Samsung KS32C chip.
It #includes the following chip drivers:
nullVme.c - dummy VMEbus routines
lpc2210Timer.c - SNGKS32CARM7 timer driver
lpc2210IntrCtl.c - SNGKS32CARM7 interrupt controller driver
nullNvRam.c - dummy NVRAM routines
It #includes the following BSP files:
sysSerial.c - serial device initialization routines
sysEnd.c - END network driver support routines.
INCLUDE FILES: sysLib.h string.h intLib.h taskLib.h vxLib.h muxLib.h
SEE ALSO:
<Configuration>
<ARM Architecture Reference Manual>,
<Samsung KS32C50100 Microcontroller User's Manual>,
<Samsung KS32C5000(A)/50100 Microcontroller Application Notes>
*/
/* includes */
#include "vxWorks.h"
#include "config.h"
#include "sysLib.h"
#include "string.h"
#include "intLib.h"
#include "taskLib.h"
#include "vxLib.h"
#include "muxLib.h"
#include "cacheLib.h"
#include "memLib.h"
#include "wrSbcArm7.h"
#include "lpc2210.h"
/* imports */
IMPORT char end; /* end of system, created by ld */
IMPORT VOIDFUNCPTR _func_armIntStackSplit; /* ptr to fn to split stack */
/* globals */
int sysBus = BUS; /* system bus type (VME_BUS, etc) */
int sysCpu = CPU; /* system cpu type */
char * sysBootLine = BOOT_LINE_ADRS; /* address of boot line */
char * sysExcMsg = EXC_MSG_ADRS; /* catastrophic message area */
int sysProcNum; /* processor number of this cpu */
int sysFlags; /* boot flags */
char sysBootHost [BOOT_FIELD_LEN]; /* name of host from which we booted */
char sysBootFile [BOOT_FIELD_LEN]; /* name of file from which we booted */
CACHE_FUNCS sngks32cCacheFuncs;
/* : sysSngks32cMacAddr->ne2000EnetAddr */
unsigned char dm9000EnetAddr[] = ETHERNET_MAC_ADRS;
/* locals */
/* defines */
/* externals */
IMPORT void lpc2210IntDevInit (void);
IMPORT void sysIntStackSplit (char *, long);
/*local defines*/
#ifndef SBCARM7_CTRL_REG_READ
# define SBCARM7_CTRL_REG_READ(x,result) \
((result) = *(volatile UINT32 *)(x))
#endif /*SBCARM7_READ*/
#ifndef SBCARM7_CTRL_REG_WRITE
# define SBCARM7_CTRL_REG_WRITE(x,data) \
(*((volatile UINT32 *)(x)) = (data))
#endif /*SBCARM7_WRITE*/
/* globals */
/* forward LOCAL functions declarations */
/* forward declarations */
char * sysPhysMemTop (void);
/* included source files */
#ifdef INCLUDE_FLASH
#include "flashMem.c"
#else /* INCLUDE_FLASH */
#include "mem/nullNvRam.c"
#endif /* INCLUDE_FLASH */
#include "vme/nullVme.c"
#include "sysSerial.c"
#include "lpc2210Timer.c"
#include "lpc2210IntrCtl.c"
#ifdef INCLUDE_NETWORK
#ifdef INCLUDE_END
#include "sbcCksum.c"
#include "sysEnd.c"
#endif /* INCLUDE_END */
#endif /* INCLUDE_NETWORK */
#ifdef INCLUDE_LCD
#include "sysLcd.c"
#endif /* INCLUDE_LCD */
#ifdef INCLUDE_LED
#include "sysLed.c"
#endif /* INCLUDE_LCD */
#ifdef INCLUDE_VWARE_LAUNCH
#include "sysVware.c"
#endif /* INCLUDE_VWARE_LAUNCH */
/* : added */
extern void excEnterUndef(void);
extern void excEnterSwi(void);
extern void excEnterPrefetchAbort(void);
extern void excEnterDataAbort(void);
extern void intEnt(void);
#if defined (INCLUDE_USB)
void sysUsbPciInit(void);
#endif
/******************************************************************************
*
* portInit - 针对硬板,初始化CPU各端口
*
*/
static void portInit(void)
{
/* 蜂鸣器*/
IO0DIR = BEEPCON;
IO0SET = BEEPCON;
IO2DIR = LEDCON;
IO2SET = LEDCON;
/* 网卡初始化 */
PINSEL0 = 0x05; /* P0.0 and P0.1 are set to UART0 */
PINSEL0|=0x03<<18; /* eint3 to p0.9 */
EXTMODE|=0<<3; /* eint3电平出发*/
EXTPOLAR|=1<<3; /* eint3高电平有效*/
EXTINT|=1<<3;
/*PINSEL1 = 3<<8;*/ /* ExtInt3连到P0.20 */
/*EXTMODE = 0x08;*/ /* ExtInt3沿触发*/
/*EXTPOLAR = 0;*/ /* 下降沿触发*/
/*EXTINT = 0xf;*/ /* 清除ExtInt的中断标志*/
}
/* #if 0 */
/******************************************************************************
*
* rtl8019Init - RTL8019网络芯片初始化(与NE2000不兼容)
* loopDelay - 循环延时函数,每个时间单位为100us
*/
static void loopDelay(UINT16 DelayTime)
{
UINT16 i;
UINT8 j;
for(i = 0; i < DelayTime; i ++) ;
}
/* static void InitDM9000()
{
IODIR=IODIR|0x00000100;
IOCLR=0x00000100;
loopDelay(100);
IOSET=0x00000100;
loopDelay(100);
IOCLR=0x00000100;
loopDelay(100);
} */
void sysInWordString (unsigned long port, unsigned short *pData, int count)
{
int i, byte_count; char *pbyte;
pbyte = (char *)pData;
byte_count = count*2;
for(i=0; i<byte_count; i++){
*(pbyte) = REG8(port);
pbyte++;
}
}
void sysOutWordString(unsigned long port, unsigned short *pData, int count)
{
int i, byte_count; char *pbyte;
pbyte = (char *)pData;
byte_count = count*2;
for(i=0; i<byte_count; i++){
REG8(port) = *(pbyte);
pbyte++;
}
}
/* #endif */
/******************************************************************************
*
* sysModel - return the model name of the CPU board
*
* This routine returns the model name of the CPU board.
*
* RETURNS: A pointer to a string identifying the board and CPU.
*/
char *sysModel (void)
{
/*return "wrSbcArm7 - ARM7TDMI (ARM)";*/
/* : deleted and added */
return "LPC2210 - ARM7TDMI (ARM,not Thumb) Little Endian";
}
/******************************************************************************
*
* sysBspRev - return the bsp version with the revision eg 1.1/<x>
*
* This function returns a pointer to a bsp version with the revision.
* for eg. 1.1/<x>. BSP_REV is concatenated to BSP_VERSION to form the
* BSP identification string.
*
* RETURNS: A pointer to the BSP version/revision string.
*/
char * sysBspRev (void)
{
return (BSP_VERSION BSP_REV);
}
/******************************************************************************
*
* sysHwInit - initialize the CPU board hardware
*
* This routine initializes various features of the hardware.
* Normally, it is called from usrInit() in usrConfig.c.
*
* NOTE: This routine should not be called directly by the user.
*
* RETURNS: N/A
*/
/*extern Usb_Hc_Init();*/
void sysHwInit (void)
{
PINSEL2=0x0f814914;
BCFG0=(0x10000400 | (0x00<<00) | (0x03<<05) | (0x02<<11));
BCFG1=(0x10000400 | (0x00<<00) | (0x03<<05) | (0x02<<11));
BCFG2=(0x10000400 | (0x0f<<00) | (0x1f<<05) | (0x1f<<11));
BCFG3=(0x10000400 | (0x01<<00) | (0x03<<05) | (0x03<<11));
/* : added */
portInit();
/* Usb_Hc_Init();*/
/* dm9000Init(); */
/*InitDM9000();*/
/* install the IRQ/SVC interrupt stack splitting routine */
_func_armIntStackSplit = sysIntStackSplit;
#ifdef INCLUDE_LCD /* : added */
sysLcdInit(); /* initialize the LCD panel */
sysLcdWriteString(" WindRiver ", 1, 1);
#if (_BYTE_ORDER == _LITTLE_ENDIAN)
#if (CPU == ARMARCH4)
sysLcdWriteString(" SBC ARM7 ", 2, 1);
#else /* ARMARCH4 */
sysLcdWriteString(" SBC ARM7 (t) ", 2, 1);
#endif /* ARMARCH4 */
#else /* (_BYTE_ORDER == _LITTLE_ENDIAN) */
#endif /* (_BYTE_ORDER == _LITTLE_ENDIAN) */
#endif /*INCLUDE_LCD*/
#ifdef INCLUDE_LED /* : added */
sysLedInit(); /* initialize the LED */
#endif /*INCLUDE_LED*/
/* Set the MAC address based on DIP setting
* The least significant byte of the address is changed to
* the value of the user DIP switch setting. SW4-D0 is the
* least significant bit of this byte. We invert the bits
* so Open=0.
*/
/*sysSngks32cMacAddr[5] = ~READ_USERDIP();*/ /* : deleted */
#ifdef FORCE_DEFAULT_BOOT_LINE
strncpy(sysBootLine,DEFAULT_BOOT_LINE,strlen(DEFAULT_BOOT_LINE)+1);
#elif defined INCLUDE_VWARE_LAUNCH
sysVwareBuildBootLine((char*)&sysSngks32cMacAddr);
#endif /* FORCE_DEFAULT_BOOT_LINE */
sysSerialHwInit (); /* initialize serial data structure */
}
/******************************************************************************
*
* sysHwInit2 - additional system configuration and initialization
*
* This routine connects system interrupts and does any additional
* configuration necessary.
*
* RETURNS: N/A
*
* NOMANUAL
*
* Note: this is called from sysClkConnect() in the timer driver.
*/
void sysHwInit2 (void)
{
/* 设置系统各部分时钟 */
/* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -