📄 ioman.lst
字号:
ARM COMPILER V2.42, ioman 27/03/06 10:45:50 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE ioman
OBJECT MODULE PLACED IN .\obj\ioman.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe src\ioman.c THUMB DEBUG PRINT(.\LST\IOMAN.LST) TABS(4) OBJECT(.\obj\ioman.ob
-j)
stmt level source
1 /*****************************************************************************\
2 * libfat - General purpose FAT library *
3 * ---------------------------------- *
4 * *
5 * Filename : ioman.c *
6 * Description : The IO Manager receives all requests for sectors in a central *
7 * allowing it to make smart decision regarding caching. *
8 * The IOMAN_NUMBUFFER parameter determines how many sectors *
9 * ioman can cache. ioman also supports overallocating and *
10 * backtracking sectors. *
11 * *
12 * This library is free software; you can redistribute it and/or *
13 * modify it under the terms of the GNU Lesser General Public *
14 * License as published by the Free Software Foundation; either *
15 * version 2.1 of the License, or (at your option) any later version. *
16 * *
17 * This library is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
20 * Lesser General Public License for more details. *
21 * *
22 * (c)2004 Lennart Yseboodt *
23 * (c)2004 Michael De Nil *
24 \*****************************************************************************/
25
26 /*****************************************************************************/
27 #include "ioman.h"
28 /*****************************************************************************/
29
30 esint8 ioman_init(IOManager *ioman, hwInterface *iface, euint8* bufferarea)
31 {
32 1 ioman->iface=iface;
33 1
34 1 ioman->bufptr = ioman_getBuffer(ioman,bufferarea);
35 1 ioman->numbuf = IOMAN_NUMBUFFER;
36 1 ioman->numit = IOMAN_NUMITERATIONS;
37 1
38 1 ioman_reset(ioman);
39 1 return(0);
40 1 }
41 /*****************************************************************************/
42
43 void ioman_reset(IOManager *ioman)
44 {
45 1 euint16 nb,ni;
46 1
47 1 memClr(ioman->sector,sizeof(euint32)*ioman->numbuf);
48 1 memClr(ioman->status,sizeof(euint8) *ioman->numbuf);
49 1 memClr(ioman->usage ,sizeof(euint8) *ioman->numbuf);
50 1 memClr(ioman->itptr ,sizeof(euint8) *ioman->numbuf);
51 1 ioman_setError(ioman,IOMAN_NOERROR);
52 1
53 1 for(nb=0;nb<ioman->numbuf;nb++){
54 2 for(ni=0;ni<ioman->numit;ni++){
55 3 ioman->stack[nb][ni].sector=0;
56 3 ioman->stack[nb][ni].status=0;
57 3 ioman->stack[nb][ni].usage =0;
58 3 }
ARM COMPILER V2.42, ioman 27/03/06 10:45:50 PAGE 2
59 2 }
60 1 }
61 /*****************************************************************************/
62
63 euint8* ioman_getBuffer(IOManager *ioman,euint8* bufferarea)
64 {
65 1 #ifdef IOMAN_DO_MEMALLOC
66 1 return(ioman->cache_mem);
67 1 #else
return(bufferarea);
#endif
70 1 }
*** WARNING C47 IN LINE 63 OF SRC\IOMAN.C: 'bufferarea': unreferenced parameter
71 /*****************************************************************************/
72
73 void ioman_setAttr(IOManager *ioman,euint16 bufplace,euint8 attribute,euint8 val)
74 {
75 1 if(bufplace>=ioman->numbuf){
76 2 ioman_setError(ioman,IOMAN_ERR_SETATTROUTOFBOUNDS);
77 2 return; /* Out of bounds */
78 2 }
79 1
80 1 if(val){
81 2 ioman->status[bufplace]|=1<<attribute;
82 2 }else{
83 2 ioman->status[bufplace]&=~(1<<attribute);
84 2 }
85 1 }
86 /*****************************************************************************/
87
88 euint8 ioman_getAttr(IOManager *ioman,euint16 bufplace,euint8 attribute)
89 {
90 1 if(bufplace>=ioman->numbuf){
91 2 ioman_setError(ioman,IOMAN_ERR_GETATTROUTOFBOUNDS);
92 2 return(0xFF); /* Out of bounds */
93 2 }
94 1
95 1 return(ioman->status[bufplace]&(1<<attribute));
96 1 }
97 /*****************************************************************************/
98
99 euint8 ioman_getUseCnt(IOManager *ioman,euint16 bufplace)
100 {
101 1 if(bufplace>=ioman->numbuf){
102 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
103 2 return(0x00);
104 2 }
105 1 return(ioman->usage[bufplace]);
106 1 }
107 /*****************************************************************************/
108
109
110 void ioman_incUseCnt(IOManager *ioman,euint16 bufplace)
111 {
112 1 if(bufplace>=ioman->numbuf){
113 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
114 2 return;
115 2 }
116 1 if(ioman->usage[bufplace]==0xFF)return;
117 1 else ioman->usage[bufplace]++;
118 1 }
119 /*****************************************************************************/
120
121 void ioman_decUseCnt(IOManager *ioman,euint16 bufplace)
122 {
123 1 if(bufplace>=ioman->numbuf){
ARM COMPILER V2.42, ioman 27/03/06 10:45:50 PAGE 3
124 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
125 2 return;
126 2 }
127 1 if(ioman->usage[bufplace]==0x0)return;
128 1 else ioman->usage[bufplace]--;
129 1 }
130 /*****************************************************************************/
131
132 void ioman_resetUseCnt(IOManager *ioman,euint16 bufplace)
133 {
134 1 if(bufplace>=ioman->numbuf){
135 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
136 2 return;
137 2 }
138 1 ioman->usage[bufplace]=0x00;
139 1 }
140 /*****************************************************************************/
141
142 euint8 ioman_getRefCnt(IOManager *ioman,euint16 bufplace)
143 {
144 1 if(bufplace>=ioman->numbuf){
145 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
146 2 return(0x00);
147 2 }
148 1 return(ioman->reference[bufplace]);
149 1 }
150 /*****************************************************************************/
151
152 void ioman_incRefCnt(IOManager *ioman,euint16 bufplace)
153 {
154 1 if(bufplace>=ioman->numbuf){
155 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
156 2 return;
157 2 }
158 1 if(ioman->reference[bufplace]==0xFF)return;
159 1 else ioman->reference[bufplace]++;
160 1 }
161 /*****************************************************************************/
162
163 void ioman_decRefCnt(IOManager *ioman,euint16 bufplace)
164 {
165 1 if(bufplace>=ioman->numbuf){
166 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
167 2 return;
168 2 }
169 1 if(ioman->reference[bufplace]==0x00)return;
170 1 else ioman->reference[bufplace]--;
171 1 }
172 /*****************************************************************************/
173
174 void ioman_resetRefCnt(IOManager *ioman,euint16 bufplace)
175 {
176 1 if(bufplace>=ioman->numbuf){
177 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
178 2 return;
179 2 }
180 1 ioman->reference[bufplace]=0x00;
181 1 }
182 /*****************************************************************************/
183
184 esint8 ioman_pop(IOManager *ioman,euint16 bufplace)
185 {
186 1 if(bufplace>=ioman->numbuf){
187 2 ioman_setError(ioman,IOMAN_ERR_POPEMPTYSTACK);
188 2 return(-1);
189 2 }
ARM COMPILER V2.42, ioman 27/03/06 10:45:50 PAGE 4
190 1 if(ioman->itptr[bufplace]==0 || ioman->itptr[bufplace]>IOMAN_NUMITERATIONS)return(-1);
191 1 ioman->sector[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].sector;
192 1 ioman->status[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].status;
193 1 ioman->usage[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].usage;
194 1 ioman->itptr[bufplace]--;
195 1 return(0);
196 1 }
197 /*****************************************************************************/
198
199 esint8 ioman_push(IOManager *ioman,euint16 bufplace)
200 {
201 1 if(bufplace>=ioman->numbuf){
202 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
203 2 return(-1);
204 2 }
205 1 if(ioman->itptr[bufplace]>=IOMAN_NUMITERATIONS){
206 2 ioman_setError(ioman,IOMAN_ERR_PUSHBEYONDSTACK);
207 2 return(-1);
208 2 }
209 1 ioman->itptr[bufplace]++;
210 1 ioman->stack[bufplace][ioman->itptr[bufplace]].sector = ioman->sector[bufplace];
211 1 ioman->stack[bufplace][ioman->itptr[bufplace]].status = ioman->status[bufplace];
212 1 ioman->stack[bufplace][ioman->itptr[bufplace]].usage = ioman->usage[bufplace];
213 1 return(0);
214 1 }
215 /*****************************************************************************/
216
217 euint8* ioman_getPtr(IOManager *ioman,euint16 bufplace)
218 {
219 1 if(bufplace>=ioman->numbuf){
220 2 ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS);
221 2 return(0);
222 2 }
223 1 return(ioman->bufptr+bufplace*512);
224 1 }
225 /*****************************************************************************/
226
227 esint16 ioman_getBp(IOManager *ioman,euint8* buf)
228 {
229 1 if(buf<(ioman->bufptr) || buf>=( ioman->bufptr+(ioman->numbuf*512) )){
230 2 ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
231 2 return(-1);
232 2 }
233 1 return((buf-(ioman->bufptr))/512);
234 1 }
235 /*****************************************************************************/
236
237 esint8 ioman_readSector(IOManager *ioman,euint32 address,euint8* buf)
238 {
239 1 esint8 r;
240 1
241 1 if(buf==0){
242 2 return(-1);
243 2 }
244 1
245 1 r=if_readBuf(ioman->iface,address,buf);
246 1
247 1 if(r!=0){
248 2 ioman_setError(ioman,IOMAN_ERR_READFAIL);
249 2 return(-1);
250 2 }
251 1 return(0);
252 1 }
253 /*****************************************************************************/
254
255 esint8 ioman_writeSector(IOManager *ioman, euint32 address, euint8* buf)
ARM COMPILER V2.42, ioman 27/03/06 10:45:50 PAGE 5
256 {
257 1 esint8 r;
258 1
259 1 if(buf==0)return(-1);
260 1
261 1 r=if_writeBuf(ioman->iface,address,buf);
262 1
263 1 if(r<=0){
264 2 ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);
265 2 return(-1);
266 2 }
267 1 return(0);
268 1 }
269 /*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -