// *********************************************************************
// Define the IP address to be used for the MCU running the TCP/IP stack
// *********************************************************************
#define MYIP_1 192
#define MYIP_2 168
#define MYIP_3 0
#define MYIP_4 100
#include "LPC17xx.h"
#include "timer.h"
#include "uip.h"
#include "uip_arp.h"
#include "tapdev.h"
#include <cr_section_macros.h>
#include <NXP/crp.h>
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
void uip_log(char *m)
{
//printf("uIP log message: %s\n", m);
}
char ipstring [20];
int main(void)
{
unsigned int i;
uip_ipaddr_t ipaddr; /* local IP address */
struct timer periodic_timer, arp_timer;
// Code Red - if CMSIS is being used, then SystemInit() routine
// will be called by startup code rather than in application's main()
//#ifndef __USE_CMSIS
// system init
SystemInit(); /* setup core clocks */
printf("systemInit");
//#endif
// clock init
clock_init();
// two timers for tcp/ip
timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */
timer_set(&arp_timer, CLOCK_SECOND * 10); /* 10s */
// ethernet init
tapdev_init();
// Initialize the uIP TCP/IP stack.
// uip_init();
// uip_ipaddr(ipaddr, MYIP_1,MYIP_2,MYIP_3,MYIP_4);
// uip_sethostaddr(ipaddr); /* host IP address */
// uip_ipaddr(ipaddr, MYIP_1,MYIP_2,MYIP_3,1);
// uip_setdraddr(ipaddr); /* router IP address */
// uip_ipaddr(ipaddr, 255,255,255,0);
// uip_setnetmask(ipaddr); /* mask */
// Initialize the HTTP server, listen to port 80.
httpd_init();
printf("httpd_init");
SystemCoreClockUpdate ();
printf("SystemCoreClock: %d\n", SystemCoreClock);
int abc=0;
while(1)
{
/* receive packet and put in uip_buf */
uip_len = tapdev_read(uip_buf);
if(uip_len > 0) /* received packet */
{
printf("pakiet ");
for(abc=0;abc<uip_len;abc++)printf("%x ",uip_buf[abc]);
printf("\n");
//---------------------------------------------
tapdev_send(uip_buf,uip_len);
tapdev_send("jakis tekst ktory ma sprwadzic dzialanie przesylania danych po porcie ethernet",78);
//-----------------------------------------
if(BUF->type == htons(UIP_ETHTYPE_IP)) /* IP packet */
{
printf("IP");
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
uip_arp_out();
tapdev_send(uip_buf,uip_len);
}
}
else if(BUF->type == htons(UIP_ETHTYPE_ARP)) /*ARP packet */
{
printf("ARP");
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
tapdev_send(uip_buf,uip_len); /* ARP ack*/
}
}
}
else if(timer_expired(&periodic_timer)) /* no packet but periodic_timer time out (0.5s)*/
{
timer_reset(&periodic_timer);
for(i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
uip_arp_out();
tapdev_send(uip_buf,uip_len);
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++) {
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
uip_arp_out();
tapdev_send();
}
}
#endif /* UIP_UDP */
/* Call the ARP timer function every 10 seconds. */
if(timer_expired(&arp_timer))
{
//timer_reset(&arp_timer);
//uip_arp_timer();
}
}
}
}
|