Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stm32f4xx_hal.h>
- #include "lwip/init.h"
- #include "lwip/netif.h"
- #include "lwip/tcpip.h"
- #include "lwip/dhcp.h"
- #include "lwip/api.h"
- #include "lwip/opt.h"
- #include "lwip/timeouts.h"
- #include "netif/etharp.h"
- #include "lwip/apps/sntp.h"
- #include "lwip/apps/sntp_opts.h"
- #include "ethernetif.h"
- #include "NetworkDefaults.h"
- static struct netif gnetif;
- static void StartDhcp(void);
- static void NetworkConfig(void);
- static void PrintIP(void);
- // Bring up all networking items
- void NetworkingInit(void)
- {
- // Bring up the network stack
- lwip_init();
- // Bring up the network link
- NetworkConfig();
- // Start DHCP, we'll start other services will start when we have an IP
- StartDhcp();
- }
- void NetworkingUpdate(void)
- {
- // Set link state
- //ethernetif_check_link_state(&gnetif);
- // Attempt to process ethernet frames
- ethernetif_input(&gnetif);
- // Refresh all timers
- sys_check_timeouts();
- //PrintIP();
- // If we don't have an IP or the link is down, quit now
- if(gnetif.ip_addr.addr == 0)
- {
- return;
- }
- }
- void NetworkingShutdown(void)
- {
- dhcp_stop(&gnetif);
- }
- static void StartDhcp(void)
- {
- // Zero out IP, netmask, and gateway
- ip_addr_set_zero_ip4(&gnetif.ip_addr);
- ip_addr_set_zero_ip4(&gnetif.netmask);
- ip_addr_set_zero_ip4(&gnetif.gw);
- // Start LwIP DHCP
- dhcp_start(&gnetif);
- printf("DHCP start\r\n");
- }
- // Attempt to get an address from DHCP
- static void PrintIP(void)
- {
- printf("IP address: %d.%d.%d.%d\r\n", (uint8_t)gnetif.ip_addr.addr, ((uint8_t)gnetif.ip_addr.addr >> 8), ((uint8_t)gnetif.ip_addr.addr >> 16), ((uint8_t)gnetif.ip_addr.addr >> 24));
- }
- void SetRtcFromNtpTimestamp(const uint32_t seconds, const uint32_t uSeconds)
- {
- printf("Trying to set to %lu %lu\r\n", seconds, uSeconds);
- }
- void GetRtcTimestamp(uint32_t* seconds, uint32_t* uSeconds)
- {
- }
- // Configure the network
- static void NetworkConfig(void)
- {
- ip_addr_t ipaddr;
- ip_addr_t netmask;
- ip_addr_t gw;
- // Start with settings zero'd for DHCP
- ip_addr_set_zero_ip4(&ipaddr);
- ip_addr_set_zero_ip4(&netmask);
- ip_addr_set_zero_ip4(&gw);
- /*IP_ADDR4(&ipaddr, 192, 168, 1, 50);
- IP_ADDR4(&netmask, 255, 255, 255, 0);
- IP_ADDR4(&gw, 192, 168, 1, 1);*/
- // Add the network interface
- netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input);
- // Registers the default network interface
- netif_set_default(&gnetif);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement