📄 main.c
字号:
/*
* Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* Author: Li Zhanglin <wzzlin@nankai.edu.cn>
*
*/
#include "..\GloblDef\GloblDef.h"
#include "..\TCPIP\TCPIPmem.h"
#include "..\Netif\RTL8019.h"
#include "..\TCPIP\IP.h"
#include "..\Netif\etherif.h"
#include "..\Netif\ARP.h"
#include "..\TCPIP\Netif.h"
#include "..\TCPIP\TCP.h"
#include "..\App\main.h"
BYTE DT_XDATA text_header[] = "HTTP/1.0 200K\r\nContent-Type: text/html\r\n\r\n";
BYTE DT_XDATA jpeg_header[] = "HTTP/1.0 200K\r\nContent-Type: image/jpeg\r\n\r\n";
BYTE DT_XDATA text_Content[]= "<html>Device Test!\n</html>";
socket DT_XDATA * DT_XDATA ExAccept;
socket DT_XDATA * DT_XDATA ExListen;
void OnAcceptRecv(void DT_XDATA *buf,WORD size) REENTRANT_MUL
{
buf = buf; size = size;
/* send back data */
TCPSend(ExAccept,text_header,sizeof(text_header));
TCPSend(ExAccept,text_Content,sizeof(text_Content));
for(size=0; size<0x1000; size++);
TCPClose(ExAccept);
}
void OnAccept(socket DT_XDATA *pNewSocket) REENTRANT_MUL
{
ExAccept = pNewSocket;
pNewSocket->recv = OnAcceptRecv;
pNewSocket->close = OnClose;
}
void OnClose(socket DT_XDATA * pSocket) REENTRANT_MUL
{
TCPClose(pSocket);
}
void Timer() REENTRANT_MUL interrupt 1
{
TH0 = 0x3C;
TL0 = 0xAA;
NetIfTimer();
ARPTimer();
TCPTimer();
}
void SerialInit()
{
SCON = 0x50; /* SM0SM1=01 SM2 REN TB8 RB8 TI RI */
PCON = 0x80;
TMOD = 0x20;
TH1 = 0xF3; /* TH1=F3,9600B,24MHz */
TR1 = 1;
}
void InterruptInit()
{
TMOD |= 0x01; /*GATE=0 C/T=0 M1M0=00*/
TH0 = 0x3C; /* TIMER_24M_25MS_H */
TL0 = 0xAA; /* TIMER_24M_25MS_L */
TR0 = 1;
ET0 = 1;
EA = 1;
}
main()
{
struct SEtherDevice DT_XDATA DevRTL;
IP_ADDR IPAddr = 0xC0A801FE; /* 192.168.1 .254 */
IP_ADDR NetMask = 0xFFFFFF00; /* 255.255.255.0 */
IP_ADDR GateWay = 0xC0A80101; /* 192.168.1 .1 */
BYTE DT_XDATA EtherAddr[ETHER_ADDR_LEN] = {0x00,0x4F,0x49,0x12,0x12,0x12};
/* init */
ARPInit();
TCPInit();
MemInit();
NetIfInit();
RTLInit(EtherAddr);
/* init Devcie struct and init this device */
EtherDevInit(&DevRTL,EtherAddr,RTLSendPacket,RTLReceivePacket);
NetIfAdd(IPAddr,NetMask,GateWay,EtherInput,EtherOutput,&DevRTL);
/* start */
SerialInit();
InterruptInit();
/* listen */
ExAccept = NULL;
ExListen = TCPSocket(IPAddr);
TCPListen(ExListen,80,OnAccept);
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -