mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 02:00:40 +00:00
Ethernet now successfully ARPing - good milestone
This commit is contained in:
parent
29b864719c
commit
a59a53728d
5 changed files with 43 additions and 47 deletions
|
@ -13,5 +13,7 @@ void mmio_write(long reg, unsigned int val);
|
|||
unsigned int mmio_read(long reg);
|
||||
void gpio_useAsAlt0(unsigned int pin_number);
|
||||
void gpio_useAsAlt3(unsigned int pin_number);
|
||||
void gpio_setPinOutputBool(unsigned int pin_number, unsigned int onOrOff);
|
||||
void gpio_initOutputPinWithPullNone(unsigned int pin_number);
|
||||
void uart_hex(unsigned int d);
|
||||
void uart_byte(unsigned char b);
|
||||
|
|
|
@ -139,11 +139,12 @@ void SendArpPacket(uint8_t *targetIP, uint8_t *deviceMAC)
|
|||
// Send the packet
|
||||
|
||||
if (ENC_RestoreTXBuffer(&handle, sizeof(ARP)) == 0) {
|
||||
debugstr("Sending ARP request... ");
|
||||
debugstr("Sending ARP request.");
|
||||
debugcrlf();
|
||||
|
||||
ENC_WriteBuffer((unsigned char *)&arpPacket, sizeof(ARP));
|
||||
handle.transmitLength = sizeof(ARP);
|
||||
|
||||
ENC_Transmit(&handle);
|
||||
}
|
||||
}
|
||||
|
@ -154,19 +155,17 @@ void arp_test(void)
|
|||
|
||||
SendArpPacket(routerIP, myMAC);
|
||||
|
||||
debugstr("Waiting for ARP response... ");
|
||||
debugstr("Waiting for ARP response.");
|
||||
debugcrlf();
|
||||
|
||||
while (1) {
|
||||
while (!(handle.interruptFlags & EIR_PKTIF)) ENC_IRQHandler(&handle);
|
||||
while (!ENC_GetReceivedFrame(&handle));
|
||||
|
||||
debugstr("Got one... ");
|
||||
ENC_GetReceivedFrame(&handle);
|
||||
|
||||
//uint16_t len = handle.RxFrameInfos.length;
|
||||
uint16_t len = handle.RxFrameInfos.length;
|
||||
uint8_t *buffer = (uint8_t *)handle.RxFrameInfos.buffer;
|
||||
checkPacket = (ARP *)buffer;
|
||||
|
||||
if (len > 0) {
|
||||
if (!memcmp(checkPacket->senderIP, routerIP, 4)) {
|
||||
// Success! We have found our router's MAC address
|
||||
|
||||
|
@ -183,6 +182,7 @@ void arp_test(void)
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_network(void)
|
||||
|
@ -197,15 +197,20 @@ void init_network(void)
|
|||
if (!ENC_Start(&handle)) {
|
||||
debugstr("Could not initialise network card.");
|
||||
} else {
|
||||
debugstr("Setting MAC address to C0:FF:EE:C0:FF:EE.");
|
||||
debugcrlf();
|
||||
|
||||
ENC_SetMacAddr(&handle);
|
||||
|
||||
debugstr("Network card successfully initialised.");
|
||||
}
|
||||
debugcrlf();
|
||||
|
||||
debugstr("Waiting for ifup.");
|
||||
debugcrlf();
|
||||
debugstr("Waiting for ifup... ");
|
||||
while (!(handle.LinkStatus & PHSTAT2_LSTAT)) ENC_IRQHandler(&handle);
|
||||
|
||||
debugstr("Link status: ");
|
||||
debughex(((handle.LinkStatus & PHSTAT2_LSTAT) != 0));
|
||||
debugstr("done.");
|
||||
debugcrlf();
|
||||
|
||||
// Re-enable global interrupts
|
||||
ENC_EnableInterrupts(EIE_INTIE);
|
||||
}
|
||||
|
|
|
@ -42,17 +42,14 @@ struct Spi0Regs {
|
|||
|
||||
void spi_init() {
|
||||
gpio_useAsAlt0(7); //CS1
|
||||
gpio_useAsAlt0(8); //CS0
|
||||
gpio_initOutputPinWithPullNone(8); //CS0
|
||||
gpio_useAsAlt0(9); //MISO
|
||||
gpio_useAsAlt0(10); //MOSI
|
||||
gpio_useAsAlt0(11); //SCLK
|
||||
|
||||
REGS_SPI0->cs = 0x30;
|
||||
REGS_SPI0->clock = 0x28; // 500Mhz / 40 = 12.5Mhz for ENC SPI
|
||||
}
|
||||
|
||||
void spi_chip_select(unsigned char chip_select) {
|
||||
REGS_SPI0->cs = (REGS_SPI0->cs & ~CS_CS) | (chip_select << CS_CS__SHIFT);
|
||||
gpio_setPinOutputBool(8, chip_select);
|
||||
}
|
||||
|
||||
void spi_send_recv(unsigned char *sbuffer, unsigned char *rbuffer, unsigned int size) {
|
||||
|
|
|
@ -750,18 +750,10 @@ bool ENC_Start(ENC_HandleTypeDef *handle)
|
|||
* via SPI.
|
||||
*/
|
||||
|
||||
regval = enc_rdphy(handle, ENC_PHID1);
|
||||
debugstr("PHID1: ");
|
||||
debughex(regval);
|
||||
debugcrlf();
|
||||
|
||||
regval = enc_rdbreg(handle, ENC_EREVID);
|
||||
if (regval == 0x00 || regval == 0xff) {
|
||||
return false;
|
||||
}
|
||||
debugstr("Board revision: ");
|
||||
debughex(regval);
|
||||
debugcrlf();
|
||||
|
||||
/* Initialize ECON2: Enable address auto increment.
|
||||
*/
|
||||
|
@ -847,10 +839,6 @@ bool ENC_Start(ENC_HandleTypeDef *handle)
|
|||
enc_wrbreg(handle, ENC_MAMXFLL, (CONFIG_NET_ETH_MTU+18) & 0xff);
|
||||
enc_wrbreg(handle, ENC_MAMXFLH, (CONFIG_NET_ETH_MTU+18) >> 8);
|
||||
|
||||
/* Set the Mac Address */
|
||||
|
||||
ENC_SetMacAddr(handle);
|
||||
|
||||
/* Configure LEDs (No, just use the defaults for now) */
|
||||
/* enc_wrphy(priv, ENC_PHLCON, ??); */
|
||||
|
||||
|
@ -931,8 +919,6 @@ void ENC_SetMacAddr(ENC_HandleTypeDef *handle)
|
|||
enc_wrbreg(handle, ENC_MAADR4, handle->Init.MACAddr[3]);
|
||||
enc_wrbreg(handle, ENC_MAADR5, handle->Init.MACAddr[4]);
|
||||
enc_wrbreg(handle, ENC_MAADR6, handle->Init.MACAddr[5]);
|
||||
|
||||
enc_wrbreg(handle, ENC_ECOCON, 0x2 & 0x7); // 12.5Mhz
|
||||
}
|
||||
|
||||
|
||||
|
@ -1199,6 +1185,7 @@ void ENC_Transmit(ENC_HandleTypeDef *handle)
|
|||
enc_wrbreg(handle, ENC_ERDPTH, addtTsv4 >> 8);
|
||||
|
||||
enc_rdbuffer(&tsv4, 1);
|
||||
|
||||
regval = enc_rdgreg(ENC_EIR);
|
||||
if (!(regval & EIR_TXERIF) || !(tsv4 & TSV_LATECOL)) {
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "../include/spi.h"
|
||||
#include "../kernel/kernel.h"
|
||||
|
||||
void ENC_SPI_Select(unsigned char truefalse) {
|
||||
spi_chip_select(!truefalse); // If it's true, select 0 (the ENC), if false, select 1 (i.e. deselect the ENC)
|
||||
|
@ -6,14 +7,18 @@ void ENC_SPI_Select(unsigned char truefalse) {
|
|||
|
||||
void ENC_SPI_SendBuf(unsigned char *master2slave, unsigned char *slave2master, unsigned short bufferSize) {
|
||||
spi_chip_select(0);
|
||||
HAL_Delay(1);
|
||||
spi_send_recv(master2slave, slave2master, bufferSize);
|
||||
spi_chip_select(1); // De-select the ENC
|
||||
HAL_Delay(1);
|
||||
}
|
||||
|
||||
void ENC_SPI_Send(unsigned char command) {
|
||||
spi_chip_select(0);
|
||||
HAL_Delay(1);
|
||||
spi_send(&command, 1);
|
||||
spi_chip_select(1); // De-select the ENC
|
||||
HAL_Delay(1);
|
||||
}
|
||||
|
||||
void ENC_SPI_SendWithoutSelection(unsigned char command) {
|
||||
|
|
Loading…
Reference in a new issue