📄 os_mem.ls1
字号:
150 ; return ((OS_MEM *)0);
151 ; }
152 ; plink = (void **)addr; /* Create linked list of free memor
y blocks */
153 ; pblk = (INT8U *)addr + blksize;
154 ; for (i = 0; i < (nblks - 1); i++) {
155 ; *plink = (void *)pblk;
156 ; plink = (void **)pblk;
157 ; pblk = pblk + blksize;
158 ; }
159 ; *plink = (void *)0; /* Last memory block points to NULL
*/
160 ; pmem->OSMemAddr = addr; /* Store start address of memory pa
rtition */
161 ; pmem->OSMemFreeList = addr; /* Initialize pointer to pool of fr
ee blocks */
162 ; pmem->OSMemNFree = nblks; /* Store number of free blocks in M
CB */
163 ; pmem->OSMemNBlks = nblks;
164 ; pmem->OSMemBlkSize = blksize; /* Store block size of each memory
blocks */
165 ; *err = OS_NO_ERR;
166 ; return (pmem);
167 ; }
A51 MACRO ASSEMBLER OS_MEM 08/08/2005 11:36:46 PAGE 4
168 ; /*$PAGE*/
169 ; /*
170 ; *****************************************************************************************
****************
171 ; * GET A MEMORY BLOCK
172 ; *
173 ; * Description : Get a memory block from a partition
174 ; *
175 ; * Arguments : pmem is a pointer to the memory partition control block
176 ; *
177 ; * err is a pointer to a variable containing an error message which will
be set by this
178 ; * function to either:
179 ; *
180 ; * OS_NO_ERR if the memory partition has been created corr
ectly.
181 ; * OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to al
locate to caller
182 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
183 ; *
184 ; * Returns : A pointer to a memory block if no error is detected
185 ; * A pointer to NULL if an error is detected
186 ; *****************************************************************************************
****************
187 ; */
188 ;
189 ; void *OSMemGet (OS_MEM *pmem, INT8U *err)
190 ; {
191 ;
192 ; void *pblk;
193 ;
194 ;
195 ; #if OS_ARG_CHK_EN > 0
196 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory par
tition */
197 ; *err = OS_MEM_INVALID_PMEM;
198 ; return ((OS_MEM *)0);
199 ; }
200 ; #endif
201 ; OS_ENTER_CRITICAL();
202 ; if (pmem->OSMemNFree > 0) { /* See if there are any free memory
blocks */
203 ; pblk = pmem->OSMemFreeList; /* Yes, point to next free memory b
lock */
204 ; pmem->OSMemFreeList = *(void **)pblk; /* Adjust pointer to new free
list */
205 ; pmem->OSMemNFree--; /* One less memory block in th
is partition */
206 ; OS_EXIT_CRITICAL();
207 ; *err = OS_NO_ERR; /* No error
*/
208 ; return (pblk); /* Return memory block to call
er */
209 ; }
210 ; OS_EXIT_CRITICAL();
211 ; *err = OS_MEM_NO_FREE_BLKS; /* No, Notify caller of empty memo
ry partition */
212 ; return ((void *)0); /* Return NULL pointer to call
er */
213 ; }
214 ; /*$PAGE*/
215 ; /*
216 ; *****************************************************************************************
****************
217 ; * RELEASE A MEMORY BLOCK
218 ; *
A51 MACRO ASSEMBLER OS_MEM 08/08/2005 11:36:46 PAGE 5
219 ; * Description : Returns a memory block to a partition
220 ; *
221 ; * Arguments : pmem is a pointer to the memory partition control block
222 ; *
223 ; * pblk is a pointer to the memory block being released.
224 ; *
225 ; * Returns : OS_NO_ERR if the memory block was inserted into the partition
226 ; * OS_MEM_FULL if you are returning a memory block to an already FU
LL memory
227 ; * partition (You freed more blocks than you allocated!
)
228 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
229 ; * OS_MEM_INVALID_PBLK if you passed a NULL pointer for the block to releas
e.
230 ; *****************************************************************************************
****************
231 ; */
232 ;
233 ; INT8U OSMemPut (OS_MEM *pmem, void *pblk)
234 ; {
235 ;
236 ;
237 ;
238 ; #if OS_ARG_CHK_EN > 0
239 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partitio
n */
240 ; return (OS_MEM_INVALID_PMEM);
241 ; }
242 ; if (pblk == (void *)0) { /* Must release a valid block
*/
243 ; return (OS_MEM_INVALID_PBLK);
244 ; }
245 ; #endif
246 ; OS_ENTER_CRITICAL();
247 ; if (pmem->OSMemNFree >= pmem->OSMemNBlks) { /* Make sure all blocks not already retu
rned */
248 ; OS_EXIT_CRITICAL();
249 ; return (OS_MEM_FULL);
250 ; }
251 ; *(void **)pblk = pmem->OSMemFreeList; /* Insert released block into free block
list */
252 ; pmem->OSMemFreeList = pblk;
253 ; pmem->OSMemNFree++; /* One more memory block in this partiti
on */
254 ; OS_EXIT_CRITICAL();
255 ; return (OS_NO_ERR); /* Notify caller that memory block was r
eleased */
256 ; }
257 ; /*$PAGE*/
258 ; /*
259 ; *****************************************************************************************
****************
260 ; * QUERY MEMORY PARTITION
261 ; *
262 ; * Description : This function is used to determine the number of free memory blocks and t
he number of
263 ; * used memory blocks from a memory partition.
264 ; *
265 ; * Arguments : pmem is a pointer to the memory partition control block
266 ; *
267 ; * pdata is a pointer to a structure that will contain information about t
he memory
268 ; * partition.
269 ; *
270 ; * Returns : OS_NO_ERR If no errors were found.
271 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
A51 MACRO ASSEMBLER OS_MEM 08/08/2005 11:36:46 PAGE 6
272 ; * OS_MEM_INVALID_PDATA if you passed a NULL pointer for the block to releas
e.
273 ; *****************************************************************************************
****************
274 ; */
275 ;
276 ; #if OS_MEM_QUERY_EN > 0
277 ; INT8U OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *ppdata)
278 ; {
279 ;
280 ;
281 ;
282 ; #if OS_ARG_CHK_EN > 0
283 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partitio
n */
284 ; return (OS_MEM_INVALID_PMEM);
285 ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -