📄 os_mem.ls1
字号:
184 ; *err = OS_MEM_INVALID_SIZE;
185 ; return ((OS_MEM *)0);
186 ; }
187 ; #endif
188 ; OS_ENTER_CRITICAL();
189 ; pmem = OSMemFreeList; /* Get next free memory partition
*/
190 ; if (OSMemFreeList != (OS_MEM *)0) { /* See if pool of free partitions w
as empty */
191 ; OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
192 ; }
193 ; OS_EXIT_CRITICAL();
194 ; if (pmem == (OS_MEM *)0) { /* See if we have a memory partitio
n */
195 ; *err = OS_MEM_INVALID_PART;
196 ; return ((OS_MEM *)0);
197 ; }
198 ; plink = (void **)addr; /* Create linked list of free memor
y blocks */
199 ; pblk = (INT8U *)addr + blksize;
200 ; for (i = 0; i < (nblks - 1); i++) {
201 ; *plink = (void *)pblk;
202 ; plink = (void **)pblk;
203 ; pblk = pblk + blksize;
204 ; }
205 ; *plink = (void *)0; /* Last memory block points to NULL
*/
206 ; pmem->OSMemAddr = addr; /* Store start address of memory pa
rtition */
207 ; pmem->OSMemFreeList = addr; /* Initialize pointer to pool of fr
ee blocks */
208 ; pmem->OSMemNFree = nblks; /* Store number of free blocks in M
CB */
209 ; pmem->OSMemNBlks = nblks;
210 ; pmem->OSMemBlkSize = blksize; /* Store block size of each memory
blocks */
211 ; *err = OS_NO_ERR;
212 ; return (pmem);
213 ; }
214 ; /*$PAGE*/
215 ; /*
216 ; *****************************************************************************************
****************
217 ; * GET A MEMORY BLOCK
218 ; *
219 ; * Description : Get a memory block from a partition
220 ; *
221 ; * Arguments : pmem is a pointer to the memory partition control block
222 ; *
223 ; * err is a pointer to a variable containing an error message which will
be set by this
224 ; * function to either:
225 ; *
226 ; * OS_NO_ERR if the memory partition has been created corr
ectly.
227 ; * OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to al
locate to caller
A51 MACRO ASSEMBLER OS_MEM 05/17/2005 11:19:55 PAGE 5
228 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
229 ; *
230 ; * Returns : A pointer to a memory block if no error is detected
231 ; * A pointer to NULL if an error is detected
232 ; *****************************************************************************************
****************
233 ; */
234 ;
235 ; void *OSMemGet (OS_MEM *pmem, INT8U *err)LG_REENTRANT
236 ; {
237 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status
register */
238 ; OS_CPU_SR cpu_sr;
239 ; #endif
240 ; void *pblk;
241 ;
242 ;
243 ; #if OS_ARG_CHK_EN > 0
244 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory par
tition */
245 ; *err = OS_MEM_INVALID_PMEM;
246 ; return ((OS_MEM *)0);
247 ; }
248 ; #endif
249 ; OS_ENTER_CRITICAL();
250 ; if (pmem->OSMemNFree > 0) { /* See if there are any free memory
blocks */
251 ; pblk = pmem->OSMemFreeList; /* Yes, point to next free memory b
lock */
252 ; pmem->OSMemFreeList = *(void **)pblk; /* Adjust pointer to new free
list */
253 ; pmem->OSMemNFree--; /* One less memory block in th
is partition */
254 ; OS_EXIT_CRITICAL();
255 ; *err = OS_NO_ERR; /* No error
*/
256 ; return (pblk); /* Return memory block to call
er */
257 ; }
258 ; OS_EXIT_CRITICAL();
259 ; *err = OS_MEM_NO_FREE_BLKS; /* No, Notify caller of empty memo
ry partition */
260 ; return ((void *)0); /* Return NULL pointer to call
er */
261 ; }
262 ; /*$PAGE*/
263 ; /*
264 ; *****************************************************************************************
****************
265 ; * RELEASE A MEMORY BLOCK
266 ; *
267 ; * Description : Returns a memory block to a partition
268 ; *
269 ; * Arguments : pmem is a pointer to the memory partition control block
270 ; *
271 ; * pblk is a pointer to the memory block being released.
272 ; *
273 ; * Returns : OS_NO_ERR if the memory block was inserted into the partition
274 ; * OS_MEM_FULL if you are returning a memory block to an already FU
LL memory
275 ; * partition (You freed more blocks than you allocated!
)
276 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
277 ; * OS_MEM_INVALID_PBLK if you passed a NULL pointer for the block to releas
e.
278 ; *****************************************************************************************
A51 MACRO ASSEMBLER OS_MEM 05/17/2005 11:19:55 PAGE 6
****************
279 ; */
280 ;
281 ; INT8U OSMemPut (OS_MEM *pmem, void *pblk)LG_REENTRANT
282 ; {
283 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
284 ; OS_CPU_SR cpu_sr;
285 ; #endif
286 ;
287 ;
288 ; #if OS_ARG_CHK_EN > 0
289 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partitio
n */
290 ; return (OS_MEM_INVALID_PMEM);
291 ; }
292 ; if (pblk == (void *)0) { /* Must release a valid block
*/
293 ; return (OS_MEM_INVALID_PBLK);
294 ; }
295 ; #endif
296 ; OS_ENTER_CRITICAL();
297 ; if (pmem->OSMemNFree >= pmem->OSMemNBlks) { /* Make sure all blocks not already retu
rned */
298 ; OS_EXIT_CRITICAL();
299 ; return (OS_MEM_FULL);
300 ; }
301 ; *(void **)pblk = pmem->OSMemFreeList; /* Insert released block into free block
list */
302 ; pmem->OSMemFreeList = pblk;
303 ; pmem->OSMemNFree++; /* One more memory block in this partiti
on */
304 ; OS_EXIT_CRITICAL();
305 ; return (OS_NO_ERR); /* Notify caller that memory block was r
eleased */
306 ; }
307 ; /*$PAGE*/
308 ; /*
309 ; *****************************************************************************************
****************
310 ; * QUERY MEMORY PARTITION
311 ; *
312 ; * Description : This function is used to determine the number of free memory blocks and t
he number of
313 ; * used memory blocks from a memory partition.
314 ; *
315 ; * Arguments : pmem is a pointer to the memory partition control block
316 ; *
317 ; * pdata is a pointer to a structure that will contain information about t
he memory
318 ; * partition.
319 ; *
320 ; * Returns : OS_NO_ERR If no errors were found.
321 ; * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
322 ; * OS_MEM_INVALID_PDATA if you passed a NULL pointer for the block to releas
e.
323 ; *****************************************************************************************
****************
324 ; */
325 ;
326 ; #if OS_MEM_QUERY_EN > 0
327 ; INT8U OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *os_pdata)LG_REENTRANT
328 ; {
329 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
330 ; OS_CPU_SR cpu_sr;
A51 MACRO ASSEMBLER OS_MEM 05/17/2005 11:19:55 PAGE 7
331 ; #endif
332 ;
333 ;
334 ; #if OS_ARG_CHK_EN > 0
335 ; if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partitio
n */
336 ; return (OS_MEM_INVALID_PMEM);
337 ; }
338 ; if (os_pdata == (OS_MEM_DATA *)0) { /* Must release a valid storage area
for the data */
339 ; return (OS_MEM_INVALID_PDATA);
340 ; }
341 ; #endif
342 ; OS_ENTER_CRITICAL();
343 ; os_pdata->OSAddr = pmem->OSMemAddr;
344 ; os_pdata->OSFreeList = pmem->OSMemFreeList;
345 ; os_pdata->OSBlkSize = pmem->OSMemBlkSize;
346 ; os_pdata->OSNBlks = pmem->OSMemNBlks;
347 ; os_pdata->OSNFree = pmem->OSMemNFree;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -