Add the arch files for "ti_c6711", that's a 32bit DSP. [2005.01.29 by Ming]

This commit is contained in:
ming 2005-01-29 15:19:20 +00:00
parent 9474594fde
commit 14261143e0
14 changed files with 1843 additions and 0 deletions

View File

@ -17,6 +17,11 @@ v2pro/ - Architectural files for the Xilinx Virtex-II PRO device with
coldfire/ - Architectural files for Motorola Coldfire 5272 CPU running
under Nucleus OS. Supports DMA and ISRs in ethernet driver.
ti_c6711/ - Architectural files for TI TMS320C6711 DSP running under uC/OS-II.
Supports lwIP Raw API only.
It's done with an 10/100M ethernet daughtercard.
[more info at https://sourceforge.net/projects/ucos-lwip-c6x/]
Each subdirectory (may) also include:

13
ports/ti_c6711/FILES Normal file
View File

@ -0,0 +1,13 @@
This directory contains architecture and compiler specific stuff for porting lwIP
to the TI TMS320C6711 DSP. It's done on the official C6711 DSK board, in CCS v2.10.
The sequential API has not been ported; its functions are empties. If someone is
interested in adding a sequential API, please contact the author (see below).
The ethernet connection was based on an daughtercard design by the author.
Schematic files can be found as part of project "ucos-lwip-c6x" on SourceForge.net
The daughtercard is NE2000 compliant. And the driver supports interrupts.
Zeng, Ming
<ming@zming.net>

View File

@ -0,0 +1,63 @@
[Note]:
Special options setting of lwIP in this project (for using it with uC/OS-II on TI C6000 DSP)
*******************************************************************************************
This port was for project ucos-lwip-c6x (http://gro.clinux.org/projects/ucos-lwip-c6x/).
For the moment we were writing this note, lwIP v1.1.0 was used in this project.
This note was written in Jan.22 2005 by zengming99@mails.tsinghua.edu.cn.
*******************************************************************************************
Usually, options of lwIP can be set in file "lwipopts.h".
It was included by "opt.h", amd all options would be set as default value in "opt.h"
if they were not defined in "lwipopts.h".
Each project should have its own "lwiports.h", and keep "opt.h" as it was.
In this project, for making lwIP work with uC/OS-II on a 32bits TI DSP,
following options should be set:
------------------------------------------------------------------------------------
1. Define symbol "LWIP_PROVIDE_ERRNO" in compiler of CodeComposerStudio
2. #define MEM_ALIGNMENT 4 (in "lwipopts.h" )
#define ETH_PAD_SIZE 2 (in "lwipopts.h" )
For the struct align problem on 32bits DSP.
3. #define ARP_QUEUEING 0 (in "lwipopts.h")
ARP_QUEUEING has a bug in lwIP v1.0.0 with TCP
4. #define LWIP_TASK_MAX 5 (in "sys_arch.h" )
#define LWIP_START_PRIO 5 (in "sys_arch.h" )
#define TCPIP_THREAD_PRIO 5 (in "lwipopts.h" )
That is, 5 lwIP threads were allowed, and default TCPIP_THREAD used priority 5.
So, user defined lwIP thread should have its priority between 6 ~ 9.
5. #define SYS_LIGHTWEIGHT_PROT 1 (in "lwipopts.h" )
#define SYS_ARCH_DECL_PROTECT(lev) (in "sys_arch.h" )
#define SYS_ARCH_PROTECT(lev) OS_ENTER_CRITICAL() (in "sys_arch.h" )
#define SYS_ARCH_UNPROTECT(lev) OS_EXIT_CRITICAL() (in "sys_arch.h" )
These were very important when ethernet driver used intrrupt to check packet
and pBuf function was called in ISR. Or else, uC/OS-II would run away.
A much better and clean method is to set up a thread for the driver, in ISR
just check packet and post MailBox to the thread.
Zeng, Ming
2005-01-18

View File

@ -0,0 +1,63 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: cc.h,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
#ifndef __CC_H__
#define __CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned int u32_t;
typedef signed int s32_t;
typedef u32_t mem_ptr_t;
#define BYTE_ORDER LITTLE_ENDIAN
#define PACK_STRUCT_FIELD(x) x//; #pragma STRUCT_ALIGN(x,1)
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
#ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
#endif
#ifndef LWIP_PLATFORM_ASSERT
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
#endif
#endif /* __CC_H__ */

View File

@ -0,0 +1,44 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: init.h,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
#ifndef __ARCH_INIT_H__
#define __ARCH_INIT_H__
#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg)
#endif /* __ARCH_INIT_H__ */

View File

@ -0,0 +1,45 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: lib.h,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
#ifndef __LIB_H__
#define __LIB_H__
#include "arch/cc.h"
u16_t htons(u16_t n);
u16_t ntohs(u16_t n);
u32_t htonl(u32_t n);
u32_t ntohl(u32_t n);
#endif /* __LIB_H__ */

View File

@ -0,0 +1,41 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: perf.h,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@ -0,0 +1,73 @@
/*
*********************************************************************************************************
* lwIP TCP/IP Stack
* port for uC/OS-II RTOS on TIC6711 DSK
*
* File : sys_arch.h
* By : ZengMing @ DEP,Tsinghua University,Beijing,China
* Reference: YangYe's source code for SkyEye project
*********************************************************************************************************
*/
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
#define LWIP_STK_SIZE 4096
#define LWIP_TASK_MAX 5 //max number of lwip tasks
#define LWIP_START_PRIO 5 //first prio of lwip tasks
//!!!! so priority of lwip tasks is from 5-9
#define SYS_MBOX_NULL (void*)0
#define SYS_SEM_NULL (void*)0
#define MAX_QUEUES 20
#define MAX_QUEUE_ENTRIES 20
typedef struct {
OS_EVENT* pQ;
void* pvQEntries[MAX_QUEUE_ENTRIES];
} TQ_DESCR, *PQ_DESCR;
typedef OS_EVENT* sys_sem_t;
typedef PQ_DESCR sys_mbox_t;//the structure defined above
typedef INT8U sys_thread_t;
/* Critical Region Protection */
/* These functions must be implemented in the sys_arch.c file.
In some implementations they can provide a more light-weight protection
mechanism than using semaphores. Otherwise semaphores can be used for
implementation */
/** SYS_ARCH_DECL_PROTECT
* declare a protection variable. This macro will default to defining a variable of
* type sys_prot_t. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h.
*/
#define SYS_ARCH_DECL_PROTECT(lev)
/** SYS_ARCH_PROTECT
* Perform a "fast" protect. This could be implemented by
* disabling interrupts for an embedded system or by using a semaphore or
* mutex. The implementation should allow calling SYS_ARCH_PROTECT when
* already protected. The old protection level is returned in the variable
* "lev". This macro will default to calling the sys_arch_protect() function
* which should be implemented in sys_arch.c. If a particular port needs a
* different implementation, then this macro may be defined in sys_arch.h
*/
#define SYS_ARCH_PROTECT(lev) OS_ENTER_CRITICAL()
/** SYS_ARCH_UNPROTECT
* Perform a "fast" set of the protection level to "lev". This could be
* implemented by setting the interrupt level to "lev" within the MACRO or by
* using a semaphore or mutex. This macro will default to calling the
* sys_arch_unprotect() function which should be implemented in
* sys_arch.c. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h
*/
#define SYS_ARCH_UNPROTECT(lev) OS_EXIT_CRITICAL()
#endif

View File

@ -0,0 +1,140 @@
/*
*********************************************************************************************************
* lwIP TCP/IP Stack
* port for uC/OS-II RTOS on TIC6711 DSK
*
* File : tcp_ip.c
* By : ZengMing @ DEP,Tsinghua University,Beijing,China
* Reference: YangYe's source code for SkyEye project
*********************************************************************************************************
*/
#ifndef _NE2K_H_
#define _NE2K_H_
#include "lwip/netif.h"
static err_t ne2k_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);
static void ne2k_input(struct netif *netif);
err_t ne2k_init(struct netif *netif);
#define MIN_PACKET_SIZE 60 /* smallest legal size packet, no fcs */
#define MAX_PACKET_SIZE 1514 /* largest legal size packet, no fcs */
/*----------------------------------------
* Register header for NE2000 chip
*----------------------------------------*/
#define Base_ADDR 0xA0000200 ///CE2 space of DSK is 0xA0000000
// and ethernet chip is at 0x200 by default
// actual address on DSK
#define EN_CMD *(unsigned char *)(Base_ADDR+0x00) /* The command register (for all pages) */
#define EN_DATA *(unsigned short *)(Base_ADDR+0x10) /*by ming (change to 16bit) Remote DMA Port10~17h (for all pages)*/
#define EN_RESET *(unsigned char *)(Base_ADDR+0x1F) /* Reset Port 1fh(for all pages) */
/* Page 0 register offsets */
#define EN0_STARTPG *(unsigned char *)(Base_ADDR+0x01) /* WR Starting page of ring buffer */
#define EN0_STOPPG *(unsigned char *)(Base_ADDR+0x02) /* WR Ending page +1 of ring buffer */
#define EN0_BOUNDARY *(unsigned char *)(Base_ADDR+0x03) /* RD/WR Boundary page of ring buffer */
#define EN0_TSR *(unsigned char *)(Base_ADDR+0x04) /* RD Transmit status reg */
#define EN0_TPSR *(unsigned char *)(Base_ADDR+0x04) /* WR Transmit starting page */
#define EN0_NCR *(unsigned char *)(Base_ADDR+0x05) /* RD Number of collision reg */
#define EN0_TCNTLO *(unsigned char *)(Base_ADDR+0x05) /* WR Low byte of tx byte count */
#define EN0_CRP *(unsigned char *)(Base_ADDR+0x06) /* Current Page Register */
#define EN0_TCNTHI *(unsigned char *)(Base_ADDR+0x06) /* WR High byte of tx byte count */
#define EN0_ISR *(unsigned char *)(Base_ADDR+0x07) /* RD/WR Interrupt status reg */
#define EN0_CRDALO *(unsigned char *)(Base_ADDR+0x08) /* RD low byte of current remote dma add*/
#define EN0_RSARLO *(unsigned char *)(Base_ADDR+0x08) /* WR Remote start address reg 0 */
#define EN0_CRDAHI *(unsigned char *)(Base_ADDR+0x09) /* RD high byte, current remote dma add.*/
#define EN0_RSARHI *(unsigned char *)(Base_ADDR+0x09) /* WR Remote start address reg 1 */
#define EN0_RCNTLO *(unsigned char *)(Base_ADDR+0x0A) /* WR Remote byte count reg 0 */
#define EN0_RCNTHI *(unsigned char *)(Base_ADDR+0x0B) /* WR Remote byte count reg 1 */
#define EN0_RSR *(unsigned char *)(Base_ADDR+0x0C) /* RD RX status reg */
#define EN0_RXCR *(unsigned char *)(Base_ADDR+0x0C) /* WR RX configuration reg */
#define EN0_TXCR *(unsigned char *)(Base_ADDR+0x0D) /* WR TX configuration reg */
#define EN0_DCFG *(unsigned char *)(Base_ADDR+0x0E) /* WR Data configuration reg */
#define EN0_IMR *(unsigned char *)(Base_ADDR+0x0F) /* WR Interrupt mask reg */
/* Page 1 register offsets */
#define EN1_PAR0 *(unsigned char *)(Base_ADDR+0x01) /* RD/WR This board's physical ethernet addr */
#define EN1_PAR1 *(unsigned char *)(Base_ADDR+0x02)
#define EN1_PAR2 *(unsigned char *)(Base_ADDR+0x03)
#define EN1_PAR3 *(unsigned char *)(Base_ADDR+0x04)
#define EN1_PAR4 *(unsigned char *)(Base_ADDR+0x05)
#define EN1_PAR5 *(unsigned char *)(Base_ADDR+0x06)
#define EN1_CURR *(unsigned char *)(Base_ADDR+0x07) /* RD/WR current page reg */
#define EN1_CURPAG EN1_CURR
#define EN1_MAR0 *(unsigned char *)(Base_ADDR+0x08) /* RD/WR Multicast filter mask array (8 bytes) */
#define EN1_MAR1 *(unsigned char *)(Base_ADDR+0x09)
#define EN1_MAR2 *(unsigned char *)(Base_ADDR+0x0A)
#define EN1_MAR3 *(unsigned char *)(Base_ADDR+0x0B)
#define EN1_MAR4 *(unsigned char *)(Base_ADDR+0x0C)
#define EN1_MAR5 *(unsigned char *)(Base_ADDR+0x0D)
#define EN1_MAR6 *(unsigned char *)(Base_ADDR+0x0E)
#define EN1_MAR7 *(unsigned char *)(Base_ADDR+0x0F)
/* Command Values at EN_CMD */
#define EN_STOP 0x01 /* Stop and reset the chip */
#define EN_START 0x02 /* Start the chip, clear reset */
#define EN_TRANS 0x04 /* Transmit a frame */
#define EN_RREAD 0x08 /* Remote read */
#define EN_RWRITE 0x10 /* Remote write */
#define EN_NODMA 0x20 /* Remote DMA */
#define EN_PAGE0 0x00 /* Select page chip registers */
#define EN_PAGE1 0x40 /* using the two high-order bits */
// Values for Ring-Buffer setting
#define TX_PAGES 6
#define NE_START_PG 0x40 /* First page of TX buffer */
#define TX_START_PG NE_START_PG //0x40
#define NE_STOP_PG 0x80 /* Last page + 1 of RX Ring */
#define RX_STOP_PG NE_STOP_PG //0x80
#define RX_START_PG NE_START_PG + TX_PAGES //0x46
#define RX_CURR_PG RX_START_PG + 1 //0x47
/* Bits in EN0_ISR - Interrupt status register (RD WR) */
#define ENISR_RX 0x01 /* Receiver, no error */
#define ENISR_TX 0x02 /* Transceiver, no error */
#define ENISR_RX_ERR 0x04 /* Receiver, with error */
//接收数据包出错。做重新设置BNRYCURR处理。
#define ENISR_TX_ERR 0x08 /* Transmitter, with error */
//由于冲突次数过多,发送出错。做重发处理
#define ENISR_OVER 0x10 /* Receiver overwrote the ring */
/* Gap area of receiver ring buffer was disappeared */
//网卡内存溢出。做软件重启网卡处理。见手册。
#define ENISR_COUNTERS 0x20 /* Counters need emptying */
/* MSB of network tally counter became 1 */
//出错计数器中断屏蔽掉屏蔽用IMR寄存器
#define ENISR_RDC 0x40 /* remote dma complete */
//屏蔽掉。轮询等待DMA结束。
#define ENISR_RESET 0x80 /* Reset completed */
//网卡Reset屏蔽掉。
#define ENISR_ALL 0x3f /* 3f Interrupts we will enable */
/* RST RDC CNT OVW TXE RXE PTX PRX */
/* Bits in EN0_RXCR - RX configuration reg */
//#define ENRXCR_RXCONFIG 0x04 /* EN0_RXCR: broadcasts,no multicast,errors */
#define ENRXCR_RXCONFIG 0x00 /* EN0_RXCR: only unicast */
#define ENRXCR_CRC 0x01 /* Save error packets(admit) */
#define ENRXCR_RUNT 0x02 /* Accept runt pckt(below 64bytes) */
#define ENRXCR_BCST 0x04 /* Accept broadcasts when 1 */
#define ENRXCR_MULTI 0x08 /* Multicast (if pass filter) when 0 */
#define ENRXCR_PROMP 0x10 /* Promiscuous physical addresses when 1*/
/* when 0,accept assigned PAR0~5 address */
#define ENRXCR_MON 0x20 /* Monitor mode (no packets rcvd) */
/* Bits in EN0_TXCR - TX configuration reg */
#define ENTXCR_TXCONFIG 0x00 /* Normal transmit mode */
#define ENTXCR_CRC 0x01 /* inhibit CRC,do not append crc when 1 */
#define ENTXCR_LOOP 0x02 /* set internal loopback mode ? */
#define ENTXCR_LB01 0x06 /* encoded loopback control ? */
#define ENTXCR_ATD 0x08 /* auto tx disable */
/* when 1, if specified multicast packet was received, disable transmit */
#define ENTXCR_OFST 0x10 /* collision offset enable */
/* selection of collision algorithm. When 0, gererally back-off algorithm select */
#endif /* _NE2K_H_ */

74
ports/ti_c6711/lib_arch.c Normal file
View File

@ -0,0 +1,74 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: lib_arch.c,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
/* These are generic implementations of various library functions used
* throughout the lwIP code. When porting, those should be optimized
* for the particular processor architecture, preferably coded in
* assembler.
*/
//yangye 2003-1-22
#include "lwip/arch.h"
/*u16_t
htons(u16_t n)
{
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}
u16_t
ntohs(u16_t n)
{
return htons(n);
}
u32_t
htonl(u32_t n)
{
return ((n & 0xff) << 24) |
((n & 0xff00) << 8) |
((n & 0xff0000) >> 8) |
((n & 0xff000000) >> 24);
}
u32_t
ntohl(u32_t n)
{
return htonl(n);
}*/
/*-----------------------------------------------------------------------------------*/

View File

@ -0,0 +1,595 @@
/*
*********************************************************************************************************
* lwIP TCP/IP Stack
* port for uC/OS-II RTOS on TIC6711 DSK
*
* File : tcp_ip.c
* By : ZengMing @ DEP,Tsinghua University,Beijing,China
* Reference: YangYe's source code for SkyEye project
*********************************************************************************************************
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include "netif/etharp.h"
#include "netif/ne2kif.h"
/* Define those to better describe your network interface. */
#define IFNAME0 'e'
#define IFNAME1 't'
#define DELAY 0x590b2 //0.5s test by ming
#define DELAY_2S 0xbf000 //2s test
#define DELAY_MS 0x38F4 //20ms test
struct ne2k_if {
struct eth_addr *ethaddr; //MAC Address
};
struct netif *ne2k_if_netif;
static void low_level_init(struct netif * netif);
static err_t low_level_output(struct netif * netif,struct pbuf *p);
static struct pbuf * low_level_input(struct netif *netif);
/**
* Initialize the ne2k ethernet chip, resetting the interface and getting the ethernet
* address.
*/
static void low_level_init(struct netif * netif)
{
u16_t i;
struct ne2k_if *ne2k_if;
ne2k_if = netif->state;
// the meaning of "netif->state" can be defined in drivers, here for MAC address!
netif->hwaddr_len=6;
netif->mtu = 1500;
netif->flags = NETIF_FLAG_BROADCAST;
// ---------- start -------------
i = EN_RESET;//this instruction let NE2K chip soft reset
for (i=0;i<DELAY_MS;i++); //wait
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
EN0_DCFG = (u8_t) 0x01;
/* Clear the remote byte count registers. */
EN0_RCNTHI = (u8_t) 0x00; /* MSB remote byte count reg */
EN0_RCNTLO = (u8_t) 0x00; /* LSB remote byte count reg */
/* RX configuration reg Monitor mode (no packet receive) */
EN0_RXCR = (u8_t) ENRXCR_MON;
/* TX configuration reg set internal loopback mode */
EN0_TXCR = (u8_t) ENTXCR_LOOP;
EN0_TPSR = (u8_t) 0x40; //发送缓冲首地址 大小为6页刚好是1个最大包
//为0x40-0x46
EN0_STARTPG = (u8_t) 0x46 ; /* 接收缓冲 47。Starting page of ring buffer. First page of Rx ring buffer 46h*/
EN0_BOUNDARY = (u8_t) 0x46 ; /* Boundary page of ring buffer 0x46*/
EN0_STOPPG = (u8_t) 0x80 ; /* Ending page of ring buffer ,0x80*/
EN0_ISR = (u8_t) 0xff; /* clear the all flag bits in EN0_ISR */
EN0_IMR = (u8_t) 0x00; /* Disable all Interrupt */
EN_CMD = (u8_t) (EN_PAGE1 + EN_NODMA + EN_STOP);
EN1_CURR = (u8_t) 0x47;
/* RX_CURR_PG; 47 (keep curr=boundary+1 means no new packet) */
EN1_PAR0 = (u8_t)0x12;// MAC_addr.addr[0]; //自定义的mac地址
EN1_PAR1 = (u8_t)0x34;// MAC_addr.addr[1];
EN1_PAR2 = (u8_t)0x56;// MAC_addr.addr[2];
EN1_PAR3 = (u8_t)0x78;// MAC_addr.addr[3];
EN1_PAR4 = (u8_t)0x9a;// MAC_addr.addr[4];
EN1_PAR5 = (u8_t)0xe0;// MAC_addr.addr[5];
/* make up an address. */
ne2k_if->ethaddr->addr[0] = (u8_t) 0x12;//MAC_addr.addr[0];
ne2k_if->ethaddr->addr[1] = (u8_t) 0x34;//MAC_addr.addr[1];
ne2k_if->ethaddr->addr[2] = (u8_t) 0x56;//MAC_addr.addr[2];
ne2k_if->ethaddr->addr[3] = (u8_t) 0x78;//MAC_addr.addr[3];
ne2k_if->ethaddr->addr[4] = (u8_t) 0x9a;//MAC_addr.addr[4];
ne2k_if->ethaddr->addr[5] = (u8_t) 0xe0;//MAC_addr.addr[5];
/* Initialize the multicast list to reject-all.
If we enable multicast the higher levels can do the filtering.
<multicast filter mask array (8 bytes)> */
EN1_MAR0 = (u8_t) 0x00;
EN1_MAR1 = (u8_t) 0x00;
EN1_MAR2 = (u8_t) 0x00;
EN1_MAR3 = (u8_t) 0x00;
EN1_MAR4 = (u8_t) 0x00;
EN1_MAR5 = (u8_t) 0x00;
EN1_MAR6 = (u8_t) 0x00;
EN1_MAR7 = (u8_t) 0x00;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP); /* 00001010B: PS1 PS0 RD2 RD1 RD0 TXP STA STP */
EN0_IMR = (u8_t) (ENISR_OVER + ENISR_RX + ENISR_RX_ERR);
//(ENISR_OVER + ENISR_RX + ENISR_TX + ENISR_TX_ERR);
EN0_TXCR = (u8_t) 0xE0; //ENTXCR_TXCONFIG; //TCR
EN0_RXCR = (u8_t) 0xCC; //without Multicast //0xcc //RCR
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_START);
EN0_ISR = (u8_t) 0xff; // clear the all flag bits in EN0_ISR
ne2k_if_netif = 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_t low_level_output(struct netif * netif, struct pbuf *p)
{
struct pbuf *q;
u16_t padLength,packetLength,Count,loop,rd_tmp;
u8_t *buf,flag1=0 ;
/*
* Set up to transfer the packet contents to the NIC RAM.
*/
padLength = 0;
packetLength = p->tot_len - ETH_PAD_SIZE; //05 01 millin
if ((packetLength) < 64)
{
padLength = 64 - (packetLength);
packetLength = 64;
}
/* Wait for other transmit */
while ( EN_CMD & EN_TRANS );
/* We should already be in page 0, but to be safe... */
EN_CMD = (u8_t) (EN_PAGE0 + EN_START + EN_NODMA);
EN0_IMR = (u8_t) (ENISR_OVER);
//(ENISR_OVER + ENISR_TX + ENISR_TX_ERR);
// turn off RX int
EN0_ISR = (u8_t) ENISR_RDC; // clear the RDC bit
/* Now the normal output. */
EN0_RCNTLO = (u8_t) (packetLength & 0xff);
EN0_RCNTHI = (u8_t) ((packetLength >> 8) & 0xff);
EN0_RSARLO = (u8_t) ((TX_START_PG<<8) & 0xFF);
EN0_RSARHI = (u8_t) (TX_START_PG & 0xFF);
EN_CMD = (u8_t) (EN_RWRITE + EN_START + EN_PAGE0);
/*
* Write packet to ring buffers.
*/
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. */
Count = q->len;
buf = q->payload;
if (q == p){
buf += ETH_PAD_SIZE;
Count -= ETH_PAD_SIZE;//Pad in Eth_hdr struct
}
if ( (Count & 0x0001) ) flag1 = 1;
Count = Count>>1;
for (loop=0;loop < Count ;loop++){
rd_tmp = (*buf++) + ((*buf++) << 8 );
EN_DATA = (u16_t) rd_tmp;
}
if (flag1 == 1) *(unsigned char *)(Base_ADDR+0x10) = *buf++;
}
while(padLength-- > 0){
*(unsigned char *)(Base_ADDR+0x10) = (u8_t)0x00;
// Write padding for undersized packets
}
EN0_ISR = (u8_t) ENISR_RDC; // clear the RDC bit
/* Just send it, and does not check */
EN0_TCNTLO = (u8_t) (packetLength& 0xff);
EN0_TCNTHI = (u8_t) (packetLength>> 8);
EN0_TPSR = (u8_t) TX_START_PG;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_TRANS + EN_START);
EN0_IMR = (u8_t) (ENISR_OVER + ENISR_RX + ENISR_RX_ERR);
//(ENISR_OVER + ENISR_RX + ENISR_TX + ENISR_TX_ERR);
#if LINK_STATS
lwip_stats.link.xmit++;
#endif /* LINK_STATS */
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 netif *netif)
{
struct ne2k_if *ne2k_if = netif->state;
u16_t packetLength,len,Count,loop,rd_tmp;
u8_t PDHeader[4]; // Temp storage for ethernet headers//18
struct pbuf * p;
struct pbuf * q;
u8_t *payload,*buf,flag1=0;
u8_t curr,this_frame,next_frame;
EN_CMD = (u8_t) (EN_PAGE1 + EN_NODMA + EN_START);
curr = (u8_t) EN1_CURR;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_START);
this_frame = (u8_t) EN0_BOUNDARY + 1;//millin + 1
if (this_frame >= RX_STOP_PG)
this_frame = RX_START_PG;
EN0_RCNTLO = (u8_t) 4;
EN0_RCNTHI = (u8_t) 0;
EN0_RSARLO = (u8_t) 0; /* See controller manual , use send packet command */
EN0_RSARHI = (u8_t) this_frame; /* See controller manual , use send packet command */
EN_CMD = (u8_t) (EN_PAGE0 + EN_RREAD + EN_START);
//get the first 4 bytes from nic
Count = 2;
buf = PDHeader;
while(Count--) {
rd_tmp = EN_DATA ;
*buf++ = (u8_t)(rd_tmp & 0x00ff) ;
*buf++ = (u8_t)(rd_tmp >> 8) ;
}
EN0_ISR = (u8_t) ENISR_RDC; /* clear the RDC bit */
// Store real length, set len to packet length - header
packetLength = ((unsigned) PDHeader[2] | (PDHeader[3] << 8 ));
next_frame = (u8_t) (this_frame + 1 + (packetLength >> 8));
packetLength -= 4;
if ((PDHeader[1] != next_frame)
&& (PDHeader[1] != next_frame + 1)
&& (PDHeader[1] != next_frame - (RX_STOP_PG - RX_START_PG))
&& (PDHeader[1] != next_frame + 1 - (RX_STOP_PG - RX_START_PG)))
{
EN0_BOUNDARY = (u8_t) (curr - 1);
//puts("Bad frame!\n");
return NULL;
}
if (packetLength > MAX_PACKET_SIZE || packetLength < MIN_PACKET_SIZE)
{
next_frame = PDHeader[1];
EN0_BOUNDARY = (u8_t) (next_frame-1);
//printf("Bogus Packet Size \n");
return NULL;
}
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_START);
EN0_RCNTLO = (u8_t) (packetLength & 0xff);
EN0_RCNTHI = (u8_t) (packetLength >> 8);
EN0_RSARLO = (u8_t) 4; /* See controller manual , use send packet command */
EN0_RSARHI = (u8_t) this_frame; /* See controller manual , use send packet command */
EN_CMD = (u8_t) (EN_PAGE0 + EN_RREAD + EN_START);
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, packetLength+ETH_PAD_SIZE, PBUF_POOL); /* length of buf */
// change from PBUF_LINK
if(p != NULL) {
/* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */
for(q = p; q != NULL; q= q->next){
/* Read enough bytes to fill this pbuf in the chain. The
avaliable data in the pbuf is given by the q->len
variable. */
payload = q->payload;
len = q->len;
if (q == p){ // if first buf...
payload += ETH_PAD_SIZE;
len -= ETH_PAD_SIZE;//Pad in Eth_hdr struct
}
Count = len;
buf = payload;
if ( (Count & 0x0001) ) flag1 = 1;
Count = Count>>1;
for(loop=0;loop < Count;loop++) {
rd_tmp = EN_DATA ;
*buf++ = (u8_t)(rd_tmp & 0x00ff) ;
*buf++ = (u8_t)(rd_tmp >> 8) ;
}
if ( flag1==1 ) *buf++ = *(unsigned char *)(Base_ADDR+0x10) ;
#if LINK_STATS
lwip_stats.link.recv++;
#endif /* LINK_STATS */
}//for
} else { // p == NULL
/* no more PBUF resource, Discard packet in buffer. */
Count = packetLength;
if ( (Count & 0x0001) ) flag1 = 1; Count = Count>>1;
for(loop=0;loop < Count;loop++) rd_tmp = EN_DATA;
if ( flag1==1 ) rd_tmp = *(unsigned char *)(Base_ADDR+0x10);
#if LINK_STATS
lwip_stats.link.memerr++;
lwip_stats.link.drop++;
#endif /* LINK_STATS */
}
next_frame = PDHeader[1];
EN0_BOUNDARY = (u8_t) (next_frame-1);
EN0_ISR = (u8_t) ENISR_RDC;
return p;
}
/*
* ethernetif_output():
*
* This function is called by the TCP/IP stack when an IP packet
* should be sent. It calls the function called low_level_output() to
* do the actual transmission of the packet.
*
*/
static err_t
ne2k_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr)
{
/* resolve hardware address, then send (or queue) packet */
return etharp_output(netif, ipaddr, p);
}
/*
* ethernetif_input():
*
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface.
*
*/
static void
ne2k_input(struct netif *netif)
{
struct ne2k_if *ne2k_if;
struct eth_hdr *ethhdr;
struct pbuf *p;
ne2k_if = netif->state;
//p = low_level_input(ne2k_if);
/* move received packet into a new pbuf */
p = low_level_input(netif);
/* no packet could be read, silently ignore this */
if (p == NULL) return;
/* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload;
#if LINK_STATS
lwip_stats.link.recv++;
#endif /* LINK_STATS */
switch(htons(ethhdr->type)) {
/* IP packet? */
case ETHTYPE_IP:
/* update ARP table */
etharp_ip_input(netif, p);
/* skip Ethernet header */
pbuf_header(p, -(14+ETH_PAD_SIZE));
/* pass to network layer */
netif->input(p, netif);
break;
case ETHTYPE_ARP:
/* pass p to ARP module */
etharp_arp_input(netif, ne2k_if->ethaddr, p);
break;
default:
pbuf_free(p);
p = NULL;
break;
}
}
/*-----------------------------------------------------------------------------------*/
static void
arp_timer(void *arg)
{
etharp_tmr();
sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL);
}
/*
* ethernetif_init():
*
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
*/
err_t
ne2k_init(struct netif *netif)
{
struct ne2k_if *ne2k_if;
ne2k_if = mem_malloc(sizeof(struct ne2k_if));//MAC Address
if (ne2k_if == NULL)
{
LWIP_DEBUGF(NETIF_DEBUG,("ne2k_init: out of memory!\n"));
return ERR_MEM;
}
netif->state = ne2k_if;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
netif->output = ne2k_output;
netif->linkoutput = low_level_output;
ne2k_if->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
low_level_init(netif);
etharp_init();
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
void ne2k_rx_err(void)
{
u8_t curr;
EN_CMD = (u8_t) (EN_PAGE1 + EN_NODMA + EN_STOP);
curr = (u8_t) EN1_CURR;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
EN0_BOUNDARY = (u8_t) curr-1;
}
/*-----------------------------------------------------------------------------------*/
void ne2k_rx(void)
{
u8_t curr,bnry;
EN_CMD = (u8_t) (EN_PAGE1 + EN_NODMA + EN_STOP);
curr = (u8_t) EN1_CURR;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
bnry = (u8_t) EN0_BOUNDARY + 1;//millin + 1
if (bnry >= RX_STOP_PG)
bnry = RX_START_PG;
while(curr != bnry){
ne2k_input(ne2k_if_netif);
EN_CMD = (u8_t) (EN_PAGE1 + EN_NODMA + EN_STOP);
curr = (u8_t) EN1_CURR;
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
bnry = (u8_t) EN0_BOUNDARY + 1; //millin +1
}
}
/* -----------------------------
* void ne2k_isr(void)
* can be int 4 5 6 or 7
* ----------------------------*/
void
ne2k_isr(void)
{
DSP_C6x_Save();
OSIntEnter();
if (OSIntNesting == 1)
{
OSTCBCur->OSTCBStkPtr = (OS_STK *) DSP_C6x_GetCurrentSP();
}
/* You can enable Interrupt again here,
if want to use nested interrupt..... */
//------------------------------------------------------------
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
//outb(CMD_PAGE0 | CMD_NODMA | CMD_STOP,NE_CR);
EN0_IMR = (u8_t) 0x00;//close
// ram overflow interrupt
if (EN0_ISR & ENISR_OVER) {
EN0_ISR = (u8_t) ENISR_OVER; // clear interrupt
}
// error transfer interrupt ,NIC abort tx due to excessive collisions
if (EN0_ISR & ENISR_TX_ERR) {
EN0_ISR = (u8_t) ENISR_TX_ERR; // clear interrupt
//temporarily do nothing
}
// Rx error , reset BNRY pointer to CURR (use SEND PACKET mode)
if (EN0_ISR & ENISR_RX_ERR) {
EN0_ISR = (u8_t) ENISR_RX_ERR; // clear interrupt
ne2k_rx_err();
}
//got packet with no errors
if (EN0_ISR & ENISR_RX) {
EN0_ISR = (u8_t) ENISR_RX;
ne2k_rx();
}
//Transfer complelte, do nothing here
if (EN0_ISR & ENISR_TX){
EN0_ISR = (u8_t) ENISR_TX; // clear interrupt
}
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_STOP);
EN0_ISR = (u8_t) 0xff; // clear ISR
EN0_IMR = (u8_t) (ENISR_OVER + ENISR_RX + ENISR_RX_ERR);
//(ENISR_OVER + ENISR_RX + ENISR_TX + ENISR_TX_ERR);
//open nic for next packet
EN_CMD = (u8_t) (EN_PAGE0 + EN_NODMA + EN_START);
if (led_stat & 0x04) {LED3_on;}
else {LED3_off;}
//--------------------------------------------------------
OSIntExit();
DSP_C6x_Resume();
asm (" nop 5"); //important!
// this can avoid a stack error when compile with the optimization!
}

153
ports/ti_c6711/proj/lwIP.c Normal file
View File

@ -0,0 +1,153 @@
/*
*********************************************************************************************************
* lwIP TCP/IP Stack
* port for uC/OS-II RTOS on TIC6711 DSK
*
* File : tcp_ip.c
* By : ZengMing @ DEP,Tsinghua University,Beijing,China
*********************************************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "..\uCOS-II\TI_C6711\DSP_C6x_Vectors\DSP_C6x_Vectors.H"
// -- Architecture Files --
#include "..\lwIP\arch\TI_C6711\sys_arch.c"
#include "..\lwIP\arch\TI_C6711\netif\ne2kif.c"
// -- Generic network interface --
#include "..\lwIP\src\netif\loopif.c"
#include "..\lwIP\src\netif\etharp.c"
// -- common file
#include "..\lwIP\src\core\mem.c"
#include "..\lwIP\src\core\memp.c"
#include "..\lwIP\src\core\netif.c"
#include "..\lwIP\src\core\pbuf.c"
#include "..\lwIP\src\core\stats.c"
#include "..\lwIP\src\core\sys.c"
#include "..\lwIP\src\core\tcp.c"
#include "..\lwIP\src\core\tcp_in.c"
#include "..\lwIP\src\core\tcp_out.c"
#include "..\lwIP\src\core\udp.c"
#include "..\lwIP\src\core\raw.c"
// -- target ipv4 --
#include "..\lwIP\src\core\ipv4\icmp.c"
#include "..\lwIP\src\core\ipv4\ip.c"
#include "..\lwIP\src\core\inet.c"
#include "..\lwIP\src\core\ipv4\ip_addr.c"
#include "..\lwIP\src\core\ipv4\ip_frag.c"
// -- sequential and socket APIs --
#include "..\lwIP\src\api\api_lib.c"
#include "..\lwIP\src\api\api_msg.c"
#include "..\lwIP\src\api\tcpip.c"
#include "..\lwIP\src\api\err.c"
#include "..\lwIP\src\api\sockets.c"
// sample task code (tcp-echo|telnet & http demo)
#include "sample_http.c"
struct netif ne2kif_if;
//struct netif loop_if;
void ethernet_hardreset(void); //These reset codes are built for C6711 DSP
void tcpip_init_done_ok(void * arg);
void Task_lwip_init(void * pParam)
{
struct ip_addr ipaddr, netmask, gw;
sys_sem_t sem;
ethernet_hardreset();//hard reset of EthernetDaughterCard
#if LWIP_STATS
stats_init();
#endif
// initial lwIP stack
sys_init();
mem_init();
memp_init();
pbuf_init();
netif_init();
printf("TCP/IP initializing...\n");
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done_ok, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
//add loop interface //set local loop-interface 127.0.0.1
/*
IP4_ADDR(&gw, 127,0,0,1);
IP4_ADDR(&ipaddr, 127,0,0,1);
IP4_ADDR(&netmask, 255,0,0,0);
netif_add(&loop_if, &ipaddr, &netmask, &gw, NULL, loopif_init,
tcpip_input);*/
//add ne2k interface
IP4_ADDR(&gw, 166,111,32,1);
IP4_ADDR(&ipaddr, 166,111,33,120);
IP4_ADDR(&netmask, 255,255,252,0);
netif_add(&ne2kif_if, &ipaddr, &netmask, &gw, NULL, ne2k_init, tcpip_input);
netif_set_default(&ne2kif_if);
netif_set_up(&ne2kif_if); // new step from lwip 1.0.0
printf("Applications started.\n");
//------------------------------------------------------------
//All thread(task) of lwIP must have their PRI between 5 and 9.
// http thread, a web page can be browsed
sys_thread_new(httpd_init, (void*)"httpd",6);
//------------------------------------------------------------
printf("lwIP threads created!\n");
DSP_C6x_TimerInit(); // Timer interrupt enabled
DSP_C6x_Int4Init(); // Int4(Ethernet Chip int) enabled
/* Block for ever. */
sem = sys_sem_new(0);
sys_sem_wait(sem);
printf(" never goes here, should not appear!\n");
}
//---------------------------------------------------------
void tcpip_init_done_ok(void * arg)
{
sys_sem_t *sem;
sem = arg;
sys_sem_signal(*sem);
}
/*-----------------------------------------------------------*/
/* This function do the hard reset of EthernetDaughterCard *
* through the DaughterBoardControl0 signal in DB-IF */
/*-----------------------------------------------------------*/
void ethernet_hardreset(void) //These reset codes are built for C6711 DSK
{
u32_t i;
OS_ENTER_CRITICAL();
//SET LED1 ON AND /RST pin Low
*(unsigned char *)0x90080003 = 0x06;
for (i=0;i<DELAY;i++);
//SET LED2 ON AND /RST pin High _|-|_
*(unsigned char *)0x90080003 = 0xfd;
for (i=0;i<DELAY;i++);
//SET LED3 ON AND /RST pin Low
*(unsigned char *)0x90080003 = 0x03;
for (i=0;i<DELAY_2S;i++);
OS_EXIT_CRITICAL();
}

