#define IP_ADDR_OCT1 192
#define IP_ADDR_OCT2 168
#define IP_ADDR_OCT3 0
#define IP_ADDR_OCT4 3
#define SUBNET_OCT1 0
#define SUBNET_OCT2 0
#define SUBNET_OCT3 0
#define SUBNET_OCT4 0
#define GATEWAY_IP_OCT1 255
#define GATEWAY_IP_OCT2 255
#define GATEWAY_IP_OCT3 255
#define GATEWAY_IP_OCT4 255
struct ip_addr *udpDestIpAddr;
struct udp_pcb *pcb;
struct udp_pcb *g_upcb1;
int i,j;
unsigned long index;
unsigned char buffer[1440];
unsigned char *UDPData;
unsigned char gain;
unsigned char u8_EtherNodeId = 0;
unsigned char pucMACArray[8];
unsigned char u8_EthNode;
unsigned char IP_AddrOct1;
uint32_t IP_addr,subnet_addr,gateway_addr;
//*****************************************************************************
//
// Defines for setting up the system clock.
//
//*****************************************************************************
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
//*****************************************************************************
//
// Interrupt priority definitions. The top 3 bits of these values are
// significant with lower values indicating higher priority interrupts.
//
//*****************************************************************************
#define SYSTICK_INT_PRIORITY 0x80
//#define ETHERNET_INT_PRIORITY 0xC0
//*****************************************************************************
//
// The current IP address.
//
//*****************************************************************************
uint32_t g_ui32IPAddress;
//*****************************************************************************
//
// The system clock frequency.
//
//*****************************************************************************
uint32_t g_ui32SysClock;
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
// UDP transmit ...........................................
void my_udp_tx(u8_t *data, u16_t len)
{
if(g_upcb1->remote_port != (unsigned short)0)
{
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT,len, PBUF_RAM);
memcpy(p->payload, data, len);
udp_send(g_upcb1, p);
pbuf_free(p);
}
}
void my_udp_rx(struct udp_pcb *upcb,struct ip_addr *addr, u16_t port,u8_t *buf)
{
/* process the payload in p->payload */
udp_connect(upcb, addr, port); /* connect to the remote host */
my_udp_tx(buf,1456);
free(buf); /* don't leak the pbuf!*/
}
// UDP initialization ......................................
void my_udp_init(void)
{
g_upcb1 = udp_new();
IP4_ADDR(udpDestIpAddr,172,17,2,28);
udp_bind(g_upcb1,&IP_addr,sizeof(IP_addr));
udp_sendto(struct udp_pcb *pcb, struct pbuf *p,ip_addr_t *dst_ip, 777);
}
//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void
lwIPHostTimerHandler(void)
{
}
//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Call the lwIP timer handler.
//
lwIPTimer(SYSTICKMS);
}
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int main(void)
{
char p[100];
char b[100];
char c[100];
sprintf(p,"%d.%d.%d.%d\n",IP_ADDR_OCT1,IP_ADDR_OCT2,IP_ADDR_OCT3,IP_ADDR_OCT4);
sprintf(b,"%d.%d.%d.%d\n",SUBNET_OCT1,SUBNET_OCT2,SUBNET_OCT3,SUBNET_OCT4);
sprintf(c,"%d.%d.%d.%d\n",GATEWAY_IP_OCT1,GATEWAY_IP_OCT2,GATEWAY_IP_OCT3,GATEWAY_IP_OCT4);
IP_addr = inet_addr(p);
subnet_addr = inet_addr(b);
gateway_addr = inet_addr(c);
lwIPInit(100,pucMACArray, IP_addr, subnet_addr, gateway_addr, IPADDR_USE_STATIC);
udpDestIpAddr = (struct ip_addr *)malloc(sizeof(struct ip_addr));
my_udp_init();
}