dhcp stuff

This commit is contained in:
Wolfgang Hottgenroth 2020-11-09 11:20:00 +01:00
parent f1736f0369
commit 5650a758f8
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -10,11 +10,16 @@
#include <wizchip_conf.h>
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");