Keil??????????RTX?????????????
???????????? ???????[ 2014/1/6 14:36:17 ] ?????????????? ??????
/*--------------------------- _init_box -------------------------------------*/
int _init_box (void *box_mem?? U32 box_size?? U32 blk_size)
{
/* Initialize memory block system?? returns 0 if OK?? 1 if fails. */
void *end;
void *blk;
void *next;
U32 sizeof_bm;
/* Create memory structure. */
if (blk_size & BOX_ALIGN_8) {
/* Memory blocks 8-byte aligned. */
blk_size = ((blk_size & ~BOX_ALIGN_8) + 7) & ~7;
sizeof_bm = (sizeof (struct OS_BM) + 7) & ~7;
}
else {
/* Memory blocks 4-byte aligned. */
blk_size = (blk_size + 3) & ~3;
sizeof_bm = sizeof (struct OS_BM);
}
if (blk_size == 0) {
return (1);
}
if ((blk_size + sizeof_bm) > box_size) {
return (1);
}
/* Create a Memory structure. */
blk = ((U8 *) box_mem) + sizeof_bm;
((P_BM) box_mem)->free = blk;
end = ((U8 *) box_mem) + box_size;
((P_BM) box_mem)->end = end;
((P_BM) box_mem)->blk_size = blk_size;
/* Link all free blocks using offsets. */
end = ((U8 *) end) - blk_size;
while (1) {
next = ((U8 *) blk) + blk_size;
if (next > end) break;
*((void **)blk) = next;
blk = next;
}
/* end marker */
*((void **)blk) = 0;
return (0);
}
????????????е?(blk_size + 3) & ~3;????????????????????????????????????????????????????£?
????????????????????????????????????????4????????????(blk_size + 3) & ~3;??????С???
??????4???????
????????????????
????rt_init_box (&mp_tcb?? mp_tcb_size?? sizeof(struct OS_TCB));
????U16 const mp_tcb_size = sizeof(mp_tcb);
????OS_TCB?????????????壬?????С?????????4??????????????(blk_size + 3) & ~3;???????????С????4???????
????mp_tcb_size??????4??????????sizeof(mp_tcb)????????С??????????????????
???????????????????????????????????????????????
/*--------------------------- rt_alloc_box ----------------------------------*/
void *rt_alloc_box (void *box_mem) {
/* Allocate a memory block and return start address. */
void **free;
int irq_dis;
irq_dis = __disable_irq ();
free = ((P_BM) box_mem)->free;
if (free) {
((P_BM) box_mem)->free = *free;
}
if (!irq_dis) __enable_irq ();
return (free);
}
/*--------------------------- _calloc_box -----------------------------------*/
void *_calloc_box (void *box_mem) {
/* Allocate a 0-initialized memory block and return start address. */
void *free;
U32 *p;
U32 i;
free = _alloc_box (box_mem);
if (free) {
p = free;
for (i = ((P_BM) box_mem)->blk_size; i; i -= 4) {
*p = 0;
p++;
}
}
return (free);
}
/*--------------------------- rt_free_box -----------------------------------*/
int rt_free_box (void *box_mem?? void *box) {
/* Free a memory block?? returns 0 if OK?? 1 if box does not belong to box_mem */
int irq_dis;
if (box < box_mem || box > ((P_BM) box_mem)->end) {
return (1);
}
irq_dis = __disable_irq ();
*((void **)box) = ((P_BM) box_mem)->free;
((P_BM) box_mem)->free = box;
if (!irq_dis) __enable_irq ();
return (0);
}
????Keil??RTX???????????????Щ????????????ɡ???????????????????????????????á?
????????Linux????е?????????????????????????????????????????????????????????????п??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11