Fixed fb.c across the board, iterated on Ethernet support - still WIP

This commit is contained in:
Adam Greenwood-Byrne 2021-10-26 09:50:13 +01:00
parent befc45feba
commit 66f80328bc
14 changed files with 95 additions and 89 deletions

View file

@ -15,7 +15,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -17,7 +17,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -7,7 +7,7 @@ void vga256(void)
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -15,7 +15,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -1,6 +1,8 @@
#include "../net/enc28j60.h" #include "../net/enc28j60.h"
#include "../include/fb.h" #include "../include/fb.h"
ENC_HandleTypeDef handle;
// Structure for Ethernet header // Structure for Ethernet header
typedef struct { typedef struct {
@ -11,8 +13,8 @@ typedef struct {
// Ethernet packet types // Ethernet packet types
#define ARPPACKET 0x0806 #define ARPPACKET 0x0608
#define IPPACKET 0x0800 #define IPPACKET 0x0008
// Structure for an ARP Packet // Structure for an ARP Packet
@ -31,12 +33,12 @@ typedef struct {
// ARP OpCodes // ARP OpCodes
#define ARPREPLY 0x0002 #define ARPREPLY 0x0200
#define ARPREQUEST 0x0001 #define ARPREQUEST 0x0100
// ARP hardware types // ARP hardware types
#define ETHERNET 0x0001 #define ETHERNET 0x0100
// MAC address to be assigned to the ENC28J60 // MAC address to be assigned to the ENC28J60
@ -135,32 +137,40 @@ void SendArpPacket(uint8_t *targetIP, uint8_t *deviceMAC)
} }
// Send the packet // Send the packet
if (ENC_RestoreTXBuffer(&handle, sizeof(ARP)) == 0) {
debugstr("Sending ARP request... ");
debugcrlf();
ENC_WriteBuffer((unsigned char *)&arpPacket, sizeof(ARP)); ENC_WriteBuffer((unsigned char *)&arpPacket, sizeof(ARP));
handle.transmitLength = sizeof(ARP);
ENC_Transmit(&handle);
}
} }
void arp_test(void) void arp_test(void)
{ {
unsigned int tries = 0; ARP *checkPacket;
ARP checkPacket;
debugstr("Sending ARP request... ");
SendArpPacket(routerIP, myMAC); SendArpPacket(routerIP, myMAC);
debugstr("done.");
debugcrlf();
debugstr("Waiting for ARP response... "); debugstr("Waiting for ARP response... ");
debugcrlf(); debugcrlf();
while (tries < 1000) { while (1) {
if (ENC_ReadBuffer((unsigned char *)&checkPacket, sizeof(ARP)) == 0) { if (!ENC_GetReceivedFrame(&handle)) {
continue; continue;
} }
if (!memcmp(checkPacket.senderIP, routerIP, 4)) {
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 // Success! We have found our router's MAC address
memcpy(routerMAC, checkPacket.senderMAC, 6); memcpy(routerMAC, checkPacket->senderMAC, 6);
debugstr("Router MAC is "); debugstr("Router MAC is ");
debughex(routerMAC[0]); debughex(routerMAC[0]);
debughex(routerMAC[1]); debughex(routerMAC[1]);
@ -169,26 +179,25 @@ void arp_test(void)
debughex(routerMAC[4]); debughex(routerMAC[4]);
debughex(routerMAC[5]); debughex(routerMAC[5]);
debugcrlf(); debugcrlf();
}
tries++;
}
debugstr("Timed out."); break;
debugcrlf(); }
}
}
} }
void init_network(void) void init_network(void)
{ {
ENC_HandleTypeDef handle;
debugstr("Setting MAC address to C0:FF:EE:C0:FF:EE.");
debugcrlf();
handle.Init.DuplexMode = ETH_MODE_FULLDUPLEX; handle.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
handle.Init.MACAddr = myMAC; handle.Init.MACAddr = myMAC;
handle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE; handle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
handle.Init.InterruptEnableBits = 0; handle.Init.InterruptEnableBits = 0;
debugstr("Setting MAC address to C0:FF:EE:C0:FF:EE.");
debugcrlf();
ENC_SetMacAddr(&handle);
debugstr("Starting network up."); debugstr("Starting network up.");
debugcrlf(); debugcrlf();

View file

@ -8,10 +8,10 @@
void initProgress(void) void initProgress(void)
{ {
drawRect(0, 0, 301, 50, 0x0f, 0); drawRect(0, 0, 301, 50, 0x0f, 0);
drawString(309, 21, "Core 1", 0x0f, 1); drawString(309, 21, "Core 0", 0x0f, 1);
drawRect(0, 60, 301, 110, 0x0f, 0); drawRect(0, 60, 301, 110, 0x0f, 0);
drawString(309, 81, "Core 2", 0x0f, 1); drawString(309, 81, "Core 1", 0x0f, 1);
drawRect(0, 120, 301, 170, 0x0f, 0); drawRect(0, 120, 301, 170, 0x0f, 0);
drawString(309, 141, "Timer 1", 0x0f, 1); drawString(309, 141, "Timer 1", 0x0f, 1);
@ -28,28 +28,32 @@ void drawProgress(unsigned int core, unsigned int val) {
if (val > 0) drawRect(1, (60 * core) + 1, (val * 3), (60 * core) + 49, col, 1); if (val > 0) drawRect(1, (60 * core) + 1, (val * 3), (60 * core) + 49, col, 1);
} }
unsigned int c2_done = 0; void core3_main(void) {
clear_core3(); // Only run once
void core2_main(void) // Test the network card
{
unsigned int core2_val = 0;
clear_core2(); // Only run once spi_init();
init_network();
while (core2_val <= 100) { arp_test();
wait_msec(0x100000);
drawProgress(1, core2_val);
core2_val++;
}
debugstr("Core 2 done.");
debugcrlf();
c2_done = 1;
while(1); while(1);
} }
void core0_main(void)
{
unsigned int core0_val = 0;
while (core0_val <= 100) {
wait_msec(0x100000);
drawProgress(0, core0_val);
core0_val++;
}
debugstr("Core 0 done.");
debugcrlf();
}
void core1_main(void) void core1_main(void)
{ {
unsigned int core1_val = 0; unsigned int core1_val = 0;
@ -58,7 +62,7 @@ void core1_main(void)
while (core1_val <= 100) { while (core1_val <= 100) {
wait_msec(0x3FFFF); wait_msec(0x3FFFF);
drawProgress(0, core1_val); drawProgress(1, core1_val);
core1_val++; core1_val++;
} }
@ -144,10 +148,9 @@ void main(void)
initProgress(); initProgress();
// Kick it off on core 1&2 // Kick it off on core 1
start_core1(core1_main); start_core1(core1_main);
start_core2(core2_main);
// Kick off the timers // Kick off the timers
@ -156,18 +159,13 @@ void main(void)
irq_enable(); irq_enable();
timer_init(); timer_init();
// Test the network card // Kick it off on core 3
spi_init(); start_core3(core3_main);
init_network();
arp_test();
// The work is done - wait for timers to get done // Kick it off on core 0
debugstr("Core 0 done."); core0_main();
debugcrlf();
while (!c2_done);
// Disable IRQs and loop endlessly // Disable IRQs and loop endlessly

View file

@ -15,7 +15,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -376,8 +376,7 @@ void enc_reset(ENC_HandleTypeDef *handle) {
*/ */
handle->bank = 0; /* Initialize the trace on the current selected bank */ handle->bank = 0; /* Initialize the trace on the current selected bank */
//up_mdelay(2); up_udelay(2); /* >1000 µs, conforms to errata #2 */
HAL_Delay(2); /* >1000 µs, conforms to errata #2 */
} }
/**************************************************************************** /****************************************************************************
@ -797,7 +796,7 @@ bool ENC_Start(ENC_HandleTypeDef *handle)
enc_wrbreg(handle, ENC_ERXFCON, ERXFCON_UCEN | ERXFCON_CRCEN | ERXFCON_BCEN); enc_wrbreg(handle, ENC_ERXFCON, ERXFCON_UCEN | ERXFCON_CRCEN | ERXFCON_BCEN);
do { do {
HAL_Delay(10); /* Wait for 10 ms to let the clock be ready */ up_udelay(10); /* Wait for 10 ms to let the clock be ready */
regval = enc_rdbreg(handle, ENC_ESTAT); regval = enc_rdbreg(handle, ENC_ESTAT);
} while ((regval & ESTAT_CLKRDY) == 0); } while ((regval & ESTAT_CLKRDY) == 0);
@ -993,7 +992,7 @@ void ENC_WriteBuffer(void *buffer, uint16_t buflen)
} }
/**************************************************************************** /****************************************************************************
* Function: ENC_ReadBuffer * Function: enc_rdbuffer
* *
* Description: * Description:
* Read a buffer of data. * Read a buffer of data.
@ -1010,10 +1009,8 @@ void ENC_WriteBuffer(void *buffer, uint16_t buflen)
* *
****************************************************************************/ ****************************************************************************/
uint8_t ENC_ReadBuffer(void *buffer, uint16_t buflen) static void enc_rdbuffer(void *buffer, uint16_t buflen)
{ {
uint8_t read_count = 0;
/* Select ENC28J60 chip */ /* Select ENC28J60 chip */
ENC_SPI_Select(true); ENC_SPI_Select(true);
@ -1024,11 +1021,9 @@ uint8_t ENC_ReadBuffer(void *buffer, uint16_t buflen)
/* Then read the buffer data */ /* Then read the buffer data */
read_count = ENC_SPI_SendBuf(NULL, buffer, buflen); ENC_SPI_SendBuf(NULL, buffer, buflen);
/* De-select ENC28J60 chip: done in ENC_SPI_SendBuf callback */ /* De-select ENC28J60 chip: done in ENC_SPI_SendBuf callback */
return read_count;
} }
/**************************************************************************** /****************************************************************************
@ -1153,6 +1148,8 @@ void ENC_Transmit(ENC_HandleTypeDef *handle)
PT_BEGIN(pt); PT_BEGIN(pt);
if (handle->transmitLength != 0) { if (handle->transmitLength != 0) {
debugstr("We're actually sending"); debugcrlf();
/* A frame is ready for transmission */ /* A frame is ready for transmission */
/* Set TXRTS to send the packet in the transmit buffer */ /* Set TXRTS to send the packet in the transmit buffer */
@ -1191,7 +1188,7 @@ void ENC_Transmit(ENC_HandleTypeDef *handle)
enc_wrbreg(handle, ENC_ERDPTL, addtTsv4 & 0xff); enc_wrbreg(handle, ENC_ERDPTL, addtTsv4 & 0xff);
enc_wrbreg(handle, ENC_ERDPTH, addtTsv4 >> 8); enc_wrbreg(handle, ENC_ERDPTH, addtTsv4 >> 8);
ENC_ReadBuffer(&tsv4, 1); enc_rdbuffer(&tsv4, 1);
regval = enc_rdgreg(ENC_EIR); regval = enc_rdgreg(ENC_EIR);
if (!(regval & EIR_TXERIF) || !(tsv4 & TSV_LATECOL)) { if (!(regval & EIR_TXERIF) || !(tsv4 & TSV_LATECOL)) {
break; break;
@ -1201,7 +1198,10 @@ void ENC_Transmit(ENC_HandleTypeDef *handle)
} while (handle->retries > 0); } while (handle->retries > 0);
/* Transmission finished (but can be unsuccessful) */ /* Transmission finished (but can be unsuccessful) */
handle->transmitLength = 0; handle->transmitLength = 0;
} else {
debugstr("Nothing to send"); debugcrlf();
} }
debugstr("We're done sending"); debugcrlf();
PT_END(pt); PT_END(pt);
} }
@ -1246,7 +1246,7 @@ bool ENC_GetReceivedFrame(ENC_HandleTypeDef *handle)
* and wrap to the beginning of the read buffer as necessary) * and wrap to the beginning of the read buffer as necessary)
*/ */
ENC_ReadBuffer(rsv, 6); enc_rdbuffer(rsv, 6);
/* Decode the new next packet pointer, and the RSV. The /* Decode the new next packet pointer, and the RSV. The
* RSV is encoded as: * RSV is encoded as:
@ -1285,7 +1285,7 @@ bool ENC_GetReceivedFrame(ENC_HandleTypeDef *handle)
* end_rdbuffer (above). * end_rdbuffer (above).
*/ */
ENC_ReadBuffer(handle->RxFrameInfos.buffer, handle->RxFrameInfos.length); enc_rdbuffer(handle->RxFrameInfos.buffer, handle->RxFrameInfos.length);
} }
} }

View file

@ -686,7 +686,6 @@ int8_t ENC_RestoreTXBuffer(ENC_HandleTypeDef *handle, uint16_t len);
****************************************************************************/ ****************************************************************************/
void ENC_WriteBuffer(void *buffer, uint16_t buflen); void ENC_WriteBuffer(void *buffer, uint16_t buflen);
uint8_t ENC_ReadBuffer(void *buffer, uint16_t buflen);
/**************************************************************************** /****************************************************************************
* Function: ENC_Transmit * Function: ENC_Transmit

View file

@ -12,7 +12,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -12,7 +12,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -15,7 +15,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -17,7 +17,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)

View file

@ -15,7 +15,7 @@ void fb_init()
mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier mbox[2] = MBOX_TAG_SETPHYWH; // Tag identifier
mbox[3] = 8; // Value size in bytes mbox[3] = 8; // Value size in bytes
mbox[4] = 8; // Value size in bytes (again!) mbox[4] = 0;
mbox[5] = 1920; // Value(width) mbox[5] = 1920; // Value(width)
mbox[6] = 1080; // Value(height) mbox[6] = 1080; // Value(height)