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

📄 mbuf.c

📁 用于以太网开发
💻 C
字号:
/******************************************************************************
 *
 *                      (c) Freescale  Inc. 2004 All rights reserved
 *
 * File Name     : mBuf.c
 * Description   : Implementation of a buffering scheme based on mBUFs
 *
 * Version : 1.0
 * Date    : Jun/22/2004
 *
 ******************************************************************************/
#include "mBuf.h"

#define	MBUFS_NUM	2

MBUF mBufs  [MBUFS_NUM];	/* The static array of MBufs buffers! */
MBUF mBufTx;                /* MBUF buffer for transmissions */


/*****************************************************************************
* mBufInit ()
* 
*****************************************************************************/
void mBufInit (void) 
{
	mBufs[0].status      = 0x00;
    mBufs[0].len         = 0x0000;
	mBufs[0].data        = (void *)0x0000;
	mBufs[0].working_ptr = (void *)0x0000;
	
	mBufs[1].status      = 0x00;
    mBufs[1].len         = 0x0000;
	mBufs[1].data        = (void *)0x0000;
	mBufs[1].working_ptr = (void *)0x0000;

	mBufTx.status        = 0x00;
	mBufTx.len           = 0x00;
	mBufTx.data          = (void *)0x0000;
	mBufTx.working_ptr   = (void *)0x0000;
}


/******************************************************************************
*
* 
******************************************************************************/
INT16 mENQUEUE (MBUF *m) 
{
    /*	OS_ENTER_CRITICAL();   */

    if (!(mBufs[0].status & MBUF_NOTEMPTY)) 
	{
		mBufs[0].data        = m->data;
		mBufs[0].working_ptr = m->working_ptr;
		mBufs[0].len         = m->len;
		mBufs[0].status      = m->status;
		return 0;
	}
	
	if (!(mBufs[1].status & MBUF_NOTEMPTY)) 
	{
		mBufs[1].data        = m->data;
		mBufs[1].working_ptr = m->working_ptr;
		mBufs[1].len         = m->len;
		mBufs[1].status      = m->status;
		return 0;
	}
    
/*	OS_EXIT_CRITICAL();    */
    return (~0);
}

/******************************************************************************
*
* 
******************************************************************************/
MBUF* mDEQUEUE (void)
{ 
/*	OS_ENTER_CRITICAL();   */

	if (mBufs[0].status & MBUF_NOTEMPTY)
	{
		return (MBUF *)&mBufs[0];
	}
	
	if (mBufs[1].status & MBUF_NOTEMPTY)
	{
		return (MBUF *)&mBufs[1];
	}
	return (MBUF *)0;
    
/*	OS_EXIT_CRITICAL();    */
}

⌨️ 快捷键说明

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