📄 net_buf.h
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK BUFFER MANAGEMENT
*
* Filename : net_buf.h
* Version : V1.89
* Programmer(s) : ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef NET_BUF_MODULE
#define NET_BUF_EXT
#else
#define NET_BUF_EXT extern
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK BUFFER FLAG DEFINES
*********************************************************************************************************
*/
/* ------------------- NET BUF FLAGS ------------------ */
#define NET_BUF_FLAG_NONE DEF_BIT_NONE
#define NET_BUF_FLAG_USED DEF_BIT_00 /* Buf cur used; i.e. NOT in free buf pool. */
#define NET_BUF_FLAG_CLR_MEM DEF_BIT_01
#define NET_BUF_FLAG_BROADCAST_RX DEF_BIT_04 /* Set by Net IF, chk'd by IP. */
#define NET_BUF_FLAG_BROADCAST_TX DEF_BIT_05 /* Set by IP, chk'd by Net IF. */
#define NET_BUF_FLAG_UDP_RX_CHK_SUM_VALID DEF_BIT_08 /* Indicates UDP rx chk sum valid. */
/*
*********************************************************************************************************
* NETWORK BUFFER TYPE DEFINES
*
* Note(s) : (1) NET_BUF_TYPE_??? #define values specifically chosen as ASCII representations of the network
* buffer types. Memory displays of network buffers will display the buffer TYPEs with their
* chosen ASCII names.
**********************************************************************************************************/
/* ------------------ NET BUF TYPES ------------------- */
#if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
#define NET_BUF_TYPE_NONE 0x4E4F4E45 /* "NONE" in ASCII. */
#define NET_BUF_TYPE_SMALL 0x534D414C /* "SMAL" in ASCII. */
#define NET_BUF_TYPE_LARGE 0x4C415247 /* "LARG" in ASCII. */
#else
#if (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32)
#define NET_BUF_TYPE_NONE 0x454E4F4E /* "NONE" in ASCII. */
#define NET_BUF_TYPE_SMALL 0x4C414D53 /* "SMAL" in ASCII. */
#define NET_BUF_TYPE_LARGE 0x4752414C /* "LARG" in ASCII. */
#elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
#define NET_BUF_TYPE_NONE 0x4F4E454E /* "NONE" in ASCII. */
#define NET_BUF_TYPE_SMALL 0x4D534C41 /* "SMAL" in ASCII. */
#define NET_BUF_TYPE_LARGE 0x414C4752 /* "LARG" in ASCII. */
#else /* Dflt CPU_WORD_SIZE_08. */
#define NET_BUF_TYPE_NONE 0x4E4F4E45 /* "NONE" in ASCII. */
#define NET_BUF_TYPE_SMALL 0x534D414C /* "SMAL" in ASCII. */
#define NET_BUF_TYPE_LARGE 0x4C415247 /* "LARG" in ASCII. */
#endif
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK BUFFER INDEX & SIZE DEFINES
*
* Note(s) : (1) NET_BUF_DATA_PROTOCOL_HDR_SIZE_MAX's value is pre-#define'd in 'net_cfg_net.h' :
*
* (a) NET_BUF_DATA_PROTOCOL_HDR_SIZE_MAX's ideal #define'tion :
*
* (A) IF Hdr + max(Protocol Headers)
*
* (b) NET_BUF_DATA_PROTOCOL_HDR_SIZE_MAX #define'd with hard-coded knowledge that IF, IP &
* TCP headers have the largest combined maximum size of all the protocol headers :
*
* IP Hdr 60 ARP Hdr 68 IP Hdr 60 IP Hdr 60
* ICMP Hdr 0 UDP Hdr 8 TCP Hdr 60
* ------------- ------------ ------------ ------------
* Total 60 Total 68 Total 68 Total 120
*
* (c) Assumes maximum ARP header size of 68 octets based on maximum length hardware & protocol
* addresses. Actual ARP header size depends on actual hardware & protocol address lengths.
* See 'net_arp.h Note #2' for supported hardware & protocol types.
*
* (d) The minimum network buffer size MUST be configured greater than the maximum network packet
* header sizes so that the first of any fragmented packets always contains a complete receipt
* of all frame & network packet headers.
*
* (2) (a) Since network data value macro's appropriately convert data values from any CPU addresses,
* word-aligned or not; network receive & transmit packets are NOT required to ensure that
* network packet headers (ARP/IP/UDP/TCP/etc.) & header members will locate on CPU word-
* aligned addresses. Therefore, network receive & transmit packets are NOT required to
* start on any specific network buffer indices.
*
* See also 'net_util.h NETWORK DATA VALUE MACRO'S Note #2b'.
*
* (b) However, many processors may be more efficient & may even REQUIRE that memory transfers
* occur on CPU word-aligned addresses [e.g. processors or NICs with direct memory access
* (DMA) capability]. Therefore, network receive & transmit packets SHOULD start on CPU
* word-aligned network buffer indices.
*
* (1) Receive packet index SHOULD be configured for the first CPU word-aligned
* network buffer index.
*
* (2) Transmit data index SHOULD be configured to ensure that the transmit packet
* network buffer index is CPU word-aligned.
*
* (A) However, this assumes that a single data index may be configured that can handle
* all possible combinations of network packet header lengths while still ensuring
* that each transmit packet's network buffer index is CPU word-aligned.
*
* This assumption is valid if & only if all combinations of network packet header
* lengths are multiples of the CPU's word size.
*
* See also Note #1d.
*
* See also 'lib_mem.h MEMORY DATA VALUE MACRO'S Note #1a'.
*********************************************************************************************************
*/
/* --------------- NET BUF HDR/DATA IXs --------------- */
#define NET_BUF_DATA_BASE 0
/* See Note #2b1. */
#define NET_BUF_DATA_RX_IX NET_BUF_DATA_BASE
/* Tx ix/sizes based on max pkt hdr sizes ... */
/* ... (see Note #2b2). */
#define NET_BUF_DATA_PROTOCOL_HDR_BASE NET_BUF_DATA_BASE
#define NET_BUF_DATA_TX_IX (NET_BUF_DATA_PROTOCOL_HDR_BASE + NET_BUF_DATA_PROTOCOL_HDR_SIZE_MAX)
#define NET_BUF_DATA_SIZE_MIN NET_BUF_DATA_TX_IX
#define NET_BUF_DATA_PROTOCOL_HDR_SIZE NET_BUF_DATA_TX_IX
/*$PAGE*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NETWORK BUFFER QUANTITY DATA TYPE
*********************************************************************************************************
*/
typedef CPU_INT16U NET_BUF_QTY; /* Defines max qty of net bufs to support. */
/*
*********************************************************************************************************
* NETWORK BUFFER SIZE DATA TYPE
*
* Note(s) : (1) NET_BUF_IX_NONE SHOULD be globally #define'd AFTER 'NET_BUF_SIZE' data type declared.
*********************************************************************************************************
*/
typedef CPU_INT16U NET_BUF_SIZE; /* Defines max size of net buf data. */
#define NET_BUF_IX_NONE DEF_INT_16U_MAX_VAL /* Define as max unsigned val (see Note #1). */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK BUFFER HEADER DATA TYPE
*
* NET_BUF_HDR
* |-------------|
* | Buffer Type |
* |-------------|
* | Buffer Size |
* |-------------|
* | Flags |
* Previous |-------------|
* Buffer <----------O |
* Lists |-------------| Next
* | O----------> Buffer
* Previous |-------------| Lists
* Buffer <----------O |
* |-------------| Next
* | O----------> Buffer
* |-------------|
* | O----------> Buffer
* |-------------| Timer
* | |
* | O----------> Unlink Fnct
* | | & Obj Ptrs
* |-------------|
* | Reference |
* | Counter |
* |-------------|
* | |
* | |
* | Protocol |
* | Header |
* | Indices/ |
* | Lengths |
* | |
* | |
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -