Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
1,200 Views

Triple Speed Ethernet

Hello everyone, 

I am new to FPGA, I have an Altera DE2-115 kit and i was working on triple speed Ethernet, and have successfully done the "Using Triple Speed Ethernet Tutorial", but i want some help to understand some part of the code given with the tutorial. 

 

// Triple-speed Ethernet MegaCore base address 

volatile int * tse = (int *) 0x00102000; 

 

 

// Initialize the MAC address 

*(tse + 3) = 0x116E6001; 

*(tse + 4) = 0x00000F02; 

 

 

// Specify the addresses of the PHY devices to be accessed through MDIO interface 

*(tse + 0x0F) = 0x10; 

*(tse + 0x10) = 0x11; 

 

 

// Write to register 20 of the PHY chip for Ethernet port 0 to set up line loopback 

*(tse + 0x94) = 0x4000; 

 

 

// Write to register 16 of the PHY chip for Ethernet port 1 to enable automatic crossover for all modes("| = OR") 

*(tse + 0xB0) = *(tse + 0xB0) | 0x0060; 

 

 

// Write to register 20 of the PHY chip for Ethernet port 2 to set up delay for input/output clk 

*(tse + 0xB4) = *(tse + 0xB4) | 0x0082; 

 

 

// Software reset the second PHY chip and wait 

*(tse + 0xA0) = *(tse + 0xA0) | 0x8000; 

while ( *(tse + 0xA0) & 0x8000 ) 

 

 

// Enable read and write transfers, gigabit Ethernet operation, and CRC forwarding 

*(tse + 2) = *(tse + 2) | 0x0000004B; 

 

 

Thanks.
0 Kudos
6 Replies
Highlighted
Valued Contributor III
19 Views

What exactly is it that you don't understand? Each of those lines has a comment explaining what is done. Personally I would have used# defines instead of hard coded addresses and offsets though.

0 Kudos
Highlighted
Valued Contributor III
19 Views

 

--- Quote Start ---  

What exactly is it that you don't understand? Each of those lines has a comment explaining what is done. Personally I would have used# defines instead of hard coded addresses and offsets though. 

--- Quote End ---  

 

i can understand what is commented, but i want to know i.e. "*(tse + 3) = 0x116E6001;" means?, mac address is of 6 bytes and this is an hexadecimal number which means it is of only 4 bytes, also what does this 3 represents.
0 Kudos
Highlighted
Valued Contributor III
19 Views

Can you recommend me a book or anything to get knowledge about this programming nios II?

0 Kudos
Highlighted
Valued Contributor III
19 Views

I suggest that you read the triple speed ethernet user guide (https://www.altera.com/en_us/pdfs/literature/ug/ug_ethernet.pdf). In chapter 5 you have a list of all the registers. 

Page 5-3 describes the two registers used to define the MAC address. At offset 3 you have the register mac_0 which holds the 4 most significant bytes of the MAC address, and at offset 4 you have the 2 least significant. 

The line of codes you showed are one way to write to those TSE registers. I don't know how the rest of the tutorial is written, but if your CPU has a data cache you need to be careful when you use this way of talking to the hardware. You must either flush the cache when you are finished, or use an uncached access.
0 Kudos
Highlighted
Valued Contributor III
19 Views

Just wondering if someone can send or point me to the "Using Triple Speed Ethernet" Tutorial. Every link I find online seems to be dead. Thanks!

0 Kudos
Highlighted
Valued Contributor III
19 Views

 

--- Quote Start ---  

i can understand what is commented, but i want to know i.e. "*(tse + 3) = 0x116E6001;" means?, mac address is of 6 bytes and this is an hexadecimal number which means it is of only 4 bytes, also what does this 3 represents. 

--- Quote End ---  

 

 

Your questions are more C programming issues than TSE related. The best book (in my opinion) on this is still Kernighan and Ritchie "C Programming Language". 

 

You've defined tse as a pointer to an int. It is volatile since it points to hardware instead of RAM and can be changed outside your program. This stops the optimizer from making incorrect assumptions.  

 

Assuming an "int" is 4-bytes (I always add an "assert(sizeof(int) == 4);" to make sure), adding 3 will be the value of tse + 4 * 3 = 0x00102000 + 0xC = 0x0010200C. The "*" in front means assign a value so: 

 

"*(tse + 3) = 0x116E6001;" 

 

writes 0x116E6001 to address 0x0010200C. You could also write "tse[3] = 0x116E6001;" 

 

The tutorial was probably trying to be as straightforward as possible, but, as others have said, this is a horrible way to write code. Use defines or const int's.  

 

I prefer to write a packed C struct with all the registers named something sensible.
0 Kudos