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

📄 http_demo.c

📁 基于lm3s6965的http示例代码,对初学者特别有帮助。
💻 C
字号:
/*----------------------------------------------------------------------------
 *      R T L   T C P N E T   E x a m p l e
 *----------------------------------------------------------------------------
 *      Name:    HTTP_DEMO.C
 *      Purpose: HTTP Server demo example
 *      Rev.:    V3.12
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2007 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include <stdio.h>
#include <RTL.h>
#include <Net_Config.h>
#include <LM3Sxxxx.H>
#include <string.h>

BOOL LEDrun;
BOOL LCDupdate;
BOOL tick;
U32  dhcp_tout;
U8   lcd_text[2][16+1] = {"    RL-ARM",       /* Buffer for LCD text         */
                          "  HTTP example"};

extern LOCALM localm[];                       /* Local Machine Settings      */
#define MY_IP localm[NETIF_ETH].IpAdr
#define DHCP_TOUT   50                        /* DHCP timeout 5 seconds      */

static void init_io (void);
static void init_display (void);

/*--------------------------- init ------------------------------------------*/

static void init () {
   /* Add System initialisation code here */ 

   init_io ();
   init_display ();
   init_TcpNet ();

   /* Setup and enable the SysTick timer for 100ms. */
   SysTickPeriodSet(SysCtlClockGet() / 10);
   SysTickEnable();
}


/*--------------------------- timer_poll ------------------------------------*/

static void timer_poll () {
   /* System tick timer running in poll mode */

   if ((HWREG (NVIC_ST_CTRL) >> 16) & 1) {
      /* Timer tick every 100 ms */
      timer_tick ();
      tick = __TRUE;
   }
}

/*--------------------------- init_io ---------------------------------------*/

static void init_io () {

   /* Set the clocking to run from the PLL at 50 MHz */
   SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL |
                   SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);

   /* Configure the GPIO for the LED. */
   SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOF);
   GPIOPadConfigSet (GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD);
   GPIODirModeSet (GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT);

   /* Configure UART0 for 115200 baud. */
   SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA);
   SysCtlPeripheralEnable (SYSCTL_PERIPH_UART0);
   GPIOPinTypeUART (GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
   UARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 |
                                      UART_CONFIG_STOP_ONE |
                                      UART_CONFIG_PAR_NONE));
}


/*--------------------------- fputc -----------------------------------------*/

int fputc (int ch, FILE *f)  {
   /* Debug output to serial port. */

   if (ch == '\n')  {
      UARTCharPut (UART0_BASE, '\r');        /* output CR                    */
   }
   UARTCharPut (UART0_BASE, ch);
   return (ch);
}


/*--------------------------- LED_out ---------------------------------------*/

void LED_out (U32 val) {
   GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_0, val & 1);
}


/*--------------------------- upd_display -----------------------------------*/

static void upd_display () {
   /* Update LCD Module display text. */

   //OSRAM128x64x4Clear ();
   //OSRAM128x64x4StringDraw ((const S8 *)&lcd_text[0], 20, 20, 11);
   //OSRAM128x64x4StringDraw ((const S8 *)&lcd_text[1], 20, 35, 11);
   LCDupdate =__FALSE;
}


/*--------------------------- init_display ----------------------------------*/

static void init_display () {
   /* OLED Module init */

   //OSRAM128x64x4Init(1000000);
   upd_display ();
}


/*--------------------------- dhcp_check ------------------------------------*/

static void dhcp_check () {
   /* Monitor DHCP IP address assignment. */

   if (tick == __FALSE || dhcp_tout == 0) {
      return;
   }
   if (mem_test (&MY_IP, 0, IP_ADRLEN) == __FALSE && !(dhcp_tout & 0x80000000)) {
      /* Success, DHCP has already got the IP address. */
      dhcp_tout = 0;
      sprintf((S8 *)lcd_text[0],"IP address:");
      sprintf((S8 *)lcd_text[1],"%d.%d.%d.%d", MY_IP[0], MY_IP[1],
                                               MY_IP[2], MY_IP[3]);
      LCDupdate = __TRUE;
      return;
   }
   if (--dhcp_tout == 0) {
      /* A timeout, disable DHCP and use static IP address. */
      dhcp_disable ();
      sprintf((S8 *)lcd_text[1]," DHCP failed    " );
      LCDupdate = __TRUE;
      dhcp_tout = 30 | 0x80000000;
      return;
   }
   if (dhcp_tout == 0x80000000) {
      dhcp_tout = 0;
      sprintf((S8 *)lcd_text[0],"IP address:");
      sprintf((S8 *)lcd_text[1],"%d.%d.%d.%d", MY_IP[0], MY_IP[1],
                                               MY_IP[2], MY_IP[3]);
      LCDupdate = __TRUE;
   }
}


/*--------------------------- blink_led -------------------------------------*/

static void blink_led () {
   /* Blink the LEDs on an eval board */
   static U32 LEDstat = 1;

   if (tick == __TRUE) {
      /* Every 100 ms */
      tick = __FALSE;
      if (LEDrun == __TRUE) {
         LEDstat = ~LEDstat & 0x01;
         LED_out (LEDstat);
      }
      if (LCDupdate == __TRUE) {
         upd_display ();
      }
   }
}


/*---------------------------------------------------------------------------*/

int main (void) {
   /* Main Thread of the TcpNet */

   init ();
   LEDrun = __TRUE;
   dhcp_tout = DHCP_TOUT;
   while (1) {
      timer_poll ();
      main_TcpNet ();
      dhcp_check ();
      blink_led ();
   }
}


/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/


⌨️ 快捷键说明

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