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

📄 u241mon.c

📁 三星2410源代码
💻 C
字号:
/****************************************************************
 NAME: u241mon.c
 DESC: u241mon entry point,menu,download
 HISTORY:
 Mar.25.2002:purnnamu: S3C2400X profile.c is ported for S3C2410X.
 Mar.27.2002:purnnamu: DMA is enabled.
 Apr.01.2002:purnnamu: isDownloadReady flag is added.
 Apr.10.2002:purnnamu: - Selecting menu is available in the waiting loop. 
                         So, isDownloadReady flag gets not needed
                       - UART ch.1 can be selected for the console.
 Aug.20.2002:purnnamu: revision number change 0.2 -> R1.1       
 Sep.03.2002:purnnamu: To remove the power noise in the USB signal, the unused CLKOUT0,1 is disabled.
 ****************************************************************/

#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
#include "u241mon.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2410usb.h"
#include "lcdlib.h"
#include "Glib.h"
#include "eint.h"

void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);


//#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
volatile U32 downloadAddress;

void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);


volatile unsigned char *downPt;
volatile U32 downloadFileSize;
volatile U16 checkSum;
volatile unsigned int err=0;
volatile U32 totalDmaCount;

volatile int isUsbdSetConfiguration;

int download_run=0;
U32 tempDownloadAddress;
int menuUsed=0;

extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;

void Main(void)
{
    char *mode;
    int i;
    U8 key;
    
    #if ADS10   
    __rt_lib_init(); //for ADS 1.0
    #endif

     ChangeClockDivider(1,1);    // 1:2:4   
     // rCLKDIVN=0x4;    //  1:4:4
     //ChangeMPllValue(0x92,0x4,0x2);    // FCLK=50MHz    
     //ChangeMPllValue(82,2,1);  //FCLK=135.0Mhz     
        ChangeMPllValue(82,1,1);    //FCLK=180.0Mhz     
    //ChangeMPllValue(161,3,1); //FCLK=202.8Mhz 
    //ChangeMPllValue(117,1,1);    //FCLK=250.0Mhz 
    //ChangeMPllValue(122,1,1);    //FCLK=260.0Mhz 
    //ChangeMPllValue(125,1,1);    //FCLK=266.0Mhz 
    //ChangeMPllValue(127,1,1);    //FCLK=270.0Mhz  
   // ChangeMPllValue(126,1,1);    //FCLK=268.0Mhz   
    
    Port_Init();
    
    rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);   
    //To enhance the USB signal quality.
    //CLKOUT 0,1=OUTPUT to reduce the power consumption.
    
    Isr_Init();
    if(*pMagicNum!=0x12345678)
    	consoleNum=0;
    else
    	consoleNum=1;
    	
    Uart_Init(0,115200);
    Uart_Select(consoleNum);

    rMISCCR=rMISCCR&~(1<<3); // USBD is selected instead of USBH1 
    rMISCCR=rMISCCR&~(1<<13); // USB port 1 is enabled.

//
//  USBD should be initialized first of all.
//

#if 0
    UsbdMain(); 
    MMU_Init(); //MMU should be reconfigured or turned off for the debugger, 
    //After downloading, MMU should be turned off for the MMU based program,such as WinCE.	
//#else
      isUsbdSetConfiguration=0;
      MMU_EnableICache();
      UsbdMain(); 
#endif
    Delay(0);  //calibrate Delay()
    
    pISR_SWI=(_ISR_STARTADDRESS+0xf0);    //for pSOS

    Led_Display(0x6);

#if USBDMA
    mode="DMA";
#else
    mode="Int";
#endif


    Uart_Printf("\n\n");
    Uart_Printf("+---------------------------------------------+\n");
    Uart_Printf("| S3C2410X USB Downloader ver R1.12 05/20/03  |\n");
    Uart_Printf("+---------------------------------------------+\n");
    Uart_Printf("FCLK=%dMHz,%s mode\n",FCLK/1000000,mode); 
    Uart_Printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n"); 
    Uart_Printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
    Uart_Printf("NOTE: 1. Power off/on or press the reset button for 1 sec\n");
    Uart_Printf("         in order to get a valid USB device address.\n");
    Uart_Printf("      2. For additional menu, Press any key. \n");
    Uart_Printf("\n");

    download_run=1; //The default menu is the Download & Run mode.
    Module_Test();

}





void Isr_Init(void)
{
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK=BIT_ALLMSK;	  // All interrupt is masked.

    //pISR_URXD0=(unsigned)Uart0_RxInt;	
    //rINTMSK=~(BIT_URXD0);   //enable UART0 RX Default value=0xffffffff

#if 1
    pISR_USBD =(unsigned)IsrUsbd;
    pISR_DMA2 =(unsigned)IsrDma2;
#else
    pISR_IRQ =(unsigned)IsrUsbd;	
    	//Why doesn't it receive the big file if use this. (???)
    	//It always stops when 327680 bytes are received.
#endif    
    ClearPending(BIT_DMA2);
    ClearPending(BIT_USBD);
    //rINTMSK&=~(BIT_USBD);  
   
    //pISR_FIQ,pISR_IRQ must be initialized
}


void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}


void LCD_Command_Write(unsigned short cmd)
{
   Command_Write=(unsigned short)cmd;
}
void LCD_Data_Write(U16 data)
{
   Data_Write=(U16)data;
}

void LCD_RESET(void)
{
       rGPADAT=0x7fffff;
	Delay(100);
	rGPADAT=0x7ff7ff;
	Delay(1000);
	rGPADAT=0x7fffff;
	Delay(100);
}


void LCD_init(void)
{   




LCD_Command_Write(0x002C);  //Standby Mode OFF
   Delay(50);
 LCD_Command_Write(0x00EB); //MTP mode on
   Delay(50); 
 LCD_Command_Write(0x0002);  //Oscillation Mode Set
 LCD_Command_Write(0x0001);  //EXT=0; OSC=1
   Delay(20);
 LCD_Command_Write(0x0020);  //DC-DC Select
 LCD_Command_Write(0x000a); //DC(2)=10;DC(1)=10
   Delay(20);
 LCD_Command_Write(0x0026);  //DC/DC and AMP ON/OFF Set
 LCD_Command_Write(0x0001); //AMP=0; DCDC3=0; DCDC2=0; DCDC1=1
   Delay(20); 
 LCD_Command_Write(0x0026);  
 LCD_Command_Write(0x0009); //AMP=1; DCDC3=0 DCDC2=0 DCDC1=1
   Delay(20); 
 LCD_Command_Write(0x0026);  
 LCD_Command_Write(0x000B); //AMP=1; DCDC3=0; DCDC2=1; DCDC1=1
   Delay(20); 
 LCD_Command_Write(0x0026);  
 LCD_Command_Write(0x000F); //AMP=1 DCDC3=1 DCDC2=1 DCDC1=1
   Delay(20); 
 LCD_Command_Write(0x0028);  //Temperature Compensation Set
 LCD_Command_Write(0x0001); //TCS=01
   Delay(20); 
LCD_Command_Write(0x0045);//RAM Skip Area Set
LCD_Command_Write(0x0000);//RSK=00
LCD_Command_Write(0x0053);//Specified Display Pattern Set
LCD_Command_Write(0x0000);//SDP=00;
LCD_Command_Write(0x0010);//Driver Output Mode Set
LCD_Command_Write(0x0025);//DLN=10;SDIR=1; SWP=0; CDR=1
LCD_Command_Write(0x0022);//Bias Set
LCD_Command_Write(0x0011);//Bias(2)=01;Bias(1)=01
LCD_Command_Write(0x0024);//DCDC Clock Division Set(
LCD_Command_Write(0x0011);//DIV(2)=01;DIV(1)=01
LCD_Command_Write(0x002A);//Contrast Control (1)
LCD_Command_Write(0x0bf);
LCD_Command_Write(0x002B);//Contrast Control (2) 
LCD_Command_Write(0x0054);
LCD_Command_Write(0x0030);//Addressing Mode Set
LCD_Command_Write(0x0005);//GSM=00; DSG=0; SGF=0; SGP=01; SGM=0
LCD_Command_Write(0x0032);//Row Vector Mode Set
LCD_Command_Write(0x000E);//INC=111; VEC=0
LCD_Command_Write(0x0034);//N-block inversion Set
LCD_Command_Write(0x0092);//FIM=1; FIP=0; N-block inversion=00010
LCD_Command_Write(0x0036);//Frame Frequency Control
LCD_Command_Write(0x0000);//LFS=0
LCD_Command_Write(0x0040);//Entry Mode Set
LCD_Command_Write(0x0000);//MDI=0; X/Y=0; RMW=0
LCD_Command_Write(0x0042);//X Address Area Set
LCD_Command_Write(0x0000);//X start address set=00
LCD_Command_Write(0x009F);//X end address set=9fh
LCD_Command_Write(0x0043);//Y Address Area Set
LCD_Command_Write(0x0004);//Y start address set=04h
LCD_Command_Write(0x0083);//Y end address set=83h
LCD_Command_Write(0x0055);//Partial Display Mode Set
LCD_Command_Write(0x0001);//PDM=0; PT=1
LCD_Command_Write(0x005A);//Scroll Start Line Set
LCD_Command_Write(0x0000);//Scroll Start Line Set=00h
LCD_Command_Write(0x0051); //Display ON




	
}

