element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
ZedBoard Hardware Design Zynq reads the internal temperature of the PHY chip.
  • Forums
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Avnet Boards Forums requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 4 replies
  • Answers 1 answer
  • Subscribers 41 subscribers
  • Views 211 views
  • Users 0 members are here
  • zedboard
Related

Zynq reads the internal temperature of the PHY chip.

jun_ling_
jun_ling_ over 1 year ago

Hi folks:

 

I am planning to write code on the PS (ARM) side to read the temperature of the PHY chip, namely, Marvell 88E1512 (eth0) on the zedboard, but to no avail.

Datasheet of the Marvell 88E1512 chip states that one "can read the temperature from register_26_6.4:0 or register_27_6.7:0". The data read  from there (by calling ioctl(socket, SIOCSMIIREG, &reg_info) ), unfortunately, is either 0x0000 or 0xFFFF.

What is the best practice to achieve this? Any input / recommendation would be greatly appreciated.

 

Additionally, what is the difference between phy_id and page?

 

Thank you for reading.

  • Reply
  • Cancel
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 1 year ago in reply to jun_ling_ +1 verified

    I've had a very quick look at your code  - I don't have time to pick through it all but:

     

    The phy has an ID, that's in case there are more than one on the MDIO bus,

    Inside the phy are several pages…

  • michaelkellett
    0 michaelkellett over 1 year ago

    Have you set the page address ?

    Register 22 in any page sets the page to be accessed.

     

    MK

    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • jun_ling_
    0 jun_ling_ over 1 year ago in reply to michaelkellett

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <linux/mii.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/ioctl.h>
    #include <net/if.h>
    #include <linux/sockios.h>
    #include <linux/types.h>
    #include <netinet/in.h>
    #include <unistd.h>
    #include <time.h>
    
    struct mii_ioctl_data
    {
        __u16 phy_id;
        __u16 reg_num;
        __u16 val_in;
        __u16 val_out;
    }
    
    void help()
    {
        printf("mdio:\n");
        printf("read operation: mdio phy_addr reg_addr\n");
        printf("write operation: mdio  phy_addr reg_addr value\n");
        printf("For example:\n");
        printf("mdio eth0 6 27\n");
        printf("mdio eth0 6 27 0x12\n\n");
    }
    
    
    int main(int nArgc, char *pArgv[])
    {
        if (nArgc == 1 || !strcmp(pArgv[1], "-h"))
        {
            help();
            return 0;
        }
    
        struct mii_ioctl_data *pMiiData = NULL;
        struct ifreq oRegInfo;
        memset(&oRegInfo, 0, sizeof(oRegInfo));
        strncpy(oRegInfo.ifr_name, pArgv[1], IFNAMSIZ - 1);
        printf("ifreq name : %s\n", oRegInfo.ifr_name);
    
        int nRet = 0;
        int nSockFd = -1;
    
        do
        {
            nSockFd = socket(PF_LOCAL, SOCK_DGRAM, 0);
            if (nSockFd < 0)
            {
                break;
            }
            // get phy address in smi bus
            printf("Get phy address in smi bus...\n");
            nRet = ioctl(nSockFd, SIOCGMIIPHY, &oRegInfo);
            if (nRet < 0)
            {
                break;
            }
    
            pMiiData = (struct mii_ioctl_data*) &oRegInfo.ifr_data;
            if (4 == nArgc)
            {
                pMiiData->phy_id = (uint16_t) strtoul(pArgv[2], NULL, 0);;
                pMiiData->reg_num = (uint16_t) strtoul(pArgv[3], NULL, 0);
                printf("pht_id = %d, reg_num = %d\n", pMiiData->phy_id , pMiiData->reg_num);
    
                for (int nIdx = 0; nIdx != 1000; ++nIdx)
                {
                    nRet = ioctl(nSockFd, SIOCGMIIREG, &oRegInfo);
                    if (nRet < 0)
                    {
                        printf("get register value failed\n");
                        break;
                    }
                    printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n\n",
                    pMiiData->phy_id, pMiiData->reg_num, pMiiData->val_out);
                    int nTempValue = ((pMiiData->val_out & 0xFF) - 25) * 1000;
                    printf("Round %d temperature : %d\n", nIdx, nTempValue);
    
                    struct timespec t;
                    t.tv_sec = 1;
                    t.tv_nsec = 0;
                    nanosleep(&t, NULL);
                }
            }
            else if (5 == nArgc)
            {
                pMiiData->phy_id = (uint16_t) strtoul(pArgv[2], NULL, 0);;
                pMiiData->reg_num = (uint16_t) strtoul(pArgv[3], NULL, 0);
                pMiiData->val_in = (uint16_t) strtoul(pArgv[4], NULL, 0);
                printf("pht_id = %d, reg_num = %d, set_value = %d\n", pMiiData->phy_id , pMiiData->reg_num, pMiiData->val_in);
                nRet = ioctl(nSockFd, SIOCSMIIREG, &oRegInfo);
                if (nRet < 0)
                {
                    printf("set register value failed\n");
                    break;
                }
                printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n\n",
                pMiiData->phy_id, pMiiData->reg_num, pMiiData->val_in);
    
                for (int nIdx = 0; nIdx != 1000; ++nIdx)
                {
                    nRet = ioctl(nSockFd, SIOCGMIIREG, &oRegInfo);
                    if (nRet < 0)
                    {
                        printf("get register value failed\n");
                        break;
                    }
                    printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n\n",
                    pMiiData->phy_id, pMiiData->reg_num, pMiiData->val_out);
    
                    int nTempValue = ((pMiiData->val_out & 0xFF) - 25) * 1000;
                    printf("Round %d temperature : %d\n", nIdx, nTempValue);
    
                    struct timespec t;
                    t.tv_sec = 1;
                    t.tv_nsec = 0;
                    nanosleep(&t, NULL);
                }
            }
        } while (0);
    
        if (nSockFd >= 0)
        {
            close(nSockFd);
            nSockFd = -1;
        }
        return 0;
    }

     

    My code goes like this. Input argument examples are provided in sub-function HELP starting on line 23 above.

    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 1 year ago in reply to jun_ling_

    I've had a very quick look at your code  - I don't have time to pick through it all but:

     

    The phy has an ID, that's in case there are more than one on the MDIO bus,

    Inside the phy are several pages of registers, and the page you get access to depends on what is in register 22 which is common to all pages

     

    Your code only seems to set phy_id and reg_num to access registers - you have to look after the page as well.

     

    Find some registers on different pages in the data sheet and check the contents. Then adjust register 22 and do it again.

    I think you'll find that you are operating with register 22 set to zero (power up default).

     

    The Marvel data sheet does describe all this (I can't quite go so far as to suggest that it explains any of it very well )

     

    MK

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • jun_ling_
    0 jun_ling_ over 1 year ago in reply to michaelkellett

    Hi MK:

     

    Thanks for the tip, and that does the trick.

    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube