📄 rtfifoif.c
字号:
/* * Copyright (c) 2001, 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 based in one file part of the lwIP TCP/IP stack. The file is: *//* ethernetif.c *//* which author is: Adam Dunkels <adam@sics.se> *//* *//* This file has been modified 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 "lwip/opt.h"#include "lwip/def.h"#include "lwip/ip.h"#include "lwip/mem.h"#include "lwip/pbuf.h"#include "lwip/sys.h"#include "bcopy.h"#include "netif/arp.h"#include <time.h>#include <rtl_sched.h>#include <rtl_fifo.h>#ifdef __RTFIFOOPTS__#define DEVWRITE "/dev/rtf0"#define DEVREAD "/dev/rtf1"#define IFNAME0 'r'#define IFNAME1 't'#define SETBYTEONE(a,b) (a=(b & 0x000F))#define SETBYTETWO(a,b) (a=(b & 0x00F0)) #define SETBYTETHREE(a,b) (a=(b & 0x0F00))#define SETBYTEFOUR(a,b) (a=(b & 0xF000))static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};struct rtfifoif { struct eth_addr *ethaddr; int writefd; int readfd;};/* Forward declarations. */static void rtfifoif_input(struct netif *netif);static err_t rtfifoif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);static void rtfifoif_thread(void *arg);/*-----------------------------------------------------------------------------------*/static voidlow_level_init(struct netif *netif){ struct rtfifoif *rtfifoif; rtfifoif = netif->state; /* Obtain MAC address from network interface. */ string2mac(rtfifoif->ethaddr,RTFIFO_MAC); /* We use RTfifo 0 for writing */ rtfifoif->writefd = 0; /* We use RTfifo 1 for reading */ rtfifoif->readfd = 1; sys_thread_new(rtfifoif_thread, netif, RTFIFO_THREAD_PERIOD);}/*-----------------------------------------------------------------------------------*/static void rtfifoif_thread(void *arg){ struct netif *netif; struct rtfifoif *rtfifoif; netif = arg; rtfifoif = netif->state; while(1) { pthread_wait_np(); /* Wait for a packet to arrive. */ while(rtf_isempty(rtfifoif->readfd)){ usleep(RTFIFO_DELAY); } /* Handle incoming packet. */ rtfifoif_input(netif); }}/*-----------------------------------------------------------------------------------*//* * low_level_output(): * * Should do the actual transmission of the packet. The packet is * contained in the pbuf that is passed to the function. This pbuf * might be chained. * *//*-----------------------------------------------------------------------------------*/static err_tlow_level_output(struct rtfifoif *rtfifoif, struct pbuf *p){ struct pbuf *q; char buf[1500]; char *bufptr; unsigned char size_of_packet[4]; /* initiate transfer(); */ bufptr = &buf[0]; for(q = p; q != NULL; q = q->next) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ /* send data from(q->payload, q->len); */ bcopy(q->payload, bufptr, q->len); bufptr += q->len; } SETBYTEONE(size_of_packet[0],p->tot_len); SETBYTETWO(size_of_packet[1],p->tot_len); SETBYTETHREE(size_of_packet[2],p->tot_len); SETBYTEFOUR(size_of_packet[3],p->tot_len); if(rtf_put(rtfifoif->writefd, &size_of_packet, 4) == -1) { rtl_printf("low_level_output: rtf_put error"); }else{ if(rtf_put(rtfifoif->writefd, buf, p->tot_len) == -1) { rtl_printf("low_level_output: rtf_put error"); } } return ERR_OK;}/*-----------------------------------------------------------------------------------*//* * low_level_input(): * * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * *//*-----------------------------------------------------------------------------------*/static struct pbuf *low_level_input(struct rtfifoif *rtfifoif){ struct pbuf *p, *q; u16_t len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -