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

📄 init.c

📁 S3C24A0的完整BSP包,对开发此芯片的开发者很有用.
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  init.c
//
//  Samsung SMDK24A0 board initialization code.
//
#include <bsp.h>
#include <oal.h>
#include <s3c24A0.h>


void InitEthMemBank(void); 
void InitDisplay();

void OEMInitPort();

extern const unsigned short ScreenBitmap[];
#define RETAIL_ON 	1

//------------------------------------------------------------------------------
//
//  Globals.

//  The global variables are storing virual address for interrupt and port
//  registers for use in interrupt handling to avoid possible time consumig
//  call to OALPAtoVA function.
//
static volatile S3C24A0_IOPORT_REG *g_pPortRegs;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//
//  Function:  OEMInit
//
//  This is Windows CE OAL initialization function. It is called from kernel
//  after basic initialization is made.
//
void OEMInit()
{
    OALMSG(OAL_FUNC, (L"+OEMInit\r\n"));

    // Set memory size for DrWatson kernel support
    dwNKDrWatsonSize = 128 * 1024;

    // Initilize cache globals
    OALCacheGlobalsInit();

    OALLogSerial(
        L"DCache: %d sets, %d ways, %d line size, %d size\r\n", 
        g_oalCacheInfo.L1DSetsPerWay, g_oalCacheInfo.L1DNumWays,
        g_oalCacheInfo.L1DLineSize, g_oalCacheInfo.L1DSize
    );
    OALLogSerial(
        L"ICache: %d sets, %d ways, %d line size, %d size\r\n", 
        g_oalCacheInfo.L1ISetsPerWay, g_oalCacheInfo.L1INumWays,
        g_oalCacheInfo.L1ILineSize, g_oalCacheInfo.L1ISize
    );
    RETAILMSG(RETAIL_ON, (TEXT("In OEMInit before interrupt initialization...\r\n")));
 //    Initialize interrupts
    if (!OALIntrInit()) {
        OALMSG(1, (
            L"ERROR: OEMInit: failed to initialize interrupts\r\n"
        ));
    }
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after interrupt initialization\r\n")));
    
	// Initialize system clock
    //OALTimerInit(1, S3C24A0_PCLK/2000, 0);
	OALTimerInit(1, OEM_COUNT_1MS, 0);
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after OALTimerInit \r\n")));
    	
	//Initialize S24A0 GPIO ports
	//OEMInitPort();
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after OEMInitPort\r\n")));

	//Initialize the ethernet memory bank
	//InitEthMemBank();
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after InitEthMemBank\r\n")));

	// Initialize S24A0 LCD controller
	//InitDisplay();
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after InitDisplay\r\n")));

	// Initialize the KITL connection if required
   	OALKitlStart();
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after OALKitlStart\r\n")));
		
	// Initialize the ROM chain (multi-region).
	//InitRomChain();
	RETAILMSG(RETAIL_ON, (TEXT("In OEMInit after InitRomChain\r\n")));

	RETAILMSG(RETAIL_ON, (L"-OEMInit\r\n"));
}

void InitEthMemBank(void)
{
	volatile S3C24A0_SROM_REG *sromReg = 0;
	
	sromReg = (S3C24A0_SROM_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_SROM, FALSE);	

	RETAILMSG(RETAIL_ON, (TEXT("Ethernet memory bank configuration\r\n")));

	sromReg->SROM_BW &= ~(7<<3);
	sromReg->SROM_BW |= 7<<3;

#define B1_Tacs		0x0	//0  clk
#define B1_Tcos		0x3	//0  clk
#define B1_Tacc		0x7	//20 clks
#define B1_Tcoh		0x1	//0  clk
#define B1_Tcah		0x3	//0  clk
#define B1_Tacp		0x3	
#define B1_PMC		0x0	//normal


	sromReg->SROM_BC1 = 	((B1_Tacs<<14)+(B1_Tcos<<12)+(B1_Tacc<<8)+(B1_Tcoh<<6)+(B1_Tcah<<4)+(B1_Tacp<<2)+(B1_PMC));   //;GCS1 
}

#define LCDBASEL(n) 		((n) & 0xffffff)	// To get lower 24 bits
void InitDisplay()
{
   	volatile S3C24A0_LCD_REG *s24A0LCD	= (S3C24A0_LCD_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_LCD, FALSE);
	volatile S3C24A0_BUS_REG *pBusReg	= (S3C24A0_BUS_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_BUSCTRL, FALSE);
	
	int  clkval = 9;

	pBusReg->PRIORITY1 |= (1<<1);

	clkval = (WORD)((float)(S3C24A0_HCLK) / (2.0 * 5000000) + 0.5) - 1;
	
	RETAILMSG(RETAIL_ON,(TEXT("VCLK:%d\r\n"),clkval));

	s24A0LCD->LCDCON1		= (1<<28)|(0<<21)|(1<<19)|(clkval<<13)|(1<<12)|(0x0<<9)|(5<<2)|0; 
	s24A0LCD->LCDCON2		= (2<<9)|(1<<6)|(1<<5)|(1<<0);
	s24A0LCD->LCDTCON1		= (LCD_VBPD<<16)|(LCD_VFPD<<8)|(LCD_VSPW);
	s24A0LCD->LCDTCON2		= (LCD_HBPD<<16)|(LCD_HFPD<<8)|(LCD_HSPW);		
	s24A0LCD->LCDTCON3		= (LCD_LINEVAL_TFT<<11)|(LCD_HOZVAL_TFT);
	s24A0LCD->LCDSADDRB1	= IMAGE_FRAMEBUF_DMA_BASE;
	s24A0LCD->LCDEADDRB1	= LCDBASEL(IMAGE_FRAMEBUF_DMA_BASE + (LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2));
	s24A0LCD->LCDVSCRB1	= ((LCD_XSIZE_TFT - LCD_XSIZE_TFT) * 2<<13)|(LCD_XSIZE_TFT * 2);
	s24A0LCD->LCDSADDRB2	= IMAGE_FRAMEBUF_DMA_BASE;
	s24A0LCD->LCDEADDRB2	= LCDBASEL(IMAGE_FRAMEBUF_DMA_BASE + (LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2));
	s24A0LCD->LCDVSCRB2	= ((LCD_XSIZE_TFT - LCD_XSIZE_TFT) * 2<<13)|(LCD_XSIZE_TFT * 2);

	//LcdEnvidOnOff
	s24A0LCD->LCDCON1		= s24A0LCD->LCDCON1|(3); // ENVID On using Per Frame method

	memcpy((void *)IMAGE_FRAMEBUF_BASE, ScreenBitmap, ARRAY_SIZE_TFT_16BIT);
}

void OEMInitPort(void)
{
	DWORD rdata;
	
	g_pPortRegs = (S3C24A0_IOPORT_REG*)OALPAtoVA(S3C24A0_BASE_REG_PA_IOPORT, FALSE);
#if 0	
//	DWORD rdata;	
	
    //CAUTION:Follow the configuration order for setting the ports. 
    // 1) setting value(GPDAT) 
    // 2) setting control register  (GPCON_U,GPCON_M, GPCON_L))
    // 3) configure pull-up resistor(GPUP)  

    //Ports  :GP31 GP30 GP29 GP28 GP27 GP26 GP25 GP24 PG23 GP22 GP21 GP20 GP19	
    //GPDAT  :0    0    0    0    0    0    0    0    0    0    0    0    0
    //GPCON_U:i    i    i    i    i    i    i    i    i    i    i    i    i
    //GPPU   :x    o    o    x    x    x    x    x    x    x    x    x    x 
 	g_pPortRegs->GPCON_U = 0x3fbffff; 
    //-----------------------------------------------------------------------
    //Ports  :GP18 GP17 GP16 GP15 GP14 GP13 GP12 GP11
    //GPDAT  :0    0    0    0    0    0    0    0   
    //GPCON_M:i    i    i    i    i    i    i    i   
    //GPPU   :x    o    o    o    x    o    x    x   
	g_pPortRegs->GPCON_M = 0xd5aa;
    //-----------------------------------------------------------------------
    //Ports  :GP10 GP9  GP8  GP7  GP6  GP5  GP4  GP3  GP2  GP1  GP0
    //GPDAT  :0    0    0    0    0    0    0    0    0    0    0   
    //GPCON_L:i    i    i    O    O    O    O    i    i    i    i
    //GPPU   :o    x    o    x    x    x    x    o    o    x    x       
	g_pPortRegs->GPCON_L = 0x255545;

	//disable pull-up function
	g_pPortRegs->GPPU = 0xffffffff;

	g_pPortRegs->GPCON_U &= ~((3 << 24)|(3 << 22));	// Configure GP31 and GP30 for UART1 Tx and Rx, respectively.
	g_pPortRegs->GPCON_U |=  ((2 << 24)|(2 << 22));	//

	g_pPortRegs->GPCON_U &= ~((3 << 20)|(3 << 18));	// Configure GP29 and GP28 for UART1 Tx and Rx, respectively.
	g_pPortRegs->GPCON_U |=  ((2 << 20)|(2 << 18));	//


	g_pPortRegs->GPPU  |=   (1 << 31)|(1 << 30);		// Disable pull-up on TXD1 and RXD1.	

    //External interrupt will be falling edge triggered.
	g_pPortRegs->EXTINTC0= 0x222;			//EINT2~0
	g_pPortRegs->EXTINTC1 = 0x22222222;		//EINT10~3
	g_pPortRegs->EXTINTC2 = 0x22222222;		//EINT18~11, falling edge & disabling filter

#endif
	// Ethernet gpio enable
	rdata  = g_pPortRegs->GPCON_M;
	rdata &= ~(3 << 4);
	rdata |=  (2 << 4);
	g_pPortRegs->GPCON_M = rdata;			/* External Interrupt #13 Enable			*/

	rdata  = g_pPortRegs->EXTINTC2;
	rdata &= ~(7 << 8);
	rdata |=  (4 << 8);
	g_pPortRegs->EXTINTC2 = rdata;			/* Rising Edge Detect Mode				*/
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -