void ETH_communication(int data1, int data2, int t)
{
uint8_t macaddr[6], *workbuff;
uint32_t physts = 0;
int32_t rxBytes, i;
bool ethpkttgl = true;
volatile int k = 1;
int data3, data4, data5, data6;
data3 = floor(data1/10);
data4 = data1 - data3*10;
data5 = floor(data2/10);
data6 = data2 - data5*10;
SystemCoreClockUpdate();
Board_Init();
/* LED0 is used for the link status, on = PHY cable detected */
/* Initial LED state is off to show an unconnected cable state */
Board_LED_Set(0, false);
/* Setup ethernet and PHY */
#if defined(USE_RMII)
Chip_ENET_Init(LPC_ETHERNET, true);
#else
Chip_ENET_Init(LPC_ETHERNET, false);
#endif
/* Setup MII clock rate and PHY address */
Chip_ENET_SetupMII(LPC_ETHERNET, Chip_ENET_FindMIIDiv(LPC_ETHERNET, 2500000), 1);
lpc_phy_init(true, localMsDelay);
/* Setup MAC address for device */
Board_ENET_GetMacADDR(macaddr);
Chip_ENET_SetADDR(LPC_ETHERNET, macaddr);
/* Setup descriptors */
InitDescriptors();
/* Enable RX/TX after descriptors are setup */
Chip_ENET_TXEnable(LPC_ETHERNET);
Chip_ENET_RXEnable(LPC_ETHERNET);
/* Only if link detected */
if (physts & PHY_LINK_CONNECTED) {
workbuff = ENET_TXBuffGet();
if (workbuff) {
/* Destination is broadcast */
for (i = 0; i < 6; i++) {
workbuff = 0xFF;
}
/* Source is this MAC address */
memcpy(&workbuff[6], macaddr, 6);
/* Size will be 128 bytes (total) */
workbuff[12] = 0;
workbuff[13] = 64;
if(t==1)
{
workbuff[14]=1;
}
if(t==0)
{
workbuff[14]=0;
}
workbuff[14] = data3;
workbuff[15] = data4;
workbuff[16] = data5;
workbuff[17] = data6;
/* Some dummy data, fill beyond end of packet */
for (i = 0; i < 128; i++) {
workbuff[i + 14] = i; //(uint8_t) (i & 0xFF);
}
ENET_TXQueue(128);
DEBUGOUT("Packet sent! \r\n");
Board_LED_Set(1, true);
}
}
if (ENET_IsTXFinish()) {
Board_LED_Set(1, false);
}
/* PHY status state machine, LED on when connected. This function will
not block. */
physts = lpcPHYStsPoll();
/* Only check for connection state when the PHY status has changed */
if (physts & PHY_LINK_CHANGED) {
if (physts & PHY_LINK_CONNECTED) {
Board_LED_Set(0, true);
/* Set interface speed and duplex */
if(physts & PHY_LINK_FULLDUPLX)
Chip_ENET_SetFullDuplex(LPC_ETHERNET);
else
Chip_ENET_SetHalfDuplex(LPC_ETHERNET);
if(physts & PHY_LINK_SPEED100)
Chip_ENET_Set100Mbps(LPC_ETHERNET);
else
Chip_ENET_Set10Mbps(LPC_ETHERNET);
}
else {
Board_LED_Set(0, false);
}
DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0));
}
}
|