Beruflich Dokumente
Kultur Dokumente
Jrgen Wickenhuser
Wickenhuser Elektrotechnik
ABSTRACT
The MSC121x family of 8051 microcontrollers, with its rich array of on-chip features, is an
ideal hardware platform for sophisticated applications built with the FlexGate TCP/IP Stack.
This application report describes the use of the MSC121x as an ultra-compact webserver on
a simple printed circuit board (PCB) containing only a few components. Except where
otherwise noted, all references to the MSC121x indicate any member of the MSC1210,
MSC1211, and/or MSC1212 family of microcontrollers.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1
Protocol Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Receiving Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
10
User Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
11
Demonstration Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
12
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Related Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Appendix A Schematics, Board Layout, and Parts Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Appendix B \SRC\MSC1210\ELM_FLEX\ELMET.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Appendix C ELM_FLEX.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
FlexGate is a registered trademark of Wickenhuser Elektrotechnik. All other trademarks are the property of their respective
owners.
1
SBAA114
Introduction
Technological advancements as a result of the Internet are now accepted as a matter of fact.
Changes in terminology have also occurred as the use of the Internet has become more and
more widespread. Until recently, for example, connectivity was merely synonymous with a
device being capable of linking to a PC via an RS-232 or RS-485 interface and a simple cable.
However, connectivity now refers to the ability to link to the global network of the Internet;
sharing data is both enabled and expected through a series of physical and virtual connections.
Although Internet usage is common, many users may have only a trivial understanding of the
process by which the Internet works. Even training courses in networking are often abstract and
theoretical, with very little hands-on experience. Consequently, this report includes a brief
discussion of stack protocols and their function in the process of networking.
The FlexGate TCP/IP Stack is an open-source implementation of an internet protocol stack for
virtually all 8051 microcontrollers. It is a highly scalable software package that requires a
minimum of hardware resources. This application report describes the use of the MSC121x
family of microcontrollers as an ultra-compact webserver, built on the FlexGate TCP/IP stack.
Protocol Basics
Communication between electronic systems occurs through a series of standard protocols, or
established hardware and software rules which collectively form a communications language.
Protocols are most often combined in a suite (that defines the entire set) which is then
implemented by software in a given configuration called a protocol stack.
Protocol stacks are typically divided into three primary sections (or layers): media, transport, and
applications. Network servers and user PCs built on a given operating system, such as Microsoft
Windows, generally have two well-defined software interfaces: one between the applications
and transport layers, and one between the transport and media layers. Two of the protocols that
have been fundamental in the development of Internet technology are Transmission Control
Protocol (TCP) and Internet Protocol (IP), which are implemented in a stack commonly known
as TCP/IP. One of the most common network architectures that enables TCP/IP networking is
the Ethernet. Ethernet architecture uses a bus (or star) topology and supports data transfer
rates of 10MBPS to 100MBPS.
The software interface between the transport and media layers defines how transport protocol
software uses specific media and hardware types, or card drivers. For example, this interface
level would define how TCP/IP transport software would talk to Ethernet hardware.
The application-to-transport interface defines how application programs make use of the
transport layers. For instance, this interface level would define how a web browser program
would talk to TCP/IP transport software.
There are several implementations of the TCP/IP stacking protocol presently in wide use. (For
additional information, see Application Report SLAA137A, MSP430 Internet Connectivity,
available for download at www.ti.com.) This implementation of the MSP430 is
application-specific; that is, it supports only one software object that connects a network protocol
to an application (a single socket) and was tailored to only one single HTML page. This limited
usage may be sufficient in some cases (and makes it much easier to understand the underlying
software design), but is inadequate as a practical webserver for real-world applications.
SBAA114
Two other commonly-used protocols in the realm of Internet-based networking are file-transfer
protocol (FTP) and user datagram protocol (UDP). FTP requires at least two sockets for
communication to be successfully transmitted, received, and acknowledged, while one socket is
sufficient for UDP.
The MSC121x with the FlexGate TCP/IP Stack offers various possibilities for Internet
connectivity. This document will discuss only the topics of how to build and operate a webserver;
it will not review any other features of the FlexGate TCP/IP Stack.
SBAA114
SBAA114
Although it is not obvious, the PCB layout is fully compatible with the standard downloader
(supplied by Texas Instruments) for the MSC121x family. The only difference is that the two
jumpers (JP1 and JP2) must be set to enable PC download. The two jumpers must remain in
this position during development. If the software is finished, JP1 and JP2 must be removed, so
the CPU is protected against further downloads. Jumper JP3 enables traditional download by
pulling PSEN low. Normally, JP3 should always be left open; downloading via JP1 and JP2 is
recommended.
The webserver runs fine with the 11.0592MHz CPU (keep in mind that the MSC121x family is
more than 2.5 times faster than a generic 8051). The PCB incorporates a standard RS-232 port
(UART0), an RS-485 port (for UART1), and an I2C port which is not supported in this software.
The power consumption of the complete webserver is between 100140mA, with most current
being taken by the Ethernet driver IC. The supply voltage should be between 7.59V. A higher
voltage will dissipate unnecessary heat.
1.13k,
0.01%
Signal
AINCOM/AGND
SBAA114
To keep this application simple, no additional linearization is made, thus giving an expected
precision of about 0.5C in the range of 10C to +50C. Summation could be enabled by a
software switch, as described in the companion source code. If working with PT100, the device
self-heating should be considered; the current passing through the PT100 may increase the
temperature slightly. Most PT100 suppliers offer maximum current recommendations. Another
approach is to use higher currents for measurement, but then switch off the sensor excitation.
The MSC121x auxiliary interrupt can be used to build an RTC and access the temperature in a
precise yet simple manner. After the auxiliary interrupt is enabled, it can be configured to trigger
each second and each time the analog-to-digital (A/D) converter has a new result. For additional
details, please see \SRC\MSC1210\ELM_FLEX\ELMET.C (Appendix B). Care must be taken if
accessing data that are modified by the interrupt. For this purpose, several transfer functions
exist (that is, for reading and setting the RTC, or reading the A/D converter result). In light of the
fact that this was only a demonstration project, the A/D converter was calibrated only at
power-up. For an actual system, a calibration should also be performed from time to time, which
could best be resolved by a logical state machine within the auxiliary interrupt routine.
The complete MSC121x initialization is also done in the above-mentioned file. Note that the
internal RAM must be mapped to 0x8400 as the first action. This mapping is performed by the
function, startup_first().
List 1: NET.H
/**************************************************************************
* OPTION DEFs for this Stack (Change for your needs)
**************************************************************************/
//#define DEBUG_REC
//if defined: Record Send/received Frames
//#define USE_UDP
//If defined: UDPSupport added
//#define USE_TCP_CLIENT
//If defined: TCPClient (Active open, Active
ARP)
// RXBuffer (only one)
#define MAX_RX
100
// TXBuffers (>=1)
#define MAX_TX
100
#define MAX_SOCK 4
#define TX_BUFFERS
SBAA114
For an MSC121x webserver, the first three options are not required. Because there is only 1kB
RAM available (movx accessible), only a small number of buffers are available. MAX_SOCK
defines the maximum number of simultaneously active TCP/IP connections. The MSC12x
webserver forces immediate closing after a page is transmitted, so a total of four sockets is
sufficient.
It should be noted that embedded graphics in HTML code may require more than one socket,
even if only one page is generated. Moreover, the limited RAM of the CS8900A can only buffer a
small number of Ethernet data frames. Although TCP retransmission mechanisms will monitor
this, it will increase the overall transmission time of a page.
List 2: d_page.html
<html>
<head>
<title>Dynamic HTML</title>
</head>
<body>
Hello @adr @name!<br><br>
</body>
</html>
The tag for dynamic variables is the @. Thus, the adr and name tags are actually C variables
(strings). These strings could be defined in the corresponding C file as:
char adr[5];
char name[50];
If the FlexGate webserver driver encounters a tagged variable, it will simply include the
variables content in the generated HTML code. If adr[ ] is equal to Mr. and name[ ] is
Wickenhuser, the HTML will be Hello Mr. Wickenhuser!
There is no limit to the number of available variables other than the CPU RAM (movx
accessible). It is important that the reserved space for the variable must be large enough and
that the terminating \0 byte of a C-string counts as 1 byte. For example, adr[ ] must not hold
longer strings than Mrs. (four characters) for the declaration char adr[5].
The contents of the strings can be altered or assigned with all standard C functions such as
sprintf() or strcpy(). The application is responsible for setting up the required variables.
This document will not go into any deeper description of HTML; many good and easy-to-read
resources are widely available. If opened in a raw state with a standard browser, developing
HTML pages for the FlexGate TCP/IP Stack is not complicated because the tagged C variables
will appear as simple text. It is even possible to include advanced features such as JavaScript or
URL-attached session management.
SBAA114
As mentioned before, it is also possible to include graphics (GIF and JPEG) in FlexGate
dynamic pages, as shown in this example:
<img src=logo.gif>
Note that moving graphics to other webservers will save a great deal of memory on the
MSC121x. In this case, a reference to a graphics would look like this example code:
<img src=http://www.xxx.com/logo.gif>
The screen display for the webserver appears as in Figure 3, which shows the current
temperature and time. The bar graph contains two nested tables. The outer table has a yellow
background and a fixed size, while the inner table size depends on the measured temperature.
SBAA114
7.1
D_TOKEN and END_TOKEN are special characters. It is evident that this file can be
assembled separately. If the receiving web browser finds unresolved references, of course,
there will be error messages exchanged. Consequently, the user must declare these unresolved
references somewhere within the program, as in this example:
char adr[5];
// defines and reserves space in xram
char name[50];
// dto.
extern code char d_page[]; // declaration without definition
SBAA114
Receiving Input
The FlexGate webserver supports URL-attached argument passing, which is equal to the
GET-method used in HTML forms.
The webserver supports only variables named a1 to a255 or A1 to A255. Webserver
functions will retrieve the number of such an argument or zero; another function will retrieve a
pointer to the arguments value. By looking into the example source code, the mechanism by
which this is accomplished is clear. Using these limited names for input is a design trade-off; it
should be emphasized that there is no possibility to use a similar system such as tagged
variables (which are used for output), because the input arguments are not known at the compile
time (as shown in 9.4).
If a URL request is too long, the webserver will ignore the request in order to prevent a buffer
overflow.
10
SBAA114
9.1
Initialization
The main() function is located in \SRC\MSC1210\ELM_FLEX\ELM_FLEX.C. This is the entry
point of the software.
9.2
Selecting an IP Address
There is one item to be cleared; that is the webservers IP address. Keep in mind that each
member system within a local TCP/IP network must have an unique IP address. The selection of
this address is not the focus of this document, however; and if the user has any concerns
regarding the IP address assigned to the webserver, the local network administrator should be
contacted. The source code default IP assignment s is 192.168.1.156. A macro from NET.H
will execute the instruction:
COMPOSE_IP(my_ip,192,168,1,156);
my_ip is the variable within the stack that is holding the local IP address. After the two
initfunctions init_msc1210() and init_net() have been called, the sockets that can be used for
HTML must be initialized (note that some sockets may be reserved for other types of
connections, such as e-mail, Telnet, or UDP).
// Enable ALL (or less) Sockets as General Server HTTP at port 80
for(i=0;i<MAX_SOCK;i++) SOCKET_SETUP(i,SOCKET_TCP,80,FLAG_PASSIVE_OPEN);
9.3
Poll Webserver
After this, the software will stay in an endless loop that must periodically call the function
poll_webserver().
If no transactions or executions have occurred, poll_webserver() will return 0. In any other
case, the result (or event) will contain a code in its high byte, and (optionally) the number of the
socket in its low byte. There are many more events than the few that are required for a
webserver. Here only two events are needed:
9.4
EVENT_HTTP_REQUEST
EVENT_SOCKET_IDLETIMER
Respond to Events
The last event appears about twice each second and will do nothing more than toggle the
User-LED. The other event shows that an HTML page was requested. If this event is not
processed, a default page containing the text Page not found will be sent.
11
SBAA114
In this application, the name of the requested page is examined first. Because there are only a
few pages on the webserver, only the first letter is used for distinction. Each page may require
filling out a limited number of variables.
In the demo, there is only one page that may receive arguments: reply.html. A simple loop
scans the arguments until no further arguments are found. Arguments A1 to A3 control the
RTC; A4 to A6 set LED3 and LED4. The usage of A4 may be unclear (because there are only
a total of two LEDs and three arguments), but A4 serves as a hidden input that clears both
LEDs. Arguments A5 and A6 will appear only if explicitly checked in the HTML form.
It is important to reiterate that the URL arguments copied to C variables never exceed the
reserved space. Any size limits in the corresponding HTML forms should not be relied upon.
Functions such as strlen() could be used for verification.
Figure 4 shows another example of the webserver screen display, containing a dynamic form.
The page shown here actually contains two forms. Both forms pass their arguments to
reply.html, depending on which Set-button was pressed.
12
SBAA114
http://192.168.1.156/reply.html?A1=16&A2=24&A3=37&A9=Set+Clock
http://192.168.1.156/reply.html?A4=&A5=on&A9=Set+LEDs
A ? character announces that parameters are following. All parameters are connected by a &.
Space characters in the input are replaced by a +. Argument A4 (corresponding to LED3) is
empty.
10
User Tasks
There is no explicit user task that must be performed on the MSC121x, because the auxiliary
interrupts execute all necessary functions.
In cases where an additional user task is required, several points must be noted:
11
The user task should be kept as short as possible. Although the CS8900A has some on-chip
RAM, it will buffer only a certain number of Ethernet frames. As a recommendation, the user
task should not run longer than 10100 msec.
It is more efficient to use a software state machine for more complex user tasks.
Demonstration Results
The complete source code is available for free download (www.wickenhaeuser.de). It can be
compiled with the free demo version of the C/51 ANSI C-Compiler. Normally, the demonstration
version will compile only 8kB of code, but contributions have been made that allow up to 16kB
under several conditions, such as those described here for the hardware and software.
Upon installation of the C/51 ANSI C-Compiler, a short step-by-step instruction about the
software from this application note can be found in the directory \SRC\MSC1210\ELM_FLEX\*.*.
Ready-to-run hardware kits are also available from Elektor Electronics magazine
(www.elektor.org).
12
Summary
This document gives only a very brief overview about some of the possible applications of the
FlexGate TCP/IP Stack. Many other protocols and services are widely available; for example,
UDP can be used for transferring data to many receivers simultaneously, while TELNET enables
text-based applications. The FlexGate TCP/IP stack also includes support for SMTP and POP3,
thus enabling the sending and receipt of e-mail.
Internal details of the stack have also been intentionally omitted.
Many other additional features are currently under construction, such as firmware upload over
Ethernet or using a GSM-dial-up-PPP connection instead of the Ethernet.
13
SBAA114
References
Stevens, W.R. (1993.). TCP/IP Illustrated, Volume 1: The Protocols. Reading, MA:
AddisonWesley.
Postel, J. (1981.). RFC791: Internet Protocol. http://www.faqs.org/rfcs/rfc791.html
Postel, J. (1981.). RFC792: Internet Control Message Protocol.
http://www.faqs.org/rfcs/rfc792.html
Postel, J. (1981.). RFC793: Transmission Control Protocol. http://www.faqs.org/rfcs/rfc793.html
Bentham, J. (2002.). TCP/IP Lean: Web Servers for Embedded Systems. (2nd ed.) Lawrence,
KS: CMP Books.
MSP430 Internet Connectivity (SLAA137A). (Available for download from www.ti.com)
Related Links
Wickenhuser Elektrotechnik (www.wickenhaeuser.de). Information on the C/51 ANSI
C-Compiler and FlexGate TCP/IP stack.
Elektor Electronics magazine (www.elektor.org).
Cirrus Logic/Crystal Semiconductor (www.cirrus.com) Information on the CS8900A.
RealTek (www.realtek.com.tw). Information on the RTL8019AS.
Asix (www.asix.com.tw). Information on the AX88796L.
14
SBAA114
Appendix A
A.1
CPU Board.
15
SBAA114
16
SBAA114
17
SBAA114
18
SBAA114
Qty
Description
IC1
IC2, IC6
IC4
IC5
T1
D1
D2, D3
D4, D5
D6
LED1
C7, C5
C8
C13
C14, C15
C19C21
Tantalum capacitor 10F/6.3V (parts may be omitted for low-cost version of board),
tantalum-B
R1R3,
R12R13
R6R7, R11,
R14, R22
R8R9,
R17R18,
R20R21
R15, R16
R19
X1
K1
K2
K3
(K4, K5)
J1J2
Jumper
(J3)
S1
B1B4
PCB
IC3
19
SBAA114
2. LAN Board.
20
SBAA114
21
SBAA114
22
SBAA114
Qty
Description
IC1
LED1LED4
C1C2,
C4C10
C3
R1
R6R9
R2R3
R5, R10
R4
IND1
X1
CON1
K1
K2
S1
Mini push-button
B1B4
23
SBAA114
Appendix B
\SRC\MSC1210\ELM_FLEX\ELMET.C
/************************************************************************
* ELEKTORMETER TOOLBOX V2.0
WICKENHAEUSER.DE
*
* MSC1210 @ 11.0592 MHz
************************************************************************/
#include <stdio.h>
#include <irq52.h>
#include <REG1210.H>
#include <ROM1210.H>
#asm
.include <REG1210.DEF>
#endasm
#include utility.h
#include elmet.h
// SFR
// ROM Routines
// SFR for ASM
// Utility functions for accessing the A/D
// special ELMET routines and constants
24
SBAA114
/************************************************************************
* get_rtc_time(): Copy static (IRQ maintained) time to uservariable
* The structure is copied by components (although uC/51 allows structure
* copy (like rtc_time=cnt_time) but for small structures this is faster:
************************************************************************/
void get_rtc_time(void){
EAI=0;
// Disable Auxiliary IRQ
rtc_time.hr=cnt_time.hr; // Copy components
rtc_time.min=cnt_time.min;
rtc_time.sec=cnt_time.sec;
EAI=1;
// ReEnable Auxiliary IRQ
}
/************************************************************************
* set_rtc_time(): Copy usertime to static (IRQ maintained) time.
* user_s time is verified, on success return 0, else time will not be set.
************************************************************************/
uchar set_rtc_time(void){
if(rtc_time.hr>23 || rtc_time.min>59 || rtc_time.sec>59) return 1; // FAIL
EAI=0;
// Disable Auxiliary IRQ
cnt_time.hr=rtc_time.hr; // Copy components
cnt_time.min=rtc_time.min;
cnt_time.sec=rtc_time.sec;
EAI=1;
// ReEnable Auxiliary IRQ
return 0; // OK
}
25
SBAA114
cnt_time.hr=0;
}
}
}
}
AI=0; // Clear Aux INT (Bit in EICON)
}
#pragma option g cpu51 b0 // Restore debug info level to default
// and enable temporaries
/********************************************************************
* Because the Adr. Space 0..$7FFF is decoded for the CS8900A,
* the internal XRAM of the CPU must be mapped to >$8000 prior to
* the C startup()function (startup() expects the RAM to be found at the
* correct location, for initialisation)
**********************************************************************/
#asm
.segment ___startup_first
.export __startup_first
.export STARTUP_FIRST ; This two lines generate a global linker definition
STARTUP_FIRST=1
; if anything <>0, _startup() will the users
; call __startup_first()
__startup_first:
; as first action (see lib\lib_c\startup.c).
mov MCON,#1
; Map RAM to $8400
ret
#endasm
/***********************************************************************
* init_msc1210(): Initialize CPU 11.0592 MHz
***********************************************************************/
void init_msc1210(void){
T2CON = 0x34;
// T2 as baudrate generator
RCAP2H = (RCAP2>>8);
RCAP2L = (RCAP2&255);
SCON
= 0x50;
// Async mode 1, 8bit UART, enable rcvr, TI=0, RI=0
MSECH=(ONEMS>>8);
MSECL=(ONEMS&255);
HMSEC=99;
#ifdef USE_WD
PDCON &= ~0x04;
WDTCON=0x80;
WDTCON=0x00;
WDSERV();
#endif
// Milisecond register
// 100 Milisecondregister
// Defined from extern (see elm_flex.h)
// WD ON
// WDEnable
// initial serve Watchdog
// A/DConverter
PDCON &= 0x0f7;
//ADCON
ACLK = 11;
// ACLK = 11.0592MHz/(11+1)= 0.9216MHz
ADCON3=(DECIMATION>>8);
ADCON2=(DECIMATION&255); // ADSpeed
ADCON0 = EVREF|EBUF|GAIN_1;
// Vref on 1.25V, Buff on, BOD off, PGA 1
// Sec Timer
PDCON &= 0x0fD;
SECINT=9|128;
// System Timer ON
// Load immediatelly 1/sec
// IRQ enable (Dontt OR the AIE, else unwanted IRQs may be enabled!)
#ifdef AD_FILT8
AIE=0x80+0x40;
// Enable SEC_INT(0x80), SUMMER_INT (0x40);
#else
AIE=0x80+0x20;
// Enable A/D_INT(0x20), SEC_INT(0x80);
26
SBAA114
#endif
EAI=1;
// Fast XRAM
CKCON=0;
}
// EOF
27
SBAA114
Appendix C
ELM_FLEX.C
/*************************************************************************
* ELM_FLEX.C ELEKTORMETER as Webserver V1.0
*
* (C) 2004 ELEKTORVERLAG, WWW.WICKENHAEUSER.COM
*
* MSC1210 @ 11.0592 MHz
*************************************************************************/
#include <stdio.h>
#include <irq52.h>
#include <REG1210.H>
#include <ROM1210.H>
// SFR
// ROM Routines
#include utility.h
#include elmet.h
// Webserver Headers
#include ..\..\flexgate\tcpip\net.h
// Numeric ID
// Numeric HitCounter
id[6]=0;
// ID Must hold strings max. 65535+\0
t_wid[6]=256;
// Width for T_DISP Bar 0..512\0
t_deg[12]=98.76;
// Temp. in Celsius xx.yy as Text
ctime[12]=11:22:33; // Time for T_DISP hh:mm:ss
hr[4]=12;
// Hrs for Setup
min[4]=34;
// Hrs for Setup
sec[4]=56;
// Hrs for Setup
ls3[2];
// The Checkboxes for the LED3+4s
ls4[2];
//
are a little bit tricky...
hits[6]=0;
// a hit_counter
/**************************************************************************
* get_temp(): Get the current temperature as int
*
* Settings are for a PT1001/3DIN Temperature Sensor and a Resistor 1.13k
* (0.01%, TK15) If calibrated to 0 Degr. C (use ICE) and 40 Degr. C (use a
* fever thermometer and warm water) The maximum deviation in the range
* 20...+50 Degr. C is smaller than +/ 0.25 Degr. C
**************************************************************************/
#define T_SUB 5456005L
// 0Point at 0 Degr. in A/DCounts
// as LONG (calc)
#define T_MUL 5.20036910E03
// Slope for 40 Degr. (calculated)
int get_temp(void){
long trel_lt;
float trel_f;
28
SBAA114
trel_lt=get_adval_bip()T_SUB;
//
trel_f=(float)trel_lt*T_MUL;
//
// Result
return (int)trel_f;
//
//
}
/************************************************************************
* M A I N
************************************************************************/
void main(void){
uint res;
uchar i;
uchar socket;
xdata uchar *pc;
int temp100;
init_msc1210();
puts(*** www.FLEXGATE.com TCP/IP __DATE__ , __TIME__ ***);
// A HTTPServer with only passive sockets requires only an IP
// address
COMPOSE_IP(my_ip,192,168,1,156);
if(Init_net()) puts(<NET FAILURE>);// Init Variables,
// Counter, ...
printf(My MAC: %02x:%02x:%02x:%02x:%02x:%02x\n, my_mac[0],my_mac[1],
my_mac[2],my_mac[3],my_mac[4],my_mac[5]);
printf(My IP: %u.%u.%u.%u\n,my_ip.bytes[0],my_ip.bytes[1],
my_ip.bytes[2],my_ip.bytes[3]);
puts(*** MINIWEBSERVER Elektors ElmFlex ***);
// Enable ALL (or less) Sockets as General Server HTTP at port 80
for(i=0;i<MAX_SOCK;i++) SOCKET_SETUP(i,SOCKET_TCP,80,
FLAG_PASSIVE_OPEN);
// Initialise A/D at last...
set_adval_bip(0x78,EVREF|EBUF|VREFH|GAIN_8); // Vref on 2.5V,
// Buff On,
// BOD off, PGA 1
// * Now Net is ready to start *
for(;;){
// ENOUGH TIME IN THIS LOOP FOR OTHER JOBS...
WDSERV();
// Serve Watchdog about every 3 seconds! (see elmet.h)
res=poll_webserver();
if((res&0xFF00) ==EVENT_HTTP_REQUEST){
socket=(uchar)res;
pc=webpage_name(); // get name of requested page
printf(Request %s\n,pc);// Show requested page
// (for Debug)
switch(*pc){
case r:
id_num++;
// Increment ID
sprintf(id,%u,id_num);
for(;;){
// ReplyPage: Parse Arguments
i=url_getarg_no();
if(!i) break;
pc=url_getarg_str();
29
SBAA114
printf(Arg A%u: %s\n,i,pc);
// Opt. Show Args...
// (Enable for Debug)
switch(i){
case 1:
rtc_time.hr=(uchar)atoi(pc);
break;
case 2:
rtc_time.min=(uchar)atoi(pc);
break;
case 3:
rtc_time.sec=(uchar)atoi(pc);
set_rtc_time();
break;
case 4:// Hidden Argument comes first...
LED3=1;
// OFF
LED4=1;
// OFF
ls3[0]=0;
// Empty String
ls4[0]=0;
// Empty String
break;
case 5:
ls3[0]=d; // d gives checked
LED3=0;
// ON
break;
case 6:
ls4[0]=d; // d gives checked
LED4=0;
// ON
break;
}
// ignore other Args...
}
webpage_bind(socket,reply);
break;
case s:
sprintf(id,%u,id_num);
get_rtc_time();
sprintf(hr,%02u,rtc_time.hr);
sprintf(min,%02u,rtc_time.min);
sprintf(sec,%02u,rtc_time.sec);
webpage_bind(socket,set);
break;
case t:
sprintf(id,%u,id_num);
get_rtc_time();
sprintf(ctime,%02u:%02u:%02u,rtc_time.hr, rtc_time.min,
rtc_time.sec);
temp100=get_temp();
sprintf(t_deg,%d.%02u,temp100/100,((uint)temp100)%100);
if(temp100<1000) temp100=1000;
else if(temp100>3499) temp100=3499;
sprintf(t_wid,%u,(temp1001000)/5);//0..500: FullScale
webpage_bind(socket,t_disp);
break;
default:
sprintf(hits,%u,++hits_num);
sprintf(id,%u,id_num);
webpage_bind(socket,home);
}
30
SBAA114
}else if(res==EVENT_SOCKET_IDLETIMER){
RED_LED^=1; // *** BLINK LED ***
}
} // for(;;)
}
// EOF
31
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,
enhancements, improvements, and other changes to its products and services at any time and to discontinue
any product or service without notice. Customers should obtain the latest relevant information before placing
orders and should verify that such information is current and complete. All products are sold subject to TIs terms
and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in
accordance with TIs standard warranty. Testing and other quality control techniques are used to the extent TI
deems necessary to support this warranty. Except where mandated by government requirements, testing of all
parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for
their products and applications using TI components. To minimize the risks associated with customer products
and applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right,
copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process
in which TI products or services are used. Information published by TI regarding third-party products or services
does not constitute a license from TI to use such products or services or a warranty or endorsement thereof.
Use of such information may require a license from a third party under the patents or other intellectual property
of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of information in TI data books or data sheets is permissible only if reproduction is without
alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction
of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for
such altered documentation.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that
product or service voids all express and any implied warranties for the associated TI product or service and
is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.
Following are URLs where you can obtain information on other Texas Instruments products and application
solutions:
Products
Applications
Amplifiers
amplifier.ti.com
Audio
www.ti.com/audio
Data Converters
dataconverter.ti.com
Automotive
www.ti.com/automotive
DSP
dsp.ti.com
Broadband
www.ti.com/broadband
Interface
interface.ti.com
Digital Control
www.ti.com/digitalcontrol
Logic
logic.ti.com
Military
www.ti.com/military
Power Mgmt
power.ti.com
Optical Networking
www.ti.com/opticalnetwork
Microcontrollers
microcontroller.ti.com
Security
www.ti.com/security
Telephony
www.ti.com/telephony
www.ti.com/video
Wireless
www.ti.com/wireless
Mailing Address:
Texas Instruments
Post Office Box 655303 Dallas, Texas 75265
Copyright 2004, Texas Instruments Incorporated