URL
https://opencores.org/ocsvn/turbo8051/turbo8051/trunk
Subversion Repositories turbo8051
Compare Revisions
- This comparison shows the changes necessary to convert path
/turbo8051
- from Rev 45 to Rev 46
- ↔ Reverse comparison
Rev 45 → Rev 46
/trunk/apps/avr-webserver/arp.h
File deleted
/trunk/apps/avr-webserver/udp.c
File deleted
/trunk/apps/avr-webserver/icmp.c
File deleted
/trunk/apps/avr-webserver/struct.h
File deleted
/trunk/apps/avr-webserver/read.me
File deleted
/trunk/apps/avr-webserver/homepage.htm
File deleted
\ No newline at end of file
/trunk/apps/avr-webserver/udp.h
File deleted
/trunk/apps/avr-webserver/icmp.h
File deleted
/trunk/apps/avr-webserver/enc28j60.c
File deleted
/trunk/apps/avr-webserver/avrnet.aps
File deleted
/trunk/apps/avr-webserver/lcd.c
File deleted
/trunk/apps/avr-webserver/ReadmeEN.html
File deleted
\ No newline at end of file
/trunk/apps/avr-webserver/default/Makefile
File deleted
/trunk/apps/avr-webserver/enc28j60.h
File deleted
/trunk/apps/avr-webserver/lcd.h
File deleted
/trunk/apps/avr-webserver/ip.c
File deleted
/trunk/apps/avr-webserver/ReadmeTH.html
File deleted
\ No newline at end of file
/trunk/apps/avr-webserver/ip.h
File deleted
/trunk/apps/avr-webserver/http.c
File deleted
/trunk/apps/avr-webserver/AVRnetCPannel.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
trunk/apps/avr-webserver/AVRnetCPannel.gif
Property changes :
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
Index: trunk/apps/avr-webserver/http.h
===================================================================
--- trunk/apps/avr-webserver/http.h (revision 45)
+++ trunk/apps/avr-webserver/http.h (nonexistent)
@@ -1,38 +0,0 @@
-//********************************************************************************************
-//
-// File : http.h implement for Hyper Text transfer Protocol
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-
-//********************************************************************************************
-//
-// Prototype function
-//
-//********************************************************************************************
-extern WORD http_home( BYTE *rxtx_buffer );
-extern BYTE http_get_variable ( BYTE *rxtx_buffer, WORD dlength, PGM_P val_key, BYTE *dest );
-extern BYTE http_get_ip ( BYTE *buf, BYTE *dest );
-extern void urldecode( BYTE *urlbuf);
-extern void http_webserver_process ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip );
-extern WORD http_put_request ( BYTE *rxtx_buffer );
Index: trunk/apps/avr-webserver/avrnet.pnproj
===================================================================
--- trunk/apps/avr-webserver/avrnet.pnproj (revision 45)
+++ trunk/apps/avr-webserver/avrnet.pnproj (nonexistent)
@@ -1 +0,0 @@
-
\ No newline at end of file
Index: trunk/apps/avr-webserver/tcp.c
===================================================================
--- trunk/apps/avr-webserver/tcp.c (revision 45)
+++ trunk/apps/avr-webserver/tcp.c (nonexistent)
@@ -1,246 +0,0 @@
-//********************************************************************************************
-//
-// File : tcp.c implement for Transmission Control Protocol
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#include "includes.h"
-//********************************************************************************************
-//
-// +------------+-----------+------------+----------+
-// + MAC header + IP header + TCP header + Data ::: +
-// +------------+-----------+------------+----------+
-//
-// TCP Header
-//
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Source Port + Destination Port +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Sequence Number +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Acknowledgment Number +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// +Data Offset+reserved+ ECN + Control Bits + Window size +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Checksum + Urgent Pointer +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Options and padding ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Data ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-//
-//********************************************************************************************
-
-// global variables ***********************************************************************
-static BYTE seqnum=0xa; // my initial tcp sequence number
-//static DWORD_BYTES tcp_sequence_number;
-
-//*****************************************************************************************
-//
-// Function : tcp_get_dlength
-// Description : claculate tcp received data length
-//
-//*****************************************************************************************
-WORD tcp_get_dlength ( BYTE *rxtx_buffer )
-{
- int dlength, hlength;
-
- dlength = ( rxtx_buffer[ IP_TOTLEN_H_P ] <<8 ) | ( rxtx_buffer[ IP_TOTLEN_L_P ] );
- dlength -= sizeof(IP_HEADER);
- hlength = (rxtx_buffer[ TCP_HEADER_LEN_P ]>>4) * 4; // generate len in bytes;
- dlength -= hlength;
- if ( dlength <= 0 )
- dlength=0;
-
- return ((WORD)dlength);
-}
-//*****************************************************************************************
-//
-// Function : tcp_get_hlength
-// Description : claculate tcp received header length
-//
-//*****************************************************************************************
-BYTE tcp_get_hlength ( BYTE *rxtx_buffer )
-{
- return ((rxtx_buffer[ TCP_HEADER_LEN_P ]>>4) * 4); // generate len in bytes;
-}
-//********************************************************************************************
-//
-// Function : tcp_puts_data_p
-// Description : puts data from program memory to tx buffer
-//
-//********************************************************************************************
-WORD tcp_puts_data_p ( BYTE *rxtx_buffer, PGM_P data, WORD offset )
-{
- BYTE ch;
-
- while( (ch = pgm_read_byte(data++)) )
- {
- rxtx_buffer[ TCP_DATA_P + offset ] = ch;
- offset++;
- }
-
- return offset;
-}
-//********************************************************************************************
-//
-// Function : tcp_puts_data
-// Description : puts data from RAM to tx buffer
-//
-//********************************************************************************************
-WORD tcp_puts_data ( BYTE *rxtx_buffer, BYTE *data, WORD offset )
-{
- while( *data )
- {
- rxtx_buffer[ TCP_DATA_P + offset ] = *data++;
- offset++;
- }
-
- return offset;
-}
-//********************************************************************************************
-//
-// Function : tcp_send_packet
-// Description : send tcp packet to network.
-//
-//********************************************************************************************
-void tcp_send_packet (
- BYTE *rxtx_buffer,
- WORD_BYTES dest_port,
- WORD_BYTES src_port,
- BYTE flags,
- BYTE max_segment_size,
- BYTE clear_seqack,
- WORD next_ack_num,
- WORD dlength,
- BYTE *dest_mac,
- BYTE *dest_ip )
-{
- BYTE i, tseq;
- WORD_BYTES ck;
-
- // generate ethernet header
- eth_generate_header ( rxtx_buffer, (WORD_BYTES){ETH_TYPE_IP_V}, dest_mac );
-
- // sequence numbers:
- // add the rel ack num to SEQACK
- if ( next_ack_num )
- {
- for( i=4; i>0; i-- )
- {
- next_ack_num = rxtx_buffer [ TCP_SEQ_P + i - 1] + next_ack_num;
- tseq = rxtx_buffer [ TCP_SEQACK_P + i - 1];
- rxtx_buffer [ TCP_SEQACK_P + i - 1] = 0xff & next_ack_num;
-
- // copy the acknum sent to us into the sequence number
- rxtx_buffer[ TCP_SEQ_P + i - 1 ] = tseq;
-
- next_ack_num >>= 8;
- }
- }
-
- // initial tcp sequence number
- // setup maximum segment size
- // require to setup first packet is receive or transmit only
- if ( max_segment_size )
- {
- // initial sequence number
- rxtx_buffer[ TCP_SEQ_P + 0 ] = 0;
- rxtx_buffer[ TCP_SEQ_P + 1 ] = 0;
- rxtx_buffer[ TCP_SEQ_P + 2 ] = seqnum;
- rxtx_buffer[ TCP_SEQ_P + 3 ] = 0;
- seqnum += 2;
-
- // setup maximum segment size
- rxtx_buffer[ TCP_OPTIONS_P + 0 ] = 2;
- rxtx_buffer[ TCP_OPTIONS_P + 1 ] = 4;
- rxtx_buffer[ TCP_OPTIONS_P + 2 ] = HIGH(1408);
- rxtx_buffer[ TCP_OPTIONS_P + 3 ] = LOW(1408);
- // setup tcp header length 24 bytes: 6*32/8 = 24
- rxtx_buffer[ TCP_HEADER_LEN_P ] = 0x60;
- dlength += 4;
- }
- else
- {
- // no options: 20 bytes: 5*32/8 = 20
- rxtx_buffer[ TCP_HEADER_LEN_P ] = 0x50;
- }
-
- // generate ip header and checksum
- ip_generate_header ( rxtx_buffer, (WORD_BYTES){(sizeof(IP_HEADER) + sizeof(TCP_HEADER) + dlength)}, IP_PROTO_TCP_V, dest_ip );
-
- // clear sequence ack number before send tcp SYN packet
- if ( clear_seqack )
- {
- rxtx_buffer[ TCP_SEQACK_P + 0 ] = 0;
- rxtx_buffer[ TCP_SEQACK_P + 1 ] = 0;
- rxtx_buffer[ TCP_SEQACK_P + 2 ] = 0;
- rxtx_buffer[ TCP_SEQACK_P + 3 ] = 0;
- }
-
- // setup tcp flags
- rxtx_buffer [ TCP_FLAGS_P ] = flags;
-
- // setup destination port
- rxtx_buffer [ TCP_DST_PORT_H_P ] = dest_port.byte.high;
- rxtx_buffer [ TCP_DST_PORT_L_P ] = dest_port.byte.low;
-
- // setup source port
- rxtx_buffer [ TCP_SRC_PORT_H_P ] = src_port.byte.high;
- rxtx_buffer [ TCP_SRC_PORT_L_P ] = src_port.byte.low;
-
- // setup maximum windows size
- rxtx_buffer [ TCP_WINDOWSIZE_H_P ] = HIGH((MAX_RX_BUFFER-sizeof(IP_HEADER)-sizeof(ETH_HEADER)));
- rxtx_buffer [ TCP_WINDOWSIZE_L_P ] = LOW((MAX_RX_BUFFER-sizeof(IP_HEADER)-sizeof(ETH_HEADER)));
-
- // setup urgend pointer (not used -> 0)
- rxtx_buffer[ TCP_URGENT_PTR_H_P ] = 0;
- rxtx_buffer[ TCP_URGENT_PTR_L_P ] = 0;
-
- // clear old checksum and calculate new checksum
- rxtx_buffer[ TCP_CHECKSUM_H_P ] = 0;
- rxtx_buffer[ TCP_CHECKSUM_L_P ] = 0;
- // This is computed as the 16-bit one's complement of the one's complement
- // sum of a pseudo header of information from the
- // IP header, the TCP header, and the data, padded
- // as needed with zero bytes at the end to make a multiple of two bytes.
- // The pseudo header contains the following fields:
- //
- // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- // +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+
- // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- // + Source IP address +
- // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- // + Destination IP address +
- // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- // + 0 + IP Protocol + Total length +
- // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
- ck.word = software_checksum( &rxtx_buffer[IP_SRC_IP_P], sizeof(TCP_HEADER)+dlength+8, IP_PROTO_TCP_V + sizeof(TCP_HEADER) + dlength );
- rxtx_buffer[ TCP_CHECKSUM_H_P ] = ck.byte.high;
- rxtx_buffer[ TCP_CHECKSUM_L_P ] = ck.byte.low;
-
- // send packet to ethernet media
- enc28j60_packet_send ( rxtx_buffer, sizeof(ETH_HEADER)+sizeof(IP_HEADER)+sizeof(TCP_HEADER)+dlength );
-}
Index: trunk/apps/avr-webserver/adc.c
===================================================================
--- trunk/apps/avr-webserver/adc.c (revision 45)
+++ trunk/apps/avr-webserver/adc.c (nonexistent)
@@ -1,143 +0,0 @@
-//********************************************************************************************
-//
-// File : adc.c implement for on-board temparature sensor and ADC0
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#include "includes.h"
-// Thermistor resistance and ADC calculation.
-//
-// Rntc = R0 * exp B(1/T - 1/T0)
-//
-// R0 : Zero resistance @ 25 degree celsius.
-// B : constant value (see datasheet)
-// T0 : Zero temparature in Kevin
-//
-// constant from TTC05's datasheet : R0 = 10kOhm, B = 4050K, T0 = 25+273.15
-//
-// Rntc
-// Vref o-----/\/\/-------
-// |------o Vout
-// 0V o-----/\/\/-------
-// Rout
-// Rout = 10k
-// Vout = (2.56 * 10000.0) / (10000.0 + Rntc)
-// ADC = (Vout / 2.56) * 1024.0
-//
-// 2.56 is Internal Vref
-//
-// below table are ADC values, calculate from T=0 to T=99
-prog_uint16_t temp_list[100] =
-{
-229, 239, 249, 259, 270, 280, 291, 302, 313, 324,
-335, 347, 358, 370, 382, 394, 405, 417, 429, 441,
-453, 465, 477, 489, 500, 512, 524, 535, 547, 558,
-569, 580, 591, 602, 613, 623, 633, 644, 654, 663,
-673, 682, 692, 701, 710, 718, 727, 735, 743, 751,
-759, 766, 774, 781, 788, 795, 801, 808, 814, 820,
-826, 832, 837, 843, 848, 853, 858, 863, 867, 872,
-876, 881, 885, 889, 893, 897, 900, 904, 907, 911,
-914, 917, 920, 923, 926, 929, 931, 934, 936, 939,
-941, 944, 946, 948, 950, 952, 954, 956, 958, 960,
-};
-//********************************************************************************************
-//
-// Function : adc_read
-// Description : read ADC value, select ADC channel to read by channel argument
-//
-//********************************************************************************************
-WORD adc_read ( BYTE channel )
-{
- // Analog channel selection
- ADMUX = ((ADMUX) & ~0x1f) | (channel & 0x1f);
-
- // Start conversion
- ADCSRA |= _BV(ADSC);
-
- // Wait until conversion complete
- while( bit_is_set(ADCSRA, ADSC) );
-
- // CAUTION: READ ADCL BEFORE ADCH!!!
- return ((ADCL) | ((ADCH)<<8));
-}
-//********************************************************************************************
-//
-// Function : adc_init
-// Description : Initial analog to digital convertion
-//
-//********************************************************************************************
-//void adc_init ( void ) __attribute__ ((naked));
-void adc_init ( void )
-{
- //BYTE i;
-
- // ADC enable, Prescaler divide by 128, ADC clock = 16MHz/128 = 125kHz
- ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
-
- // Select Vref, internal Vref 2.56V and external capacitor
- ADMUX = _BV(REFS1) | _BV(REFS0);
-
- // reading temparature
- //for ( i=0; i<32; i++ )
- // adc_read_temp ();
-}
-//********************************************************************************************
-//
-// Function : adc_read_temp
-// Description : read temparature from ADC1 and convert to real temparature
-//
-//********************************************************************************************
-BYTE adc_read_temp ( void )
-{
- static WORD temp_buf[ ADC_TEMP_BUFFER ];
- static BYTE buf_index=0;
- WORD result=0,data;
- BYTE loop;
-
- // Store each sample to buffer
- temp_buf[ buf_index ] = adc_read ( ADC_TEMP_CHANNEL );
-
- // Low pass filter 8 samples by default.
- for ( loop=0; loop= 5 )
- *ptr++ = ( (dec/10000) + '0' );
- if ( digit >= 4 )
- *ptr++ = ( ((dec%10000)/1000) + '0' );
- if ( digit >= 3 )
- *ptr++ = ( ((dec%1000)/100) + '0' );
- if ( digit >= 2 )
- *ptr++ = ( ((dec%100)/10) + '0' );
- *ptr++ = ( ((dec%10)) + '0' );
-
- return ptr;
-}
-//*****************************************************************************************
-//
-// Function : print_temp
-// Description : Print ADC0 and temparature to buffer
-//
-//*****************************************************************************************
-void print_temp ( BYTE *dest )
-{
- WORD adc0_value;
- BYTE temp_value;
-
- adc0_value = adc_read ( 0 );
- temp_value = adc_read_temp ( );
-
- dest = print_decimal ( dest, 4, adc0_value );
- *dest++ = ',';
- dest = print_decimal ( dest, 2, temp_value );
- *dest++ = ASCII_DEGREE;
- *dest++ = 'C';
- *dest = '\0';
-}
-//*****************************************************************************************
-//
-// Function : print_ip
-// Description : Print ip address format to buffer e.g. 10.1.1.1
-//
-//*****************************************************************************************
-void print_ip ( BYTE *ptr, BYTE *ip, BYTE cursor )
-{
- BYTE i, digit, temp;
-
- for ( i=0; i<4; i++ )
- {
- temp = ip [ i ];
- if ( temp > 99 )
- digit = 3;
- else if ( temp > 9 )
- digit = 2;
- else
- digit = 1;
-
- if ( (i+1) == cursor )
- {
- *ptr = ASCII_CURSOR;
- ptr++;
- }
- else if ( i > 0 )
- {
- *ptr = '.';
- ptr++;
- }
- ptr = print_decimal ( ptr, digit, temp );
-
- }
- *ptr = '\0';
-}
-//*****************************************************************************************
-//
-// Function : print_time
-// Description : Print time format to buffer e.g. 01:23:45
-//
-//*****************************************************************************************
-void print_time ( BYTE *ptr, BYTE *time, BYTE cursor )
-{
- BYTE i;
-
- // show setting cursor when enter to setting mode
- if ( cursor == 0 )
- {
- if ( time [ 0 ] )
- {
- time++;
- for ( i=0; i<3; i++ )
- {
- if ( (i+2) == cursor )
- {
- *ptr++ = ASCII_CURSOR;
- }
- else if ( i > 0 )
- {
- *ptr++ = ':';
- }
- ptr = print_decimal ( ptr, 2, *time++ );
- }
- }
- else
- {
- ptr = my_strcpy ( ptr, (PGM_P)str_disable );
- }
- }
- else
- {
- if ( cursor == 1 )
- {
- *ptr++ = ASCII_CURSOR;
- // show Enable/Disable send temparature to server
- if ( time [ 0 ] )
- ptr = my_strcpy ( ptr, (PGM_P)str_enable );
- else
- ptr = my_strcpy ( ptr, (PGM_P)str_disable );
- }
- else
- {
- time++;
- for ( i=0; i<3; i++ )
- {
- if ( (i+2) == cursor )
- {
- *ptr++ = ASCII_CURSOR;
- }
- else if ( i > 0 )
- {
- *ptr++ = ':';
- }
- ptr = print_decimal ( ptr, 2, *time++ );
- }
- }
- }
-
- *ptr = '\0';
-}
-//*****************************************************************************************
-//
-// Function : time_base
-// Description : count-down timer for send temparature to server. you can enable/disable and
-// adjust timer by "Send temp config" menu.
-//
-//*****************************************************************************************
-void time_base ( void )
-{
- static BYTE send_temp_timeout=0;
-
- if ( ++sec_count == 250 )
- {
- sec_count = 0;
-
- // update lcd display
- flag1.bits.update_display = 1;
-
- // timeout for send temparature to webserver
- if ( flag1.bits.syn_is_sent )
- {
- // 5 seconds
- if ( ++send_temp_timeout == 5 )
- {
- send_temp_timeout = 0;
- flag1.bits.send_temp_timeout = 1;
- }
- }
- // send temparature to server countdown
- if ( count_time[ 0 ] && menu_index!=4 )
- {
- if ( --count_time[ 3 ] > 59 )
- {
- //count_time[ 3 ] = 59;
- count_time[ 3 ] = 20; // debug
- if ( --count_time[ 2 ] > 59 )
- {
- count_time[ 2 ] = 59;
- if ( --count_time[ 1 ] > 23 )
- {
- // read hour
- count_time[ 1 ] = eeprom_read_byte( ee_count_time + 1 );
- // read minute
- count_time[ 2 ] = eeprom_read_byte( ee_count_time + 2 );
- // clear second
- count_time[ 3 ] = 0;
- flag1.bits.send_temp = 1;
- }
- }
- }
- }
- }
-}
-//*******************************************************************************************
-//
-// Function : standby_display
-// Description : display board status such as AVR ip, server ip, countdown time, temparature
-//
-//*******************************************************************************************
-void standby_display ( void )
-{
- BYTE generic_buf[64];
-
- // update lcd display flag not set, exit from function
- if ( flag1.bits.update_display == 0 )
- return;
- flag1.bits.update_display = 0;
- // lcd display is displaying other information, wait until busy flag clear
- if ( flag1.bits.lcd_busy )
- return;
- // now displaying menu information, wait until exit from menu
- if ( menu_index )
- return;
-
- // display status on lcd line 1
- lcd_putc ( '\f' );
- lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] );
-
- // display status on lcd line 2
- lcd_putc ( '\n' );
- // display avr ip
- if ( standby_cursor == 1 )
- {
- print_ip ( generic_buf, (BYTE*)&avr_ip, 0 );
- }
- // display server ip
- else if ( standby_cursor == 2 )
- {
- print_ip ( generic_buf, (BYTE*)&server_ip, 0 );
- }
- // display countdown timer
- else if ( standby_cursor == 3 )
- {
- print_time ( generic_buf, count_time, 0 );
- }
- // display current temparature
- else if ( standby_cursor == 4 )
- {
- print_temp ( generic_buf );
- }
- lcd_print ( generic_buf );
-}
-//*******************************************************************************************
-//
-// Function : display_menu
-// Description : display LCD user interface menu on LCD
-//
-//*******************************************************************************************
-void display_menu(void)
-{
- BYTE generic_buf[64];
-
- if( menu_index == 0)
- return;
-
- // display menu title on lcd first line
- lcd_putc( '\f' );
- lcd_print ( (BYTE *)menu_list[ menu_index - 1 ] );
-
- // display menu detail on lcd second line
- lcd_putc( '\n' );
- if( menu_index == 1 )//MENU_MAIN)
- {
- lcd_print( (BYTE *)menu_list[ submenu_index ] );
- }
- // setup avr ip address
- else if( menu_index == 2 )
- {
- print_ip ( generic_buf, (BYTE*)&avr_ip, setting_cursor+1 );
- lcd_print ( generic_buf );
- }
- // setup server ip address
- else if(menu_index == 3 )
- {
- print_ip ( generic_buf, (BYTE*)&server_ip, setting_cursor+1 );
- lcd_print ( generic_buf );
- }
- // setup countdown timer for send temparature
- else if ( menu_index == 4 )
- {
- print_time ( generic_buf, count_time, setting_cursor+1 );
- lcd_print ( generic_buf );
- }
- // ping server
- else if ( menu_index == 5 )
- {
- print_ip ( generic_buf, (BYTE*)&server_ip, 1 );
- lcd_print ( generic_buf );
- }
- // send temparature now
- //else if ( menu_index == 6 )
- //{
- // lcd_put ( ASCII_CURSOR );
- // lcd_print_p ( PSTR ( "OK" ) );
- //}
-}
-//*******************************************************************************************
-//
-// Function : key_up_process
-// Description :
-//
-//*******************************************************************************************
-void key_up_process ( void )
-{
- BYTE temp;
-
- // standby display, display board status
- if(menu_index == 0)
- {
- if ( ++ standby_cursor == ((sizeof(standby_list)/2)+1) )
- standby_cursor = 1;
- flag1.bits.update_display = 1;
- }
- // main menu
- else if(menu_index == 1)
- {
- if( ++submenu_index == (sizeof(menu_list)/2) )
- {
- submenu_index = 1;
- }
- }
- // setup avr ip
- else if( menu_index == 2 )
- {
- avr_ip.byte [ setting_cursor ]++;
- eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
- }
- // setup server ip
- else if( menu_index == 3 )
- {
- server_ip.byte [ setting_cursor ]++;
- eeprom_write_block ( &server_ip, ee_server_ip, 4 );
- }
- // setup countdown timer
- else if( menu_index == 4 )
- {
- temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
- if ( ++count_time [ setting_cursor ] == temp )
- count_time [ setting_cursor ] = 0;
- eeprom_write_block ( count_time, ee_count_time, 4 );
- }
-}
-//*******************************************************************************************
-//
-// Function : key_dw_process
-// Description :
-//
-//*******************************************************************************************
-void key_dw_process ( void )
-{
- BYTE temp;
-
- // standby display, display board status
- if(menu_index == 0)
- {
- if ( -- standby_cursor == 0 )
- standby_cursor = sizeof(standby_list)/2;
- flag1.bits.update_display = 1;
- }
- // main menu
- else if(menu_index == 1)
- {
- if( --submenu_index == 0 )
- {
- submenu_index = (sizeof(menu_list)/2)-1;
- }
- }
- // setup avr ip
- else if( menu_index == 2 )
- {
- avr_ip.byte [ setting_cursor ]--;
- eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
- }
- // setup server ip
- else if( menu_index == 3 )
- {
- server_ip.byte [ setting_cursor ]--;
- eeprom_write_block ( &server_ip, ee_server_ip, 4 );
- }
- // setup countdown timer
- else if( menu_index == 4 )
- {
- temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
- if ( --count_time [ setting_cursor ] == 0xff )
- count_time [ setting_cursor ] = temp;
- eeprom_write_block ( count_time, ee_count_time, 4 );
- }
-}
-//*******************************************************************************************
-//
-// Function : key_process
-// Description : Process all key code from get_key_code function
-//
-//*******************************************************************************************
-void menu_process ( void )
-{
- static BYTE key_hold_count=0, key_hold_step_delay=0;
- BYTE rxtx_buffer[MAX_RXTX_BUFFER];
- BYTE key_code, temp;
- static BYTE backlight_sec=31, backlight_seccount=250;
-
- // get switch value from port
- key_code = SW_PIN & ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) );
-
- // Check key press?
- if ( key_code == ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ) )
- {
- flag1.bits.key_is_executed = 0;
- flag2.bits.key_hold = 0;
- key_hold_count = 0;
- key_hold_step_delay = 0;
-
- // lcd backlight control
- // lcd backlight off after key is unpress ( 30 seconds)
- if ( backlight_sec )
- {
- if ( --backlight_seccount > 250 )
- {
- backlight_seccount = 250;
- if ( --backlight_sec == 1 )
- {
- backlight_sec = 0;
- // lcd backlight off
- LCD_BL_PORT &= ~_BV( LCD_BL_PIN );
- }
- }
- }
- return;
- }
-
- // lcd backlight on
- // and hold-on 30 seconds
- backlight_sec = 31;
- LCD_BL_PORT |= _BV( LCD_BL_PIN );
-
- // check hold key
- if ( ++key_hold_count == 200 )
- {
- key_hold_count = 0;
- flag2.bits.key_hold = 1;
- }
-
- if ( flag2.bits.key_hold )
- {
- if ( ++key_hold_step_delay == 30 )
- {
- key_hold_step_delay = 0;
- if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) )
- {
- key_up_process ();
- }
- // if down key is pressed
- else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) )
- {
- key_dw_process ();
- }
- display_menu();
- }
- }
- // key code already executed
- if ( flag1.bits.key_is_executed )
- return;
- // check key code, what is key pressed?
- // if menu key is pressed
- if ( key_code == ((~_BV ( SW_MENU ) ) & 0xf0) )
- {
- // enter to main menu
- if( menu_index == 0 )
- {
- setting_cursor = 0;
- menu_index = 1;
- submenu_index = 1;
- }
- // enter to submenu
- else if( menu_index == 1 )
- {
- menu_stack = menu_index;
- submenu_stack = submenu_index;
- menu_index = submenu_index + menu_index;
- submenu_index = 1;
- }
- // ping server
- else if ( menu_index == 5 )
- {
- // Show on lcd first line
- lcd_putc( '\f' );
- lcd_print ( (BYTE *)menu_list[ 4 ] );
- lcd_putc( '\n' );
- if ( icmp_ping ( (BYTE*)rxtx_buffer, (BYTE*)&server_mac, (BYTE*)&server_ip ) )
- {
- lcd_print_p ( PSTR ( "Ping OK." ) );
- }
- else
- {
- lcd_print_p ( PSTR ( "Not found." ) );
- }
- flag1.bits.lcd_busy = 1;
- menu_index = 0;
- submenu_index = 0;
- flag1.bits.key_is_executed = 1;
- return;
- }
- // change cursor setting on each menu
- else
- {
- temp = pgm_read_byte ( (PGM_P)(setting_cursor_max + menu_index - 2) );
-
- if ( ++setting_cursor == temp )
- setting_cursor = 0;
- }
- }
- // if exit key is pressed
- else if ( key_code == ((~_BV ( SW_EXIT ) ) & 0xf0) )
- {
- setting_cursor = 0;
- if(menu_index > 1)
- {
- menu_index = menu_stack;
- submenu_index = submenu_stack;
- }
- else
- {
- menu_index = 0;
- submenu_index = 0;
-
- }
- }
- // if up key is pressed
- else if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) )
- {
- key_up_process ();
- }
- // if down key is pressed
- else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) )
- {
- key_dw_process ();
- }
- // display menu information on LCD
- display_menu();
- flag1.bits.key_is_executed = 1;
- flag1.bits.lcd_busy = 0;
-}
-//*******************************************************************************************
-//
-// Function : menu_init
-// Description : initial I/O direction for all key,
-// initial timer1 for countdown timer
-//
-//*******************************************************************************************
-void menu_init ( void )
-{
- // setup countdown initial value
- sec_count = 0;
- eeprom_read_block ( count_time, ee_count_time, 3 );
- count_time[3] = 0;
-
- // setup menu and standby display
- flag1.byte = 0;
- flag2.byte = 0;
- menu_index = 0;
- submenu_index = 0;
- menu_stack = 0;
- submenu_stack = 0;
- setting_cursor = 0;
- standby_cursor = 1;
-}
Index: trunk/apps/avr-webserver/avrnet.aws
===================================================================
--- trunk/apps/avr-webserver/avrnet.aws (revision 45)
+++ trunk/apps/avr-webserver/avrnet.aws (nonexistent)
@@ -1 +0,0 @@
-
Index: trunk/apps/avr-webserver/menu.h
===================================================================
--- trunk/apps/avr-webserver/menu.h (revision 45)
+++ trunk/apps/avr-webserver/menu.h (nonexistent)
@@ -1,92 +0,0 @@
-//********************************************************************************************
-//
-// File : menu.h implement for User interface menu
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#define SW_DW 7
-#define SW_UP 6
-#define SW_EXIT 5
-#define SW_MENU 4
-#define SW_DDR DDRA
-#define SW_PORT PORTA
-#define SW_PIN PINA
-#define LCD_BL_PIN PB3
-#define LCD_BL_PORT PORTB
-#define LCD_BL_DDR DDRB
-
-//#define MENU_MAIN 1
-//#define MENU_SET_AVR_IP 2
-//#define MENU_SET_SERVER_IP 3
-//#define MENU_SET_COUNT_TIME 4
-//#define MENU_PING_SERVER 5
-//#define MENU_SEND_TEMP 6
-
-#define SUBMENU_SET_AVR_IP 1
-#define SUBMENU_SET_SERVER_IP 2
-#define SUBMENU_SET_COUNT_TIME 3
-#define SUBMENU_PING_SERVER 4
-#define SUBMENU_SEND_TEMP 6
-
-#define CURSOR_SET_AVR_IP1 0
-#define CURSOR_SET_AVR_IP2 1
-#define CURSOR_SET_AVR_IP3 2
-#define CURSOR_SET_AVR_IP4 3
-
-#define CURSOR_SET_SERVER_IP1 0
-#define CURSOR_SET_SERVER_IP2 1
-#define CURSOR_SET_SERVER_IP3 2
-#define CURSOR_SET_SERVER_IP4 3
-
-#define CURSOR_SET_COUNT_TIME1 0
-#define CURSOR_SET_COUNT_TIME2 1
-#define CURSOR_SET_COUNT_TIME3 2
-#define CURSOR_SET_COUNT_TIME4 3
-
-//#define STANDBY_CURSOR_AVR_IP 1
-//#define STANDBY_CURSOR_SERVER_IP 2
-//#define STANDBY_CURSOR_COUNT_DOWN 3
-//#define STANDBY_CURSOR_TEMP 4
-
-#define ASCII_CURSOR 0x7E
-
-#include
-
-extern BYTE standby_cursor;
-extern BYTE ee_count_time[] EEMEM;
-extern BYTE count_time[];
-
-//********************************************************************************************
-//
-// Prototype function
-//
-//********************************************************************************************
-extern void menu_process ( void );
-extern void menu_init ( void );
-extern void standby_display ( void );
-extern void time_base ( void );
-extern void print_ip ( BYTE *ptr, BYTE *ip, BYTE cursor );
-extern void print_time ( BYTE *ptr, BYTE *time, BYTE cursor );
-extern BYTE *print_decimal ( BYTE *ptr, BYTE digit, WORD dec );
-extern void key_up_process ( void );
-extern void key_dw_process ( void );
Index: trunk/apps/avr-webserver/includes.h
===================================================================
--- trunk/apps/avr-webserver/includes.h (revision 45)
+++ trunk/apps/avr-webserver/includes.h (nonexistent)
@@ -1,82 +0,0 @@
-//********************************************************************************************
-//
-// File : include.h includes all header file for AVRethernet development board.
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-// struct.h MUST be include first
-#include "struct.h"
-#include "enc28j60.h"
-#include "ethernet.h"
-#include "ip.h"
-#include "tcp.h"
-#include "icmp.h"
-#include "arp.h"
-#include "udp.h"
-#include "http.h"
-#include "lcd.h"
-#include "menu.h"
-#include "adc.h"
-
-// define I/O interface
-
-#define LED_PIN1_DDR DDC6
-#define LED_PIN1 PC6
-#define LED_PIN2_DDR DDC7
-#define LED_PIN2 PC7
-#define LED_PORT PORTC
-#define LED_DDR DDRC
-
-#define LOW(uint) (uint&0xFF)
-#define HIGH(uint) ((uint>>8)&0xFF)
-
-#define MAX_RXTX_BUFFER 1518
-
-// global variables
-extern MAC_ADDR avr_mac;
-extern IP_ADDR avr_ip;
-
-//extern MAC_ADDR client_mac;
-//extern IP_ADDR client_ip;
-
-extern MAC_ADDR server_mac;
-extern IP_ADDR server_ip;
-
-extern BYTE generic_buf[];
-extern BYTE ee_avr_ip[];
-extern BYTE ee_server_ip[];
-//********************************************************************************************
-//
-// Prototype function from main.c
-//
-//********************************************************************************************
-extern void initial_system( void );
-
Index: trunk/apps/avr-webserver/ethernet.c
===================================================================
--- trunk/apps/avr-webserver/ethernet.c (revision 45)
+++ trunk/apps/avr-webserver/ethernet.c (nonexistent)
@@ -1,119 +0,0 @@
-//********************************************************************************************
-//
-// File : ethernet.c implement for Ethernet Protocol
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#include "includes.h"
-//********************************************************************************************
-//
-// Ethernet is a large, diverse family of frame-based computer networking technologies
-// that operates at many speeds for local area networks (LANs).
-// The name comes from the physical concept of the ether.
-// It defines a number of wiring and signaling standards for the physical layer,
-// through means of network access at the Media Access Control (MAC)/Data Link Layer,
-// and a common addressing format.
-//
-// Ethernet has been standardized as IEEE 802.3.
-// The combination of the twisted pair versions of ethernet for connecting end systems to
-// the network with the fiber optic versions for site backbones
-// become the most widespread wired LAN technology in use from the 1990s to the present,
-// largely replacing competing LAN standards such as coaxial cable Ethernet,
-// token ring, FDDI, and ARCNET. In recent years, Wi-Fi,
-// the wireless LAN standardized by IEEE 802.11,
-// has been used instead of Ethernet for many home and small office networks
-// and in addition to Ethernet in larger installations.
-//
-//
-//********************************************************************************************
-
-//********************************************************************************************
-//
-// Function : eth_generate_header
-// Description : generarete ethernet header, contain destination and source MAC address,
-// ethernet type.
-//
-//********************************************************************************************
-void eth_generate_header ( BYTE *rxtx_buffer, WORD_BYTES type, BYTE *dest_mac )
-{
- BYTE i;
- //copy the destination mac from the source and fill my mac into src
- for ( i=0; i1)
- {
- sum += 0xFFFF & (*rxtx_buffer<<8|*(rxtx_buffer+1));
- rxtx_buffer+=2;
- len-=2;
- }
- // if there is a byte left then add it (padded with zero)
- if (len)
- {
- sum += (0xFF & *rxtx_buffer)<<8;
- }
- // now calculate the sum over the bytes in the sum
- // until the result is only 16bit long
- while (sum>>16)
- {
- sum = (sum & 0xFFFF)+(sum >> 16);
- }
- // build 1's complement:
- return( (WORD) sum ^ 0xFFFF);
-}
Index: trunk/apps/avr-webserver/arp.c
===================================================================
--- trunk/apps/avr-webserver/arp.c (revision 45)
+++ trunk/apps/avr-webserver/arp.c (nonexistent)
@@ -1,215 +0,0 @@
-//********************************************************************************************
-//
-// File : arp.c implement for Address Resolution Protocol
-//
-//********************************************************************************************
-//
-// Copyright (C) 2007
-//
-// This program is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free Software
-// Foundation; either version 2 of the License, or (at your option) any later
-// version.
-// This program is distributed in the hope that it will be useful, but
-//
-// WITHOUT ANY WARRANTY;
-//
-// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-// PURPOSE. See the GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin St, Fifth Floor, Boston, MA 02110, USA
-//
-// http://www.gnu.de/gpl-ger.html
-//
-//********************************************************************************************
-#include "includes.h"
-//********************************************************************************************
-//
-// Address Resolution Protocol (ARP) is the method for finding a host's hardware address
-// when only its network layer address is known.
-// Due to the overwhelming prevalence of IPv4 and Ethernet,
-// ARP is primarily used to translate IP addresses to Ethernet MAC addresses.
-// It is also used for IP over other LAN technologies,
-// such as Token Ring, FDDI, or IEEE 802.11, and for IP over ATM.
-//
-// ARP is used in four cases of two hosts communicating:
-//
-// 1. When two hosts are on the same network and one desires to send a packet to the other
-// 2. When two hosts are on different networks and must use a gateway/router to reach the other host
-// 3. When a router needs to forward a packet for one host through another router
-// 4. When a router needs to forward a packet from one host to the destination host on the same network
-//
-// +------------+------------+-----------+
-// + MAC header + ARP header + Data ::: +
-// +------------+------------+-----------+
-//
-// ARP header
-//
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Hardware type + Protocol type +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + HardwareAddressLength + ProtocolAddressLength + Opcode +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Source hardware address ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Source protocol address ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Destination hardware address ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Destination protocol address ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-// + Data ::: +
-// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
-//
-//********************************************************************************************
-
-//********************************************************************************************
-//
-// Function : arp_generate_packet
-// Description : generate arp packet
-//
-//********************************************************************************************
-void arp_generate_packet ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip )
-{
- unsigned char i;
-
- // setup hardware type to ethernet 0x0001
- rxtx_buffer[ ARP_HARDWARE_TYPE_H_P ] = ARP_HARDWARE_TYPE_H_V;
- rxtx_buffer[ ARP_HARDWARE_TYPE_L_P ] = ARP_HARDWARE_TYPE_L_V;
-
- // setup protocol type to ip 0x0800
- rxtx_buffer[ ARP_PROTOCOL_H_P ] = ARP_PROTOCOL_H_V;
- rxtx_buffer[ ARP_PROTOCOL_L_P ] = ARP_PROTOCOL_L_V;
-
- // setup hardware length to 0x06
- rxtx_buffer[ ARP_HARDWARE_SIZE_P ] = ARP_HARDWARE_SIZE_V;
-
- // setup protocol length to 0x04
- rxtx_buffer[ ARP_PROTOCOL_SIZE_P ] = ARP_PROTOCOL_SIZE_V;
-
- // setup arp destination and source mac address
- for ( i=0; i1 new seq,seqack with data
- 0, // tcp data length
- (BYTE*)&server_mac, // server mac address
- (BYTE*)&server_ip ); // server ip address
- // setup http request to server
- dlength = http_put_request( (BYTE*)&rxtx_buffer );
- // send http request packet
- // send packet with PSHACK
- tcp_send_packet (
- (BYTE*)&rxtx_buffer,
- (WORD_BYTES){80}, // destination port
- (WORD_BYTES){1200}, // source port
- TCP_FLAG_ACK_V | TCP_FLAG_PSH_V, // flag
- 0, // (bool)maximum segment size
- 0, // (bool)clear sequence ack number
- 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
- dlength, // tcp data length
- (BYTE*)&server_mac, // server mac address
- (BYTE*)&server_ip ); // server ip address
- return;
- }
- // after AVR send http request to server, server response by send data with PSHACK to AVR
- // AVR answer by send ACK and FINACK to server
- if ( rxtx_buffer [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PSH_V) )
- {
- dlength = tcp_get_dlength( (BYTE*)&rxtx_buffer );
-
- // send ACK to answer PSHACK from server
- tcp_send_packet (
- (BYTE*)&rxtx_buffer,
- (WORD_BYTES){80}, // destination port
- (WORD_BYTES){1200}, // source port
- TCP_FLAG_ACK_V, // flag
- 0, // (bool)maximum segment size
- 0, // (bool)clear sequence ack number
- dlength, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
- 0, // tcp data length
- (BYTE*)&server_mac, // server mac address
- (BYTE*)&server_ip ); // server ip address
- // send finack to disconnect from web server
-
- tcp_send_packet (
- (BYTE*)&rxtx_buffer,
- (WORD_BYTES){80}, // destination port
- (WORD_BYTES){1200}, // source port
- TCP_FLAG_FIN_V|TCP_FLAG_ACK_V, // flag
- 0, // (bool)maximum segment size
- 0, // (bool)clear sequence ack number
- 0, // (bool)calculate new seq and seqack number
- 0, // tcp data length
- (BYTE*)&server_mac, // server mac address
- (BYTE*)&server_ip ); // server ip address
- return;
- //menu_flag.bits.send_temp = 0;
- //send_syn = 0;
- }
- // answer FINACK from web server by send ACK to web server
- if ( rxtx_buffer [ TCP_FLAGS_P ] == (TCP_FLAG_FIN_V|TCP_FLAG_ACK_V) )
- {
- // send ACK with seqack = 1
- tcp_send_packet (
- (BYTE*)&rxtx_buffer,
- (WORD_BYTES){80}, // destination port
- (WORD_BYTES){1200}, // source port
- TCP_FLAG_ACK_V, // flag
- 0, // (bool)maximum segment size
- 0, // (bool)clear sequence ack number
- 1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
- 0, // tcp data length
- (BYTE*)&server_mac, // server mac address
- (BYTE*)&server_ip ); // server ip address
- // temparature has been sent
- // and wait for next schedule to send temparature
- flag1.bits.send_temp = 0;
- flag1.bits.syn_is_sent = 0;
- }
-}
-//*****************************************************************************************
-//
-// Function : main
-// Description : main program,
-//
-//*****************************************************************************************
-void lcd_backlight( void )
-{
-
-
-
-}
-//*****************************************************************************************
-//
-// Function : main
-// Description : main program,
-//
-//*****************************************************************************************
-int main (void)
-{
- // change your mac address here
- avr_mac.byte[0] = 'A';
- avr_mac.byte[1] = 'V';
- avr_mac.byte[2] = 'R';
- avr_mac.byte[3] = 'P';
- avr_mac.byte[4] = 'O';
- avr_mac.byte[5] = 'R';
-
- // read avr and server ip from eeprom
- eeprom_read_block ( &avr_ip, ee_avr_ip, 4 );
- eeprom_read_block ( &server_ip, ee_server_ip, 4 );
-
- // setup port as input and enable pull-up
- SW_DDR &= ~ ( _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW ) );
- SW_PORT |= _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW );
- SFIOR &= ~_BV( PUD );
-
- // setup lcd backlight as output
- LCD_BL_DDR |= _BV( LCD_BL_PIN );
- // lcd backlight on
- LCD_BL_PORT |= _BV( LCD_BL_PIN );
-
- // setup clock for timer1
- TCCR1B = 0x01; // clk/1 no prescaling
-
- // initial adc, lcd, and menu
- adc_init();
- lcd_init ();
- menu_init ();
-
- // set LED1, LED2 as output */
- LED_DDR |= _BV( LED_PIN1_DDR ) | _BV( LED_PIN2_DDR );
- // set LED pin to "1" ( LED1,LED2 off)
- LED_PORT |= _BV( LED_PIN1 ) | _BV( LED_PIN2 );
-
- // initial enc28j60
- enc28j60_init( (BYTE*)&avr_mac );
-
- // loop forever
- for(;;)
- {
- // wait until timer1 overflow
- while ( (TIFR & _BV ( TOV1 )) == 0 );
- TIFR |= _BV(TOV1);
- TCNT1 = 1536; // Timer1 overflow every 1/16MHz * ( 65536 - 1536 ) = 4ms, 250Hz
-
- // general time base, generate by timer1
- // overflow every 1/250 seconds
- time_base ();
-
- // read temparature
- adc_read_temp();
-
- // server process response for arp, icmp, http
- server_process ();
-
- // send temparature to web server unsing http protocol
- // disable by default.
- client_process ();
-
- // lcd user interface menu
- // setup IP address, countdown timer
- menu_process ();
-
- // display AVR ethernet status
- // temparature, AVR ip, server ip, countdown time
- standby_display ();
- }
-
- return 0;
-}
Index: trunk/apps/MicroWeb/ip.c
===================================================================
--- trunk/apps/MicroWeb/ip.c (revision 45)
+++ trunk/apps/MicroWeb/ip.c (nonexistent)
@@ -1,187 +0,0 @@
-//////////////////////////////////////////////////////////////////////
-//// ////
-//// Tubo 8051 WebServer Project ////
-//// ////
-//// This file is part of the Turbo 8051 cores project ////
-//// http://www.opencores.org/cores/turbo8051/ ////
-//// ////
-//// Description ////
-//// The basic code is taken from MicroWeb project and necessary ////
-// upgrade is done to match the Turbo 8051 Webserver ////
-//// ////
-//// To Do: ////
-//// nothing ////
-//// ////
-//// Author(s): ////
-//// - Dinesh Annayya, dinesha@opencores.org ////
-//// ////
-//////////////////////////////////////////////////////////////////////
-//// ////
-//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
-//// ////
-//// This source file may be used and distributed without ////
-//// restriction provided that this copyright statement is not ////
-//// removed from the file and that any derivative work contains ////
-//// the original copyright notice and the associated disclaimer. ////
-//// ////
-//// This source file is free software; you can redistribute it ////
-//// and/or modify it under the terms of the GNU Lesser General ////
-//// Public License as published by the Free Software Foundation; ////
-//// either version 2.1 of the License, or (at your option) any ////
-//// later version. ////
-//// ////
-//// This source is distributed in the hope that it will be ////
-//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
-//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
-//// PURPOSE. See the GNU Lesser General Public License for more ////
-//// details. ////
-//// ////
-//// You should have received a copy of the GNU Lesser General ////
-//// Public License along with this source; if not, download it ////
-//// from http://www.opencores.org/lgpl.shtml ////
-//// ////
-//////////////////////////////////////////////////////////////////////
-// Basic Code is from :
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// ip.c: IP protocol processing
-/************************************************************
-IP4 header:
-
- 1. Version. 4 bits.
- Specifies the format of the IP packet header.
- 4 --- IP, Internet Protocol.
- 2. IHL, Internet Header Length. 4 bits.
- Specifies the length of the IP packet header in 32 bit words.
- The minimum value for a valid header is 5.
-
- 3. Differentiated Services. 8 bits.
-
- 4. Codepoint. 6 bits.
-
- 5. unused. 2 bits.
-
- 6. TOS, Type of Service. 8 bits.
-
- 7. Total length. 16 bits.
- Contains the length of the datagram.
-
- 8. Identification. 16 bits.
- Used to identify the fragments of one datagram from those of another.
- The originating protocol module of an internet datagram sets the identification field to a value that must be unique for that source-destination pair and protocol for the time the datagram will be active in the internet system. The originating protocol module of a complete datagram clears the MF bit to zero and the Fragment Offset field to zero.
-
- 9. Flags. 3 bits.
- 9.A R, reserved. 1 bit.
- Should be cleared to 0.
- 9.B DF, Don't fragment. 1 bit.
- Controls the fragmentation of the datagram.
- 9.C MF, More fragments. 1 bit.
- Indicates if the datagram contains additional fragments.
-
- 10. Fragment Offset. 13 bits.
-
- 11. TTL, Time to Live. 8 bits.
- A timer field used to track the lifetime of the datagram.
- When the TTL field is decremented down to zero, the datagram is discarded.
-
- 12. Protocol. 8 bits.
- This field specifies the next encapsulated protocol.
-
- 1 -- ICMP, Internet Control Message Protocol.
- 2 -- IGAP, IGMP for user Authentication Protocol.
- IGMP, Internet Group Management Protocol.
- RGMP, Router-port Group Management Protocol.
- 4 -- IP in IP encapsulation.
- 6 -- TCP, Transmission Control Protocol.
- 17-- UDP, User Datagram Protocol.
- 41-- IPv6 over IPv4.
- 58-- ICMPv6, Internet Control Message Protocol for IPv6.
- MLD, Multicast Listener Discovery.
- 59-- IPv6 No Next Header.
- 97-- EtherIP.
-**********************************************************************/
-
-
-#include
-#include "packets.h"
-#include "csio.h"
-
-unsigned char rx_ip_packet(unsigned char *rx_buffer)
-{
- struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
- struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
- unsigned int *chksum_hdr = (unsigned int *)rx_ip_hdr;
- int i;
- unsigned int chksum = 0;
-
- // Make sure that the packet is destined for me or for broadcast
- if ((!memcmp(myIP, &rx_ip_hdr->destIP, sizeof(unsigned char) * 4)) || (!memcmp(myBCAST, &rx_ip_hdr->destIP, sizeof(unsigned char) * 4)))
- {
- // Save the source MAC and IP for when I reply
- memcpy(srcMAC, &rx_eth_hdr->shost, sizeof(unsigned char) * 6);
- memcpy(srcIP, &rx_ip_hdr->srcIP, sizeof(unsigned char) * 4);
-
- // Compute the checksum
- for (i = 0; i < 10; i++)
- if (i != 5)
- chksum += *chksum_hdr;
- chksum = ~chksum;
-
- // packet is valid if they match
- if (chksum == rx_ip_hdr->hdrchksum)
- {
- return rx_ip_hdr->proto;
- }
- else
- return 0;
- }
- return 0;
-}
-
-void tx_ip_packet(unsigned char *tx_buffer, unsigned char tx_length)
-{
- struct eth_hdr *tx_eth_hdr = (struct eth_hdr *)tx_buffer;
- struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buffer + sizeof(struct eth_hdr));
- unsigned int *chksum_hdr = (unsigned int *)tx_ip_hdr;
- int i;
- unsigned int chksum = 0;
-
- tx_ip_hdr->verIHL = 0x45;
- tx_ip_hdr->totlen = tx_length + sizeof(struct ip_hdr);
- tx_ip_hdr->TTL = 0x32;
- tx_ip_hdr->proto = IP_UDP;
-
- memcpy(tx_ip_hdr->srcIP, myIP, sizeof(unsigned char) * 4);
- memcpy(tx_ip_hdr->destIP, targetIP, sizeof(unsigned char) * 4);
-
- chksum_hdr = (unsigned int *)tx_ip_hdr;
- // Compute the checksum
- for (i = 0; i < 10; i++)
- if (i != 5)
- chksum += *chksum_hdr;
- chksum = ~chksum;
- tx_ip_hdr->hdrchksum = chksum;
-
- tx_eth_hdr->type = ETHER_IP;
- memcpy(tx_eth_hdr->shost, myMAC, sizeof(unsigned char) * 6);
- memcpy(tx_eth_hdr->dhost, targetMAC, sizeof(unsigned char) * 6);
-
- tx_packet(tx_buffer, tx_length);
-}
-
Index: trunk/apps/MicroWeb/README
===================================================================
--- trunk/apps/MicroWeb/README (revision 45)
+++ trunk/apps/MicroWeb/README (nonexistent)
@@ -1,11 +0,0 @@
-== MicroWeb v0.01 ==
-
-This program is a Web Server and TCP/IP stack for 8051 microcontrollers.
-It started out as my Senior Project while a Senior at Bradley University.
-I hope to expand it to work on other microcontrollers and be used in a
-variety of applications.
-
-This version is meant to be compiled with SDCC on Linux.
-
-Mason Kidd
-
Index: trunk/apps/MicroWeb/ip.h
===================================================================
--- trunk/apps/MicroWeb/ip.h (revision 45)
+++ trunk/apps/MicroWeb/ip.h (nonexistent)
@@ -1,27 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// ip.h: defines for IP
-
-#ifndef H__IP
-#define H__IP
-
-void tx_ip_packet(unsigned char *tx_buffer, unsigned char tx_length);
-unsigned char rx_ip_packet(unsigned char *rx_buffer);
-
-#endif
Index: trunk/apps/MicroWeb/http.c
===================================================================
--- trunk/apps/MicroWeb/http.c (revision 45)
+++ trunk/apps/MicroWeb/http.c (nonexistent)
@@ -1,89 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// http.c: HTTP protocol processing
-
-#include
-#include "packets.h"
-#include "tcp.h"
-#include "http.h"
-
-void http_response();
-void http_error(int nStatus, char *szTitle, char *szText);
-void http_header(int nStatus, char *szTitle, int nLength);
-
-unsigned char szBuf[500];
-unsigned char *pszBuf = szBuf;
-unsigned char cTCB = 0;
-
-void tx_http_packet(unsigned char *szData, unsigned char nLength)
-{
- tx_tcp_packet(cTCB, 0, szData, nLength);
-}
-
-void rx_http_packet(unsigned char *szData, unsigned char nLength, unsigned char current_TCB)
-{
- unsigned char method[5], path[100], protocol[10];
- char *file;
- int nFileLength;
-
- pszBuf = szBuf;
- cTCB = current_TCB;
-
- if (sscanf(szData, "%[^ ] %[^ ] %[^\r]", method, path, protocol) != 3)
- http_error(400, "Bad Request", "Unable to prarse request.");
- if (strcasecmp(method, "get") != 0)
- http_error(501, "Not Implemented", "That method is not implemented.");
- if (path[0] != '/')
- http_error(400, "Bad Request", "Bad filename.");
- file = &(path[1]);
- nFileLength = strlen(file);
- if (nFileLength == 0)
- http_response();
- else if ((strcasecmp(file, "index.html") == 0) || (strcasecmp(file, "index.htm") == 0))
- http_response();
- else
- http_error(404, "Not Found", "File not found.");
-}
-
-void http_response()
-{
- http_header(200, "Ok", -1);
- pszBuf += sprintf(szBuf, "%s ", _HTTP_SERVER);
- pszBuf += sprintf(szBuf, "The current temperature is %d degrees Fahrenheit", 20);
-
- tx_http_packet(szBuf, strlen(szBuf));
-}
-
-void http_error(int nStatus, char *szTitle, char *szText)
-{
- http_header(nStatus, szTitle, -1);
- pszBuf += sprintf(szBuf, "%s ", szTitle);
- pszBuf += sprintf(szBuf, "%s", szText);
-}
-
-void http_header(int nStatus, char *szTitle, int nLength)
-{
- pszBuf += sprintf(szBuf, "%s %d %s\r\n", _HTTP_PROTOCOL, nStatus, szTitle);
- pszBuf += sprintf(szBuf, "Server: %s\r\n", _HTTP_SERVER);
- pszBuf += sprintf(szBuf, "Connection: close\r\n");
- pszBuf += sprintf(szBuf, "Content-Type: text/html\r\n");
- if (nLength > 0)
- pszBuf += sprintf(szBuf, "Content-Length: %d\r\n", nLength);
- pszBuf += sprintf(szBuf, "\r\n");
-}
Index: trunk/apps/MicroWeb/arp.c
===================================================================
--- trunk/apps/MicroWeb/arp.c (revision 45)
+++ trunk/apps/MicroWeb/arp.c (nonexistent)
@@ -1,181 +0,0 @@
-//////////////////////////////////////////////////////////////////////
-//// ////
-//// Tubo 8051 WebServer Project ////
-//// ////
-//// This file is part of the Turbo 8051 cores project ////
-//// http://www.opencores.org/cores/turbo8051/ ////
-//// ////
-//// Description ////
-//// The basic code is taken from MicroWeb project and necessary ////
-// upgrade is done to match the Turbo 8051 Webserver ////
-//// ////
-//// To Do: ////
-//// nothing ////
-//// ////
-//// Author(s): ////
-//// - Dinesh Annayya, dinesha@opencores.org ////
-//// ////
-//////////////////////////////////////////////////////////////////////
-//// ////
-//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
-//// ////
-//// This source file may be used and distributed without ////
-//// restriction provided that this copyright statement is not ////
-//// removed from the file and that any derivative work contains ////
-//// the original copyright notice and the associated disclaimer. ////
-//// ////
-//// This source file is free software; you can redistribute it ////
-//// and/or modify it under the terms of the GNU Lesser General ////
-//// Public License as published by the Free Software Foundation; ////
-//// either version 2.1 of the License, or (at your option) any ////
-//// later version. ////
-//// ////
-//// This source is distributed in the hope that it will be ////
-//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
-//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
-//// PURPOSE. See the GNU Lesser General Public License for more ////
-//// details. ////
-//// ////
-//// You should have received a copy of the GNU Lesser General ////
-//// Public License along with this source; if not, download it ////
-//// from http://www.opencores.org/lgpl.shtml ////
-//// ////
-//////////////////////////////////////////////////////////////////////
-
-/////////////////////////////////////////////////////////////////////
-// Basic Code is from :
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// arp.c: processing for ARP packets
-/*******************************************************
- Arp Packet Format
- [15:0] - HRD = 1
- [15:0] - PRO = 0x0800
- [7:0] - HLN = 6
- [7:0] - PLN = 4
- [15:0] - OP
- [47:0] - SHA [0-5]
- [31:0] - SPA [0-3]
- [47:0] - THA [0-5]
- [31:0] - TPA [0-3]
-
-HRD (Hardware Type): This field specfies the type of hardware used for the local network
-transmitting the ARP message.
- 1 - Ethernet (10MB)
- 6 - IEEE 802 Networks
- 7 - ARCNET
- 15 - Frame Relay
- 16 - Asynhronous Transfer Mode (ATM)
- 17 - HDLC
- 18 - Fibre Channel
- 19 - Asynchronous
-
-
-PRO (Protocol Type): This field is the complement of the Hardware Type field,
- specifying the type of layer three addresses used in the message.
- For IPv4 addresses, this value is 2048 (0800 hex),
- which corresponds to the EtherType code for the Internet Protocol.
-
-HLN (Hardware Address Length):
- Specifies how long hardware addresses are in this message.
- For Ethernet or other networks using IEEE 802 MAC addresses, the value is 6.
-
-PLN (Protocol Address Length):
- The complement of the preceding field; specifies how long protocol (layer three)
- addresses are in this message. For IP(v4) addresses this value is of course 4.
-
-OP (Opcode): This field specifes the nature of the Arp Message being sent
- 1 -- ARP Request
- 2 -- ARP Reply
- 3 -- RARP Request
- 4 -- RARP Reply
- 5 -- DRARP Request
- 6 -- DRARP Reply
- 7 -- DRARP Error
- 8 -- InARP Request
- 9 -- InARP Reply
-
-SHA (Sender Hardware Address):
- The hardware (layer two) address of the device sending this message
-
-SPA (Sender Protocol Address):
- The IP address of the device sending this message.
-
-THA (Target Hardware Address):
- The hardware (layer two) address of the device this message is being sent to.
-
-TPA (Target Protocol Address):
- The IP address of the device this message is being sent to.
-
-
-********************************************************/
-
-#include
-#include "packets.h"
-#include "csio.h"
-#include "arp.h"
-
-void tx_arp_packet(unsigned int arp_oper)
-{
- unsigned char tx_buf[BUF_LEN];
- struct eth_hdr *tx_eth_hdr = (struct eth_hdr *)(tx_buf);
- struct eth_arp *tx_eth_arp = (struct eth_arp *)(tx_buf + sizeof(struct eth_hdr));
- unsigned int nLength = 0;
-
- tx_eth_arp->eth_arp_hdr.ar_hrd = ARP_HRD_ETHER;
- tx_eth_arp->eth_arp_hdr.ar_pro = ETHER_IP;
- tx_eth_arp->eth_arp_hdr.ar_hln = MAC_ADDR_LEN;
- tx_eth_arp->eth_arp_hdr.ar_pln = IP_ADDR_LEN;
- tx_eth_arp->eth_arp_hdr.ar_op = arp_oper;
-
- memcpy(tx_eth_arp->ar_sha, myMAC, sizeof(char) * MAC_ADDR_LEN);
- memcpy(tx_eth_arp->ar_spa, myIP, sizeof(char) * IP_ADDR_LEN);
- memcpy(tx_eth_arp->ar_tha, targetMAC, sizeof(char) * MAC_ADDR_LEN);
- memcpy(tx_eth_arp->ar_tpa, targetIP, sizeof(char) * IP_ADDR_LEN);
-
- memcpy(tx_eth_hdr->dhost, targetMAC, sizeof(char) * MAC_ADDR_LEN);
- memcpy(tx_eth_hdr->shost, myMAC, sizeof(char) * MAC_ADDR_LEN);
- tx_eth_hdr->type = ETHER_ARP;
-
- nLength += sizeof(struct eth_hdr) + sizeof(struct eth_arp);
-
- tx_packet(tx_buf, nLength);
-}
-
-void rx_arp_packet(unsigned char *rx_buffer)
-{
- struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
- struct eth_arp *rx_eth_arp = (struct eth_arp *)(rx_buffer + sizeof(struct eth_hdr));
-
- // make sure the ARP packet is Ethernet and IP
- if ((rx_eth_arp->eth_arp_hdr.ar_hrd == ARP_HRD_ETHER) && (rx_eth_arp->eth_arp_hdr.ar_pro == ETHER_IP))
- {
- // make sure the ARP packet is a request destined for us
- if ((rx_eth_arp->eth_arp_hdr.ar_op == ARP_REQUEST) && (!memcmp(myIP, rx_eth_arp->ar_tpa, sizeof(unsigned char) * 4)))
- {
- // send a reply
- memcpy(targetMAC, rx_eth_arp->ar_sha, sizeof(char) * MAC_ADDR_LEN);
- memcpy(targetIP, rx_eth_arp->ar_spa, sizeof(char) * IP_ADDR_LEN);
- tx_arp_packet(ARP_REPLY);
- }
- // else discard packet
- }
- // else discard packet
-}
-
Index: trunk/apps/MicroWeb/main.c
===================================================================
--- trunk/apps/MicroWeb/main.c (revision 45)
+++ trunk/apps/MicroWeb/main.c (nonexistent)
@@ -1,91 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// main.c: main source code file
-
-//#include
-#include <8051.h>
-#include
-#include "csio.h"
-#include "packets.h"
-#include "keypad.h"
-#include "arp.h"
-#include "ip.h"
-#include "icmp.h"
-#include "udp.h"
-#include "tcp.h"
-
-unsigned char myMAC[6] = {0x00,0x08,0x07,0x06,0x05,0x04};
-unsigned char myIP[4] = {192,168,1,1};
-unsigned char targetIP[4] = {192,168,1,2};
-unsigned char targetMAC[6] = {0x00,0xa0,0x24,0x66,0xda,0x3f};
-unsigned char srcMAC[6] = {0,0,0,0,0,0};
-unsigned char srcIP[4] = {0,0,0,0};
-unsigned char tmp_mac[6];
-unsigned char tmp_ip[4];
-unsigned char myBCAST[4] = {255,255,255,255};
-
-unsigned char rx_ip_type;
-unsigned char rx_buf[BUF_LEN];
-unsigned int rx_buf_len;
-unsigned int rx_packet_type;
-
-void main(void)
-{
- unsigned char cTest;
- struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buf;
- unsigned char bEvent = 0;
- unsigned char bValid = 0;
- unsigned char i = 0;
-
- tcp_init();
- cTest = cs_test();
- cs_init(myMAC);
-
- while (1)
- {
- bEvent = rx_event_poll();
- if (bEvent == 1)
- {
- rx_buf_len = rx_packet(rx_buf);
- rx_packet_type = rx_eth_hdr->type;
- switch (rx_packet_type)
- {
- case ETHER_IP:
- bValid = rx_ip_packet(rx_buf);
- if(bValid !=0) break;
- switch (rx_ip_type)
- {
- case IP_ICMP:
- rx_icmp_packet(rx_buf);
- break;
- case IP_UDP:
- rx_udp_packet(rx_buf);
- break;
- case IP_TCP:
- rx_tcp_packet(rx_buf);
- break;
- }
- break;
- case ETHER_ARP:
- rx_arp_packet(rx_buf);
- break;
- }
- }
- }
-}
Index: trunk/apps/MicroWeb/http.h
===================================================================
--- trunk/apps/MicroWeb/http.h (revision 45)
+++ trunk/apps/MicroWeb/http.h (nonexistent)
@@ -1,31 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// http.h: defines for HTTP protocol
-
-#ifndef H__HTTP
-#define H__HTTP
-
-#define _HTTP_PROTOCOL "HTTP/1.0"
-#define _HTTP_SERVER "Microweb v0.1"
-
-void tx_http_packet(unsigned char *szData, unsigned char nLength);
-void rx_http_packet(unsigned char *szData, unsigned char nLength, unsigned char current_TCB);
-
-#endif
-
Index: trunk/apps/MicroWeb/tcp.c
===================================================================
--- trunk/apps/MicroWeb/tcp.c (revision 45)
+++ trunk/apps/MicroWeb/tcp.c (nonexistent)
@@ -1,245 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// tcp.c: TCP protocol processing
-
-#include "packets.h"
-#include "ip.h"
-#include "tcp.h"
-//#include "http.h"
-
-static struct tcp_TCB tcp_table[TCP_MAX_CONN];
-
-void tcp_init(void)
-{
- int i;
-
- for (i = 0; i < TCP_MAX_CONN; i++)
- {
- tcp_table[i].local_port = 0;
- tcp_table[i].remote_port = 0;
- tcp_table[i].remote_addr[0] = 0;
- tcp_table[i].remote_addr[1] = 0;
- tcp_table[i].remote_addr[2] = 0;
- tcp_table[i].remote_addr[3] = 0;
- tcp_table[i].state = LISTEN;
- tcp_table[i].local_seq = 0;
- tcp_table[i].remote_seq = 0;
-
- }
-}
-
-unsigned char tcp_get_TCB(unsigned char remote_addr[4], unsigned int remote_port, unsigned int local_port)
-{
- int i = 0;
- unsigned char free_TCB = TCP_MAX_CONN;
-
- for (i = 0; i < TCP_MAX_CONN; i++)
- {
- if (tcp_table[i].remote_addr[0] == remote_addr[0] &&
- tcp_table[i].remote_addr[0] == remote_addr[1] &&
- tcp_table[i].remote_addr[0] == remote_addr[2] &&
- tcp_table[i].remote_addr[0] == remote_addr[3] &&
- tcp_table[i].remote_port == remote_port &&
- tcp_table[i].local_port == local_port)
- return i;
- else if (tcp_table[i].state == LISTEN)
- free_TCB = i;
- }
-
- if (free_TCB != TCP_MAX_CONN)
- {
- tcp_table[free_TCB].local_port = local_port;
- tcp_table[free_TCB].remote_port = remote_port;
- tcp_table[free_TCB].remote_addr[0] = remote_addr[0];
- tcp_table[free_TCB].remote_addr[1] = remote_addr[1];
- tcp_table[free_TCB].remote_addr[2] = remote_addr[2];
- tcp_table[free_TCB].remote_addr[3] = remote_addr[3];
- return free_TCB;
- }
-
- return 0;
-}
-
-void delete_TCB(unsigned char num_TCB)
-{
- tcp_table[num_TCB].local_port = 0;
- tcp_table[num_TCB].remote_port = 0;
- tcp_table[num_TCB].remote_addr[0] = 0;
- tcp_table[num_TCB].remote_addr[1] = 0;
- tcp_table[num_TCB].remote_addr[2] = 0;
- tcp_table[num_TCB].remote_addr[3] = 0;
- tcp_table[num_TCB].state = LISTEN;
- tcp_table[num_TCB].local_seq = 0;
- tcp_table[num_TCB].remote_seq = 0;
-}
-
-void rx_tcp_packet(unsigned char *rx_buffer)
-{
- struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
- struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
- struct tcp_hdr *rx_tcp_hdr = (struct tcp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
- unsigned int *tcp_data = (unsigned int *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct tcp_hdr));
- unsigned int *chksum_hdr = (unsigned int *)rx_ip_hdr->srcIP;
- unsigned int tcp_len = rx_ip_hdr->totlen - sizeof(rx_ip_hdr);
- unsigned int chksum = tcp_len + IP_TCP;
- unsigned char current_TCB = 0;
- bit process_data = 0;
- int i;
-
- for (i = 0; i < 8; i++)
- chksum += *chksum_hdr;
-
- chksum_hdr = (unsigned int *)rx_tcp_hdr;
-
- // if the packet length is odd, pad it
- if (tcp_len % 2)
- *((unsigned char *)chksum_hdr + tcp_len) = 0;
-
- tcp_len = (tcp_len + 1) >> 1;
- for (i = 0; i < tcp_len; i++, chksum_hdr++)
- if (i != 8)
- chksum += *chksum_hdr;
- chksum = ~chksum;
-
- if (chksum == rx_tcp_hdr->checksum)
- {
- current_TCB = tcp_get_TCB(rx_ip_hdr->srcIP, rx_tcp_hdr->src_port, rx_tcp_hdr->dst_port);
- if (current_TCB != 0)
- {
- switch (tcp_table[current_TCB].state)
- {
- case LISTEN:
- if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_SYN)
- {
- // received SYN, send SYN and ACK, enter SYN_RECVD
- tcp_table[current_TCB].state = SYN_RECVD;
- tcp_table[current_TCB].local_seq = TCP_START_SEQ;
- tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
- tx_tcp_packet(current_TCB, TCP_CNTRL_ACK | TCP_CNTRL_SYN, 0, 0);
- }
- break;
- case SYN_SENT:
- if (rx_tcp_hdr->cntrl_bits & (TCP_CNTRL_ACK || TCP_CNTRL_SYN))
- {
- // received SYN and ACK, enter ESTABLISHED, send ACK
- tcp_table[current_TCB].state = ESTABLISHED;
- tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
- tx_tcp_packet(current_TCB, TCP_CNTRL_ACK, 0, 0);
- }
- else if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_SYN)
- {
- // received SYN, enter SYN_RECVD, send ACK
- tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
- tcp_table[current_TCB].state = SYN_RECVD;
- tx_tcp_packet(current_TCB, TCP_CNTRL_ACK, 0, 0);
- }
- break;
- case SYN_RECVD:
- if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_ACK)
- {
- // received ACK, enter ESTABLISHED
- tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
- tcp_table[current_TCB].state = ESTABLISHED;
- }
- break;
- case ESTABLISHED:
- if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_FIN)
- {
- // received FIN, send ACK, close connection
- // skip the CLOSE_WAIT state
- tcp_table[current_TCB].state = LAST_ACK;
- tx_tcp_packet(current_TCB, TCP_CNTRL_ACK | TCP_CNTRL_FIN, 0, 0);
- }
- else
- process_data = 1;
- break;
- case CLOSE_WAIT:
- break;
- case FIN_WAIT_1:
- break;
- case FIN_WAIT_2:
- break;
- case CLOSING:
- break;
- case LAST_ACK:
- if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_ACK)
- {
- tcp_table[current_TCB].state = CLOSED;
- }
- case CLOSED:
- delete_TCB(current_TCB);
- break;
- case TIME_WAIT:
- break;
- }
- // connection is established, send data to correct socket
- if (process_data == 1)
- switch (rx_tcp_hdr->dst_port)
- {
- case TCP_PORT_HTTP:
- //rx_http_packet((unsigned char *)tcp_data, tcp_len - sizeof(struct tcp_hdr));
- break;
- }
- }
- }
- // else discard packet
-}
-
-void tx_tcp_packet(unsigned char current_TCB, unsigned char control_bits, unsigned char *szData, unsigned int nLength)
-{
- unsigned char tx_buf[BUF_LEN];
- struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
- struct tcp_hdr *tx_tcp_hdr = (struct tcp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
- unsigned char *tcp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct tcp_hdr));
- unsigned int *chksum_hdr = (unsigned int *)tx_ip_hdr->srcIP;
- unsigned int tcp_len = nLength + sizeof(struct tcp_hdr);
- unsigned int chksum = tcp_len + IP_TCP;
- int i;
-
- for (i = 0; i < nLength; i++)
- {
- *tcp_data = szData[i];
- tcp_data++;
- }
-
- tx_tcp_hdr->src_port = tcp_table[current_TCB].local_port;
- tx_tcp_hdr->dst_port = tcp_table[current_TCB].remote_port;
- tx_tcp_hdr->seq = tcp_table[current_TCB].local_seq++;
- if (control_bits & TCP_CNTRL_ACK)
- tx_tcp_hdr->ack = tcp_table[current_TCB].remote_seq;
- tx_tcp_hdr->cntrl_bits = control_bits;
-
- for (i = 0; i < 8; i++)
- chksum += *chksum_hdr;
-
- chksum_hdr = (unsigned int *)tx_tcp_hdr;
-
- // if the packet length is odd, pad it
- if (tcp_len % 2)
- *((unsigned char *)chksum_hdr + tcp_len) = 0;
-
- tcp_len = (tcp_len + 1) >> 1;
- for (i = 0; i < tcp_len; i++, chksum_hdr++)
- if (i != 8)
- chksum += *chksum_hdr;
- chksum = ~chksum;
-
- tx_ip_packet(tx_buf, nLength + sizeof(struct tcp_hdr));
-}
-
Index: trunk/apps/MicroWeb/arp.h
===================================================================
--- trunk/apps/MicroWeb/arp.h (revision 45)
+++ trunk/apps/MicroWeb/arp.h (nonexistent)
@@ -1,27 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// arp.h: defines for ARP processing
-
-#ifndef H__ARP
-#define H__ARP
-
-void rx_arp_packet(unsigned char *rx_buffer);
-void tx_arp_packet(unsigned int arp_oper);
-
-#endif
Index: trunk/apps/MicroWeb/udp.c
===================================================================
--- trunk/apps/MicroWeb/udp.c (revision 45)
+++ trunk/apps/MicroWeb/udp.c (nonexistent)
@@ -1,105 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// tcp.c: TCP protocol processing
-
-#include
-#include "packets.h"
-#include "ip.h"
-#include "udp.h"
-
-void tx_udp_packet(unsigned char *szData, unsigned char nLength)
-{
- unsigned char tx_buf[BUF_LEN];
- struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
- struct udp_hdr *tx_udp_hdr = (struct udp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
- unsigned char *udp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct udp_hdr));
- unsigned int *chksum_hdr = (unsigned int *)tx_udp_hdr;
- int i;
- unsigned int chksum = 0;
-
- for (i = 0; i < nLength; i++)
- {
- *udp_data = szData[i];
- udp_data++;
- }
-
- tx_udp_hdr->src_port = MY_UDP_PORT;
- tx_udp_hdr->dst_port = MY_UDP_PORT;
- tx_udp_hdr->length = sizeof(struct udp_hdr) + nLength;
-
- // Compute the checksum
- for (i = 0; i < 3; i++)
- {
- chksum += *chksum_hdr;
- chksum_hdr++;
- }
- chksum_hdr = (unsigned int *)&(tx_ip_hdr->proto);
- chksum += *chksum_hdr;
- chksum_hdr = (unsigned int *)&targetIP;
- for (i = 0; i < 4; i++)
- {
- chksum += *chksum_hdr;
- chksum_hdr++;
- }
- chksum = ~chksum;
- tx_udp_hdr->checksum = chksum;
-
- tx_ip_packet(tx_buf, nLength + sizeof(struct udp_hdr));
-}
-
-void rx_udp_packet(unsigned char *rx_buffer)
-{
- struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
- struct udp_hdr *rx_udp_hdr = (struct udp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
- unsigned int *tmp_chk = (unsigned int *)&rx_ip_hdr->srcIP;
- unsigned int checksum = 0;
- unsigned int i;
-#define msglen 15
- unsigned char msg[msglen] = "This is a test.";
-
- // check the length
- if (rx_udp_hdr->length == rx_ip_hdr->totlen - (sizeof(struct ip_hdr) / 8))
- {
- // check the checksum
- checksum = rx_udp_hdr->length + rx_ip_hdr->proto;
- checksum += (*tmp_chk)++;
- checksum += (*tmp_chk)++;
- checksum += (*tmp_chk)++;
- checksum += (*tmp_chk);
-
- tmp_chk = (unsigned int *)rx_udp_hdr;
-
- for (i = 0; i < rx_udp_hdr->length; i++)
- if (i != 3) //skip existing checksum
- checksum += *tmp_chk;
- checksum = ~checksum;
-
- // packet is valid if they match
- if (checksum == rx_udp_hdr->checksum)
- // check the port numbers
- if ((rx_udp_hdr->src_port == MY_UDP_PORT) && (rx_udp_hdr->dst_port == MY_UDP_PORT))
- {
- // packet is ok, respond
- tx_udp_packet(msg, strlen(msg));
- }
- // else discard packet
- }
- // else discard packet
-}
-
Index: trunk/apps/MicroWeb/icmp.c
===================================================================
--- trunk/apps/MicroWeb/icmp.c (revision 45)
+++ trunk/apps/MicroWeb/icmp.c (nonexistent)
@@ -1,76 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// icmp.c: ICMP protocol processing
-
-#include
-#include "packets.h"
-#include "ip.h"
-#include "icmp.h"
-
-void tx_icmp_packet(unsigned char tx_type, unsigned char *szData, unsigned char nLength)
-{
- unsigned char tx_buf[BUF_LEN];
- struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
- struct icmp_hdr *tx_icmp_hdr = (struct icmp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
- unsigned char *icmp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct icmp_hdr));
- unsigned int *chksum_hdr = (unsigned int *)tx_icmp_hdr;
- int i;
- unsigned int chksum = 0;
-
- tx_icmp_hdr->type = tx_type;
- tx_icmp_hdr->sequence = 0x01;
- for (i = 0; i < nLength; i++)
- {
- *icmp_data = *szData;
- icmp_data++;
- szData++;
- }
-
- // Compute the checksum
- for (i = 0; i < 5; i++)
- if (i != 1)
- {
- chksum += *chksum_hdr;
- chksum_hdr++;
- }
- chksum = ~chksum;
- tx_icmp_hdr->checksum = 0x0b12;
-
- tx_ip_packet(tx_buf, nLength + sizeof(struct icmp_hdr));
-}
-
-void rx_icmp_packet(unsigned char *rx_buffer)
-{
- struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
- struct icmp_hdr *rx_icmp_hdr = (struct icmp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
- unsigned char *pszData = (unsigned char *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct icmp_hdr));
- unsigned int nDataLen = rx_ip_hdr->totlen - sizeof(struct icmp_hdr) - sizeof(struct ip_hdr);
-
- // if it's an echo request, send a reply
- if (rx_icmp_hdr->type == ICMP_ECHO)
- {
- // switch source and destination IP's
- memcpy(targetMAC, srcMAC, sizeof(unsigned char) * 6);
- memcpy(targetIP, srcIP, sizeof(unsigned char) * 4);
-
- tx_icmp_packet(ICMP_ECHOREPLY, pszData, nDataLen);
- }
- // else discard packet
-}
-
Index: trunk/apps/MicroWeb/tcp.h
===================================================================
--- trunk/apps/MicroWeb/tcp.h (revision 45)
+++ trunk/apps/MicroWeb/tcp.h (nonexistent)
@@ -1,70 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// tcp.h: structures for tcp connections
-
-#ifndef H__TCP
-#define H__TCP
-
-#define TCP_MAX_CONN 1
-
-enum tcp_state
-{
- LISTEN = 1,
- SYN_SENT,
- SYN_RECVD,
- ESTABLISHED,
- FIN_WAIT_1,
- FIN_WAIT_2,
- CLOSE_WAIT,
- CLOSING,
- LAST_ACK,
- TIME_WAIT,
- CLOSED
-};
-
-enum tcp_cntrl_flags
-{
- TCP_CNTRL_FIN = 0x01,
- TCP_CNTRL_SYN = 0x02,
- TCP_CNTRL_RST = 0x04,
- TCP_CNTRL_PSH = 0x08,
- TCP_CNTRL_ACK = 0x10,
- TCP_CNTRL_URG = 0x20
-};
-
-struct tcp_TCB
-{
- unsigned int local_port; // Local port number
- unsigned int remote_port; // Remote port number
- unsigned char remote_addr[4]; // Remote IP address
- unsigned char state; // Our current state
- unsigned char local_seq; // Local sequence number
- unsigned char remote_seq; // Remote sequence number
-};
-
-#define TCP_PORT_HTTP 80
-
-#define TCP_START_SEQ 50
-
-void tcp_init(void);
-void rx_tcp_packet(unsigned char *rx_buffer);
-void tx_tcp_packet(unsigned char current_TCB, unsigned char control_bits, unsigned char *szData, unsigned int nLength);
-
-#endif
-
Index: trunk/apps/MicroWeb/csioa.asm
===================================================================
--- trunk/apps/MicroWeb/csioa.asm (revision 45)
+++ trunk/apps/MicroWeb/csioa.asm (nonexistent)
@@ -1,127 +0,0 @@
-; Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-;
-; This file is part of MicroWeb.
-;
-; MicroWeb is free software; you can redistribute it and/or modify
-; it under the terms of the GNU General Public License as published by
-; the Free Software Foundation; either version 2 of the License, or
-; (at your option) any later version.
-;
-; MicroWeb is distributed in the hope that it will be useful,
-; but WITHOUT ANY WARRANTY; without even the implied warranty of
-; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-; GNU General Public License for more details.
-;
-; You should have received a copy of the GNU General Public License
-; along with MicroWeb; if not, write to the Free Software
-; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-; csio.a51: driver code for CS8900A chip located at 7000h
-
- .module csioa
-
- .globl _write_byte
- .globl _read_byte
- .globl _write_word
- .globl _read_wordL
- .globl _read_wordH
- .globl _write_byte_PARM_2
- .globl _write_word_PARM_2
-
- .area XSEG (XDATA)
-_write_byte_PARM_2::
- .ds 2
-_write_word_PARM_2::
- .ds 2
-
-csio_port = 0x70
-
- .area CSEG (CODE)
-
-; write_byte(io_port = R7, data = R5)
-_write_byte:
- push ACC
- mov A, dpl
- add A, #csio_port
- mov DPH, A
- mov A, R5
- movx @dptr, a
- pop ACC
- ret
-
-; read_byte(io_port = R7), value returned in R7
-_read_byte:
- push ACC
- mov A, R7
- add A, #csio_port
- mov DPH, A
- movx a, @dptr
- mov R7, A
- pop ACC
- ret
-
-; write_word(io_port(8 bits), data(16 bits))
-_write_word:
- push ACC
- mov A, DPL
- add A, #csio_port
- mov R1, A
- mov dptr, #_write_word_PARM_2
- movx a, @dptr
- push acc
- mov a, r1
- mov dph, a
- pop acc
- movx @dptr, a
- mov dptr, #_write_word_PARM_2
- inc dptr
- movx a, @dptr
- push acc
- mov A, R1
- inc A
- mov DPH, A
- pop acc
- movx @dptr, a
- pop ACC
- ret
-
-; read_wordL(io_port = DPL) return in DPTR
-; read the low order byte first(R7)
-_read_wordL:
- push ACC
- mov A, DPL
- add A, #csio_port
- mov R1, A
- mov DPH, A
- movx A, @dptr
- push acc
- mov A, R1
- inc A
- mov DPH, A
- movx a, @dptr
- mov dph, A
- pop dpl
- pop ACC
- ret
-
-; read_wordH(io_port = DPL) return in DPTR
-; read the high order byte first(R6)
-_read_wordH:
- push ACC
- mov A, dpl
- add A, #csio_port
- mov R1, A
- inc A
- mov DPH, A
- movx a, @dptr
- push acc
- mov A, R1
- mov DPH, A
- movx a, @dptr
- mov dpl, A
- pop dph
- pop ACC
- ret
-
-;.end
-
Index: trunk/apps/MicroWeb/Makefile
===================================================================
--- trunk/apps/MicroWeb/Makefile (revision 45)
+++ trunk/apps/MicroWeb/Makefile (nonexistent)
@@ -1,28 +0,0 @@
-#
-#
-#
-
-SHELL = /bin/sh
-SDCCFLAGS = --model-large -I /home/dinesha/download/sdcc/device/include/mcs51 -I /home/dinesha/download/sdcc/device/include/ -L /home/dinesha/download/sdcc/device/lib/build/large
-ASLINKFLAGS = --code-loc 0x8000 --data-loc 0x30 --stack-loc 0x20 --xram-loc 0xD000
-MODULES = main.rel csio.rel csioa.rel tcp.rel udp.rel icmp.rel arp.rel ip.rel
-
-%.rel: %.c
- sdcc $(SDCCFLAGS) -c $<
-
-#main.rel: main.c
-# sdcc $(SDCCFLAGS) -c $<
-
-%.rel: %.asm
- sdas8051 -los $<
-
-all: microweb.hex
-
-microweb.hex :: $(MODULES)
- sdcc $(SDCCFLAGS) $(ASLINKFLAGS) $(MODULES)
- packihx main.ihx > microweb.hex
-
-clean:
- rm -f tcp.asm udp.asm icmp.asm arp.asm ip.asm csio.asm main.asm main.mem
- rm -f *.hex *.ihx *.lnk *.lst *.map *.rel *.rst *.sym
-
Index: trunk/apps/MicroWeb/icmp.h
===================================================================
--- trunk/apps/MicroWeb/icmp.h (revision 45)
+++ trunk/apps/MicroWeb/icmp.h (nonexistent)
@@ -1,27 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// icmp.h: defines for ICMP
-
-#ifndef H__ICMP
-#define H__ICMP
-
-void tx_icmp_packet(unsigned char tx_type, unsigned char *szData, unsigned char nLength);
-void rx_icmp_packet(unsigned char *rx_buffer);
-
-#endif
Index: trunk/apps/MicroWeb/csio.c
===================================================================
--- trunk/apps/MicroWeb/csio.c (revision 45)
+++ trunk/apps/MicroWeb/csio.c (nonexistent)
@@ -1,143 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// csio.c: driver code for CS8900A chip
-
-#include "csio.h"
-#include "csioa.h"
-
-void cs_init(unsigned char my_MAC_addr[])
-{
- unsigned int nReturn = 0;
-
- // reset the chip
- write_word(IO_PPPointer, PP_SelfCTL);
- write_word(IO_PPData, RESET);
-
- // wait until chip is ready
- while (!(nReturn & INITD))
- {
- write_word(IO_PPPointer, PP_SelfST);
- nReturn = read_wordL(IO_PPData);
- }
-
- // setup RxCTL(0104h)
- write_word(IO_PPPointer, PP_RxCTL);
- write_word(IO_PPData, RX_OK_ACCEPT | RX_IA_ACCEPT | RX_BROADCAST_ACCEPT);
- nReturn = read_wordL(IO_PPData);
-
- // write the MAC address starting at 0158h
- write_word(IO_PPPointer, PP_IA);
- write_word(IO_PPData, (my_MAC_addr[1] << 8) | my_MAC_addr[0]);
- write_word(IO_PPPointer, PP_IA + 2);
- write_word(IO_PPData, (my_MAC_addr[3] << 8) | my_MAC_addr[2]);
- write_word(IO_PPPointer, PP_IA + 4);
- write_word(IO_PPData, (my_MAC_addr[5] << 8) | my_MAC_addr[4]);
-
- // enable receive and transmit
- write_word(IO_PPPointer, PP_LineCTL);
- write_word(IO_PPData, SERIAL_RX_ON | SERIAL_TX_ON);
-}
-
-unsigned char cs_test(void)
-{
- unsigned int nReturn;
-
- // Read from PPData port, should get 0E63h
- nReturn = read_wordL(IO_PPData);
-
- if (nReturn != 0x630E)
- return 0;
-
- // Read from register RxCFG(0102h), should get 3h
- write_word(IO_PPPointer, PP_RxCFG);
- nReturn = read_wordL(IO_PPData);
-
- if (nReturn != 0x0003)
- return 0;
-
- // Display OK Here at Hyper Teminal or at LCD Monitor
-
- return 1;
-}
-
-unsigned char rx_event_poll(void)
-{
- unsigned int nReturn = 0x0000;
-
- write_word(IO_PPPointer, PP_RxEvent);
- nReturn = read_wordL(IO_PPData);
-
- if ((nReturn & RX_OK) && !(nReturn & RX_HASH))
- return 1;
-
- return 0;
-}
-
-unsigned int rx_packet(unsigned char *rx_buffer)
-{
- unsigned int data nReturn = 0x0000;
- unsigned int data nLength = 0x0000;
- unsigned int data nData = 0x0000;
- unsigned char i;
-
- write_word(IO_PPPointer, PP_RxStatus);
- nReturn = read_wordL(IO_PPData);
-
- write_word(IO_PPPointer, PP_RxLength);
- nLength = read_wordL(IO_PPData);
-
- for (i = 0; i < nLength; i += 2)
- {
- write_word(IO_PPPointer, PP_RxFrame + i);
- nData = read_wordL(IO_PPData);
- rx_buffer[i] = (unsigned char)(nData & 0xFF);
- rx_buffer[i + 1] = (unsigned char)((nData >> 8) & 0xFF);
- }
-
- return nLength;
-}
-
-void tx_packet(unsigned char *tx_buffer, unsigned int tx_buffer_len)
-{
- unsigned int nReturn = 0;
- unsigned int i = 0;
- unsigned char *tx_send = (unsigned char *)tx_buffer;
-
- // write transmit command to TxCMD port
- write_word(IO_TxCMD, 0x00C0);
- // write transmit size to TxLength port
- write_word(IO_TxLength, tx_buffer_len);
-
- // wait until space is available
- while (!(nReturn & READY_FOR_TX_NOW))
- {
- write_word(IO_PPPointer, PP_BusST);
- nReturn = read_wordL(IO_PPData);
- }
-
- // round odd packets up and convert to words
- tx_buffer_len = (tx_buffer_len + 1) >> 1;
- for (i = 0; i < tx_buffer_len; i++)
- {
- write_word(IO_RxTxData, *(tx_send++));
- tx_send += 2;
- }
-}
-
-
Index: trunk/apps/MicroWeb/udp.h
===================================================================
--- trunk/apps/MicroWeb/udp.h (revision 45)
+++ trunk/apps/MicroWeb/udp.h (nonexistent)
@@ -1,28 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// udp.h: defines for UDP
-
-#ifndef H__UDP
-#define H__UDP
-
-void tx_udp_packet(unsigned char *szData, unsigned char nLength);
-void rx_udp_packet(unsigned char *rx_buffer);
-
-#endif
-
Index: trunk/apps/MicroWeb/packets.h
===================================================================
--- trunk/apps/MicroWeb/packets.h (revision 45)
+++ trunk/apps/MicroWeb/packets.h (nonexistent)
@@ -1,139 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// packets.h: definitions for packet structures
-
-#ifndef H__PACKETS
-#define H__PACKETS
-
-#define MAC_ADDR_LEN 6
-#define IP_ADDR_LEN 4
-
-struct eth_hdr
-{
- unsigned char dhost[MAC_ADDR_LEN]; // destination MAC address
- unsigned char shost[MAC_ADDR_LEN]; // source MAC address
- unsigned int type; // packet type
-};
-
-#define ETHER_IP 0x0800
-#define ETHER_ARP 0x0806
-
-struct arp_hdr
-{
- unsigned int ar_hrd; // Hardware Address format
- unsigned int ar_pro; // Protocol Address format
- unsigned char ar_hln; // Byte length of each hardware address
- unsigned char ar_pln; // Byte length of each protocol address
- unsigned int ar_op; // Opcode
-};
-
-#define ARP_REQUEST 0x01
-#define ARP_REPLY 0x02
-#define ARP_HRD_ETHER 0x01
-
-struct eth_arp
-{
- struct arp_hdr eth_arp_hdr;
- unsigned char ar_sha[MAC_ADDR_LEN]; // Sender's MAC address
- unsigned char ar_spa[4]; // Sender's protocol address
- unsigned char ar_tha[MAC_ADDR_LEN]; // Target's MAC address
- unsigned char ar_tpa[4]; // Target's protocol address
-};
-
-struct ip_hdr
-{
- unsigned char verIHL; // version - 4 bits, Internet Header Length - 4 bits
- unsigned char TOS; // Type of Service - 8 bits
- unsigned int totlen; // Total Length of the datagram - 16 bits
- unsigned int id; // Identification of datagram - 16 bits
- unsigned int fragoff; // Flags - 3 bits, Fragment Offset - 13 bits
- unsigned char TTL; // Time to Live - 8 bits
- unsigned char proto; // Protocol - 8 bits
- unsigned int hdrchksum; // Header Checksum - 16 bits
- unsigned char srcIP[4]; // Source IP Address - 32 bits
- unsigned char destIP[4]; // Destination IP Address - 32 bits
-};
-
-#define IP_ICMP 0x0001
-#define IP_TCP 0x0006
-#define IP_UDP 0x0011
-
-struct icmp_hdr
-{
- unsigned char type;
- unsigned char icode;
- unsigned int checksum;
- unsigned int identifier;
- unsigned int sequence;
-// unsigned long icdata;
-};
-
-#define ICMP_ECHOREPLY 0 /* Echo Reply */
-#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
-#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
-#define ICMP_REDIRECT 5 /* Redirect (change route) */
-#define ICMP_ECHO 8 /* Echo Request */
-#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
-#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
-#define ICMP_TIMESTAMP 13 /* Timestamp Request */
-#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
-#define ICMP_INFO_REQUEST 15 /* Information Request */
-#define ICMP_INFO_REPLY 16 /* Information Reply */
-#define ICMP_ADDRESS 17 /* Address Mask Request */
-#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
-
-struct udp_hdr
-{
- unsigned int src_port; // Source port, optional
- unsigned int dst_port; // Destination port
- unsigned int length; // Length of datagram in bytes, incl. header
- unsigned int checksum; // Checksum of psuedo-header
-};
-
-#define MY_UDP_PORT 0x6969
-
-struct tcp_hdr
-{
- unsigned int src_port; // Source port
- unsigned int dst_port; // Destination port
- unsigned long seq; // Sequence number
- unsigned long ack; // Acknowledgement number
- unsigned char data_off; // Data offset - upper 4 bits
- unsigned char cntrl_bits; // Control bits - lower 6 bits
- unsigned int window; // Window
- unsigned int checksum; // Checksum
- unsigned int urgent; // Urgent pointer
- // Options may additionally follow
-};
-
-#define BUF_LEN 1500
-
-extern unsigned char myMAC[6];
-extern unsigned char myIP[4];
-extern unsigned char targetIP[4];
-extern unsigned char targetMAC[6];
-extern unsigned char srcMAC[6];
-extern unsigned char srcIP[4];
-extern unsigned char tmpMAC[6];
-extern unsigned char tmpIP[4];
-extern unsigned char myBCAST[4];
-extern int mac_size;
-extern int ip_size;
-
-#endif
Index: trunk/apps/MicroWeb/csio.h
===================================================================
--- trunk/apps/MicroWeb/csio.h (revision 45)
+++ trunk/apps/MicroWeb/csio.h (nonexistent)
@@ -1,99 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// csio.h: defines and variables for CS8900A driver code
-
-#ifndef H__CSIO
-#define H__CSIO
-
-// PacketPage control and config registers
-#define PP_RxCFG 0x0102 /* Rx Bus config */
-#define PP_RxCTL 0x0104 /* Receive Control Register */
-#define PP_TxCFG 0x0106 /* Transmit Config Register */
-#define PP_TxCMD 0x0108 /* Transmit Command Register */
-#define PP_BufCFG 0x010A /* Bus configuration Register */
-#define PP_LineCTL 0x0112 /* Line Config Register */
-#define PP_SelfCTL 0x0114 /* Self Command Register */
-#define PP_BusCTL 0x0116 /* ISA bus control Register */
-#define PP_TestCTL 0x0118 /* Test Register */
-
-// PacketPage status and event registers
-#define PP_RxEvent 0x0124 /* Rx Event Register */
-#define PP_TxEvent 0x0128 /* Tx Event Register */
-#define PP_BufEvent 0x012C /* Bus Event Register */
-#define PP_RxMiss 0x0130 /* Receive Miss Count */
-#define PP_TxCol 0x0132 /* Transmit Collision Count */
-#define PP_LineST 0x0134 /* Line State Register */
-#define PP_SelfST 0x0136 /* Self State register */
-#define PP_BusST 0x0138 /* Bus Status */
-
-// PacketPage IO Port registers
-#define PP_TxCommand 0x0144 /* Tx Command */
-#define PP_TxLength 0x0146 /* Tx Length */
-#define PP_LAF 0x0150 /* Hash Table */
-#define PP_IA 0x0158 /* Physical Address Register */
-#define PP_RxStatus 0x0400 /* Receive start of frame */
-#define PP_RxLength 0x0402 /* Receive Length of frame */
-#define PP_RxFrame 0x0404 /* Beginning of received frame */
-
-// PP_RxEvent bits
-#define RX_OK 0x0100 /* Received a frame */
-#define RX_HASH 0x0200 /* Hashed address */
-
-// PP_RxCTL bits
-#define RX_IA_HASH_ACCEPT 0x0040 /* Accept Hashed frames */
-#define RX_OK_ACCEPT 0x0100 /* Accept frames */
-#define RX_IA_ACCEPT 0x0400 /* Accept destined for individual address */
-#define RX_BROADCAST_ACCEPT 0x0800 /* Accept destined for broadcast address */
-
-// PP_LineCTL bits
-#define SERIAL_RX_ON 0x0040 /* Receive frames on */
-#define SERIAL_TX_ON 0x0080 /* Transmit frames on */
-
-// PP_SelfST bits
-#define INITD 0x0080 /* Init is done */
-
-// PP_BusST bits
-#define TX_BID_ERROR 0x0080 /* Error on bidding for space */
-#define READY_FOR_TX_NOW 0x0100 /* Bid for space ok, ready to transmit */
-
-// PP_TestCTL bits
-#define ENDECLOOP 0x0200 /* Set to loopback mode */
-
-// PP_SelfCTL bits
-#define RESET 0x0040 /* Reset chip */
-
-// IO Port addresses
-#define IO_RxTxData 0x0000 /* Receive Transmit Data (Port 0) IO Port */
-#define IO_TxCMD 0x0004 /* Transmit Command IO Port */
-#define IO_TxLength 0x0006 /* Transmit Length IO Port */
-#define IO_PPPointer 0x000A /* PacketPage Pointer IO Port */
-#define IO_PPData 0x000C /* PacketPage Data IO Port */
-
-void cs_init(unsigned char my_MAC_addr[]);
-unsigned char cs_test(void);
-//void cs_reset(void);
-unsigned char rx_event_poll(void);
-unsigned int rx_packet(unsigned char *rx_buffer);
-void tx_packet(unsigned char *tx_buffer, unsigned int tx_buffer_len);
-
-#endif
-
-
-
-
Index: trunk/apps/MicroWeb/csioa.h
===================================================================
--- trunk/apps/MicroWeb/csioa.h (revision 45)
+++ trunk/apps/MicroWeb/csioa.h (nonexistent)
@@ -1,30 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-// csioa.h: assembly routines for accessing CS8900A
-
-#ifndef H__CSIOA
-#define H__CSIOA
-
-extern void write_byte(unsigned char io_port, unsigned char out_data);
-extern unsigned char read_byte(unsigned char io_port);
-extern void write_word(unsigned char io_port, unsigned int out_data);
-extern unsigned int read_wordL(unsigned char io_port);
-extern unsigned int read_wordH(unsigned char io_port);
-
-#endif
Index: trunk/apps/MicroWeb/COPYLEFT
===================================================================
--- trunk/apps/MicroWeb/COPYLEFT (revision 45)
+++ trunk/apps/MicroWeb/COPYLEFT (nonexistent)
@@ -1,17 +0,0 @@
-// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
-//
-// This file is part of MicroWeb.
-//
-// MicroWeb is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// MicroWeb is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with MicroWeb; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Index: trunk/apps/reference/MicroWeb/ip.c
===================================================================
--- trunk/apps/reference/MicroWeb/ip.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/ip.c (revision 46)
@@ -0,0 +1,187 @@
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Tubo 8051 WebServer Project ////
+//// ////
+//// This file is part of the Turbo 8051 cores project ////
+//// http://www.opencores.org/cores/turbo8051/ ////
+//// ////
+//// Description ////
+//// The basic code is taken from MicroWeb project and necessary ////
+// upgrade is done to match the Turbo 8051 Webserver ////
+//// ////
+//// To Do: ////
+//// nothing ////
+//// ////
+//// Author(s): ////
+//// - Dinesh Annayya, dinesha@opencores.org ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+// Basic Code is from :
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// ip.c: IP protocol processing
+/************************************************************
+IP4 header:
+
+ 1. Version. 4 bits.
+ Specifies the format of the IP packet header.
+ 4 --- IP, Internet Protocol.
+ 2. IHL, Internet Header Length. 4 bits.
+ Specifies the length of the IP packet header in 32 bit words.
+ The minimum value for a valid header is 5.
+
+ 3. Differentiated Services. 8 bits.
+
+ 4. Codepoint. 6 bits.
+
+ 5. unused. 2 bits.
+
+ 6. TOS, Type of Service. 8 bits.
+
+ 7. Total length. 16 bits.
+ Contains the length of the datagram.
+
+ 8. Identification. 16 bits.
+ Used to identify the fragments of one datagram from those of another.
+ The originating protocol module of an internet datagram sets the identification field to a value that must be unique for that source-destination pair and protocol for the time the datagram will be active in the internet system. The originating protocol module of a complete datagram clears the MF bit to zero and the Fragment Offset field to zero.
+
+ 9. Flags. 3 bits.
+ 9.A R, reserved. 1 bit.
+ Should be cleared to 0.
+ 9.B DF, Don't fragment. 1 bit.
+ Controls the fragmentation of the datagram.
+ 9.C MF, More fragments. 1 bit.
+ Indicates if the datagram contains additional fragments.
+
+ 10. Fragment Offset. 13 bits.
+
+ 11. TTL, Time to Live. 8 bits.
+ A timer field used to track the lifetime of the datagram.
+ When the TTL field is decremented down to zero, the datagram is discarded.
+
+ 12. Protocol. 8 bits.
+ This field specifies the next encapsulated protocol.
+
+ 1 -- ICMP, Internet Control Message Protocol.
+ 2 -- IGAP, IGMP for user Authentication Protocol.
+ IGMP, Internet Group Management Protocol.
+ RGMP, Router-port Group Management Protocol.
+ 4 -- IP in IP encapsulation.
+ 6 -- TCP, Transmission Control Protocol.
+ 17-- UDP, User Datagram Protocol.
+ 41-- IPv6 over IPv4.
+ 58-- ICMPv6, Internet Control Message Protocol for IPv6.
+ MLD, Multicast Listener Discovery.
+ 59-- IPv6 No Next Header.
+ 97-- EtherIP.
+**********************************************************************/
+
+
+#include
+#include "packets.h"
+#include "csio.h"
+
+unsigned char rx_ip_packet(unsigned char *rx_buffer)
+{
+ struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
+ struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)rx_ip_hdr;
+ int i;
+ unsigned int chksum = 0;
+
+ // Make sure that the packet is destined for me or for broadcast
+ if ((!memcmp(myIP, &rx_ip_hdr->destIP, sizeof(unsigned char) * 4)) || (!memcmp(myBCAST, &rx_ip_hdr->destIP, sizeof(unsigned char) * 4)))
+ {
+ // Save the source MAC and IP for when I reply
+ memcpy(srcMAC, &rx_eth_hdr->shost, sizeof(unsigned char) * 6);
+ memcpy(srcIP, &rx_ip_hdr->srcIP, sizeof(unsigned char) * 4);
+
+ // Compute the checksum
+ for (i = 0; i < 10; i++)
+ if (i != 5)
+ chksum += *chksum_hdr;
+ chksum = ~chksum;
+
+ // packet is valid if they match
+ if (chksum == rx_ip_hdr->hdrchksum)
+ {
+ return rx_ip_hdr->proto;
+ }
+ else
+ return 0;
+ }
+ return 0;
+}
+
+void tx_ip_packet(unsigned char *tx_buffer, unsigned char tx_length)
+{
+ struct eth_hdr *tx_eth_hdr = (struct eth_hdr *)tx_buffer;
+ struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buffer + sizeof(struct eth_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)tx_ip_hdr;
+ int i;
+ unsigned int chksum = 0;
+
+ tx_ip_hdr->verIHL = 0x45;
+ tx_ip_hdr->totlen = tx_length + sizeof(struct ip_hdr);
+ tx_ip_hdr->TTL = 0x32;
+ tx_ip_hdr->proto = IP_UDP;
+
+ memcpy(tx_ip_hdr->srcIP, myIP, sizeof(unsigned char) * 4);
+ memcpy(tx_ip_hdr->destIP, targetIP, sizeof(unsigned char) * 4);
+
+ chksum_hdr = (unsigned int *)tx_ip_hdr;
+ // Compute the checksum
+ for (i = 0; i < 10; i++)
+ if (i != 5)
+ chksum += *chksum_hdr;
+ chksum = ~chksum;
+ tx_ip_hdr->hdrchksum = chksum;
+
+ tx_eth_hdr->type = ETHER_IP;
+ memcpy(tx_eth_hdr->shost, myMAC, sizeof(unsigned char) * 6);
+ memcpy(tx_eth_hdr->dhost, targetMAC, sizeof(unsigned char) * 6);
+
+ tx_packet(tx_buffer, tx_length);
+}
+
Index: trunk/apps/reference/MicroWeb/arp.c
===================================================================
--- trunk/apps/reference/MicroWeb/arp.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/arp.c (revision 46)
@@ -0,0 +1,181 @@
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Tubo 8051 WebServer Project ////
+//// ////
+//// This file is part of the Turbo 8051 cores project ////
+//// http://www.opencores.org/cores/turbo8051/ ////
+//// ////
+//// Description ////
+//// The basic code is taken from MicroWeb project and necessary ////
+// upgrade is done to match the Turbo 8051 Webserver ////
+//// ////
+//// To Do: ////
+//// nothing ////
+//// ////
+//// Author(s): ////
+//// - Dinesh Annayya, dinesha@opencores.org ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+//// ////
+//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
+//// ////
+//// This source file may be used and distributed without ////
+//// restriction provided that this copyright statement is not ////
+//// removed from the file and that any derivative work contains ////
+//// the original copyright notice and the associated disclaimer. ////
+//// ////
+//// This source file is free software; you can redistribute it ////
+//// and/or modify it under the terms of the GNU Lesser General ////
+//// Public License as published by the Free Software Foundation; ////
+//// either version 2.1 of the License, or (at your option) any ////
+//// later version. ////
+//// ////
+//// This source is distributed in the hope that it will be ////
+//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
+//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
+//// PURPOSE. See the GNU Lesser General Public License for more ////
+//// details. ////
+//// ////
+//// You should have received a copy of the GNU Lesser General ////
+//// Public License along with this source; if not, download it ////
+//// from http://www.opencores.org/lgpl.shtml ////
+//// ////
+//////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////
+// Basic Code is from :
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// arp.c: processing for ARP packets
+/*******************************************************
+ Arp Packet Format
+ [15:0] - HRD = 1
+ [15:0] - PRO = 0x0800
+ [7:0] - HLN = 6
+ [7:0] - PLN = 4
+ [15:0] - OP
+ [47:0] - SHA [0-5]
+ [31:0] - SPA [0-3]
+ [47:0] - THA [0-5]
+ [31:0] - TPA [0-3]
+
+HRD (Hardware Type): This field specfies the type of hardware used for the local network
+transmitting the ARP message.
+ 1 - Ethernet (10MB)
+ 6 - IEEE 802 Networks
+ 7 - ARCNET
+ 15 - Frame Relay
+ 16 - Asynhronous Transfer Mode (ATM)
+ 17 - HDLC
+ 18 - Fibre Channel
+ 19 - Asynchronous
+
+
+PRO (Protocol Type): This field is the complement of the Hardware Type field,
+ specifying the type of layer three addresses used in the message.
+ For IPv4 addresses, this value is 2048 (0800 hex),
+ which corresponds to the EtherType code for the Internet Protocol.
+
+HLN (Hardware Address Length):
+ Specifies how long hardware addresses are in this message.
+ For Ethernet or other networks using IEEE 802 MAC addresses, the value is 6.
+
+PLN (Protocol Address Length):
+ The complement of the preceding field; specifies how long protocol (layer three)
+ addresses are in this message. For IP(v4) addresses this value is of course 4.
+
+OP (Opcode): This field specifes the nature of the Arp Message being sent
+ 1 -- ARP Request
+ 2 -- ARP Reply
+ 3 -- RARP Request
+ 4 -- RARP Reply
+ 5 -- DRARP Request
+ 6 -- DRARP Reply
+ 7 -- DRARP Error
+ 8 -- InARP Request
+ 9 -- InARP Reply
+
+SHA (Sender Hardware Address):
+ The hardware (layer two) address of the device sending this message
+
+SPA (Sender Protocol Address):
+ The IP address of the device sending this message.
+
+THA (Target Hardware Address):
+ The hardware (layer two) address of the device this message is being sent to.
+
+TPA (Target Protocol Address):
+ The IP address of the device this message is being sent to.
+
+
+********************************************************/
+
+#include
+#include "packets.h"
+#include "csio.h"
+#include "arp.h"
+
+void tx_arp_packet(unsigned int arp_oper)
+{
+ unsigned char tx_buf[BUF_LEN];
+ struct eth_hdr *tx_eth_hdr = (struct eth_hdr *)(tx_buf);
+ struct eth_arp *tx_eth_arp = (struct eth_arp *)(tx_buf + sizeof(struct eth_hdr));
+ unsigned int nLength = 0;
+
+ tx_eth_arp->eth_arp_hdr.ar_hrd = ARP_HRD_ETHER;
+ tx_eth_arp->eth_arp_hdr.ar_pro = ETHER_IP;
+ tx_eth_arp->eth_arp_hdr.ar_hln = MAC_ADDR_LEN;
+ tx_eth_arp->eth_arp_hdr.ar_pln = IP_ADDR_LEN;
+ tx_eth_arp->eth_arp_hdr.ar_op = arp_oper;
+
+ memcpy(tx_eth_arp->ar_sha, myMAC, sizeof(char) * MAC_ADDR_LEN);
+ memcpy(tx_eth_arp->ar_spa, myIP, sizeof(char) * IP_ADDR_LEN);
+ memcpy(tx_eth_arp->ar_tha, targetMAC, sizeof(char) * MAC_ADDR_LEN);
+ memcpy(tx_eth_arp->ar_tpa, targetIP, sizeof(char) * IP_ADDR_LEN);
+
+ memcpy(tx_eth_hdr->dhost, targetMAC, sizeof(char) * MAC_ADDR_LEN);
+ memcpy(tx_eth_hdr->shost, myMAC, sizeof(char) * MAC_ADDR_LEN);
+ tx_eth_hdr->type = ETHER_ARP;
+
+ nLength += sizeof(struct eth_hdr) + sizeof(struct eth_arp);
+
+ tx_packet(tx_buf, nLength);
+}
+
+void rx_arp_packet(unsigned char *rx_buffer)
+{
+ struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
+ struct eth_arp *rx_eth_arp = (struct eth_arp *)(rx_buffer + sizeof(struct eth_hdr));
+
+ // make sure the ARP packet is Ethernet and IP
+ if ((rx_eth_arp->eth_arp_hdr.ar_hrd == ARP_HRD_ETHER) && (rx_eth_arp->eth_arp_hdr.ar_pro == ETHER_IP))
+ {
+ // make sure the ARP packet is a request destined for us
+ if ((rx_eth_arp->eth_arp_hdr.ar_op == ARP_REQUEST) && (!memcmp(myIP, rx_eth_arp->ar_tpa, sizeof(unsigned char) * 4)))
+ {
+ // send a reply
+ memcpy(targetMAC, rx_eth_arp->ar_sha, sizeof(char) * MAC_ADDR_LEN);
+ memcpy(targetIP, rx_eth_arp->ar_spa, sizeof(char) * IP_ADDR_LEN);
+ tx_arp_packet(ARP_REPLY);
+ }
+ // else discard packet
+ }
+ // else discard packet
+}
+
Index: trunk/apps/reference/MicroWeb/packets.h
===================================================================
--- trunk/apps/reference/MicroWeb/packets.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/packets.h (revision 46)
@@ -0,0 +1,139 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// packets.h: definitions for packet structures
+
+#ifndef H__PACKETS
+#define H__PACKETS
+
+#define MAC_ADDR_LEN 6
+#define IP_ADDR_LEN 4
+
+struct eth_hdr
+{
+ unsigned char dhost[MAC_ADDR_LEN]; // destination MAC address
+ unsigned char shost[MAC_ADDR_LEN]; // source MAC address
+ unsigned int type; // packet type
+};
+
+#define ETHER_IP 0x0800
+#define ETHER_ARP 0x0806
+
+struct arp_hdr
+{
+ unsigned int ar_hrd; // Hardware Address format
+ unsigned int ar_pro; // Protocol Address format
+ unsigned char ar_hln; // Byte length of each hardware address
+ unsigned char ar_pln; // Byte length of each protocol address
+ unsigned int ar_op; // Opcode
+};
+
+#define ARP_REQUEST 0x01
+#define ARP_REPLY 0x02
+#define ARP_HRD_ETHER 0x01
+
+struct eth_arp
+{
+ struct arp_hdr eth_arp_hdr;
+ unsigned char ar_sha[MAC_ADDR_LEN]; // Sender's MAC address
+ unsigned char ar_spa[4]; // Sender's protocol address
+ unsigned char ar_tha[MAC_ADDR_LEN]; // Target's MAC address
+ unsigned char ar_tpa[4]; // Target's protocol address
+};
+
+struct ip_hdr
+{
+ unsigned char verIHL; // version - 4 bits, Internet Header Length - 4 bits
+ unsigned char TOS; // Type of Service - 8 bits
+ unsigned int totlen; // Total Length of the datagram - 16 bits
+ unsigned int id; // Identification of datagram - 16 bits
+ unsigned int fragoff; // Flags - 3 bits, Fragment Offset - 13 bits
+ unsigned char TTL; // Time to Live - 8 bits
+ unsigned char proto; // Protocol - 8 bits
+ unsigned int hdrchksum; // Header Checksum - 16 bits
+ unsigned char srcIP[4]; // Source IP Address - 32 bits
+ unsigned char destIP[4]; // Destination IP Address - 32 bits
+};
+
+#define IP_ICMP 0x0001
+#define IP_TCP 0x0006
+#define IP_UDP 0x0011
+
+struct icmp_hdr
+{
+ unsigned char type;
+ unsigned char icode;
+ unsigned int checksum;
+ unsigned int identifier;
+ unsigned int sequence;
+// unsigned long icdata;
+};
+
+#define ICMP_ECHOREPLY 0 /* Echo Reply */
+#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
+#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
+#define ICMP_REDIRECT 5 /* Redirect (change route) */
+#define ICMP_ECHO 8 /* Echo Request */
+#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
+#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
+#define ICMP_TIMESTAMP 13 /* Timestamp Request */
+#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
+#define ICMP_INFO_REQUEST 15 /* Information Request */
+#define ICMP_INFO_REPLY 16 /* Information Reply */
+#define ICMP_ADDRESS 17 /* Address Mask Request */
+#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
+
+struct udp_hdr
+{
+ unsigned int src_port; // Source port, optional
+ unsigned int dst_port; // Destination port
+ unsigned int length; // Length of datagram in bytes, incl. header
+ unsigned int checksum; // Checksum of psuedo-header
+};
+
+#define MY_UDP_PORT 0x6969
+
+struct tcp_hdr
+{
+ unsigned int src_port; // Source port
+ unsigned int dst_port; // Destination port
+ unsigned long seq; // Sequence number
+ unsigned long ack; // Acknowledgement number
+ unsigned char data_off; // Data offset - upper 4 bits
+ unsigned char cntrl_bits; // Control bits - lower 6 bits
+ unsigned int window; // Window
+ unsigned int checksum; // Checksum
+ unsigned int urgent; // Urgent pointer
+ // Options may additionally follow
+};
+
+#define BUF_LEN 1500
+
+extern unsigned char myMAC[6];
+extern unsigned char myIP[4];
+extern unsigned char targetIP[4];
+extern unsigned char targetMAC[6];
+extern unsigned char srcMAC[6];
+extern unsigned char srcIP[4];
+extern unsigned char tmpMAC[6];
+extern unsigned char tmpIP[4];
+extern unsigned char myBCAST[4];
+extern int mac_size;
+extern int ip_size;
+
+#endif
Index: trunk/apps/reference/MicroWeb/csio.h
===================================================================
--- trunk/apps/reference/MicroWeb/csio.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/csio.h (revision 46)
@@ -0,0 +1,99 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// csio.h: defines and variables for CS8900A driver code
+
+#ifndef H__CSIO
+#define H__CSIO
+
+// PacketPage control and config registers
+#define PP_RxCFG 0x0102 /* Rx Bus config */
+#define PP_RxCTL 0x0104 /* Receive Control Register */
+#define PP_TxCFG 0x0106 /* Transmit Config Register */
+#define PP_TxCMD 0x0108 /* Transmit Command Register */
+#define PP_BufCFG 0x010A /* Bus configuration Register */
+#define PP_LineCTL 0x0112 /* Line Config Register */
+#define PP_SelfCTL 0x0114 /* Self Command Register */
+#define PP_BusCTL 0x0116 /* ISA bus control Register */
+#define PP_TestCTL 0x0118 /* Test Register */
+
+// PacketPage status and event registers
+#define PP_RxEvent 0x0124 /* Rx Event Register */
+#define PP_TxEvent 0x0128 /* Tx Event Register */
+#define PP_BufEvent 0x012C /* Bus Event Register */
+#define PP_RxMiss 0x0130 /* Receive Miss Count */
+#define PP_TxCol 0x0132 /* Transmit Collision Count */
+#define PP_LineST 0x0134 /* Line State Register */
+#define PP_SelfST 0x0136 /* Self State register */
+#define PP_BusST 0x0138 /* Bus Status */
+
+// PacketPage IO Port registers
+#define PP_TxCommand 0x0144 /* Tx Command */
+#define PP_TxLength 0x0146 /* Tx Length */
+#define PP_LAF 0x0150 /* Hash Table */
+#define PP_IA 0x0158 /* Physical Address Register */
+#define PP_RxStatus 0x0400 /* Receive start of frame */
+#define PP_RxLength 0x0402 /* Receive Length of frame */
+#define PP_RxFrame 0x0404 /* Beginning of received frame */
+
+// PP_RxEvent bits
+#define RX_OK 0x0100 /* Received a frame */
+#define RX_HASH 0x0200 /* Hashed address */
+
+// PP_RxCTL bits
+#define RX_IA_HASH_ACCEPT 0x0040 /* Accept Hashed frames */
+#define RX_OK_ACCEPT 0x0100 /* Accept frames */
+#define RX_IA_ACCEPT 0x0400 /* Accept destined for individual address */
+#define RX_BROADCAST_ACCEPT 0x0800 /* Accept destined for broadcast address */
+
+// PP_LineCTL bits
+#define SERIAL_RX_ON 0x0040 /* Receive frames on */
+#define SERIAL_TX_ON 0x0080 /* Transmit frames on */
+
+// PP_SelfST bits
+#define INITD 0x0080 /* Init is done */
+
+// PP_BusST bits
+#define TX_BID_ERROR 0x0080 /* Error on bidding for space */
+#define READY_FOR_TX_NOW 0x0100 /* Bid for space ok, ready to transmit */
+
+// PP_TestCTL bits
+#define ENDECLOOP 0x0200 /* Set to loopback mode */
+
+// PP_SelfCTL bits
+#define RESET 0x0040 /* Reset chip */
+
+// IO Port addresses
+#define IO_RxTxData 0x0000 /* Receive Transmit Data (Port 0) IO Port */
+#define IO_TxCMD 0x0004 /* Transmit Command IO Port */
+#define IO_TxLength 0x0006 /* Transmit Length IO Port */
+#define IO_PPPointer 0x000A /* PacketPage Pointer IO Port */
+#define IO_PPData 0x000C /* PacketPage Data IO Port */
+
+void cs_init(unsigned char my_MAC_addr[]);
+unsigned char cs_test(void);
+//void cs_reset(void);
+unsigned char rx_event_poll(void);
+unsigned int rx_packet(unsigned char *rx_buffer);
+void tx_packet(unsigned char *tx_buffer, unsigned int tx_buffer_len);
+
+#endif
+
+
+
+
Index: trunk/apps/reference/MicroWeb/csioa.h
===================================================================
--- trunk/apps/reference/MicroWeb/csioa.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/csioa.h (revision 46)
@@ -0,0 +1,30 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// csioa.h: assembly routines for accessing CS8900A
+
+#ifndef H__CSIOA
+#define H__CSIOA
+
+extern void write_byte(unsigned char io_port, unsigned char out_data);
+extern unsigned char read_byte(unsigned char io_port);
+extern void write_word(unsigned char io_port, unsigned int out_data);
+extern unsigned int read_wordL(unsigned char io_port);
+extern unsigned int read_wordH(unsigned char io_port);
+
+#endif
Index: trunk/apps/reference/MicroWeb/COPYLEFT
===================================================================
--- trunk/apps/reference/MicroWeb/COPYLEFT (nonexistent)
+++ trunk/apps/reference/MicroWeb/COPYLEFT (revision 46)
@@ -0,0 +1,17 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Index: trunk/apps/reference/MicroWeb/README
===================================================================
--- trunk/apps/reference/MicroWeb/README (nonexistent)
+++ trunk/apps/reference/MicroWeb/README (revision 46)
@@ -0,0 +1,11 @@
+== MicroWeb v0.01 ==
+
+This program is a Web Server and TCP/IP stack for 8051 microcontrollers.
+It started out as my Senior Project while a Senior at Bradley University.
+I hope to expand it to work on other microcontrollers and be used in a
+variety of applications.
+
+This version is meant to be compiled with SDCC on Linux.
+
+Mason Kidd
+
Index: trunk/apps/reference/MicroWeb/ip.h
===================================================================
--- trunk/apps/reference/MicroWeb/ip.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/ip.h (revision 46)
@@ -0,0 +1,27 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// ip.h: defines for IP
+
+#ifndef H__IP
+#define H__IP
+
+void tx_ip_packet(unsigned char *tx_buffer, unsigned char tx_length);
+unsigned char rx_ip_packet(unsigned char *rx_buffer);
+
+#endif
Index: trunk/apps/reference/MicroWeb/http.c
===================================================================
--- trunk/apps/reference/MicroWeb/http.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/http.c (revision 46)
@@ -0,0 +1,89 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// http.c: HTTP protocol processing
+
+#include
+#include "packets.h"
+#include "tcp.h"
+#include "http.h"
+
+void http_response();
+void http_error(int nStatus, char *szTitle, char *szText);
+void http_header(int nStatus, char *szTitle, int nLength);
+
+unsigned char szBuf[500];
+unsigned char *pszBuf = szBuf;
+unsigned char cTCB = 0;
+
+void tx_http_packet(unsigned char *szData, unsigned char nLength)
+{
+ tx_tcp_packet(cTCB, 0, szData, nLength);
+}
+
+void rx_http_packet(unsigned char *szData, unsigned char nLength, unsigned char current_TCB)
+{
+ unsigned char method[5], path[100], protocol[10];
+ char *file;
+ int nFileLength;
+
+ pszBuf = szBuf;
+ cTCB = current_TCB;
+
+ if (sscanf(szData, "%[^ ] %[^ ] %[^\r]", method, path, protocol) != 3)
+ http_error(400, "Bad Request", "Unable to prarse request.");
+ if (strcasecmp(method, "get") != 0)
+ http_error(501, "Not Implemented", "That method is not implemented.");
+ if (path[0] != '/')
+ http_error(400, "Bad Request", "Bad filename.");
+ file = &(path[1]);
+ nFileLength = strlen(file);
+ if (nFileLength == 0)
+ http_response();
+ else if ((strcasecmp(file, "index.html") == 0) || (strcasecmp(file, "index.htm") == 0))
+ http_response();
+ else
+ http_error(404, "Not Found", "File not found.");
+}
+
+void http_response()
+{
+ http_header(200, "Ok", -1);
+ pszBuf += sprintf(szBuf, "%s ", _HTTP_SERVER);
+ pszBuf += sprintf(szBuf, "The current temperature is %d degrees Fahrenheit", 20);
+
+ tx_http_packet(szBuf, strlen(szBuf));
+}
+
+void http_error(int nStatus, char *szTitle, char *szText)
+{
+ http_header(nStatus, szTitle, -1);
+ pszBuf += sprintf(szBuf, "%s ", szTitle);
+ pszBuf += sprintf(szBuf, "%s", szText);
+}
+
+void http_header(int nStatus, char *szTitle, int nLength)
+{
+ pszBuf += sprintf(szBuf, "%s %d %s\r\n", _HTTP_PROTOCOL, nStatus, szTitle);
+ pszBuf += sprintf(szBuf, "Server: %s\r\n", _HTTP_SERVER);
+ pszBuf += sprintf(szBuf, "Connection: close\r\n");
+ pszBuf += sprintf(szBuf, "Content-Type: text/html\r\n");
+ if (nLength > 0)
+ pszBuf += sprintf(szBuf, "Content-Length: %d\r\n", nLength);
+ pszBuf += sprintf(szBuf, "\r\n");
+}
Index: trunk/apps/reference/MicroWeb/http.h
===================================================================
--- trunk/apps/reference/MicroWeb/http.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/http.h (revision 46)
@@ -0,0 +1,31 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// http.h: defines for HTTP protocol
+
+#ifndef H__HTTP
+#define H__HTTP
+
+#define _HTTP_PROTOCOL "HTTP/1.0"
+#define _HTTP_SERVER "Microweb v0.1"
+
+void tx_http_packet(unsigned char *szData, unsigned char nLength);
+void rx_http_packet(unsigned char *szData, unsigned char nLength, unsigned char current_TCB);
+
+#endif
+
Index: trunk/apps/reference/MicroWeb/main.c
===================================================================
--- trunk/apps/reference/MicroWeb/main.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/main.c (revision 46)
@@ -0,0 +1,91 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// main.c: main source code file
+
+//#include
+#include <8051.h>
+#include
+#include "csio.h"
+#include "packets.h"
+#include "keypad.h"
+#include "arp.h"
+#include "ip.h"
+#include "icmp.h"
+#include "udp.h"
+#include "tcp.h"
+
+unsigned char myMAC[6] = {0x00,0x08,0x07,0x06,0x05,0x04};
+unsigned char myIP[4] = {192,168,1,1};
+unsigned char targetIP[4] = {192,168,1,2};
+unsigned char targetMAC[6] = {0x00,0xa0,0x24,0x66,0xda,0x3f};
+unsigned char srcMAC[6] = {0,0,0,0,0,0};
+unsigned char srcIP[4] = {0,0,0,0};
+unsigned char tmp_mac[6];
+unsigned char tmp_ip[4];
+unsigned char myBCAST[4] = {255,255,255,255};
+
+unsigned char rx_ip_type;
+unsigned char rx_buf[BUF_LEN];
+unsigned int rx_buf_len;
+unsigned int rx_packet_type;
+
+void main(void)
+{
+ unsigned char cTest;
+ struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buf;
+ unsigned char bEvent = 0;
+ unsigned char bValid = 0;
+ unsigned char i = 0;
+
+ tcp_init();
+ cTest = cs_test();
+ cs_init(myMAC);
+
+ while (1)
+ {
+ bEvent = rx_event_poll();
+ if (bEvent == 1)
+ {
+ rx_buf_len = rx_packet(rx_buf);
+ rx_packet_type = rx_eth_hdr->type;
+ switch (rx_packet_type)
+ {
+ case ETHER_IP:
+ bValid = rx_ip_packet(rx_buf);
+ if(bValid !=0) break;
+ switch (rx_ip_type)
+ {
+ case IP_ICMP:
+ rx_icmp_packet(rx_buf);
+ break;
+ case IP_UDP:
+ rx_udp_packet(rx_buf);
+ break;
+ case IP_TCP:
+ rx_tcp_packet(rx_buf);
+ break;
+ }
+ break;
+ case ETHER_ARP:
+ rx_arp_packet(rx_buf);
+ break;
+ }
+ }
+ }
+}
Index: trunk/apps/reference/MicroWeb/tcp.c
===================================================================
--- trunk/apps/reference/MicroWeb/tcp.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/tcp.c (revision 46)
@@ -0,0 +1,245 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// tcp.c: TCP protocol processing
+
+#include "packets.h"
+#include "ip.h"
+#include "tcp.h"
+//#include "http.h"
+
+static struct tcp_TCB tcp_table[TCP_MAX_CONN];
+
+void tcp_init(void)
+{
+ int i;
+
+ for (i = 0; i < TCP_MAX_CONN; i++)
+ {
+ tcp_table[i].local_port = 0;
+ tcp_table[i].remote_port = 0;
+ tcp_table[i].remote_addr[0] = 0;
+ tcp_table[i].remote_addr[1] = 0;
+ tcp_table[i].remote_addr[2] = 0;
+ tcp_table[i].remote_addr[3] = 0;
+ tcp_table[i].state = LISTEN;
+ tcp_table[i].local_seq = 0;
+ tcp_table[i].remote_seq = 0;
+
+ }
+}
+
+unsigned char tcp_get_TCB(unsigned char remote_addr[4], unsigned int remote_port, unsigned int local_port)
+{
+ int i = 0;
+ unsigned char free_TCB = TCP_MAX_CONN;
+
+ for (i = 0; i < TCP_MAX_CONN; i++)
+ {
+ if (tcp_table[i].remote_addr[0] == remote_addr[0] &&
+ tcp_table[i].remote_addr[0] == remote_addr[1] &&
+ tcp_table[i].remote_addr[0] == remote_addr[2] &&
+ tcp_table[i].remote_addr[0] == remote_addr[3] &&
+ tcp_table[i].remote_port == remote_port &&
+ tcp_table[i].local_port == local_port)
+ return i;
+ else if (tcp_table[i].state == LISTEN)
+ free_TCB = i;
+ }
+
+ if (free_TCB != TCP_MAX_CONN)
+ {
+ tcp_table[free_TCB].local_port = local_port;
+ tcp_table[free_TCB].remote_port = remote_port;
+ tcp_table[free_TCB].remote_addr[0] = remote_addr[0];
+ tcp_table[free_TCB].remote_addr[1] = remote_addr[1];
+ tcp_table[free_TCB].remote_addr[2] = remote_addr[2];
+ tcp_table[free_TCB].remote_addr[3] = remote_addr[3];
+ return free_TCB;
+ }
+
+ return 0;
+}
+
+void delete_TCB(unsigned char num_TCB)
+{
+ tcp_table[num_TCB].local_port = 0;
+ tcp_table[num_TCB].remote_port = 0;
+ tcp_table[num_TCB].remote_addr[0] = 0;
+ tcp_table[num_TCB].remote_addr[1] = 0;
+ tcp_table[num_TCB].remote_addr[2] = 0;
+ tcp_table[num_TCB].remote_addr[3] = 0;
+ tcp_table[num_TCB].state = LISTEN;
+ tcp_table[num_TCB].local_seq = 0;
+ tcp_table[num_TCB].remote_seq = 0;
+}
+
+void rx_tcp_packet(unsigned char *rx_buffer)
+{
+ struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buffer;
+ struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
+ struct tcp_hdr *rx_tcp_hdr = (struct tcp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
+ unsigned int *tcp_data = (unsigned int *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct tcp_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)rx_ip_hdr->srcIP;
+ unsigned int tcp_len = rx_ip_hdr->totlen - sizeof(rx_ip_hdr);
+ unsigned int chksum = tcp_len + IP_TCP;
+ unsigned char current_TCB = 0;
+ bit process_data = 0;
+ int i;
+
+ for (i = 0; i < 8; i++)
+ chksum += *chksum_hdr;
+
+ chksum_hdr = (unsigned int *)rx_tcp_hdr;
+
+ // if the packet length is odd, pad it
+ if (tcp_len % 2)
+ *((unsigned char *)chksum_hdr + tcp_len) = 0;
+
+ tcp_len = (tcp_len + 1) >> 1;
+ for (i = 0; i < tcp_len; i++, chksum_hdr++)
+ if (i != 8)
+ chksum += *chksum_hdr;
+ chksum = ~chksum;
+
+ if (chksum == rx_tcp_hdr->checksum)
+ {
+ current_TCB = tcp_get_TCB(rx_ip_hdr->srcIP, rx_tcp_hdr->src_port, rx_tcp_hdr->dst_port);
+ if (current_TCB != 0)
+ {
+ switch (tcp_table[current_TCB].state)
+ {
+ case LISTEN:
+ if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_SYN)
+ {
+ // received SYN, send SYN and ACK, enter SYN_RECVD
+ tcp_table[current_TCB].state = SYN_RECVD;
+ tcp_table[current_TCB].local_seq = TCP_START_SEQ;
+ tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
+ tx_tcp_packet(current_TCB, TCP_CNTRL_ACK | TCP_CNTRL_SYN, 0, 0);
+ }
+ break;
+ case SYN_SENT:
+ if (rx_tcp_hdr->cntrl_bits & (TCP_CNTRL_ACK || TCP_CNTRL_SYN))
+ {
+ // received SYN and ACK, enter ESTABLISHED, send ACK
+ tcp_table[current_TCB].state = ESTABLISHED;
+ tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
+ tx_tcp_packet(current_TCB, TCP_CNTRL_ACK, 0, 0);
+ }
+ else if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_SYN)
+ {
+ // received SYN, enter SYN_RECVD, send ACK
+ tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
+ tcp_table[current_TCB].state = SYN_RECVD;
+ tx_tcp_packet(current_TCB, TCP_CNTRL_ACK, 0, 0);
+ }
+ break;
+ case SYN_RECVD:
+ if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_ACK)
+ {
+ // received ACK, enter ESTABLISHED
+ tcp_table[current_TCB].remote_seq = rx_tcp_hdr->seq;
+ tcp_table[current_TCB].state = ESTABLISHED;
+ }
+ break;
+ case ESTABLISHED:
+ if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_FIN)
+ {
+ // received FIN, send ACK, close connection
+ // skip the CLOSE_WAIT state
+ tcp_table[current_TCB].state = LAST_ACK;
+ tx_tcp_packet(current_TCB, TCP_CNTRL_ACK | TCP_CNTRL_FIN, 0, 0);
+ }
+ else
+ process_data = 1;
+ break;
+ case CLOSE_WAIT:
+ break;
+ case FIN_WAIT_1:
+ break;
+ case FIN_WAIT_2:
+ break;
+ case CLOSING:
+ break;
+ case LAST_ACK:
+ if (rx_tcp_hdr->cntrl_bits & TCP_CNTRL_ACK)
+ {
+ tcp_table[current_TCB].state = CLOSED;
+ }
+ case CLOSED:
+ delete_TCB(current_TCB);
+ break;
+ case TIME_WAIT:
+ break;
+ }
+ // connection is established, send data to correct socket
+ if (process_data == 1)
+ switch (rx_tcp_hdr->dst_port)
+ {
+ case TCP_PORT_HTTP:
+ //rx_http_packet((unsigned char *)tcp_data, tcp_len - sizeof(struct tcp_hdr));
+ break;
+ }
+ }
+ }
+ // else discard packet
+}
+
+void tx_tcp_packet(unsigned char current_TCB, unsigned char control_bits, unsigned char *szData, unsigned int nLength)
+{
+ unsigned char tx_buf[BUF_LEN];
+ struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
+ struct tcp_hdr *tx_tcp_hdr = (struct tcp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
+ unsigned char *tcp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct tcp_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)tx_ip_hdr->srcIP;
+ unsigned int tcp_len = nLength + sizeof(struct tcp_hdr);
+ unsigned int chksum = tcp_len + IP_TCP;
+ int i;
+
+ for (i = 0; i < nLength; i++)
+ {
+ *tcp_data = szData[i];
+ tcp_data++;
+ }
+
+ tx_tcp_hdr->src_port = tcp_table[current_TCB].local_port;
+ tx_tcp_hdr->dst_port = tcp_table[current_TCB].remote_port;
+ tx_tcp_hdr->seq = tcp_table[current_TCB].local_seq++;
+ if (control_bits & TCP_CNTRL_ACK)
+ tx_tcp_hdr->ack = tcp_table[current_TCB].remote_seq;
+ tx_tcp_hdr->cntrl_bits = control_bits;
+
+ for (i = 0; i < 8; i++)
+ chksum += *chksum_hdr;
+
+ chksum_hdr = (unsigned int *)tx_tcp_hdr;
+
+ // if the packet length is odd, pad it
+ if (tcp_len % 2)
+ *((unsigned char *)chksum_hdr + tcp_len) = 0;
+
+ tcp_len = (tcp_len + 1) >> 1;
+ for (i = 0; i < tcp_len; i++, chksum_hdr++)
+ if (i != 8)
+ chksum += *chksum_hdr;
+ chksum = ~chksum;
+
+ tx_ip_packet(tx_buf, nLength + sizeof(struct tcp_hdr));
+}
+
Index: trunk/apps/reference/MicroWeb/arp.h
===================================================================
--- trunk/apps/reference/MicroWeb/arp.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/arp.h (revision 46)
@@ -0,0 +1,27 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// arp.h: defines for ARP processing
+
+#ifndef H__ARP
+#define H__ARP
+
+void rx_arp_packet(unsigned char *rx_buffer);
+void tx_arp_packet(unsigned int arp_oper);
+
+#endif
Index: trunk/apps/reference/MicroWeb/icmp.c
===================================================================
--- trunk/apps/reference/MicroWeb/icmp.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/icmp.c (revision 46)
@@ -0,0 +1,76 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// icmp.c: ICMP protocol processing
+
+#include
+#include "packets.h"
+#include "ip.h"
+#include "icmp.h"
+
+void tx_icmp_packet(unsigned char tx_type, unsigned char *szData, unsigned char nLength)
+{
+ unsigned char tx_buf[BUF_LEN];
+ struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
+ struct icmp_hdr *tx_icmp_hdr = (struct icmp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
+ unsigned char *icmp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct icmp_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)tx_icmp_hdr;
+ int i;
+ unsigned int chksum = 0;
+
+ tx_icmp_hdr->type = tx_type;
+ tx_icmp_hdr->sequence = 0x01;
+ for (i = 0; i < nLength; i++)
+ {
+ *icmp_data = *szData;
+ icmp_data++;
+ szData++;
+ }
+
+ // Compute the checksum
+ for (i = 0; i < 5; i++)
+ if (i != 1)
+ {
+ chksum += *chksum_hdr;
+ chksum_hdr++;
+ }
+ chksum = ~chksum;
+ tx_icmp_hdr->checksum = 0x0b12;
+
+ tx_ip_packet(tx_buf, nLength + sizeof(struct icmp_hdr));
+}
+
+void rx_icmp_packet(unsigned char *rx_buffer)
+{
+ struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
+ struct icmp_hdr *rx_icmp_hdr = (struct icmp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
+ unsigned char *pszData = (unsigned char *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct icmp_hdr));
+ unsigned int nDataLen = rx_ip_hdr->totlen - sizeof(struct icmp_hdr) - sizeof(struct ip_hdr);
+
+ // if it's an echo request, send a reply
+ if (rx_icmp_hdr->type == ICMP_ECHO)
+ {
+ // switch source and destination IP's
+ memcpy(targetMAC, srcMAC, sizeof(unsigned char) * 6);
+ memcpy(targetIP, srcIP, sizeof(unsigned char) * 4);
+
+ tx_icmp_packet(ICMP_ECHOREPLY, pszData, nDataLen);
+ }
+ // else discard packet
+}
+
Index: trunk/apps/reference/MicroWeb/udp.c
===================================================================
--- trunk/apps/reference/MicroWeb/udp.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/udp.c (revision 46)
@@ -0,0 +1,105 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// tcp.c: TCP protocol processing
+
+#include
+#include "packets.h"
+#include "ip.h"
+#include "udp.h"
+
+void tx_udp_packet(unsigned char *szData, unsigned char nLength)
+{
+ unsigned char tx_buf[BUF_LEN];
+ struct ip_hdr *tx_ip_hdr = (struct ip_hdr *)(tx_buf + sizeof(struct eth_hdr));
+ struct udp_hdr *tx_udp_hdr = (struct udp_hdr *)(tx_buf + sizeof(struct ip_hdr) + sizeof(struct eth_hdr));
+ unsigned char *udp_data = (unsigned char *)(tx_buf + sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct udp_hdr));
+ unsigned int *chksum_hdr = (unsigned int *)tx_udp_hdr;
+ int i;
+ unsigned int chksum = 0;
+
+ for (i = 0; i < nLength; i++)
+ {
+ *udp_data = szData[i];
+ udp_data++;
+ }
+
+ tx_udp_hdr->src_port = MY_UDP_PORT;
+ tx_udp_hdr->dst_port = MY_UDP_PORT;
+ tx_udp_hdr->length = sizeof(struct udp_hdr) + nLength;
+
+ // Compute the checksum
+ for (i = 0; i < 3; i++)
+ {
+ chksum += *chksum_hdr;
+ chksum_hdr++;
+ }
+ chksum_hdr = (unsigned int *)&(tx_ip_hdr->proto);
+ chksum += *chksum_hdr;
+ chksum_hdr = (unsigned int *)&targetIP;
+ for (i = 0; i < 4; i++)
+ {
+ chksum += *chksum_hdr;
+ chksum_hdr++;
+ }
+ chksum = ~chksum;
+ tx_udp_hdr->checksum = chksum;
+
+ tx_ip_packet(tx_buf, nLength + sizeof(struct udp_hdr));
+}
+
+void rx_udp_packet(unsigned char *rx_buffer)
+{
+ struct ip_hdr *rx_ip_hdr = (struct ip_hdr *)(rx_buffer + sizeof(struct eth_hdr));
+ struct udp_hdr *rx_udp_hdr = (struct udp_hdr *)(rx_buffer + sizeof(struct eth_hdr) + sizeof(struct ip_hdr));
+ unsigned int *tmp_chk = (unsigned int *)&rx_ip_hdr->srcIP;
+ unsigned int checksum = 0;
+ unsigned int i;
+#define msglen 15
+ unsigned char msg[msglen] = "This is a test.";
+
+ // check the length
+ if (rx_udp_hdr->length == rx_ip_hdr->totlen - (sizeof(struct ip_hdr) / 8))
+ {
+ // check the checksum
+ checksum = rx_udp_hdr->length + rx_ip_hdr->proto;
+ checksum += (*tmp_chk)++;
+ checksum += (*tmp_chk)++;
+ checksum += (*tmp_chk)++;
+ checksum += (*tmp_chk);
+
+ tmp_chk = (unsigned int *)rx_udp_hdr;
+
+ for (i = 0; i < rx_udp_hdr->length; i++)
+ if (i != 3) //skip existing checksum
+ checksum += *tmp_chk;
+ checksum = ~checksum;
+
+ // packet is valid if they match
+ if (checksum == rx_udp_hdr->checksum)
+ // check the port numbers
+ if ((rx_udp_hdr->src_port == MY_UDP_PORT) && (rx_udp_hdr->dst_port == MY_UDP_PORT))
+ {
+ // packet is ok, respond
+ tx_udp_packet(msg, strlen(msg));
+ }
+ // else discard packet
+ }
+ // else discard packet
+}
+
Index: trunk/apps/reference/MicroWeb/tcp.h
===================================================================
--- trunk/apps/reference/MicroWeb/tcp.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/tcp.h (revision 46)
@@ -0,0 +1,70 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// tcp.h: structures for tcp connections
+
+#ifndef H__TCP
+#define H__TCP
+
+#define TCP_MAX_CONN 1
+
+enum tcp_state
+{
+ LISTEN = 1,
+ SYN_SENT,
+ SYN_RECVD,
+ ESTABLISHED,
+ FIN_WAIT_1,
+ FIN_WAIT_2,
+ CLOSE_WAIT,
+ CLOSING,
+ LAST_ACK,
+ TIME_WAIT,
+ CLOSED
+};
+
+enum tcp_cntrl_flags
+{
+ TCP_CNTRL_FIN = 0x01,
+ TCP_CNTRL_SYN = 0x02,
+ TCP_CNTRL_RST = 0x04,
+ TCP_CNTRL_PSH = 0x08,
+ TCP_CNTRL_ACK = 0x10,
+ TCP_CNTRL_URG = 0x20
+};
+
+struct tcp_TCB
+{
+ unsigned int local_port; // Local port number
+ unsigned int remote_port; // Remote port number
+ unsigned char remote_addr[4]; // Remote IP address
+ unsigned char state; // Our current state
+ unsigned char local_seq; // Local sequence number
+ unsigned char remote_seq; // Remote sequence number
+};
+
+#define TCP_PORT_HTTP 80
+
+#define TCP_START_SEQ 50
+
+void tcp_init(void);
+void rx_tcp_packet(unsigned char *rx_buffer);
+void tx_tcp_packet(unsigned char current_TCB, unsigned char control_bits, unsigned char *szData, unsigned int nLength);
+
+#endif
+
Index: trunk/apps/reference/MicroWeb/Makefile
===================================================================
--- trunk/apps/reference/MicroWeb/Makefile (nonexistent)
+++ trunk/apps/reference/MicroWeb/Makefile (revision 46)
@@ -0,0 +1,28 @@
+#
+#
+#
+
+SHELL = /bin/sh
+SDCCFLAGS = --model-large -I /home/dinesha/download/sdcc/device/include/mcs51 -I /home/dinesha/download/sdcc/device/include/ -L /home/dinesha/download/sdcc/device/lib/build/large
+ASLINKFLAGS = --code-loc 0x8000 --data-loc 0x30 --stack-loc 0x20 --xram-loc 0xD000
+MODULES = main.rel csio.rel csioa.rel tcp.rel udp.rel icmp.rel arp.rel ip.rel
+
+%.rel: %.c
+ sdcc $(SDCCFLAGS) -c $<
+
+#main.rel: main.c
+# sdcc $(SDCCFLAGS) -c $<
+
+%.rel: %.asm
+ sdas8051 -los $<
+
+all: microweb.hex
+
+microweb.hex :: $(MODULES)
+ sdcc $(SDCCFLAGS) $(ASLINKFLAGS) $(MODULES)
+ packihx main.ihx > microweb.hex
+
+clean:
+ rm -f tcp.asm udp.asm icmp.asm arp.asm ip.asm csio.asm main.asm main.mem
+ rm -f *.hex *.ihx *.lnk *.lst *.map *.rel *.rst *.sym
+
Index: trunk/apps/reference/MicroWeb/csioa.asm
===================================================================
--- trunk/apps/reference/MicroWeb/csioa.asm (nonexistent)
+++ trunk/apps/reference/MicroWeb/csioa.asm (revision 46)
@@ -0,0 +1,127 @@
+; Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+;
+; This file is part of MicroWeb.
+;
+; MicroWeb is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; MicroWeb is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+; GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with MicroWeb; if not, write to the Free Software
+; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+; csio.a51: driver code for CS8900A chip located at 7000h
+
+ .module csioa
+
+ .globl _write_byte
+ .globl _read_byte
+ .globl _write_word
+ .globl _read_wordL
+ .globl _read_wordH
+ .globl _write_byte_PARM_2
+ .globl _write_word_PARM_2
+
+ .area XSEG (XDATA)
+_write_byte_PARM_2::
+ .ds 2
+_write_word_PARM_2::
+ .ds 2
+
+csio_port = 0x70
+
+ .area CSEG (CODE)
+
+; write_byte(io_port = R7, data = R5)
+_write_byte:
+ push ACC
+ mov A, dpl
+ add A, #csio_port
+ mov DPH, A
+ mov A, R5
+ movx @dptr, a
+ pop ACC
+ ret
+
+; read_byte(io_port = R7), value returned in R7
+_read_byte:
+ push ACC
+ mov A, R7
+ add A, #csio_port
+ mov DPH, A
+ movx a, @dptr
+ mov R7, A
+ pop ACC
+ ret
+
+; write_word(io_port(8 bits), data(16 bits))
+_write_word:
+ push ACC
+ mov A, DPL
+ add A, #csio_port
+ mov R1, A
+ mov dptr, #_write_word_PARM_2
+ movx a, @dptr
+ push acc
+ mov a, r1
+ mov dph, a
+ pop acc
+ movx @dptr, a
+ mov dptr, #_write_word_PARM_2
+ inc dptr
+ movx a, @dptr
+ push acc
+ mov A, R1
+ inc A
+ mov DPH, A
+ pop acc
+ movx @dptr, a
+ pop ACC
+ ret
+
+; read_wordL(io_port = DPL) return in DPTR
+; read the low order byte first(R7)
+_read_wordL:
+ push ACC
+ mov A, DPL
+ add A, #csio_port
+ mov R1, A
+ mov DPH, A
+ movx A, @dptr
+ push acc
+ mov A, R1
+ inc A
+ mov DPH, A
+ movx a, @dptr
+ mov dph, A
+ pop dpl
+ pop ACC
+ ret
+
+; read_wordH(io_port = DPL) return in DPTR
+; read the high order byte first(R6)
+_read_wordH:
+ push ACC
+ mov A, dpl
+ add A, #csio_port
+ mov R1, A
+ inc A
+ mov DPH, A
+ movx a, @dptr
+ push acc
+ mov A, R1
+ mov DPH, A
+ movx a, @dptr
+ mov dpl, A
+ pop dph
+ pop ACC
+ ret
+
+;.end
+
Index: trunk/apps/reference/MicroWeb/udp.h
===================================================================
--- trunk/apps/reference/MicroWeb/udp.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/udp.h (revision 46)
@@ -0,0 +1,28 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// udp.h: defines for UDP
+
+#ifndef H__UDP
+#define H__UDP
+
+void tx_udp_packet(unsigned char *szData, unsigned char nLength);
+void rx_udp_packet(unsigned char *rx_buffer);
+
+#endif
+
Index: trunk/apps/reference/MicroWeb/csio.c
===================================================================
--- trunk/apps/reference/MicroWeb/csio.c (nonexistent)
+++ trunk/apps/reference/MicroWeb/csio.c (revision 46)
@@ -0,0 +1,143 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// csio.c: driver code for CS8900A chip
+
+#include "csio.h"
+#include "csioa.h"
+
+void cs_init(unsigned char my_MAC_addr[])
+{
+ unsigned int nReturn = 0;
+
+ // reset the chip
+ write_word(IO_PPPointer, PP_SelfCTL);
+ write_word(IO_PPData, RESET);
+
+ // wait until chip is ready
+ while (!(nReturn & INITD))
+ {
+ write_word(IO_PPPointer, PP_SelfST);
+ nReturn = read_wordL(IO_PPData);
+ }
+
+ // setup RxCTL(0104h)
+ write_word(IO_PPPointer, PP_RxCTL);
+ write_word(IO_PPData, RX_OK_ACCEPT | RX_IA_ACCEPT | RX_BROADCAST_ACCEPT);
+ nReturn = read_wordL(IO_PPData);
+
+ // write the MAC address starting at 0158h
+ write_word(IO_PPPointer, PP_IA);
+ write_word(IO_PPData, (my_MAC_addr[1] << 8) | my_MAC_addr[0]);
+ write_word(IO_PPPointer, PP_IA + 2);
+ write_word(IO_PPData, (my_MAC_addr[3] << 8) | my_MAC_addr[2]);
+ write_word(IO_PPPointer, PP_IA + 4);
+ write_word(IO_PPData, (my_MAC_addr[5] << 8) | my_MAC_addr[4]);
+
+ // enable receive and transmit
+ write_word(IO_PPPointer, PP_LineCTL);
+ write_word(IO_PPData, SERIAL_RX_ON | SERIAL_TX_ON);
+}
+
+unsigned char cs_test(void)
+{
+ unsigned int nReturn;
+
+ // Read from PPData port, should get 0E63h
+ nReturn = read_wordL(IO_PPData);
+
+ if (nReturn != 0x630E)
+ return 0;
+
+ // Read from register RxCFG(0102h), should get 3h
+ write_word(IO_PPPointer, PP_RxCFG);
+ nReturn = read_wordL(IO_PPData);
+
+ if (nReturn != 0x0003)
+ return 0;
+
+ // Display OK Here at Hyper Teminal or at LCD Monitor
+
+ return 1;
+}
+
+unsigned char rx_event_poll(void)
+{
+ unsigned int nReturn = 0x0000;
+
+ write_word(IO_PPPointer, PP_RxEvent);
+ nReturn = read_wordL(IO_PPData);
+
+ if ((nReturn & RX_OK) && !(nReturn & RX_HASH))
+ return 1;
+
+ return 0;
+}
+
+unsigned int rx_packet(unsigned char *rx_buffer)
+{
+ unsigned int data nReturn = 0x0000;
+ unsigned int data nLength = 0x0000;
+ unsigned int data nData = 0x0000;
+ unsigned char i;
+
+ write_word(IO_PPPointer, PP_RxStatus);
+ nReturn = read_wordL(IO_PPData);
+
+ write_word(IO_PPPointer, PP_RxLength);
+ nLength = read_wordL(IO_PPData);
+
+ for (i = 0; i < nLength; i += 2)
+ {
+ write_word(IO_PPPointer, PP_RxFrame + i);
+ nData = read_wordL(IO_PPData);
+ rx_buffer[i] = (unsigned char)(nData & 0xFF);
+ rx_buffer[i + 1] = (unsigned char)((nData >> 8) & 0xFF);
+ }
+
+ return nLength;
+}
+
+void tx_packet(unsigned char *tx_buffer, unsigned int tx_buffer_len)
+{
+ unsigned int nReturn = 0;
+ unsigned int i = 0;
+ unsigned char *tx_send = (unsigned char *)tx_buffer;
+
+ // write transmit command to TxCMD port
+ write_word(IO_TxCMD, 0x00C0);
+ // write transmit size to TxLength port
+ write_word(IO_TxLength, tx_buffer_len);
+
+ // wait until space is available
+ while (!(nReturn & READY_FOR_TX_NOW))
+ {
+ write_word(IO_PPPointer, PP_BusST);
+ nReturn = read_wordL(IO_PPData);
+ }
+
+ // round odd packets up and convert to words
+ tx_buffer_len = (tx_buffer_len + 1) >> 1;
+ for (i = 0; i < tx_buffer_len; i++)
+ {
+ write_word(IO_RxTxData, *(tx_send++));
+ tx_send += 2;
+ }
+}
+
+
Index: trunk/apps/reference/MicroWeb/icmp.h
===================================================================
--- trunk/apps/reference/MicroWeb/icmp.h (nonexistent)
+++ trunk/apps/reference/MicroWeb/icmp.h (revision 46)
@@ -0,0 +1,27 @@
+// Copyright (C) 2002 Mason Kidd (mrkidd@nettaxi.com)
+//
+// This file is part of MicroWeb.
+//
+// MicroWeb is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// MicroWeb is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with MicroWeb; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// icmp.h: defines for ICMP
+
+#ifndef H__ICMP
+#define H__ICMP
+
+void tx_icmp_packet(unsigned char tx_type, unsigned char *szData, unsigned char nLength);
+void rx_icmp_packet(unsigned char *rx_buffer);
+
+#endif
Index: trunk/apps/reference/avr-webserver/enc28j60.c
===================================================================
--- trunk/apps/reference/avr-webserver/enc28j60.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/enc28j60.c (revision 46)
@@ -0,0 +1,602 @@
+//********************************************************************************************
+//
+// File : enc28j60.c Microchip ENC28J60 Ethernet Interface Driver
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+//
+//#define F_CPU 8000000UL // 8 MHz
+
+//struct enc28j60_flag
+//{
+// unsigned rx_buffer_is_free:1;
+// unsigned unuse:7;
+//}enc28j60_flag;
+static BYTE Enc28j60Bank;
+static WORD_BYTES next_packet_ptr;
+
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+BYTE enc28j60ReadOp(BYTE op, BYTE address)
+{
+ // activate CS
+ CSACTIVE;
+ // issue read command
+ SPDR = op | (address & ADDR_MASK);
+ waitspi();
+ // read data
+ SPDR = 0x00;
+ waitspi();
+ // do dummy read if needed (for mac and mii, see datasheet page 29)
+ if(address & 0x80)
+ {
+ SPDR = 0x00;
+ waitspi();
+ }
+ // release CS
+ CSPASSIVE;
+ return(SPDR);
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+void enc28j60WriteOp(BYTE op, BYTE address, BYTE data)
+{
+ CSACTIVE;
+ // issue write command
+ SPDR = op | (address & ADDR_MASK);
+ waitspi();
+ // write data
+ SPDR = data;
+ waitspi();
+ CSPASSIVE;
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+void enc28j60SetBank(BYTE address)
+{
+ // set the bank (if needed)
+ if((address & BANK_MASK) != Enc28j60Bank)
+ {
+ // set the bank
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, (ECON1_BSEL1|ECON1_BSEL0));
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, (address & BANK_MASK)>>5);
+ Enc28j60Bank = (address & BANK_MASK);
+ }
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+BYTE enc28j60Read(BYTE address)
+{
+ // select bank to read
+ enc28j60SetBank(address);
+
+ // do the read
+ return enc28j60ReadOp(ENC28J60_READ_CTRL_REG, address);
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+void enc28j60Write(BYTE address, BYTE data)
+{
+ // select bank to write
+ enc28j60SetBank(address);
+
+ // do the write
+ enc28j60WriteOp(ENC28J60_WRITE_CTRL_REG, address, data);
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+WORD enc28j60_read_phyreg(BYTE address)
+{
+ WORD data;
+
+ // set the PHY register address
+ enc28j60Write(MIREGADR, address);
+ enc28j60Write(MICMD, MICMD_MIIRD);
+
+ // Loop to wait until the PHY register has been read through the MII
+ // This requires 10.24us
+ while( (enc28j60Read(MISTAT) & MISTAT_BUSY) );
+
+ // Stop reading
+ enc28j60Write(MICMD, MICMD_MIIRD);
+
+ // Obtain results and return
+ data = enc28j60Read ( MIRDL );
+ data |= enc28j60Read ( MIRDH );
+
+ return data;
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+void enc28j60PhyWrite(BYTE address, WORD_BYTES data)
+{
+ // set the PHY register address
+ enc28j60Write(MIREGADR, address);
+ // write the PHY data
+ enc28j60Write(MIWRL, data.byte.low);
+ enc28j60Write(MIWRH, data.byte.high);
+ // wait until the PHY write completes
+ while(enc28j60Read(MISTAT) & MISTAT_BUSY)
+ {
+ _delay_us(15);
+ }
+}
+//*******************************************************************************************
+//
+// Function : icmp_send_request
+// Description : Send ARP request packet to destination.
+//
+//*******************************************************************************************
+/*
+void enc28j60_init( BYTE *avr_mac)
+{
+ // initialize I/O
+ //DDRB |= _BV( DDB4 );
+ //CSPASSIVE;
+
+
+
+ // enable PB0, reset as output /
+ ENC28J60_DDR |= _BV(ENC28J60_RESET_PIN_DDR);
+
+ // enable PD2/INT0, as input /
+ ENC28J60_DDR &= ~_BV(ENC28J60_INT_PIN_DDR);
+
+ // set output to gnd, reset the ethernet chip /
+ ENC28J60_PORT &= ~_BV(ENC28J60_RESET_PIN);
+ _delay_ms(10);
+ // set output to Vcc, reset inactive /
+ ENC28J60_PORT |= _BV(ENC28J60_RESET_PIN);
+ _delay_ms(200);
+
+ //initialize enc28j60/
+ //enc28j60Init( avr_mac );
+ //_delay_ms( 20 );
+
+
+ DDRB |= _BV( DDB4 ) | _BV( DDB5 ) | _BV( DDB7 ); // mosi, sck, ss output
+ //DDRB &= ~_BV( DDB6 ); // MISO is input
+
+ CSPASSIVE;
+
+ PORTB &= ~(_BV( PB5 ) | _BV( PB7 ) );
+
+ // initialize SPI interface
+ // master mode and Fosc/2 clock:
+ SPCR = _BV( SPE ) | _BV( MSTR );
+ SPSR |= _BV( SPI2X );
+
+ // perform system reset
+ enc28j60WriteOp(ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
+ _delay_ms(50);
+
+ // check CLKRDY bit to see if reset is complete
+ // The CLKRDY does not work. See Rev. B4 Silicon Errata point. Just wait.
+ //while(!(enc28j60Read(ESTAT) & ESTAT_CLKRDY));
+ // do bank 0 stuff
+ // initialize receive buffer
+ // 16-bit transfers, must write low byte first
+ // set receive buffer start address
+ next_packet_ptr.word = RXSTART_INIT;
+ // Rx start
+ enc28j60Write(ERXSTL, RXSTART_INIT&0xFF);
+ enc28j60Write(ERXSTH, RXSTART_INIT>>8);
+ // set receive pointer address
+ enc28j60Write(ERXRDPTL, RXSTART_INIT&0xFF);
+ enc28j60Write(ERXRDPTH, RXSTART_INIT>>8);
+ // RX end
+ enc28j60Write(ERXNDL, RXSTOP_INIT&0xFF);
+ enc28j60Write(ERXNDH, RXSTOP_INIT>>8);
+ // TX start
+ enc28j60Write(ETXSTL, TXSTART_INIT&0xFF);
+ enc28j60Write(ETXSTH, TXSTART_INIT>>8);
+ // TX end
+ enc28j60Write(ETXNDL, TXSTOP_INIT&0xFF);
+ enc28j60Write(ETXNDH, TXSTOP_INIT>>8);
+ // do bank 1 stuff, packet filter:
+ // For broadcast packets we allow only ARP packtets
+ // All other packets should be unicast only for our mac (MAADR)
+ //
+ // The pattern to match on is therefore
+ // Type ETH.DST
+ // ARP BROADCAST
+ // 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9
+ // in binary these poitions are:11 0000 0011 1111
+ // This is hex 303F->EPMM0=0x3f,EPMM1=0x30
+ enc28j60Write(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
+ enc28j60Write(EPMM0, 0x3f);
+ enc28j60Write(EPMM1, 0x30);
+ enc28j60Write(EPMCSL, 0xf9);
+ enc28j60Write(EPMCSH, 0xf7);
+
+
+
+ // do bank 2 stuff
+ // enable MAC receive
+ enc28j60Write(MACON1, MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS);
+ // bring MAC out of reset
+ //enc28j60Write(MACON2, 0x00);
+ // enable automatic padding to 60bytes and CRC operations
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, MACON3, MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN);
+ // set inter-frame gap (non-back-to-back)
+ enc28j60Write(MAIPGL, 0x12);
+ enc28j60Write(MAIPGH, 0x0C);
+ // set inter-frame gap (back-to-back)
+ enc28j60Write(MABBIPG, 0x12);
+ // Set the maximum packet size which the controller will accept
+ // Do not send packets longer than MAX_FRAMELEN:
+ enc28j60Write(MAMXFLL, MAX_FRAMELEN&0xFF);
+ enc28j60Write(MAMXFLH, MAX_FRAMELEN>>8);
+ // do bank 3 stuff
+ // write MAC address
+ // NOTE: MAC address in ENC28J60 is byte-backward
+
+ // ENC28J60 is big-endian avr gcc is little-endian
+ enc28j60Write(MAADR5, avr_mac[0]);
+ enc28j60Write(MAADR4, avr_mac[1]);
+ enc28j60Write(MAADR3, avr_mac[2]);
+ enc28j60Write(MAADR2, avr_mac[3]);
+ enc28j60Write(MAADR1, avr_mac[4]);
+ enc28j60Write(MAADR0, avr_mac[5]);
+ // no loopback of transmitted frames
+ enc28j60PhyWrite(PHCON2, (WORD_BYTES){PHCON2_HDLDIS});
+ // switch to bank 0
+ enc28j60SetBank(ECON1);
+ // enable interrutps
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, EIE, EIE_INTIE|EIE_PKTIE);
+ // enable packet reception
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN);
+
+
+
+ // Magjack leds configuration, see enc28j60 datasheet, page 11 /
+ // LEDB=yellow LEDA=green
+ //
+ // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
+ // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
+ enc28j60PhyWrite(PHLCON,(WORD_BYTES){0x0472});
+
+ // set LED B to display recieve and transmit activate
+
+ //enc28j60PhyWrite( PHLCON, 0x0476 );
+
+
+
+ //enc28j60_flag.rx_buffer_is_free = 1;
+ _delay_ms(20);
+}
+*/
+void enc28j60_init( BYTE *avr_mac)
+{
+ // initialize I/O
+ //DDRB |= _BV( DDB4 );
+ //CSPASSIVE;
+
+ // enable PB0, reset as output
+ ENC28J60_DDR |= _BV(ENC28J60_RESET_PIN_DDR);
+
+ // enable PD2/INT0, as input
+ ENC28J60_DDR &= ~_BV(ENC28J60_INT_PIN_DDR);
+ ENC28J60_PORT |= _BV(ENC28J60_INT_PIN);
+
+ // set output to gnd, reset the ethernet chip
+ ENC28J60_PORT &= ~_BV(ENC28J60_RESET_PIN);
+ _delay_ms(10);
+
+ // set output to Vcc, reset inactive
+ ENC28J60_PORT |= _BV(ENC28J60_RESET_PIN);
+ _delay_ms(200);
+
+ //
+ DDRB |= _BV( DDB4 ) | _BV( DDB5 ) | _BV( DDB7 ); // mosi, sck, ss output
+ //DDRB &= ~_BV( DDB6 ); // MISO is input
+
+ CSPASSIVE;
+ PORTB &= ~(_BV( PB5 ) | _BV( PB7 ) );
+ //
+ // initialize SPI interface
+ // master mode and Fosc/2 clock:
+ SPCR = _BV( SPE ) | _BV( MSTR );
+ SPSR |= _BV( SPI2X );
+
+ // perform system reset
+ enc28j60WriteOp(ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
+ _delay_ms(50);
+
+ // check CLKRDY bit to see if reset is complete
+ // The CLKRDY does not work. See Rev. B4 Silicon Errata point. Just wait.
+ //while(!(enc28j60Read(ESTAT) & ESTAT_CLKRDY));
+ // do bank 0 stuff
+ // initialize receive buffer
+ // 16-bit transfers, must write low byte first
+ // set receive buffer start address
+ next_packet_ptr.word = RXSTART_INIT;
+ // Rx start
+ enc28j60Write(ERXSTL, RXSTART_INIT&0xFF);
+ enc28j60Write(ERXSTH, RXSTART_INIT>>8);
+ // set receive pointer address
+ enc28j60Write(ERXRDPTL, RXSTART_INIT&0xFF);
+ enc28j60Write(ERXRDPTH, RXSTART_INIT>>8);
+ // RX end
+ enc28j60Write(ERXNDL, RXSTOP_INIT&0xFF);
+ enc28j60Write(ERXNDH, RXSTOP_INIT>>8);
+ // TX start
+ enc28j60Write(ETXSTL, TXSTART_INIT&0xFF);
+ enc28j60Write(ETXSTH, TXSTART_INIT>>8);
+ // TX end
+ enc28j60Write(ETXNDL, TXSTOP_INIT&0xFF);
+ enc28j60Write(ETXNDH, TXSTOP_INIT>>8);
+
+ // do bank 2 stuff
+ // enable MAC receive
+ enc28j60Write(MACON1, MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS);
+
+ // bring MAC out of reset
+ //enc28j60Write(MACON2, 0x00);
+
+ // enable automatic padding to 60bytes and CRC operations
+ enc28j60Write(MACON3, MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN);
+
+ // Allow infinite deferals if the medium is continuously busy
+ // (do not time out a transmission if the half duplex medium is
+ // completely saturated with other people's data)
+ enc28j60Write(MACON4, MACON4_DEFER);
+
+ // Late collisions occur beyond 63+8 bytes (8 bytes for preamble/start of frame delimiter)
+ // 55 is all that is needed for IEEE 802.3, but ENC28J60 B5 errata for improper link pulse
+ // collisions will occur less often with a larger number.
+ enc28j60Write(MACLCON2, 63);
+
+ // Set non-back-to-back inter-packet gap to 9.6us. The back-to-back
+ // inter-packet gap (MABBIPG) is set by MACSetDuplex() which is called
+ // later.
+ enc28j60Write(MAIPGL, 0x12);
+ enc28j60Write(MAIPGH, 0x0C);
+
+ // Set the maximum packet size which the controller will accept
+ // Do not send packets longer than MAX_FRAMELEN:
+ enc28j60Write(MAMXFLL, MAX_FRAMELEN&0xFF);
+ enc28j60Write(MAMXFLH, MAX_FRAMELEN>>8);
+
+ // do bank 3 stuff
+ // write MAC address
+ // NOTE: MAC address in ENC28J60 is byte-backward
+ // ENC28J60 is big-endian avr gcc is little-endian
+ enc28j60Write(MAADR5, avr_mac[0]);
+ enc28j60Write(MAADR4, avr_mac[1]);
+ enc28j60Write(MAADR3, avr_mac[2]);
+ enc28j60Write(MAADR2, avr_mac[3]);
+ enc28j60Write(MAADR1, avr_mac[4]);
+ enc28j60Write(MAADR0, avr_mac[5]);
+
+ // no loopback of transmitted frames
+ enc28j60PhyWrite(PHCON2, (WORD_BYTES){PHCON2_HDLDIS});
+
+ // Magjack leds configuration, see enc28j60 datasheet, page 11
+ // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
+ // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 00 10);
+ enc28j60PhyWrite(PHLCON,(WORD_BYTES){0x0472});
+
+ // do bank 1 stuff, packet filter:
+ // For broadcast packets we allow only ARP packtets
+ // All other packets should be unicast only for our mac (MAADR)
+ //
+ // The pattern to match on is therefore
+ // Type ETH.DST
+ // ARP BROADCAST
+ // 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9
+ // in binary these poitions are:11 0000 0011 1111
+ // This is hex 303F->EPMM0=0x3f,EPMM1=0x30
+ enc28j60Write(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
+ enc28j60Write(EPMM0, 0x3f);
+ enc28j60Write(EPMM1, 0x30);
+ enc28j60Write(EPMCSL, 0xf9);
+ enc28j60Write(EPMCSH, 0xf7);
+
+ // set inter-frame gap (back-to-back)
+ enc28j60Write(MABBIPG, 0x12);
+
+ // switch to bank 0
+ enc28j60SetBank(ECON1);
+
+ // enable interrutps
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, EIE, EIE_INTIE|EIE_PKTIE);
+
+ // enable packet reception
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN);
+
+ _delay_ms(20);
+}
+//*******************************************************************************************
+//
+// Function : enc28j60getrev
+// Description : read the revision of the chip.
+//
+//*******************************************************************************************
+BYTE enc28j60getrev(void)
+{
+ return(enc28j60Read(EREVID));
+}
+//*******************************************************************************************
+//
+// Function : enc28j60_packet_send
+// Description : Send packet to network.
+//
+//*******************************************************************************************
+void enc28j60_packet_send ( BYTE *buffer, WORD length )
+{
+ //Set the write pointer to start of transmit buffer area
+ enc28j60Write(EWRPTL, LOW(TXSTART_INIT) );
+ enc28j60Write(EWRPTH, HIGH(TXSTART_INIT) );
+
+ // Set the TXND pointer to correspond to the packet size given
+ enc28j60Write(ETXNDL, LOW((TXSTART_INIT+length)) );
+ enc28j60Write(ETXNDH, HIGH((TXSTART_INIT+length)) );
+
+ // write per-packet control byte (0x00 means use macon3 settings)
+ enc28j60WriteOp(ENC28J60_WRITE_BUF_MEM, 0, 0x00);
+
+ CSACTIVE;
+ // issue write command
+ SPDR = ENC28J60_WRITE_BUF_MEM;
+ waitspi();
+ while(length)
+ {
+ length--;
+ // write data
+ SPDR = *buffer++;
+ waitspi();
+ }
+ CSPASSIVE;
+
+ // send the contents of the transmit buffer onto the network
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS);
+
+ // Reset the transmit logic problem. See Rev. B4 Silicon Errata point 12.
+ if( (enc28j60Read(EIR) & EIR_TXERIF) )
+ {
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
+ }
+}
+//*******************************************************************************************
+//
+// Function : enc28j60_mac_is_linked
+// Description : return MAC link status.
+//
+//*******************************************************************************************
+/*
+BYTE enc28j60_mac_is_linked(void)
+{
+ if ( (enc28j60_read_phyreg(PHSTAT1) & PHSTAT1_LLSTAT ) )
+ return 1;
+ else
+ return 0;
+}
+*/
+//*******************************************************************************************
+//
+// Function : enc28j60_packet_receive
+// Description : check received packet and return length of data
+//
+//*******************************************************************************************
+//WORD data_length;
+WORD enc28j60_packet_receive ( BYTE *rxtx_buffer, WORD max_length )
+{
+ WORD_BYTES rx_status, data_length;
+
+ // check if a packet has been received and buffered
+ // if( !(enc28j60Read(EIR) & EIR_PKTIF) ){
+ // The above does not work. See Rev. B4 Silicon Errata point 6.
+ if( enc28j60Read(EPKTCNT) == 0 )
+ {
+ return 0;
+ }
+
+ // Set the read pointer to the start of the received packet
+ enc28j60Write(ERDPTL, next_packet_ptr.bytes[0]);
+ enc28j60Write(ERDPTH, next_packet_ptr.bytes[1]);
+
+ // read the next packet pointer
+ next_packet_ptr.bytes[0] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+ next_packet_ptr.bytes[1] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+
+ // read the packet length (see datasheet page 43)
+ data_length.bytes[0] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+ data_length.bytes[1] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+ data_length.word -=4; //remove the CRC count
+
+ // read the receive status (see datasheet page 43)
+ rx_status.bytes[0] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+ rx_status.bytes[1] = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
+
+ if ( data_length.word > (max_length-1) )
+ {
+ data_length.word = max_length-1;
+ }
+
+ // check CRC and symbol errors (see datasheet page 44, table 7-3):
+ // The ERXFCON.CRCEN is set by default. Normally we should not
+ // need to check this.
+ if ( (rx_status.word & 0x80)==0 )
+ {
+ // invalid
+ data_length.word = 0;
+ }
+ else
+ {
+ // read data from rx buffer and save to rxtx_buffer
+ rx_status.word = data_length.word;
+ CSACTIVE;
+ // issue read command
+ SPDR = ENC28J60_READ_BUF_MEM;
+ waitspi();
+ while(rx_status.word)
+ {
+ rx_status.word--;
+ SPDR = 0x00;
+ waitspi();
+ *rxtx_buffer++ = SPDR;
+ }
+ CSPASSIVE;
+ }
+
+ // Move the RX read pointer to the start of the next received packet
+ // This frees the memory we just read out
+ enc28j60Write(ERXRDPTL, next_packet_ptr.bytes[0]);
+ enc28j60Write(ERXRDPTH, next_packet_ptr.bytes[1]);
+
+ // decrement the packet counter indicate we are done with this packet
+ enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PKTDEC);
+
+ return( data_length.word );
+}
+
Index: trunk/apps/reference/avr-webserver/avrnet.aps
===================================================================
--- trunk/apps/reference/avr-webserver/avrnet.aps (nonexistent)
+++ trunk/apps/reference/avr-webserver/avrnet.aps (revision 46)
@@ -0,0 +1 @@
+avrnet 14-Dec-2006 13:47:01 24-Jun-2007 13:47:20 241 0 14-Dec-2006 13:47:01 4 4, 12, 0, 491 AVR GCC default\avrnet.elf D:\Work\AVR\avrnet-v1.0\ JTAG ICE ATmega32 false R00 R01 R02 R03 R04 R05 R06 R07 R08 R09 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 R27 R28 R29 R30 R31 Auto 1 0 0 enc28j60.c main.c http.c arp.c tcp.c ip.c ethernet.c icmp.c menu.c lcd.c adc.c udp.c enc28j60.h http.h arp.h tcp.h ip.h ethernet.h icmp.h menu.h lcd.h adc.h includes.h struct.h udp.h default\avrnet.lss default\avrnet.map default NO atmega32 1 avrnet.elf default\ 1 -Wall -gdwarf-2 -DF_CPU=16000000UL -Os -fsigned-char default 1 C:\WinAVR-20070525\bin\avr-gcc.exe C:\WinAVR-20070525\utils\bin\make.exe 0 214 224 131 4000000 0 1 1 19200 50000 0 0 0 0 1 0 0 0 0 0 0 0 0 1 main 1 1 -654736 D:\Work\AVR\avrnet-v1.0\enc28j60.h D:\Work\AVR\avrnet-v1.0\http.h D:\Work\AVR\avrnet-v1.0\arp.h D:\Work\AVR\avrnet-v1.0\tcp.h D:\Work\AVR\avrnet-v1.0\ip.h D:\Work\AVR\avrnet-v1.0\ethernet.h D:\Work\AVR\avrnet-v1.0\icmp.h D:\Work\AVR\avrnet-v1.0\menu.h D:\Work\AVR\avrnet-v1.0\lcd.h D:\Work\AVR\avrnet-v1.0\adc.h D:\Work\AVR\avrnet-v1.0\includes.h D:\Work\AVR\avrnet-v1.0\struct.h D:\Work\AVR\avrnet-v1.0\udp.h D:\Work\AVR\avrnet-v1.0\enc28j60.c D:\Work\AVR\avrnet-v1.0\main.c D:\Work\AVR\avrnet-v1.0\http.c D:\Work\AVR\avrnet-v1.0\arp.c D:\Work\AVR\avrnet-v1.0\tcp.c D:\Work\AVR\avrnet-v1.0\ip.c D:\Work\AVR\avrnet-v1.0\ethernet.c D:\Work\AVR\avrnet-v1.0\icmp.c D:\Work\AVR\avrnet-v1.0\menu.c D:\Work\AVR\avrnet-v1.0\lcd.c D:\Work\AVR\avrnet-v1.0\adc.c D:\Work\AVR\avrnet-v1.0\udp.c 00000 enc28j60.c 259 00001 http.c 259 00002 tcp.c 259 00003 menu.c 259 00004 lcd.c 259 00005 main.c 259 00006 arp.c 257 00007 includes.h 257 00008 adc.c 259 00009 ethernet.c 257 00010 icmp.c 257 00011 ip.c 257 00012 ip.h 1 00013 enc28j60.h 1 00014 ethernet.h 1 00015 arp.h 1 00016 menu.h 257 00017 adc.h 1 00018 icmp.h 1 00019 http.h 1 00020 lcd.h 1 00021 struct.h 257 00022 tcp.h 1 00023 udp.c 257 00024 udp.h 1 198 91 1053 577 0 0 186 64 1041 550 0 0 123 22 978 508 0 0 159 46 1014 532 0 0 38 -73 725 256 0 0 195 70 1022 532 288 0 117 18 972 504 0 0 43 -90 870 396 0 0 120 20 975 506 0 0 60 -51 747 278 0 0 103 -10 958 476 52 2 88 -60 915 426 0 0 103 -50 958 436 0 0 52 -84 879 402 0 0 59 -59 746 268 0 0 84 -35 771 292 0 0 171 54 1026 540 0 0 55 -26 910 462 0 0 180 51 867 378 0 0 117 -13 804 314 0 0 162 48 1017 536 0 0 169 73 884 400 0 0 180 60 1035 546 0 0 170 72 1025 558 34 2 Maximized 183 62 1038 548 23 33
Index: trunk/apps/reference/avr-webserver/enc28j60.h
===================================================================
--- trunk/apps/reference/avr-webserver/enc28j60.h (nonexistent)
+++ trunk/apps/reference/avr-webserver/enc28j60.h (revision 46)
@@ -0,0 +1,297 @@
+//********************************************************************************************
+//
+// File : enc28j60.h Microchip ENC28J60 Ethernet Interface Driver
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+
+//#ifndef ENC28J60_H
+#define ENC28J60_H
+
+// ENC28J60 Control Registers
+// Control register definitions are a combination of address,
+// bank number, and Ethernet/MAC/PHY indicator bits.
+// - Register address (bits 0-4)
+// - Bank number (bits 5-6)
+// - MAC/PHY indicator (bit 7)
+#define ADDR_MASK 0x1F
+#define BANK_MASK 0x60
+#define SPRD_MASK 0x80
+// All-bank registers
+#define EIE 0x1B
+#define EIR 0x1C
+#define ESTAT 0x1D
+#define ECON2 0x1E
+#define ECON1 0x1F
+// Bank 0 registers
+#define ERDPTL (0x00|0x00)
+#define ERDPTH (0x01|0x00)
+#define EWRPTL (0x02|0x00)
+#define EWRPTH (0x03|0x00)
+#define ETXSTL (0x04|0x00)
+#define ETXSTH (0x05|0x00)
+#define ETXNDL (0x06|0x00)
+#define ETXNDH (0x07|0x00)
+#define ERXSTL (0x08|0x00)
+#define ERXSTH (0x09|0x00)
+#define ERXNDL (0x0A|0x00)
+#define ERXNDH (0x0B|0x00)
+#define ERXRDPTL (0x0C|0x00)
+#define ERXRDPTH (0x0D|0x00)
+#define ERXWRPTL (0x0E|0x00)
+#define ERXWRPTH (0x0F|0x00)
+#define EDMASTL (0x10|0x00)
+#define EDMASTH (0x11|0x00)
+#define EDMANDL (0x12|0x00)
+#define EDMANDH (0x13|0x00)
+#define EDMADSTL (0x14|0x00)
+#define EDMADSTH (0x15|0x00)
+#define EDMACSL (0x16|0x00)
+#define EDMACSH (0x17|0x00)
+// Bank 1 registers
+#define EHT0 (0x00|0x20)
+#define EHT1 (0x01|0x20)
+#define EHT2 (0x02|0x20)
+#define EHT3 (0x03|0x20)
+#define EHT4 (0x04|0x20)
+#define EHT5 (0x05|0x20)
+#define EHT6 (0x06|0x20)
+#define EHT7 (0x07|0x20)
+#define EPMM0 (0x08|0x20)
+#define EPMM1 (0x09|0x20)
+#define EPMM2 (0x0A|0x20)
+#define EPMM3 (0x0B|0x20)
+#define EPMM4 (0x0C|0x20)
+#define EPMM5 (0x0D|0x20)
+#define EPMM6 (0x0E|0x20)
+#define EPMM7 (0x0F|0x20)
+#define EPMCSL (0x10|0x20)
+#define EPMCSH (0x11|0x20)
+#define EPMOL (0x14|0x20)
+#define EPMOH (0x15|0x20)
+#define EWOLIE (0x16|0x20)
+#define EWOLIR (0x17|0x20)
+#define ERXFCON (0x18|0x20)
+#define EPKTCNT (0x19|0x20)
+// Bank 2 registers
+#define MACON1 (0x00|0x40|0x80)
+#define MACON2 (0x01|0x40|0x80)
+#define MACON3 (0x02|0x40|0x80)
+#define MACON4 (0x03|0x40|0x80)
+#define MABBIPG (0x04|0x40|0x80)
+#define MAIPGL (0x06|0x40|0x80)
+#define MAIPGH (0x07|0x40|0x80)
+#define MACLCON1 (0x08|0x40|0x80)
+#define MACLCON2 (0x09|0x40|0x80)
+#define MAMXFLL (0x0A|0x40|0x80)
+#define MAMXFLH (0x0B|0x40|0x80)
+#define MAPHSUP (0x0D|0x40|0x80)
+#define MICON (0x11|0x40|0x80)
+#define MICMD (0x12|0x40|0x80)
+#define MIREGADR (0x14|0x40|0x80)
+#define MIWRL (0x16|0x40|0x80)
+#define MIWRH (0x17|0x40|0x80)
+#define MIRDL (0x18|0x40|0x80)
+#define MIRDH (0x19|0x40|0x80)
+// Bank 3 registers
+#define MAADR1 (0x00|0x60|0x80)
+#define MAADR0 (0x01|0x60|0x80)
+#define MAADR3 (0x02|0x60|0x80)
+#define MAADR2 (0x03|0x60|0x80)
+#define MAADR5 (0x04|0x60|0x80)
+#define MAADR4 (0x05|0x60|0x80)
+#define EBSTSD (0x06|0x60)
+#define EBSTCON (0x07|0x60)
+#define EBSTCSL (0x08|0x60)
+#define EBSTCSH (0x09|0x60)
+#define MISTAT (0x0A|0x60|0x80)
+#define EREVID (0x12|0x60)
+#define ECOCON (0x15|0x60)
+#define EFLOCON (0x17|0x60)
+#define EPAUSL (0x18|0x60)
+#define EPAUSH (0x19|0x60)
+// PHY registers
+#define PHCON1 0x00
+#define PHSTAT1 0x01
+#define PHHID1 0x02
+#define PHHID2 0x03
+#define PHCON2 0x10
+#define PHSTAT2 0x11
+#define PHIE 0x12
+#define PHIR 0x13
+#define PHLCON 0x14
+
+// ENC28J60 ERXFCON Register Bit Definitions
+#define ERXFCON_UCEN 0x80
+#define ERXFCON_ANDOR 0x40
+#define ERXFCON_CRCEN 0x20
+#define ERXFCON_PMEN 0x10
+#define ERXFCON_MPEN 0x08
+#define ERXFCON_HTEN 0x04
+#define ERXFCON_MCEN 0x02
+#define ERXFCON_BCEN 0x01
+// ENC28J60 EIE Register Bit Definitions
+#define EIE_INTIE 0x80
+#define EIE_PKTIE 0x40
+#define EIE_DMAIE 0x20
+#define EIE_LINKIE 0x10
+#define EIE_TXIE 0x08
+#define EIE_WOLIE 0x04
+#define EIE_TXERIE 0x02
+#define EIE_RXERIE 0x01
+// ENC28J60 EIR Register Bit Definitions
+#define EIR_PKTIF 0x40
+#define EIR_DMAIF 0x20
+#define EIR_LINKIF 0x10
+#define EIR_TXIF 0x08
+#define EIR_WOLIF 0x04
+#define EIR_TXERIF 0x02
+#define EIR_RXERIF 0x01
+// ENC28J60 ESTAT Register Bit Definitions
+#define ESTAT_INT 0x80
+#define ESTAT_LATECOL 0x10
+#define ESTAT_RXBUSY 0x04
+#define ESTAT_TXABRT 0x02
+#define ESTAT_CLKRDY 0x01
+// ENC28J60 ECON2 Register Bit Definitions
+#define ECON2_AUTOINC 0x80
+#define ECON2_PKTDEC 0x40
+#define ECON2_PWRSV 0x20
+#define ECON2_VRPS 0x08
+// ENC28J60 ECON1 Register Bit Definitions
+#define ECON1_TXRST 0x80
+#define ECON1_RXRST 0x40
+#define ECON1_DMAST 0x20
+#define ECON1_CSUMEN 0x10
+#define ECON1_TXRTS 0x08
+#define ECON1_RXEN 0x04
+#define ECON1_BSEL1 0x02
+#define ECON1_BSEL0 0x01
+// ENC28J60 MACON1 Register Bit Definitions
+#define MACON1_LOOPBK 0x10
+#define MACON1_TXPAUS 0x08
+#define MACON1_RXPAUS 0x04
+#define MACON1_PASSALL 0x02
+#define MACON1_MARXEN 0x01
+// ENC28J60 MACON2 Register Bit Definitions
+#define MACON2_MARST 0x80
+#define MACON2_RNDRST 0x40
+#define MACON2_MARXRST 0x08
+#define MACON2_RFUNRST 0x04
+#define MACON2_MATXRST 0x02
+#define MACON2_TFUNRST 0x01
+// ENC28J60 MACON3 Register Bit Definitions
+#define MACON3_PADCFG2 0x80
+#define MACON3_PADCFG1 0x40
+#define MACON3_PADCFG0 0x20
+#define MACON3_TXCRCEN 0x10
+#define MACON3_PHDRLEN 0x08
+#define MACON3_HFRMLEN 0x04
+#define MACON3_FRMLNEN 0x02
+#define MACON3_FULDPX 0x01
+// ENC28J60 MACON4 Register Bit Definitions
+#define MACON4_DEFER (1<<6)
+#define MACON4_BPEN (1<<5)
+#define MACON4_NOBKOFF (1<<4)
+// ENC28J60 MICMD Register Bit Definitions
+#define MICMD_MIISCAN 0x02
+#define MICMD_MIIRD 0x01
+// ENC28J60 MISTAT Register Bit Definitions
+#define MISTAT_NVALID 0x04
+#define MISTAT_SCAN 0x02
+#define MISTAT_BUSY 0x01
+// ENC28J60 PHY PHCON1 Register Bit Definitions
+#define PHCON1_PRST 0x8000
+#define PHCON1_PLOOPBK 0x4000
+#define PHCON1_PPWRSV 0x0800
+#define PHCON1_PDPXMD 0x0100
+// ENC28J60 PHY PHSTAT1 Register Bit Definitions
+#define PHSTAT1_PFDPX 0x1000
+#define PHSTAT1_PHDPX 0x0800
+#define PHSTAT1_LLSTAT 0x0004
+#define PHSTAT1_JBSTAT 0x0002
+// ENC28J60 PHY PHCON2 Register Bit Definitions
+#define PHCON2_FRCLINK 0x4000
+#define PHCON2_TXDIS 0x2000
+#define PHCON2_JABBER 0x0400
+#define PHCON2_HDLDIS 0x0100
+
+// ENC28J60 Packet Control Byte Bit Definitions
+#define PKTCTRL_PHUGEEN 0x08
+#define PKTCTRL_PPADEN 0x04
+#define PKTCTRL_PCRCEN 0x02
+#define PKTCTRL_POVERRIDE 0x01
+
+// SPI operation codes
+#define ENC28J60_READ_CTRL_REG 0x00
+#define ENC28J60_READ_BUF_MEM 0x3A
+#define ENC28J60_WRITE_CTRL_REG 0x40
+#define ENC28J60_WRITE_BUF_MEM 0x7A
+#define ENC28J60_BIT_FIELD_SET 0x80
+#define ENC28J60_BIT_FIELD_CLR 0xA0
+#define ENC28J60_SOFT_RESET 0xFF
+
+// set CS to 0 = active
+#define CSACTIVE PORTB &= ~_BV(PB4)
+// set CS to 1 = passive
+#define CSPASSIVE PORTB |= _BV(PB4)
+//
+#define waitspi() while(!(SPSR&(1<";
+prog_int8_t tag_hr[] = "
"; +prog_int8_t tag_form[] = "" ), dlen ); + + // AVR IP address + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P) tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " " ), dlen ); + + // Server IP address + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P)tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " " ), dlen ); + + // Write LCD form + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P) tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " LCD Line 1
" ), dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " LCD Line 2
" ), dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( "" ), dlen ); + + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P)tag_hr, dlen ); + + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( "Refresh" ), dlen ); + + return(dlen); +} Index: trunk/apps/reference/avr-webserver/arp.c =================================================================== --- trunk/apps/reference/avr-webserver/arp.c (nonexistent) +++ trunk/apps/reference/avr-webserver/arp.c (revision 46) @@ -0,0 +1,215 @@ +//******************************************************************************************** +// +// File : arp.c implement for Address Resolution Protocol +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include "includes.h" +//******************************************************************************************** +// +// Address Resolution Protocol (ARP) is the method for finding a host's hardware address +// when only its network layer address is known. +// Due to the overwhelming prevalence of IPv4 and Ethernet, +// ARP is primarily used to translate IP addresses to Ethernet MAC addresses. +// It is also used for IP over other LAN technologies, +// such as Token Ring, FDDI, or IEEE 802.11, and for IP over ATM. +// +// ARP is used in four cases of two hosts communicating: +// +// 1. When two hosts are on the same network and one desires to send a packet to the other +// 2. When two hosts are on different networks and must use a gateway/router to reach the other host +// 3. When a router needs to forward a packet for one host through another router +// 4. When a router needs to forward a packet from one host to the destination host on the same network +// +// +------------+------------+-----------+ +// + MAC header + ARP header + Data ::: + +// +------------+------------+-----------+ +// +// ARP header +// +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+ +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Hardware type + Protocol type + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + HardwareAddressLength + ProtocolAddressLength + Opcode + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Source hardware address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Source protocol address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Destination hardware address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Destination protocol address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Data ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// +//******************************************************************************************** + +//******************************************************************************************** +// +// Function : arp_generate_packet +// Description : generate arp packet +// +//******************************************************************************************** +void arp_generate_packet ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip ) +{ + unsigned char i; + + // setup hardware type to ethernet 0x0001 + rxtx_buffer[ ARP_HARDWARE_TYPE_H_P ] = ARP_HARDWARE_TYPE_H_V; + rxtx_buffer[ ARP_HARDWARE_TYPE_L_P ] = ARP_HARDWARE_TYPE_L_V; + + // setup protocol type to ip 0x0800 + rxtx_buffer[ ARP_PROTOCOL_H_P ] = ARP_PROTOCOL_H_V; + rxtx_buffer[ ARP_PROTOCOL_L_P ] = ARP_PROTOCOL_L_V; + + // setup hardware length to 0x06 + rxtx_buffer[ ARP_HARDWARE_SIZE_P ] = ARP_HARDWARE_SIZE_V; + + // setup protocol length to 0x04 + rxtx_buffer[ ARP_PROTOCOL_SIZE_P ] = ARP_PROTOCOL_SIZE_V; + + // setup arp destination and source mac address + for ( i=0; i>8)
+#define UDP_AVR_PORT_L_V (UDP_AVR_PORT_V&0xff)
+
+#define UDP_SRC_PORT_H_P 0x22
+#define UDP_SRC_PORT_L_P 0x23
+#define UDP_DST_PORT_H_P 0x24
+#define UDP_DST_PORT_L_P 0x25
+#define UDP_LENGTH_H_P 0x26
+#define UDP_LENGTH_L_P 0x27
+#define UDP_CHECKSUM_H_P 0x28
+#define UDP_CHECKSUM_L_P 0x29
+#define UDP_DATA_P 0x2A
+
+extern void udp_generate_header ( BYTE *rxtx_buffer, WORD_BYTES dest_port, WORD_BYTES length );
+extern WORD udp_puts_data ( BYTE *rxtx_buffer, BYTE *data, WORD offset );
+extern WORD udp_puts_data_p ( BYTE *rxtx_buffer, PGM_P data, WORD offset );
+extern BYTE udp_receive ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip );
Index: trunk/apps/reference/avr-webserver/lcd.c
===================================================================
--- trunk/apps/reference/avr-webserver/lcd.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/lcd.c (revision 46)
@@ -0,0 +1,155 @@
+//********************************************************************************************
+//
+// File : lcd.c implement for 16x2 LCD module
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+//********************************************************************************************
+//
+// Function : lcd_send_nibble
+// Description : Send data (nibble) to lcd module
+//
+//********************************************************************************************
+void lcd_send_nibble(unsigned char data)
+{
+ data &= 0xF0;
+ LCD_DATA_PORT &= 0x0F;
+ LCD_DATA_PORT |= data;
+ _delay_us(1); // 1us
+ LCD_CONTROL_PORT |= _BV(LCD_EN_PIN);
+ _delay_us(2);
+ LCD_CONTROL_PORT &= ~_BV(LCD_EN_PIN);
+}
+//********************************************************************************************
+//
+// Function : lcd_send_byte
+// Description : Send data (byte) to lcd module
+//
+//********************************************************************************************
+void lcd_send_byte( char data_or_cmd, char data )
+{
+ LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN);
+ if(data_or_cmd)
+ LCD_CONTROL_PORT |= _BV(LCD_RS_PIN);
+ else
+ LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN);
+ _delay_us(50); // 1us
+ LCD_CONTROL_PORT &= ~_BV(LCD_EN_PIN);
+ lcd_send_nibble(data & 0xF0);
+ lcd_send_nibble(data << 4);
+}
+//********************************************************************************************
+//
+// Function : lcd_init
+// Description : Lcd module initiation.(4-bits mode)
+//
+//********************************************************************************************
+void lcd_init(void)
+{
+ char i;
+ LCD_DATA_DDR |= (_BV(LCD_D7) | _BV(LCD_D6) | _BV(LCD_D5) | _BV(LCD_D4));
+ LCD_CONTROL_DDR |= (_BV(LCD_RS_PIN) | _BV(LCD_RW_PIN) | _BV(LCD_EN_PIN));
+
+ LCD_DATA_PORT &= ~(_BV(LCD_D7) | _BV(LCD_D6) | _BV(LCD_D5) | _BV(LCD_D4));
+ LCD_CONTROL_PORT &= ~(_BV(LCD_RS_PIN) | _BV(LCD_RS_PIN) | _BV(LCD_RS_PIN));
+
+ _delay_ms(15); // 15 ms
+ for(i=1;i<=3;++i)
+ {
+ lcd_send_nibble(0x30);
+ _delay_ms(5); // 5 ms
+ }
+ lcd_send_nibble(0x20);
+ lcd_send_byte(WRITE_COMMAND, SET_FUNCTION);
+ lcd_send_byte(WRITE_COMMAND, DISPLAY_ON);
+ lcd_send_byte(WRITE_COMMAND, DISPLAY_CLR);
+ lcd_send_byte(WRITE_COMMAND, ENTRY_MODE);
+}
+//********************************************************************************************
+//
+// Function : lcd_gotoxy
+// Description : Send SET_DDRAM command to lcd module
+//
+//********************************************************************************************
+void lcd_gotoxy( unsigned char x, unsigned char y)
+{
+ char address=0;
+
+ if(y!=1)
+ address = LCD_LINE_TWO;
+ address += x-1;
+ lcd_send_byte(WRITE_COMMAND, SET_DDRAM|address);
+}
+//********************************************************************************************
+//
+// Function : lcd_putc
+// Description : Send data(byte) or command to lcd module
+// '\f' is clear display command
+// '\n' is new line (second line) command
+// '\b' is cursor back command
+//
+//********************************************************************************************
+void lcd_putc( unsigned char c)
+{
+ if(c == '\f')
+ {
+ lcd_send_byte(WRITE_COMMAND, DISPLAY_CLR);
+ _delay_ms(2); // 2ms
+ }
+ else if(c == '\n')
+ lcd_gotoxy(1, 2);
+ else if(c == '\b')
+ lcd_send_byte(WRITE_COMMAND, CURSOR_BACK);
+ else
+ lcd_send_byte(WRITE_DATA, c);
+}
+//********************************************************************************************
+//
+// Function : lcd_print
+// Description : print string from ram to lcd module
+//
+//********************************************************************************************
+void lcd_print( BYTE *ptr )
+{
+
+ while( *ptr )
+ {
+ lcd_putc(*ptr++);
+ }
+}
+//********************************************************************************************
+//
+// Function : lcd_print_p
+// Description : print string from program memory to lcd module
+//
+//********************************************************************************************
+void lcd_print_p( PGM_P ptr )
+{
+ unsigned char c;
+
+ while( (c = pgm_read_byte ( ptr++ )) )
+ {
+ lcd_putc(c);
+ }
+}
Index: trunk/apps/reference/avr-webserver/ReadmeEN.html
===================================================================
--- trunk/apps/reference/avr-webserver/ReadmeEN.html (nonexistent)
+++ trunk/apps/reference/avr-webserver/ReadmeEN.html (revision 46)
@@ -0,0 +1,76 @@
+
+
+AVRnet V0.9 by avrportal.com
+
+
+AVRnet V1.0 by avrportal.com
+Hardware is base on V0.9
+What's new?
+- UDP (User Datagram Protocol) has been added to V1.0
+- New software AVRnet CPannel for UDP interfacing, written using CodeBlocks C++ IDE with wxWidgets GUI tool kits and MinGW GCC compiler.
+ +![](AVRnetCPannel.gif)
+
Download
+AVRnet V1.0 source code
+AVRnet CPannel source code
+AVRnet CPannel binary
+
+
+ +AVRnet V0.9 by avrportal.com
+
+AVRnet Firmware Version 0.9
+
+AVRnet is an Ethernet development board, v0.9 first is pubblic release.
+You can use AVRnet to build a small web-server and web-client for send data to webserver.
+Before you can use web-client application, Apache and PHP must be installed on your pc.
+More detail about Apache and PHP installation please visit http://www.avrportal.com
+
+
+
+Hardware feature
+
+- MCU : ATMEGA32 @ 16MHz
+- Ethernet controller : ENC28J60
+- RJ11 for LAN
+- LCD user interface menu
+- JTAG interface for program and debug
+- Temparature sensor using thermistor
+- 1 potentiometer for ADC0
+- I2C connector with pull-up resistor
+- Built-in Voltage regulator
+- LEDs display and switchs for LCD menu
+
+
+Firmware feature
+
+- Firmware is GPL using AVR GCC compiler
+- LCD user interface menu and borad status
+- Webserver listen on port 80 ( example page "webpage.htm" )
+- Webclient listen on port 1200 ( use for send temparature to webserver.)
+
+
+LCD user interface menu
+AVRnet use 4 tact switchs are menu, exit, up and dw for LCD menu.
+You can setup AVR IP, Server IP, Countdown timer by enter to each menu.
+
+Main menu
+
+standby display mode
+
+ + \ No newline at end of file Index: trunk/apps/reference/avr-webserver/default/Makefile =================================================================== --- trunk/apps/reference/avr-webserver/default/Makefile (nonexistent) +++ trunk/apps/reference/avr-webserver/default/Makefile (revision 46) @@ -0,0 +1,108 @@ +############################################################################### +# Makefile for the project avrnet +############################################################################### + +## General Flags +PROJECT = avrnet +MCU = atmega32 +TARGET = avrnet.elf +CC = avr-gcc.exe + +## Options common to compile, link and assembly rules +COMMON = -mmcu=$(MCU) + +## Compile options common for all C compilation units. +CFLAGS = $(COMMON) +CFLAGS += -Wall -gdwarf-2 -DF_CPU=16000000UL -Os -fsigned-char +CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d + +## Assembly specific flags +ASMFLAGS = $(COMMON) +ASMFLAGS += $(CFLAGS) +ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 + +## Linker flags +LDFLAGS = $(COMMON) +LDFLAGS += -Wl,-Map=avrnet.map + + +## Intel Hex file production flags +HEX_FLASH_FLAGS = -R .eeprom + +HEX_EEPROM_FLAGS = -j .eeprom +HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" +HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings + + +## Objects that must be built in order to link +OBJECTS = enc28j60.o main.o http.o arp.o tcp.o ip.o ethernet.o icmp.o menu.o lcd.o adc.o udp.o + +## Objects explicitly added by the user +LINKONLYOBJECTS = + +## Build +all: $(TARGET) avrnet.hex avrnet.eep avrnet.lss size + +## Compile +enc28j60.o: ../enc28j60.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +main.o: ../main.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +http.o: ../http.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +arp.o: ../arp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +tcp.o: ../tcp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +ip.o: ../ip.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +ethernet.o: ../ethernet.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +icmp.o: ../icmp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +menu.o: ../menu.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +lcd.o: ../lcd.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +adc.o: ../adc.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +udp.o: ../udp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +##Link +$(TARGET): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) + +%.hex: $(TARGET) + avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ + +%.eep: $(TARGET) + -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 + +%.lss: $(TARGET) + avr-objdump -h -S $< > $@ + +size: ${TARGET} + @echo + @avr-size -C --mcu=${MCU} ${TARGET} + +## Clean target +.PHONY: clean +clean: + -rm -rf $(OBJECTS) avrnet.elf dep/* avrnet.hex avrnet.eep avrnet.lss avrnet.map + + +## Other dependencies +-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) + Index: trunk/apps/reference/avr-webserver/menu.c =================================================================== --- trunk/apps/reference/avr-webserver/menu.c (nonexistent) +++ trunk/apps/reference/avr-webserver/menu.c (revision 46) @@ -0,0 +1,651 @@ +//******************************************************************************************** +// +// File : menu.c implement for User interface menu +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include "includes.h" +//******************************************************************************************* +// +// Global variable +// +//******************************************************************************************* +BYTE menu_index, submenu_index; +BYTE menu_stack, submenu_stack; +BYTE setting_cursor; +BYTE standby_cursor; +BYTE sec_count; +// max index for cursor setting +prog_uint8_t setting_cursor_max[3] = { 4, 4, 4 }; +// count down timer for send temp. H:M:S +prog_uint8_t count_time_max[4] = { 2, 60, 60, 24 }; +// countdown timer 4-bytes, [0]=en/dis, [1]=hour, [2]=min, [3]=sec +BYTE count_time[4]; +// count down time initial value stored in eeprom. Enable/Disable, Hour, Minute +BYTE ee_count_time[3] EEMEM = { 0, 0, 1 }; +prog_uint8_t str_enable[] = "Enable"; +prog_uint8_t str_disable[] = "Disable"; + +// menu and standby display string +PGM_P menu_list[5] = +{ + "Main menu", + "AVR IP config", + "Server IP config", + "Send temp config", + "Ping server" +}; + +PGM_P standby_list[4] = +{ + "AVR IP", + "Server IP", + "Send temp in", + "ADC0 & Temp" +}; + +//***************************************************************************************** +// +// Function : my_memcpy +// Description : copy string (end '\0') from program memory to ram and return pointer +// to end of string +// +//***************************************************************************************** +BYTE *my_strcpy ( BYTE *dest, PGM_P src ) +{ + BYTE ch; + + while ( (ch = pgm_read_byte( src++ )) ) + { + *dest++ = ch; + } + return dest; +} + +//***************************************************************************************** +// +// Function : print_decimal +// Description : Print decimal to buffer, up to 5 digits +// +//***************************************************************************************** +BYTE * print_decimal ( BYTE *ptr, BYTE digit, WORD dec ) +{ + if ( digit >= 5 ) + *ptr++ = ( (dec/10000) + '0' ); + if ( digit >= 4 ) + *ptr++ = ( ((dec%10000)/1000) + '0' ); + if ( digit >= 3 ) + *ptr++ = ( ((dec%1000)/100) + '0' ); + if ( digit >= 2 ) + *ptr++ = ( ((dec%100)/10) + '0' ); + *ptr++ = ( ((dec%10)) + '0' ); + + return ptr; +} +//***************************************************************************************** +// +// Function : print_temp +// Description : Print ADC0 and temparature to buffer +// +//***************************************************************************************** +void print_temp ( BYTE *dest ) +{ + WORD adc0_value; + BYTE temp_value; + + adc0_value = adc_read ( 0 ); + temp_value = adc_read_temp ( ); + + dest = print_decimal ( dest, 4, adc0_value ); + *dest++ = ','; + dest = print_decimal ( dest, 2, temp_value ); + *dest++ = ASCII_DEGREE; + *dest++ = 'C'; + *dest = '\0'; +} +//***************************************************************************************** +// +// Function : print_ip +// Description : Print ip address format to buffer e.g. 10.1.1.1 +// +//***************************************************************************************** +void print_ip ( BYTE *ptr, BYTE *ip, BYTE cursor ) +{ + BYTE i, digit, temp; + + for ( i=0; i<4; i++ ) + { + temp = ip [ i ]; + if ( temp > 99 ) + digit = 3; + else if ( temp > 9 ) + digit = 2; + else + digit = 1; + + if ( (i+1) == cursor ) + { + *ptr = ASCII_CURSOR; + ptr++; + } + else if ( i > 0 ) + { + *ptr = '.'; + ptr++; + } + ptr = print_decimal ( ptr, digit, temp ); + + } + *ptr = '\0'; +} +//***************************************************************************************** +// +// Function : print_time +// Description : Print time format to buffer e.g. 01:23:45 +// +//***************************************************************************************** +void print_time ( BYTE *ptr, BYTE *time, BYTE cursor ) +{ + BYTE i; + + // show setting cursor when enter to setting mode + if ( cursor == 0 ) + { + if ( time [ 0 ] ) + { + time++; + for ( i=0; i<3; i++ ) + { + if ( (i+2) == cursor ) + { + *ptr++ = ASCII_CURSOR; + } + else if ( i > 0 ) + { + *ptr++ = ':'; + } + ptr = print_decimal ( ptr, 2, *time++ ); + } + } + else + { + ptr = my_strcpy ( ptr, (PGM_P)str_disable ); + } + } + else + { + if ( cursor == 1 ) + { + *ptr++ = ASCII_CURSOR; + // show Enable/Disable send temparature to server + if ( time [ 0 ] ) + ptr = my_strcpy ( ptr, (PGM_P)str_enable ); + else + ptr = my_strcpy ( ptr, (PGM_P)str_disable ); + } + else + { + time++; + for ( i=0; i<3; i++ ) + { + if ( (i+2) == cursor ) + { + *ptr++ = ASCII_CURSOR; + } + else if ( i > 0 ) + { + *ptr++ = ':'; + } + ptr = print_decimal ( ptr, 2, *time++ ); + } + } + } + + *ptr = '\0'; +} +//***************************************************************************************** +// +// Function : time_base +// Description : count-down timer for send temparature to server. you can enable/disable and +// adjust timer by "Send temp config" menu. +// +//***************************************************************************************** +void time_base ( void ) +{ + static BYTE send_temp_timeout=0; + + if ( ++sec_count == 250 ) + { + sec_count = 0; + + // update lcd display + flag1.bits.update_display = 1; + + // timeout for send temparature to webserver + if ( flag1.bits.syn_is_sent ) + { + // 5 seconds + if ( ++send_temp_timeout == 5 ) + { + send_temp_timeout = 0; + flag1.bits.send_temp_timeout = 1; + } + } + // send temparature to server countdown + if ( count_time[ 0 ] && menu_index!=4 ) + { + if ( --count_time[ 3 ] > 59 ) + { + //count_time[ 3 ] = 59; + count_time[ 3 ] = 20; // debug + if ( --count_time[ 2 ] > 59 ) + { + count_time[ 2 ] = 59; + if ( --count_time[ 1 ] > 23 ) + { + // read hour + count_time[ 1 ] = eeprom_read_byte( ee_count_time + 1 ); + // read minute + count_time[ 2 ] = eeprom_read_byte( ee_count_time + 2 ); + // clear second + count_time[ 3 ] = 0; + flag1.bits.send_temp = 1; + } + } + } + } + } +} +//******************************************************************************************* +// +// Function : standby_display +// Description : display board status such as AVR ip, server ip, countdown time, temparature +// +//******************************************************************************************* +void standby_display ( void ) +{ + BYTE generic_buf[64]; + + // update lcd display flag not set, exit from function + if ( flag1.bits.update_display == 0 ) + return; + flag1.bits.update_display = 0; + // lcd display is displaying other information, wait until busy flag clear + if ( flag1.bits.lcd_busy ) + return; + // now displaying menu information, wait until exit from menu + if ( menu_index ) + return; + + // display status on lcd line 1 + lcd_putc ( '\f' ); + lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] ); + + // display status on lcd line 2 + lcd_putc ( '\n' ); + // display avr ip + if ( standby_cursor == 1 ) + { + print_ip ( generic_buf, (BYTE*)&avr_ip, 0 ); + } + // display server ip + else if ( standby_cursor == 2 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, 0 ); + } + // display countdown timer + else if ( standby_cursor == 3 ) + { + print_time ( generic_buf, count_time, 0 ); + } + // display current temparature + else if ( standby_cursor == 4 ) + { + print_temp ( generic_buf ); + } + lcd_print ( generic_buf ); +} +//******************************************************************************************* +// +// Function : display_menu +// Description : display LCD user interface menu on LCD +// +//******************************************************************************************* +void display_menu(void) +{ + BYTE generic_buf[64]; + + if( menu_index == 0) + return; + + // display menu title on lcd first line + lcd_putc( '\f' ); + lcd_print ( (BYTE *)menu_list[ menu_index - 1 ] ); + + // display menu detail on lcd second line + lcd_putc( '\n' ); + if( menu_index == 1 )//MENU_MAIN) + { + lcd_print( (BYTE *)menu_list[ submenu_index ] ); + } + // setup avr ip address + else if( menu_index == 2 ) + { + print_ip ( generic_buf, (BYTE*)&avr_ip, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // setup server ip address + else if(menu_index == 3 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // setup countdown timer for send temparature + else if ( menu_index == 4 ) + { + print_time ( generic_buf, count_time, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // ping server + else if ( menu_index == 5 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, 1 ); + lcd_print ( generic_buf ); + } + // send temparature now + //else if ( menu_index == 6 ) + //{ + // lcd_put ( ASCII_CURSOR ); + // lcd_print_p ( PSTR ( "OK" ) ); + //} +} +//******************************************************************************************* +// +// Function : key_up_process +// Description : +// +//******************************************************************************************* +void key_up_process ( void ) +{ + BYTE temp; + + // standby display, display board status + if(menu_index == 0) + { + if ( ++ standby_cursor == ((sizeof(standby_list)/2)+1) ) + standby_cursor = 1; + flag1.bits.update_display = 1; + } + // main menu + else if(menu_index == 1) + { + if( ++submenu_index == (sizeof(menu_list)/2) ) + { + submenu_index = 1; + } + } + // setup avr ip + else if( menu_index == 2 ) + { + avr_ip.byte [ setting_cursor ]++; + eeprom_write_block ( &avr_ip, ee_avr_ip, 4 ); + } + // setup server ip + else if( menu_index == 3 ) + { + server_ip.byte [ setting_cursor ]++; + eeprom_write_block ( &server_ip, ee_server_ip, 4 ); + } + // setup countdown timer + else if( menu_index == 4 ) + { + temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) ); + if ( ++count_time [ setting_cursor ] == temp ) + count_time [ setting_cursor ] = 0; + eeprom_write_block ( count_time, ee_count_time, 4 ); + } +} +//******************************************************************************************* +// +// Function : key_dw_process +// Description : +// +//******************************************************************************************* +void key_dw_process ( void ) +{ + BYTE temp; + + // standby display, display board status + if(menu_index == 0) + { + if ( -- standby_cursor == 0 ) + standby_cursor = sizeof(standby_list)/2; + flag1.bits.update_display = 1; + } + // main menu + else if(menu_index == 1) + { + if( --submenu_index == 0 ) + { + submenu_index = (sizeof(menu_list)/2)-1; + } + } + // setup avr ip + else if( menu_index == 2 ) + { + avr_ip.byte [ setting_cursor ]--; + eeprom_write_block ( &avr_ip, ee_avr_ip, 4 ); + } + // setup server ip + else if( menu_index == 3 ) + { + server_ip.byte [ setting_cursor ]--; + eeprom_write_block ( &server_ip, ee_server_ip, 4 ); + } + // setup countdown timer + else if( menu_index == 4 ) + { + temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) ); + if ( --count_time [ setting_cursor ] == 0xff ) + count_time [ setting_cursor ] = temp; + eeprom_write_block ( count_time, ee_count_time, 4 ); + } +} +//******************************************************************************************* +// +// Function : key_process +// Description : Process all key code from get_key_code function +// +//******************************************************************************************* +void menu_process ( void ) +{ + static BYTE key_hold_count=0, key_hold_step_delay=0; + BYTE rxtx_buffer[MAX_RXTX_BUFFER]; + BYTE key_code, temp; + static BYTE backlight_sec=31, backlight_seccount=250; + + // get switch value from port + key_code = SW_PIN & ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ); + + // Check key press? + if ( key_code == ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ) ) + { + flag1.bits.key_is_executed = 0; + flag2.bits.key_hold = 0; + key_hold_count = 0; + key_hold_step_delay = 0; + + // lcd backlight control + // lcd backlight off after key is unpress ( 30 seconds) + if ( backlight_sec ) + { + if ( --backlight_seccount > 250 ) + { + backlight_seccount = 250; + if ( --backlight_sec == 1 ) + { + backlight_sec = 0; + // lcd backlight off + LCD_BL_PORT &= ~_BV( LCD_BL_PIN ); + } + } + } + return; + } + + // lcd backlight on + // and hold-on 30 seconds + backlight_sec = 31; + LCD_BL_PORT |= _BV( LCD_BL_PIN ); + + // check hold key + if ( ++key_hold_count == 200 ) + { + key_hold_count = 0; + flag2.bits.key_hold = 1; + } + + if ( flag2.bits.key_hold ) + { + if ( ++key_hold_step_delay == 30 ) + { + key_hold_step_delay = 0; + if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) ) + { + key_up_process (); + } + // if down key is pressed + else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) ) + { + key_dw_process (); + } + display_menu(); + } + } + // key code already executed + if ( flag1.bits.key_is_executed ) + return; + // check key code, what is key pressed? + // if menu key is pressed + if ( key_code == ((~_BV ( SW_MENU ) ) & 0xf0) ) + { + // enter to main menu + if( menu_index == 0 ) + { + setting_cursor = 0; + menu_index = 1; + submenu_index = 1; + } + // enter to submenu + else if( menu_index == 1 ) + { + menu_stack = menu_index; + submenu_stack = submenu_index; + menu_index = submenu_index + menu_index; + submenu_index = 1; + } + // ping server + else if ( menu_index == 5 ) + { + // Show on lcd first line + lcd_putc( '\f' ); + lcd_print ( (BYTE *)menu_list[ 4 ] ); + lcd_putc( '\n' ); + if ( icmp_ping ( (BYTE*)rxtx_buffer, (BYTE*)&server_mac, (BYTE*)&server_ip ) ) + { + lcd_print_p ( PSTR ( "Ping OK." ) ); + } + else + { + lcd_print_p ( PSTR ( "Not found." ) ); + } + flag1.bits.lcd_busy = 1; + menu_index = 0; + submenu_index = 0; + flag1.bits.key_is_executed = 1; + return; + } + // change cursor setting on each menu + else + { + temp = pgm_read_byte ( (PGM_P)(setting_cursor_max + menu_index - 2) ); + + if ( ++setting_cursor == temp ) + setting_cursor = 0; + } + } + // if exit key is pressed + else if ( key_code == ((~_BV ( SW_EXIT ) ) & 0xf0) ) + { + setting_cursor = 0; + if(menu_index > 1) + { + menu_index = menu_stack; + submenu_index = submenu_stack; + } + else + { + menu_index = 0; + submenu_index = 0; + + } + } + // if up key is pressed + else if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) ) + { + key_up_process (); + } + // if down key is pressed + else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) ) + { + key_dw_process (); + } + // display menu information on LCD + display_menu(); + flag1.bits.key_is_executed = 1; + flag1.bits.lcd_busy = 0; +} +//******************************************************************************************* +// +// Function : menu_init +// Description : initial I/O direction for all key, +// initial timer1 for countdown timer +// +//******************************************************************************************* +void menu_init ( void ) +{ + // setup countdown initial value + sec_count = 0; + eeprom_read_block ( count_time, ee_count_time, 3 ); + count_time[3] = 0; + + // setup menu and standby display + flag1.byte = 0; + flag2.byte = 0; + menu_index = 0; + submenu_index = 0; + menu_stack = 0; + submenu_stack = 0; + setting_cursor = 0; + standby_cursor = 1; +} Index: trunk/apps/reference/avr-webserver/avrnet.aws =================================================================== --- trunk/apps/reference/avr-webserver/avrnet.aws (nonexistent) +++ trunk/apps/reference/avr-webserver/avrnet.aws (revision 46) @@ -0,0 +1 @@ +
Index: trunk/apps/reference/avr-webserver/lcd.h
===================================================================
--- trunk/apps/reference/avr-webserver/lcd.h (nonexistent)
+++ trunk/apps/reference/avr-webserver/lcd.h (revision 46)
@@ -0,0 +1,59 @@
+//********************************************************************************************
+//
+// File : lcd.h implement for 16x2 LCD module
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#define LCD_DATA_PORT PORTD
+#define LCD_DATA_DDR DDRD
+#define LCD_D7 PD7
+#define LCD_D6 PD6
+#define LCD_D5 PD5
+#define LCD_D4 PD4
+#define LCD_CONTROL_PORT PORTB
+#define LCD_CONTROL_DDR DDRB
+#define LCD_RS_PIN PB0
+#define LCD_RW_PIN PB1
+#define LCD_EN_PIN PB2
+
+#define SET_FUNCTION 0x28 // 8bits, 2lines
+#define DISPLAY_ON 0x0C
+#define DISPLAY_CLR 0x01
+#define ENTRY_MODE 0x06 // Entry = increase
+#define RETURN_HOME 0x02
+#define CURSOR_BACK 0x10
+#define SET_DDRAM 0x80
+#define WRITE_DATA 1
+#define WRITE_COMMAND 0
+#define LCD_EN 0x80
+#define LCD_LINE_TWO 0x40
+//********************************************************************************************
+//
+// Prototype function
+//
+//********************************************************************************************
+extern void lcd_init(void);
+extern void lcd_gotoxy(unsigned char x,unsigned char y);
+extern void lcd_putc(unsigned char c);
+extern void lcd_print( unsigned char * ptr );
+extern void lcd_print_p( PGM_P ptr );
Index: trunk/apps/reference/avr-webserver/menu.h
===================================================================
--- trunk/apps/reference/avr-webserver/menu.h (nonexistent)
+++ trunk/apps/reference/avr-webserver/menu.h (revision 46)
@@ -0,0 +1,92 @@
+//********************************************************************************************
+//
+// File : menu.h implement for User interface menu
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#define SW_DW 7
+#define SW_UP 6
+#define SW_EXIT 5
+#define SW_MENU 4
+#define SW_DDR DDRA
+#define SW_PORT PORTA
+#define SW_PIN PINA
+#define LCD_BL_PIN PB3
+#define LCD_BL_PORT PORTB
+#define LCD_BL_DDR DDRB
+
+//#define MENU_MAIN 1
+//#define MENU_SET_AVR_IP 2
+//#define MENU_SET_SERVER_IP 3
+//#define MENU_SET_COUNT_TIME 4
+//#define MENU_PING_SERVER 5
+//#define MENU_SEND_TEMP 6
+
+#define SUBMENU_SET_AVR_IP 1
+#define SUBMENU_SET_SERVER_IP 2
+#define SUBMENU_SET_COUNT_TIME 3
+#define SUBMENU_PING_SERVER 4
+#define SUBMENU_SEND_TEMP 6
+
+#define CURSOR_SET_AVR_IP1 0
+#define CURSOR_SET_AVR_IP2 1
+#define CURSOR_SET_AVR_IP3 2
+#define CURSOR_SET_AVR_IP4 3
+
+#define CURSOR_SET_SERVER_IP1 0
+#define CURSOR_SET_SERVER_IP2 1
+#define CURSOR_SET_SERVER_IP3 2
+#define CURSOR_SET_SERVER_IP4 3
+
+#define CURSOR_SET_COUNT_TIME1 0
+#define CURSOR_SET_COUNT_TIME2 1
+#define CURSOR_SET_COUNT_TIME3 2
+#define CURSOR_SET_COUNT_TIME4 3
+
+//#define STANDBY_CURSOR_AVR_IP 1
+//#define STANDBY_CURSOR_SERVER_IP 2
+//#define STANDBY_CURSOR_COUNT_DOWN 3
+//#define STANDBY_CURSOR_TEMP 4
+
+#define ASCII_CURSOR 0x7E
+
+#include
+
+extern BYTE standby_cursor;
+extern BYTE ee_count_time[] EEMEM;
+extern BYTE count_time[];
+
+//********************************************************************************************
+//
+// Prototype function
+//
+//********************************************************************************************
+extern void menu_process ( void );
+extern void menu_init ( void );
+extern void standby_display ( void );
+extern void time_base ( void );
+extern void print_ip ( BYTE *ptr, BYTE *ip, BYTE cursor );
+extern void print_time ( BYTE *ptr, BYTE *time, BYTE cursor );
+extern BYTE *print_decimal ( BYTE *ptr, BYTE digit, WORD dec );
+extern void key_up_process ( void );
+extern void key_dw_process ( void );
Index: trunk/apps/reference/avr-webserver/ReadmeTH.html
===================================================================
--- trunk/apps/reference/avr-webserver/ReadmeTH.html (nonexistent)
+++ trunk/apps/reference/avr-webserver/ReadmeTH.html (revision 46)
@@ -0,0 +1,88 @@
+
+
+AVRnet V0.9 by avrportal.com
+
+
+
+AVRnet V1.0 by avrportal.com
+ÎÒÃì´áÇÃìãªéÎÒÃì´áÇÃìà´ÔÁ¨Ò¡ V0.9
+ÁÕÍÐäÃãËÁèã¹ V1.0?
+- à¾ÔèÁâ»ÃⵤÍÅ UDP (User Datagram Protocol)
+- ÁÕâ»Ãá¡ÃÁ AVRnet CPannel ÊÓËÃѺãªéµÔ´µèͺÍÃì´ AVRnet ¼èÒ¹â»ÃⵤÍÅ UDP â»Ãá¡ÃÁ AVRnet CPannel à¢Õ¹¢Öé¹ÁÒâ´Âãªé CodeBlocks C++ IDE ÃèÇÁ¡Ñº wxWidgets GUI tool kits áÅÐãªé MinGW GCC compiler
+ +ÊÓËÃѺÇÔ¸Õ¡ÒõԴµÑé§ CodeBlocks, wxWidgets, MinGW ÊÒÁÒö´Ùà¾ÔèÁàµÔÁ¨Ò¡ËÑÇ¢éÍ ¡ÒõԴµÑé§ CodeBlocks free C++ IDE, wxWidgets, MinGW
+
+ +![](AVRnetCPannel.gif)
+
+´ÒǹìâËÅ´
+AVRnet V1.0 source code
+AVRnet CPannel source code
+AVRnet CPannel binary
+ +
+
+AVRnet V0.9 by avrportal.com
+
+AVRnet Firmware Version 0.9
+
+ AVRnet à»ç¹ºÍÃì´ÊÓËÃѺ¾Ñ²¹ÒáÅÐÈÖ¡ÉÒ¡ÒÃãªéäÁâ¤Ã¤Í¹â·ÃÅàÅÍÃì 㹡ÒÃàª×èÍÁµè͡Ѻ Ethernet protocol +ãªéäÁâ¤Ã¤Í¹â·ÃÅàÅÍÃìµÃСÙÅ AVR ATMEGA32 à»ç¹µÑǤǺ¤ØÁËÅÑ¡ ãªé ENC28J60 à»ç¹ Ethernet controller +áÅÐÂѧÁÕ LCD ÊÓËÃѺµÔ´µè͡Ѻ¼Ùéãªé§Ò¹ ÊÓËÃѺ¡ÒõÑ駤èÒáÅÐáÊ´§Ê¶Ò¹ÐµèÒ§æ¢Í§ºÍÃì´
+ àÃÒÊÒÁÒö¹ÓºÍÃì´ AVRnet ä»ÊÃéÒ§à»ç¹ web-server ¢¹Ò´àÅç¡ÊÓËÃѺ¤Çº¤ØÁÍØ»¡Ã³ì,à¤Ã×èͧãªéä¿¿éÒ¼èÒ¹·Ò§ Internet ËÃ×ÍÃкº LAN +ã¹ firmware v0.9 ¹ÕéÂѧÁÕ¡ÒùӺÍÃì´ AVRnet ä»·Óà»ç¹ web-client ÊÓËÃѺ¡ÒÃÊ觤èÒÍسËÀÙÁÔº¹ºÍÃì´ä»à¡çºäÇé·Õè web-server +â´Âãªé protocol http (ÊÒÁÒö¹Óä»ãªéà»ç¹ web data loger) â´Âã¹ firmware v0.9 ¨Ð»Ô´¡ÒÃãªé§Ò¹ web-client äÇéà»ç¹¤èÒàÃÔèÁµé¹ +áµè¤Ø³ÊÒÁÒöà»Ô´¡ÒÃãªé§Ò¹ web-client ä´é·ÕèàÁ¹Ù Send temp config áµèà¤Ã×èͧ¤ÍÁ¾ÔÇàµÍÃì¢Í§¤Ø³¨ÐµéͧµÔ´µÑé§ web-server áÅÐ server script ¡è͹ +ÊÓËÃѺ¡ÒõԴµÑé§ web-server áÅÐ server script ÊÒÁÒöà¢éÒä»´Ùä´é·Õè http://www.avrportal.com
+
+
+
+Hardware feature
+
+- MCU : ATMEGA32 @ 16MHz
+- Ethernet controller : ENC28J60
+- RJ11 for LAN
+- LCD user interface menu
+- JTAG interface for program and debug
+- Temparature sensor using thermistor
+- 1 potentiometer for ADC0
+- I2C connector with pull-up resistor
+- Built-in Voltage regulator
+- LEDs display and switchs for LCD menu
+
+
+Firmware feature
+
+- Firmware is GPL using AVR GCC compiler
+- LCD user interface menu and borad status
+- Webserver listen on port 80 ( example page "webpage.htm" )
+- Webclient listen on port 1200 ( use for send temparature to webserver.)
+
+
+LCD user interface menu
+AVRnet ÁÕÊÇÔµ«ì·ÕèãªéÊÓËÃѺ LCD àÁ¹Ù ´Ñ§¹Õé Menu, Exit, Up, Dw ¡ÒõÑ駤èÒµèÒ§ÊÒÁÒö·Óä´éâ´Âà¢éÒä»·ÕèàÁ¹Ù¡ÒõÑ駤èҢͧáµèÅÐàÁ¹Ù.
+ÃÒÂÅÐàÍÕ´¢Í§áµèÅÐàÁ¹ÙÁմѧ¹Õé.
+
+Main menu
+
+standby display mode
+
+ + \ No newline at end of file Index: trunk/apps/reference/avr-webserver/includes.h =================================================================== --- trunk/apps/reference/avr-webserver/includes.h (nonexistent) +++ trunk/apps/reference/avr-webserver/includes.h (revision 46) @@ -0,0 +1,82 @@ +//******************************************************************************************** +// +// File : include.h includes all header file for AVRethernet development board. +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// struct.h MUST be include first
+#include "struct.h"
+#include "enc28j60.h"
+#include "ethernet.h"
+#include "ip.h"
+#include "tcp.h"
+#include "icmp.h"
+#include "arp.h"
+#include "udp.h"
+#include "http.h"
+#include "lcd.h"
+#include "menu.h"
+#include "adc.h"
+
+// define I/O interface
+
+#define LED_PIN1_DDR DDC6
+#define LED_PIN1 PC6
+#define LED_PIN2_DDR DDC7
+#define LED_PIN2 PC7
+#define LED_PORT PORTC
+#define LED_DDR DDRC
+
+#define LOW(uint) (uint&0xFF)
+#define HIGH(uint) ((uint>>8)&0xFF)
+
+#define MAX_RXTX_BUFFER 1518
+
+// global variables
+extern MAC_ADDR avr_mac;
+extern IP_ADDR avr_ip;
+
+//extern MAC_ADDR client_mac;
+//extern IP_ADDR client_ip;
+
+extern MAC_ADDR server_mac;
+extern IP_ADDR server_ip;
+
+extern BYTE generic_buf[];
+extern BYTE ee_avr_ip[];
+extern BYTE ee_server_ip[];
+//********************************************************************************************
+//
+// Prototype function from main.c
+//
+//********************************************************************************************
+extern void initial_system( void );
+
Index: trunk/apps/reference/avr-webserver/ethernet.c
===================================================================
--- trunk/apps/reference/avr-webserver/ethernet.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/ethernet.c (revision 46)
@@ -0,0 +1,119 @@
+//********************************************************************************************
+//
+// File : ethernet.c implement for Ethernet Protocol
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+//********************************************************************************************
+//
+// Ethernet is a large, diverse family of frame-based computer networking technologies
+// that operates at many speeds for local area networks (LANs).
+// The name comes from the physical concept of the ether.
+// It defines a number of wiring and signaling standards for the physical layer,
+// through means of network access at the Media Access Control (MAC)/Data Link Layer,
+// and a common addressing format.
+//
+// Ethernet has been standardized as IEEE 802.3.
+// The combination of the twisted pair versions of ethernet for connecting end systems to
+// the network with the fiber optic versions for site backbones
+// become the most widespread wired LAN technology in use from the 1990s to the present,
+// largely replacing competing LAN standards such as coaxial cable Ethernet,
+// token ring, FDDI, and ARCNET. In recent years, Wi-Fi,
+// the wireless LAN standardized by IEEE 802.11,
+// has been used instead of Ethernet for many home and small office networks
+// and in addition to Ethernet in larger installations.
+//
+//
+//********************************************************************************************
+
+//********************************************************************************************
+//
+// Function : eth_generate_header
+// Description : generarete ethernet header, contain destination and source MAC address,
+// ethernet type.
+//
+//********************************************************************************************
+void eth_generate_header ( BYTE *rxtx_buffer, WORD_BYTES type, BYTE *dest_mac )
+{
+ BYTE i;
+ //copy the destination mac from the source and fill my mac into src
+ for ( i=0; i1)
+ {
+ sum += 0xFFFF & (*rxtx_buffer<<8|*(rxtx_buffer+1));
+ rxtx_buffer+=2;
+ len-=2;
+ }
+ // if there is a byte left then add it (padded with zero)
+ if (len)
+ {
+ sum += (0xFF & *rxtx_buffer)<<8;
+ }
+ // now calculate the sum over the bytes in the sum
+ // until the result is only 16bit long
+ while (sum>>16)
+ {
+ sum = (sum & 0xFFFF)+(sum >> 16);
+ }
+ // build 1's complement:
+ return( (WORD) sum ^ 0xFFFF);
+}
Index: trunk/apps/reference/avr-webserver/ethernet.h
===================================================================
--- trunk/apps/reference/avr-webserver/ethernet.h (nonexistent)
+++ trunk/apps/reference/avr-webserver/ethernet.h (revision 46)
@@ -0,0 +1,47 @@
+//********************************************************************************************
+//
+// File : ethernet.h implement for Ethernet Protocol
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#define ETH_TYPE_ARP_V 0x0806
+#define ETH_TYPE_ARP_H_V 0x08
+#define ETH_TYPE_ARP_L_V 0x06
+#define ETH_TYPE_IP_V 0x0800
+#define ETH_TYPE_IP_H_V 0x08
+#define ETH_TYPE_IP_L_V 0x00
+
+#define ETH_HEADER_LEN 14
+
+#define ETH_DST_MAC_P 0
+#define ETH_SRC_MAC_P 6
+#define ETH_TYPE_H_P 12
+#define ETH_TYPE_L_P 13
+//********************************************************************************************
+//
+// Prototype function
+//
+//********************************************************************************************
+//void eth_generate_packet ( ETH_HEADER eth_header );
+extern WORD software_checksum( BYTE *rxtx_buffer, WORD len, DWORD sum);
+extern void eth_generate_header ( BYTE *rxtx_buffer, WORD_BYTES type, BYTE *dest_mac );
Index: trunk/apps/reference/avr-webserver/AVRnetCPannel.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/apps/reference/avr-webserver/AVRnetCPannel.gif
===================================================================
--- trunk/apps/reference/avr-webserver/AVRnetCPannel.gif (nonexistent)
+++ trunk/apps/reference/avr-webserver/AVRnetCPannel.gif (revision 46)
- 1
"; +prog_int8_t tag_form[] = "" ), dlen ); + + // AVR IP address + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P) tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " " ), dlen ); + + // Server IP address + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P)tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " " ), dlen ); + + // Write LCD form + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P) tag_form, dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " LCD Line 1
" ), dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( " LCD Line 2
" ), dlen ); + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( "" ), dlen ); + + dlen = tcp_puts_data_p ( rxtx_buffer, (PGM_P)tag_hr, dlen ); + + dlen = tcp_puts_data_p ( rxtx_buffer, PSTR ( "Refresh" ), dlen ); + + return(dlen); +} Index: trunk/apps/reference/avr-webserver/arp.c =================================================================== --- trunk/apps/reference/avr-webserver/arp.c (nonexistent) +++ trunk/apps/reference/avr-webserver/arp.c (revision 46) @@ -0,0 +1,215 @@ +//******************************************************************************************** +// +// File : arp.c implement for Address Resolution Protocol +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include "includes.h" +//******************************************************************************************** +// +// Address Resolution Protocol (ARP) is the method for finding a host's hardware address +// when only its network layer address is known. +// Due to the overwhelming prevalence of IPv4 and Ethernet, +// ARP is primarily used to translate IP addresses to Ethernet MAC addresses. +// It is also used for IP over other LAN technologies, +// such as Token Ring, FDDI, or IEEE 802.11, and for IP over ATM. +// +// ARP is used in four cases of two hosts communicating: +// +// 1. When two hosts are on the same network and one desires to send a packet to the other +// 2. When two hosts are on different networks and must use a gateway/router to reach the other host +// 3. When a router needs to forward a packet for one host through another router +// 4. When a router needs to forward a packet from one host to the destination host on the same network +// +// +------------+------------+-----------+ +// + MAC header + ARP header + Data ::: + +// +------------+------------+-----------+ +// +// ARP header +// +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+ +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Hardware type + Protocol type + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + HardwareAddressLength + ProtocolAddressLength + Opcode + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Source hardware address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Source protocol address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Destination hardware address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Destination protocol address ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// + Data ::: + +// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +// +//******************************************************************************************** + +//******************************************************************************************** +// +// Function : arp_generate_packet +// Description : generate arp packet +// +//******************************************************************************************** +void arp_generate_packet ( BYTE *rxtx_buffer, BYTE *dest_mac, BYTE *dest_ip ) +{ + unsigned char i; + + // setup hardware type to ethernet 0x0001 + rxtx_buffer[ ARP_HARDWARE_TYPE_H_P ] = ARP_HARDWARE_TYPE_H_V; + rxtx_buffer[ ARP_HARDWARE_TYPE_L_P ] = ARP_HARDWARE_TYPE_L_V; + + // setup protocol type to ip 0x0800 + rxtx_buffer[ ARP_PROTOCOL_H_P ] = ARP_PROTOCOL_H_V; + rxtx_buffer[ ARP_PROTOCOL_L_P ] = ARP_PROTOCOL_L_V; + + // setup hardware length to 0x06 + rxtx_buffer[ ARP_HARDWARE_SIZE_P ] = ARP_HARDWARE_SIZE_V; + + // setup protocol length to 0x04 + rxtx_buffer[ ARP_PROTOCOL_SIZE_P ] = ARP_PROTOCOL_SIZE_V; + + // setup arp destination and source mac address + for ( i=0; i
+Hardware is base on V0.9
+What's new?
+- UDP (User Datagram Protocol) has been added to V1.0
+- New software AVRnet CPannel for UDP interfacing, written using CodeBlocks C++ IDE with wxWidgets GUI tool kits and MinGW GCC compiler.
+ +
![](AVRnetCPannel.gif)
+
Download
+AVRnet V1.0 source code
+AVRnet CPannel source code
+AVRnet CPannel binary
+
+
+ +AVRnet V0.9 by avrportal.com
+
+AVRnet Firmware Version 0.9
+
+AVRnet is an Ethernet development board, v0.9 first is pubblic release.
+You can use AVRnet to build a small web-server and web-client for send data to webserver.
+Before you can use web-client application, Apache and PHP must be installed on your pc.
+More detail about Apache and PHP installation please visit http://www.avrportal.com
+
+
+
+Hardware feature
+
+- MCU : ATMEGA32 @ 16MHz
+- Ethernet controller : ENC28J60
+- RJ11 for LAN
+- LCD user interface menu
+- JTAG interface for program and debug
+- Temparature sensor using thermistor
+- 1 potentiometer for ADC0
+- I2C connector with pull-up resistor
+- Built-in Voltage regulator
+- LEDs display and switchs for LCD menu
+
+
+Firmware feature
+
+- Firmware is GPL using AVR GCC compiler
+- LCD user interface menu and borad status
+- Webserver listen on port 80 ( example page "webpage.htm" )
+- Webclient listen on port 1200 ( use for send temparature to webserver.)
+
+
+LCD user interface menu
+AVRnet use 4 tact switchs are menu, exit, up and dw for LCD menu.
+You can setup AVR IP, Server IP, Countdown timer by enter to each menu.
+
+Main menu
+
-
+
- AVR IP config (setup AVRnet IP address) +
- Server IP config (setup AVRnet IP address) +
- Send temp config (setup countdown timer for send temparature to webserver) +
- Ping server (check server online status) +
+standby display mode
+
-
+
- AVR IP(show current AVR IP address) +
- Server IP (show current server IP address) +
- Send temp in (show countdown timer for send temp) +
- ADC0 & Temp (show current ADC0 and temparature) +
+ + \ No newline at end of file Index: trunk/apps/reference/avr-webserver/default/Makefile =================================================================== --- trunk/apps/reference/avr-webserver/default/Makefile (nonexistent) +++ trunk/apps/reference/avr-webserver/default/Makefile (revision 46) @@ -0,0 +1,108 @@ +############################################################################### +# Makefile for the project avrnet +############################################################################### + +## General Flags +PROJECT = avrnet +MCU = atmega32 +TARGET = avrnet.elf +CC = avr-gcc.exe + +## Options common to compile, link and assembly rules +COMMON = -mmcu=$(MCU) + +## Compile options common for all C compilation units. +CFLAGS = $(COMMON) +CFLAGS += -Wall -gdwarf-2 -DF_CPU=16000000UL -Os -fsigned-char +CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d + +## Assembly specific flags +ASMFLAGS = $(COMMON) +ASMFLAGS += $(CFLAGS) +ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 + +## Linker flags +LDFLAGS = $(COMMON) +LDFLAGS += -Wl,-Map=avrnet.map + + +## Intel Hex file production flags +HEX_FLASH_FLAGS = -R .eeprom + +HEX_EEPROM_FLAGS = -j .eeprom +HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" +HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings + + +## Objects that must be built in order to link +OBJECTS = enc28j60.o main.o http.o arp.o tcp.o ip.o ethernet.o icmp.o menu.o lcd.o adc.o udp.o + +## Objects explicitly added by the user +LINKONLYOBJECTS = + +## Build +all: $(TARGET) avrnet.hex avrnet.eep avrnet.lss size + +## Compile +enc28j60.o: ../enc28j60.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +main.o: ../main.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +http.o: ../http.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +arp.o: ../arp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +tcp.o: ../tcp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +ip.o: ../ip.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +ethernet.o: ../ethernet.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +icmp.o: ../icmp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +menu.o: ../menu.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +lcd.o: ../lcd.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +adc.o: ../adc.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +udp.o: ../udp.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +##Link +$(TARGET): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) + +%.hex: $(TARGET) + avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ + +%.eep: $(TARGET) + -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 + +%.lss: $(TARGET) + avr-objdump -h -S $< > $@ + +size: ${TARGET} + @echo + @avr-size -C --mcu=${MCU} ${TARGET} + +## Clean target +.PHONY: clean +clean: + -rm -rf $(OBJECTS) avrnet.elf dep/* avrnet.hex avrnet.eep avrnet.lss avrnet.map + + +## Other dependencies +-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) + Index: trunk/apps/reference/avr-webserver/menu.c =================================================================== --- trunk/apps/reference/avr-webserver/menu.c (nonexistent) +++ trunk/apps/reference/avr-webserver/menu.c (revision 46) @@ -0,0 +1,651 @@ +//******************************************************************************************** +// +// File : menu.c implement for User interface menu +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include "includes.h" +//******************************************************************************************* +// +// Global variable +// +//******************************************************************************************* +BYTE menu_index, submenu_index; +BYTE menu_stack, submenu_stack; +BYTE setting_cursor; +BYTE standby_cursor; +BYTE sec_count; +// max index for cursor setting +prog_uint8_t setting_cursor_max[3] = { 4, 4, 4 }; +// count down timer for send temp. H:M:S +prog_uint8_t count_time_max[4] = { 2, 60, 60, 24 }; +// countdown timer 4-bytes, [0]=en/dis, [1]=hour, [2]=min, [3]=sec +BYTE count_time[4]; +// count down time initial value stored in eeprom. Enable/Disable, Hour, Minute +BYTE ee_count_time[3] EEMEM = { 0, 0, 1 }; +prog_uint8_t str_enable[] = "Enable"; +prog_uint8_t str_disable[] = "Disable"; + +// menu and standby display string +PGM_P menu_list[5] = +{ + "Main menu", + "AVR IP config", + "Server IP config", + "Send temp config", + "Ping server" +}; + +PGM_P standby_list[4] = +{ + "AVR IP", + "Server IP", + "Send temp in", + "ADC0 & Temp" +}; + +//***************************************************************************************** +// +// Function : my_memcpy +// Description : copy string (end '\0') from program memory to ram and return pointer +// to end of string +// +//***************************************************************************************** +BYTE *my_strcpy ( BYTE *dest, PGM_P src ) +{ + BYTE ch; + + while ( (ch = pgm_read_byte( src++ )) ) + { + *dest++ = ch; + } + return dest; +} + +//***************************************************************************************** +// +// Function : print_decimal +// Description : Print decimal to buffer, up to 5 digits +// +//***************************************************************************************** +BYTE * print_decimal ( BYTE *ptr, BYTE digit, WORD dec ) +{ + if ( digit >= 5 ) + *ptr++ = ( (dec/10000) + '0' ); + if ( digit >= 4 ) + *ptr++ = ( ((dec%10000)/1000) + '0' ); + if ( digit >= 3 ) + *ptr++ = ( ((dec%1000)/100) + '0' ); + if ( digit >= 2 ) + *ptr++ = ( ((dec%100)/10) + '0' ); + *ptr++ = ( ((dec%10)) + '0' ); + + return ptr; +} +//***************************************************************************************** +// +// Function : print_temp +// Description : Print ADC0 and temparature to buffer +// +//***************************************************************************************** +void print_temp ( BYTE *dest ) +{ + WORD adc0_value; + BYTE temp_value; + + adc0_value = adc_read ( 0 ); + temp_value = adc_read_temp ( ); + + dest = print_decimal ( dest, 4, adc0_value ); + *dest++ = ','; + dest = print_decimal ( dest, 2, temp_value ); + *dest++ = ASCII_DEGREE; + *dest++ = 'C'; + *dest = '\0'; +} +//***************************************************************************************** +// +// Function : print_ip +// Description : Print ip address format to buffer e.g. 10.1.1.1 +// +//***************************************************************************************** +void print_ip ( BYTE *ptr, BYTE *ip, BYTE cursor ) +{ + BYTE i, digit, temp; + + for ( i=0; i<4; i++ ) + { + temp = ip [ i ]; + if ( temp > 99 ) + digit = 3; + else if ( temp > 9 ) + digit = 2; + else + digit = 1; + + if ( (i+1) == cursor ) + { + *ptr = ASCII_CURSOR; + ptr++; + } + else if ( i > 0 ) + { + *ptr = '.'; + ptr++; + } + ptr = print_decimal ( ptr, digit, temp ); + + } + *ptr = '\0'; +} +//***************************************************************************************** +// +// Function : print_time +// Description : Print time format to buffer e.g. 01:23:45 +// +//***************************************************************************************** +void print_time ( BYTE *ptr, BYTE *time, BYTE cursor ) +{ + BYTE i; + + // show setting cursor when enter to setting mode + if ( cursor == 0 ) + { + if ( time [ 0 ] ) + { + time++; + for ( i=0; i<3; i++ ) + { + if ( (i+2) == cursor ) + { + *ptr++ = ASCII_CURSOR; + } + else if ( i > 0 ) + { + *ptr++ = ':'; + } + ptr = print_decimal ( ptr, 2, *time++ ); + } + } + else + { + ptr = my_strcpy ( ptr, (PGM_P)str_disable ); + } + } + else + { + if ( cursor == 1 ) + { + *ptr++ = ASCII_CURSOR; + // show Enable/Disable send temparature to server + if ( time [ 0 ] ) + ptr = my_strcpy ( ptr, (PGM_P)str_enable ); + else + ptr = my_strcpy ( ptr, (PGM_P)str_disable ); + } + else + { + time++; + for ( i=0; i<3; i++ ) + { + if ( (i+2) == cursor ) + { + *ptr++ = ASCII_CURSOR; + } + else if ( i > 0 ) + { + *ptr++ = ':'; + } + ptr = print_decimal ( ptr, 2, *time++ ); + } + } + } + + *ptr = '\0'; +} +//***************************************************************************************** +// +// Function : time_base +// Description : count-down timer for send temparature to server. you can enable/disable and +// adjust timer by "Send temp config" menu. +// +//***************************************************************************************** +void time_base ( void ) +{ + static BYTE send_temp_timeout=0; + + if ( ++sec_count == 250 ) + { + sec_count = 0; + + // update lcd display + flag1.bits.update_display = 1; + + // timeout for send temparature to webserver + if ( flag1.bits.syn_is_sent ) + { + // 5 seconds + if ( ++send_temp_timeout == 5 ) + { + send_temp_timeout = 0; + flag1.bits.send_temp_timeout = 1; + } + } + // send temparature to server countdown + if ( count_time[ 0 ] && menu_index!=4 ) + { + if ( --count_time[ 3 ] > 59 ) + { + //count_time[ 3 ] = 59; + count_time[ 3 ] = 20; // debug + if ( --count_time[ 2 ] > 59 ) + { + count_time[ 2 ] = 59; + if ( --count_time[ 1 ] > 23 ) + { + // read hour + count_time[ 1 ] = eeprom_read_byte( ee_count_time + 1 ); + // read minute + count_time[ 2 ] = eeprom_read_byte( ee_count_time + 2 ); + // clear second + count_time[ 3 ] = 0; + flag1.bits.send_temp = 1; + } + } + } + } + } +} +//******************************************************************************************* +// +// Function : standby_display +// Description : display board status such as AVR ip, server ip, countdown time, temparature +// +//******************************************************************************************* +void standby_display ( void ) +{ + BYTE generic_buf[64]; + + // update lcd display flag not set, exit from function + if ( flag1.bits.update_display == 0 ) + return; + flag1.bits.update_display = 0; + // lcd display is displaying other information, wait until busy flag clear + if ( flag1.bits.lcd_busy ) + return; + // now displaying menu information, wait until exit from menu + if ( menu_index ) + return; + + // display status on lcd line 1 + lcd_putc ( '\f' ); + lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] ); + + // display status on lcd line 2 + lcd_putc ( '\n' ); + // display avr ip + if ( standby_cursor == 1 ) + { + print_ip ( generic_buf, (BYTE*)&avr_ip, 0 ); + } + // display server ip + else if ( standby_cursor == 2 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, 0 ); + } + // display countdown timer + else if ( standby_cursor == 3 ) + { + print_time ( generic_buf, count_time, 0 ); + } + // display current temparature + else if ( standby_cursor == 4 ) + { + print_temp ( generic_buf ); + } + lcd_print ( generic_buf ); +} +//******************************************************************************************* +// +// Function : display_menu +// Description : display LCD user interface menu on LCD +// +//******************************************************************************************* +void display_menu(void) +{ + BYTE generic_buf[64]; + + if( menu_index == 0) + return; + + // display menu title on lcd first line + lcd_putc( '\f' ); + lcd_print ( (BYTE *)menu_list[ menu_index - 1 ] ); + + // display menu detail on lcd second line + lcd_putc( '\n' ); + if( menu_index == 1 )//MENU_MAIN) + { + lcd_print( (BYTE *)menu_list[ submenu_index ] ); + } + // setup avr ip address + else if( menu_index == 2 ) + { + print_ip ( generic_buf, (BYTE*)&avr_ip, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // setup server ip address + else if(menu_index == 3 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // setup countdown timer for send temparature + else if ( menu_index == 4 ) + { + print_time ( generic_buf, count_time, setting_cursor+1 ); + lcd_print ( generic_buf ); + } + // ping server + else if ( menu_index == 5 ) + { + print_ip ( generic_buf, (BYTE*)&server_ip, 1 ); + lcd_print ( generic_buf ); + } + // send temparature now + //else if ( menu_index == 6 ) + //{ + // lcd_put ( ASCII_CURSOR ); + // lcd_print_p ( PSTR ( "OK" ) ); + //} +} +//******************************************************************************************* +// +// Function : key_up_process +// Description : +// +//******************************************************************************************* +void key_up_process ( void ) +{ + BYTE temp; + + // standby display, display board status + if(menu_index == 0) + { + if ( ++ standby_cursor == ((sizeof(standby_list)/2)+1) ) + standby_cursor = 1; + flag1.bits.update_display = 1; + } + // main menu + else if(menu_index == 1) + { + if( ++submenu_index == (sizeof(menu_list)/2) ) + { + submenu_index = 1; + } + } + // setup avr ip + else if( menu_index == 2 ) + { + avr_ip.byte [ setting_cursor ]++; + eeprom_write_block ( &avr_ip, ee_avr_ip, 4 ); + } + // setup server ip + else if( menu_index == 3 ) + { + server_ip.byte [ setting_cursor ]++; + eeprom_write_block ( &server_ip, ee_server_ip, 4 ); + } + // setup countdown timer + else if( menu_index == 4 ) + { + temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) ); + if ( ++count_time [ setting_cursor ] == temp ) + count_time [ setting_cursor ] = 0; + eeprom_write_block ( count_time, ee_count_time, 4 ); + } +} +//******************************************************************************************* +// +// Function : key_dw_process +// Description : +// +//******************************************************************************************* +void key_dw_process ( void ) +{ + BYTE temp; + + // standby display, display board status + if(menu_index == 0) + { + if ( -- standby_cursor == 0 ) + standby_cursor = sizeof(standby_list)/2; + flag1.bits.update_display = 1; + } + // main menu + else if(menu_index == 1) + { + if( --submenu_index == 0 ) + { + submenu_index = (sizeof(menu_list)/2)-1; + } + } + // setup avr ip + else if( menu_index == 2 ) + { + avr_ip.byte [ setting_cursor ]--; + eeprom_write_block ( &avr_ip, ee_avr_ip, 4 ); + } + // setup server ip + else if( menu_index == 3 ) + { + server_ip.byte [ setting_cursor ]--; + eeprom_write_block ( &server_ip, ee_server_ip, 4 ); + } + // setup countdown timer + else if( menu_index == 4 ) + { + temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) ); + if ( --count_time [ setting_cursor ] == 0xff ) + count_time [ setting_cursor ] = temp; + eeprom_write_block ( count_time, ee_count_time, 4 ); + } +} +//******************************************************************************************* +// +// Function : key_process +// Description : Process all key code from get_key_code function +// +//******************************************************************************************* +void menu_process ( void ) +{ + static BYTE key_hold_count=0, key_hold_step_delay=0; + BYTE rxtx_buffer[MAX_RXTX_BUFFER]; + BYTE key_code, temp; + static BYTE backlight_sec=31, backlight_seccount=250; + + // get switch value from port + key_code = SW_PIN & ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ); + + // Check key press? + if ( key_code == ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ) ) + { + flag1.bits.key_is_executed = 0; + flag2.bits.key_hold = 0; + key_hold_count = 0; + key_hold_step_delay = 0; + + // lcd backlight control + // lcd backlight off after key is unpress ( 30 seconds) + if ( backlight_sec ) + { + if ( --backlight_seccount > 250 ) + { + backlight_seccount = 250; + if ( --backlight_sec == 1 ) + { + backlight_sec = 0; + // lcd backlight off + LCD_BL_PORT &= ~_BV( LCD_BL_PIN ); + } + } + } + return; + } + + // lcd backlight on + // and hold-on 30 seconds + backlight_sec = 31; + LCD_BL_PORT |= _BV( LCD_BL_PIN ); + + // check hold key + if ( ++key_hold_count == 200 ) + { + key_hold_count = 0; + flag2.bits.key_hold = 1; + } + + if ( flag2.bits.key_hold ) + { + if ( ++key_hold_step_delay == 30 ) + { + key_hold_step_delay = 0; + if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) ) + { + key_up_process (); + } + // if down key is pressed + else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) ) + { + key_dw_process (); + } + display_menu(); + } + } + // key code already executed + if ( flag1.bits.key_is_executed ) + return; + // check key code, what is key pressed? + // if menu key is pressed + if ( key_code == ((~_BV ( SW_MENU ) ) & 0xf0) ) + { + // enter to main menu + if( menu_index == 0 ) + { + setting_cursor = 0; + menu_index = 1; + submenu_index = 1; + } + // enter to submenu + else if( menu_index == 1 ) + { + menu_stack = menu_index; + submenu_stack = submenu_index; + menu_index = submenu_index + menu_index; + submenu_index = 1; + } + // ping server + else if ( menu_index == 5 ) + { + // Show on lcd first line + lcd_putc( '\f' ); + lcd_print ( (BYTE *)menu_list[ 4 ] ); + lcd_putc( '\n' ); + if ( icmp_ping ( (BYTE*)rxtx_buffer, (BYTE*)&server_mac, (BYTE*)&server_ip ) ) + { + lcd_print_p ( PSTR ( "Ping OK." ) ); + } + else + { + lcd_print_p ( PSTR ( "Not found." ) ); + } + flag1.bits.lcd_busy = 1; + menu_index = 0; + submenu_index = 0; + flag1.bits.key_is_executed = 1; + return; + } + // change cursor setting on each menu + else + { + temp = pgm_read_byte ( (PGM_P)(setting_cursor_max + menu_index - 2) ); + + if ( ++setting_cursor == temp ) + setting_cursor = 0; + } + } + // if exit key is pressed + else if ( key_code == ((~_BV ( SW_EXIT ) ) & 0xf0) ) + { + setting_cursor = 0; + if(menu_index > 1) + { + menu_index = menu_stack; + submenu_index = submenu_stack; + } + else + { + menu_index = 0; + submenu_index = 0; + + } + } + // if up key is pressed + else if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) ) + { + key_up_process (); + } + // if down key is pressed + else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) ) + { + key_dw_process (); + } + // display menu information on LCD + display_menu(); + flag1.bits.key_is_executed = 1; + flag1.bits.lcd_busy = 0; +} +//******************************************************************************************* +// +// Function : menu_init +// Description : initial I/O direction for all key, +// initial timer1 for countdown timer +// +//******************************************************************************************* +void menu_init ( void ) +{ + // setup countdown initial value + sec_count = 0; + eeprom_read_block ( count_time, ee_count_time, 3 ); + count_time[3] = 0; + + // setup menu and standby display + flag1.byte = 0; + flag2.byte = 0; + menu_index = 0; + submenu_index = 0; + menu_stack = 0; + submenu_stack = 0; + setting_cursor = 0; + standby_cursor = 1; +} Index: trunk/apps/reference/avr-webserver/avrnet.aws =================================================================== --- trunk/apps/reference/avr-webserver/avrnet.aws (nonexistent) +++ trunk/apps/reference/avr-webserver/avrnet.aws (revision 46) @@ -0,0 +1 @@ +
+ÎÒÃì´áÇÃìãªéÎÒÃì´áÇÃìà´ÔÁ¨Ò¡ V0.9
+ÁÕÍÐäÃãËÁèã¹ V1.0?
+- à¾ÔèÁâ»ÃⵤÍÅ UDP (User Datagram Protocol)
+- ÁÕâ»Ãá¡ÃÁ AVRnet CPannel ÊÓËÃѺãªéµÔ´µèͺÍÃì´ AVRnet ¼èÒ¹â»ÃⵤÍÅ UDP â»Ãá¡ÃÁ AVRnet CPannel à¢Õ¹¢Öé¹ÁÒâ´Âãªé CodeBlocks C++ IDE ÃèÇÁ¡Ñº wxWidgets GUI tool kits áÅÐãªé MinGW GCC compiler
+ +ÊÓËÃѺÇÔ¸Õ¡ÒõԴµÑé§ CodeBlocks, wxWidgets, MinGW ÊÒÁÒö´Ùà¾ÔèÁàµÔÁ¨Ò¡ËÑÇ¢éÍ ¡ÒõԴµÑé§ CodeBlocks free C++ IDE, wxWidgets, MinGW
+
+ +
![](AVRnetCPannel.gif)
+
+´ÒǹìâËÅ´
+AVRnet V1.0 source code
+AVRnet CPannel source code
+AVRnet CPannel binary
+ +
+
+AVRnet V0.9 by avrportal.com
+
+AVRnet Firmware Version 0.9
+
+ AVRnet à»ç¹ºÍÃì´ÊÓËÃѺ¾Ñ²¹ÒáÅÐÈÖ¡ÉÒ¡ÒÃãªéäÁâ¤Ã¤Í¹â·ÃÅàÅÍÃì 㹡ÒÃàª×èÍÁµè͡Ѻ Ethernet protocol +ãªéäÁâ¤Ã¤Í¹â·ÃÅàÅÍÃìµÃСÙÅ AVR ATMEGA32 à»ç¹µÑǤǺ¤ØÁËÅÑ¡ ãªé ENC28J60 à»ç¹ Ethernet controller +áÅÐÂѧÁÕ LCD ÊÓËÃѺµÔ´µè͡Ѻ¼Ùéãªé§Ò¹ ÊÓËÃѺ¡ÒõÑ駤èÒáÅÐáÊ´§Ê¶Ò¹ÐµèÒ§æ¢Í§ºÍÃì´
+ àÃÒÊÒÁÒö¹ÓºÍÃì´ AVRnet ä»ÊÃéÒ§à»ç¹ web-server ¢¹Ò´àÅç¡ÊÓËÃѺ¤Çº¤ØÁÍØ»¡Ã³ì,à¤Ã×èͧãªéä¿¿éÒ¼èÒ¹·Ò§ Internet ËÃ×ÍÃкº LAN +ã¹ firmware v0.9 ¹ÕéÂѧÁÕ¡ÒùӺÍÃì´ AVRnet ä»·Óà»ç¹ web-client ÊÓËÃѺ¡ÒÃÊ觤èÒÍسËÀÙÁÔº¹ºÍÃì´ä»à¡çºäÇé·Õè web-server +â´Âãªé protocol http (ÊÒÁÒö¹Óä»ãªéà»ç¹ web data loger) â´Âã¹ firmware v0.9 ¨Ð»Ô´¡ÒÃãªé§Ò¹ web-client äÇéà»ç¹¤èÒàÃÔèÁµé¹ +áµè¤Ø³ÊÒÁÒöà»Ô´¡ÒÃãªé§Ò¹ web-client ä´é·ÕèàÁ¹Ù Send temp config áµèà¤Ã×èͧ¤ÍÁ¾ÔÇàµÍÃì¢Í§¤Ø³¨ÐµéͧµÔ´µÑé§ web-server áÅÐ server script ¡è͹ +ÊÓËÃѺ¡ÒõԴµÑé§ web-server áÅÐ server script ÊÒÁÒöà¢éÒä»´Ùä´é·Õè http://www.avrportal.com
+
+
+
+Hardware feature
+
+- MCU : ATMEGA32 @ 16MHz
+- Ethernet controller : ENC28J60
+- RJ11 for LAN
+- LCD user interface menu
+- JTAG interface for program and debug
+- Temparature sensor using thermistor
+- 1 potentiometer for ADC0
+- I2C connector with pull-up resistor
+- Built-in Voltage regulator
+- LEDs display and switchs for LCD menu
+
+
+Firmware feature
+
+- Firmware is GPL using AVR GCC compiler
+- LCD user interface menu and borad status
+- Webserver listen on port 80 ( example page "webpage.htm" )
+- Webclient listen on port 1200 ( use for send temparature to webserver.)
+
+
+LCD user interface menu
+AVRnet ÁÕÊÇÔµ«ì·ÕèãªéÊÓËÃѺ LCD àÁ¹Ù ´Ñ§¹Õé Menu, Exit, Up, Dw ¡ÒõÑ駤èÒµèÒ§ÊÒÁÒö·Óä´éâ´Âà¢éÒä»·ÕèàÁ¹Ù¡ÒõÑ駤èҢͧáµèÅÐàÁ¹Ù.
+ÃÒÂÅÐàÍÕ´¢Í§áµèÅÐàÁ¹ÙÁմѧ¹Õé.
+
+Main menu
+
-
+
- AVR IP config (setup AVRnet IP address) +
- Server IP config (setup AVRnet IP address) +
- Send temp config (setup countdown timer for send temparature to webserver) +
- Ping server (check server status) +
+standby display mode
+
-
+
- AVR IP(show current AVR IP address) +
- Server IP (show current server IP address) +
- Send temp in (show countdown timer for send temp) +
- ADC0 & Temp (show current ADC0 and temparature) +
+ + \ No newline at end of file Index: trunk/apps/reference/avr-webserver/includes.h =================================================================== --- trunk/apps/reference/avr-webserver/includes.h (nonexistent) +++ trunk/apps/reference/avr-webserver/includes.h (revision 46) @@ -0,0 +1,82 @@ +//******************************************************************************************** +// +// File : include.h includes all header file for AVRethernet development board. +// +//******************************************************************************************** +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// This program is distributed in the hope that it will be useful, but +// +// WITHOUT ANY WARRANTY; +// +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110, USA +// +// http://www.gnu.de/gpl-ger.html +// +//******************************************************************************************** +#include
trunk/apps/reference/avr-webserver/AVRnetCPannel.gif
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/apps/reference/avr-webserver/main.c
===================================================================
--- trunk/apps/reference/avr-webserver/main.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/main.c (revision 46)
@@ -0,0 +1,360 @@
+//********************************************************************************************
+//
+// AVRnet firmware Version 1.0
+//
+// MCU : ATMEGA32 @ 16MHz
+// Ethernet controller : ENC28J60
+// IDE & Compiler : AVR Studio version 4.13.528 & WINAVR version 20070122
+// Author : Jirawat Kongkaen
+// Website : http://www.avrportal.com/
+//
+//********************************************************************************************
+//
+// File : main.c main program for AVRnet development board.
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+
+// Global variables
+MAC_ADDR avr_mac;
+IP_ADDR avr_ip;
+
+MAC_ADDR server_mac;
+IP_ADDR server_ip;
+
+//BYTE generic_buf[128];
+
+// Change your avr and server ip address here
+// avr and server ip address are stored in eeprom
+BYTE ee_avr_ip[4] EEMEM = { 10, 1, 1, 1 };
+BYTE ee_server_ip[4] EEMEM = { 10, 1, 1, 76 };
+//*****************************************************************************************
+//
+// Function : server_process
+// Description : Run web server and listen on port 80
+//
+//*****************************************************************************************
+void server_process ( void )
+{
+ MAC_ADDR client_mac;
+ IP_ADDR client_ip;
+ // you can change rx,tx buffer size in includes.h
+ BYTE rxtx_buffer[MAX_RXTX_BUFFER];
+ WORD plen;
+
+ if ( flag1.bits.syn_is_sent )
+ return;
+ // get new packet
+ plen = enc28j60_packet_receive( (BYTE*)&rxtx_buffer, MAX_RXTX_BUFFER );
+
+ //plen will ne unequal to zero if there is a valid packet (without crc error)
+ if(plen==0)
+ return;
+
+ // copy client mac address from buffer to client mac variable
+ memcpy ( (BYTE*)&client_mac, &rxtx_buffer[ ETH_SRC_MAC_P ], sizeof(MAC_ADDR) );
+
+ // check arp packet if match with avr ip let's send reply
+ if ( arp_packet_is_arp( rxtx_buffer, (WORD_BYTES){ARP_OPCODE_REQUEST_V} ) )
+ {
+ arp_send_reply ( (BYTE*)&rxtx_buffer, (BYTE*)&client_mac );
+ return;
+ }
+
+ // get client ip address
+ memcpy ( (BYTE*)&client_ip, &rxtx_buffer[ IP_SRC_IP_P ], sizeof(IP_ADDR) );
+ // check ip packet send to avr or not?
+ if ( ip_packet_is_ip ( (BYTE*)&rxtx_buffer ) == 0 )
+ {
+ return;
+ }
+
+ // check ICMP packet, if packet is icmp packet let's send icmp echo reply
+ if ( icmp_send_reply ( (BYTE*)&rxtx_buffer, (BYTE*)&client_mac, (BYTE*)&client_ip ) )
+ {
+ return;
+ }
+
+ // check UDP packet
+ if (udp_receive ( (BYTE *)&rxtx_buffer, (BYTE *)&client_mac, (BYTE *)&client_ip ))
+ {
+ return;
+ }
+
+ // tcp start here
+ // start web server at port 80, see http.c
+ http_webserver_process ( (BYTE*)rxtx_buffer, (BYTE*)&client_mac, (BYTE*)&client_ip );
+}
+//*****************************************************************************************
+//
+// Function : client_process
+// Description : send temparature to web server, this option is disabled by default.
+// YOU MUST install webserver and server script before enable this option,
+// I recommented Apache webserver and PHP script.
+// More detail about Apache and PHP installation please visit http://www.avrportal.com/
+//
+//*****************************************************************************************
+void client_process ( void )
+{
+ WORD dlength;
+ // you can change rx,tx buffer size in includes.h
+ BYTE rxtx_buffer[MAX_RXTX_BUFFER];
+
+ // wait for send temparature flag is set, this flag set by time_base function (menu.c)
+ if ( flag1.bits.send_temp == 0 )
+ return;
+ // AVR busy now and wait untill transfer data to web browser completed.
+ if ( flag1.bits.syn_is_received )
+ return;
+ // AVR sent temparature to web server but not found web server on port 80
+ //if ( flag1.bits.not_found_server )
+ // return;
+ // send SYN to initial connection
+ if ( flag1.bits.syn_is_sent == 0 )
+ {
+ // start arp
+ // server ip was not found on network
+ if ( arp_who_is ( rxtx_buffer, (BYTE*)&server_mac, (BYTE*)&server_ip ) == 0 )
+ {
+ flag1.bits.send_temp = 0;
+ return;
+ }
+
+ // send SYN packet to initial connection
+ tcp_send_packet (
+ rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_SYN_V, // flag
+ 1, // (bool)maximum segment size
+ 1, // (bool)clear sequence ack number
+ 0, // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data
+ 0, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ flag1.bits.syn_is_sent = 1;
+ }
+ // get new packet
+ dlength = enc28j60_packet_receive( (BYTE*)&rxtx_buffer, MAX_RXTX_BUFFER );
+
+ // no new packet incoming
+ if ( dlength == 0 )
+ {
+ // timeout occured, when SYN has been sent but no response from web server
+ // reset send_temp and syn_is_sent flags
+ if ( flag1.bits.send_temp_timeout )
+ {
+ flag1.bits.send_temp_timeout = 0;
+ flag1.bits.send_temp = 0;
+ flag1.bits.syn_is_sent = 0;
+ }
+ return;
+ }
+
+ // check ip packet send to avr or not?
+ // accept ip packet only
+ if ( ip_packet_is_ip ( (BYTE*)&rxtx_buffer ) == 0 )
+ {
+ return;
+ }
+
+ // check SYNACK flag, after AVR send SYN server response by send SYNACK to AVR
+ if ( rxtx_buffer [ TCP_FLAGS_P ] == ( TCP_FLAG_SYN_V | TCP_FLAG_ACK_V ) )
+ {
+ // send ACK to answer SYNACK
+ tcp_send_packet (
+ (BYTE*)&rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_ACK_V, // flag
+ 0, // (bool)maximum segment size
+ 0, // (bool)clear sequence ack number
+ 1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
+ 0, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ // setup http request to server
+ dlength = http_put_request( (BYTE*)&rxtx_buffer );
+ // send http request packet
+ // send packet with PSHACK
+ tcp_send_packet (
+ (BYTE*)&rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_ACK_V | TCP_FLAG_PSH_V, // flag
+ 0, // (bool)maximum segment size
+ 0, // (bool)clear sequence ack number
+ 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
+ dlength, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ return;
+ }
+ // after AVR send http request to server, server response by send data with PSHACK to AVR
+ // AVR answer by send ACK and FINACK to server
+ if ( rxtx_buffer [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PSH_V) )
+ {
+ dlength = tcp_get_dlength( (BYTE*)&rxtx_buffer );
+
+ // send ACK to answer PSHACK from server
+ tcp_send_packet (
+ (BYTE*)&rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_ACK_V, // flag
+ 0, // (bool)maximum segment size
+ 0, // (bool)clear sequence ack number
+ dlength, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
+ 0, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ // send finack to disconnect from web server
+
+ tcp_send_packet (
+ (BYTE*)&rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_FIN_V|TCP_FLAG_ACK_V, // flag
+ 0, // (bool)maximum segment size
+ 0, // (bool)clear sequence ack number
+ 0, // (bool)calculate new seq and seqack number
+ 0, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ return;
+ //menu_flag.bits.send_temp = 0;
+ //send_syn = 0;
+ }
+ // answer FINACK from web server by send ACK to web server
+ if ( rxtx_buffer [ TCP_FLAGS_P ] == (TCP_FLAG_FIN_V|TCP_FLAG_ACK_V) )
+ {
+ // send ACK with seqack = 1
+ tcp_send_packet (
+ (BYTE*)&rxtx_buffer,
+ (WORD_BYTES){80}, // destination port
+ (WORD_BYTES){1200}, // source port
+ TCP_FLAG_ACK_V, // flag
+ 0, // (bool)maximum segment size
+ 0, // (bool)clear sequence ack number
+ 1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data
+ 0, // tcp data length
+ (BYTE*)&server_mac, // server mac address
+ (BYTE*)&server_ip ); // server ip address
+ // temparature has been sent
+ // and wait for next schedule to send temparature
+ flag1.bits.send_temp = 0;
+ flag1.bits.syn_is_sent = 0;
+ }
+}
+//*****************************************************************************************
+//
+// Function : main
+// Description : main program,
+//
+//*****************************************************************************************
+void lcd_backlight( void )
+{
+
+
+
+}
+//*****************************************************************************************
+//
+// Function : main
+// Description : main program,
+//
+//*****************************************************************************************
+int main (void)
+{
+ // change your mac address here
+ avr_mac.byte[0] = 'A';
+ avr_mac.byte[1] = 'V';
+ avr_mac.byte[2] = 'R';
+ avr_mac.byte[3] = 'P';
+ avr_mac.byte[4] = 'O';
+ avr_mac.byte[5] = 'R';
+
+ // read avr and server ip from eeprom
+ eeprom_read_block ( &avr_ip, ee_avr_ip, 4 );
+ eeprom_read_block ( &server_ip, ee_server_ip, 4 );
+
+ // setup port as input and enable pull-up
+ SW_DDR &= ~ ( _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW ) );
+ SW_PORT |= _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW );
+ SFIOR &= ~_BV( PUD );
+
+ // setup lcd backlight as output
+ LCD_BL_DDR |= _BV( LCD_BL_PIN );
+ // lcd backlight on
+ LCD_BL_PORT |= _BV( LCD_BL_PIN );
+
+ // setup clock for timer1
+ TCCR1B = 0x01; // clk/1 no prescaling
+
+ // initial adc, lcd, and menu
+ adc_init();
+ lcd_init ();
+ menu_init ();
+
+ // set LED1, LED2 as output */
+ LED_DDR |= _BV( LED_PIN1_DDR ) | _BV( LED_PIN2_DDR );
+ // set LED pin to "1" ( LED1,LED2 off)
+ LED_PORT |= _BV( LED_PIN1 ) | _BV( LED_PIN2 );
+
+ // initial enc28j60
+ enc28j60_init( (BYTE*)&avr_mac );
+
+ // loop forever
+ for(;;)
+ {
+ // wait until timer1 overflow
+ while ( (TIFR & _BV ( TOV1 )) == 0 );
+ TIFR |= _BV(TOV1);
+ TCNT1 = 1536; // Timer1 overflow every 1/16MHz * ( 65536 - 1536 ) = 4ms, 250Hz
+
+ // general time base, generate by timer1
+ // overflow every 1/250 seconds
+ time_base ();
+
+ // read temparature
+ adc_read_temp();
+
+ // server process response for arp, icmp, http
+ server_process ();
+
+ // send temparature to web server unsing http protocol
+ // disable by default.
+ client_process ();
+
+ // lcd user interface menu
+ // setup IP address, countdown timer
+ menu_process ();
+
+ // display AVR ethernet status
+ // temparature, AVR ip, server ip, countdown time
+ standby_display ();
+ }
+
+ return 0;
+}
Index: trunk/apps/reference/avr-webserver/avrnet.pnproj
===================================================================
--- trunk/apps/reference/avr-webserver/avrnet.pnproj (nonexistent)
+++ trunk/apps/reference/avr-webserver/avrnet.pnproj (revision 46)
@@ -0,0 +1 @@
+
\ No newline at end of file
Index: trunk/apps/reference/avr-webserver/tcp.c
===================================================================
--- trunk/apps/reference/avr-webserver/tcp.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/tcp.c (revision 46)
@@ -0,0 +1,246 @@
+//********************************************************************************************
+//
+// File : tcp.c implement for Transmission Control Protocol
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+//********************************************************************************************
+//
+// +------------+-----------+------------+----------+
+// + MAC header + IP header + TCP header + Data ::: +
+// +------------+-----------+------------+----------+
+//
+// TCP Header
+//
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Source Port + Destination Port +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Sequence Number +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Acknowledgment Number +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// +Data Offset+reserved+ ECN + Control Bits + Window size +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Checksum + Urgent Pointer +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Options and padding ::: +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+// + Data ::: +
+// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+//
+//********************************************************************************************
+
+// global variables ***********************************************************************
+static BYTE seqnum=0xa; // my initial tcp sequence number
+//static DWORD_BYTES tcp_sequence_number;
+
+//*****************************************************************************************
+//
+// Function : tcp_get_dlength
+// Description : claculate tcp received data length
+//
+//*****************************************************************************************
+WORD tcp_get_dlength ( BYTE *rxtx_buffer )
+{
+ int dlength, hlength;
+
+ dlength = ( rxtx_buffer[ IP_TOTLEN_H_P ] <<8 ) | ( rxtx_buffer[ IP_TOTLEN_L_P ] );
+ dlength -= sizeof(IP_HEADER);
+ hlength = (rxtx_buffer[ TCP_HEADER_LEN_P ]>>4) * 4; // generate len in bytes;
+ dlength -= hlength;
+ if ( dlength <= 0 )
+ dlength=0;
+
+ return ((WORD)dlength);
+}
+//*****************************************************************************************
+//
+// Function : tcp_get_hlength
+// Description : claculate tcp received header length
+//
+//*****************************************************************************************
+BYTE tcp_get_hlength ( BYTE *rxtx_buffer )
+{
+ return ((rxtx_buffer[ TCP_HEADER_LEN_P ]>>4) * 4); // generate len in bytes;
+}
+//********************************************************************************************
+//
+// Function : tcp_puts_data_p
+// Description : puts data from program memory to tx buffer
+//
+//********************************************************************************************
+WORD tcp_puts_data_p ( BYTE *rxtx_buffer, PGM_P data, WORD offset )
+{
+ BYTE ch;
+
+ while( (ch = pgm_read_byte(data++)) )
+ {
+ rxtx_buffer[ TCP_DATA_P + offset ] = ch;
+ offset++;
+ }
+
+ return offset;
+}
+//********************************************************************************************
+//
+// Function : tcp_puts_data
+// Description : puts data from RAM to tx buffer
+//
+//********************************************************************************************
+WORD tcp_puts_data ( BYTE *rxtx_buffer, BYTE *data, WORD offset )
+{
+ while( *data )
+ {
+ rxtx_buffer[ TCP_DATA_P + offset ] = *data++;
+ offset++;
+ }
+
+ return offset;
+}
+//********************************************************************************************
+//
+// Function : tcp_send_packet
+// Description : send tcp packet to network.
+//
+//********************************************************************************************
+void tcp_send_packet (
+ BYTE *rxtx_buffer,
+ WORD_BYTES dest_port,
+ WORD_BYTES src_port,
+ BYTE flags,
+ BYTE max_segment_size,
+ BYTE clear_seqack,
+ WORD next_ack_num,
+ WORD dlength,
+ BYTE *dest_mac,
+ BYTE *dest_ip )
+{
+ BYTE i, tseq;
+ WORD_BYTES ck;
+
+ // generate ethernet header
+ eth_generate_header ( rxtx_buffer, (WORD_BYTES){ETH_TYPE_IP_V}, dest_mac );
+
+ // sequence numbers:
+ // add the rel ack num to SEQACK
+ if ( next_ack_num )
+ {
+ for( i=4; i>0; i-- )
+ {
+ next_ack_num = rxtx_buffer [ TCP_SEQ_P + i - 1] + next_ack_num;
+ tseq = rxtx_buffer [ TCP_SEQACK_P + i - 1];
+ rxtx_buffer [ TCP_SEQACK_P + i - 1] = 0xff & next_ack_num;
+
+ // copy the acknum sent to us into the sequence number
+ rxtx_buffer[ TCP_SEQ_P + i - 1 ] = tseq;
+
+ next_ack_num >>= 8;
+ }
+ }
+
+ // initial tcp sequence number
+ // setup maximum segment size
+ // require to setup first packet is receive or transmit only
+ if ( max_segment_size )
+ {
+ // initial sequence number
+ rxtx_buffer[ TCP_SEQ_P + 0 ] = 0;
+ rxtx_buffer[ TCP_SEQ_P + 1 ] = 0;
+ rxtx_buffer[ TCP_SEQ_P + 2 ] = seqnum;
+ rxtx_buffer[ TCP_SEQ_P + 3 ] = 0;
+ seqnum += 2;
+
+ // setup maximum segment size
+ rxtx_buffer[ TCP_OPTIONS_P + 0 ] = 2;
+ rxtx_buffer[ TCP_OPTIONS_P + 1 ] = 4;
+ rxtx_buffer[ TCP_OPTIONS_P + 2 ] = HIGH(1408);
+ rxtx_buffer[ TCP_OPTIONS_P + 3 ] = LOW(1408);
+ // setup tcp header length 24 bytes: 6*32/8 = 24
+ rxtx_buffer[ TCP_HEADER_LEN_P ] = 0x60;
+ dlength += 4;
+ }
+ else
+ {
+ // no options: 20 bytes: 5*32/8 = 20
+ rxtx_buffer[ TCP_HEADER_LEN_P ] = 0x50;
+ }
+
+ // generate ip header and checksum
+ ip_generate_header ( rxtx_buffer, (WORD_BYTES){(sizeof(IP_HEADER) + sizeof(TCP_HEADER) + dlength)}, IP_PROTO_TCP_V, dest_ip );
+
+ // clear sequence ack number before send tcp SYN packet
+ if ( clear_seqack )
+ {
+ rxtx_buffer[ TCP_SEQACK_P + 0 ] = 0;
+ rxtx_buffer[ TCP_SEQACK_P + 1 ] = 0;
+ rxtx_buffer[ TCP_SEQACK_P + 2 ] = 0;
+ rxtx_buffer[ TCP_SEQACK_P + 3 ] = 0;
+ }
+
+ // setup tcp flags
+ rxtx_buffer [ TCP_FLAGS_P ] = flags;
+
+ // setup destination port
+ rxtx_buffer [ TCP_DST_PORT_H_P ] = dest_port.byte.high;
+ rxtx_buffer [ TCP_DST_PORT_L_P ] = dest_port.byte.low;
+
+ // setup source port
+ rxtx_buffer [ TCP_SRC_PORT_H_P ] = src_port.byte.high;
+ rxtx_buffer [ TCP_SRC_PORT_L_P ] = src_port.byte.low;
+
+ // setup maximum windows size
+ rxtx_buffer [ TCP_WINDOWSIZE_H_P ] = HIGH((MAX_RX_BUFFER-sizeof(IP_HEADER)-sizeof(ETH_HEADER)));
+ rxtx_buffer [ TCP_WINDOWSIZE_L_P ] = LOW((MAX_RX_BUFFER-sizeof(IP_HEADER)-sizeof(ETH_HEADER)));
+
+ // setup urgend pointer (not used -> 0)
+ rxtx_buffer[ TCP_URGENT_PTR_H_P ] = 0;
+ rxtx_buffer[ TCP_URGENT_PTR_L_P ] = 0;
+
+ // clear old checksum and calculate new checksum
+ rxtx_buffer[ TCP_CHECKSUM_H_P ] = 0;
+ rxtx_buffer[ TCP_CHECKSUM_L_P ] = 0;
+ // This is computed as the 16-bit one's complement of the one's complement
+ // sum of a pseudo header of information from the
+ // IP header, the TCP header, and the data, padded
+ // as needed with zero bytes at the end to make a multiple of two bytes.
+ // The pseudo header contains the following fields:
+ //
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // +00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // + Source IP address +
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // + Destination IP address +
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // + 0 + IP Protocol + Total length +
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ ck.word = software_checksum( &rxtx_buffer[IP_SRC_IP_P], sizeof(TCP_HEADER)+dlength+8, IP_PROTO_TCP_V + sizeof(TCP_HEADER) + dlength );
+ rxtx_buffer[ TCP_CHECKSUM_H_P ] = ck.byte.high;
+ rxtx_buffer[ TCP_CHECKSUM_L_P ] = ck.byte.low;
+
+ // send packet to ethernet media
+ enc28j60_packet_send ( rxtx_buffer, sizeof(ETH_HEADER)+sizeof(IP_HEADER)+sizeof(TCP_HEADER)+dlength );
+}
Index: trunk/apps/reference/avr-webserver/adc.c
===================================================================
--- trunk/apps/reference/avr-webserver/adc.c (nonexistent)
+++ trunk/apps/reference/avr-webserver/adc.c (revision 46)
@@ -0,0 +1,143 @@
+//********************************************************************************************
+//
+// File : adc.c implement for on-board temparature sensor and ADC0
+//
+//********************************************************************************************
+//
+// Copyright (C) 2007
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+// This program is distributed in the hope that it will be useful, but
+//
+// WITHOUT ANY WARRANTY;
+//
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110, USA
+//
+// http://www.gnu.de/gpl-ger.html
+//
+//********************************************************************************************
+#include "includes.h"
+// Thermistor resistance and ADC calculation.
+//
+// Rntc = R0 * exp B(1/T - 1/T0)
+//
+// R0 : Zero resistance @ 25 degree celsius.
+// B : constant value (see datasheet)
+// T0 : Zero temparature in Kevin
+//
+// constant from TTC05's datasheet : R0 = 10kOhm, B = 4050K, T0 = 25+273.15
+//
+// Rntc
+// Vref o-----/\/\/-------
+// |------o Vout
+// 0V o-----/\/\/-------
+// Rout
+// Rout = 10k
+// Vout = (2.56 * 10000.0) / (10000.0 + Rntc)
+// ADC = (Vout / 2.56) * 1024.0
+//
+// 2.56 is Internal Vref
+//
+// below table are ADC values, calculate from T=0 to T=99
+prog_uint16_t temp_list[100] =
+{
+229, 239, 249, 259, 270, 280, 291, 302, 313, 324,
+335, 347, 358, 370, 382, 394, 405, 417, 429, 441,
+453, 465, 477, 489, 500, 512, 524, 535, 547, 558,
+569, 580, 591, 602, 613, 623, 633, 644, 654, 663,
+673, 682, 692, 701, 710, 718, 727, 735, 743, 751,
+759, 766, 774, 781, 788, 795, 801, 808, 814, 820,
+826, 832, 837, 843, 848, 853, 858, 863, 867, 872,
+876, 881, 885, 889, 893, 897, 900, 904, 907, 911,
+914, 917, 920, 923, 926, 929, 931, 934, 936, 939,
+941, 944, 946, 948, 950, 952, 954, 956, 958, 960,
+};
+//********************************************************************************************
+//
+// Function : adc_read
+// Description : read ADC value, select ADC channel to read by channel argument
+//
+//********************************************************************************************
+WORD adc_read ( BYTE channel )
+{
+ // Analog channel selection
+ ADMUX = ((ADMUX) & ~0x1f) | (channel & 0x1f);
+
+ // Start conversion
+ ADCSRA |= _BV(ADSC);
+
+ // Wait until conversion complete
+ while( bit_is_set(ADCSRA, ADSC) );
+
+ // CAUTION: READ ADCL BEFORE ADCH!!!
+ return ((ADCL) | ((ADCH)<<8));
+}
+//********************************************************************************************
+//
+// Function : adc_init
+// Description : Initial analog to digital convertion
+//
+//********************************************************************************************
+//void adc_init ( void ) __attribute__ ((naked));
+void adc_init ( void )
+{
+ //BYTE i;
+
+ // ADC enable, Prescaler divide by 128, ADC clock = 16MHz/128 = 125kHz
+ ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
+
+ // Select Vref, internal Vref 2.56V and external capacitor
+ ADMUX = _BV(REFS1) | _BV(REFS0);
+
+ // reading temparature
+ //for ( i=0; i<32; i++ )
+ // adc_read_temp ();
+}
+//********************************************************************************************
+//
+// Function : adc_read_temp
+// Description : read temparature from ADC1 and convert to real temparature
+//
+//********************************************************************************************
+BYTE adc_read_temp ( void )
+{
+ static WORD temp_buf[ ADC_TEMP_BUFFER ];
+ static BYTE buf_index=0;
+ WORD result=0,data;
+ BYTE loop;
+
+ // Store each sample to buffer
+ temp_buf[ buf_index ] = adc_read ( ADC_TEMP_CHANNEL );
+
+ // Low pass filter 8 samples by default.
+ for ( loop=0; loopAVRnet V0.9 by AVRportal.com AVRnet V0.9 by AVRportal.com
LED 1 : OFF [ ON ], LED 2 : OFF [ ON ]
ACD0 = 0516
Temparature = 29°C
Refresh
LED 1 : OFF [ ON ], LED 2 : OFF [ ON ]
ACD0 = 0516
Temparature = 29°C
Refresh