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

📄 main.c

📁 一种操作系统源码核
💻 C
字号:
#include <absacc.h>
#include <INTRINS.H>
#include "page1.h"
sbit bResetNe2000 = P1^2;
volatile BOOLEAN Timer_bIndicated;		// indicate 0.2 second timer
static DCHAR _iWholeSecond;
static DCHAR _iTimer;
static DCHAR _iTH0;
static DCHAR _iTL0;
 DCHAR  iIpackId;
static XLONG _lSleepDivide;
static BOOLEAN bArpResolved;
extern PXCHAR  _pSerialSendbuf;//serial inout buffer pointer
extern PXCHAR _pSerialRevbuf; 
extern BOOLEAN bSerialMode;
extern XCHAR  _SerialTcpOutPostion;  //serial next send TcpPacket store postion
extern XCHAR _SerialPortInPosition; //serial port in postion
static BOOLEAN	Dhcp_bEnable;

void main(void)
{
   Udp_bOutputDebug=0;
   Udp_bBroadcastDebug=0;
  _iWholeSecond=0;
    bResetNe2000=1;
    _nop_();
    bResetNe2000=0;
    bArpResolved=FALSE;
    SysSleep(2000);       //delay 2ms to load the contexts  of 9346
    SramInitialize();
    Ne2000Initialize();
    if (Adapter_bOK)
	 {
	     	ProtocolInitialize();
	 }
	 ControlInitialize();
    Led_Off(NORMAL_LIGHT);
  //   SerialSend();  //Serial port send,prepared tcp out data,arpsend
    while (1)
    {
//	 TA=0XAA;
 //	TA=0x55;
//	  RWT=1; //reset watchDog in period;
 		if (Adapter_bOK)
		{
			Ne2000Run();
			if ((_SerialPortInPosition!=_SerialTcpOutPostion) && (bSerialMode!=SERVERMODE))
			{
			  ArpSend(Remote_pIPAddress);    //if serial send buffer is not empty entry client mode
           bSerialMode=CLIENTMODE;
         }
          //UdpDebugUpdate();
		}
		if (Timer_bIndicated)
		{
		 _iWholeSecond ++;
			if (_iWholeSecond == 0x32)
			{
			   Led_On(NORMAL_LIGHT);
				_iWholeSecond = 0;
			}
			else if (_iWholeSecond == 0x19)
				ProtocolHandleTimer();
		
			Timer_bIndicated = FALSE;
		}   //Timer_bIndicated
	}     //while
}    //main
void Timer0Interrupt() interrupt 1
{
	
    _iTimer ++;
    if (_iTimer == 10)	// 0.2 second timer
    {
        _iTimer = 0;
		Timer_bIndicated = TRUE;
    }

    // set the initial number again
	TH0 = _iTH0;
    TL0 = _iTL0;
}

void WatchDogInterrupt() interrupt 12  using 2
{
// Debugstrimg("WatchDogInterrupt occuer");              
}
void SerialInterrupt() interrupt 5 using 2
{

SerialHandleInterrupt();
}
void Ne2000Interrupt() interrupt 2 using 2
{
	
  	    Ne2000HandleInterrupt();
	
}
void TaskHandleTimer()
{
	
	 TelnetHandleTimer();
     SerialHandleTimer();

}
void 	ProtocolHandleTimer()
{
 //if(bEnableDhcp)
  //   DHCPHANDLETIMER;
 // if(bDhcpUnfinished)
 // {
   ArpHandleTimer();
 // TimeHandleTimer;
   TaskHandleTimer();
//  }
}
  
void ProtocolInitialize()
{
  //0x6b1e~0x6b1f=0
       iIpackId=0;
  if (Dhcp_bEnable)
  {
     UdpInitialize();
   //  DHCPINITIALIZE();
  //   DHCPDISCOVER();
     DebugVal(0x1041);
  
   }
  else{
    bDhcpUnFinished=1;
    UdpInitialize();
	ArpInitialize();
    IcmpInitialize();
	TcpInitialize();
   // TimeIntialize ();

    TaskInitialize();
   }
	
}

void SysSleep(ULONG lUSecond)
{
	XLONG l;
	lUSecond /= _lSleepDivide;
	for (l = 0; l < lUSecond; l ++)
	{
	}
}


// Call this function just before entering main loop
void ControlInitialize()
{
 #ifdef VER_P89C51DX2 
  bit EXTRAM=AUXR&04;
  EXTRAM=0; //enable ext ram
 #endif
#ifdef VER_W78E56
  PMR=0x8f; //enable ext ram
 #endif
	TMOD = 0x21;		// T/C0 function mode 1 timer; T/C1 function mode 2 timer for serial communication
    CKCON &= 0xe7;		// timer0, timer 1 count by clk/12
	TH0 = _iTH0;		// set timer 0 initial number, make it interrupt every 20ms
	TL0 = _iTL0;
	TR0 = 1;    //timer0 start
//	IP = 0;				// no interrupt has higher piority
//    IE = 0x96;		// enable timer0, serial and external 1 interrupts; EA = 1, ES = 1, EX1 = 1, ET0 = 1
  	EA = 1;
	ET0 = 1;
 	EX1 = 1;      
  
  // TA=0XAA;
//	TA=0x55;
//	WDCON=02;//enable WatchDog
	
	EWDI=1;//enable watchdog interrupt
   
  
}
void   TaskInitialize()
{
  SerialInitialize();
  TelnetInitialize();
 
}











⌨️ 快捷键说明

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