⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init_mem.c

📁 可自行修改移植的CAN应用层协议栈
💻 C
字号:
/*--------------------------------------------------------------------------
MALLOC.C is part of the CARM Compiler package from Keil Software.
Copyright (c) 1995 - 2005 Keil Software.  All rights reserved.
--------------------------------------------------------------------------*/

#include "ican_STDLIB.H"


struct __mp__  {                   /* memory pool */
  struct __mp__   *next;           /* single-linked list */
  unsigned int      len;           /* length of following block */
};

struct __mp__ *__mp__;      /* Memory Pool Header */
#define	HLEN	(sizeof(struct __mp__))

/*  Memory pool header:  __mp__ points to the first available.
 *
 *  Note that the list is maintained in address order.  __mp__ points to the
 *  block with the lowest address.  That block points to the block with the
 *  next higher address and so on.                                          */


/* Initialize Block oriented memory pool */
void ican_init_mempool (
  void *pool,                      /* address of the memory pool  */
  unsigned int size)  {            /* size of the pool in bytes   */

/*  Set the __mp__ to point to the beginning of the pool and set
 *  the pool size.                                                     */

  pool = (void *) (((unsigned int)pool+3)&~3);  // 25.7.2005
  __mp__ = (struct __mp__ *) pool;              // =========

/*  Set the link of the block in the pool to NULL (since it's the only
 *  block) and initialize the size of its data area.                   */

  ((struct __mp__ *) pool)->next       = NULL;
  ((struct __mp__ *) pool)->len        = size - HLEN;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -