-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.c
More file actions
129 lines (108 loc) · 2.13 KB
/
Main.c
File metadata and controls
129 lines (108 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Main File including the main-routine with initializations-
* and stack-routines.
*
* Author: Simon Kueppers
* Email: simon.kueppers@web.de
* Homepage: http://klinkerstein.m-faq.de
*
*
* Additions for the connected LED-Matrix-Display
* made by Bjoern Biesenbach
* */
#include <avr/io.h>
#include <avr/interrupt.h>
#include "Hardware/Enc28j60.h"
#include "Hardware/Spi.h"
#include "Net/uip/uip.h"
#include "Net/uip/uip_arp.h"
#include "Net/uip/uip_TcpAppHub.h"
#include "led_matrix.h"
static uint8_t g_nPrescaler = 100;
static volatile struct
{
uint8_t fPeriodic :1;
} g_nFlags =
{ 0 };
int main()
{
uip_ipaddr_t IpAddr;
SpiInit();
Enc28j60Init();
uip_arp_init();
uip_init();
uip_TcpAppHubInit();
Enc28j60SetClockPrescaler(2);
TCCR1B = (1<<WGM12)|(3<<CS10);
OCR1A = 19531; //12500000 / 64 / 19531,25 = 10Hz (100ms)
TIMSK = (1<<OCIE1A);
uip_ipaddr(IpAddr, 192, 168, 0, 93);
uip_sethostaddr(IpAddr);
uip_ipaddr(IpAddr, 192, 168, 0, 254);
uip_setdraddr(IpAddr);
uip_ipaddr(IpAddr, 255, 255, 0, 0);
uip_setnetmask(IpAddr);
led_init();
sei ();
while (1)
{
uip_len = Enc28j60Receive(uip_buf);
if (uip_len> 0)
{
if (((struct uip_eth_hdr *)&uip_buf[0])->type
== htons(UIP_ETHTYPE_IP))
{
//uip_arp_ipin();
uip_input();
if (uip_len> 0)
{
uip_arp_out();
Enc28j60CopyPacket(uip_buf, uip_len);
Enc28j60Send();
}
}
else if (((struct uip_eth_hdr *)&uip_buf[0])->type
== htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
if (uip_len> 0)
{
Enc28j60CopyPacket(uip_buf, uip_len);
Enc28j60Send();
}
}
}
if (g_nFlags.fPeriodic)
{
cli();
g_nFlags.fPeriodic = 0;
sei();
int i= UIP_CONNS;
while (i)
{
i--;
uip_periodic(i);
if (uip_len> 0)
{
uip_arp_out();
Enc28j60CopyPacket(uip_buf, uip_len);
Enc28j60Send();
}
}
g_nPrescaler--;
if (g_nPrescaler == 0)
{
//Every 10 seconds
uip_arp_timer();
g_nPrescaler = 100;
}
}
/* Comment this out and your led-matrix will go up in flames */
led_runner();
}
return 0;
}
ISR(TIMER1_COMPA_vect)
{
g_nFlags.fPeriodic = 1;
}