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

📄 main.c

📁 aesop s3c2440a BSP for windowsce 6.0
💻 C
📖 第 1 页 / 共 4 页
字号:
//
// 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.
//
//
//
// 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.
//

#include <windows.h>
#include <bsp.h>
#include <ethdbg.h>
#include <fmd.h>
#include "loader.h"


char *inet_ntoa(DWORD dwIP);
DWORD inet_addr( char *pszDottedD );
BOOL EbootInitEtherTransport (EDBG_ADDR *pEdbgAddr, LPDWORD pdwSubnetMask,
                              BOOL *pfJumpImg,
                              DWORD *pdwDHCPLeaseTime,
                              UCHAR VersionMajor, UCHAR VersionMinor,
                              char *szPlatformString, char *szDeviceName,
                              UCHAR CPUId, DWORD dwBootFlags);
BOOL EbootEtherReadData (DWORD cbData, LPBYTE pbData);
EDBG_OS_CONFIG_DATA *EbootWaitForHostConnect (EDBG_ADDR *pDevAddr, EDBG_ADDR *pHostAddr);
// End   ***************************************


// Globals
//
DWORD			g_ImageType;
MultiBINInfo	g_BINRegionInfo;
PBOOT_CFG		g_pBootCfg;
UCHAR			g_TOC[SECTOR_SIZE];
const PTOC 		g_pTOC = (PTOC)&g_TOC;
DWORD			g_dwImageStartBlock;
DWORD			g_dwTocEntry;
BOOL			g_bBootMediaExist = FALSE;
BOOL			g_bDownloadImage  = TRUE;
BOOL 			g_bWaitForConnect = TRUE;

EDBG_ADDR 		g_DeviceAddr; // NOTE: global used so it remains in scope throughout download process
                        // since eboot library code keeps a global pointer to the variable provided.

// External definitions.
//
extern const BYTE ScreenBitmap[];


/*
    @func   void | SpinForever | Halts execution (used in error conditions).
    @rdesc  
    @comm    
    @xref   
*/
static void SpinForever(void)
{
    EdbgOutputDebugString("SpinForever...\r\n");

    while(1)
    {
        ;
    }
}


/*
    @func   void | main | Samsung bootloader C routine entry point.
    @rdesc  N/A.
    @comm    
    @xref   
*/

void main(void)
{
    // Clear LEDs.
    //   
//    OEMWriteDebugLED(0, 0xF);
	
    // Common boot loader (blcommon) main routine.
    //    
    BootloaderMain();

    // Should never get here.
    // 
    SpinForever();
}


char *disp32bit(unsigned int data)
{
    unsigned int mask = 0x80000000;
    int j, bufidx=0;
    static char buf[32+8];
    //char buf[32+8];
     
    for(j=0; j<32; j++)
    {
        if( data&mask ) // !0
        {
                if( (j%4) == 3 )
                { 
               buf[bufidx++] = '1';
               buf[bufidx++] = ' ';
            }
            else
            {
                buf[bufidx++] = '1'; 
            }
        }
        else // 0
        {
                if( (j%4) == 3 )
                {
               buf[bufidx++] = '0';
               buf[bufidx++] = ' ';
            }
            else
            {
                buf[bufidx++] = '0';
            }
        }

        mask >>= 1;
    }

    buf[bufidx] = 0;

    return buf;
    //printf("%s\n", buf);
}

