Ich versuche anhand des Demos XMEGA_wzWebSrv1 einen kleinen Webserver auf einem Arduino Mega zum Laufen zu bekommen.
Es scheint, dass das Programm in der Routine " wzListen(SocketTCP);" hängen bleibt, zumindest ist kein Verkehr auf dem SPI Bus zu erkennen.
Die Initialisierung läuft anscheinend, ich habe den CS auf Portb.4 liegen.
Das seltsame ist aber, wenn ich im define
das
"TINAport = SPI, PortB, 4; //Portb.4 is CS of 5100"
auf irgend einen anderen Port lege, ändert das nichts, das Programm läuft denn beim Init des Chips durch, keine Fehlermeldung. Ich würde erwarten, dass bei " if not wzTINA_Init.." ein Fehler kommt.
Was könnte da nicht stimmen?
program PoolWeb;
{ $OPTIMISE}
{$NOSHADOW}
{ $WG} {global Warnings on}
{$DEFINE Enable_W5100}
{$DEFINE Enable_TCP}
{ $DEFINE Enable_UDP}
{ $DEFINE Enable_W5100_Diag}
Device = mega2560, VCC=5;
{ $BOOTRST $03800} {Reset Jump to $03800}
Define_Fuses
Override_Fuses;
NoteBook = A;
COMport = USB;
LockBits0 = [];
FuseBits0 = [CKSEL0, SUT0];
FuseBits1 = [];
FuseBits2 = [];
ProgMode = SPI;
ProgFuses = true;
ProgLock = false;
ProgFlash = true;
ProgEEprom = true;
Import SysTick, wzTINAstack, SerPort, SPIdriver; //, FAT16, watchdog;
from System import longword;
//from System import Tasks;
from wzTINAstack import wzTCP;
Define
ProcClock = 16000000; {Hertz}
SysTick = 5; {msec}
// WatchDog = msec500; {presc = 3}
StackSize = $0150, iData;
FrameSize = $0150, iData;
SerPort = 38400, Stop2; {Baud, StopBits|Parity}
RxBuffer = 8, iData;
TxBuffer = 20, iData;
SPIMode = 0 ;
SPIpresc = 0;
SPIOrder = MSB;
SPI_SS = false;
// FAT16 = MMC_SPI, iData;
// F16_MMCspeed = slow ;
// F16_FileHandles = 1;
// F16_DirLevels = 1;
TINAdriver = WizNet5100; // WizNet5100 or WizNet5200 or WizNet5500
TINAport = SPI, PortB, 4; //Portb.4 is CS of 5100
TINAtimer = Timer1; // 1..3
TINAsockets = 2; // socket count,1..4
Uses uWzTINA5100;
Implementation
alias
wSerOut = Serout;
wSerStat = SerStat;
wSerInp = SerInp;
{$EEPROM}
structconst
dummy : word = $1234;
UDPAknPort : word = 0;
LocalIP : tIPaddr = (192, 168, 178, 110); // our wiznet modul IP
Gateway : tIPaddr = (192, 168, 178, 1);
RemPort : word = 0000;
RemHost : tIPaddr = (192, 168, 178, 19);
LocPort : word = 80; // example for server mode
Mask : tIPaddr = (255, 255, 255, 0);
MacAddr : TMacAddr = ($00, $0B, $DC, $1D, $6F, $26);
SendRetry : byte = 3;
SendTimeOut : word = 2000;
BoardName : string[20] = 'POOLWEB';
{$IDATA}
{--------------------------------------------------------------}
{ functions }
const
structconst
WEBGetCommand : string = 'GET /';
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
LED[@PortB, 7] : bit;
buffer : array[600] of byte;
RxTxBuff[@buffer] : array[600] of byte;
SocketTCP : TSocketHandle;
procedure PortInit;
begin
DDRB.7:=1; // redled
DDRB.4:=1; //W5100_CS
incl(portb.4);
end;
{------------------------------------------------------------------------------}
procedure HttpWriteln(WebString : string[50]);
begin
Append(#13 + #10, WebString);
CopyBlock(@WebString + 1, @buffer, word(WebString[0]));
wzSendBuffer(SocketTCP, @buffer, word(WebString[0]));
end;
procedure HttpWrite(WebString : string[50]);
begin
CopyBlock(@WebString + 1, @buffer, word(WebString[0]));
wzSendBuffer(SocketTCP, @buffer, word(WebString[0]));
end;
procedure HttpServer;
var
lrecv : word;
ReceivedBytes : word;
Webptr : pointer;
ab : word;
adStr : string[16];
idx : byte;
lIP : tIPaddr;
begin
if WzInitOk then
Writeln(wSerOut, 'WZINIT OK');
SocketTCP:= wzCreateSocket;
if sockettcp=NIL then
Writeln(wSerOut, 'Socket=NIL');
endif;
with SocketTCP^ do
Protocol:= protTCP;
LocalPort:= 80; // our Web port
MaxSegSize:= 1460;
DelayAck:= NoDelayedAck;
PacketRecInfo.BufferPtr:= @RxTxBuff;
PacketRecInfo.BufferLen:= Sizeof(RxTxBuff);
endwith;
Writeln(wSerOut, 'Port set');
wzListen(SocketTCP);
loop
Writeln(wSerOut, 'listen');
if wzClientConnected(SocketTCP) then
Writeln(wSerOut, 'Socket');
lIP:= SocketTCP^.PacketRecInfo.PeerIp;
repeat
if wzPacketReceived(SocketTCP) then
ReceivedBytes:= 0;
Webptr:= SocketTCP^.PacketRecInfo.BufferPtr;
repeat
lrecv:= wzReceiveBuffer(SocketTCP);
Inc(SocketTCP^.PacketRecInfo.BufferPtr, lrecv);
ReceivedBytes:= ReceivedBytes + lrecv;
until lrecv = 0;
SocketTCP^.PacketRecInfo.BufferPtr:= @RxTxBuff;
if ReceivedBytes > 0 then
//printHex(SocketTCP^.PacketRecInfo.BufferPtr, ReceivedBytes);
if CompareBlock(Webptr, @WEBGetCommand + 1, 5) then // we recv GET / command
HttpWriteln('HTTP/1.1 200 OK');
HttpWriteln('Content-Type: text/html');
HttpWriteln('Connection: close'); // the connection will be closed after completion of the response
HttpWriteln('Refresh: 5'); // refresh the page automatically every 5 sec
HttpWriteln('');
HttpWriteln('<!DOCTYPE HTML>');
HttpWriteln('<html><center><strong>');
HttpWriteln('E-LAB XMEGA ADC Simple WebServ </strong><br />');
HttpWriteln('Your IP: ' + IPToStr(lIP) + ' <br />');
HttpWriteln('autorefresh every 5 sec. ');
HttpWriteln('<br /><font color="#0000FF">');
for idx:= 0 to 7 do
HttpWrite('analog input ');
HttpWrite(byteToStr(idx));
HttpWrite(' is ');
// ab:= GetADCB(idx);
ab:=10;
adStr:= IntToStr(ab : 6);
HttpWrite(adStr);
HttpWriteln('<br />');
endfor;
HttpWriteln('</font></html>');
mdelay(100); // small delay to give mobil dev. time to recv. the answer
wzDisconnect(SocketTCP);
endif;
endif;
endif; // recv
if SocketTCP^.PeerTryToDisconnect then
wzDisconnect(SocketTCP);
endif;
mdelay(500);
until SocketTCP^.SocketClosed;
if SocketTCP^.SocketClosed then
mdelay(100);
wzListen(SocketTCP);
endif;
endif; // connected
endloop;
endif;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
PortInit;
LED:= true;
mdelay(1000);
LED:= false;
EnableInts;
wzHWReset;
wzsetIPAddr(LocalIP, Mask);
wzsetGatewayAddr(Gateway);
wzsetHWAddr(MacAddr);
wzsetTimeOut(2000); // connect wait timeout
wzsetRetryCount(5);
wzChipmainInit.ResponsePing:= true;
// Important ! If set to Very High Priori
wzChipmainInit.Prio:= TINAPrioHigh;
Writeln(wSerOut, #13 + #10 + 'Start');
if not wzTINA_Init then
loop
Writeln(wSerOut, 'Init Failed');
Toggle(LED);
mdelay(300);
endloop;
endif;
mdelay(2000); //Wait for Switch/Hub to see Phy !
// BeepOut(2500, 20);
Writeln(wSerOut, #13 + #10 + '------- Simple WebServ start -----------');
loop
// wzTINA_Init;
HttpServer;
endloop;
end PoolWeb.
Es scheint, dass das Programm in der Routine " wzListen(SocketTCP);" hängen bleibt, zumindest ist kein Verkehr auf dem SPI Bus zu erkennen.
Die Initialisierung läuft anscheinend, ich habe den CS auf Portb.4 liegen.
Das seltsame ist aber, wenn ich im define
das
"TINAport = SPI, PortB, 4; //Portb.4 is CS of 5100"
auf irgend einen anderen Port lege, ändert das nichts, das Programm läuft denn beim Init des Chips durch, keine Fehlermeldung. Ich würde erwarten, dass bei " if not wzTINA_Init.." ein Fehler kommt.
Was könnte da nicht stimmen?
Code
program PoolWeb;
{ $OPTIMISE}
{$NOSHADOW}
{ $WG} {global Warnings on}
{$DEFINE Enable_W5100}
{$DEFINE Enable_TCP}
{ $DEFINE Enable_UDP}
{ $DEFINE Enable_W5100_Diag}
Device = mega2560, VCC=5;
{ $BOOTRST $03800} {Reset Jump to $03800}
Define_Fuses
Override_Fuses;
NoteBook = A;
COMport = USB;
LockBits0 = [];
FuseBits0 = [CKSEL0, SUT0];
FuseBits1 = [];
FuseBits2 = [];
ProgMode = SPI;
ProgFuses = true;
ProgLock = false;
ProgFlash = true;
ProgEEprom = true;
Import SysTick, wzTINAstack, SerPort, SPIdriver; //, FAT16, watchdog;
from System import longword;
//from System import Tasks;
from wzTINAstack import wzTCP;
Define
ProcClock = 16000000; {Hertz}
SysTick = 5; {msec}
// WatchDog = msec500; {presc = 3}
StackSize = $0150, iData;
FrameSize = $0150, iData;
SerPort = 38400, Stop2; {Baud, StopBits|Parity}
RxBuffer = 8, iData;
TxBuffer = 20, iData;
SPIMode = 0 ;
SPIpresc = 0;
SPIOrder = MSB;
SPI_SS = false;
// FAT16 = MMC_SPI, iData;
// F16_MMCspeed = slow ;
// F16_FileHandles = 1;
// F16_DirLevels = 1;
TINAdriver = WizNet5100; // WizNet5100 or WizNet5200 or WizNet5500
TINAport = SPI, PortB, 4; //Portb.4 is CS of 5100
TINAtimer = Timer1; // 1..3
TINAsockets = 2; // socket count,1..4
Uses uWzTINA5100;
Implementation
alias
wSerOut = Serout;
wSerStat = SerStat;
wSerInp = SerInp;
{$EEPROM}
structconst
dummy : word = $1234;
UDPAknPort : word = 0;
LocalIP : tIPaddr = (192, 168, 178, 110); // our wiznet modul IP
Gateway : tIPaddr = (192, 168, 178, 1);
RemPort : word = 0000;
RemHost : tIPaddr = (192, 168, 178, 19);
LocPort : word = 80; // example for server mode
Mask : tIPaddr = (255, 255, 255, 0);
MacAddr : TMacAddr = ($00, $0B, $DC, $1D, $6F, $26);
SendRetry : byte = 3;
SendTimeOut : word = 2000;
BoardName : string[20] = 'POOLWEB';
{$IDATA}
{--------------------------------------------------------------}
{ functions }
const
structconst
WEBGetCommand : string = 'GET /';
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
LED[@PortB, 7] : bit;
buffer : array[600] of byte;
RxTxBuff[@buffer] : array[600] of byte;
SocketTCP : TSocketHandle;
procedure PortInit;
begin
DDRB.7:=1; // redled
DDRB.4:=1; //W5100_CS
incl(portb.4);
end;
{------------------------------------------------------------------------------}
procedure HttpWriteln(WebString : string[50]);
begin
Append(#13 + #10, WebString);
CopyBlock(@WebString + 1, @buffer, word(WebString[0]));
wzSendBuffer(SocketTCP, @buffer, word(WebString[0]));
end;
procedure HttpWrite(WebString : string[50]);
begin
CopyBlock(@WebString + 1, @buffer, word(WebString[0]));
wzSendBuffer(SocketTCP, @buffer, word(WebString[0]));
end;
procedure HttpServer;
var
lrecv : word;
ReceivedBytes : word;
Webptr : pointer;
ab : word;
adStr : string[16];
idx : byte;
lIP : tIPaddr;
begin
if WzInitOk then
Writeln(wSerOut, 'WZINIT OK');
SocketTCP:= wzCreateSocket;
if sockettcp=NIL then
Writeln(wSerOut, 'Socket=NIL');
endif;
with SocketTCP^ do
Protocol:= protTCP;
LocalPort:= 80; // our Web port
MaxSegSize:= 1460;
DelayAck:= NoDelayedAck;
PacketRecInfo.BufferPtr:= @RxTxBuff;
PacketRecInfo.BufferLen:= Sizeof(RxTxBuff);
endwith;
Writeln(wSerOut, 'Port set');
wzListen(SocketTCP);
loop
Writeln(wSerOut, 'listen');
if wzClientConnected(SocketTCP) then
Writeln(wSerOut, 'Socket');
lIP:= SocketTCP^.PacketRecInfo.PeerIp;
repeat
if wzPacketReceived(SocketTCP) then
ReceivedBytes:= 0;
Webptr:= SocketTCP^.PacketRecInfo.BufferPtr;
repeat
lrecv:= wzReceiveBuffer(SocketTCP);
Inc(SocketTCP^.PacketRecInfo.BufferPtr, lrecv);
ReceivedBytes:= ReceivedBytes + lrecv;
until lrecv = 0;
SocketTCP^.PacketRecInfo.BufferPtr:= @RxTxBuff;
if ReceivedBytes > 0 then
//printHex(SocketTCP^.PacketRecInfo.BufferPtr, ReceivedBytes);
if CompareBlock(Webptr, @WEBGetCommand + 1, 5) then // we recv GET / command
HttpWriteln('HTTP/1.1 200 OK');
HttpWriteln('Content-Type: text/html');
HttpWriteln('Connection: close'); // the connection will be closed after completion of the response
HttpWriteln('Refresh: 5'); // refresh the page automatically every 5 sec
HttpWriteln('');
HttpWriteln('<!DOCTYPE HTML>');
HttpWriteln('<html><center><strong>');
HttpWriteln('E-LAB XMEGA ADC Simple WebServ </strong><br />');
HttpWriteln('Your IP: ' + IPToStr(lIP) + ' <br />');
HttpWriteln('autorefresh every 5 sec. ');
HttpWriteln('<br /><font color="#0000FF">');
for idx:= 0 to 7 do
HttpWrite('analog input ');
HttpWrite(byteToStr(idx));
HttpWrite(' is ');
// ab:= GetADCB(idx);
ab:=10;
adStr:= IntToStr(ab : 6);
HttpWrite(adStr);
HttpWriteln('<br />');
endfor;
HttpWriteln('</font></html>');
mdelay(100); // small delay to give mobil dev. time to recv. the answer
wzDisconnect(SocketTCP);
endif;
endif;
endif; // recv
if SocketTCP^.PeerTryToDisconnect then
wzDisconnect(SocketTCP);
endif;
mdelay(500);
until SocketTCP^.SocketClosed;
if SocketTCP^.SocketClosed then
mdelay(100);
wzListen(SocketTCP);
endif;
endif; // connected
endloop;
endif;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
PortInit;
LED:= true;
mdelay(1000);
LED:= false;
EnableInts;
wzHWReset;
wzsetIPAddr(LocalIP, Mask);
wzsetGatewayAddr(Gateway);
wzsetHWAddr(MacAddr);
wzsetTimeOut(2000); // connect wait timeout
wzsetRetryCount(5);
wzChipmainInit.ResponsePing:= true;
// Important ! If set to Very High Priori
wzChipmainInit.Prio:= TINAPrioHigh;
Writeln(wSerOut, #13 + #10 + 'Start');
if not wzTINA_Init then
loop
Writeln(wSerOut, 'Init Failed');
Toggle(LED);
mdelay(300);
endloop;
endif;
mdelay(2000); //Wait for Switch/Hub to see Phy !
// BeepOut(2500, 20);
Writeln(wSerOut, #13 + #10 + '------- Simple WebServ start -----------');
loop
// wzTINA_Init;
HttpServer;
endloop;
end PoolWeb.