Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

System ID and creation timestamp (sysid)

Hi:

Perhaps this is very simple but....

I'd like to use the SysId component timestamp field for system validation purposes, but not as simple as the long lvalue compare the HAL does, what I want is to convert this timestamp value (seconds elapsed from january 1st, 1970) to year, month, day,...

Has anyone done it before? Is there any code available for doing this convertion?

Thanks,

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi VLorenzo,

    > I want is to convert this timestamp value (seconds elapsed from january 1st, 1970) to

    > year, month, day,

    <<snip>>

    > Has anyone done it before? Is there any code available for doing this convertion?

    Yes, the u-boot code supports this. Here&#39;s a snip of code from cpu/nios2/sysid.c (code

    is available at: http://www.psyent.com/download (http://www.psyent.com/download) )

    void display_sysid (void)
    {
            struct nios_sysid_t *sysid = (struct nios_sysid_t *)CFG_NIOS_SYSID_BASE;
            struct tm t;
            char asc;
            time_t stamp;
            stamp = readl (&sysid->timestamp);
            localtime_r (&stamp, &t);
            asctime_r (&t, asc);
            printf ("SYSID : %08x, %s", readl (&sysid->id), asc);
    }

    I believe the hal has support for asctime_r and localtime_r ... if not, you can just

    hoist the code from the u-boot sources.

    Regards,

    --Scott