Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

NIOS II (system time problem)

Good evening, 


I have an issue to get my "local" system time in nios 2 c/c++. At first I thought it could be easily implemented by using <time.h> library and its provided functions. 

I used localtime() as well as gmtime() to compare some results, but everything I could get were somehow constants. 


This is an example of my testing code 



time_t t=time(NULL); 

struct tm ts; 




unsigned char secs=ts.tm_sec; // secs has a range from 0..61 ....dont know why tm_sec is integer type when 6 bits are fully sufficient 

unsigned char min = ts.tm_min; // minutes 

unsigned char hour = ts.tm_hour;  

unsigned char day = ts.tm_mday; // and so on  

unsigned char month = ts.tm_mon; 

unsigned char year = ts.tm_year; // Actual date from 1900 ....meaning 2016-1900 should be =116 ...8 bits are enough in this case 




When I watch that values with printf() I am getting the same constants which dont fit at all. Same constants are shown when I use localtime()-,gmtime_r()- and gmtime()-function. 


Seconds are 0x3B // seconds and minutes are always the same the way wrong 

Minutes are 0x3B // 

Hour is 0x17 // wrong 

Day is 0x1F // its the 31.12.16 ?? ... wrong 

Month is 0xB // Has a range from 0 to 11 ...meaning 11 represents decembre.. result is OK 

Year is 0x45 // decimal 69 ..... MS Visual Studio showed 116 (2016-1900) ..wrong 


I mean I ve used same functions in microsoft visual studio to make some comparisons.MS VS is actually showing me the right results which I am expecting but the NIOS processor is doing some unknown stuff. 


I ve made some research in the internet with " getting system time altera " and i think someone has sayed that the NIOS processor isnt able to use these mentioned functions properly. But how u re supposed to use this library correctly? 


I ve seen and read some different approachs like using ntp. But what can I do if I am only limited to a de0 nano development kit which has no ethernet protocol and so on for some testing.  


I think I ve read somewhere that u can communicate with the jtag uart and forcing it to send u the correct time and date. I ve seen some altera s tutorials how to send data to the jtag uart. But how am i supposed to force the jtag uart to send me the rigth time and date frame?
0 Kudos
0 Replies