/*
    @func   void | InitDisplay | Initializes the LCD controller and displays a splashscreen image.
    @rdesc  N/A.
    @comm    
    @xref   
*/
static void InitDisplay(void)
{
    volatile S3C2440A_IOPORT_REG *s2440IOP = (S3C2440A_IOPORT_REG *)OALPAtoVA(S3C2440A_BASE_REG_PA_IOPORT, FALSE);
    volatile S3C2440A_LCD_REG    *s2440LCD = (S3C2440A_LCD_REG *)OALPAtoVA(S3C2440A_BASE_REG_PA_LCD, FALSE);
    unsigned int clkval_calc;  // 040507
    volatile S3C2440A_CLKPWR_REG *s2440CLKPWR = (S3C2440A_CLKPWR_REG *)OALPAtoVA(S3C2440A_BASE_REG_PA_CLOCK_POWER, FALSE);
    volatile S3C2440A_UART_REG *pUARTReg = (S3C2440A_UART_REG *)OALPAtoVA(S3C2440A_BASE_REG_PA_UART0, FALSE);

EdbgOutputDebugString("InitDisplay = %x\n", (int)InitDisplay);

EdbgOutputDebugString("%x\n", s2440CLKPWR->LOCKTIME);
EdbgOutputDebugString("%x\n", s2440CLKPWR->MPLLCON);
EdbgOutputDebugString("%x\n", s2440CLKPWR->UPLLCON);
EdbgOutputDebugString("%x\n", s2440CLKPWR->CLKCON);
EdbgOutputDebugString("%x\n", s2440CLKPWR->CLKSLOW);
EdbgOutputDebugString("%x\n", s2440CLKPWR->CLKDIVN);
EdbgOutputDebugString("%x\n", s2440CLKPWR->CAMDIVN);

EdbgOutputDebugString("%x\n", pUARTReg->UBRDIV);

	// Set up the LCD controller registers to display a power-on bitmap image.
    //
    s2440IOP->GPCUP     = 0xFFFFFFFF;
    s2440IOP->GPCCON    = 0xAAAAAAAA;
                                    
    s2440IOP->GPDUP     = 0xFFFFFFFF;
    s2440IOP->GPDCON    = 0xAAAAAAAA; 


        s2440IOP->GPCDAT = 0x000000e0;
        s2440IOP->GPCUP  = 0x0000ffff;
        s2440IOP->GPCCON = 0xaaaa56a9;

	s2440IOP->GPDDAT = 0x00000000;
        s2440IOP->GPDUP  = 0x0000ffff;
        s2440IOP->GPDCON = 0xaaaaaaaa;


#define S3C2410_LCDCON1_TFT24BPP (13<<1)

#define H_FP    1               /* front porch */
#define H_SW    40              /* Hsync width  */
#define H_BP    1               /* Back porch */

#define V_FP    1               /* front porch */
#define V_SW    9               /* Vsync width */
#define V_BP    1               /* Back porch */

#define H_RESOLUTION    480     /* x resolition */
#define V_RESOLUTION    272     /* y resolution  */
#define VFRAME_FREQ     60      /* frame rate freq. */
#define LCD_PIXEL_CLOCK (VFRAME_FREQ *(H_FP+H_SW+H_BP+H_RESOLUTION) * (V_FP+V_SW+V_BP+V_RESOLUTION))

#define DIV  S3C2440A_HCLK/(LCD_PIXEL_CLOCK)
clkval_calc = (DIV/2)-1;
if(clkval_calc<0)
   clkval_calc = 0;

//	clkval_calc = (WORD)((float)(S3C2440A_HCLK)/(2.0*5000000)+0.5)-1;
    s2440LCD->LCDCON1   =  (clkval_calc           <<  8) |       /* VCLK = HCLK / ((CLKVAL + 1) * 2) -> About 7 Mhz  */
                           (3           <<  5) |       /* TFT LCD Pannel                                   */
                           (12          <<  1) |       /* 16bpp Mode                                       */
//                           (13          <<  1) |       /* 24bpp Mode                                       */
                           (0           <<  0) ;       /* Disable LCD Output                               */

    s2440LCD->LCDCON2   =  (V_BP        << 24) |   /* VBPD          :   1                              */
                           ((V_RESOLUTION-1) << 14) |   /* Vertical Size : 272 -1                             */
                           (V_FP        <<  6) |   /* VFPD          :   2                              */
                           (V_SW        <<  0) ;   /* VSPW          :   1                              */

    s2440LCD->LCDCON3   =  (H_BP        << 19) |   /* HBPD          :   6                              */
                           ((H_RESOLUTION-1)  <<  8) |   /* HOZVAL_TFT    : 240 - 1                          */
                           (H_FP        <<  0) ;   /* HFPD          :   2                              */


    s2440LCD->LCDCON4   =  (H_SW        <<  0) ;   /* HSPW          :   4                              */

#if 0
    s2440LCD->LCDCON5   =  (1           << 11) |       /* FRM565 MODE   : 5:6:5 Format                     */
                           (1           <<  9) |       /* INVVLINE      : Inverted Polarity                */
                           (1           <<  8) ;       /* INVVFRAME     : Inverted Polarity                */


    s2440LCD->LCDCON5   =  (1           << 11) |       /* FRM565 MODE   : 5:6:5 Format                     */
                           (1           <<  9) |       /* INVVLINE      : Inverted Polarity                */
                           (1           <<  8) |       /* INVVFRAME     : Inverted Polarity                */
                           (1           <<  0) ;       /* Half-Word swap control bit.        in case 16bpp    */
#endif

#if 0    
    s2440LCD->LCDSADDR1 = ((IMAGE_FRAMEBUFFER_DMA_BASE >> 22)     << 21) | 
                          ((M5D(IMAGE_FRAMEBUFFER_DMA_BASE >> 1)) <<  0);

    s2440LCD->LCDSADDR2 = M5D((IMAGE_FRAMEBUFFER_DMA_BASE + (H_RESOLUTION * 4 * (V_RESOLUTION+0))) >> 1);
#else
        s2440LCD->LCDSADDR1 = (IMAGE_FRAMEBUFFER_DMA_BASE >> 1);
        s2440LCD->LCDSADDR2 = ((IMAGE_FRAMEBUFFER_DMA_BASE & 0x3ffffe) + H_RESOLUTION * 2 * (V_RESOLUTION + 0)) >> 1;
#endif    
    s2440LCD->LCDSADDR3 = ( H_RESOLUTION*2/ 2);        

    //s2440LCD->TCONSEL   |= 0x3;
#if 0
    s2440LCD->TCONSEL   &= (~7);
    s2440LCD->TCONSEL   |= (0x1<<4);
#endif
    s2440LCD->TCONSEL   = 0xe0;

    s2440LCD->TPAL      = 0x0;        

 
#if 1    
        EdbgOutputDebugString("con1:    %s   %x\n", disp32bit(s2440LCD->LCDCON1),s2440LCD->LCDCON1);
        EdbgOutputDebugString("con2:    %s   %x\n", disp32bit(s2440LCD->LCDCON2),s2440LCD->LCDCON2);
        EdbgOutputDebugString("con3:    %s   %x\n", disp32bit(s2440LCD->LCDCON3),s2440LCD->LCDCON3);
        EdbgOutputDebugString("con4:    %s   %x\n", disp32bit(s2440LCD->LCDCON4),s2440LCD->LCDCON4);
        EdbgOutputDebugString("con5:    %s   %x\n", disp32bit(s2440LCD->LCDCON5),s2440LCD->LCDCON5);
        EdbgOutputDebugString("adr1:    %s   %x\n", disp32bit(s2440LCD->LCDSADDR1),s2440LCD->LCDSADDR1);
        EdbgOutputDebugString("adr2:    %s   %x\n", disp32bit(s2440LCD->LCDSADDR2),s2440LCD->LCDSADDR2);
        EdbgOutputDebugString("adr3:    %s   %x\n", disp32bit(s2440LCD->LCDSADDR3),s2440LCD->LCDSADDR3);
        EdbgOutputDebugString("TCONSEL: %x\n", (s2440LCD->TCONSEL));
        EdbgOutputDebugString("TPAL:    %x\n", (s2440LCD->TPAL));
#endif

    s2440LCD->LCDCON1  |= 1;

    // Display a bitmap image on the LCD...
    //
#if 0
    EdbgOutputDebugString("Display init...1\r\n");
    while(1)
    {
          int ii;
          int iii;
	  volatile UINT *fp;

          for(iii=0;iii<20;iii++)
          {
	  fp = (volatile UINT *)IMAGE_FRAMEBUFFER_UA_BASE;
          for(ii=0;ii<480*272;ii++)
          {
                 *fp = 0x00ff0000;
                 fp++;
          }
          }


          for(iii=0;iii<20;iii++)
          {
	  fp = (volatile UINT *)IMAGE_FRAMEBUFFER_UA_BASE;
          for(ii=0;ii<480*272;ii++)
              {
                     *fp = 0xffffffff;
                    fp++;
          }
          }
    }
#else
//    memcpy((void *)IMAGE_FRAMEBUFFER_UA_BASE, ScreenBitmap, LCD_ARRAY_SIZE_TFT_16BIT);
    memcpy((void *)IMAGE_FRAMEBUFFER_UA_BASE, ScreenBitmap, 480*272*2);
#endif
    
}


/*
    @func   void | SetIP | Accepts IP address from user input.
    @rdesc  N/A.
    @comm    
    @xref   
*/

static void SetIP(PBOOT_CFG pBootCfg)
{
    CHAR   szDottedD[16];   // The string used to collect the dotted decimal IP address.
    USHORT cwNumChars = 0;
    USHORT InChar = 0;

    EdbgOutputDebugString("\r\nEnter new IP address: ");

    while(!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
        {
            // If it's a number or a period, add it to the string.
            //
            if (InChar == '.' || (InChar >= '0' && InChar <= '9')) 
            {
                if (cwNumChars < 16) 
                {
                    szDottedD[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up.
            //
            else if (InChar == 8) 
            {
                if (cwNumChars > 0) 
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    //
    if (cwNumChars) 
    {
        szDottedD[cwNumChars] = '\0';
        pBootCfg->EdbgAddr.dwIP = inet_addr(szDottedD);
    }
}


/*
    @func   void | SetMask | Accepts subnet mask from user input.
    @rdesc  N/A.
    @comm    
    @xref   
*/
static void SetMask(PBOOT_CFG pBootCfg)
{
    CHAR szDottedD[16]; // The string used to collect the dotted masks.
    USHORT cwNumChars = 0;
    USHORT InChar = 0;

    EdbgOutputDebugString("\r\nEnter new subnet mask: ");

    while(!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
        {
            // If it's a number or a period, add it to the string.

⌨️ 快捷键说明

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