syslog
This commit is contained in:
@ -39,23 +39,19 @@ static void wiz_cs_deselect(void) {
|
||||
static uint8_t wiz_spi_readbyte(void) {
|
||||
uint8_t rbuf;
|
||||
HAL_SPI_Receive(ðerSpi, &rbuf, 1, HAL_MAX_DELAY);
|
||||
// coloredMsg(LOG_YELLOW, "R: %02x", rbuf);
|
||||
return rbuf;
|
||||
}
|
||||
|
||||
static void wiz_spi_writebyte(uint8_t wb) {
|
||||
// coloredMsg(LOG_YELLOW, "W: %02x", wb);
|
||||
HAL_SPI_Transmit(ðerSpi, &wb, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
static void wiz_spi_readburst(uint8_t* pBuf, uint16_t len) {
|
||||
HAL_SPI_Receive(ðerSpi, pBuf, len, HAL_MAX_DELAY);
|
||||
// coloredMsg(LOG_YELLOW, "RB: %d %02x %02x %02x", len, pBuf[0], pBuf[1], pBuf[2]);
|
||||
}
|
||||
|
||||
static void wiz_spi_writeburst(uint8_t* pBuf, uint16_t len) {
|
||||
HAL_SPI_Transmit(ðerSpi, pBuf, len, HAL_MAX_DELAY);
|
||||
// coloredMsg(LOG_YELLOW, "WB: %d %02x %02x %02x", len, pBuf[0], pBuf[1], pBuf[2]);
|
||||
}
|
||||
|
||||
static void wizReset(bool b) {
|
||||
@ -64,36 +60,36 @@ static void wizReset(bool b) {
|
||||
|
||||
|
||||
static void wizDHCPAssign() {
|
||||
coloredMsg(LOG_GREEN, "wizda");
|
||||
coloredMsg(LOG_BLUE, false, "wizda");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_GREEN, "wizda, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_GREEN, "wizda, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_GREEN, "wizda, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_GREEN, "wizda, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_GREEN, "wizda, set netinfo again");
|
||||
coloredMsg(LOG_BLUE, false, "wizda, set netinfo again");
|
||||
|
||||
networkAvailable = true;
|
||||
coloredMsg(LOG_GREEN, "wizda, network is available");
|
||||
coloredMsg(LOG_BLUE, false, "wizda, network is available");
|
||||
}
|
||||
|
||||
static void wizDHCPUpdate() {
|
||||
coloredMsg(LOG_YELLOW, "wizdu");
|
||||
coloredMsg(LOG_BLUE, false, "wizdu");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_YELLOW, "wizdu, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_YELLOW, "wizdu, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_YELLOW, "wizdu, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_YELLOW, "wizdu, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_YELLOW, "wizdu, netinfo updated");
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, netinfo updated");
|
||||
}
|
||||
|
||||
static void wizDHCPHandler(void *handle) {
|
||||
@ -102,7 +98,7 @@ static void wizDHCPHandler(void *handle) {
|
||||
uint8_t res = DHCP_run();
|
||||
|
||||
if (lastDhcpRes != res) {
|
||||
coloredMsg(LOG_RED, "wizdh, dhcp state has changed: %d", res);
|
||||
coloredMsg(LOG_BLUE, false, "wizdh, dhcp state has changed: %d", res);
|
||||
lastDhcpRes = res;
|
||||
}
|
||||
}
|
||||
@ -114,7 +110,7 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
uint8_t phyLink = 0;
|
||||
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
||||
if (lastStablePhyLink != phyLink) {
|
||||
coloredMsg(LOG_RED, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||
lastStablePhyLink = phyLink;
|
||||
|
||||
if (phyLink == PHY_LINK_ON) {
|
||||
@ -122,24 +118,24 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
||||
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
||||
DHCP_init(DHCP_SOCK, dhcpBuffer);
|
||||
coloredMsg(LOG_RED, "wizplh, DHCP initialized");
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP initialized");
|
||||
|
||||
// run the dhcp handler the first time after 1s and then every 100ms
|
||||
schAdd(wizDHCPHandler, NULL, 1000, 1000);
|
||||
coloredMsg(LOG_RED, "wizplh, DHCP handler scheduled");
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler scheduled");
|
||||
|
||||
dhcpInitialized = true;
|
||||
} else {
|
||||
networkAvailable = false;
|
||||
coloredMsg(LOG_RED, "wizplh, network is unavailable");
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable");
|
||||
|
||||
// stop DHCP handler
|
||||
if (dhcpInitialized) {
|
||||
DHCP_stop();
|
||||
coloredMsg(LOG_RED, "wizplh, DHCP stopped");
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP stopped");
|
||||
|
||||
schDel(wizDHCPHandler, NULL);
|
||||
coloredMsg(LOG_RED, "wizplh, DHCP handler unscheduled");
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler unscheduled");
|
||||
|
||||
dhcpInitialized = false;
|
||||
}
|
||||
@ -148,29 +144,29 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
}
|
||||
|
||||
int wizInit() {
|
||||
coloredMsg(LOG_RED, "wizI, resetting Ethernet module");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
||||
wizReset(true);
|
||||
activeDelay(2);
|
||||
wizReset(false);
|
||||
activeDelay(50);
|
||||
|
||||
coloredMsg(LOG_RED, "wizI, registering callbacks");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, registering callbacks");
|
||||
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
|
||||
coloredMsg(LOG_GREEN, "wizI, cs funcs registed");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, cs funcs registed");
|
||||
reg_wizchip_spi_cbfunc(wiz_spi_readbyte, wiz_spi_writebyte);
|
||||
coloredMsg(LOG_GREEN, "wizI, spi funcs registed");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi funcs registed");
|
||||
reg_wizchip_spiburst_cbfunc(wiz_spi_readburst, wiz_spi_writeburst);
|
||||
coloredMsg(LOG_GREEN, "wizI, spi burst funcs registed");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi burst funcs registed");
|
||||
|
||||
|
||||
coloredMsg(LOG_RED, "wizI, initializing Ethernet module");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, initializing Ethernet module");
|
||||
uint8_t bufSizes[] = { 2, 2, 2, 2, 2, 2, 2, 2 };
|
||||
int8_t res = wizchip_init(bufSizes, bufSizes);
|
||||
coloredMsg(LOG_RED, "wizI, module driver returned %d", res);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, module driver returned %d", res);
|
||||
|
||||
wizphy_reset();
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_RED, "wizI, reset phy");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, reset phy");
|
||||
|
||||
wiz_PhyConf wpc;
|
||||
wpc.mode = PHY_MODE_MANUAL;
|
||||
@ -178,21 +174,21 @@ int wizInit() {
|
||||
wpc.duplex = PHY_DUPLEX_FULL;
|
||||
wizphy_setphyconf(&wpc);
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_RED, "wizI, phy config set");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, phy config set");
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_RED, "wizI, netinfo set to Ethernet module");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, netinfo set to Ethernet module");
|
||||
|
||||
res = wizchip_setnetmode(NM_FORCEARP); // and not NM_PINGBLOCK
|
||||
coloredMsg(LOG_RED, "wizI, set netmode, result is %d", res);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, set netmode, result is %d", res);
|
||||
|
||||
uint8_t buf[6];
|
||||
res = ctlwizchip(CW_GET_ID, (void*) buf);
|
||||
coloredMsg(LOG_RED, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
|
||||
|
||||
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||
coloredMsg(LOG_RED, "wizI, PhyLink handler scheduled");
|
||||
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user