?? lwip.c
字號(hào):
/****************************************Copyright (c)****************************************************
**
** http://www.powermcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: LWIP.c
** Descriptions: None
**
**--------------------------------------------------------------------------------------------------------
** Created by: AVRman
** Created date: 2011-3-10
** Version: v1.0
** Descriptions: The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
*********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "lwip/memp.h"
#include "lwIP.h"
#include "lwIP/tcp.h"
#include "lwIP/udp.h"
#include "lwIP/tcpip.h"
#include "netif/etharp.h"
#include "lwIP/dhcp.h"
#include "ethernetif.h"
#include "arch/sys_arch.h"
#include <includes.h>
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Private variables ---------------------------------------------------------*/
struct netif _netif;
static uint32_t IPaddress = 0;
/* Global Rx Buffer data */
uint8_t __attribute__ ((aligned (4))) gRxBuf[EMAC_MAX_PACKET_SIZE];
uint8_t __attribute__ ((aligned (4))) gTxBuf[EMAC_MAX_PACKET_SIZE];
/* Private function prototypes -----------------------------------------------*/
static void list_if (void);
static void TcpipInitDone (void *arg);
static void USART_Configuration (void);
/*******************************************************************************
* Function Name : ENET_IRQHandler
* Description : Ethernet service routine handler
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void ENET_IRQHandler (void)
{
/* EMAC Ethernet Controller Interrupt function. */
uint32_t int_stat;
/* Get EMAC interrupt status */
while ((int_stat = (LPC_EMAC->IntStatus & LPC_EMAC->IntEnable)) != 0) {
/* Clear interrupt status */
LPC_EMAC->IntClear = int_stat;
/* scan interrupt status source */
/* ---------- receive overrun ------------*/
if((int_stat & EMAC_INT_RX_OVERRUN))
{
//RXOverrunCount++;
//printf("Rx overrun \r\n");
}
/*----------- receive error -------------*/
/* Note:
* The EMAC doesn't distinguish the frame type and frame length,
* so, e.g. when the IP(0x8000) or ARP(0x0806) packets are received,
* it compares the frame type with the max length and gives the
* "Range" error. In fact, this bit is not an error indication,
* but simply a statement by the chip regarding the status of
* the received frame
*/
if ((int_stat & EMAC_INT_RX_ERR))
{
if (EMAC_CheckReceiveDataStatus(EMAC_RINFO_RANGE_ERR) == RESET)
{
//RXErrorCount++;
//printf("Rx error: \r\n");
}
}
/* ---------- RX Finished Process Descriptors ----------*/
if ((int_stat & EMAC_INT_RX_FIN))
{
//RxFinishedCount++;
//printf("Rx finish \r\n");
}
/* ---------- Receive Done -----------------------------*/
/* Note: All packets are greater than (TX_PACKET_SIZE + 4)
* will be ignore!
*/
if ((int_stat & EMAC_INT_RX_DONE))
{
extern OS_EVENT* ethernetinput;
/* a frame has been received */
OSSemPost(ethernetinput);
//RxDoneCount++;
//printf("Rx done \r\n");
}
/*------------------- Transmit Underrun -----------------------*/
if ((int_stat & EMAC_INT_TX_UNDERRUN))
{
//TXUnderrunCount++;
//printf("Tx under-run \r\n");
}
/*------------------- Transmit Error --------------------------*/
if ((int_stat & EMAC_INT_TX_ERR))
{
//TXErrorCount++;
//printf("Tx error \r\n");
}
/* ----------------- TX Finished Process Descriptors ----------*/
if ((int_stat & EMAC_INT_TX_FIN))
{
//TxFinishedCount++;
//printf("Tx finish \r\n");
}
/* ----------------- Transmit Done ----------------------------*/
if ((int_stat & EMAC_INT_TX_DONE))
{
//TxDoneCount++;
//printf("Tx done \r\n");
}
}
}
/*******************************************************************************
* Function Name : list_if
* Description : display ip address in serial port debug windows
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static void list_if(void)
{
USART_Configuration();
printf("Default network interface: %c%c \r\n", _netif.name[0], _netif.name[1]);
printf("ip address: %s \r\n", inet_ntoa(*((struct in_addr*)&(_netif.ip_addr))));
printf("gw address: %s \r\n", inet_ntoa(*((struct in_addr*)&(_netif.gw))));
printf("net mask : %s \r\n", inet_ntoa(*((struct in_addr*)&(_netif.netmask))));
}
/*******************************************************************************
* Function Name : TcpipInitDone
* Description : TcpipInitDone wait for tcpip init being done
* Input : - arg: the semaphore to be signaled
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static void TcpipInitDone(void *arg)
{
sys_sem_t *sem;
sem = arg;
sys_sem_signal(*sem);
}
/*******************************************************************************
* Function Name : USART_Configuration
* Description : Configure USART2
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static void USART_Configuration(void)
{
uint32_t Fdiv;
PINSEL_CFG_Type PinCfg;
/*
* Initialize UART2 pin connect
*/
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Portnum = 0;
PinCfg.Pinnum = 10;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 11;
PINSEL_ConfigPin(&PinCfg);
/* Initialize UART Configuration parameter structure to default state:
* Baudrate = 115200bps
* 8 data bit
* 1 Stop bit
* None parity
*/
LPC_SC->PCONP = LPC_SC->PCONP|(1<<24); /* UART2 Power bit */
LPC_UART2->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
#define FOSC 12000000 /* 振蕩器頻率 */
#define FCCLK (FOSC * 8) /* 主時(shí)鐘頻率<=100Mhz FOSC的整數(shù)倍 */
#define FPCLK (FCCLK / 4) /* 外設(shè)時(shí)鐘頻率 FCCLK的1/2 1/4 */
Fdiv = ( FPCLK / 16 ) / 115200 ; /*baud rate */
LPC_UART2->DLM = Fdiv / 256;
LPC_UART2->DLL = Fdiv % 256;
LPC_UART2->LCR = 0x03; /* DLAB = 0 */
LPC_UART2->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
}
/*******************************************************************************
* Function Name : Ethernet_Initialize
* Description : Ethernet Initialize function
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void Ethernet_Initialize(void)
{
/* EMAC configuration type */
EMAC_CFG_Type Emac_Config;
/* pin configuration */
PINSEL_CFG_Type PinCfg;
/* EMAC address */
uint8_t EMACAddr[] = {emacETHADDR0, emacETHADDR1, emacETHADDR2, \
emacETHADDR3, emacETHADDR4, emacETHADDR5};
uint32_t i;
/*
* Enable P1 Ethernet Pins:
* P1.0 - ENET_TXD0
* P1.1 - ENET_TXD1
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -