init.c

来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C语言 代码 · 共 481 行 · 第 1/2 页

C
481
字号
//
// 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 SMDK6410 board initialization code.
//
#include <bsp.h>

#define RETAILMSG(cond,printf_exp)	  ((cond)?(NKDbgPrintfW printf_exp),1:0)

#define NOT_FIXEDUP (DWORD)-1
DWORD dwOEMDrWatsonSize = 128 * 1024;//NOT_FIXEDUP;


UINT32 g_oalIoCtlClockSpeed;

void Init_BspArgs(void);
void Port_Init(void);


//------------------------------------------------------------------------------
//
//  Global:  g_oalRtcResetTime
//
//  RTC init time after a RTC reset has occured.
//
SYSTEMTIME g_oalRtcResetTime =
{
	2007, 	// wYear
	7,		// wMonth
	7,		// wDayofWeek
	1,		// wDay
	12,		// wHour
	0,		// wMinute
	0,		// wSecond
	0		// wMilliseconds
};

static void InitializeINFORMSFR(void);
static void InitializeGPIO(void);
static void InitializeCLKGating(void);
static void InitializeBlockPower(void);
static void InitializeCLKSource(void);
#if	(CPU_NAME == S3C6410)
static void InitializeOTGCLK(void);

static void Delay(UINT32 count)
{
	volatile int i, j = 0;
	volatile static int loop = S3C6410_ACLK/100000;
	
	for(;count > 0;count--)
		for(i=0;i < loop; i++) { j++; }
}
#endif

extern BOOL (*pfnOEMSetMemoryAttributes) (LPVOID pVirtualAddr, LPVOID pPhysAddr, DWORD cbSize, DWORD dwAttributes);

//------------------------------------------------------------------------------
//
//  OEMSetMemoryAttributes
//
//  OEM function to change memory attributes that isn't supported by kernel.
//  Current implementaion only supports PAGE_WRITECOMBINE.
//
//  This function first try to use PAT, and then try MTRR if PAT isn't available.
//
//------------------------------------------------------------------------------
BOOL OEMSetMemoryAttributes (
    LPVOID pVirtAddr,       // Virtual address of region
    LPVOID pPhysAddrShifted,// PhysicalAddress >> 8 (to support up to 40 bit address)
    DWORD  cbSize,          // Size of the region
    DWORD  dwAttributes     // attributes to be set
    )
{
    if (PAGE_WRITECOMBINE != dwAttributes) {
        DEBUGMSG (1, (L"OEMSetMemoryAttributes: Only PAGE_WRITECOMBINE is supported\r\n"));
        return FALSE;
    }

    return NKVirtualSetAttributes (pVirtAddr, cbSize,
                                  0x4,                  // not cacheable, but bufferable
                                  0xC,                  // Mask of all cache related bits
                                  &dwAttributes);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMInit
//
//  This is Windows CE OAL initialization function. It is called from kernel
//  after basic initialization is made.
//
void OEMInit()
{
	UINT32 logMask_Backup;
	extern DWORD CEProcessorType;	// From nkarm.h in the private tree.
   	//volatile S3C6410_VIC_REG *pIntr = (S3C6410_VIC_REG*)OALPAtoVA(S3C6410_BASE_REG_PA_VIC0, FALSE);

    //NKForceCleanBoot();
	OALMSG(OAL_FUNC, (L"[OAL] ++OEMInit()\r\n"));
	OALMSG(TRUE, (L"[OAL] ++OEMInit()\r\n"));

	OALMSG(TRUE, (TEXT("[OAL] FCLK   : %d\n\r"), S3C6410_APLL_CLK));  // mod by shin.0313
	OALMSG(TRUE, (TEXT("[OAL] ARMCLK : %d\n\r"), S3C6410_ACLK));
	OALMSG(TRUE, (TEXT("[OAL] HCLK   : %d\n\r"), S3C6410_HCLK));
	OALMSG(TRUE, (TEXT("[OAL] PCLK   : %d\n\r"), S3C6410_PCLK));

	g_oalIoCtlClockSpeed = S3C6410_APLL_CLK;  	// mod by shin.0313

    // Lie about the Processor Type (we do this so that the visual C tools work)
	CEProcessorType = PROCESSOR_STRONGARM;

	logMask_Backup = g_oalLogMask;
	OALLogSetZones( (1<<OAL_LOG_ERROR) | (1<<OAL_LOG_WARN) | (1<<OAL_LOG_FUNC) );

	RETAILMSG(1,(TEXT("CEProcessorType = 0x%x\r\n"),CEProcessorType));
	OALMSG(OAL_FUNC, (L"+OEMInit\r\n"));
	// mod by shin.0313
	RETAILMSG(1,(TEXT("FCLK: %d, HCLK: %d, PCLK: %d, Prescaler: %d\r\n"),S3C6410_APLL_CLK, S3C6410_HCLK, S3C6410_PCLK, SYS_TIMER_PRESCALER)); 
	// Set memory size for DrWatson kernel support
 	if (dwOEMDrWatsonSize != NOT_FIXEDUP)
 	{
        	dwNKDrWatsonSize = dwOEMDrWatsonSize;      // set size of reserved memory for Watson dump
 	}
	// Intialize optional kernel functions. (Processor Extended Feature)
	//
 	pOEMIsProcessorFeaturePresent = OALIsProcessorFeaturePresent;
 	
	// Set OEMSetMemoryAttributes function
	pfnOEMSetMemoryAttributes = OEMSetMemoryAttributes;
	 	
	// Turn Off all Debug LED
	//
	OEMWriteDebugLED(0, 0x0);

	// Initialize INFORM SFR
	// This function should be called for CPU Identification.
	InitializeINFORMSFR();
	
	// Initialize Clock Source
	//
	InitializeCLKSource();

	// Initialize Clock Gating
	//
	InitializeCLKGating();

	// Initialize Block Power
	//
	InitializeBlockPower();
#if	(CPU_NAME == S3C6410)
	// Initialize OTG PHY Clock
	//
	InitializeOTGCLK();
#endif

	// 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
	);

	// Initialize Interrupts
	//
	if (!OALIntrInit())
	{
		OALMSG(OAL_ERROR, (L"[OAL:ERR] OEMInit() : failed to initialize interrupts\r\n"));
	}

	// Initialize system clock
	OALTimerInit(RESCHED_PERIOD, OEM_COUNT_1MS, 0);
	// Initialize GPIO
	//
	InitializeGPIO();

	// Initialize the KITL connection if required
	RETAILMSG(1, (TEXT("OALKitlStart() \n\r")));
	OALKitlStart();

	Init_BspArgs();
	OALMSG(OAL_FUNC, (L"-OEMInit\r\n"));

	OALLogSetZones(logMask_Backup);
}

//------------------------------------------------------------------------------
#define pBSPArgs					((BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START)
void Init_BspArgs(void)
{
	// Initialize the BSP args structure.
	//
	if (
		pBSPArgs->header.signature  != OAL_ARGS_SIGNATURE ||
		pBSPArgs->header.oalVersion != OAL_ARGS_VERSION   ||
		pBSPArgs->header.bspVersion != BSP_ARGS_VERSION
	)
	{
		OALMSG(OAL_FUNC, (L"Init_BspArgs.\n"));
		memset(pBSPArgs, 0, sizeof(BSP_ARGS));
		pBSPArgs->header.signature	   = OAL_ARGS_SIGNATURE;
		pBSPArgs->header.oalVersion	  = OAL_ARGS_VERSION;
		pBSPArgs->header.bspVersion	  = BSP_ARGS_VERSION;
		pBSPArgs->fUpdateMode = FALSE ;
		pBSPArgs->fUldrReboot = FALSE ;
	}
	RETAILMSG(1, (TEXT("pBSPArgs->header.signature(%x)=%x\n"), OAL_ARGS_SIGNATURE, pBSPArgs->header.signature));
	RETAILMSG(1, (TEXT("pBSPArgs->header.oalVersion(%x)=%x\n"), OAL_ARGS_VERSION, pBSPArgs->header.oalVersion));
	RETAILMSG(1, (TEXT("pBSPArgs->header.bspVersion(%x)=%x\n"), BSP_ARGS_VERSION, pBSPArgs->header.bspVersion));
	RETAILMSG(1, (TEXT("pBSPArgs->fUpdateMode=%x\n"), pBSPArgs->fUpdateMode));
	RETAILMSG(1, (TEXT("pBSPArgs->kitl.flags=%x\n"), pBSPArgs->kitl.flags));

}

/*
void Port_Init(void)
{
    volatile S3C6410_GPIO_REG *s6410IOP = (S3C6410_GPIO_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_GPIO, FALSE);

    //CAUTION:Follow the configuration order for setting the ports.
    // 1) setting value(GPnDAT)
    // 2) setting control register  (GPnCON)

⌨️ 快捷键说明

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