pbuf.h
来自「AMLOGIC DPF source code」· C头文件 代码 · 共 180 行
H
180 行
/*******************************************************************
*
* Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
*
* Description:
*
* Author: Amlogic Software
* Created: Fri Nov 11 00:41:38 2005
*
*******************************************************************/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __LWIP_PBUF_H__
#define __LWIP_PBUF_H__
#include "arch/cc.h"
#ifdef HAS_USB_NET
#include "listop.h"
#endif // HAS_USB_NET
#define PBUF_TRANSPORT_HLEN 20
#define PBUF_IP_HLEN 20
/* pbuf_layer_offsets[] in pbuf.c must also be updated
* if you change this */
typedef enum {
PBUF_TRANSPORT,
PBUF_IP,
PBUF_LINK,
PBUF_RAW,
PBUF_MAX_LAYER
} pbuf_layer;
/* The pbuf_alloc_handlers[] table in pbuf.c must
* be updated if you change this */
typedef enum {
PBUF_RAM,
PBUF_ROM,
PBUF_REF,
PBUF_PACKET,
PBUF_POOL,
PBUF_MAX_FLAG
} pbuf_flag;
/* Definitions for the pbuf flag field. These are NOT the flags that
* are passed to pbuf_alloc(). */
#define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */
#define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */
#define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */
#define PBUF_FLAG_REF 0x04U /* Flags thet the pbuf payload refers to RAM */
#define PBUF_FLAG_PACK 0x08U /* Flag that the pbuf is a raw packet off of the net */
/** indicates this packet was broadcast on the link */
#define PBUF_FLAG_LINK_BROADCAST 0x80U
#if BYTE_ORDER == BIG_ENDIAN
#define PBUF_MAGIC 0x50425546 /* "PBUF" */
#else
#define PBUF_MAGIC 0x46554250 /* "PBUF" */
#endif
struct pbuf {
#ifdef HAS_USB_NET
struct list_head head;
#endif // HAS_USB_NET
u32_t magic;
/** next pbuf in singly linked pbuf chain */
struct pbuf *next;
/** pointer to the actual data in the buffer */
void *payload;
/** used for debuging */
void *raw_payload;
/* Interface pbuf was received on */
struct netif *netif;
/**
* total length of this buffer and all next buffers in chain
* belonging to the same packet.
*
* For non-queue packet chains this is the invariant:
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
*/
u32_t tot_len;
/** length of this buffer */
u16_t len;
/** flags telling the type of pbuf, see PBUF_FLAG_ */
u16_t flags;
/**
* the reference count always equals the number of pointers
* that refer to this pbuf. This can be pointers from an application,
* the stack itself, or pbuf->next pointers from a chain.
*/
u16_t ref;
#ifdef HAS_USB_NET
u16_t padding; // Make cb[] 32-bit word aligned.
char cb[16];
#endif // HAS_USB_NET
};
#ifdef HAS_USB_NET
struct pbuf_head {
struct list_head head;
u32_t qlen;
};
#endif // HAS_USB_NET
#define PBUF_PAYLOAD_CHAR(p) ((u8_t *)((p)->payload))
/* Increment the payload in pbuf p by n bytes */
#define PBUF_PAYLOAD_INC(p, n) (((u8_t *)((p)->payload)) += n)
void pbuf_init(void);
#if (OS_TASK_DEBUGHELPER_EN>0)
#define pbuf_alloc(l,size,flag) pbuf_alloc_trace( __LINE__, __FILE__ ,l ,size ,flag)
struct pbuf *pbuf_alloc_trace(int line, char *file, pbuf_layer l, u16_t size, pbuf_flag flag);
#else
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
#endif
void pbuf_realloc(struct pbuf *p, u16_t size);
u8_t pbuf_header(struct pbuf *p, s16_t header_size);
void pbuf_ref(struct pbuf *p);
void pbuf_ref_chain(struct pbuf *p);
u8_t pbuf_free(struct pbuf *p);
u8_t pbuf_clen(struct pbuf *p);
void pbuf_cat(struct pbuf *h, struct pbuf *t);
void pbuf_chain(struct pbuf *h, struct pbuf *t);
#if (OS_TASK_DEBUGHELPER_EN>0)
#define pbuf_take(f) pbuf_take_trace( __LINE__, __FILE__ ,f)
struct pbuf *pbuf_take_trace(int line, char *file,struct pbuf *f);
#else
struct pbuf *pbuf_take(struct pbuf *f);
#endif
struct pbuf *pbuf_dechain(struct pbuf *p);
void pbuf_queue(struct pbuf *p, struct pbuf *n);
struct pbuf * pbuf_dequeue(struct pbuf *p);
int pbuf_set_pack_pbufs_config ( uint32_t total, uint32_t size );
void pbuf_get_pack_pbufs_config ( uint32_t * total, uint32_t * size );
#endif /* __LWIP_PBUF_H__ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?