Contiki-NG
queuebuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header file for the Packet queue buffer management
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup net
42  * @{
43  */
44 
45 /**
46  * \defgroup queuebuf Packet buffer queue
47  * @{
48  *
49  * The queuebuf module handles buffers that are queued.
50  *
51  */
52 
53 #ifndef QUEUEBUF_H_
54 #define QUEUEBUF_H_
55 
56 #include "net/packetbuf.h"
57 
58 /* QUEUEBUF_NUM is the total number of queuebuf */
59 #ifdef QUEUEBUF_CONF_NUM
60 #define QUEUEBUF_NUM QUEUEBUF_CONF_NUM
61 #else
62 #define QUEUEBUF_NUM 8
63 #endif
64 
65 /* QUEUEBUFRAM_NUM is the number of queuebufs stored in RAM.
66  If QUEUEBUFRAM_CONF_NUM is set lower than QUEUEBUF_NUM,
67  swapping is enabled and queuebufs are stored either in RAM of CFS.
68  If QUEUEBUFRAM_CONF_NUM is unset or >= to QUEUEBUF_NUM, all
69  queuebufs are in RAM and swapping is disabled. */
70 #ifdef QUEUEBUFRAM_CONF_NUM
71  #if QUEUEBUFRAM_CONF_NUM>QUEUEBUF_NUM
72  #error "QUEUEBUFRAM_CONF_NUM cannot be greater than QUEUEBUF_NUM"
73  #else
74  #define QUEUEBUFRAM_NUM QUEUEBUFRAM_CONF_NUM
75  #define WITH_SWAP (QUEUEBUFRAM_NUM < QUEUEBUF_NUM)
76  #endif
77 #else /* QUEUEBUFRAM_CONF_NUM */
78  #define QUEUEBUFRAM_NUM QUEUEBUF_NUM
79  #define WITH_SWAP 0
80 #endif /* QUEUEBUFRAM_CONF_NUM */
81 
82 #ifdef QUEUEBUF_CONF_DEBUG
83 #define QUEUEBUF_DEBUG QUEUEBUF_CONF_DEBUG
84 #else /* QUEUEBUF_CONF_DEBUG */
85 #define QUEUEBUF_DEBUG 0
86 #endif /* QUEUEBUF_CONF_DEBUG */
87 
88 struct queuebuf;
89 
90 void queuebuf_init(void);
91 
92 #if QUEUEBUF_DEBUG
93 struct queuebuf *queuebuf_new_from_packetbuf_debug(const char *file, int line);
94 #define queuebuf_new_from_packetbuf() queuebuf_new_from_packetbuf_debug(__FILE__, __LINE__)
95 #else /* QUEUEBUF_DEBUG */
96 struct queuebuf *queuebuf_new_from_packetbuf(void);
97 #endif /* QUEUEBUF_DEBUG */
98 void queuebuf_update_attr_from_packetbuf(struct queuebuf *b);
99 void queuebuf_update_from_packetbuf(struct queuebuf *b);
100 
101 void queuebuf_to_packetbuf(struct queuebuf *b);
102 void queuebuf_free(struct queuebuf *b);
103 
104 void *queuebuf_dataptr(struct queuebuf *b);
105 int queuebuf_datalen(struct queuebuf *b);
106 
107 linkaddr_t *queuebuf_addr(struct queuebuf *b, uint8_t type);
108 packetbuf_attr_t queuebuf_attr(struct queuebuf *b, uint8_t type);
109 
110 void queuebuf_debug_print(void);
111 
112 int queuebuf_numfree(void);
113 
114 #endif /* __QUEUEBUF_H__ */
115 
116 /** @} */
117 /** @} */
Header file for the Packet buffer (packetbuf) management