📄 fifo_policy.c
字号:
/*********************************************************************************//* This file has been written by Sergio Perez Alca駃z <serpeal@upvnet.upv.es> *//* Departamento de Inform醫ica de Sistemas y Computadores *//* Universidad Polit閏nica de Valencia *//* Valencia (Spain) *//* *//* The RTL-lwIP project has been supported by the Spanish Government Research *//* Office (CICYT) under grant TIC2002-04123-C03-03 *//* *//* Copyright (c) March, 2003 SISTEMAS DE TIEMPO REAL EMPOTRADOS, FIABLES Y *//* DISTRIBUIDOS BASADOS EN COMPONENTES *//* *//* This program is free software; you can redistribute it and/or modify *//* it under the terms of the GNU General Public License as published by *//* the Free Software Foundation; either version 2 of the License, or *//* (at your option) any later version. *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warrabnty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//* Linking RTL-lwIP statically or dynamically with other modules is making a *//* combined work based on RTL-lwIP. Thus, the terms and conditions of the GNU *//* General Public License cover the whole combination. *//* *//* As a special exception, the copyright holders of RTL-lwIP give you *//* permission to link RTL-lwIP with independent modules that communicate with *//* RTL-lwIP solely through the interfaces, regardless of the license terms of *//* these independent modules, and to copy and distribute the resulting combined *//* work under terms of your choice, provided that every copy of the combined *//* work is accompanied by a complete copy of the source code of RTL-lwIP (the *//* version of RTL-lwIP used to produce the combined work), being distributed *//* under the terms of the GNU General Public License plus this exception. An *//* independent module is a module which is not derived from or based on *//* RTL-lwIP. *//* *//* Note that people who make modified versions of RTL-lwIP are not obligated to *//* grant this special exception for their modified versions; it is their choice *//* whether to do so. The GNU General Public License gives permission to *//* release a modified version without this exception; this exception also makes *//* it possible to release a modified version which carries forward this *//* exception. *//*********************************************************************************/#include "netif/net_policy/FIFO_policy.h"#include <rtl_malloc.h>#include "memcopy.h"/*************************************************************************************/void FIFO_initialize_rx_buffer(void *rx_buffer){ struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; struct fifo_rx_slot_t *tmp; int i; tmp = fifo_rx_buffer->first = fifo_rx_buffer->add = fifo_rx_buffer->extract = rtl_malloc(sizeof(struct fifo_rx_slot_t)); for(i=0;i<(MAX_FIFO_RX_BUFFER_ENTRIES-1); i++){ tmp->next = rtl_malloc(sizeof(struct fifo_rx_slot_t)); tmp->read = 0x01; tmp->length = 0; tmp->data = rtl_malloc(PKT_BUF_SZ); tmp = tmp->next; } tmp->next = fifo_rx_buffer->first; tmp->read = 0x01; tmp->data = rtl_malloc(PKT_BUF_SZ); return;}/*************************************************************************************/void FIFO_dealloc_rx_buffer(void *rx_buffer){ struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; struct fifo_rx_slot_t *tmp = fifo_rx_buffer->first->next, *actual; int i; for(i=0;i<(MAX_FIFO_RX_BUFFER_ENTRIES-1); i++){ actual = tmp->next; if(tmp->data != NULL) rtl_free(tmp->data); rtl_free(tmp); tmp = actual; } if(fifo_rx_buffer->first->data != NULL) rtl_free(fifo_rx_buffer->first->data); rtl_free(fifo_rx_buffer->first); return;}/*************************************************************************************/int FIFO_add_frame_to_buffer(void *rx_buffer, unsigned char *data, int len){ struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; /* If the packet in the position that we're writting hasn't still been read is */ /* because we're receiving too much packets, so we need to drop it. */ if(fifo_rx_buffer->add->read != 0x00){ fifo_rx_buffer->add->length = len; memcpy(fifo_rx_buffer->add->data,data, len); fifo_rx_buffer->add->read = 0x00; fifo_rx_buffer->add = fifo_rx_buffer->add->next; return 0; }else // The packet is dropped return -1;}/*************************************************************************************/int FIFO_extract_frame_of_buffer(void *rx_buffer, void *data){ struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; struct fifo_rx_slot_t *tmp = fifo_rx_buffer->extract; ((struct memory *)data)->mem = tmp->data; tmp->read = 0x01; fifo_rx_buffer->extract = fifo_rx_buffer->extract->next; return tmp->length;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -