LPC1768 Mini-DK EasyWeb application with SPI TFT output. Started from EasyWebCR and modified for DM9161 PHY support.

Dependencies:   Mini-DK mbed

This is a very basic EasyWeb application.

No error checking is performed during initialisation.

Information

If the webpage is not reachable or the 'Webserver running' message does not appear, press the reset button on the Mini-DK and wait until the message 'Webserver running' appears.
This happens sometimes when powering up the Mini-DK because the DM9161 reset pin is NOT controlled by the LPC1768, it is directly connected to the reset button.

IP adress/mask/gateway in tcpip.h : 192.168.0.200 / 255.255.255.0 / 192.168.0.1

MAC address in ethmac.h : 6-5-4-3-2-1

Committer:
frankvnk
Date:
Tue Jan 15 06:43:51 2013 +0000
Revision:
8:4c3db9231e3f
Parent:
4:5313680c1ef5
DM9161_BMSR - bit 13 define modified

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 3:342aa2cf54e8 1 /******************************************************************
frankvnk 3:342aa2cf54e8 2 ***** *****
frankvnk 3:342aa2cf54e8 3 ***** Name: easyweb.cpp *****
frankvnk 3:342aa2cf54e8 4 ***** Ver.: 1.0 *****
frankvnk 3:342aa2cf54e8 5 ***** Date: 17/12/2012 *****
frankvnk 3:342aa2cf54e8 6 ***** Auth: Frank Vannieuwkerke *****
frankvnk 3:342aa2cf54e8 7 ***** Func: implements a dynamic HTTP-server by using *****
frankvnk 3:342aa2cf54e8 8 ***** the easyWEB-API *****
frankvnk 3:342aa2cf54e8 9 ***** Rewrite from Andreas Dannenberg *****
frankvnk 3:342aa2cf54e8 10 ***** HTWK Leipzig *****
frankvnk 3:342aa2cf54e8 11 ***** university of applied sciences *****
frankvnk 3:342aa2cf54e8 12 ***** Germany *****
frankvnk 3:342aa2cf54e8 13 ***** adannenb@et.htwk-leipzig.de *****
frankvnk 3:342aa2cf54e8 14 ***** *****
frankvnk 3:342aa2cf54e8 15 ******************************************************************/
frankvnk 3:342aa2cf54e8 16
frankvnk 3:342aa2cf54e8 17 #include "stdio.h"
frankvnk 3:342aa2cf54e8 18 #include "mbed.h"
frankvnk 3:342aa2cf54e8 19 #include "Mini_DK.h"
frankvnk 3:342aa2cf54e8 20
frankvnk 3:342aa2cf54e8 21 //#include "stdlib.h"
frankvnk 3:342aa2cf54e8 22 //#include "string.h"
frankvnk 3:342aa2cf54e8 23
frankvnk 3:342aa2cf54e8 24 // SPI TFT
frankvnk 3:342aa2cf54e8 25 // TFT -> mosi, miso, sclk, cs
frankvnk 3:342aa2cf54e8 26 SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT");
frankvnk 3:342aa2cf54e8 27
frankvnk 3:342aa2cf54e8 28
frankvnk 3:342aa2cf54e8 29 #include "easyweb.h"
frankvnk 3:342aa2cf54e8 30 #include "ethmac.h"
frankvnk 3:342aa2cf54e8 31 #include "tcpip.h" // easyWEB TCP/IP stack
frankvnk 3:342aa2cf54e8 32 #include "website.h" // website for our HTTP server (HTML)
frankvnk 3:342aa2cf54e8 33
frankvnk 3:342aa2cf54e8 34 unsigned int aaPagecounter=0;
frankvnk 3:342aa2cf54e8 35 unsigned int adcValue = 0;
frankvnk 3:342aa2cf54e8 36
frankvnk 3:342aa2cf54e8 37 int main (void)
frankvnk 3:342aa2cf54e8 38 {
frankvnk 3:342aa2cf54e8 39
frankvnk 3:342aa2cf54e8 40 TFT.claim(stdout); // send stdout to the TFT display
frankvnk 3:342aa2cf54e8 41 TFT.background(Black); // set background to black
frankvnk 3:342aa2cf54e8 42 TFT.foreground(White); // set chars to white
frankvnk 3:342aa2cf54e8 43 TFT.cls(); // clear the screen
frankvnk 3:342aa2cf54e8 44 TFT.set_font((unsigned char*) Arial12x12); // select the font
frankvnk 3:342aa2cf54e8 45
frankvnk 3:342aa2cf54e8 46 // Display IP/MAC settings stored in tcpip.h and ethmac.h
frankvnk 3:342aa2cf54e8 47 // MAC address : 6-5-4-3-2-1 Stored in ethmac.h (MYMAC_1 to MYMAC_6)
frankvnk 3:342aa2cf54e8 48 // IP address : 192.168.0.200 Stored in tcpip.h (MYIP_1 to MYIP_4)
frankvnk 3:342aa2cf54e8 49 // gateway : 192.168.0.1 Stored in tcpip.h (GWIP_1 to GWIP_1)
frankvnk 3:342aa2cf54e8 50 // mask : 255.255.255.0 Stored in tcpip.h (SUBMASK_1 to SUBMASK_4)
frankvnk 3:342aa2cf54e8 51 TFT.locate(0,0);
frankvnk 4:5313680c1ef5 52 printf("IP address\n");
frankvnk 4:5313680c1ef5 53 printf("%d.%d.%d.%d\n\n",MYIP_1,MYIP_2,MYIP_3,MYIP_4);
frankvnk 4:5313680c1ef5 54 printf("MAC address\n");
frankvnk 4:5313680c1ef5 55 printf("%02X:%02X:%02X:%02X:%02X:%02X\n\n",MYMAC_6, MYMAC_5, MYMAC_4, MYMAC_3, MYMAC_2, MYMAC_1);
frankvnk 4:5313680c1ef5 56 printf("Initialising..please wait..\n\n");
frankvnk 3:342aa2cf54e8 57 TCPLowLevelInit();
frankvnk 3:342aa2cf54e8 58
frankvnk 3:342aa2cf54e8 59 /*
frankvnk 3:342aa2cf54e8 60 *(unsigned char *)RemoteIP = 24; // uncomment those lines to get the
frankvnk 3:342aa2cf54e8 61 *((unsigned char *)RemoteIP + 1) = 8; // quote of the day from a real
frankvnk 3:342aa2cf54e8 62 *((unsigned char *)RemoteIP + 2) = 69; // internet server! (gateway must be
frankvnk 3:342aa2cf54e8 63 *((unsigned char *)RemoteIP + 3) = 7; // set to your LAN-router)
frankvnk 3:342aa2cf54e8 64
frankvnk 3:342aa2cf54e8 65 TCPLocalPort = 2025;
frankvnk 3:342aa2cf54e8 66 TCPRemotePort = TCP_PORT_QOTD;
frankvnk 3:342aa2cf54e8 67
frankvnk 3:342aa2cf54e8 68 TCPActiveOpen();
frankvnk 3:342aa2cf54e8 69
frankvnk 3:342aa2cf54e8 70 while (SocketStatus & SOCK_ACTIVE) // read the quote from memory
frankvnk 3:342aa2cf54e8 71 { // by using the hardware-debugger
frankvnk 3:342aa2cf54e8 72 DoNetworkStuff();
frankvnk 3:342aa2cf54e8 73 }
frankvnk 3:342aa2cf54e8 74 */
frankvnk 3:342aa2cf54e8 75
frankvnk 3:342aa2cf54e8 76 HTTPStatus = 0; // clear HTTP-server's flag register
frankvnk 3:342aa2cf54e8 77
frankvnk 3:342aa2cf54e8 78 TCPLocalPort = TCP_PORT_HTTP; // set port we want to listen to
frankvnk 3:342aa2cf54e8 79
frankvnk 4:5313680c1ef5 80 printf("Webserver running");
frankvnk 3:342aa2cf54e8 81
frankvnk 3:342aa2cf54e8 82 while (1) // repeat forever
frankvnk 3:342aa2cf54e8 83 {
frankvnk 3:342aa2cf54e8 84 if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen(); // listen for incoming TCP-connection
frankvnk 3:342aa2cf54e8 85 DoNetworkStuff(); // handle network and easyWEB-stack
frankvnk 3:342aa2cf54e8 86 // events
frankvnk 3:342aa2cf54e8 87 HTTPServer();
frankvnk 3:342aa2cf54e8 88 }
frankvnk 3:342aa2cf54e8 89 }
frankvnk 3:342aa2cf54e8 90
frankvnk 3:342aa2cf54e8 91 // This function implements a very simple dynamic HTTP-server.
frankvnk 3:342aa2cf54e8 92 // It waits until connected, then sends a HTTP-header and the
frankvnk 3:342aa2cf54e8 93 // HTML-code stored in memory. Before sending, it replaces
frankvnk 3:342aa2cf54e8 94 // some special strings with dynamic values.
frankvnk 3:342aa2cf54e8 95 // NOTE: For strings crossing page boundaries, replacing will
frankvnk 3:342aa2cf54e8 96 // not work. In this case, simply add some extra lines
frankvnk 3:342aa2cf54e8 97 // (e.g. CR and LFs) to the HTML-code.
frankvnk 3:342aa2cf54e8 98
frankvnk 3:342aa2cf54e8 99 void HTTPServer(void)
frankvnk 3:342aa2cf54e8 100 {
frankvnk 3:342aa2cf54e8 101 if (SocketStatus & SOCK_CONNECTED) // check if somebody has connected to our TCP
frankvnk 3:342aa2cf54e8 102 {
frankvnk 3:342aa2cf54e8 103 if (SocketStatus & SOCK_DATA_AVAILABLE) // check if remote TCP sent data
frankvnk 3:342aa2cf54e8 104 TCPReleaseRxBuffer(); // and throw it away
frankvnk 3:342aa2cf54e8 105
frankvnk 3:342aa2cf54e8 106 if (SocketStatus & SOCK_TX_BUF_RELEASED) // check if buffer is free for TX
frankvnk 3:342aa2cf54e8 107 {
frankvnk 3:342aa2cf54e8 108 if (!(HTTPStatus & HTTP_SEND_PAGE)) // init byte-counter and pointer to website
frankvnk 3:342aa2cf54e8 109 { // if called the 1st time
frankvnk 3:342aa2cf54e8 110 HTTPBytesToSend = sizeof(website) - 1; // get HTML length, ignore trailing zero
frankvnk 3:342aa2cf54e8 111 Pwebsite = (unsigned char *)website; // pointer to HTML-code
frankvnk 3:342aa2cf54e8 112 }
frankvnk 3:342aa2cf54e8 113
frankvnk 3:342aa2cf54e8 114 if (HTTPBytesToSend > MAX_TCP_TX_DATA_SIZE) // transmit a segment of MAX_SIZE
frankvnk 3:342aa2cf54e8 115 {
frankvnk 3:342aa2cf54e8 116 if (!(HTTPStatus & HTTP_SEND_PAGE)) // 1st time, include HTTP-header
frankvnk 3:342aa2cf54e8 117 {
frankvnk 3:342aa2cf54e8 118 memcpy(TCP_TX_BUF, GetResponse, sizeof(GetResponse) - 1);
frankvnk 3:342aa2cf54e8 119 memcpy(TCP_TX_BUF + sizeof(GetResponse) - 1, Pwebsite, MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1);
frankvnk 3:342aa2cf54e8 120 HTTPBytesToSend -= MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1;
frankvnk 3:342aa2cf54e8 121 Pwebsite += MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1;
frankvnk 3:342aa2cf54e8 122 }
frankvnk 3:342aa2cf54e8 123 else
frankvnk 3:342aa2cf54e8 124 {
frankvnk 3:342aa2cf54e8 125 memcpy(TCP_TX_BUF, Pwebsite, MAX_TCP_TX_DATA_SIZE);
frankvnk 3:342aa2cf54e8 126 HTTPBytesToSend -= MAX_TCP_TX_DATA_SIZE;
frankvnk 3:342aa2cf54e8 127 Pwebsite += MAX_TCP_TX_DATA_SIZE;
frankvnk 3:342aa2cf54e8 128 }
frankvnk 3:342aa2cf54e8 129
frankvnk 3:342aa2cf54e8 130 TCPTxDataCount = MAX_TCP_TX_DATA_SIZE; // bytes to xfer
frankvnk 3:342aa2cf54e8 131 InsertDynamicValues(); // exchange some strings...
frankvnk 3:342aa2cf54e8 132 TCPTransmitTxBuffer(); // xfer buffer
frankvnk 3:342aa2cf54e8 133 }
frankvnk 3:342aa2cf54e8 134 else if (HTTPBytesToSend) // transmit leftover bytes
frankvnk 3:342aa2cf54e8 135 {
frankvnk 3:342aa2cf54e8 136 memcpy(TCP_TX_BUF, Pwebsite, HTTPBytesToSend);
frankvnk 3:342aa2cf54e8 137 TCPTxDataCount = HTTPBytesToSend; // bytes to xfer
frankvnk 3:342aa2cf54e8 138 InsertDynamicValues(); // exchange some strings...
frankvnk 3:342aa2cf54e8 139 TCPTransmitTxBuffer(); // send last segment
frankvnk 3:342aa2cf54e8 140 TCPClose(); // and close connection
frankvnk 3:342aa2cf54e8 141 HTTPBytesToSend = 0; // all data sent
frankvnk 3:342aa2cf54e8 142 }
frankvnk 3:342aa2cf54e8 143
frankvnk 3:342aa2cf54e8 144 HTTPStatus |= HTTP_SEND_PAGE; // ok, 1st loop executed
frankvnk 3:342aa2cf54e8 145 }
frankvnk 3:342aa2cf54e8 146 }
frankvnk 3:342aa2cf54e8 147 else
frankvnk 3:342aa2cf54e8 148 HTTPStatus &= ~HTTP_SEND_PAGE; // reset help-flag if not connected
frankvnk 3:342aa2cf54e8 149 }
frankvnk 3:342aa2cf54e8 150
frankvnk 3:342aa2cf54e8 151 // Pseudo AD convertor, we simply increment a counter
frankvnk 3:342aa2cf54e8 152 // when the function is called, wrapping at 1024.
frankvnk 3:342aa2cf54e8 153 volatile unsigned int aaScrollbar = 400;
frankvnk 3:342aa2cf54e8 154
frankvnk 3:342aa2cf54e8 155 unsigned int GetAD7Val(void)
frankvnk 3:342aa2cf54e8 156 {
frankvnk 3:342aa2cf54e8 157 aaScrollbar = (aaScrollbar +16) % 1024;
frankvnk 3:342aa2cf54e8 158 adcValue = (aaScrollbar / 10) * 1000/1024;
frankvnk 3:342aa2cf54e8 159 return aaScrollbar;
frankvnk 3:342aa2cf54e8 160 }
frankvnk 3:342aa2cf54e8 161
frankvnk 3:342aa2cf54e8 162 void InsertDynamicValues(void)
frankvnk 3:342aa2cf54e8 163 {
frankvnk 3:342aa2cf54e8 164 unsigned char *Key;
frankvnk 3:342aa2cf54e8 165 char NewKey[6];
frankvnk 3:342aa2cf54e8 166 unsigned int i;
frankvnk 3:342aa2cf54e8 167
frankvnk 3:342aa2cf54e8 168 if (TCPTxDataCount < 4) return; // there can't be any special string
frankvnk 3:342aa2cf54e8 169
frankvnk 3:342aa2cf54e8 170 Key = TCP_TX_BUF;
frankvnk 3:342aa2cf54e8 171
frankvnk 3:342aa2cf54e8 172 for (i = 0; i < (TCPTxDataCount - 3); i++)
frankvnk 3:342aa2cf54e8 173 {
frankvnk 3:342aa2cf54e8 174 if (*Key == 'A')
frankvnk 3:342aa2cf54e8 175 if (*(Key + 1) == 'D')
frankvnk 3:342aa2cf54e8 176 if (*(Key + 3) == '%')
frankvnk 3:342aa2cf54e8 177 switch (*(Key + 2))
frankvnk 3:342aa2cf54e8 178 {
frankvnk 3:342aa2cf54e8 179 case '8' : // "AD8%"?
frankvnk 3:342aa2cf54e8 180 {
frankvnk 3:342aa2cf54e8 181 sprintf(NewKey, "%04d", GetAD7Val()); // insert pseudo-ADconverter value
frankvnk 3:342aa2cf54e8 182 memcpy(Key, NewKey, 4);
frankvnk 3:342aa2cf54e8 183 break;
frankvnk 3:342aa2cf54e8 184 }
frankvnk 3:342aa2cf54e8 185 case '7' : // "AD7%"?
frankvnk 3:342aa2cf54e8 186 {
frankvnk 3:342aa2cf54e8 187 sprintf(NewKey, "%3u", adcValue); // copy saved value from previous read
frankvnk 3:342aa2cf54e8 188 memcpy(Key, NewKey, 3);
frankvnk 3:342aa2cf54e8 189 break;
frankvnk 3:342aa2cf54e8 190 }
frankvnk 3:342aa2cf54e8 191 case '1' : // "AD1%"?
frankvnk 3:342aa2cf54e8 192 {
frankvnk 3:342aa2cf54e8 193 sprintf(NewKey, "%4u", ++aaPagecounter); // increment and insert page counter
frankvnk 3:342aa2cf54e8 194 memcpy(Key, NewKey, 4);
frankvnk 3:342aa2cf54e8 195 // *(Key + 3) = ' ';
frankvnk 3:342aa2cf54e8 196 break;
frankvnk 3:342aa2cf54e8 197 }
frankvnk 3:342aa2cf54e8 198 }
frankvnk 3:342aa2cf54e8 199 Key++;
frankvnk 3:342aa2cf54e8 200 }
frankvnk 3:342aa2cf54e8 201 }