Tool/software: Code Composer Studio
Howdy,
I am trying to implement LWIP on the tm4c1294ncpdt on my own board in order to only receive a consistently multicasted packet from a source IP. I have attached what I have going so far based off of lwip documentation and other posts on this forum. If anyone has any pointers or notices any mistakes that would be incredibly helpful. I have t
1. How/Where do I access the final data payload of a UDP message when I receive it?
2. Is there a way to listen for a packet not directed at me that is of a specific length?
3. How does lwip interact with pbuf?
4. What kind of callback is udp_recv looking for?
Any Help Appreciated.
#define IPADDRESS 0xA9FEB95D
#define NETMASK 0xFFFF0000
#define GATEWAY 0
#define PORTNUMBER 0
//
// 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;
// I2C Master instance data
tI2CMInstance g_sI2CInst;
// boolean variable used for callback function
volatile bool g_bLSM303DLHCMagDone;
//lsm303dlhc(magnetometer) instance data
tLSM303DLHCMag g_sLSM303DLHCMag;
//array used to store data read from magnetometer
uint_fast16_t g_fMag[3];
void Maginthandler (void);
static void MagCallback(void *pvCallbackData, uint_fast8_t ui8Status);
void MagInit (void);
float getHeading (void);
struct udp_pcb * upcb;
//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void lwIPHostTimerHandler(void)
{
uint32_t ui32Idx, ui32NewIPAddress;
//
// Get the current IP address.
//
ui32NewIPAddress = lwIPLocalIPAddrGet();
//
// See if the IP address has changed.
//
if(ui32NewIPAddress != g_ui32IPAddress)
{
//
// See if there is an IP address assigned.
//
if(ui32NewIPAddress == 0xffffffff)
{
//
// Indicate that there is no link.
//
// UARTprintf("Waiting for link.\n");
}
else if(ui32NewIPAddress == 0)
{
//
// There is no IP address, so indicate that the DHCP process is
// running.
//
// UARTprintf("Waiting for IP address.\n");
}
else
{
//
// Display the new IP address.
//
// UARTprintf("IP Address: ");
// DisplayIPAddress(ui32NewIPAddress);
// UARTprintf("\nOpen a browser and enter the IP address.\n");
}
//
// Save the new IP address.
//
g_ui32IPAddress = ui32NewIPAddress;
//
// Turn GPIO off.
//
// MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, ~GPIO_PIN_1);
}
//
// If there is not an IP address.
//
if((ui32NewIPAddress == 0) || (ui32NewIPAddress == 0xffffffff))
{
//
// Loop through the LED animation.
//
for(ui32Idx = 1; ui32Idx < 17; ui32Idx++)
{
//
// Toggle the GPIO
//
// MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1,
// (MAP_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1) ^
// GPIO_PIN_1));
SysCtlDelay(120000000/(ui32Idx << 1));
}
}
}
//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Call the lwIP timer handler.
//
lwIPTimer(SYSTICKMS);
}
int main(void)
{
//set clock frequency to 120MHz using the 25MHz external oscilator
uint32_t freq = SysCtlClockFreqSet(SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_XTAL_25MHZ | SYSCTL_CFG_VCO_480,120000000);
//configure all pins for the project and enable peripherals
pinconfig();
//Enable Floating Point Unit
FPUEnable();
//ETHERNET-----------------------------------------------------------------------------------------------------------------------------------
uint32_t ui32User0, ui32User1;
uint8_t pui8MACArray[8];
// Configure SysTick for a periodic interrupt.
MAP_SysTickPeriodSet(120000000 / SYSTICKHZ);
MAP_SysTickEnable();
MAP_SysTickIntEnable();
MAP_IntPrioritySet(INT_EMAC0, ETHERNET_INT_PRIORITY);
MAP_IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY);
// Configure the hardware MAC address for Ethernet Controller filtering of
// incoming packets. The MAC address will be stored in the non-volatile
// USER0 and USER1 registers.
MAP_FlashUserGet(&ui32User0, &ui32User1);
if ((ui32User0 == 0xffffffff) || (ui32User1 == 0xffffffff))
{
// We should never get here. This is an error if the MAC address has
// not been programmed into the device. Exit the program.
// Let the user know there is no MAC address
// UARTprintf("No MAC programmed!\n");
while (1)
{
}
}
// Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
// address needed to program the hardware registers, then program the MAC
// address into the Ethernet Controller registers.
pui8MACArray[0] = ((ui32User0 >> 0) & 0xff);
pui8MACArray[1] = ((ui32User0 >> 8) & 0xff);
pui8MACArray[2] = ((ui32User0 >> 16) & 0xff);
pui8MACArray[3] = ((ui32User1 >> 0) & 0xff);
pui8MACArray[4] = ((ui32User1 >> 8) & 0xff);
pui8MACArray[5] = ((ui32User1 >> 16) & 0xff);
// Initialize the lwIP library, using a static IP
lwIPInit(120000000, pui8MACArray, IPADDRESS, NETMASK, GATEWAY,IPADDR_USE_STATIC);
// showServerInfo();
upcb = udp_new();
err_t error = udp_bind(upcb, IP_ADDR_ANY, PORTNUMBER);
udp_recv(upcb, UDPRecvData, NULL);
struct pbuf * udp_pbuf = pbuf_alloc(PBUF_TRANSPORT, 131, PBUF_ROM);
}