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

📄 cfw.c

📁 2440开发板pb4.2增加两个串口需更改的文件。
💻 C
📖 第 1 页 / 共 4 页
字号:
/*++ 
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2001. Samsung Electronics, co. ltd  All rights reserved.
--*/

#include "windows.h"
#include "nkintr.h"
#include "oalintr.h"
#include "shx.h"
#include "p2.h"
#include "p2debug.h"
#include "tchaud.h"
#include "drv_glob.h"
#include <memory.h>
#ifdef MODULE_CERTIFY
#include "key1024.c"    // OEMLoadInit/OEMLoadModule implementation and the public key used for module signature verification.
#endif
//#include "timer.h"
#include <S2440.h>
#include <pehdr.h>
#include <romldr.h>

extern const unsigned short ScreenBitmap[];

/*
    @doc    EXTERNAL KERNEL HAL

    @module cfwp2.c - P2 HW Support | 
        OEM support Functions for the Windows CE P2 Platform.
    
    @xref <f OEMInit> <f OEMInterruptEnable> <f OEMInterruptDisable> 
          <f OEMInterruptDone> <l HAL Overview.Windows CE Kernel OEM Interface>
          
    @topic Windows CE Kernel OEM Interface |
          This defines the HAL layer - OEM and platform dependent pieces of
          code which we expect the OEM to deliver to us. There are three pieces
          of OEM deliverable code  - the bootstrap loader & monitor (for 
          debugging), the HAL portions which are interfaces between the kernel
          and the firmware, and the driver interface. This topic covers just 
          the HAL portion.

          The philosophy is to keep the HAL layer as simple as possible.  The 
          HAL should not be confused with the machine or CPU independence. HAL 
          is specific for a particular CPU and platform. It includes interfaces 
          for the following devices:<nl>
          Real Time Clock<nl>
          Interval Timer (used for the scheduler operation) <nl>
          Interrupt handlers and support <nl>

          Note that it does not include abstractions for devices like the DMA 
          controller etc. since the kernel does not use one. Also note that the
          list could change for different CPU's and platforms - for instance, 
          some chips might include a lot of peripheral devices (like the 
          interval timer) on the CPU chip itself, removing the need for a 
          separate interface for them.

          The interfaces for the real time clock and interval timer are still 
          being developed. But they should in general be extremely simple and
          straightforward. For details on the interrupt support model in the 
          kernel look at <l Interrupt Support Overview.Kernel Interrupt Support>

    @xref <l Interrupt Support Overview.Kernel Interrupt Support>
          <f OEMInit> <f OEMInterruptEnable> <f OEMInterruptDisable> 
          <f OEMInterruptDone> <f HookInterrupt>
             
 */


unsigned long OEMClockFreq;				// OEM clock frequency is used only in OAL

//
// Kernel global variables used by GetIdleTime( ) to determine CPU utilization
//
extern DWORD idleconv; 					// translation constant in 1 ms units
extern DWORD curridlehigh, curridlelow;	// 64-bit idle time in ms

extern int P2ISR();
extern void InitClock();
extern void HalCpuInit();
extern void HalTimerInit();
extern void HalSleep(DWORD);

extern void TIMERINIT();
extern void InitDebugEther(void);

static void InitDisplay(void);
static void OEMInitInterrupts(void);
static void InitSDMMC(void);
#ifdef YL_2440_SUPPORT
static void HzhInitPIO(void);
#endif

typedef volatile WORD *PVWORD;    /* pointer to a volatile word */
typedef volatile DWORD *PVDWORD;    /* pointer to a volatile dword */


#define REG(base, id)   (*(PVWORD)((base)+(id)))
#define REG32(base, id)   (*(PVDWORD)((base)+(id)))

#ifdef YL_2440_SUPPORT
#define SDIO_FOR_100BD	0//1
#else
#define SDIO_FOR_100BD	0
#endif
/*
#if (CE_MAJOR_VER == 0x0003)
	//Cedar
	// The kernel exports...
	#ifdef AddrCurMSec
		// Some kernels export a pointer to the CurMSec variable.
		static volatile DWORD * pCurMSec  = (volatile DWORD *) AddrCurMSec;
		static volatile DWORD * pDiffMSec = (volatile DWORD *) AddrDiffMSec;
	#else
		extern volatile DWORD CurMSec;
		extern volatile DWORD DiffMSec;
		static volatile DWORD * pCurMSec = &CurMSec;
		static volatile DWORD * pDiffMSec = &DiffMSec;
	#endif

	extern DWORD dwSleepMin;
	extern DWORD dwPartialDiffMSec;
	extern DWORD ticksleft;

#else
// dougfir or later
//
	#ifdef AddrCurMSec
		// Some kernels export a pointer to the CurMSec variable.
		static volatile DWORD * pCurMSec  = (volatile DWORD *) AddrCurMSec;
	#else
		extern volatile DWORD CurMSec;
		static volatile DWORD * pCurMSec = &CurMSec;
	#endif
	
extern DWORD dwReschedTime;
#endif
*/

// dougfir or later
//
	#ifdef AddrCurMSec
		// Some kernels export a pointer to the CurMSec variable.
		static volatile DWORD * pCurMSec  = (volatile DWORD *) AddrCurMSec;
	#else
		extern volatile DWORD CurMSec;
		static volatile DWORD * pCurMSec = &CurMSec;
	#endif
	
extern DWORD dwReschedTime;


extern BOOL fIntrTime;
extern BOOL bProfileTimerRunning;

volatile ULARGE_INTEGER CurTicks = { 0, 0 };
volatile ULARGE_INTEGER * pCurTicks = &CurTicks;

extern DWORD dwReschedIncrement;
extern DWORD OEMCount1ms;
//extern void Camera_Initialize(void);


#define NOT_FIXEDUP		   (DWORD*)-1
DWORD *pdwXIPLoc = NOT_FIXEDUP;
extern  ROMChain_t         *OEMRomChain;

/*
    @func   void | InitRomChain | Collects chain information for all image regions for the kernel.
    @rdesc  N/A.
    @comm    
    @xref   
*/
/*
void InitRomChain(void)
{
	static		ROMChain_t	s_pNextRom[MAX_ROM] = {0};
	DWORD		dwRomCount = 0;
    DWORD       dwChainCount = 0;
    DWORD		*pdwCurXIP;
    DWORD       dwNumXIPs;
    PXIPCHAIN_ENTRY pChainEntry = NULL;

    if(pdwXIPLoc == NOT_FIXEDUP)
	{
        return;  // no chain or not fixed up properly
    }

    // set the top bit to mark it as a virtual address
    pdwCurXIP = (DWORD*)(((DWORD)pdwXIPLoc) | 0x80000000);

    // first DWORD is number of XIPs
    dwNumXIPs = (*pdwCurXIP);

    if(dwNumXIPs > MAX_ROM)
	{
      lpWriteDebugStringFunc(TEXT("ERROR: Number of XIPs exceeds MAX\n"));
      return;
    }

    pChainEntry = (PXIPCHAIN_ENTRY)(pdwCurXIP + 1);

    while(dwChainCount < dwNumXIPs)
    {
        if ((pChainEntry->usFlags & ROMXIP_OK_TO_LOAD) &&  // flags indicates valid XIP
            *(LPDWORD)(((DWORD)(pChainEntry->pvAddr)) + ROM_SIGNATURE_OFFSET) == ROM_SIGNATURE)
        {
            s_pNextRom[dwRomCount].pTOC = *(ROMHDR **)(((DWORD)(pChainEntry->pvAddr)) + ROM_SIGNATURE_OFFSET + 4);
            s_pNextRom[dwRomCount].pNext = NULL;

            if (dwRomCount != 0)
            {
                s_pNextRom[dwRomCount-1].pNext = &s_pNextRom[dwRomCount];
            }
            else
            {
                OEMRomChain = s_pNextRom;
            }
            dwRomCount++;
        }
        else
        {
            lpWriteDebugStringFunc( _T("Invalid XIP found\n") );
        }

        ++pChainEntry;
		dwChainCount++;
	}
}
*/

#define FROM_BCD(n)		((((n) >> 4) * 10) + ((n) & 0xf))


//------------------------------------------------------------------------------
//
//  @func   void | OEMInit | Initialize Hardware Interfaces
//  @rdesc  none
//  @comm   OEMInit is called by the kernel after it has performed minimal
//          initialization. Interrupts are disabled and the kernel is not
//          ready to handle exceptions. The only kernel service available
//          to this function is <f HookInterrupt>. This should be used to 
//          install ISR's for all the hardware interrupts to be handled by
//          the firmware. Note that ISR's must be installed for any interrupt
//          that is to be routed to a device driver - otherwise the 
//          <f InterruptInitialize> call from the driver will fail.
//  @xref   <l Overview.Windows CE Kernel OEM Interface> <f HookInterrupt>
//          <f InterruptInitialize>
//            
//------------------------------------------------------------------------------
void OEMInit()  
{
	volatile IOPreg *s2440IOP = (IOPreg *)IOP_BASE;

	// Instead of calling OEMWriteDebugString directly, call through exported
	// function pointer.  This will allow these messages to be seen if debug
	// message output is redirected to Ethernet or the parallel port.  Otherwise,
	// lpWriteDebugStringFunc == OEMWriteDebugString.
	lpWriteDebugStringFunc(TEXT("\nWindows CE Firmware Init\r\n"));


#ifdef MODULE_CERTIFY
	//
	// Set the module signature verification hooks
	//
	pOEMLoadInit   = OEMLoadInit;
	pOEMLoadModule = OEMLoadModule;
	//
	// Init the signature verification public key
	//
	InitPubKey(g_bSignPublicKeyBlob,sizeof(g_bSignPublicKeyBlob));
#endif

    //
    // Set up translation constant for GetIdleTime() (1 ms units).
    // Note: Since curridlehigh, curridlelow is counting in ms, and GetIdleTime()
    // reports in ms, the conversion ratio is one.  If curridlehigh, curridlelow
    // were using other units (like ticks), then the conversion would be calculated
    // from the clock frequency.
    //
    idleconv = 1;

	// Initialize interrupts.
	//
    lpWriteDebugStringFunc(TEXT("INFO: Initializing system interrupts...\r\n"));
	OEMInitInterrupts();

	// Initialize the system clock(s).
	//
    lpWriteDebugStringFunc(TEXT("INFO: Initializing system clock(s)...\r\n"));
    InitClock();

    // Initialize driver globals area.
	//
    lpWriteDebugStringFunc(TEXT("INFO: Initializing driver globals area...\r\n"));
    memset((PVOID)DRIVER_GLOBALS_ZEROINIT_START, 0, DRIVER_GLOBALS_ZEROINIT_SIZE);
    
    // Initialize S2440X01 LCD controller
	InitDisplay();
#ifdef YL_2440_SUPPORT
	HzhInitPIO();
#endif
	
    // Initialize debug Ethernet (KITL) connection.
    //
	// InitDebugEther();	
 
	// Initialize GPIO	/// ;;; SHL
	s2440IOP->rPAD9 = (1<<12) | (0<<11);	// what is rPAD9? hzh
	//s2440IOP->rGPJCON = 0x016aaaa;
	//s2440IOP->rGPJUP  = ~((0<<12) | (1<<11));

	s2440IOP->rGPHCON = (s2440IOP->rGPHCON & ~(0xf<<18)) | (1<<20) | (1<<18);	// CLKOUT1, CLKOUT0

	s2440IOP->rDSC0 = 0x3ff;
	s2440IOP->rDSC1 = 0x3fffffff;

	// camera
	//Camera_Initialize();
	//s2440IOP->rGPJCON = 0x2aaaaaa;
	//s2440IOP->rGPJUP  = 0x1fff;

	InitSDMMC();

	// Initialize the ROM chain (multi-region).
	//
//	InitRomChain();
	lpWriteDebugStringFunc(TEXT("OEMInit Done...\r\n"));
}


//------------------------------------------------------------------------------
//  
//  @func   BOOL | OEMInterruptEnable | Enable a hardware interrupt
//  @rdesc  Returns TRUE if valid interrupt ID or FALSE if invalid ID.
//  @comm   This function is called by the Kernel when a device driver
//          calls <f InterruptInitialize>. The system is not preemptible when this
//          function is called.
//  @xref   <l Overview.Windows CE Kernel OEM Interface> <f InterruptInitialize>
//  
//------------------------------------------------------------------------------
BOOL 
OEMInterruptEnable(DWORD  idInt,	// @parm Interrupt ID to be enabled. See <l Interrupt ID's.Interrupt ID's>  for a list of possble values.
				   LPVOID pvData,	// @parm ptr to data passed in in the <f InterruptInitialize> call
		           DWORD  cbData)	// @parm Size of data pointed to be <p pvData>
{
	volatile INTreg *s2440INT = (INTreg *)INT_BASE;
	volatile IOPreg *s2440IOP = (IOPreg *)IOP_BASE;
	volatile MMCreg *s2440SDIO = (MMCreg *)MMC_BACE;
	BOOL bRet = TRUE;

	INTERRUPTS_OFF();
	
	switch (idInt) 
	{
	case SYSINTR_VMINI:		// Vmini.
		//return (TRUE);
		break;

	case SYSINTR_BREAK:		// There is no halt button on P2.
		//return(FALSE);
        break;


    case SYSINTR_DMA0:
        s2440INT->rINTMSK &= ~BIT_DMA0; // SDIO DMA interrupt
		//RETAILMSG(1,(TEXT("::: SYSINTR_DMA0    OEMInterruptDisable\r\n")));
       	break;

	case SYSINTR_SDMMC:
		s2440INT->rINTMSK &= ~BIT_MMC;

⌨️ 快捷键说明

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