www.pudn.com > TCPmodbushy.rar > pbuf.h


/* 
 * 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  
 * 
 */ 
 
#ifndef __LWIP_PBUF_H__ 
#define __LWIP_PBUF_H__ 
 
#include "o:/arch/cc.h" 
 
/****************************************************************************** 
* Function switch 
*******************************************************************************/ 
#define NEED_PBUF_QUEUE 0 
#define NEED_PBUF_DECHAIN 0 
 
#define PBUF_TRANSPORT_HLEN 20 
#define PBUF_IP_HLEN        20 
 
typedef enum { 
  PBUF_TRANSPORT, 
  PBUF_IP, 
  PBUF_LINK, 
  PBUF_RAW 
} pbuf_layer; 
 
typedef enum { 
  PBUF_RAM, 
  PBUF_ROM, 
  PBUF_REF, 
  PBUF_POOL 
} 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 */ 
 
/** indicates this packet was broadcast on the link */ 
#define PBUF_FLAG_LINK_BROADCAST 0x80U 
 
struct pbuf { 
  /** next pbuf in singly linked pbuf chain */ 
  struct pbuf xdata *next; 
 
  /** pointer to the actual data in the buffer */ 
  void xdata *payload; 
 
  /** 
   * 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) 
   */ 
  u16_t tot_len; 
   
  /** length of this buffer */ 
  u16_t len;   
 
  /** flags telling the type of pbuf, see PBUF_FLAG_ */ 
  u8_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. 
   */ 
  u8_t ref; 
   
}; 
 
extern struct pbuf xdata* pCashData; 
 
void pbuf_init(void); 
 
struct pbuf xdata *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag); 
void pbuf_realloc(struct pbuf xdata *p, u16_t size);  
u8_t pbuf_header(struct pbuf xdata *p, s16_t header_size); 
void pbuf_ref(struct pbuf xdata *p); 
void pbuf_ref_chain(struct pbuf xdata *p); 
u8_t pbuf_free(struct pbuf xdata *p); 
u8_t pbuf_clen(struct pbuf xdata *p);   
void pbuf_cat(struct pbuf xdata *h, struct pbuf xdata *t); 
void pbuf_chain(struct pbuf xdata *h, struct pbuf xdata *t); 
struct pbuf xdata *pbuf_take(struct pbuf xdata *f); 
 
#if NEED_PBUF_DECHAIN 
struct pbuf xdata *pbuf_dechain(struct pbuf xdata *p); 
#endif 
 
#if NEED_PBUF_QUEUE  
void pbuf_queue(struct pbuf xdata *p, struct pbuf xdata *n); 
#endif 
 
struct pbuf xdata *pbuf_dequeue(struct pbuf xdata *p); 
 
#endif /* __LWIP_PBUF_H__ */