Contiki-Inga 3.x
queuebuf.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimequeuebuf Rime queue buffer management
8  * @{
9  *
10  * The queuebuf module handles buffers that are queued.
11  *
12  */
13 
14 /*
15  * Copyright (c) 2006, Swedish Institute of Computer Science.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution.
26  * 3. Neither the name of the Institute nor the names of its contributors
27  * may be used to endorse or promote products derived from this software
28  * without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  *
42  * This file is part of the Contiki operating system.
43  *
44  */
45 
46 /**
47  * \file
48  * Header file for the Rime queue buffer management
49  * \author
50  * Adam Dunkels <adam@sics.se>
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 
100 void queuebuf_to_packetbuf(struct queuebuf *b);
101 void queuebuf_free(struct queuebuf *b);
102 
103 void *queuebuf_dataptr(struct queuebuf *b);
104 int queuebuf_datalen(struct queuebuf *b);
105 
106 linkaddr_t *queuebuf_addr(struct queuebuf *b, uint8_t type);
107 packetbuf_attr_t queuebuf_attr(struct queuebuf *b, uint8_t type);
108 
109 void queuebuf_debug_print(void);
110 
111 #endif /* QUEUEBUF_H_ */
112 
113 /** @} */
114 /** @} */