📄 http_demo.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.: $tnVer / $tnDate
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) $CopyR KEIL - An ARM Company. All rights reserved. $end
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <RTL.h>
#include <LPC230x.H> /* LPC23xx definitions */
#include "type.h"
#include "target.h"
#include "LCD.h"
#if PERFORMANCE_MEASURE
volatile DWORD USBTick1 = 0, USBTick2 = 0;
volatile DWORD EtherTick1 = 0, EtherTick2 = 0;
volatile DWORD CPUTick1 = 0, CPUTick2 = 0;
volatile DWORD USBTimerTotal = 0;
volatile DWORD EtherTimerTotal = 0;
volatile DWORD CPUTimerTotal = 0;
volatile DWORD USBTotal = 0;
volatile DWORD EtherTotal = 0;
volatile DWORD CPUTotal = 0;
#endif
#define MCLK 57600000 /* Master Clock 57.6 MHz */
#define TCLK 10 /* Timer Clock rate 10/s */
#define TCNT (MCLK/TCLK/4) /* Timer Counts */
BOOL LEDrun;
BOOL LCDupdate;
U8 lcd_text[2][16+1] = {" RTL-ARM", /* Buffer for LCD text */
" HTTP example" };
#ifndef RTX_KERNEL
BOOL tick;
#else
U64 tcp_stack[800/8]; /* A bigger stack for tcp_task */
/* Forward references */
void init (void) __task;
void blink_led (void) __task;
void timer_task (void) __task;
void tcp_task (void) __task;
static void init_display (void);
#endif
extern void usbaudioInit( void );
/*--------------------------- init ------------------------------------------*/
#ifndef RTX_KERNEL
static void init () {
/* Add System initialisation code here */
#if PERFORMANCE_MEASURE
USBTimerTotal = 0;
EtherTimerTotal = 0;
CPUTimerTotal = 0;
#endif
/* I/O Ports configured as Output (Push-pull) */
FIO2DIR = 0x000000FF;
FIO2MASK = 0x00000000;
FIO2PIN = 0x00000000;
PINSEL10 = 0;
/* Timer 1 as interval timer, reload to 100ms. */
T1TCR = 1;
T1MCR = 3;
T1MR0 = TCNT - 1;
/* Configure UART1 for 115200 baud. */
PINSEL0 &= ~0xC0000000;
PINSEL0 |= 0x40000000; /* Enable TxD1 pin */
PINSEL1 &= ~0x00000003;
PINSEL1 |= 0x00000001; /* Enable RxD1 pin */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit*/
#if 0
U1DLL = 3; /* for 12MHz PCLK Clock */
#else
U1DLL = Fpclk / ( 16 * 115200 );
#endif
U1FDR = 0x67; /* Fractional Divider */
U1LCR = 0x03; /* DLAB = 0 */
}
#else
void init (void) __task {
/* Add System initialisation code here */
/* I/O Ports configured as Output (Push-pull) */
FIO2DIR = 0x000000FF;
FIO2MASK = 0x00000000;
FIO2PIN = 0x00000000;
PINSEL10 = 0;
/* Configure UART1 for 115200 baud. */
PINSEL0 &= ~0xC0000000;
PINSEL0 |= 0x40000000; /* Enable TxD1 pin */
PINSEL1 &= ~0x00000003;
PINSEL1 |= 0x00000001; /* Enable RxD1 pin */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit*/
#if 0
U1DLL = 3; /* for 12MHz PCLK Clock */
#else
U1DLL = Fpclk / ( 16 * 115200 );
#endif
U1FDR = 0x67; /* Fractional Divider */
U1LCR = 0x03; /* DLAB = 0 */
init_display ();
init_TcpNet ();
/* Initialize Tasks */
os_tsk_prio_self (100);
os_tsk_create (blink_led, 20);
os_tsk_create (timer_task, 30);
os_tsk_create_user (tcp_task, 0, &tcp_stack, sizeof(tcp_stack));
os_tsk_delete_self();
}
#endif
/*--------------------------- timer_poll ------------------------------------*/
#ifndef RTX_KERNEL
static void timer_poll () {
/* System tick timer running in poll mode */
#if PERFORMANCE_MEASURE
DWORD TotalTemp;
CPUTick1 = T0TC/16;
#endif
if (T1IR & 1) {
T1IR = 1;
/* Timer tick every 100 ms */
timer_tick ();
tick = 1;
}
#if PERFORMANCE_MEASURE
CPUTick2 = T0TC/16;
TotalTemp = CPUTimerTotal;
if ( CPUTick2 < CPUTick1 )
{
CPUTimerTotal += ((0xFFFFFFFF - CPUTick1) + CPUTick2);
}
else
{
CPUTimerTotal += (CPUTick2 - CPUTick1);
}
if ( CPUTimerTotal < TotalTemp )
{
CPUTotal++;
}
#endif
}
#else
void timer_task (void) __task {
/* System tick timer task */
os_itv_set (10);
while (1) {
timer_tick ();
os_itv_wait ();
}
}
#endif
/*--------------------------- sendchar --------------------------------------*/
int sendchar (int ch) {
/* Debug output to serial port. */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = '\r'; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
/*--------------------------- LED_out ---------------------------------------*/
void LED_out (U32 val) {
FIO2SET = val;
FIO2CLR = ~val;
}
/*--------------------------- upd_display -----------------------------------*/
static void upd_display () {
/* Update LCD Module display text. */
/* Set P1.30 as GPIO pin */
PINSEL3 &= ~0x30000000; /* a patch for USB Vbus pin share P1.30 for LCD */
// PINSEL3 |= 0x20000000;
LCD_cls ();
LCD_puts (lcd_text[0]);
LCD_gotoxy (1,2);
LCD_puts (lcd_text[1]);
LCDupdate =__FALSE;
/* Set P1.30 as USB Vbus pin. */
PINSEL3 &= ~0x30000000; /* a patch for USB Vbus pin share P1.30 for LCD */
PINSEL3 |= 0x20000000;
}
/*--------------------------- init_display ----------------------------------*/
static void init_display () {
/* LCD Module.2x16 init*/
LCD_init ();
LCD_cur_off ();
upd_display ();
}
/*--------------------------- blink_led -------------------------------------*/
#ifndef RTX_KERNEL
static void blink_led () {
/* Blink the LEDs on MCB-STR9 board */
const U8 led_val[16] = { 0x48,0x88,0x84,0x44,0x42,0x22,0x21,0x11,
0x12,0x0A,0x0C,0x14,0x18,0x28,0x30,0x50 };
static U32 cnt;
#if PERFORMANCE_MEASURE
DWORD TotalTemp;
CPUTick1 = T0TC/16;
#endif
if (tick) {
/* Every 100 ms */
tick = 0;
if (LEDrun) {
LED_out (led_val[cnt]);
if (++cnt >= sizeof(led_val)) {
cnt = 0;
}
}
if (LCDupdate) {
upd_display ();
}
}
#if PERFORMANCE_MEASURE
CPUTick2 = T0TC/16;
TotalTemp = CPUTimerTotal;
if ( CPUTick2 < CPUTick1 )
{
CPUTimerTotal += ((0xFFFFFFFF - CPUTick1) + CPUTick2);
}
else
{
CPUTimerTotal += (CPUTick2 - CPUTick1);
}
if ( CPUTimerTotal < TotalTemp )
{
CPUTotal++;
}
#endif
}
#else
void blink_led () __task {
/* Blink the LEDs on MCB-STR9 board */
const U8 led_val[16] = { 0x48,0x88,0x84,0x44,0x42,0x22,0x21,0x11,
0x12,0x0A,0x0C,0x14,0x18,0x28,0x30,0x50 };
static U32 cnt;
LEDrun = 1;
while(1) {
/* Every 100 ms */
if (LEDrun) {
LED_out (led_val[cnt]);
if (++cnt >= sizeof(led_val)) {
cnt = 0;
}
}
if (LCDupdate) {
upd_display ();
}
os_dly_wait(10);
}
}
#endif
/*---------------------------------------------------------------------------*/
#ifndef RTX_KERNEL
int main (void) {
/* Main Thread of the TcpNet */
#if PERFORMANCE_MEASURE
DWORD TotalTemp;
#endif
init ();
init_display ();
init_TcpNet ();
usbaudioInit();
LEDrun = 1;
while (1) {
timer_poll ();
#if PERFORMANCE_MEASURE
CPUTick1 = T0TC/16;
#endif
main_TcpNet ();
#if PERFORMANCE_MEASURE
CPUTick2 = T0TC/16;
TotalTemp = CPUTimerTotal;
if ( CPUTick2 < CPUTick1 )
{
CPUTimerTotal += ((0xFFFFFFFF - CPUTick1) + CPUTick2);
}
else
{
CPUTimerTotal += (CPUTick2 - CPUTick1);
}
if ( CPUTimerTotal < TotalTemp )
{
CPUTotal++;
}
#endif
blink_led ();
}
}
#else
void tcp_task (void) __task {
/* Main Thread of the TcpNet. This task should have */
/* the lowest priority because it is always READY. */
while (1) {
main_TcpNet();
os_tsk_pass();
}
}
int main (void) {
/* Start with 'init' task. */
os_sys_init(init);
usbaudioInit();
while(1);
}
#endif
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -