⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enet_uip.c

📁 最新版IAR FOR ARM(EWARM)5.11中的代码例子
💻 C
📖 第 1 页 / 共 2 页
字号:
//*****************************************************************************
//
// enet_uip.c - Sample WebServer Application for Ethernet Demo
//
// Copyright (c) 2007 Luminary Micro, Inc.  All rights reserved.
// 
// Software License Agreement
// 
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
// 
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws.  All rights are reserved.  You may not combine
// this software with "viral" open-source software in order to form a larger
// program.  Any use in violation of the foregoing restrictions may subject
// the user to criminal sanctions under applicable laws, as well as to civil
// liability for the breach of the terms and conditions of this license.
// 
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 1952 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************

#include "../../../hw_ints.h"
#include "../../../hw_memmap.h"
#include "../../../hw_types.h"
#include "../../../src/debug.h"
#include "../../../src/interrupt.h"
#include "../../../src/sysctl.h"
#include "../../../src/systick.h"
#include "../../../src/ethernet.h"
#include "../../../src/flash.h"
#include "../../../src/gpio.h"
#include "../../../src/ethernet.h"
#include "../../../utils/diag.h"
#include "../rit128x96x4.h"
#include "uip.h"
#include "uip_arp.h"
#include "httpd.h"

//*****************************************************************************
//
//! \addtogroup ek_lm3s6965_revc_list
//! <h1>Ethernet with uIP (enet_uip)</h1>
//!
//! This example application demonstrates the operation of the Stellaris
//! Ethernet controller using the uIP TCP/IP Stack.  A basic web site is served
//! over the Ethernet port, located at link local address 169.254.19.63.  If a
//! node on the network has already chosen this link local address, nothing is
//! done by the application to choose another address and a conflict will
//! occur.  The web site displays a few lines of text, and a counter that
//! increments each time the page is sent.
//!
//! For additional details on uIP, refer to the uIP web page at:
//! http://www.sics.se/~adam/uip/
//
//*****************************************************************************

//*****************************************************************************
//
// Defines for setting up the system clock.
//
//*****************************************************************************
#define SYSTICKHZ               100
#define SYSTICKMS               (1000 / SYSTICKHZ)
#define SYSTICKUS               (1000000 / SYSTICKHZ)
#define SYSTICKNS               (1000000000 / SYSTICKHZ)

//*****************************************************************************
//
// Macro for accessing the Ethernet header information in the buffer.
//
//*****************************************************************************
#define BUF                     ((struct uip_eth_hdr *)&uip_buf[0])

//*****************************************************************************
//
// A set of flags.  The flag bits are defined as follows:
//
//     0 -> An indicator that a SysTick interrupt has occurred.
//     1 -> An RX Packet has been received.
//
//*****************************************************************************
#define FLAG_SYSTICK            0
#define FLAG_RXPKT              1
static volatile unsigned long g_ulFlags;

//*****************************************************************************
//
// Default TCP/IP Settings for this application.
//
// Default to Link Local address ... (169.254.1.0 to 169.254.254.255).  Note:
// This application does not implement the Zeroconf protocol.  No ARP query is
// issued to determine if this static IP address is already in use.
//
//*****************************************************************************
#ifndef DEFAULT_IPADDR0
#define DEFAULT_IPADDR0         169
#endif

#ifndef DEFAULT_IPADDR1
#define DEFAULT_IPADDR1         254
#endif

#ifndef DEFAULT_IPADDR2
#define DEFAULT_IPADDR2         19
#endif

#ifndef DEFAULT_IPADDR3
#define DEFAULT_IPADDR3         63
#endif

#ifndef DEFAULT_NETMASK0
#define DEFAULT_NETMASK0        255
#endif

#ifndef DEFAULT_NETMASK1
#define DEFAULT_NETMASK1        255
#endif

#ifndef DEFAULT_NETMASK2
#define DEFAULT_NETMASK2        0
#endif

#ifndef DEFAULT_NETMASK3
#define DEFAULT_NETMASK3        0
#endif

//*****************************************************************************
//
// UIP Timers (in MS)
//
//*****************************************************************************
#define UIP_PERIODIC_TIMER_MS   500
#define UIP_ARP_TIMER_MS        10000

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
    //
    // Indicate that a SysTick interrupt has occurred.
    //
    HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 1;
}

//*****************************************************************************
//
// The interrupt handler for the Ethernet interrupt.
//
//*****************************************************************************
void
EthernetIntHandler(void)
{
    unsigned long ulTemp;

    //
    // Read and Clear the interrupt.
    //
    ulTemp = EthernetIntStatus(ETH_BASE, false);
    EthernetIntClear(ETH_BASE, ulTemp);

    //
    // Check to see if an RX Interrupt has occured.
    //
    if(ulTemp & ETH_INT_RX)
    {
        //
        // Indicate that a packet has been received.
        //
        HWREGBITW(&g_ulFlags, FLAG_RXPKT) = 1;

        //
        // Disable Ethernet RX Interrupt.
        //
        EthernetIntDisable(ETH_BASE, ETH_INT_RX);
    }
}

//*****************************************************************************
//
// Display a uIP type IP Address.
//
//*****************************************************************************
static void
DisplayIPAddress(uip_ipaddr_t ipaddr, unsigned long ulCol, unsigned long ulRow)
{
    char pucBuf[16];
    int iIndex = 0;
    unsigned char *pucTemp = (unsigned char *)ipaddr;
    unsigned char ucValue;

    //
    // Process first byte of IP Address.
    //
    ucValue = pucTemp[0];
    if(ucValue > 9)
    {
        if(ucValue > 99)
        {
            pucBuf[iIndex++] = '0' + (ucValue / 100);
            ucValue %= 100;
        }
        pucBuf[iIndex++] = '0' + (ucValue / 10);
        ucValue %= 10;
    }
    pucBuf[iIndex++] = '0' + (ucValue);
    pucBuf[iIndex++] = '.';

    //
    // Process second byte of IP Address.
    //
    ucValue = pucTemp[1];
    if(ucValue > 9)
    {
        if(ucValue > 99)
        {
            pucBuf[iIndex++] = '0' + (ucValue / 100);
            ucValue %= 100;
        }
        pucBuf[iIndex++] = '0' + (ucValue / 10);
        ucValue %= 10;
    }
    pucBuf[iIndex++] = '0' + (ucValue);
    pucBuf[iIndex++] = '.';

    //
    // Process third byte of IP Address.
    //
    ucValue = pucTemp[2];
    if(ucValue > 9)
    {
        if(ucValue > 99)
        {
            pucBuf[iIndex++] = '0' + (ucValue / 100);
            ucValue %= 100;
        }
        pucBuf[iIndex++] = '0' + (ucValue / 10);
        ucValue %= 10;
    }
    pucBuf[iIndex++] = '0' + (ucValue);
    pucBuf[iIndex++] = '.';

    //
    // Process last byte of IP Address.
    //
    ucValue = pucTemp[3];
    if(ucValue > 9)
    {
        if(ucValue > 99)
        {
            pucBuf[iIndex++] = '0' + (ucValue / 100);
            ucValue %= 100;
        }
        pucBuf[iIndex++] = '0' + (ucValue / 10);
        ucValue %= 10;
    }
    pucBuf[iIndex++] = '0' + (ucValue);
    pucBuf[iIndex] = 0;

    //
    // Display the string.
    //
    RIT128x96x4StringDraw(pucBuf, ulCol, ulRow, 15);
}

//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller with the uIP
// TCP/IP stack.
//
//*****************************************************************************
int

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -