/****************************************************************************** * * Name: main.C * * Description: Hardware initial main function * * Copyright: (c) 2005-2050 IC Plus Corp. * All rights reserved. By Chance * *******************************************************************************/ //20060110 #include #include #include #include "type_def.h" //#include "utility.h" #include "eepdef.h" #include "MACdriver.h" #include "public.h" #include "version.h" #include "flash.h" #include "httpd.h" #include "Warn_htm.h" SFILENAME * fs_open03(char *name); extern uFW_EE_Info* ptr_EE_Info; //#define FU_ALL_RUN_IN_MIRROR //volatile u8_t uip_acc32[4];//for macdriver extern u16_t Global_flash_ID; void bootmain(void); //SFILENAME * fs_open03(char *name); /****************************************************************************** * * Function: Check_MAC() * * Description: Check MAC Address Invalid or Valid * * Parameters: None * * Returns: If Valid return 1. Otherwise, return 0 * *******************************************************************************/ u8_t Check_MAC() { u8_t AllF_buf[size_EEMACID];//={0xff,0xff,0xff,0xff,0xff,0xff}; // u8_t All0_buf[size_EEMACID]={0x0,0x0,0x0,0x0,0x0,0x0}; u8_t valid_flag=1;//,fcount=0,zcount=0,i; memset(AllF_buf,0xFF,size_EEMACID); if(!memcmp(ptr_EE_Info->netif.MACID,AllF_buf,size_EEMACID)) { valid_flag=0; } memset(AllF_buf,0x00,size_EEMACID); if(!memcmp(ptr_EE_Info->netif.MACID,AllF_buf,size_EEMACID)) { valid_flag=0; } if((ptr_EE_Info->netif.MACID[0])&0x01) { valid_flag=0; } if(!valid_flag) { memcpy(ptr_EE_Info->netif.MACID, EE_Default.netif.MACID, size_EEMACID); } return valid_flag; } /****************************************************************************** * * Function: boot_proc() * * Description: Boot procedure * * Parameters: None * * Returns: None * *******************************************************************************/ void boot_proc() { //*********************************** // Switch(Flash_Type) //printf("boot_proc_1"); #ifdef FLASHERASE_IN_WHILE//sorbica071018 #else FirmwareUpdateEraseFlash();//sorbica071018 #endif//FLASHERASE_IN_WHILE//sorbica071018 //printf("boot_proc_2"); Timercounter_Init();//sorbica071024 EEPROMInit();//eeprom.h //printf("boot_proc_3"); //if(!Check_MAC()) { //printf("\n\n\rInvalid MAC Address in EEPROM. Please check EEPROM!\n\rMAC Address use default value now!"); } //printf("boot_proc_4"); TRACE_TEST(("\n->EEPROMInit()\n~")); MAC_init();//MACdriver.h //printf("boot_proc_5"); TRACE_TEST(("\n->MAC_init()\n~")); bootmain(); TRACE_TEST(("\n->bootmain()\n~")); } /****************************************************************************** * * Function: IP210_SWReset * * Description: Software reset * * Parameters: NONE * * Returns: NONE * *******************************************************************************/ void IP210_SWReset(void) { u8_t i; IP210RegWrite(REG_SW_RESET, 0x1); for(i=0;i<10;i++) _nop_(); } /****************************************************************************** * * Function: main * * Description: System initial * * Parameters: NONE * * Returns: NONE * *******************************************************************************/ extern u8_t flashcheck_error_flag; void main (void) { u8_t chk_tmp; IP210_SWReset();//utility.h WatchDogTimerInit(); WDT_DIS=0x0; //enable HW WDT WDTEN=1; //enable watch dog timer // WDT_DIS=0x1; // WDTEN=0; Serial_Init();//serial.h TRACE_TEST(("\n->Serial_Init()~")); printf("\n\r%s",FW_CODE_VERSION); chk_tmp=DBYTE[SFR_IE_TEMP]; TRACE_TEST(("\\n\r (%x)DBYTE[SFR_IE_TEMP]",(u16_t)chk_tmp)); //Mirro mode // printf("\n\r Before Mirror"); FirmwareUpdatMirrorMode(0x8000,0x0,0x2000); FlashIdentification(); #ifdef FU_ALL_RUN_IN_MIRROR//sorbica071008 #else Stop_Mirror_Mode(); #endif//sorbica071008 //printf("\n\r After Mirror"); //Check flash code if(chk_tmp==0xA6) { boot_proc(); // httpd_init_file(fs_open03("Warn.htm")); } else { if((!FirmwareUpdateFlashCheck())) { // printf("\nFlashCheck Error!"); //*********************************** flashcheck_error_flag=1; boot_proc(); // httpd_init_file(fs_open03("Warn.htm")); } else { printf("\nFlashCheck OK!"); //*********************************** //change to webcontrol code //*********************************** //printf("\nRun Webcontrol code!"); #ifdef FU_ALL_RUN_IN_MIRROR//sorbica071008 Stop_Mirror_Mode(); #endif//sorbica071008 CPU_GOTO_0000H(); } } }