-1

Recently, I started working on a project relevant to emac and came across few doubts and blockages with respect to implementation, and decided to post my Q here to get some advise and suggestions from experienced people.

At present, I am working on interfacing the EMAC-DM9161A module with my SAM3x - Taiji Uino board for high speed ethernet communication.I am using the library developed by Palliser which is uploaded on Github as elechouse/EMAC-Demo. In the source code - ethernet_phy.c, I came across this function to initialize the DM9161A PHY component as follows:

unit8_t ethernet_phy_init(Emac*p_emac, uint8_t uc_phy_addr, uint32_t mck);

Problem: The argument uint8_t uc_phy_addr is an 8 bit register through which I want to pass a 48 bit MAC address such as - 70-62-D8-28-C2-8E. I understand that, I can use two 32 bit registers to store the first 32 bit of the MAC address i.e. 70-62-D8-28 in one 32 bit register and the rest 16 bit MAC address i.e. C2-8E in another 32 bit register. However, I cannot do this, since I need to use the above ethernet_phy_init function in which a unit8_t is used to pass the 48 bit MAC address. So, I'd like to know, how to make this happen?

Another Question: I executed some code to understand by some trial methods and came across some doubts,here is the code:

  int main()
{
  unit8_t phy_addr =49;     //Assign a value 49 to 8 bit Reg
  int8_t phy_addr1 = 49;
  int phy_addr2 = 49;
  cout<<phy_addr;
  cout<<phy_addr1
  cout<<phy_addr2;
  getchar();
  return 0;
 }

Output Results:

 1
 1
 49

So my doubt is, why is the output being displayed in ASCII character wherever I use a 8 bit variable to store the value 49, but when I use a normal 32 bit int variable to store 49, it displays a decimal value of 49. Why does this happen?. And lastly how to store MAC address in an 8 bit register?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
PsychedGuy
  • 187
  • 3
  • 11
  • 8
    `And lastly how to store MAC address in an 8 bit register?` You don´t. That parameter has to mean something different than MACs. And the output part: Because cout works that way. (Btw., don´t call C++ function parameters "registers", and don´t call questions "doubts") – deviantfan Apr 15 '15 at 10:35
  • I am certain that, it means physical address, which is also known as Ethernet address or MAC address. But still, since you said, I will cross check on that. Thanks. – PsychedGuy Apr 15 '15 at 10:40
  • An 8-bit parameter *cannot* mean a 48-bit address, unless the API design is uttertly broken and the API absolutely unusable. – Angew is no longer proud of SO Apr 15 '15 at 10:47
  • The API design is proper, as I cross checked it with other sources online. Definitely I am missing out something and getting it wrong . So working on figuring it out. Even if I convert the MAC address from Hexa decimal to decimal, still cannot assign the value to uint8_t. Now I am trying my way through storing the decimal values by creating an array[3]. – PsychedGuy Apr 15 '15 at 11:23
  • It is probably a physical address on the bus in the computer or somesuch. Little if nothing to do with MAC. – Yakk - Adam Nevraumont Apr 15 '15 at 11:39
  • `The API design is proper, as I cross checked it with other sources online.` So what? Just because it´s not an error in the docs, the whole thing could be garbage nonetheless. But again, it can´t be a MAC: – deviantfan Apr 15 '15 at 11:43
  • 1
    Pigeonhole principle. There are billions of devices with unique MAC addresses, there are 256 unique values of a `uint8_t`. That is already sufficient to establish that no matter what mapping you try, the MAC address wont fit. – MSalters Apr 15 '15 at 11:55
  • @Yakk: You're likely correct. It's not even 8 bits, apparently: `ETH_PHY_MAX_ADDR` is 31. That means just 5 bits, but C++ doesn't have 5 bits variables. – MSalters Apr 15 '15 at 11:58
  • Yeah guys. You all are right, my bad. I just figured out, that its not the MAC address. It has to do something with the bus address of the MII. Damn! :(. I am in process and close to the figuring it out. Thank you all for your inputs. – PsychedGuy Apr 15 '15 at 12:25

3 Answers3

0

About second question:

uint8_t/int8_t is same as unsigned/signed char and cout will handli it as char. Use static_cast<int> to print as number.

About first quiestion:

I never worked with emac, but judging by this example mac should be set this way:

#define ETHERNET_CONF_ETHADDR0                        0x00
#define ETHERNET_CONF_ETHADDR0                        0x00
#define ETHERNET_CONF_ETHADDR1                        0x04
#define ETHERNET_CONF_ETHADDR2                        0x25
#define ETHERNET_CONF_ETHADDR3                        0x1C
#define ETHERNET_CONF_ETHADDR4                        0xA0
#define ETHERNET_CONF_ETHADDR5                        0x02

static uint8_t gs_uc_mac_address[] =
        { ETHERNET_CONF_ETHADDR0, ETHERNET_CONF_ETHADDR1, ETHERNET_CONF_ETHADDR2,
            ETHERNET_CONF_ETHADDR3, ETHERNET_CONF_ETHADDR4, ETHERNET_CONF_ETHADDR5
};

emac_options_t emac_option;
memcpy(emac_option.uc_mac_addr, gs_uc_mac_address, sizeof(gs_uc_mac_address));
emac_dev_init(EMAC, &gs_emac_dev, &emac_option);
trvecvlt
  • 102
  • 1
  • 10
0

Regarding your second question: the first 2 variables are 8bit (one signed and one unsigned), so the ostream assumes they are chars (also 8bit wide) and displays the char representation for them ("1" = ASCII 49).

As for original question, i browsed a little bit the Atmel sources and the MAC address has nothing to do in ethernet_phy_init (all is at a much lower level): uc_phy_addr - seems to be interface index mck - seems to be a timer related value.

CristiFati
  • 38,250
  • 9
  • 50
  • 87
0

I figured it out, so I am going to answer my own question for those beginners like me who may encounter this same doubt.

Answer: As suggested by the members in the comments, yes they were right and thanks to them. The function parameter uint8_t uc_phy_addr represents the 5 bit port address in the PHY chip - Register and not the MAC Address, hence the address is set as 0x01 to enable only the receive pin and keeping the other 4 bits 0. The 4th bit is the CSR which is also set 0 in this case (for more details, Please refer data sheet of DM9161A).

PsychedGuy
  • 187
  • 3
  • 11