00001 /*********************************************************************************/ 00002 /* This file has been written by Sergio Perez Alcañiz <serpeal@disca.upv.es> */ 00003 /* Departamento de Informática de Sistemas y Computadores */ 00004 /* Universidad Politécnica de Valencia */ 00005 /* Valencia (Spain) */ 00006 /* */ 00007 /* The RTL-lwIP project has been supported by the Spanish Government Research */ 00008 /* Office (CICYT) under grant TIC2002-04123-C03-03 */ 00009 /* */ 00010 /* Copyright (c) March, 2003 SISTEMAS DE TIEMPO REAL EMPOTRADOS, FIABLES Y */ 00011 /* DISTRIBUIDOS BASADOS EN COMPONENTES */ 00012 /* */ 00013 /* This program is free software; you can redistribute it and/or modify */ 00014 /* it under the terms of the GNU General Public License as published by */ 00015 /* the Free Software Foundation; either version 2 of the License, or */ 00016 /* (at your option) any later version. */ 00017 /* */ 00018 /* This program is distributed in the hope that it will be useful, */ 00019 /* but WITHOUT ANY WARRANTY; without even the implied warrabnty of */ 00020 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 00021 /* GNU General Public License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU General Public License */ 00024 /* along with this program; if not, write to the Free Software */ 00025 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00026 /* */ 00027 /* Linking RTL-lwIP statically or dynamically with other modules is making a */ 00028 /* combined work based on RTL-lwIP. Thus, the terms and conditions of the GNU */ 00029 /* General Public License cover the whole combination. */ 00030 /* */ 00031 /* As a special exception, the copyright holders of RTL-lwIP give you */ 00032 /* permission to link RTL-lwIP with independent modules that communicate with */ 00033 /* RTL-lwIP solely through the interfaces, regardless of the license terms of */ 00034 /* these independent modules, and to copy and distribute the resulting combined */ 00035 /* work under terms of your choice, provided that every copy of the combined */ 00036 /* work is accompanied by a complete copy of the source code of RTL-lwIP (the */ 00037 /* version of RTL-lwIP used to produce the combined work), being distributed */ 00038 /* under the terms of the GNU General Public License plus this exception. An */ 00039 /* independent module is a module which is not derived from or based on */ 00040 /* RTL-lwIP. */ 00041 /* */ 00042 /* Note that people who make modified versions of RTL-lwIP are not obligated to */ 00043 /* grant this special exception for their modified versions; it is their choice */ 00044 /* whether to do so. The GNU General Public License gives permission to */ 00045 /* release a modified version without this exception; this exception also makes */ 00046 /* it possible to release a modified version which carries forward this */ 00047 /* exception. */ 00048 /*********************************************************************************/ 00049 00050 #include "netif/net_policy/FIFO_policy.h" 00051 #include <rtl_malloc.h> 00052 #include "memcopy.h" 00053 00054 /*************************************************************************************/ 00055 void FIFO_initialize_rx_buffer(void *rx_buffer){ 00056 struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; 00057 struct fifo_rx_slot_t *tmp; 00058 int i; 00059 tmp = fifo_rx_buffer->first = fifo_rx_buffer->add = fifo_rx_buffer->extract = rtl_malloc(sizeof(struct fifo_rx_slot_t)); 00060 00061 for(i=0;i<(MAX_FIFO_RX_BUFFER_ENTRIES-1); i++){ 00062 tmp->next = rtl_malloc(sizeof(struct fifo_rx_slot_t)); 00063 tmp->read = 0x01; 00064 tmp->length = 0; 00065 tmp->data = rtl_malloc(PKT_BUF_SZ); 00066 tmp = tmp->next; 00067 } 00068 tmp->next = fifo_rx_buffer->first; 00069 tmp->read = 0x01; 00070 tmp->data = rtl_malloc(PKT_BUF_SZ); 00071 00072 return; 00073 } 00074 00075 /*************************************************************************************/ 00076 void FIFO_dealloc_rx_buffer(void *rx_buffer){ 00077 struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; 00078 struct fifo_rx_slot_t *tmp = fifo_rx_buffer->first->next, *actual; 00079 int i; 00080 00081 for(i=0;i<(MAX_FIFO_RX_BUFFER_ENTRIES-1); i++){ 00082 actual = tmp->next; 00083 if(tmp->data != NULL) 00084 rtl_free(tmp->data); 00085 rtl_free(tmp); 00086 tmp = actual; 00087 } 00088 if(fifo_rx_buffer->first->data != NULL) 00089 rtl_free(fifo_rx_buffer->first->data); 00090 rtl_free(fifo_rx_buffer->first); 00091 00092 return; 00093 } 00094 00095 /*************************************************************************************/ 00096 int FIFO_add_frame_to_buffer(void *rx_buffer, unsigned char *data, int len){ 00097 struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; 00098 00099 /* If the packet in the position that we're writting hasn't still been read is */ 00100 /* because we're receiving too much packets, so we need to drop it. */ 00101 00102 00103 if(fifo_rx_buffer->add->read != 0x00){ 00104 fifo_rx_buffer->add->length = len; 00105 00106 memcpy(fifo_rx_buffer->add->data,data, len); 00107 00108 fifo_rx_buffer->add->read = 0x00; 00109 fifo_rx_buffer->add = fifo_rx_buffer->add->next; 00110 00111 return 0; 00112 }else 00113 // The packet is dropped 00114 return -1; 00115 } 00116 00117 /*************************************************************************************/ 00118 int FIFO_extract_frame_of_buffer(void *rx_buffer, void *data){ 00119 struct fifo_rx_buffer_t *fifo_rx_buffer = (struct fifo_rx_buffer_t *) rx_buffer; 00120 struct fifo_rx_slot_t *tmp = fifo_rx_buffer->extract; 00121 00122 ((struct memory *)data)->mem = tmp->data; 00123 tmp->read = 0x01; 00124 fifo_rx_buffer->extract = fifo_rx_buffer->extract->next; 00125 00126 return tmp->length; 00127 } 00128 00129