82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
#include <wizHelper.h>
|
|
|
|
#include <stdint.h>
|
|
#include <main2.h>
|
|
#include <spi.h>
|
|
#include <stdbool.h>
|
|
#include <logger.h>
|
|
#include <PontCoopScheduler.h>
|
|
#include <utils.h>
|
|
#include <wizchip_conf.h>
|
|
|
|
|
|
wiz_NetInfo wizNetInfo = {
|
|
.mac = { 0xa0, 0x57, 0x62, 0x01, 0x02, 0x03 },
|
|
.dhcp = NETINFO_DHCP
|
|
};
|
|
|
|
|
|
void wiz_cs_select(void) {
|
|
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_RESET);
|
|
}
|
|
|
|
void wiz_cs_deselect(void) {
|
|
HAL_GPIO_WritePin(ETHER_CS_GPIO_Port, ETHER_CS_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
uint8_t wiz_spi_readbyte(void) {
|
|
uint8_t rbuf;
|
|
HAL_SPI_Receive(ðerSpi, &rbuf, 1, HAL_MAX_DELAY);
|
|
return rbuf;
|
|
}
|
|
|
|
void wiz_spi_writebyte(uint8_t wb) {
|
|
HAL_SPI_Transmit(ðerSpi, &wb, 1, HAL_MAX_DELAY);
|
|
}
|
|
|
|
void wiz_spi_readburst(uint8_t* pBuf, uint16_t len) {
|
|
|
|
}
|
|
|
|
void wiz_spi_writeburst(uint8_t* pBuf, uint16_t len) {
|
|
|
|
}
|
|
|
|
static void wizReset(bool b) {
|
|
HAL_GPIO_WritePin(ETHER_RES_GPIO_Port, ETHER_RES_Pin, b ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
|
}
|
|
|
|
static void wizDHCPHandler(void *handle) {
|
|
uint8_t phyLink = 0;
|
|
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
|
coloredMsg(LOG_RED, "wizdh, ctlwizchip returns %d, phy link is %d", res, phyLink);
|
|
}
|
|
|
|
int wizInit() {
|
|
coloredMsg(LOG_RED, "wizI, resetting Ethernet module");
|
|
wizReset(true);
|
|
activeDelay(2);
|
|
wizReset(false);
|
|
activeDelay(2);
|
|
|
|
coloredMsg(LOG_RED, "wizI, registering callbacks");
|
|
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
|
|
coloredMsg(LOG_GREEN, "wizI, cs funcs registed");
|
|
reg_wizchip_spi_cbfunc(wiz_spi_readbyte, wiz_spi_writebyte);
|
|
coloredMsg(LOG_GREEN, "wizI, spi funcs registed");
|
|
// reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len));
|
|
|
|
|
|
coloredMsg(LOG_RED, "wizI, initializing Ethernet module");
|
|
int8_t res = wizchip_init(NULL, NULL);
|
|
coloredMsg(LOG_RED, "wizI, module driver returned %d", res);
|
|
|
|
wizchip_setnetinfo(&wizNetInfo);
|
|
coloredMsg(LOG_RED, "wizI, netinfo set to Ethernet module");
|
|
|
|
schAdd(wizDHCPHandler, NULL, 0, 1000);
|
|
coloredMsg(LOG_RED, "wizI, DHCP handler scheduled");
|
|
|
|
return 0;
|
|
}
|