2007-02-28 17:38:51 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006, 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. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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 Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2007-03-30 01:18:47 +02:00
|
|
|
* Implementation of the Rime queue buffers
|
2007-02-28 17:38:51 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
2014-11-08 01:15:42 +01:00
|
|
|
/**
|
|
|
|
* \addtogroup rimequeuebuf
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2007-05-15 10:09:21 +02:00
|
|
|
#include "contiki-net.h"
|
2015-03-24 08:26:34 +01:00
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
|
|
|
#include "cfs/cfs.h"
|
|
|
|
#endif
|
2007-02-28 17:38:51 +01:00
|
|
|
|
2007-03-15 10:56:15 +01:00
|
|
|
#include <string.h> /* for memcpy() */
|
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
/* Structure pointing to a buffer either stored
|
|
|
|
in RAM or swapped in CFS */
|
2007-02-28 17:38:51 +01:00
|
|
|
struct queuebuf {
|
2010-11-25 09:43:59 +01:00
|
|
|
#if QUEUEBUF_DEBUG
|
|
|
|
struct queuebuf *next;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
clock_time_t time;
|
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
|
|
|
enum {IN_RAM, IN_CFS} location;
|
|
|
|
union {
|
|
|
|
#endif
|
|
|
|
struct queuebuf_data *ram_ptr;
|
|
|
|
#if WITH_SWAP
|
|
|
|
int swap_id;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The actual queuebuf data */
|
|
|
|
struct queuebuf_data {
|
2010-04-30 09:29:08 +02:00
|
|
|
uint8_t data[PACKETBUF_SIZE];
|
2014-11-10 14:27:17 +01:00
|
|
|
uint16_t len;
|
2009-03-12 22:58:20 +01:00
|
|
|
struct packetbuf_attr attrs[PACKETBUF_NUM_ATTRS];
|
|
|
|
struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
|
2007-02-28 17:38:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
MEMB(bufmem, struct queuebuf, QUEUEBUF_NUM);
|
2011-09-27 16:05:30 +02:00
|
|
|
MEMB(buframmem, struct queuebuf_data, QUEUEBUFRAM_NUM);
|
|
|
|
|
|
|
|
#if WITH_SWAP
|
|
|
|
|
|
|
|
/* Swapping allows to store up to QUEUEBUF_NUM - QUEUEBUFRAM_NUM
|
|
|
|
queuebufs in CFS. The swap is made of several large CFS files.
|
|
|
|
Every buffer stored in CFS has a swap id, referring to a specific
|
|
|
|
offset in one of these files. */
|
|
|
|
#define NQBUF_FILES 4
|
|
|
|
#define NQBUF_PER_FILE 256
|
|
|
|
#define QBUF_FILE_SIZE (NQBUF_PER_FILE*sizeof(struct queuebuf_data))
|
|
|
|
#define NQBUF_ID (NQBUF_PER_FILE * NQBUF_FILES)
|
|
|
|
|
|
|
|
struct qbuf_file {
|
|
|
|
int fd;
|
|
|
|
int usage;
|
|
|
|
int renewable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A statically allocated queuebuf used as a cache for swapped qbufs */
|
|
|
|
static struct queuebuf_data tmpdata;
|
|
|
|
/* A pointer to the qbuf associated to the data in tmpdata */
|
|
|
|
static struct queuebuf *tmpdata_qbuf = NULL;
|
|
|
|
/* The swap id counter */
|
|
|
|
static int next_swap_id = 0;
|
|
|
|
/* The swap files */
|
|
|
|
static struct qbuf_file qbuf_files[NQBUF_FILES];
|
|
|
|
/* The timer used to renew files during inactivity periods */
|
|
|
|
static struct ctimer renew_timer;
|
|
|
|
|
|
|
|
#endif
|
2007-03-31 20:31:27 +02:00
|
|
|
|
2010-11-25 09:43:59 +01:00
|
|
|
#if QUEUEBUF_DEBUG
|
|
|
|
#include "lib/list.h"
|
|
|
|
LIST(queuebuf_list);
|
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
|
|
|
|
2007-03-31 20:31:27 +02:00
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
2010-02-08 22:10:32 +01:00
|
|
|
#ifdef QUEUEBUF_CONF_STATS
|
|
|
|
#define QUEUEBUF_STATS QUEUEBUF_CONF_STATS
|
2010-06-24 11:48:21 +02:00
|
|
|
#else
|
|
|
|
#define QUEUEBUF_STATS 0
|
2010-02-08 22:10:32 +01:00
|
|
|
#endif /* QUEUEBUF_CONF_STATS */
|
|
|
|
|
2007-05-15 10:09:21 +02:00
|
|
|
#if QUEUEBUF_STATS
|
2015-03-24 08:26:34 +01:00
|
|
|
uint8_t queuebuf_len, queuebuf_max_len;
|
2007-05-15 10:09:21 +02:00
|
|
|
#endif /* QUEUEBUF_STATS */
|
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
qbuf_renew_file(int file)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char name[2];
|
|
|
|
name[0] = 'a' + file;
|
|
|
|
name[1] = '\0';
|
|
|
|
if(qbuf_files[file].renewable == 1) {
|
|
|
|
PRINTF("qbuf_renew_file: removing file %d\n", file);
|
|
|
|
cfs_remove(name);
|
|
|
|
}
|
|
|
|
ret = cfs_open(name, CFS_READ | CFS_WRITE);
|
|
|
|
if(ret == -1) {
|
|
|
|
PRINTF("qbuf_renew_file: cfs open error\n");
|
|
|
|
}
|
|
|
|
qbuf_files[file].fd = ret;
|
|
|
|
qbuf_files[file].usage = 0;
|
|
|
|
qbuf_files[file].renewable = 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Renews every file with renewable flag set */
|
|
|
|
static void
|
|
|
|
qbuf_renew_all(void *unused)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0; i<NQBUF_FILES; i++) {
|
|
|
|
if(qbuf_files[i].renewable == 1) {
|
|
|
|
qbuf_renew_file(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Removes a queuebuf from its swap file */
|
|
|
|
static void
|
|
|
|
queuebuf_remove_from_file(int swap_id)
|
|
|
|
{
|
|
|
|
int fileid;
|
|
|
|
if(swap_id != -1) {
|
|
|
|
fileid = swap_id / NQBUF_PER_FILE;
|
|
|
|
qbuf_files[fileid].usage--;
|
|
|
|
|
|
|
|
/* The file is full but doesn't contain any more queuebuf, mark it as renewable */
|
|
|
|
if(qbuf_files[fileid].usage == 0 && fileid != next_swap_id / NQBUF_PER_FILE) {
|
|
|
|
qbuf_files[fileid].renewable = 1;
|
|
|
|
/* This file is renewable, set a timer to renew files */
|
|
|
|
ctimer_set(&renew_timer, 0, qbuf_renew_all, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmpdata_qbuf->swap_id == swap_id) {
|
|
|
|
tmpdata_qbuf->swap_id = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
get_new_swap_id(void)
|
|
|
|
{
|
|
|
|
int fileid;
|
|
|
|
int swap_id = next_swap_id;
|
|
|
|
fileid = swap_id / NQBUF_PER_FILE;
|
|
|
|
if(swap_id % NQBUF_PER_FILE == 0) { /* This is the first id in the file */
|
|
|
|
if(qbuf_files[fileid].renewable) {
|
|
|
|
qbuf_renew_file(fileid);
|
|
|
|
}
|
|
|
|
if(qbuf_files[fileid].usage>0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qbuf_files[fileid].usage++;
|
|
|
|
next_swap_id = (next_swap_id+1) % NQBUF_ID;
|
|
|
|
return swap_id;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Flush tmpdata to CFS */
|
|
|
|
static int
|
|
|
|
queuebuf_flush_tmpdata(void)
|
|
|
|
{
|
|
|
|
int fileid, fd, ret;
|
|
|
|
cfs_offset_t offset;
|
|
|
|
if(tmpdata_qbuf) {
|
|
|
|
queuebuf_remove_from_file(tmpdata_qbuf->swap_id);
|
|
|
|
tmpdata_qbuf->swap_id = get_new_swap_id();
|
|
|
|
if(tmpdata_qbuf->swap_id == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fileid = tmpdata_qbuf->swap_id / NQBUF_PER_FILE;
|
|
|
|
offset = (tmpdata_qbuf->swap_id % NQBUF_PER_FILE) * sizeof(struct queuebuf_data);
|
|
|
|
fd = qbuf_files[fileid].fd;
|
|
|
|
ret = cfs_seek(fd, offset, CFS_SEEK_SET);
|
|
|
|
if(ret == -1) {
|
|
|
|
PRINTF("queuebuf_flush_tmpdata: cfs seek error\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = cfs_write(fd, &tmpdata, sizeof(struct queuebuf_data));
|
|
|
|
if(ret == -1) {
|
|
|
|
PRINTF("queuebuf_flush_tmpdata: cfs write error\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* If the queuebuf is in CFS, load it to tmpdata */
|
|
|
|
static struct queuebuf_data *
|
|
|
|
queuebuf_load_to_ram(struct queuebuf *b)
|
|
|
|
{
|
|
|
|
int fileid, fd, ret;
|
|
|
|
cfs_offset_t offset;
|
|
|
|
if(b->location == IN_RAM) { /* the qbuf is loacted in RAM */
|
|
|
|
return b->ram_ptr;
|
|
|
|
} else { /* the qbuf is located in CFS */
|
|
|
|
if(tmpdata_qbuf && tmpdata_qbuf->swap_id == b->swap_id) { /* the qbuf is already in tmpdata */
|
|
|
|
return &tmpdata;
|
|
|
|
} else { /* the qbuf needs to be loaded from CFS */
|
|
|
|
tmpdata_qbuf = b;
|
|
|
|
/* read the qbuf from CFS */
|
|
|
|
fileid = b->swap_id / NQBUF_PER_FILE;
|
|
|
|
offset = (b->swap_id % NQBUF_PER_FILE) * sizeof(struct queuebuf_data);
|
|
|
|
fd = qbuf_files[fileid].fd;
|
|
|
|
ret = cfs_seek(fd, offset, CFS_SEEK_SET);
|
|
|
|
if(ret == -1) {
|
|
|
|
PRINTF("queuebuf_load_to_ram: cfs seek error\n");
|
|
|
|
}
|
|
|
|
ret = cfs_read(fd, &tmpdata, sizeof(struct queuebuf_data));
|
|
|
|
if(ret == -1) {
|
|
|
|
PRINTF("queuebuf_load_to_ram: cfs read error\n");
|
|
|
|
}
|
|
|
|
return &tmpdata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* WITH_SWAP */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static struct queuebuf_data *
|
|
|
|
queuebuf_load_to_ram(struct queuebuf *b)
|
|
|
|
{
|
|
|
|
return b->ram_ptr;
|
|
|
|
}
|
|
|
|
#endif /* WITH_SWAP */
|
2007-02-28 17:38:51 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
queuebuf_init(void)
|
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
|
|
|
int i;
|
|
|
|
for(i=0; i<NQBUF_FILES; i++) {
|
|
|
|
qbuf_files[i].renewable = 1;
|
|
|
|
qbuf_renew_file(i);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
memb_init(&buframmem);
|
2007-02-28 17:38:51 +01:00
|
|
|
memb_init(&bufmem);
|
2007-05-15 10:09:21 +02:00
|
|
|
#if QUEUEBUF_STATS
|
2015-03-24 08:26:34 +01:00
|
|
|
queuebuf_max_len = 0;
|
2007-05-15 10:09:21 +02:00
|
|
|
#endif /* QUEUEBUF_STATS */
|
2007-02-28 17:38:51 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-09-02 16:19:08 +02:00
|
|
|
int
|
|
|
|
queuebuf_numfree(void)
|
|
|
|
{
|
2015-03-24 08:26:34 +01:00
|
|
|
return memb_numfree(&bufmem);
|
2013-09-02 16:19:08 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-25 09:43:59 +01:00
|
|
|
#if QUEUEBUF_DEBUG
|
|
|
|
struct queuebuf *
|
|
|
|
queuebuf_new_from_packetbuf_debug(const char *file, int line)
|
|
|
|
#else /* QUEUEBUF_DEBUG */
|
2007-02-28 17:38:51 +01:00
|
|
|
struct queuebuf *
|
2009-03-12 22:58:20 +01:00
|
|
|
queuebuf_new_from_packetbuf(void)
|
2010-11-25 09:43:59 +01:00
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
|
|
|
struct queuebuf *buf;
|
|
|
|
|
2015-03-24 08:26:34 +01:00
|
|
|
struct queuebuf_data *buframptr;
|
|
|
|
buf = memb_alloc(&bufmem);
|
|
|
|
if(buf != NULL) {
|
2010-11-25 09:43:59 +01:00
|
|
|
#if QUEUEBUF_DEBUG
|
2015-03-24 08:26:34 +01:00
|
|
|
list_add(queuebuf_list, buf);
|
|
|
|
buf->file = file;
|
|
|
|
buf->line = line;
|
|
|
|
buf->time = clock_time();
|
2010-11-25 09:43:59 +01:00
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
2015-03-24 08:26:34 +01:00
|
|
|
buf->ram_ptr = memb_alloc(&buframmem);
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
2015-03-24 08:26:34 +01:00
|
|
|
/* If the allocation failed, store the qbuf in swap files */
|
|
|
|
if(buf->ram_ptr != NULL) {
|
|
|
|
buf->location = IN_RAM;
|
2011-09-27 16:05:30 +02:00
|
|
|
buframptr = buf->ram_ptr;
|
2015-03-24 08:26:34 +01:00
|
|
|
} else {
|
|
|
|
buf->location = IN_CFS;
|
|
|
|
buf->swap_id = -1;
|
|
|
|
tmpdata_qbuf = buf;
|
|
|
|
buframptr = &tmpdata;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(buf->ram_ptr == NULL) {
|
|
|
|
PRINTF("queuebuf_new_from_packetbuf: could not queuebuf data\n");
|
|
|
|
memb_free(&bufmem, buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
buframptr = buf->ram_ptr;
|
2011-09-27 16:05:30 +02:00
|
|
|
#endif
|
|
|
|
|
2015-03-24 08:26:34 +01:00
|
|
|
buframptr->len = packetbuf_copyto(buframptr->data);
|
|
|
|
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
|
2011-09-27 16:05:30 +02:00
|
|
|
|
|
|
|
#if WITH_SWAP
|
2015-03-24 08:26:34 +01:00
|
|
|
if(buf->location == IN_CFS) {
|
|
|
|
if(queuebuf_flush_tmpdata() == -1) {
|
|
|
|
/* We were unable to write the data in the swap */
|
|
|
|
memb_free(&bufmem, buf);
|
|
|
|
return NULL;
|
2011-09-27 16:05:30 +02:00
|
|
|
}
|
2015-03-24 08:26:34 +01:00
|
|
|
}
|
2011-09-27 16:05:30 +02:00
|
|
|
#endif
|
|
|
|
|
2007-05-15 10:09:21 +02:00
|
|
|
#if QUEUEBUF_STATS
|
2015-03-24 08:26:34 +01:00
|
|
|
++queuebuf_len;
|
|
|
|
PRINTF("#A q=%d\n", queuebuf_len);
|
|
|
|
if(queuebuf_len > queuebuf_max_len) {
|
|
|
|
queuebuf_max_len = queuebuf_len;
|
|
|
|
}
|
2007-05-15 10:09:21 +02:00
|
|
|
#endif /* QUEUEBUF_STATS */
|
2011-09-27 16:05:30 +02:00
|
|
|
|
2015-03-24 08:26:34 +01:00
|
|
|
} else {
|
|
|
|
PRINTF("queuebuf_new_from_packetbuf: could not allocate a queuebuf\n");
|
2007-02-28 17:38:51 +01:00
|
|
|
}
|
2015-03-24 08:26:34 +01:00
|
|
|
return buf;
|
2007-02-28 17:38:51 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2011-06-15 16:10:07 +02:00
|
|
|
queuebuf_update_attr_from_packetbuf(struct queuebuf *buf)
|
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(buf);
|
|
|
|
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
|
|
|
|
#if WITH_SWAP
|
|
|
|
if(buf->location == IN_CFS) {
|
|
|
|
queuebuf_flush_tmpdata();
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-15 16:10:07 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2014-04-26 11:39:51 +02:00
|
|
|
queuebuf_update_from_packetbuf(struct queuebuf *buf)
|
|
|
|
{
|
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(buf);
|
|
|
|
packetbuf_attr_copyto(buframptr->attrs, buframptr->addrs);
|
|
|
|
buframptr->len = packetbuf_copyto(buframptr->data);
|
|
|
|
#if WITH_SWAP
|
|
|
|
if(buf->location == IN_CFS) {
|
|
|
|
queuebuf_flush_tmpdata();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2007-02-28 17:38:51 +01:00
|
|
|
queuebuf_free(struct queuebuf *buf)
|
|
|
|
{
|
|
|
|
if(memb_inmemb(&bufmem, buf)) {
|
2011-09-27 16:05:30 +02:00
|
|
|
#if WITH_SWAP
|
|
|
|
if(buf->location == IN_RAM) {
|
|
|
|
memb_free(&buframmem, buf->ram_ptr);
|
|
|
|
} else {
|
|
|
|
queuebuf_remove_from_file(buf->swap_id);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
memb_free(&buframmem, buf->ram_ptr);
|
|
|
|
#endif
|
2007-02-28 17:38:51 +01:00
|
|
|
memb_free(&bufmem, buf);
|
2007-05-15 10:09:21 +02:00
|
|
|
#if QUEUEBUF_STATS
|
|
|
|
--queuebuf_len;
|
2015-03-24 08:26:34 +01:00
|
|
|
PRINTF("#A q=%d\n", queuebuf_len);
|
2007-05-15 10:09:21 +02:00
|
|
|
#endif /* QUEUEBUF_STATS */
|
2010-11-25 09:43:59 +01:00
|
|
|
#if QUEUEBUF_DEBUG
|
|
|
|
list_remove(queuebuf_list, buf);
|
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
2007-02-28 17:38:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2009-03-12 22:58:20 +01:00
|
|
|
queuebuf_to_packetbuf(struct queuebuf *b)
|
2007-02-28 17:38:51 +01:00
|
|
|
{
|
|
|
|
if(memb_inmemb(&bufmem, b)) {
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
|
|
|
packetbuf_copyfrom(buframptr->data, buframptr->len);
|
|
|
|
packetbuf_attr_copyfrom(buframptr->attrs, buframptr->addrs);
|
2007-02-28 17:38:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-20 13:26:23 +01:00
|
|
|
void *
|
|
|
|
queuebuf_dataptr(struct queuebuf *b)
|
|
|
|
{
|
|
|
|
if(memb_inmemb(&bufmem, b)) {
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
|
|
|
return buframptr->data;
|
2007-03-20 13:26:23 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
queuebuf_datalen(struct queuebuf *b)
|
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
|
|
|
return buframptr->len;
|
2007-03-20 13:26:23 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_t *
|
2010-04-30 09:29:08 +02:00
|
|
|
queuebuf_addr(struct queuebuf *b, uint8_t type)
|
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
|
|
|
return &buframptr->addrs[type - PACKETBUF_ADDR_FIRST].addr;
|
2010-04-30 09:29:08 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-10-04 22:26:01 +02:00
|
|
|
packetbuf_attr_t
|
|
|
|
queuebuf_attr(struct queuebuf *b, uint8_t type)
|
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
|
|
|
return buframptr->attrs[type].val;
|
2010-10-04 22:26:01 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-25 09:43:59 +01:00
|
|
|
void
|
|
|
|
queuebuf_debug_print(void)
|
|
|
|
{
|
|
|
|
#if QUEUEBUF_DEBUG
|
|
|
|
struct queuebuf *q;
|
|
|
|
printf("queuebuf_list: ");
|
|
|
|
for(q = list_head(queuebuf_list); q != NULL;
|
|
|
|
q = list_item_next(q)) {
|
|
|
|
printf("%s,%d,%lu ", q->file, q->line, q->time);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif /* QUEUEBUF_DEBUG */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-03-31 20:31:27 +02:00
|
|
|
/** @} */
|