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 #ifdef QUEUEBUF_CONF_ENABLED
59 #define QUEUEBUF_ENABLED QUEUEBUF_CONF_ENABLED
60 #else /* QUEUEBUF_CONF_ENABLED */
61 #define QUEUEBUF_ENABLED 1
62 #endif /* QUEUEBUF_CONF_ENABLED */
63 
64 /* QUEUEBUF_NUM is the total number of queuebuf */
65 #ifdef QUEUEBUF_CONF_NUM
66 #define QUEUEBUF_NUM QUEUEBUF_CONF_NUM
67 #else
68 #define QUEUEBUF_NUM 8
69 #endif
70 
71 /* QUEUEBUFRAM_NUM is the number of queuebufs stored in RAM.
72  If QUEUEBUFRAM_CONF_NUM is set lower than QUEUEBUF_NUM,
73  swapping is enabled and queuebufs are stored either in RAM of CFS.
74  If QUEUEBUFRAM_CONF_NUM is unset or >= to QUEUEBUF_NUM, all
75  queuebufs are in RAM and swapping is disabled. */
76 #ifdef QUEUEBUFRAM_CONF_NUM
77  #if QUEUEBUFRAM_CONF_NUM>QUEUEBUF_NUM
78  #error "QUEUEBUFRAM_CONF_NUM cannot be greater than QUEUEBUF_NUM"
79  #else
80  #define QUEUEBUFRAM_NUM QUEUEBUFRAM_CONF_NUM
81  #define WITH_SWAP (QUEUEBUFRAM_NUM < QUEUEBUF_NUM)
82  #endif
83 #else /* QUEUEBUFRAM_CONF_NUM */
84  #define QUEUEBUFRAM_NUM QUEUEBUF_NUM
85  #define WITH_SWAP 0
86 #endif /* QUEUEBUFRAM_CONF_NUM */
87 
88 #ifdef QUEUEBUF_CONF_DEBUG
89 #define QUEUEBUF_DEBUG QUEUEBUF_CONF_DEBUG
90 #else /* QUEUEBUF_CONF_DEBUG */
91 #define QUEUEBUF_DEBUG 0
92 #endif /* QUEUEBUF_CONF_DEBUG */
93 
94 struct queuebuf;
95 
96 void queuebuf_init(void);
97 
98 #if QUEUEBUF_DEBUG
99 struct queuebuf *queuebuf_new_from_packetbuf_debug(const char *file, int line);
100 #define queuebuf_new_from_packetbuf() queuebuf_new_from_packetbuf_debug(__FILE__, __LINE__)
101 #else /* QUEUEBUF_DEBUG */
102 struct queuebuf *queuebuf_new_from_packetbuf(void);
103 #endif /* QUEUEBUF_DEBUG */
104 void queuebuf_update_attr_from_packetbuf(struct queuebuf *b);
105 void queuebuf_update_from_packetbuf(struct queuebuf *b);
106 
107 void queuebuf_to_packetbuf(struct queuebuf *b);
108 void queuebuf_free(struct queuebuf *b);
109 
110 void *queuebuf_dataptr(struct queuebuf *b);
111 int queuebuf_datalen(struct queuebuf *b);
112 
113 linkaddr_t *queuebuf_addr(struct queuebuf *b, uint8_t type);
114 packetbuf_attr_t queuebuf_attr(struct queuebuf *b, uint8_t type);
115 
116 void queuebuf_debug_print(void);
117 
118 int queuebuf_numfree(void);
119 
120 #endif /* __QUEUEBUF_H__ */
121 
122 /** @} */
123 /** @} */
Header file for the Packet buffer (packetbuf) management