[En-Nut-Discussion] uart help please
anieve01
anieve01 at yahoo.com
Tue Mar 27 20:59:10 CEST 2007
Hi,
I've been trying to modify the httpd example so that it can read serial data
from the same uart that it already prints out to. Does someone know how I
can do this? I looked at the uart.c example and tried many things to
incorporate the code from that example into the httpd, but nothing worked.
I see that the httpd example already assigns stdout to the uart, but how do
I assign stdin to the uart as well without interferring with the existing
fuctionality. Can someone show me what changes do I need to make the
httpd.c file. I've shown it below for convenience. Thank you in advance.
Tony
#define MY_MAC "\x00\x06\x98\x21\x18\x02"
/*
* Unique IP address of the Ethernut Board.
*
* Ignored if DHCP is used.
*/
#define MY_IPADDR "129.49.82.142"
/*
* IP network mask of the Ethernut Board.
*
* Ignored if DHCP is used.
*/
#define MY_IPMASK "255.255.255.0"
/*
* Gateway IP address for the Ethernut Board.
*
* Ignored if DHCP is used.
*/
#define MY_IPGATE "129.49.82.254"
#define DATA 0
#define SCK 1
/* ICCAVR Demo is limited. Try to use the bare minimum. */
#if !defined(__IMAGECRAFT__)
/* Wether we should use DHCP. */
#define USE_DHCP
/* Wether we should run a discovery responder. */
#define USE_DISCOVERY
/* Wether to use PHAT file system. */
//#define USE_PHAT
#endif /* __IMAGECRAFT__ */
#ifdef USE_PHAT
#if defined(ETHERNUT3)
/* Ethernut 3 file system. */
#define MY_FSDEV devPhat0
#define MY_FSDEV_NAME "PHAT0"
/* Ethernut 3 block device interface. */
#define MY_BLKDEV devNplMmc0
#define MY_BLKDEV_NAME "MMC0"
#elif defined(AT91SAM7X_EK)
/* SAM7X-EK file system. */
#define MY_FSDEV devPhat0
#define MY_FSDEV_NAME "PHAT0"
/* SAM7X-EK block device interface. */
#define MY_BLKDEV devAt91SpiMmc0
#define MY_BLKDEV_NAME "MMC0"
#elif defined(AT91SAM9260_EK)
/* SAM9260-EK file system. */
#define MY_FSDEV devPhat0
#define MY_FSDEV_NAME "PHAT0"
/* SAM9260-EK block device interface. */
#define MY_BLKDEV devAt91Mci0
#define MY_BLKDEV_NAME "MCI0"
#endif
#endif /* USE_PHAT */
#ifndef MY_FSDEV
#define MY_FSDEV devUrom
#endif
#ifdef MY_FSDEV_NAME
#define MY_HTTPROOT MY_FSDEV_NAME ":/"
#endif
#include <cfg/os.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <dev/board.h>
#include <dev/urom.h>
#include <dev/nplmmc.h>
#include <dev/sbimmc.h>
#include <fs/phatfs.h>
#include <sys/version.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/heap.h>
#include <sys/confnet.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <pro/httpd.h>
#include <pro/dhcp.h>
#include <pro/ssi.h>
#include <pro/asp.h>
#include <pro/discover.h>
#ifdef NUTDEBUG
#include <sys/osdebug.h>
#include <net/netdebug.h>
#endif
static char *html_mt = "text/html";
const u_char tempCmd = 0x03;
void toggleLED();
int getSHT75Temp();
/**************************************************************/
/* ASPCallback */
/* */
/* This routine must have been registered by */
/* NutRegisterAspCallback() and is automatically called by */
/* NutHttpProcessFileRequest() when the server process a page */
/* with an asp function. */
/* */
/* Return 0 on success, -1 otherwise. */
/**************************************************************/
static int ASPCallback (char *pASPFunction, FILE *stream)
{
if (strcmp(pASPFunction, "usr_date") == 0) {
fprintf(stream, "Dummy example: 01.01.2005");
return(0);
}
if (strcmp(pASPFunction, "usr_time") == 0) {
fprintf(stream, "Dummy example: 12:15:02");
return(0);
}
return (-1);
}
/*
* CGI Sample: Show request parameters.
*
* See httpd.h for REQUEST structure.
*
* This routine must have been registered by NutRegisterCgi() and is
* automatically called by NutHttpProcessRequest() when the client
* request the URL 'cgi-bin/test.cgi'.
*/
static int ShowQuery(FILE * stream, REQUEST * req)
{
char *cp;
/*
* This may look a little bit weird if you are not used to C programming
* for flash microcontrollers. The special type 'prog_char' forces the
* string literals to be placed in flash ROM. This saves us a lot of
* precious RAM.
*/
static prog_char head[] =
"<HTML><HEAD><TITLE>Parameters</TITLE></HEAD><BODY><H1>Parameters</H1>";
static prog_char foot[] = "</BODY></HTML>";
static prog_char req_fmt[] = "Method: %s<BR>\r\nVersion:
HTTP/%d.%d<BR>\r\nContent length: %d<BR>\r\n";
static prog_char url_fmt[] = "URL: %s<BR>\r\n";
static prog_char query_fmt[] = "Argument: %s<BR>\r\n";
static prog_char type_fmt[] = "Content type: %s<BR>\r\n";
static prog_char cookie_fmt[] = "Cookie: %s<BR>\r\n";
static prog_char auth_fmt[] = "Auth info: %s<BR>\r\n";
static prog_char agent_fmt[] = "User agent: %s<BR>\r\n";
/* These useful API calls create a HTTP response for us. */
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, html_mt, -1);
/* Send HTML header. */
fputs_P(head, stream);
/*
* Send request parameters.
*/
switch (req->req_method) {
case METHOD_GET:
cp = "GET";
break;
case METHOD_POST:
cp = "POST";
break;
case METHOD_HEAD:
cp = "HEAD";
break;
default:
cp = "UNKNOWN";
break;
}
fprintf_P(stream, req_fmt, cp, req->req_version / 10, req->req_version %
10, req->req_length);
if (req->req_url)
fprintf_P(stream, url_fmt, req->req_url);
if (req->req_query)
fprintf_P(stream, query_fmt, req->req_query);
if (req->req_type)
fprintf_P(stream, type_fmt, req->req_type);
if (req->req_cookie)
fprintf_P(stream, cookie_fmt, req->req_cookie);
if (req->req_auth)
fprintf_P(stream, auth_fmt, req->req_auth);
if (req->req_agent)
fprintf_P(stream, agent_fmt, req->req_agent);
/* Send HTML footer and flush output buffer. */
fputs_P(foot, stream);
fflush(stream);
return 0;
}
/*
* CGI Sample: Show list of threads.
*
* This routine must have been registered by NutRegisterCgi() and is
* automatically called by NutHttpProcessRequest() when the client
* request the URL 'cgi-bin/threads.cgi'.
*/
static int ShowThreads(FILE * stream, REQUEST * req)
{
static prog_char head[] =
"<HTML><HEAD><TITLE>Threads</TITLE></HEAD><BODY><H1>Threads</H1>\r\n"
"<TABLE
BORDER><TR><TH>Handle</TH><TH>Name</TH><TH>Priority</TH><TH>Status</TH><TH>Event<BR>Queue</TH><TH>Timer</TH><TH>Stack-<BR>pointer</TH><TH>Free<BR>Stack</TH></TR>\r\n";
#if defined(__AVR__)
static prog_char tfmt[] =
"<TR><TD>%04X</TD><TD>%s</TD><TD>%u</TD><TD>%s</TD><TD>%04X</TD><TD>%04X</TD><TD>%04X</TD><TD>%u</TD><TD>%s</TD></TR>\r\n";
#else
static prog_char tfmt[] =
"<TR><TD>%08lX</TD><TD>%s</TD><TD>%u</TD><TD>%s</TD><TD>%08lX</TD><TD>%08lX</TD><TD>%08lX</TD><TD>%lu</TD><TD>%s</TD></TR>\r\n";
#endif
static prog_char foot[] = "</TABLE></BODY></HTML>";
static char *thread_states[] = { "TRM", "RUN", "RDY", "SLP" };
NUTTHREADINFO *tdp = nutThreadList;
/* Send HTTP response. */
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, html_mt, -1);
/* Send HTML header. */
fputs_P(head, stream);
for (tdp = nutThreadList; tdp; tdp = tdp->td_next) {
fprintf_P(stream, tfmt, (uptr_t) tdp, tdp->td_name,
tdp->td_priority,
thread_states[tdp->td_state], (uptr_t) tdp->td_queue,
(uptr_t) tdp->td_timer,
(uptr_t) tdp->td_sp, (uptr_t) tdp->td_sp - (uptr_t)
tdp->td_memory,
*((u_long *) tdp->td_memory) != DEADBEEF ? "Corr" : "OK");
}
fputs_P(foot, stream);
fflush(stream);
return 0;
}
/*
* CGI Sample: Show list of timers.
*
* This routine must have been registered by NutRegisterCgi() and is
* automatically called by NutHttpProcessRequest() when the client
* request the URL 'cgi-bin/timers.cgi'.
*/
static int ShowTimers(FILE * stream, REQUEST * req)
{
static prog_char head[] =
"<HTML><HEAD><TITLE>Timers</TITLE></HEAD><BODY><H1>Timers</H1>\r\n";
static prog_char thead[] =
"<TABLE BORDER><TR><TH>Handle</TH><TH>Countdown</TH><TH>Tick
Reload</TH><TH>Callback<BR>Address</TH><TH>Callback<BR>Argument</TH></TR>\r\n";
#if defined(__AVR__)
static prog_char tfmt[] =
"<TR><TD>%04X</TD><TD>%lu</TD><TD>%lu</TD><TD>%04X</TD><TD>%04X</TD></TR>\r\n";
#else
static prog_char tfmt[] =
"<TR><TD>%08lX</TD><TD>%lu</TD><TD>%lu</TD><TD>%08lX</TD><TD>%08lX</TD></TR>\r\n";
#endif
static prog_char foot[] = "</TABLE></BODY></HTML>";
NUTTIMERINFO *tnp;
u_long ticks_left;
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, html_mt, -1);
/* Send HTML header. */
fputs_P(head, stream);
if ((tnp = nutTimerList) != 0) {
fputs_P(thead, stream);
ticks_left = 0;
while (tnp) {
ticks_left += tnp->tn_ticks_left;
fprintf_P(stream, tfmt, (uptr_t) tnp, ticks_left, tnp->tn_ticks,
(uptr_t) tnp->tn_callback, (uptr_t) tnp->tn_arg);
tnp = tnp->tn_next;
}
}
fputs_P(foot, stream);
fflush(stream);
return 0;
}
/*
* CGI Sample: Show list of sockets.
*
* This routine must have been registered by NutRegisterCgi() and is
* automatically called by NutHttpProcessRequest() when the client
* request the URL 'cgi-bin/sockets.cgi'.
*/
static int ShowSockets(FILE * stream, REQUEST * req)
{
/* String literals are kept in flash ROM. */
static prog_char head[] = "<HTML><HEAD><TITLE>Sockets</TITLE></HEAD>"
"<BODY><H1>Sockets</H1>\r\n"
"<TABLE
BORDER><TR><TH>Handle</TH><TH>Type</TH><TH>Local</TH><TH>Remote</TH><TH>Status</TH></TR>\r\n";
#if defined(__AVR__)
static prog_char tfmt1[] =
"<TR><TD>%04X</TD><TD>TCP</TD><TD>%s:%u</TD>";
#else
static prog_char tfmt1[] =
"<TR><TD>%08lX</TD><TD>TCP</TD><TD>%s:%u</TD>";
#endif
static prog_char tfmt2[] = "<TD>%s:%u</TD><TD>";
static prog_char foot[] = "</TABLE></BODY></HTML>";
static prog_char st_listen[] = "LISTEN";
static prog_char st_synsent[] = "SYNSENT";
static prog_char st_synrcvd[] = "SYNRCVD";
static prog_char st_estab[] = "ESTABL";
static prog_char st_finwait1[] = "FINWAIT1";
static prog_char st_finwait2[] = "FINWAIT2";
static prog_char st_closewait[] = "CLOSEWAIT";
static prog_char st_closing[] = "CLOSING";
static prog_char st_lastack[] = "LASTACK";
static prog_char st_timewait[] = "TIMEWAIT";
static prog_char st_closed[] = "CLOSED";
static prog_char st_unknown[] = "UNKNOWN";
prog_char *st_P;
extern TCPSOCKET *tcpSocketList;
TCPSOCKET *ts;
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, html_mt, -1);
/* Send HTML header. */
fputs_P(head, stream);
for (ts = tcpSocketList; ts; ts = ts->so_next) {
switch (ts->so_state) {
case TCPS_LISTEN:
st_P = (prog_char *) st_listen;
break;
case TCPS_SYN_SENT:
st_P = (prog_char *) st_synsent;
break;
case TCPS_SYN_RECEIVED:
st_P = (prog_char *) st_synrcvd;
break;
case TCPS_ESTABLISHED:
st_P = (prog_char *) st_estab;
break;
case TCPS_FIN_WAIT_1:
st_P = (prog_char *) st_finwait1;
break;
case TCPS_FIN_WAIT_2:
st_P = (prog_char *) st_finwait2;
break;
case TCPS_CLOSE_WAIT:
st_P = (prog_char *) st_closewait;
break;
case TCPS_CLOSING:
st_P = (prog_char *) st_closing;
break;
case TCPS_LAST_ACK:
st_P = (prog_char *) st_lastack;
break;
case TCPS_TIME_WAIT:
st_P = (prog_char *) st_timewait;
break;
case TCPS_CLOSED:
st_P = (prog_char *) st_closed;
break;
default:
st_P = (prog_char *) st_unknown;
break;
}
/*
* Fixed a bug reported by Zhao Weigang.
*/
fprintf_P(stream, tfmt1, (uptr_t) ts, inet_ntoa(ts->so_local_addr),
ntohs(ts->so_local_port));
fprintf_P(stream, tfmt2, inet_ntoa(ts->so_remote_addr),
ntohs(ts->so_remote_port));
fputs_P(st_P, stream);
fputs("</TD></TR>\r\n", stream);
fflush(stream);
}
fputs_P(foot, stream);
fflush(stream);
return 0;
}
/*
* CGI Sample: Proccessing a form.
*
* This routine must have been registered by NutRegisterCgi() and is
* automatically called by NutHttpProcessRequest() when the client
* request the URL 'cgi-bin/form.cgi'.
*
* Thanks to Tom Boettger, who provided this sample for ICCAVR.
*/
int ShowForm(FILE * stream, REQUEST * req)
{
int tempValue = 0;
static prog_char html_head[] = "<HTML><BODY><BR><H1>Form
Result</H1><BR><BR>";
static prog_char html_body[] = "<BR><BR><p> \"../index.html\" return to
main </BODY></HTML></p>";
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, html_mt, -1);
/* Send HTML header. */
fputs_P(html_head, stream);
if (req->req_query) {
char *name;
char *value;
int i;
int count;
count = NutHttpGetParameterCount(req);
/* Extract count parameters. */
for (i = 0; i < count; i++) {
name = NutHttpGetParameterName(req, i);
value = NutHttpGetParameterValue(req, i);
/* Send the parameters back to the client. */
if(i == 0){
tempValue = getSHT75Temp();
if(strcmp("1", value) == 0){
//toggleLED();
fprintf_P(stream, PSTR("%s: %d:<BR>\r\n"), "Green",
tempValue);
cbi(PORTB, 0);
}else{
fprintf_P(stream, PSTR("%s:<BR>\r\n"), "Red");
sbi(PORTB, 0);
}
}
#ifdef __IMAGECRAFT__
fprintf(stream, "%s: %s<BR>\r\n", name, value);
#else
fprintf_P(stream, PSTR("%s: %s<BR>\r\n"), name, value);
#endif
}// end for
// show SHT75 temperature
//getSHT75Temp();
}// end if
fputs_P(html_body, stream);
fflush(stream);
return 0;
}
/*! \fn Service(void *arg)
* \brief HTTP service thread.
*
* The endless loop in this thread waits for a client connect,
* processes the HTTP request and disconnects. Nut/Net doesn't
* support a server backlog. If one client has established a
* connection, further connect attempts will be rejected.
* Typically browsers open more than one connection in order
* to load images concurrently. So we run this routine by
* several threads.
*
*/
THREAD(Service, arg)
{
TCPSOCKET *sock;
FILE *stream;
u_char id = (u_char) ((uptr_t) arg);
/*
* Now loop endless for connections.
*/
for (;;) {
/*
* Create a socket.
*/
if ((sock = NutTcpCreateSocket()) == 0) {
printf("[%u] Creating socket failed\n", id);
NutSleep(5000);
continue;
}
/*
* Listen on port 80. This call will block until we get a connection
* from a client.
*/
NutTcpAccept(sock, 80);
#if defined(__AVR__)
printf("[%u] Connected, %u bytes free\n", id, NutHeapAvailable());
#else
printf("[%u] Connected, %lu bytes free\n", id, NutHeapAvailable());
#endif
/*
* Wait until at least 8 kByte of free RAM is available. This will
* keep the client connected in low memory situations.
*/
#if defined(__AVR__)
while (NutHeapAvailable() < 8192) {
#else
while (NutHeapAvailable() < 4096) {
#endif
printf("[%u] Low mem\n", id);
NutSleep(1000);
}
/*
* Associate a stream with the socket so we can use standard I/O
calls.
*/
if ((stream = _fdopen((int) ((uptr_t) sock), "r+b")) == 0) {
printf("[%u] Creating stream device failed\n", id);
} else {
/*
* This API call saves us a lot of work. It will parse the
* client's HTTP request, send any requested file from the
* registered file system or handle CGI requests by calling
* our registered CGI routine.
*/
NutHttpProcessRequest(stream);
/*
* Destroy the virtual stream device.
*/
fclose(stream);
}
/*
* Close our socket.
*/
NutTcpCloseSocket(sock);
printf("[%u] Disconnected\n", id);
}
}
void toggleLED(){
cbi(PORTB, 0);
NutSleep(1000);
sbi(PORTB, 0);
NutSleep(1000);
cbi(PORTB, 0);
NutSleep(1000);
sbi(PORTB, 0);
NutSleep(1000);
cbi(PORTB, 0);
NutSleep(1000);
sbi(PORTB, 0);
}
int getSHT75Temp(){
toggleLED();
sbi(PORTB, 0);
u_char j;
u_char cmdVal = tempCmd;
u_char cmd;
u_char temp1, temp2, mask, highByte = 0x00, lowByte = 0x00;
int val;
// initiate start sequence to SHT75
sbi(PORTD, 1); // bring sck high
sbi(PORTD, 0); // bring data high
cbi(PORTD, 0);
cbi(PORTD, 1);
sbi(PORTD, 1);
sbi(PORTD, 0);
cbi(PORTD, 1);
NutSleep(2);
// write temperature sample command (0x03) to SHT75
for(j = 0; j < 8; j++){
cbi(PORTD, 1); // bring sck low
cmd = cmdVal << j;
cmd = cmd & 0x80;
if(cmd > 0){// MSB = 1
sbi(PORTD, 0);
NutSleep(1);
}else{// MSB = 0
cbi(PORTD, 0);
NutSleep(1);
}
sbi(PORTD, 1); // clock it in
}
cbi(DDRD, 0); // make DATA an input to receive acknowledge
sbi(PORTD, 0); // pullup resistor
NutSleep(100); // let ports settle
cbi(PORTD, 1); // receive ack
// Wait for SHT75 to pull the data line low as acknowledge
temp1 = inb(PIND);
temp1 = temp1 & 0x01;
while(temp1){
cbi(PORTB, 0);
temp1 = inb(PIND);
temp1 = temp1 & 0x01;
}
sbi(PORTB, 0);
sbi(PORTD, 1); // ack
cbi(PORTD, 1); // this tiggers a measurement to be made
// Delay 80 ms for SHT75 to complete the measurement
NutSleep(80);
// wait for SHT75 to pull data line low as ack that measurement is
complete
temp1 = inb(PIND);
temp1 = temp1 & 0x01;
while(temp1){
temp1 = inb(PIND);
temp1 = temp1 & 0x01;
}
// measurement is now ready - and the first MSB is ready - read data
cbi(PORTD, 1);
// Read high byte
for(j = 7; j >= 0; j--){
mask = 0x01;
sbi(PORTD, 1);
NutSleep(1);
mask = (mask << j);
temp1 = inb(PIND); // read the data line
temp1 = temp1 & 0x01;
// make the appropriate bit high if high data was read for each bit
read
if(temp1){// data is high
highByte = (highByte | mask);
}
cbi(PORTD, 1); // clk it in
}
// get low byte now
sbi(DDRD, 0);
cbi(PORTD, 0);
NutSleep(100); // wait for port to settle
sbi(PORTD, 1); // acknowledge
cbi(DDRD, 0); // make DATA line an input line
sbi(PORTD, 0); // pullup resistor
NutSleep(100);
// Read low byte
for(j = 7; j >= 0; j--){
mask = 0x01;
sbi(PORTD, 1);
NutSleep(1);
mask = (mask << j);
temp1 = inb(PIND); // read the data line
temp1 = temp1 & 0x01;
// make the appropriate bit high if high data was read for each bit
read
if(temp1){// data is high
lowByte = (lowByte | mask);
}
cbi(PORTD, 1); // clk it in
}
sbi(DDRD, 0);
sbi(PORTD, 0);
NutSleep(100);
sbi(PORTD, 1);
cbi(PORTD, 1);
// convert the temperature reading
val = (int)lowByte;
return (-40 + 0.018*val - ((val - 7000) * (val - 7000))*0.00000002);
}
/*!
* \brief Main application routine.
*
* Nut/OS automatically calls this entry after initialization.
*/
int main(void)
{
u_long baud = 115200;
u_char i, j;
int ch;
sbi(DDRD, 0); // Configure PD0 and PD1 to output
sbi(DDRD, 1);
sbi(DDRB, 0);
NutSleep(500);
sbi(PORTB, 0);
/*
* Initialize the uart device.
*/
NutRegisterDevice(&DEV_DEBUG, 0, 0);
freopen(DEV_DEBUG_NAME, "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud);
NutSleep(200);
printf("\n\nNut/OS %s HTTP Daemon...", NutVersionString());
#ifdef NUTDEBUG
NutTraceTcp(stdout, 0);
NutTraceOs(stdout, 0);
NutTraceHeap(stdout, 0);
NutTracePPP(stdout, 0);
#endif
/*
* Register Ethernet controller.
*/
if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
puts("Registering device failed");
}
printf("Configure %s...", DEV_ETHER_NAME);
if (NutNetLoadConfig(DEV_ETHER_NAME)) {
u_char mac[] = MY_MAC;
printf("initial boot...");
#ifdef USE_DHCP
if (NutDhcpIfConfig(DEV_ETHER_NAME, mac, 60000))
#endif
{
u_long ip_addr = inet_addr(MY_IPADDR);
u_long ip_mask = inet_addr(MY_IPMASK);
u_long ip_gate = inet_addr(MY_IPGATE);
printf("No DHCP...");
if (NutNetIfConfig(DEV_ETHER_NAME, mac, ip_addr, ip_mask) == 0)
{
/* Without DHCP we had to set the default gateway
manually.*/
if(ip_gate) {
printf("hard coded gate...");
NutIpRouteAdd(0, 0, ip_gate, &DEV_ETHER);
}
puts("OK");
}
else {
puts("failed");
}
}
}
else {
#ifdef USE_DHCP
if (NutDhcpIfConfig(DEV_ETHER_NAME, 0, 60000)) {
puts("failed");
}
else {
puts("OK");
}
#else
if (NutNetIfConfig(DEV_ETHER_NAME, 0, 0, confnet.cdn_ip_mask)) {
puts("failed");
}
else {
puts("OK");
}
#endif
}
printf("%s ready\n", inet_ntoa(confnet.cdn_ip_addr));
#ifdef USE_DISCOVERY
NutRegisterDiscovery((u_long)-1, 0, DISF_INITAL_ANN);
#endif
/*
* Register our device for the file system.
*/
NutRegisterDevice(&MY_FSDEV, 0, 0);
#ifdef MY_BLKDEV
/* Register block device. */
printf("Registering block device '" MY_BLKDEV_NAME "'...");
if (NutRegisterDevice(&MY_BLKDEV, 0, 0)) {
puts("failed");
for (;;);
}
puts("OK");
/* Mount partition. */
printf("Mounting block device '" MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME
"'...");
if (_open(MY_BLKDEV_NAME ":1/" MY_FSDEV_NAME, _O_RDWR | _O_BINARY) ==
-1) {
puts("failed");
for (;;);
}
puts("OK");
#endif
#ifdef MY_HTTPROOT
/* Register root path. */
printf("Registering HTTP root '" MY_HTTPROOT "'...");
if (NutRegisterHttpRoot(MY_HTTPROOT)) {
puts("failed");
for (;;);
}
puts("OK");
#endif
/*
* Register our CGI sample. This will be called
* by http://host/cgi-bin/test.cgi?anyparams
*/
NutRegisterCgi("test.cgi", ShowQuery);
/*
* Register some CGI samples, which display interesting
* system informations.
*/
NutRegisterCgi("threads.cgi", ShowThreads);
NutRegisterCgi("timers.cgi", ShowTimers);
NutRegisterCgi("sockets.cgi", ShowSockets);
/*
* Finally a CGI example to process a form.
*/
NutRegisterCgi("form.cgi", ShowForm);
/*
* Protect the cgi-bin directory with
* user and password.
*/
NutRegisterAuth("cgi-bin", "root:root");
/*
* Register SSI and ASP handler
*/
NutRegisterSsi();
NutRegisterAsp();
NutRegisterAspCallback(ASPCallback);
/*
* Start four server threads.
*/
for (i = 1; i <= 4; i++) {
char *thname = "httpd0";
thname[5] = '0' + i;
NutThreadCreate(thname, Service, (void *) (uptr_t) i,
NUT_THREAD_MAINSTACK);
}
/*
* We could do something useful here, like serving a watchdog.
*/
NutThreadSetPriority(254);
cbi(DDRB, 1); // make pb1 input
sbi(PORTB, 1); // pullup
/* u_char vt, tempv;
vt = inb(PINB);
tempv = vt & 0x02;
// is it a 1 - should be yes
if(tempv > 0)
cbi(PORTB, 0);
else
toggleLED();
*/
for (;;) {
/*
if(scanf("%d", &ch) == 1){
printf("%s", "test");
if(ch == 'a')
cbi(PORTB, 0);
else if(ch == 'b')
toggleLED();
else if(ch == 'c')
sbi(PORTB, 0);
}
*/
/* Output different letters serially to the hyperterminal
depending on the level of the PB1 pin
if(bit_is_clear(PINB, 1))
printf("%s", "a");
else
printf("%s", "b");
*/
NutSleep(1000);
}
}
--
View this message in context: http://www.nabble.com/uart-help-please-tf3474950.html#a9698880
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.
More information about the En-Nut-Discussion
mailing list