diff --git a/Makefile b/Makefile index 1cce738..6862527 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,6 @@ html_data.c html_data.h: html tools tools/fileadder -a -s -b BANK1 -d html -p html_data httpd: html_data.h - $(MAKE) -C $@ $(SUBDIRS): $(MAKE) -C $@ diff --git a/httpd/httpd.c b/httpd/httpd.c index b7b3492..8eff8d3 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -12,10 +12,7 @@ extern __code struct f_data f_data[]; extern __code fcall_ptr f_calls[]; -__xdata uint8_t outbuf[2048]; __xdata uint8_t entry; -__xdata uint16_t slen; -__xdata uint16_t o_idx; __xdata uint16_t mpos; __xdata uint16_t len_left; @@ -60,6 +57,7 @@ uint8_t find_entry(uint8_t *e) void httpd_appcall(void) { __xdata struct httpd_state *s = &(uip_conn->appstate); + __xdata uint8_t *outbuf = s->outbuf; write_char('P'); if(uip_connected() && s->tstate == TSTATE_CLOSED) { @@ -77,24 +75,24 @@ void httpd_appcall(void) // write_char('p'); } else if (uip_acked() && s->tstate == TSTATE_TX) { print_string("ACK\n"); - if (slen > uip_mss()) { - slen -= uip_mss(); - o_idx += uip_mss(); + if (s->slen > uip_mss()) { + s->slen -= uip_mss(); + s->o_idx += uip_mss(); } else { - slen = 0; - o_idx += slen; + s->slen = 0; + s->o_idx += s->slen; } s->tstate = TSTATE_ACKED; - if (slen > uip_mss()) { - print_string("Sending A: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, uip_mss()); + if (s->slen > uip_mss()) { + print_string("Sending A: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, uip_mss()); print_string("Sending A done\n"); s->tstate = TSTATE_TX; - } else if (slen > 0) { - print_string("Sending B: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, slen); + } else if (s->slen > 0) { + print_string("Sending B: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, s->slen); print_string("Sending B done\n"); s->tstate = TSTATE_TX; } @@ -121,14 +119,14 @@ void httpd_appcall(void) print_string("Entry is: "); print_byte(entry); write_char('\n'); if (entry == 0xff) { print_string("Not found\n"); - slen = strtox(outbuf, "HTTP/1.1 404 Not found\r\nContent-Type: text/html\r\n\r\n"); - print_string("slen: "); print_short(slen); write_char('\n'); - slen += strtox(outbuf + slen, "\n404 Not Found\n

Not Found

\n"); + s->slen = strtox(outbuf, "HTTP/1.1 404 Not found\r\nContent-Type: text/html\r\n\r\n"); + print_string("slen: "); print_short(s->slen); write_char('\n'); + s->slen += strtox(outbuf + s->slen, "\n404 Not Found\n

Not Found

\n"); } else { print_string("Have entry\n"); - slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: "); - slen += strtox(outbuf + slen, f_data[entry].mime); - slen += strtox(outbuf + slen, "\r\n\r\n"); + s->slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: "); + s->slen += strtox(outbuf + s->slen, f_data[entry].mime); + s->slen += strtox(outbuf + s->slen, "\r\n\r\n"); len_left = f_data[entry].len; if (f_data[entry].mime[0] == 't' && f_data[entry].mime[5] == 'h') { print_string("MIME is html len is "); print_short(len_left); write_char('\n'); @@ -139,49 +137,49 @@ void httpd_appcall(void) print_string("Entry-len:"); print_short(len_left); write_char('\n'); mpos = len_left - mpos; print_string("l/pos: "); print_short(mpos); write_char('\n'); - flash_read_bulk(outbuf + slen, f_data[entry].start + f_data[entry].len - len_left, mpos + CMARK_S); // call marker is e.g. #{001} - slen += mpos; - write_char('@'); write_char(outbuf[slen + 2]); write_char(outbuf[slen + 3]); write_char(outbuf[slen + 4]); - fcall_ptr ptr = f_calls[(outbuf[slen + 2] - '0') * 100 + (outbuf[slen + 3]-'0') * 10 + outbuf[slen + 4] - '0']; - slen -= CMARK_S; // Overwrite marker with generated html + flash_read_bulk(outbuf + s->slen, f_data[entry].start + f_data[entry].len - len_left, mpos + CMARK_S); // call marker is e.g. #{001} + s->slen += mpos; + write_char('@'); write_char(outbuf[s->slen + 2]); write_char(outbuf[s->slen + 3]); write_char(outbuf[s->slen + 4]); + fcall_ptr ptr = f_calls[(outbuf[s->slen + 2] - '0') * 100 + (outbuf[s->slen + 3]-'0') * 10 + outbuf[s->slen + 4] - '0']; + s->slen -= CMARK_S; // Overwrite marker with generated html print_string("Call location is: "); print_short((uint16_t)ptr); write_char('\n'); -// f_calls[outbuf[slen + 2] * 100 + outbuf[slen + 3] * 10 + outbuf[slen + 4]](); - ptr(); +// f_calls[outbuf[s->slen + 2] * 100 + outbuf[s->slen + 3] * 10 + outbuf[s->slen + 4]](); + ptr(outbuf); print_string("call done\n"); mpos += CMARK_S; len_left -= mpos; flash_find_mark(f_data[entry].start + mpos, len_left, "#{"); } print_string("At end mpos: "); print_short(mpos); write_char('\n'); - flash_read_bulk(outbuf + slen, f_data[entry].start + f_data[entry].len - len_left, len_left); - slen += len_left; + flash_read_bulk(outbuf + s->slen, f_data[entry].start + f_data[entry].len - len_left, len_left); + s->slen += len_left; } else { print_string("MIME: "); print_string(f_data[entry].mime); write_char('\n'); - flash_read_bulk(outbuf + slen, f_data[entry].start, len_left); - slen += len_left; + flash_read_bulk(outbuf + s->slen, f_data[entry].start, len_left); + s->slen += len_left; } } - print_string("slen: "); print_short(slen); write_char('\n'); - o_idx = 0; - if (slen > uip_mss()) { - print_string("Sending a: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, uip_mss()); + print_string("slen: "); print_short(s->slen); write_char('\n'); + s->o_idx = 0; + if (s->slen > uip_mss()) { + print_string("Sending a: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, uip_mss()); print_string("Sending a done\n"); } else { - print_string("Sending b: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, slen); + print_string("Sending b: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, s->slen); print_string("Sending b done\n"); } s->tstate = TSTATE_TX; } else if (uip_rexmit()) { // Connection established, need to rexmit? print_string("RETRANSMIT requested\n"); - if (slen > uip_mss()) { - print_string("Sending C: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, uip_mss()); + if (s->slen > uip_mss()) { + print_string("Sending C: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, uip_mss()); print_string("Sending C done\n"); - } else if (slen > 0) { - print_string("Sending D: "); print_short(slen); write_char('\n'); - uip_send(outbuf + o_idx, slen); + } else if (s->slen > 0) { + print_string("Sending D: "); print_short(s->slen); write_char('\n'); + uip_send(outbuf + s->o_idx, s->slen); print_string("Sending D done\n"); } s->tstate = TSTATE_TX; diff --git a/httpd/httpd.h b/httpd/httpd.h index 59ed289..8f84a0c 100644 --- a/httpd/httpd.h +++ b/httpd/httpd.h @@ -12,6 +12,9 @@ for each TCP connection. */ typedef struct httpd_state { uint8_t tstate; + uint8_t outbuf[2048]; + uint16_t slen; + uint16_t o_idx; } uip_tcp_appstate_t; /* Finally we define the application function to be called by uIP. */ diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 67ce46b..62cbb5d 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -4,81 +4,75 @@ #pragma codeseg BANK1 -extern __xdata uint8_t outbuf[2048]; -extern __xdata uint16_t slen; extern __code uint8_t * __code hex; extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; extern __code uint8_t ownMAC[]; -inline void byte_to_html(uint8_t a) -{ - outbuf[slen++] = hex[(a >> 4) & 0xf]; - outbuf[slen++] = hex[a & 0xf]; -} +#define PUTC(c) *outbuf++ = c; +#define PUTBYTE(a) { *outbuf++ = hex[(a >> 4) & 0xf]; *outbuf++ = hex[a & 0xf]; } -inline void char_to_html(char c) -{ - outbuf[slen++] = c; -} - - -inline void itoa_html(uint8_t v) +inline uint8_t itoa_html(uint8_t v, __xdata uint8_t *outbuf) { uint8_t t = (v / 100) % 10; if (t) - char_to_html('0' + t); + PUTC('0' + t); t = (v / 10) % 10; if (t) - char_to_html('0' + t); - char_to_html('0' + (v % 10)); + PUTC('0' + t); + PUTC('0' + (v % 10)); + + if (v >= 100) + return 3; + else if (v >= 10) + return 2; + else + return 1; } -uint16_t stat_content(void) +uint16_t stat_content(__xdata uint8_t *outbuf) { print_string("stat_content called\n"); return 0; } -uint16_t port_status(void) +uint16_t port_status(__xdata uint8_t *outbuf) { print_string("port_status called\n"); return 0; } -uint16_t html_index(void) +uint16_t html_index(__xdata uint8_t *outbuf) { + __xdata uint8_t *oldptr = outbuf; + print_string("html_index called\n"); - slen += strtox(outbuf + slen, "IP Address"); - print_string("\nIP:"); - print_byte(uip_hostaddr[0]); write_char('.'); - print_byte(uip_hostaddr[0] >> 8); write_char('.'); - print_byte(uip_hostaddr[1]); write_char('.'); - print_byte(uip_hostaddr[1] >> 8); write_char('\n'); - itoa_html(uip_hostaddr[0]); char_to_html('.'); - itoa_html(uip_hostaddr[0] >> 8); char_to_html('.'); - itoa_html(uip_hostaddr[1]); char_to_html('.'); - itoa_html(uip_hostaddr[1]); - slen += strtox(outbuf + slen, "Gateway"); - itoa_html(uip_draddr[0]); char_to_html('.'); - itoa_html(uip_draddr[0] >> 8); char_to_html('.'); - itoa_html(uip_draddr[1]); char_to_html('.'); - itoa_html(uip_draddr[1] >> 8); - slen += strtox(outbuf + slen, "Netmask"); - itoa_html(uip_netmask[0]); char_to_html('.'); - itoa_html(uip_netmask[0] >> 8); char_to_html('.'); - itoa_html(uip_netmask[1]); char_to_html('.'); - itoa_html(uip_netmask[1] >> 8); - slen += strtox(outbuf + slen, "MAC Address"); - byte_to_html(ownMAC[0]); char_to_html(':'); - byte_to_html(ownMAC[1]); char_to_html(':'); - byte_to_html(ownMAC[2]); char_to_html(':'); - byte_to_html(ownMAC[3]); char_to_html(':'); - byte_to_html(ownMAC[4]); char_to_html(':'); - byte_to_html(ownMAC[5]); - slen += strtox(outbuf + slen, ""); - return 0; + outbuf += strtox(outbuf, "IP Address"); + outbuf += itoa_html(uip_hostaddr[0], outbuf); PUTC('.'); + outbuf += itoa_html(uip_hostaddr[0] >> 8, outbuf); PUTC('.'); + outbuf += itoa_html(uip_hostaddr[1], outbuf); PUTC('.'); + outbuf += itoa_html(uip_hostaddr[1] >> 8, outbuf); + outbuf += strtox(outbuf, "Gateway"); + outbuf += itoa_html(uip_draddr[0], outbuf); PUTC('.'); + outbuf += itoa_html(uip_draddr[0] >> 8, outbuf); PUTC('.'); + outbuf += itoa_html(uip_draddr[1], outbuf); PUTC('.'); + outbuf += itoa_html(uip_draddr[1] >> 8, outbuf); + outbuf += strtox(outbuf, "Netmask"); + outbuf += itoa_html(uip_netmask[0], outbuf); PUTC('.'); + outbuf += itoa_html(uip_netmask[0] >> 8, outbuf); PUTC('.'); + outbuf += itoa_html(uip_netmask[1], outbuf); PUTC('.'); + outbuf += itoa_html(uip_netmask[1] >> 8, outbuf); + outbuf += strtox(outbuf, "MAC Address"); + PUTBYTE(ownMAC[0]); PUTC(':'); + PUTBYTE(ownMAC[1]); PUTC(':'); + PUTBYTE(ownMAC[2]); PUTC(':'); + PUTBYTE(ownMAC[3]); PUTC(':'); + PUTBYTE(ownMAC[4]); PUTC(':'); + PUTBYTE(ownMAC[5]); + outbuf += strtox(outbuf, ""); + + return outbuf - oldptr; } diff --git a/tools/fileadder.c b/tools/fileadder.c index eff98b7..6bc27ab 100644 --- a/tools/fileadder.c +++ b/tools/fileadder.c @@ -200,7 +200,7 @@ int replaceCalls(int pos) buffer[pos + i + 5] = '}'; i += 6; fbuf_p += snprintf(&fbuf[fbuf_p], DEF_SIZE - fbuf_p, " %s,\n", function_buf); - xbuf_p += snprintf(&xbuf[xbuf_p], DEF_SIZE - xbuf_p, "extern uint16_t %s(void);\n", function_buf); + xbuf_p += snprintf(&xbuf[xbuf_p], DEF_SIZE - xbuf_p, "extern uint16_t %s(__xdata uint8_t *outbuf);\n", function_buf); callNum++; } i++; @@ -266,7 +266,7 @@ int main(int argc, char **argv) defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "#define FDATA_DEFS_H\n\n"); defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "#include \n\n"); defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "struct f_data {\n __code char *file;\n uint32_t start;\n uint16_t len;\n __code char *mime;\n};\n\n"); - defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "typedef uint16_t (* fcall_ptr)(void);\n\n"); + defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "typedef uint16_t (* fcall_ptr)(__xdata uint8_t *outbuf);\n\n"); ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "// This file is automatically generated, do not edit!\n\n"); if (arguments.prefix) diff --git a/uip/uip-conf.h b/uip/uip-conf.h index 08f7439..b92c0f8 100644 --- a/uip/uip-conf.h +++ b/uip/uip-conf.h @@ -94,14 +94,14 @@ typedef unsigned short uip_stats_t; * * \hideinitializer */ -#define UIP_CONF_MAX_CONNECTIONS 1 +#define UIP_CONF_MAX_CONNECTIONS 3 /** * Maximum number of listening TCP ports. TODO: increase this! * * \hideinitializer */ -#define UIP_CONF_MAX_LISTENPORTS 1 +#define UIP_CONF_MAX_LISTENPORTS 3 /** * uIP buffer size.