View File

@ -0,0 +1,316 @@
/*
* 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 part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: lwipopts.h,v 1.1 2005/01/29 15:19:21 ming Exp $
*/
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
// for TI C6000 DSP target, struct align....
//------------------------------------------------
#define ETH_PAD_SIZE 2
//------------------------------------------------
//------------------------------------------------
/* Critical Region Protection */
//------------------------------------------------
/** SYS_LIGHTWEIGHT_PROT
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
* for certain critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT 1 //millin
//----------------------------------------------------------------------
/* ---------- Memory options ---------- */
//----------------------------------------------------------------------
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
byte alignment -> define MEM_ALIGNMENT to 2. */
#define MEM_ALIGNMENT 4
/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */
#define MEM_SIZE 512000//1600
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
sends a lot of data out of ROM (or other static memory), this
should be set high. */
#define MEMP_NUM_PBUF 64//16
/* Number of raw connection PCBs */
#define MEMP_NUM_RAW_PCB 4
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
#define MEMP_NUM_UDP_PCB 6//4
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
connections. */
#define MEMP_NUM_TCP_PCB 10//5
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 8//6///8
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
segments. */
#define MEMP_NUM_TCP_SEG 16//8//16
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
timeouts. */
#define MEMP_NUM_SYS_TIMEOUT 3
//----------------------------------------------------------------------
/* The following four are used only with the sequential API and can be
set to 0 if the application only will use the raw API. */
//----------------------------------------------------------------------
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
#define MEMP_NUM_NETBUF 64//2
/* MEMP_NUM_NETCONN: the number of struct netconns. */
#define MEMP_NUM_NETCONN 64//4
/* MEMP_NUM_APIMSG: the number of struct api_msg, used for
communication between the TCP/IP stack and the sequential
programs. */
#define MEMP_NUM_API_MSG 64//8
/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used
for sequential API communication and incoming packets. Used in
src/api/tcpip.c. */
#define MEMP_NUM_TCPIP_MSG 64//16//8
//----------------------------------------------------------------------
/* ---------- Pbuf options ---------- */
//----------------------------------------------------------------------
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE 128//16 must>6
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#define PBUF_POOL_BUFSIZE 2048//128
/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
link level header. */
#define PBUF_LINK_HLEN 14//16//14
//----------------------------------------------------------------------
/* ---------- ARP options ---------- */
//----------------------------------------------------------------------
/** Number of active hardware address, IP address pairs cached */
#define ARP_TABLE_SIZE 20//10
/**
* If enabled, outgoing packets are queued during hardware address
* resolution.
*
* This feature has not stabilized yet. Single-packet queueing is
* believed to be stable, multi-packet queueing is believed to
* clash with the TCP segment queueing.
*
* As multi-packet-queueing is currently disabled, enabling this
* _should_ work, but we need your testing feedback on lwip-users.
*
*/
#define ARP_QUEUEING 0
// if TCP was used, must disable this in v1.1.0 //millin
//----------------------------------------------------------------------
/* ---------- IP options ---------- */
//----------------------------------------------------------------------
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
IP packets across network interfaces. If you are going to run lwIP
on a device with only one network interface, define this to 0. */
#define IP_FORWARD 0
/* If defined to 1, IP options are allowed (but not parsed). If
defined to 0, all packets with IP options are dropped. */
#define IP_OPTIONS 0
/** IP reassembly and segmentation. Even if they both deal with IP
* fragments, note that these are orthogonal, one dealing with incoming
* packets, the other with outgoing packets
*/
/** Reassemble incoming fragmented IP packets */
#define IP_REASSEMBLY 1
/** Fragment outgoing IP packets if their size exceeds MTU */
#define IP_FRAG 1
//----------------------------------------------------------------------
/* ---------- ICMP options ---------- */
//----------------------------------------------------------------------
#define ICMP_TTL 255
//----------------------------------------------------------------------
/* ---------- RAW options ---------- */
//----------------------------------------------------------------------
#define LWIP_RAW 1
#define RAW_TTL 255
//----------------------------------------------------------------------
/* ---------- DHCP options ---------- */
//----------------------------------------------------------------------
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
turning this on does currently not work. */
#define LWIP_DHCP 0
/* 1 if you want to do an ARP check on the offered address
(recommended). */
#define DHCP_DOES_ARP_CHECK 1
//----------------------------------------------------------------------
/* ---------- UDP options ---------- */
//----------------------------------------------------------------------
#define LWIP_UDP 1
#define UDP_TTL 255
//----------------------------------------------------------------------
/* ---------- TCP options ---------- */
//----------------------------------------------------------------------
#define LWIP_TCP 1
#define TCP_TTL 255
/* TCP receive window. */
#define TCP_WND 8192//1024//2048
/* Maximum number of retransmissions of data segments. */
#define TCP_MAXRTX 12
/* Maximum number of retransmissions of SYN segments. */
#define TCP_SYNMAXRTX 4//6
/* Controls if TCP should queue segments that arrive out of
order. Define to 0 if your device is low on memory. */
#define TCP_QUEUE_OOSEQ 1
/* TCP Maximum segment size. */
#define TCP_MSS 1024//128
/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF 8192//256
/* TCP sender buffer space (pbufs). This must be at least = 2 *
TCP_SND_BUF/TCP_MSS for things to work. */
#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS
/* TCP writable space (bytes). This must be less than or equal
to TCP_SND_BUF. It is the amount of space which must be
available in the tcp snd_buf for select to return writable */
#define TCP_SNDLOWAT TCP_SND_BUF/2
//----------------------------------------------------------------------
/* ---------- Other options ---------- */
//----------------------------------------------------------------------
/* Support loop interface (127.0.0.1) */
#define LWIP_HAVE_LOOPIF 0
//#define LWIP_EVENT_API 1//
#define LWIP_CALLBACK_API 1// only one of these two
#define LWIP_COMPAT_SOCKETS 1
// for uC/OS-II port on TI DSP
#define TCPIP_THREAD_PRIO 5 //millin
//#define SLIPIF_THREAD_PRIO 1
//#define PPP_THREAD_PRIO 1
//#define DEFAULT_THREAD_PRIO 1
//----------------------------------------------------------------------
/* ---------- Socket Options ---------- */
//----------------------------------------------------------------------
/* Enable SO_REUSEADDR and SO_REUSEPORT options */
#define SO_REUSE 0
//----------------------------------------------------------------------
/* ---------- Statistics options ---------- */
//----------------------------------------------------------------------
#define STATS 0
#if LWIP_STATS
#define LWIP_STATS_DISPLAY 1
#define LINK_STATS 1
#define IP_STATS 1
#define IPFRAG_STATS 1
#define ICMP_STATS 1
#define UDP_STATS 1
#define TCP_STATS 1
#define MEM_STATS 1
#define MEMP_STATS 1
#define PBUF_STATS 1
#define SYS_STATS 1
#define RAW_STATS 1
#endif /* STATS */
//----------------------------------------------------------------------
/* ------------if you need to do debug-------------*/
//----------------------------------------------------------------------
/*
define LWIP_DEBUG in compiler and following...
*/
#define DBG_MIN_LEVEL DBG_LEVEL_SERIOUS
//DBG_LEVEL_WARNING DBG_LEVEL_SERIOUS DBG_LEVEL_SEVERE
#define DBG_TYPES_ON 0//DBG_TRACE | DBG_STATE |DBG_FRESH | DBG_HALT
/*
Then, define debug class in opt.h
* --------------------------------------------------*/
#define ETHARP_DEBUG DBG_OFF
#define NETIF_DEBUG DBG_OFF
#define PBUF_DEBUG DBG_OFF
#define API_LIB_DEBUG DBG_OFF
#define API_MSG_DEBUG DBG_OFF
#define SOCKETS_DEBUG DBG_OFF
#define ICMP_DEBUG DBG_OFF
#define INET_DEBUG DBG_OFF
#define IP_DEBUG DBG_OFF
#define IP_REASS_DEBUG DBG_OFF
#define RAW_DEBUG DBG_OFF
#define MEM_DEBUG DBG_OFF
#define MEMP_DEBUG DBG_OFF
#define SYS_DEBUG DBG_OFF
#define TCP_DEBUG DBG_OFF
#define TCP_INPUT_DEBUG DBG_OFF
#define TCP_FR_DEBUG DBG_OFF
#define TCP_RTO_DEBUG DBG_OFF
#define TCP_REXMIT_DEBUG DBG_OFF
#define TCP_CWND_DEBUG DBG_OFF
#define TCP_WND_DEBUG DBG_OFF
#define TCP_OUTPUT_DEBUG DBG_OFF
#define TCP_RST_DEBUG DBG_OFF
#define TCP_QLEN_DEBUG DBG_OFF
#define UDP_DEBUG DBG_OFF
#define TCPIP_DEBUG DBG_OFF
#define PPP_DEBUG DBG_OFF
#define SLIP_DEBUG DBG_OFF
#define DHCP_DEBUG DBG_OFF
#endif /* __LWIPOPTS_H__ */

218
ports/ti_c6711/sys_arch.c Normal file
View File

@ -0,0 +1,218 @@
/*
*********************************************************************************************************
* lwIP TCP/IP Stack
* port for uC/OS-II RTOS on TIC6711 DSK
*
* File : sys_arch.c
* By : ZengMing @ DEP,Tsinghua University,Beijing,China
* Reference: YangYe's source code for SkyEye project
*********************************************************************************************************
*/
//#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "arch/sys_arch.h"
static OS_MEM *pQueueMem;
const void * const pvNullPointer;
static char pcQueueMemoryPool[MAX_QUEUES * sizeof(TQ_DESCR) ];
struct sys_timeouts lwip_timeouts[LWIP_TASK_MAX];
struct sys_timeouts null_timeouts;
OS_STK LWIP_TASK_STK[LWIP_TASK_MAX][LWIP_STK_SIZE];
/*-----------------------------------------------------------------------------------*/
/* This func should be called first in lwip task!
* ------------------------------------------------- */
void sys_init(void)
{
u8_t i;
u8_t ucErr;
//init mem used by sys_mbox_t //use ucosII functions
pQueueMem = OSMemCreate( (void*)pcQueueMemoryPool, MAX_QUEUES, sizeof(TQ_DESCR), &ucErr );
//init lwip_timeouts for every lwip task
for(i=0;i<LWIP_TASK_MAX;i++){
lwip_timeouts[i].next = NULL;
}
}
/*-----------------------------------------------------------------------------------*/
sys_sem_t sys_sem_new(u8_t count)
{
sys_sem_t pSem;
pSem = OSSemCreate((u16_t)count );
return pSem;
}
/*-----------------------------------------------------------------------------------*/
void sys_sem_free(sys_sem_t sem)
{
u8_t ucErr;
(void)OSSemDel((OS_EVENT *)sem, OS_DEL_NO_PEND, &ucErr );
}
/*-----------------------------------------------------------------------------------*/
void sys_sem_signal(sys_sem_t sem)
{
OSSemPost((OS_EVENT *)sem );
}
/*-----------------------------------------------------------------------------------*/
u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
{
u8_t err;
u32_t ucos_timeout;
ucos_timeout = 0;
if(timeout != 0){
ucos_timeout = (timeout * OS_TICKS_PER_SEC) / 1000;
if(ucos_timeout < 1)
ucos_timeout = 1;
else if(ucos_timeout > 65535) //ucOS only support u16_t pend
ucos_timeout = 65535;
}
OSSemPend ((OS_EVENT *)sem,(u16_t)ucos_timeout, (u8_t *)&err);
if(err == OS_TIMEOUT)
return 0; // only when timeout!
else
return 1;
}
/*-----------------------------------------------------------------------------------*/
sys_mbox_t sys_mbox_new(void)
{
u8_t ucErr;
PQ_DESCR pQDesc;
pQDesc = OSMemGet( pQueueMem, &ucErr );
if( ucErr == OS_NO_ERR ) {
pQDesc->pQ = OSQCreate( &(pQDesc->pvQEntries[0]), MAX_QUEUE_ENTRIES );
if( pQDesc->pQ != NULL ) {
return pQDesc;
}
}
return SYS_MBOX_NULL;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_free(sys_mbox_t mbox)
{
u8_t ucErr;
//clear OSQ EVENT
OSQFlush( mbox->pQ );
//del OSQ EVENT
(void)OSQDel( mbox->pQ, OS_DEL_NO_PEND, &ucErr);
//put mem back to mem queue
ucErr = OSMemPut( pQueueMem, mbox );
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_post(sys_mbox_t mbox, void *msg)
{
if( !msg )
msg = (void*)&pvNullPointer;
(void)OSQPost( mbox->pQ, msg);
}
/*-----------------------------------------------------------------------------------*/
u32_t
sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
{
u8_t ucErr;
u32_t ucos_timeout;
ucos_timeout = 0;
if(timeout != 0){
ucos_timeout = (timeout * OS_TICKS_PER_SEC)/1000;
if(ucos_timeout < 1)
ucos_timeout = 1;
else if(ucos_timeout > 65535) //ucOS only support u16_t timeout
ucos_timeout = 65535;
}
if(msg != NULL){
*msg = OSQPend( mbox->pQ, (u16_t)ucos_timeout, &ucErr );
}else{
//just discard return value if msg==NULL
OSQPend(mbox->pQ,(u16_t)ucos_timeout,&ucErr);
}
if( ucErr == OS_TIMEOUT ) {
timeout = 0;
} else {
if(*msg == (void*)&pvNullPointer )
*msg = NULL;
timeout = 1;
}
return timeout;
}
/*----------------------------------------------------------------------*/
struct
sys_timeouts * sys_arch_timeouts(void)
{
u8_t curr_prio;
s16_t offset;
OS_TCB curr_task_pcb;
null_timeouts.next = NULL;
OSTaskQuery(OS_PRIO_SELF,&curr_task_pcb);
curr_prio = curr_task_pcb.OSTCBPrio;
offset = curr_prio - LWIP_START_PRIO;
//not called by a lwip task ,return timeouts->NULL
if(offset < 0 || offset >= LWIP_TASK_MAX)
{
return &null_timeouts;
}
return &lwip_timeouts[offset];
}
/*------------------------------------------------------------------------*/
sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio)
{
if(prio - LWIP_START_PRIO < LWIP_TASK_MAX){
OSTaskCreate(thread, (void *)0x1111, &LWIP_TASK_STK[prio - LWIP_START_PRIO][LWIP_STK_SIZE-1], prio);
return prio;
} else {
printf(" lwip task prio out of range ! error! ");
return 0;
}
}