Webserver Summer Project

  • 1
  • 2
  • Page 1 of 2
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Webserver Summer Project

 · 
Posted: 27.12.2010 - 06:08  ·  #1
Hi,

I have an Arduino TwentyTen PCB that has a Mega328P processor. TwentyTen
I also have a Arduino Ethernet Shield that has a W5100 on it. W5100 Shield

So I thought I would try making a web server. :happy:
Unfortunately, I have run out of room on the Mega328P :(

The Ethernet W5100 interface code and TCP state machine code only use 10KB (30%) of the 32K of flash and with a 1KB Ethernet buffer, I have 600 Bytes of ram free.
For a basic Web server the buffer could be made smaller and give up some ram.

I can do a Basic "Hello World" as it stands but I would like to use a MMC card.

BUT..... Just bringing in the FAT16 code requires 35K of flash :( :(

Any way of making the FAT16 code smaller? Restrict to just 1 file handle & directory?

I don't have an external static IP address but here is a link to the actual Mega328 Web Server http://121.44.239.39:8080 for as long as it lasts.

Ideas??

Neil.
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 27.12.2010 - 09:57  ·  #2
Hi All,

This is what the main application looks like
Code
program Ethernet_TwentyTen;

{$NOSHADOW}
{ $WG}                      {global Warnings on}

{$DEFINE Enable_W5100}
{$DEFINE Enable_TCP}
{ $DEFINE Enable_UDP}


Device = mega328p, VCC=5;
{ $BOOTRST $03800}         {Reset Jump to $03800}

Define_Fuses
  Override_Fuses;
  NoteBook   = A;
  COMport    = USB;
  LockBits0 = [];
  FuseBits0  = [CKSEL0];
  FuseBits1  = [];
  FuseBits2  = [];
  ProgMode   = SPI;
  ProgFuses  = true;
  ProgLock   = false;
  ProgFlash  = true;
  ProgEEprom = false;

Import SysTick, WatchDog, SerPort, SPIdriver, TWImaster;

From System Import ;
From System Import LongWord, LongInt;

Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  WatchDog       = msec125;         {presc = 3}
  StackSize      = $0064, iData;
  FrameSize      = $0064, iData;
  SerPort        = 38400, Stop2;    {Baud, StopBits|Parity}
  RxBuffer       = 8, iData;
  TxBuffer       = 8, iData;
  TWIpresc       = TWI_BR100;

  SPIMode        = 0 ;
  SPIpresc       = 0;
  SPIOrder       = MSB;
  SPI_SS         = true;
  
  
{
//  FAT16          = SPI_C, PortA, 6, iData; // PortX defines the SS-Port and n (6) the SS-Pin
  FAT16          = MMC_SPI, iData;
  F16_FileHandles= 1;
  F16_DirLevels  = 1;
}

{$IFDEF Enable_W5100}
Uses
    uIPGLOBAL,
    uWEB,
    uW5100;
//    UFAT16;
//    uxAP_Definitions,
//    uxAP_UDP;

{$EndIf}

Implementation

{$IDATA}

{--------------------------------------------------------------}
{ Type Declarations }

type
   tTCPServerBuffer = Array[0..999] of Byte;

{--------------------------------------------------------------}
{ Const Declarations }
structconst
  dummy            : word   = $1234;                            // Negate possible data corruption at start of eeprom
  Firmware_Version : String = '1.0.0.0' ;                       // From Header at the top of this file
  CRLF             : String = #13+#10;
  WebPageContent : String = 'HTTP/1.0 200 OK'+#13+#10+'Content-type: text/plain'+#13+#10+#13+#10+'Hello World. I''m a Mega328P & W5100 running AVRCo. Hits=';
  WebPageCRLF : String = #13+#10;

{--------------------------------------------------------------}
{ Var Declarations }
Var
{$IDATA}
  WEBServer           : tIPSocket ;
  pWEBServer          : pIPSocketHandle;
  WEBServerBuf        : tTCPServerBuffer ; // Shared for Tx & Rx

  Result             : Boolean ;
  RedLED[@portd, 5]  : bit;
  St_Tx,St_Rx        : String[50];
  WebPageCounter     : Word ;
  WebPage            : String[200];
{--------------------------------------------------------------}
{ functions }

procedure InitPorts;
begin
  DDRB.5:=  1; // redled
end InitPorts;

Procedure StartupBlinks;
Var
  I              : Byte;
Begin
//  WatchDogLED := OFF;
  For I := 1 to 3 do
    RedLED := 0;
    mdelay(200);
    RedLED := 1;
    mdelay(200);
  Endfor;
End;

{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin
  InitPorts;
  EnableInts;
  Writeln(Serout,'Start.');
  StartupBlinks;

  With IP_Core do
    StrToIP('10.0.0.250', IP);
    StrToIP('255.255.255.0', Mask);
    StrToIP('10.0.0.1', GateWay);
    StrToMac('00-A0-A1-A2-A3-A4', MAC);
    ResponsePing         := True;
    RXBroadcast          := True;
    RXCheckSumCheck      := True;
    SendICMPCtrlMessages := False;
  Endwith;

  IF NOT W5100_Init(1500) then
   Repeat
       Writeln(Serout,'W5100 failed to respond?');
//     Beepout(200,100);  // W5100 failed to respond.
     mdelay(1000);
   Until W5100_Init(1500);
  endif;

// =======================================================
  // Define TCP Server Socket connection parameters

  pWEBServer := @WEBServer;
  With pWEBServer^ do
    SocketNo   := 0 ;               // 0 or 1 or 2 or 3
    Protocol   := pTCP;
    DelayAck   := NoDelayedAck;           // TCP Only
    LocalPort  := 8080;
//    StrToIP('10.0.0.101', RemoteHost);             // Only required for TCP Client Mode. NOT TCP Server Mode
//    RemotePort := 270;                             // Only required for TCP Client Mode. NOT TCP Server Mode
    PacketInfo.TxBufferPtr := @WEBServerBuf;
    PacketInfo.RxBufferPtr := @WEBServerBuf;
    PacketInfo.BufferLen   := SizeOf(tTCPServerBuffer);
  endwith;

  //OpenSocket(pWEBServer);
  //TCP_Listen(pWEBServer);
  Process_TCP_State_Machine(pWEBServer) ;
// =======================================================
//  WatchDogStart;
  loop
      If Process_TCP_State_Machine(pWEBServer) then
        // We have a connection established and received data
        Writeln(Serout,'Rx Data');
        If TCP_Recv(pWebServer) then
           Inc(WebPageCounter);
           WebPage := WebPageContent + InttoStr(WebPageCounter:5) + #13+#10;
           copyblock(@WebServerBuf,@St_Rx+1,Word(IP_DataAv(pWebServer)));
           St_Rx[0] := Char(IP_DataAv(pWebServer));
           Writeln(Serout,'Count = '+InttoStr(WebPageCounter:5));

//           writeln(serout,'WEB Server Rx ='+St_Rx+'.');
//           writeln(serout,'WEB Server Rx ='+inttostr(WebServer.RxPacketSize));

           if compareblock(@WebServerBuf,@WEBGetCommand+1,5) then     // 'GET /' received
              copyblock(@WebPage+1,@WebServerBuf,Word(WebPage[0]));
              TCP_Send(pWebServer,Word(WebPage[0]));
           Endif;
           TCP_DisConnect(pWebServer);
         EndIf;
      EndIf;
  //  WatchDogTrig;
    mdelay(100); // Don't need to hammer the W5100

  endloop;
end Ethernet_TwentyTen.

rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Webserver Summer Project

 · 
Posted: 29.12.2010 - 17:32  ·  #3
Hello Neil,

do you use the Merlin Optimiser???
It removes all unused functions from such drivers like FAT16.

rolf
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 29.12.2010 - 23:27  ·  #4
Hi Rolf,

Thanks for responding, I was beginning to the my call for help had fallen on deaf ears :-(
I thought the Optimizer was on by default? The make and Optimize button (Brick wall) is grayed out.
I have put the compiler switch in {$OPTIMISE} after the program name line and it has made no difference.
Still adds 35K to a project. All I've put into the source code is the FAT16 import and the three lines in the define section.
NOTHING else. and yet it adds 35K??

Is the Optimizer turned OFF for this unit?

Neil.
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 29.12.2010 - 23:59  ·  #5
Hi Neil,

look at the end of your Ethernet_TwentyTen.asm!
You should see some remarks of the optiomizer:

; Merlin Optimiser V x.x.x removed ...

Gunter
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 30.12.2010 - 00:11  ·  #6
Hi Gunter/Rolf,

Starting to get some where :-)
In the system Admin, the parameters for the Optimiser were not put in (Lines 8&9 were empty) .
I have now put them in and select the brick wall icon and now it compiles.
Shouldn't the optimiser be compiled in automatically each time? Instead of Ctrl+Shift+F9

Gunter,
It now looks like your image in MMC issue

Actually, my Lines 8 & 9 look like -
8. Disasm C:\E-LAB\AVRco\Optimiser\MerlinOptimiser.exe %Mp\%Mb.asm
9. Optimiser C:\E-LAB\AVRco\Optimiser\AVRCoASMOptimiser.exe %Mp\%Mb.asm

Is this correct ????

Neil.
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 30.12.2010 - 00:20  ·  #7
Hi Neil,

no - the Opti is always optional!
Or include compiler switches.
Look at the Opti Change History. Maybe you need only the

v3.0.5.0
New directive {$OPTI SMARTLINK_ONLY} added that behaves similarly to the original linker option SMARTLINK.
WARNING - this optimisation is normally performed anyway. The effect of this directive is to DISABLE all other
optimisations!

Gunter
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: Webserver Summer Project

 · 
Posted: 30.12.2010 - 00:25  ·  #8
Hi Gunter,

I'm starting to see the light :-)
Were my lines 8 & 9 in the System Admin correct? Ie correct EXE etc?

I think I now understand how lines 1 & 3 are also working. This tells the compiler what to include as part of the Make/MakeOpt process.
In one of your posts, your Sys Admin showed the '-R' at the end of line 2. What is this for?

Neil.
  • 1
  • 2
  • Page 1 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   133   147 · Page-Gen-Time: 0.032151s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI