Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithMan-de committed Jul 23, 2016
1 parent 7a49a16 commit c2fd644
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/drivers/amd_am79c973.h
Expand Up @@ -71,7 +71,8 @@ namespace myos
int Reset(); int Reset();
common::uint32_t HandleInterrupt(common::uint32_t esp); common::uint32_t HandleInterrupt(common::uint32_t esp);



void Send(common::uint8_t* buffer, int count);
void Receive();
}; };




Expand Down
2 changes: 1 addition & 1 deletion include/drivers/driver.h
Expand Up @@ -20,7 +20,7 @@ namespace myos


class DriverManager class DriverManager
{ {
private: public:
Driver* drivers[265]; Driver* drivers[265];
int numDrivers; int numDrivers;


Expand Down
58 changes: 55 additions & 3 deletions src/drivers/amd_am79c973.cpp
Expand Up @@ -108,6 +108,7 @@ int amd_am79c973::Reset()




void printf(char*); void printf(char*);
void printfHex(uint8_t);


uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp) uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp)
{ {
Expand All @@ -120,15 +121,66 @@ uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp)
if((temp & 0x2000) == 0x2000) printf("AMD am79c973 COLLISION ERROR\n"); if((temp & 0x2000) == 0x2000) printf("AMD am79c973 COLLISION ERROR\n");
if((temp & 0x1000) == 0x1000) printf("AMD am79c973 MISSED FRAME\n"); if((temp & 0x1000) == 0x1000) printf("AMD am79c973 MISSED FRAME\n");
if((temp & 0x0800) == 0x0800) printf("AMD am79c973 MEMORY ERROR\n"); if((temp & 0x0800) == 0x0800) printf("AMD am79c973 MEMORY ERROR\n");
if((temp & 0x0400) == 0x0400) printf("AMD am79c973 DATA RECEVED\n"); if((temp & 0x0400) == 0x0400) Receive();
if((temp & 0x0200) == 0x0200) printf("AMD am79c973 DATA SENT\n"); if((temp & 0x0200) == 0x0200) printf("AMD am79c973 DATA SENT\n");


// acknoledge // acknoledge
registerAddressPort.Write(0); registerAddressPort.Write(0);
registerDataPort.Write(temp); registerDataPort.Write(temp);


if((temp & 0x0200) == 0x0200) printf("AMD am79c973 INIT DONE\n"); if((temp & 0x0100) == 0x0100) printf("AMD am79c973 INIT DONE\n");


return esp; return esp;
} }



This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 14, 2021

Sending a package :
"Flags2" shows whether an error occurred while sending and should therefore be set to 0 by the driver. The OWN bit must now be set in the “flags” field (0x80000000) in order to “transfer” the descriptor to the card. Furthermore, STP (Start of Packet, 0x02000000) and ENP (End of Packet, 0x01000000) should be set - this indicates that the data is not split up, but that it is a single Ethernet packet. Furthermore, bits 12-15 must be set (0x0000F000, are probably reserved) and bits 0-11 are negative Size of the package.

void amd_am79c973::Send(uint8_t* buffer, int size)
{
int sendDescriptor = currentSendBuffer;
currentSendBuffer = (currentSendBuffer + 1) % 8;

if(size > 1518)
size = 1518;

for(uint8_t *src = buffer + size -1,
*dst = (uint8_t*)(sendBufferDescr[sendDescriptor].address + size -1);
src >= buffer; src--, dst--)
*dst = *src;

sendBufferDescr[sendDescriptor].avail = 0;
sendBufferDescr[sendDescriptor].flags2 = 0;
sendBufferDescr[sendDescriptor].flags = 0x8300F000
| ((uint16_t)((-size) & 0xFFF));

This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 14, 2021

Now you could just wait until the card picks up the package. Alternatively, you can also set the TDMD bit (0x08) in CSR0 (i.e. write 0x48 to CSR0 to keep the interrupts activated) in order to shorten this waiting time.

registerAddressPort.Write(0);
registerDataPort.Write(0x48);
}

void amd_am79c973::Receive()
{
printf("AMD am79c973 DATA RECEIVED\n");

This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 12, 2021

buffer is empty if msb is zero

for(; (recvBufferDescr[currentRecvBuffer].flags & 0x80000000) == 0;
currentRecvBuffer = (currentRecvBuffer + 1) % 8)
{
if(!(recvBufferDescr[currentRecvBuffer].flags & 0x40000000)

This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 12, 2021

check Error bit (ERR)

&& (recvBufferDescr[currentRecvBuffer].flags & 0x03000000) == 0x03000000)

This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 12, 2021

check Start of Packet (STP) and End of Packet (ENP) bits , see page 184 of amd documentation


{
uint32_t size = recvBufferDescr[currentRecvBuffer].flags & 0xFFF;
if(size > 64) // remove checksum

This comment has been minimized.

Copy link
@amr98khaled

amr98khaled Mar 12, 2021

size of ethernet 2 frame

size -= 4;

uint8_t* buffer = (uint8_t*)(recvBufferDescr[currentRecvBuffer].address);

for(int i = 0; i < size; i++)
{
printfHex(buffer[i]);
printf(" ");
}
}

recvBufferDescr[currentRecvBuffer].flags2 = 0;
recvBufferDescr[currentRecvBuffer].flags = 0x8000F7FF;
}
}

9 changes: 8 additions & 1 deletion src/kernel.cpp
Expand Up @@ -12,6 +12,8 @@
#include <gui/window.h> #include <gui/window.h>
#include <multitasking.h> #include <multitasking.h>


#include <drivers/amd_am79c973.h>



// #define GRAPHICSMODE // #define GRAPHICSMODE


Expand Down Expand Up @@ -188,7 +190,7 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
printfHex(((size_t)allocated >> 8 ) & 0xFF); printfHex(((size_t)allocated >> 8 ) & 0xFF);
printfHex(((size_t)allocated ) & 0xFF); printfHex(((size_t)allocated ) & 0xFF);
printf("\n"); printf("\n");

TaskManager taskManager; TaskManager taskManager;
/* /*
Task task1(&gdt, taskA); Task task1(&gdt, taskA);
Expand Down Expand Up @@ -242,6 +244,11 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
desktop.AddChild(&win2); desktop.AddChild(&win2);
#endif #endif




amd_am79c973* eth0 = (amd_am79c973*)(drvManager.drivers[2]);
eth0->Send((uint8_t*)"Hello Network", 13);



interrupts.Activate(); interrupts.Activate();


Expand Down

0 comments on commit c2fd644

Please sign in to comment.