Forum Discussion
Need an information
Hello everyone,
I need to fetch the current time when I use Nios II IDE (v.9.1). Can anyone write me the syntax in C language. I tried one but it does nothing. Thanks to all for your time! Best regards!8 Replies
- Altera_Forum
Honored Contributor
Well you have the time functions, as described here (http://sources.redhat.com/newlib/libc.html#timefns), but for this to work you'll have to set the time first. If you don't, your application will be on January 1st, 1970 each time it starts.
- Altera_Forum
Honored Contributor
Thanks Daixiwen!
I found the functions in the "altera.components" folder but you confused me now a little. Why I have to set the time, can I simple fetch the time value with time, gmtime or localtime functions from the system without seting the time value? I saw that it counts from the 1970 year. Thanks. - Altera_Forum
Honored Contributor
Daixiwen I used the settimeofday function to set the time but it shows me
every time the same time when I start my application. Do I have to setup a system timer to compute the new time (e.g. xx number of ticks per second to increase the value of seconds)? Have you an idea? Best regards, Zodrax - Altera_Forum
Honored Contributor
If your system doesn't have an external battery powered RTC clock, it has no way of knowing the time. In that case it will start at January 1st 1970. To set the correct time at start-up, you can either use a client-server approach (port a NTP client and have it connect to an NTP server) or ask the user to type in the actual time and date.
Once the time is set, it will increase automatically and you can read it with gettimeofday or other time functions. - Altera_Forum
Honored Contributor
Thank you Daixiwen.
I have only the DE1 board connected to my notebook and tried to fetch the time from my OS from notebook, but unsuccessful. As the supply for my board I use my notebook over the USB port. Best Regards. - Altera_Forum
Honored Contributor
So you don't have any network connection, which will make it difficult to use NTP.
You can either type the time yourself at boot time by having your NIOS application asking it on the JTAG uart, or create your own protocol, with a small software on your PC that would send automatically the time to your NIOS application, either through the Uart or by using the console tools. The first solution is the easiest to implement. - Altera_Forum
Honored Contributor
So if I would type the tiime at boot time do I have to write also a small code so that the time can increase?
How would I implement the second above solution, e.g to write the protocol? I never tried it. Thank you very much for your time and solutions Daixiwen! Best regards! - Altera_Forum
Honored Contributor
No, once you've set up the system time in your application, it will increase automatically.
For the protocol, it really depends on your application and what kind of resources you have.