Skip to content

Commit

Permalink
SVN move
Browse files Browse the repository at this point in the history
Revision: 3
Author: ulrich
Date: 13:26:05, Donnerstag, 25. August 2011
Message:
angepasst auf mikrowebserver
  • Loading branch information
uescher committed Sep 26, 2011
1 parent 0130cb2 commit 3d0f1aa
Show file tree
Hide file tree
Showing 11 changed files with 1,892 additions and 47 deletions.
1,763 changes: 1,763 additions & 0 deletions ethernet-light-control/Hexfiles/Webserver_.hex

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions ethernet-light-control/config.h
Expand Up @@ -48,22 +48,23 @@
#define IP(a,b,c,d) ((unsigned long)(d)<<24)+((unsigned long)(c)<<16)+((unsigned long)(b)<<8)+a

//IP des Webservers und des Routers
#define MYIP IP(192,168,0,99)
//#define MYIP IP(192,168,0,99)
#define MYIP IP(10,42,23,99)
#define ROUTER_IP IP(192,168,0,1)

//Netzwerkmaske
#define NETMASK IP(255,255,255,0)

//DHCP-Server
#define USE_DHCP 0 //1 = DHCP Client on
//DHCP-Server
#define USE_DHCP 1 //1 = DHCP Client on

//DNS-Server
#define USE_DNS 0 //1 = DNS Client on
#define DNS_IP IP(192,168,0,1)


//IP des NTP-Servers z.B. Server 1.de.pool.ntp.org
#define USE_NTP 1 //1 = NTP Client on
#define USE_NTP 0 //1 = NTP Client on
#define NTP_IP IP(77,37,6,59)

//Broadcast-Adresse für WOL
Expand All @@ -73,15 +74,15 @@

//MAC Adresse des Webservers
#define MYMAC1 0x00
#define MYMAC2 0x20
#define MYMAC3 0x18
#define MYMAC4 0xB1
#define MYMAC5 0x15
#define MYMAC6 0x6F
#define MYMAC2 0x22
#define MYMAC3 0xF9
#define MYMAC4 0x01
#define MYMAC5 0x38
#define MYMAC6 0xc8

//Taktfrequenz
//#define F_CPU 20000000UL
#define F_CPU 16000000UL
#define F_CPU 8000000UL
//#define F_CPU 14745600UL
//#define F_CPU 11059200UL

Expand Down
6 changes: 3 additions & 3 deletions ethernet-light-control/httpd.c
Expand Up @@ -265,7 +265,7 @@ void httpd_header_check (unsigned char index)
if(*http_entry[index].post_ready_ptr == 0)
{
http_entry[index].post = 0;
PORTA = PORT_tmp;
//PORTA = PORT_tmp;
PORT_tmp = 0;
break;
//Submit gefunden
Expand Down Expand Up @@ -506,7 +506,7 @@ void httpd_data_send (unsigned char index)
switch(pgm_read_byte(http_entry[index].new_page_pointer+4))
{
case 'A':
b = (PORTA & (1<<pin));
//b = (PORTA & (1<<pin));
break;
case 'B':
b = (PORTB & (1<<pin));
Expand Down Expand Up @@ -542,7 +542,7 @@ void httpd_data_send (unsigned char index)
switch(pgm_read_byte(http_entry[index].new_page_pointer+3))
{
case 'A':
b = (PINA & (1<<pin));
//b = (PINA & (1<<pin));
break;
case 'B':
b = (PINB & (1<<pin));
Expand Down
30 changes: 19 additions & 11 deletions ethernet-light-control/main.c
Expand Up @@ -43,7 +43,7 @@
#include "camera/servo.h"
#include "sendmail.h"
#include <avr/eeprom.h>

#include <util/delay.h>
#include "dhcpc.h"
#include "dnsc.h"

Expand All @@ -53,12 +53,11 @@ int main(void)
{
//Konfiguration der Ausgänge bzw. Eingänge
//definition erfolgt in der config.h
DDRA = OUTA;
//DDRA = OUTA;
DDRC = OUTC;
DDRD = OUTD;

unsigned long a;
#if USE_SERVO
#if USE_SERVO
servo_init ();
#endif //USE_SERVO

Expand All @@ -72,12 +71,16 @@ int main(void)
usart_write("Compiliert am "__DATE__" um "__TIME__"\r\n");
usart_write("Compiliert mit GCC Version "__VERSION__"\r\n");

for(a=0;a<1000000;a++){asm("nop");};

_delay_ms(1000);
//Applikationen starten
stack_init();
httpd_init();
telnetd_init();
#if USE_HTTPD
httpd_init();
#endif
#if USE_TELNETD
telnetd_init();
#endif

//Spielerrei mit einem LCD
#if USE_SER_LCD
Expand All @@ -88,8 +91,11 @@ int main(void)
lcd_print(0,0,"System Ready");
#endif
//Ethernetcard Interrupt enable
#if defined(__AVR_ATmega328P__)
//ETH_INT_ENABLE;
#else
ETH_INT_ENABLE;

#endif
//Globale Interrupts einschalten
sei();

Expand Down Expand Up @@ -229,8 +235,10 @@ int main(void)
#endif //USE_DHCP

//USART Daten für Telnetanwendung?
telnetd_send_data();

#if USE_TELNETD
telnetd_send_data();
#endif

if(ping.result)
{
usart_write("Get PONG: %i.%i.%i.%i\r\n",ping.ip1[0],ping.ip1[1],ping.ip1[2],ping.ip1[3]);
Expand Down
10 changes: 6 additions & 4 deletions ethernet-light-control/makefile
Expand Up @@ -31,7 +31,8 @@

# MCU name

MCU = atmega32
#MCU = atmega32
MCU = atmega328p

#MCU = atmega644

Expand Down Expand Up @@ -170,12 +171,12 @@ LDFLAGS += -lm
#

#AVRDUDE_PROGRAMMER = AVR910
AVRDUDE_PROGRAMMER = stk200
AVRDUDE_PROGRAMMER = stk500v2
#AVRDUDE_PROGRAMMER = USBasp

#AVRDUDE_PORT = usb # programmer connected to USB port
#AVRDUDE_PORT = com1 # programmer connected to serial device
AVRDUDE_PORT = lpt1 # programmer connected to parallel port
AVRDUDE_PORT = com3 # programmer connected to parallel port

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_BITS)
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
Expand Down Expand Up @@ -228,7 +229,8 @@ REMOVE = rm -f
COPY = cp

HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
#ELFSIZE = $(SIZE) -A $(TARGET).elf
ELFSIZE = $(SIZE) -C --mcu=$(MCU) $(TARGET).elf



Expand Down
2 changes: 1 addition & 1 deletion ethernet-light-control/networkcard/enc28j60.c
Expand Up @@ -284,7 +284,7 @@ static unsigned int enc_read_phyreg( unsigned char phyreg )
}
#endif

static void enc_write_phyreg( unsigned char phyreg, unsigned int value )
void enc_write_phyreg( unsigned char phyreg, unsigned int value )
{
enc_write_reg( ENC_REG_MIREGADR, phyreg );
enc_write_reg( ENC_REG_MIWRL, LO8(value) );
Expand Down
21 changes: 20 additions & 1 deletion ethernet-light-control/networkcard/enc28j60.h
Expand Up @@ -34,6 +34,20 @@
atmega <-> enc connection pins, ports, interrupt
*************************************************************/

#if defined (__AVR_ATmega328P__)
#define SPI_DDR DDRB
#define SPI_PORT PORTB
#define SPI_SCK 5
#define SPI_MISO 4
#define SPI_MOSI 3
#define SPI_SS 2

#define ENC_DDR DDRB
#define ENC_PORT PORTB
#define ENC_PIN PINB
#define ENC_CS 2 //4 für Pollin NET I/O Board
#define ENC_INT 1
#else
#define SPI_DDR DDRB
#define SPI_PORT PORTB
#define SPI_SCK 7
Expand All @@ -46,13 +60,18 @@
#define ENC_PIN PINB
#define ENC_CS 3 //4 für Pollin NET I/O Board
#define ENC_INT 2

#endif
#define enc_select() ENC_PORT &= ~(1<<ENC_CS)
#define enc_deselect() ENC_PORT |= (1<<ENC_CS)

#define ETH_INTERRUPT INT2_vect
#define ETH_INT_ACTIVE (!(ENC_PIN & (1<<ENC_INT)))

#if defined (__AVR_ATmega328P__)
#define ETH_INT_ENABLE
#define ETH_INT_DISABLE
#endif

#if defined (__AVR_ATmega32__)
#define ETH_INT_ENABLE GICR |= (1<<INT2)
#define ETH_INT_DISABLE GICR &= ~(1<<INT2)
Expand Down
13 changes: 12 additions & 1 deletion ethernet-light-control/stack.c
Expand Up @@ -57,6 +57,7 @@ UDP_PORT_ITEM UDP_PORT_TABLE[MAX_APP_ENTRY] = // Port-Tabelle
unsigned char myip[4];
unsigned char netmask[4];
unsigned char router_ip[4];
unsigned char broadcast_ip[4];
unsigned int IP_id_counter = 0;
unsigned char eth_buffer[MTU_SIZE+1];

Expand Down Expand Up @@ -98,6 +99,9 @@ void stack_init (void)
(*((unsigned long*)&dns_server_ip[0])) = get_eeprom_value(DNS_IP_EEPROM_STORE,DNS_IP);
#endif

//Broadcast-Adresse berechnen
(*((unsigned long*)&broadcast_ip[0])) = (((*((unsigned long*)&myip[0])) & (*((unsigned long*)&netmask[0]))) | (~(*((unsigned long*)&netmask[0]))));

//MAC Adresse setzen
mymac[0] = MYMAC1;
mymac[1] = MYMAC2;
Expand Down Expand Up @@ -271,12 +275,15 @@ void kill_udp_app (unsigned int port)

//----------------------------------------------------------------------------
//Interrupt von der Netzwerkkarte
#if defined(__AVR_ATmega328P__)
#else
ISR (ETH_INTERRUPT)
{
eth.data_present = 1;
stack_watchdog = 0;
ETH_INT_DISABLE;
}
#endif

//----------------------------------------------------------------------------
//ETH get data
Expand All @@ -288,7 +295,11 @@ void eth_get_data (void)
arp_timer_call();
eth.timer = 0;
}
#if defined(__AVR_ATmega328P__)
if(ETH_INT_ACTIVE)
#else
if(eth.data_present)
#endif
{
#if USE_ENC28J60
while(ETH_INT_ACTIVE)
Expand Down Expand Up @@ -390,7 +401,7 @@ void check_packet (void)
}
}
else
if (ip->IP_Destaddr == (unsigned long)0xffffffff ) // if broadcast
if (ip->IP_Destaddr == (unsigned long)0xffffffff || ip->IP_Destaddr == *((unsigned long*)&broadcast_ip[0]) ) // if broadcast
{
if( ip->IP_Proto == PROT_UDP ) udp_socket_process();
}
Expand Down
8 changes: 8 additions & 0 deletions ethernet-light-control/stack.h
Expand Up @@ -61,9 +61,17 @@ UDP_PORT_ITEM UDP_PORT_TABLE[MAX_APP_ENTRY];
extern unsigned char myip[4];
extern unsigned char netmask[4];
extern unsigned char router_ip[4];
extern unsigned char broadcast_ip[4];

extern unsigned int IP_id_counter;

#if defined (__AVR_ATmega328P__)
#define MAX_TCP_ENTRY 5
#define MAX_UDP_ENTRY 5
#define MAX_ARP_ENTRY 5
#define MTU_SIZE 600
#endif

#if defined (__AVR_ATmega32__)
#define MAX_TCP_ENTRY 5
#define MAX_UDP_ENTRY 5
Expand Down
50 changes: 35 additions & 15 deletions ethernet-light-control/timer.c
Expand Up @@ -63,10 +63,17 @@ void timer_init (void)
TIMSK = (1<<OCIE2);
#endif
#else
TCCR1B |= (1<<WGM12) | (1<<CS10 | 0<<CS11 | 1<<CS12);
#if defined (__AVR_ATmega328P__)
TCCR1B |= (1<<WGM12) | (1<<CS10 | 0<<CS11 | 1<<CS12); //1024
TCNT1 = 0;
OCR1A = (F_CPU / 1024) - 1;
OCR1A = ((F_CPU / 1024) / 200) - 1;
TIMSK1 |= (1 << OCIE1A);
#else
TCCR1B |= (1<<WGM12) | (1<<CS10 | 0<<CS11 | 1<<CS12); //1024
TCNT1 = 0;
OCR1A = ((F_CPU / 1024) / 200) - 1;
TIMSK |= (1 << OCIE1A);
#endif
#endif
return;
};
Expand All @@ -83,18 +90,31 @@ return;
ISR (TIMER1_COMPA_vect)
#endif
{
//tick 1 second
time++;
if((stack_watchdog++) > WTT) //emergency reset of the stack
{
RESET();

static uint16_t prescaler_10ms = 2;
if(!prescaler_10ms--)
{
prescaler_10ms = 1;
}

static uint16_t prescaler_s = 200;
if(!prescaler_s--)
{
prescaler_s = 199;

//tick 1 second
time++;
if((stack_watchdog++) > WTT) //emergency reset of the stack
{
RESET();
}
eth.timer = 1;
#if USE_NTP
ntp_timer--;
#endif //USE_NTP
#if USE_DHCP
if ( dhcp_lease > 0 ) dhcp_lease--;
if ( gp_timer > 0 ) gp_timer--;
#endif //USE_DHCP
}
eth.timer = 1;
#if USE_NTP
ntp_timer--;
#endif //USE_NTP
#if USE_DHCP
if ( dhcp_lease > 0 ) dhcp_lease--;
if ( gp_timer > 0 ) gp_timer--;
#endif //USE_DHCP
}
15 changes: 14 additions & 1 deletion ethernet-light-control/usart.h
Expand Up @@ -56,7 +56,19 @@
#define USART_RX USART0_RX_vect
#endif

#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
#if defined (__AVR_ATmega328P__)
#define USR UCSR0A
#define UCR UCSR0B
#define UDR UDR0
#define UBRR UBRR0L
#define TXEN TXEN0
#define RXEN RXEN0
#define RXCIE RXCIE0
#define UDRE UDRE0
#define FE FE0
#endif

#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
#define USR UCSR0A
#define UCR UCSR0B
#define UBRR UBRR0L
Expand Down Expand Up @@ -99,6 +111,7 @@

void usart_write_P (const char *Buffer,...);
#define usart_write(format, args...) usart_write_P(PSTR(format) , ## args)
//#define usart_write(...)

//----------------------------------------------------------------------------

Expand Down

0 comments on commit 3d0f1aa

Please sign in to comment.