📄 tcpipmem.lst
字号:
C51 COMPILER V7.06 TCPIPMEM 11/26/2007 20:40:52 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TCPIPMEM
OBJECT MODULE PLACED IN .\TCPIPmem.obj
COMPILER INVOKED BY: D:\Program File\keil\C51\BIN\C51.EXE ..\TCPIP\TCPIPmem.c BROWSE DEBUG OBJECTEXTEND PRINT(.\TCPIPmem
-.lst) OBJECT(.\TCPIPmem.obj)
stmt level source
1 /*
2 * Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * Author: Li Zhanglin <http://www.zlmcu.com>
28 *
29 */
30
31 #include "..\GloblDef\GloblDef.h"
32 #include "..\TCPIP\TCPIPmem.h"
33
34 /* buf for all tcpip packet */
35 static BYTE DT_XDATA TCPIPBuf[TCPIP_BUF_SIZE];
36 static struct SMemHead DT_XDATA * DT_XDATA MemHeadEnd; /* end of the chain */
37 static struct SMemHead DT_XDATA * DT_XDATA MemHeadStart;
38
39 static WORD DT_XDATA FreeSize; /* free memsize can use */
40
41 void MemInit() REENTRANT_MUL
42 {
43 1 MemHeadEnd = (struct SMemHead DT_XDATA *)(TCPIPBuf + TCPIP_BUF_SIZE);
44 1 MemHeadStart = (struct SMemHead DT_XDATA *)TCPIPBuf;
45 1
46 1 /* at inital there is only a buf block. value in
47 1 mem head is as following */
48 1 MemHeadStart->pNext = MemHeadEnd;
49 1 MemHeadStart->pPre = MemHeadStart;
50 1 MemHeadStart->used = FALSE;
51 1
52 1 FreeSize = TCPIP_BUF_SIZE - sizeof(struct SMemHead);
53 1 }
54
C51 COMPILER V7.06 TCPIPMEM 11/26/2007 20:40:52 PAGE 2
55 /* allocate a buffer size of size, and set pStart to the start of buffer,pEnd
56 to end of buffer.Also decrease FreeSize. */
57 struct SMemHead DT_XDATA *MemAllocate(WORD size) REENTRANT_SIG
58 {
59 1 struct SMemHead DT_XDATA *MemHead;
60 1 struct SMemHead DT_XDATA *NewMemHead;
61 1 WORD MemPlayloadSize;
62 1
63 1 /* search though the mem blocks */
64 1 for(MemHead = MemHeadStart; MemHead != MemHeadEnd; MemHead = MemHead->pNext)
65 1 {
66 2 /* if unused and mem playload size > size, select it. */
67 2 if(MemHead->used == FALSE &&
68 2 (MemPlayloadSize = (BYTE DT_XDATA *)(MemHead->pNext) - (BYTE DT_XDATA *)MemHead - sizeof(struct SMemHea
-d)) >= size)
69 2 {
70 3 /* if MemPalyloadSize - size > sizeof(struct SMemHead) create
71 3 a new SMemHead at the excess memory leaving for later usage */
72 3 if(MemPlayloadSize - size > sizeof(struct SMemHead))
73 3 {
74 4 NewMemHead = (struct SMemHead DT_XDATA *)((BYTE DT_XDATA *)MemHead + sizeof(struct SMemHead)+ size );
75 4
76 4 /* link into link chain */
77 4 NewMemHead->pNext = MemHead->pNext;
78 4 MemHead->pNext = NewMemHead;
79 4 NewMemHead->pPre = MemHead;
80 4 if(NewMemHead->pNext != MemHeadEnd)
81 4 {
82 5 NewMemHead->pNext->pPre = NewMemHead;
83 5 }
84 4
85 4 /* set new mem as unused */
86 4 NewMemHead->used = FALSE;
87 4
88 4 /* decrease FreeSize: playload of MemHead and the head of NewMemHead */
89 4 FreeSize -= (BYTE DT_XDATA *)(MemHead->pNext) - (BYTE DT_XDATA *)MemHead;
90 4 }
91 3 else
92 3 {
93 4 /* decrease: playload of MemHead */
94 4 FreeSize -= (BYTE DT_XDATA *)(MemHead->pNext) - (BYTE DT_XDATA *)MemHead - sizeof(struct SMemHead);
95 4 }
96 3
97 3
98 3 /* set pStart */
99 3 MemHead->pStart = (BYTE DT_XDATA *)MemHead + sizeof(struct SMemHead);
100 3
101 3 MemHead->pEnd = MemHead->pStart + size;
102 3
103 3 /* set as used */
104 3 MemHead->used = TRUE;
105 3
106 3 return MemHead;
107 3 }
108 2 }
109 1 return NULL;
110 1 }
111
112 void MemFree(struct SMemHead DT_XDATA * MemHead) REENTRANT_SIG
113 {
114 1 struct SMemHead DT_XDATA * MemHeadMergePre;
115 1 struct SMemHead DT_XDATA * MemHeadMergeNext;
C51 COMPILER V7.06 TCPIPMEM 11/26/2007 20:40:52 PAGE 3
116 1
117 1 /* set used flag to false */
118 1 MemHead->used = FALSE;
119 1
120 1 /* inc FreeSize the size of playload of 'MemHead'*/
121 1 FreeSize += (BYTE DT_XDATA *)(MemHead->pNext) - (BYTE DT_XDATA *)MemHead - sizeof(struct SMemHead);
122 1
123 1 /*
124 1 * if pNext or pPre is a unused memblock, merge with it
125 1 */
126 1
127 1 /* find the two MemHead going to merge */
128 1 if(MemHead->pPre->used == FALSE)
129 1 {
130 2 MemHeadMergePre = MemHead->pPre; /* note: if MemHead == TCPBuf, MemHead->pPre == MemHead, but it is not
-a problom */
131 2 }
132 1 else
133 1 {
134 2 MemHeadMergePre = MemHead;
135 2 }
136 1 if(MemHead->pNext != MemHeadEnd && MemHead->pNext->used == FALSE)
137 1 {
138 2 MemHeadMergeNext = MemHead->pNext;
139 2
140 2 /* MemHead of 'MemHead->pNext' will be free. Free size inc*/
141 2 FreeSize += sizeof(struct SMemHead);
142 2 }
143 1 else
144 1 {
145 2 MemHeadMergeNext = MemHead;
146 2 }
147 1
148 1 /* merge is necessary? */
149 1 if(MemHeadMergePre != MemHeadMergeNext)
150 1 {
151 2 /* merge. that is del MemHeadMergeNext from the chain */
152 2 MemHeadMergePre->pNext = MemHeadMergeNext->pNext;
153 2 if(MemHeadMergeNext->pNext != MemHeadEnd)
154 2 MemHeadMergeNext->pNext->pPre = MemHeadMergePre;
155 2
156 2 /* will MemHead of 'MemHead' will be free? */
157 2 if(MemHead != MemHeadMergePre)
158 2 FreeSize += sizeof(struct SMemHead);
159 2
160 2 }
161 1 }
162
163 WORD MemFreeSize() REENTRANT_SIG
164 {
165 1 return FreeSize;
166 1 }
167
168
169
170
171
172
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 948 ----
C51 COMPILER V7.06 TCPIPMEM 11/26/2007 20:40:52 PAGE 4
CONSTANT SIZE = ---- ----
XDATA SIZE = 8198 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -