📄 main.lst
字号:
C51 COMPILER V8.02 MAIN 10/17/2006 16:52:41 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE MAIN.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 ********************************************************************************
3 * Wiznet.
4 * 5F Simmtech Bldg., 228-3, Nonhyun-dong, Kangnam-gu,
5 * Seoul, Korea
6 *
7 * (c) Copyright 2002, Wiznet, Seoul, Korea
8 *
9 * Filename : main.c
10 * Programmer(s):
11 * Created : 2002/01/
12 * Modified : Date - 2002/10/28
13 * Description - All file revision
14 * - Version up W3100A driver (V2.0->V2.2)
15
16 * Description : Loopback program by using TCP server mode for EVB8051
17 ********************************************************************************
18 */
19
20 /*
21 ###############################################################################
22 Include Part
23 ###############################################################################
24 */
25 #include <at89x51.h> // Definition file for 8051 SFR
26 #include <stdio.h> // to use printf
27 #include "serial.h" // serial related functions
28 #include "socket.h" // W3100A driver file
29 #include "lcd.h" // lcd fucntion
30 #include "at24c02.h" // EEPROM
31 #include "netconf.h" // Network Configuration
32 #include "sockutil.h" // W3100A Useful funtion
33
34 /*
35 ###############################################################################
36 Define Part
37 ###############################################################################
38 */
39 #define MAX_BUF_SIZE 2048 // Maximum receive buffer size
40
41
42 /*
43 ###############################################################################
44 Local Variable Declaration Part
45 ###############################################################################
46 */
47 sfr CKCON = 0x8F; // CKCON Reg. Define
48 u_char xdata * data_buf = 0x7000; // Position of receive buffer
49
50 /*
51 ###############################################################################
52 Function Prototype Declaration Part
53 ###############################################################################
54 */
55 void Init8051();
C51 COMPILER V8.02 MAIN 10/17/2006 16:52:41 PAGE 2
56 void init_sock(u_char i);
57 void InitNetConfig(void);
58
59
60 /*
61 ###############################################################################
62 Function Implementation Part
63 ###############################################################################
64 */
65 /*
66 ********************************************************************************
67 * Main function to run loopback function
68 *
69 * Description: After initialization of 8051 and W3100A, wait for connection request from a peer.
70 * And do loopback function which sends back received data.
71 * When closing the channel, re-initialize the channel and wait for connection request.
72 * Arguments : None.
73 * Returns : None.
74 * Note :
75 ********************************************************************************
76 */
77 void main()
78 {
79 1 SOCKET i; //Variable to handle each socket
80 1 int len; // Variable to store received data size
81 1
82 1 Init8051(); // Initialize 8051
83 1 InitLcd(); // LCD Init
84 1 printf("LoopBack Program.(TCP Server mode)\r\n");
85 1 PutStringLn("\r\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");
86 1 PutString (" LoopBack Program.(TCP Server mode) - Created Date : ");PutLTOA(0x20021028); PutStringLn("")
-;
87 1 PutStringLn(" - Created By : WIZnet, Inc.");
88 1 PutStringLn(" - W3100A Driver: V2.2");
89 1 PutStringLn(" - Flatform : 8051 EVB V3.0");
90 1 PutStringLn("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\r\n");
91 1
92 1 initW3100A(); // Initialize W3100A
93 1 InitNetConfig(); // Setup network information
94 1
95 1 for (i = 0; i < MAX_SOCK_NUM; i++) init_sock(i); // Initialize channel for Loop Back Service and wait
-in server mode
96 1
97 1 while(1) // Loop Back Service
98 1 {
99 2 for( i = 0 ; i < MAX_SOCK_NUM ; i++ ) // Do loopback service to 4 channels of W3100A in order
100 2 {
101 3 switch(select(i,SEL_CONTROL))
102 3 {
103 4 case SOCK_ESTABLISHED: // If client is connected
104 4 if ((len = select(i, SEL_RECV)) > 0) // Confirm if received the data
105 4 {
106 5 if (len > MAX_BUF_SIZE) len = MAX_BUF_SIZE; // Handle as much as buffer size first when receiving dat
-a more than system buffer
107 5 len = recv(i, data_buf, len); // Loopback received data from client
108 5 send(i, data_buf, len);
109 5 }
110 4 break;
111 4 case SOCK_CLOSE_WAIT: // If the client request to close connection and wait
- for closing successfully
112 4 PutString("CLOSE_WAIT : ");PutHTOA(i);PutStringLn("");
113 4 /* When the socket is half-close and have some data to be received, receive the data. */
C51 COMPILER V8.02 MAIN 10/17/2006 16:52:41 PAGE 3
114 4 if ((len = select(i, SEL_RECV)) > 0) // Check to receive data when SOCK_CLOSE_WAIT
115 4 {
116 5 if (len > MAX_BUF_SIZE) // When receiving larger data than system buffer,it's processed buffer sized
- data first.
117 5 len = MAX_BUF_SIZE;
118 5 len = recv(i, data_buf, len);
119 5 PutString("Size of Received data in half-close : 0x");PutITOA(len);PutStringLn("");
120 5 }
121 4 close(i); // Close the appropriate channel connected to client
122 4 break;
123 4 case SOCK_CLOSED: // If the socket connected to client al
-ready has been closed
124 4 PutString("CLOSED : ");PutHTOA(i);PutStringLn("");
125 4 init_sock(i); // To do loopback service again in closed channel, wait in initialization and serve
-r mode
126 4 break;
127 4 }
128 3 }
129 2 }
130 1 }
131
132 /*
133 ********************************************************************************
134 * 8051 Initialization Function
135 *
136 * Description:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -