📄 init.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 SMDK2413 board initialization code.
//
#include <bsp.h>
//#include <Romldr.h>
#include "samsung.c"
static void InitDisplay(void);
extern DWORD CEProcessorType;
void ConfigureGPIO(void);
void SetCLKforDevices(void);
#ifdef DVS_EN
//-------------------------------------------
// Variables for DVS
static int CurrVoltage;
extern volatile int CurrentState;
extern volatile int PrevState;
extern volatile int NextState;
//---------------------------------------------------------------------------
// Function for DVS
void ChangeVoltage(int);
int GetCurrentVoltage(void);
// ----------------------------------------------------------------------------
#endif
// Global variable(2413 FCLK)
UINT32 g_oalIoCtlClockSpeed;
//------------------------------------------------------------------------------
//
// Function: OEMInit
//
// This is Windows CE OAL initialization function. It is called from kernel
// after basic initialization is made.
//
//extern ROMHDR *const volatile pTOC;
/*
#undef DEBUGMSG
#define DEBUGMSG(cond,printf_exp) ((void)((1)?(DbgPrintfW printf_exp),1:0))
*/
void user_test(void);
void OEMInit()
{
#ifdef DVS_EN
volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
#if (DVS_METHOD == 3)
volatile S3C2413_PWM_REG *g_pPWMRegs = (S3C2413_PWM_REG*)OALPAtoUA(S3C2413_BASE_REG_PA_PWM);
UINT32 sysIntr = SYSINTR_NOP;
#endif
#endif
OALMSG(OAL_FUNC, (L"+OEMInit\r\n"));
//#ifdef DEBUG
//DEBUGZONE(0xffffffff); //(ZONE_MEMORY|ZONE_DEBUGGER|ZONE_VIRTMEM|ZONE_ENTRY|ZONE_PHYSMEM); //ZONE_WARNING|ZONE_INIT); //ZONE_DHCP;
//#endif
OALLogSetZones( (1<<OAL_TIMER)|(1<<OAL_ARGS)|(1<<OAL_FUNC)|(1<<OAL_INTR)|(1<<OAL_ERROR)|(1<<OAL_VERBOSE) );
//OALLogSetZones( (OAL_TIMER)|(OAL_ARGS)|(OAL_FUNC)|(OAL_INTR)|(OAL_ERROR)|(OAL_VERBOSE) );
/*
memset((void*)pTOC->ulRAMFree, 0, sizeof(DWORD)*3);
NKForceCleanBoot();
*/
// The g_oalIoCtlClockSpeed variable is refered from Ioctl.c
g_oalIoCtlClockSpeed = S3C2413_FCLK;
// Display PLL setting...
OALMSG(TRUE, (L">> PLL Setting values\r\n"));
OALMSG(TRUE, (L">> FCLK:%ld\r\n", S3C2413_FCLK));
OALMSG(TRUE, (L">> HCLK:%ld\r\n", S3C2413_HCLK));
OALMSG(TRUE, (L">> PCLK:%ld\r\n", S3C2413_PCLK));
CEProcessorType=PROCESSOR_STRONGARM;
OEMWriteDebugLED(0, 0x0); // Turn off all leds.
// Set memory size for DrWatson kernel support
dwNKDrWatsonSize = 128 * 1024;
OALMSG(OAL_FUNC, (L"+InitCache.\r\n"));
// 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
OALMSG(1, (L"+OALIntrInit.\r\n"));
if (!OALIntrInit()) {
OALMSG(OAL_ERROR, (
L"ERROR: OEMInit: failed to initialize interrupts\r\n"
));
}
// Initialize system clock
OALTimerInit(RESCHED_PERIOD, OEM_COUNT_1MS, 0);
OALMSG(1, (L"+ConfigureGPIO.\r\n"));
ConfigureGPIO();
RETAILMSG(1, (L"+InitDisplay.\r\n"));
InitDisplay();
// Initialize the KITL connection if required
RETAILMSG(1, (L"+Call KITL.\r\n"));
OALKitlStart();
SetCLKforDevices();
#if (Eval_Probe == 1)
OALMSG(1, (L"Call uesr_test()\r\n"));
user_test();
#endif //(Eval_Probe == 1)
#ifdef DVS_EN
#if (DVS_METHOD == 3)
CurrentState = Active;
#endif
#endif
OALMSG(TRUE, (L"-OEMInit\r\n"));
}
//------------------------------------------------------------------------------
void SetCLKforDevices(void)
{
volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
volatile S3C2413_CLKPWR_REG *s2413CLKPWR = (S3C2413_CLKPWR_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_CLOCK_POWER, FALSE);
RETAILMSG(1, (TEXT("+SetCLKforDevices\n")));
RETAILMSG(1, (TEXT("MPLLCON[%xh]\n"), s2413CLKPWR->MPLLCON));
RETAILMSG(1, (TEXT("UPLLCON[%xh]\n"), s2413CLKPWR->UPLLCON));
RETAILMSG(1, (TEXT("CLKCON[%xh]\n"), s2413CLKPWR->CLKCON));
RETAILMSG(1, (TEXT("CLKSRC[%xh]\n"), s2413CLKPWR->CLKSRC));
RETAILMSG(1, (TEXT("CLKDIVN[%xh]\n"), s2413CLKPWR->CLKDIVN));
RETAILMSG(1, (TEXT("-SetCLKforDevices\n")));
}
//=============================================================
// For LCD display......
void SetGPIOforLDI(void)
{
volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
//GPIO Configuration for setting LDI
#ifdef SMDK2413_REV14
s2413IOP->GPBDN |= (0x1<<6);
s2413IOP->GPGDN |= (0x7<<5);
s2413IOP->GPBDAT |= (0x1<<6);
s2413IOP->GPGDAT |= (0x7<<5);
s2413IOP->GPBCON = (s2413IOP->GPBCON & ~(0x3<<12))|(0x1<<12);
s2413IOP->GPGCON = (s2413IOP->GPGCON & ~(0x3f<<10))|(0x15<<10);
#else
s2413IOP->GPEDN |= (0x3<<12);
s2413IOP->GPGDN |= (0x1<<2);
s2413IOP->GPEDAT |= (0x3<<12);
s2413IOP->GPGDAT |= (0x1<<2);
s2413IOP->GPECON = (s2413IOP->GPECON & ~(0xf<<24))|(0x5<<24);
s2413IOP->GPGCON = (s2413IOP->GPGCON & ~(0x3<<4))|(0x1<<4);
#endif
}
void delayLoop(int count)
{
volatile int j;
for(j = 0; j < count; j++) ;
}
#ifdef SMDK2413_REV14
#define LCD_DEN (1<<6) //GPB6, nSS
#define LCD_DSERI (1<<6) //GPE6, SPIMOSI
#define LCD_DCLK (1<<7) //GPE7, SPICLK
#define LCD_RESET (1<<5) //GPG5, RESET
#define LCD_DEN_Lo (s2413IOP->GPBDAT &= ~LCD_DEN)
#define LCD_DEN_Hi (s2413IOP->GPBDAT |= LCD_DEN)
#define LCD_DCLK_Lo (s2413IOP->GPGDAT &= ~LCD_DCLK)
#define LCD_DCLK_Hi (s2413IOP->GPGDAT |= LCD_DCLK)
#define LCD_DSERI_Lo (s2413IOP->GPGDAT &= ~LCD_DSERI)
#define LCD_DSERI_Hi (s2413IOP->GPGDAT |= LCD_DSERI)
#define LCD_RESET_Lo (s2413IOP->GPGDAT &= ~LCD_RESET)
#define LCD_RESET_Hi (s2413IOP->GPGDAT |= LCD_RESET)
#else
#define LCD_DEN (1<<2) //GPG2, nSS
#define LCD_DSERI (1<<12) //GPE12, SPIMOSI
#define LCD_DCLK (1<<13) //GPE13, SPICLK
#define LCD_RESET (0)
#define LCD_DEN_Lo (s2413IOP->GPGDAT &= ~LCD_DEN)
#define LCD_DEN_Hi (s2413IOP->GPGDAT |= LCD_DEN)
#define LCD_DCLK_Lo (s2413IOP->GPEDAT &= ~LCD_DCLK)
#define LCD_DCLK_Hi (s2413IOP->GPEDAT |= LCD_DCLK)
#define LCD_DSERI_Lo (s2413IOP->GPEDAT &= ~LCD_DSERI)
#define LCD_DSERI_Hi (s2413IOP->GPEDAT |= LCD_DSERI)
#define LCD_RESET_Lo (0)
#define LCD_RESET_Hi (1)
#endif
#if WIDE_LCD==1
//================================================================
// Init for Wide LCD...
void WriteLDI_LTS350(int address, int data)
{
volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
unsigned char dev_id_code=0x1D;
int j;
unsigned char DELAY=50;
LCD_DEN_Hi; // EN = High CS high
LCD_DCLK_Hi; // SCL High
LCD_DSERI_Hi; // Data Low
delayLoop(DELAY);
LCD_DEN_Lo; // EN = Low CS Low
delayLoop(DELAY);
for (j = 5; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((dev_id_code >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
// RS = "0" : index data
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
// Write
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
for (j = 15; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((address >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
LCD_DSERI_Hi;
delayLoop(DELAY);
LCD_DEN_Hi; // EN = High
delayLoop(DELAY*10);
LCD_DEN_Lo; // EN = Low CS Low
delayLoop(DELAY);
for (j = 5; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((dev_id_code >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
// RS = "1" instruction data
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Hi;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
// Write
LCD_DCLK_Lo; // CLOCK = Low
LCD_DSERI_Lo;
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
for (j = 15; j >= 0; j--)
{
LCD_DCLK_Lo; // SCL Low
if ((data >> j) & 0x0001) // DATA HIGH or LOW
{
LCD_DSERI_Hi;
}
else
{
LCD_DSERI_Lo;
}
delayLoop(DELAY);
LCD_DCLK_Hi; // CLOCK = High
delayLoop(DELAY);
}
LCD_DEN_Hi; // EN = High
delayLoop(DELAY);
}
void InitLDI_LTV350(void)
{
volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
SetGPIOforLDI();
#ifdef SMDK2413_REV14
// LCD Reset
s2413IOP->GPGDAT |= (1<<0); // Reset High
s2413IOP->GPGCON &= ~(3<<0);
s2413IOP->GPGCON |= (1<<0);
Delay(500);
s2413IOP->GPGDAT &= ~(1<<0); // Reset Low
Delay(1000);
//Delay(100);
s2413IOP->GPGDAT |= (1<<0); // Reset High
Delay(100);
#else
LCD_RESET_Hi;
Delay(500);
LCD_RESET_Lo;
Delay(1000);
LCD_RESET_Hi;
Delay(100);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -