From 5650a758f8fa76131d9d41ad503cb4ce04892384 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 9 Nov 2020 11:20:00 +0100 Subject: [PATCH] dhcp stuff --- cube/User/Src/wizHelper.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cube/User/Src/wizHelper.c b/cube/User/Src/wizHelper.c index 80e8758..606633a 100644 --- a/cube/User/Src/wizHelper.c +++ b/cube/User/Src/wizHelper.c @@ -10,11 +10,16 @@ #include -wiz_NetInfo wizNetInfo = { +wiz_NetInfo netInfo = { .mac = { 0xa0, 0x57, 0x62, 0x01, 0x02, 0x03 }, .dhcp = NETINFO_DHCP }; +#define DHCP_BUFFER_SIZE 1024 +static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE]; + +const uint8_t DHCP_SOCK = 6; + void wiz_cs_select(void) { HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_RESET); @@ -54,6 +59,22 @@ static void wizDHCPHandler(void *handle) { coloredMsg(LOG_RED, "wizdh, ctlwizchip returns %d, phy link changed to %d", res, phyLink); lastStablePhyLink = phyLink; } + if (phyLink == PHY_LINK_ON) { + static uint8_t lastRes = 255; + uint8_t res = DHCP_run(); + if (lastRes != res) { + coloredMsg(LOG_RED, "wizdh, dhcp state has changed: %d", res); + lastRes = res; + } + } +} + +static void wizDHCPAssign() { + coloredMsg(LOG_RED, "wizda"); +} + +static void wizDHCPUpdate() { + coloredMsg(LOG_RED, "wizdu"); } int wizInit() { @@ -75,9 +96,14 @@ int wizInit() { int8_t res = wizchip_init(NULL, NULL); coloredMsg(LOG_RED, "wizI, module driver returned %d", res); - wizchip_setnetinfo(&wizNetInfo); + wizchip_setnetinfo(&netInfo); coloredMsg(LOG_RED, "wizI, netinfo set to Ethernet module"); + memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE); + reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL); + DHCP_init(DHCP_SOCK, dhcpBuffer); + coloredMsg(LOG_RED, "wizI, DHCP initialized"); + schAdd(wizDHCPHandler, NULL, 0, 1000); coloredMsg(LOG_RED, "wizI, DHCP handler scheduled");