void Display_black(unsigned short data)
{
unsigned long i,j;
/* LCD_Command_Write(0x4c);
 LCD_Command_Write(0x46);
 LCD_Data_Write(0x00);
 LCD_Data_Write(0x00);
 LCD_Command_Write(0x42);

 for(i=0;i<9600;i++)
 	{
 	 LCD_Data_Write(data);
 	}	

*/

LCD_Command_Write(0x0040);//Entry Mode Set
LCD_Command_Write(0x0000);//MDI=0; X/Y=0; RMW=0
LCD_Command_Write(0x0042);//X Address Area Set
LCD_Command_Write(0x0000);//X start address set=00
LCD_Command_Write(0x009F);//X end address set=9fh
LCD_Command_Write(0x0043);//Y Address Area Set
LCD_Command_Write(0x0004);//Y start address set=04h
LCD_Command_Write(0x0083);//Y end address set=83h
LCD_Command_Write(0x51);
 for(i=0;i<128;i++)
    for(j=0;j<160;j++)
     {
	 LCD_Data_Write(0x0f8);
	 LCD_Data_Write(0x000);
	 }
}

void Display_Box(void)
{
    unsigned long i,j;
    LCD_Command_Write(0x0051);
    for(i=0;i<128;i++)
      { LCD_Data_Write(0xFFFF); LCD_Data_Write(0xFFFF); 
    }
    
	for(i=0;i<158;i++)
      {  
	     LCD_Data_Write(0xFFFF);LCD_Data_Write(0xFFFF);
		 for(j=0;j<126;j++)
           {  LCD_Data_Write(0x0000); LCD_Data_Write(0x0000);}
		 LCD_Data_Write(0xffff);  LCD_Data_Write(0xffff); 
      }
    for(j=0;j<128;j++)
      {  LCD_Data_Write(0xFFFF); LCD_Data_Write(0xffff);  }



	
}

void Display_Window(U16 star_address,U16 length,U16 wide,U8*chpt)
{
	U16 addressL,addressH,data,i,j,temp;
	U8*chp;
	chp=chpt;
	temp=star_address;
	for(j=0;j<wide;j++)
		{
		       star_address=temp+((LCD_1N0160_LENGTH/8)*j);
			addressL=star_address&0x00ff;
			addressH=(star_address>>8)&0x00ff;
			LCD_Command_Write(0x4c);
			LCD_Command_Write(0x46);
			LCD_Data_Write(addressL);
			LCD_Data_Write(addressH);
			LCD_Command_Write(0x42);

			for(i=0;i<(length/8);i++)
				{
				data=*chp;
				LCD_Data_Write(data);
				chp++;
				}
		}
}

int Set_menu()
{
if(Flag_IRQ0()==1)
{
Display_Window(menu_keyone_startaddress,menu_key_length, menu_key_wide, frame);
Display_Window(menu_keytwo_startaddress,menu_key_length, menu_key_wide, frame);
Display_Window(menu_keythree_startaddress,menu_key_length, menu_key_wide, page_down);
Display_Window(menu_keyfour_startaddress,menu_key_length, menu_key_wide, back);
Display_Window(value_area_address,setting_frame_area_lenght,setting_frame_area_wide, Help_Page_One);

   }
else
return 0;
}

void Display_normal_powerup(void)
{
	Display_Window(menu_keyone_startaddress,menu_key_length, menu_key_wide, help);
	Display_Window(menu_keytwo_startaddress,menu_key_length, menu_key_wide, setting);
	Display_Window(menu_keythree_startaddress,menu_key_length, menu_key_wide, frame);
	Display_Window(menu_keyfour_startaddress,menu_key_length, menu_key_wide, shift);
	Display_Window(table_pointer_a_address,oil_temp_icon_lenght, oil_temp_icon_wide, oil_temp_a);
	Display_Window(table_pointer_b_address,oil_temp_icon_lenght, oil_temp_icon_wide, oil_press);
	Display_Window(table_pointer_c_address,water_temp_icon_lenght,water_temp_icon_wide, water_temp);
	Display_Window(table_pointer_d_address,oil_box_icon_lenght,oil_box_icon_wide, oil_box);
	Display_Window(value_area_address,value_area_lenght,value_area_wide, value_area);
	Display_Window(information_address,information_area_lenght,information_area_wide, normal_operation);
	Display_Window(bottom_frame_address,bottom_frame_area_lenght,bottom_frame_area_wide, bottom_frame);


}
int Module_Test()
{
//	 int i,j,k,l,m; 	
	MMU_Init();
       Port_Init();
	LCD_RESET();
	LCD_init();

//	Display_Box();
//	Init_Keypad();  
  Delay(20000);
	Display_black(0x00);
	
  Delay(20000);
	
	
	Display_normal_powerup();
	
	while(1)
		{
//		Uart_Printf("waiting for Eint!\n");   
//		Uart_Printf("Flag_IRO0()=%d\n",Flag_IRQ0()); 
		if(Flag_IRQ0()==1)
			Set_menu();
		else
			{}
		}
//	Uart_Printf("Flag_IRO0()=%d\n",Flag_IRQ0()); 

   return 0;
}



⌨️ 快捷键说明

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