UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer jishnukd
Observer
16,657 Views
Registered: ‎06-16-2009

time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

Hi,

 

I wrote the following codes for measuring the execution time of certain parts of my code using time.h functions:

 

Code (1)

 

#include "xparameters.h"
#include "stdio.h"
#include "xbasic_types.h"
#include "uartlite_header.h"
#include "mb_interface.h"
#include "time.h"
#include "sys/time.h"
#include "sys/types.h"

#define TVDIFF(tv1, tv2) ( ((tv2).tv_sec - (tv1).tv_sec)*1000000 + ((tv2).tv_usec - (tv1).tv_usec) )

int main (void) {

    struct timeval time_start, time_end;
    unsigned int time_diff;
      
    Xuint32 arr[400],i;
    for(i=0;i<400;i++)
        arr[i]=i;
    
    gettimeofday(&time_start, NULL);
    
    for(i=0;i<400;i++)
        arr[i]=2*arr[i];
    
    gettimeofday(&time_end, NULL);
    
    time_diff = TVDIFF(time_start, time_end);
    xil_printf("\r\nTime taken is %d usec\n\r", time_diff);

    return 0;
}

 

And the error that I get is:

 

/cygdrive/c/DOCUME~1/DR855C~1.KAY/LOCALS~1/Temp/ccc3iSFj.o: In function `main':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:21: undefined reference to `gettimeofday'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:26: undefined reference to `gettimeofday'
collect2: ld returned 1 exit status
make: *** [TestApp_Peripheral/executable.elf] Error 1

 

 

Code (2)

 

#include "xparameters.h"
#include "stdio.h"
#include "xbasic_types.h"

#include "uartlite_header.h"
#include "mb_interface.h"include "time.h"

#include "sys/time.h"
#include "sys/types.h"

int main (void) {

    clock_t c1,c2;  

    double dur;

 

    Xuint32 arr[400],i;
    for(i=0;i<400;i++)
        arr[i]=i;
   
    c1=clock();

  
    for(i=0;i<400;i++)
        arr[i]=2*arr[i];

   

    c2=clock();

   
    dur=(double) ((c2-c1)/CLK_TCK);

    xil_printf("\r\nDuration is %f", dur);

    return 0;
}

 

And the error that I get is:

 

./microblaze_0/lib//libc.a(timer.o): In function `_gettimeofday_r':
: undefined reference to `gettimeofday'
./microblaze_0/lib//libc.a(timer.o): In function `_times_r':
: undefined reference to `times'
collect2: ld returned 1 exit status
make: *** [TestApp_Peripheral/executable.elf] Error 1

 

The error that I get on my friend's PC is:

 

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: region ilmb_cntlr_0_dlmb_cntlr_0 is full (TestApp_Peripheral/executable.elf section .text)

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .init [00000050 -> 00000077] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .fini [00000078 -> 00000093] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .rodata [00000094 -> 00000903] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .sdata2 [00000904 -> 00000907] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .data [00000908 -> 000010bf] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .ctors [000010c0 -> 000010c7] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .dtors [000010c8 -> 000010cf] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .eh_frame [000010d0 -> 000010d3] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .jcr [000010d4 -> 000010d7] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .bss [000010d8 -> 000011fb] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .heap [000011fc -> 000015ff] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: section .stack [00001600 -> 000019ff] overlaps section .text [00000050 -> 00012dfb]

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: TestApp_Peripheral/executable.elf: section .text lma 0x50 overlaps previous sections

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: TestApp_Peripheral/executable.elf: section .fini lma 0x78 overlaps previous sections

/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../../../../microblaze-xilinx-elf/bin/ld.real: TestApp_Peripheral/executable.elf: section .rodata lma 0x94 overlaps previous sections

./microblaze_0/lib//libc.a(timer.o): In function `_gettimeofday_r':

: undefined reference to `gettimeofday'

./microblaze_0/lib//libc.a(timer.o): In function `_times_r':

: undefined reference to `times'

collect2: ld returned 1 exit status

make: *** [TestApp_Peripheral/executable.elf] Error 1

 

 

 

Code (3)

 

#include "xparameters.h"
#include "stdio.h"
#include "xbasic_types.h"
#include "uartlite_header.h"
#include "mb_interface.h"
#include "time.h"

#include "sys/time.h"
#include "sys/types.h"

int main (void) {

    time_t t1,t2;  

    Xuint32 arr[400],i;
    for(i=0;i<400;i++)
        arr[i]=i;
         
    t1=time(NULL);
 
    for(i=0;i<400;i++)
        arr[i]=2*arr[i];  

    t2=time(NULL);
 
    xil_printf("\r\nDuration is %ld", t2-t1);

    return 0;
}

 

Here I'm not getting any error in build process but I'm getting both t1 and t2 zero; which is not the desired output.

 

Please guide me as to where I've slipped in all the three cases,

 

Regards,

Jishnu.

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
20,579 Views
Registered: ‎01-18-2008

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

Like I said, you need to read through the appropriate API section for every xilkernel call you use. In this case if you go to the API for xget_clock_ticks, you'll see a link to Configuring Software Timers, which points out that you need to set config_time xilkernel attribute.

 

Linker errors would occur if you don't specify -lxilkernel.

 

Personally I prefer Linux for everything, so that is what I'd suggest. The only pain point with Linux might be in getting the cable drivers installed, but once you get past that, it is really the best environment for FPGA development. 

9 Replies
Xilinx Employee
Xilinx Employee
16,649 Views
Registered: ‎01-18-2008

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution
Well, microblaze when used with standalone platform, just does not have an implementation of time functions. This is because the standalone library cannot assume anything about your system - some systems may not have a timer at all. You have multiple options to proceed though: If all you want is cycle count, then use the low level timer (xps_timer) routines to start and stop the timer. If you want to keep you software simple, then use linux or uclinux on microblaze. Then your typical desktop code should work fine.
16,648 Views
Registered: ‎08-21-2008

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

Hello.

As far as your code 2 is concerned it seems that the BRAM memory is full and unable to store further data so you have to increase the BRAM memory to 32KB or may be 64 KB if problem persists. 

Best of luck.
--
Unlimited in my Limits.
0 Kudos
Observer jishnukd
Observer
16,631 Views
Registered: ‎06-16-2009

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

@vsiva

 

I got your point. If I change my OS to Xilkernel, would it be possible for me to enable timing functions? In the description, it says, "Provides POSIX like kernel services like threads, scheduling, synchronization, timer etc. Requires an OPB timer on a MicroBlaze platform". So, would the same code be applicable to the Xilkernel OS?

 

I tried to use the xps_timer peripheral for getting an approximate idea of the time taken, but I think there is a small place where I'm going wrong. I posted that problem at http://forums.xilinx.com/xlnx/board/message?board.id=EDK&thread.id=9320 but unfortunately haven't got any replies till now.

 

@prateek_bhatt

 

Yes. It seems so. I'll try changing my OS first, unless I'm successful with xps_timer.

Message Edited by jishnukd on 06-23-2009 05:58 AM
0 Kudos
Xilinx Employee
Xilinx Employee
16,612 Views
Registered: ‎01-18-2008

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

Yes, you can get an estimate if you use xilkernel too. Check the xilkernel docs for the APIs. Note that with xilkernel, lots of things are configurable through parameters, so make sure you configure it appropriately.

 

I couldn't find the issue with the timer code - it looks ok to me. The easiest thing to do is to step through the code, and make sure that the timer and intc are properly initialized. You might want to start with a working timer example code (look in the timer drivers folder), and then modify it to suit your needs. 

0 Kudos
Observer jishnukd
Observer
16,601 Views
Registered: ‎06-16-2009

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution
>> I couldn't find the issue with the timer code - it looks ok to me

I wrote that code by referring to the API docs of xps_timer and a sample code at http://newsgroups.derkeiler.com/Archive/Comp/comp.arch.fpga/2008-02/msg00854.html Is there anything wrong with the image of the system assembly view that I've attached?
 



Also, I needed your suggestion on one more thing; I'm planning to port uClinux later on. What do you recommend for a beginner or newbie? Do I use:

1) two PCs: with Windows (Xilinx ISE and EDK) on one and Linux (uClinux) on other
2) or use Xilinx tools also on Linux platform (I read somewhere that CentOS works fine) (PS: I've got very little experience of linux platforms)




I included Xilkernel, specified xps_timer_1 in the systmr_spec in Software Platform Settings and wrote this code:

#include "xmk.h"
#include "xparameters.h"
#include "stdio.h"
#include "xbasic_types.h"
#include "uartlite_header.h"
#include "mb_interface.h"
#include "sys/timer.h"

int main (void) { 
 unsigned int t1,t2; 

 Xuint32 arr[400],i;
 for(i=0;i<400;i++)
  arr[i]=i;
 
 t1=xget_clock_ticks();
 
 for(i=0;i<400;i++)
  arr[i]=2*arr[i];
 
 t2=xget_clock_ticks();
 
 xil_printf("Clock ticks elapsed: %d \n\r", t2-t1);
 
 //xilkernel_main();

 while(1) {
 
 }

  return 0;
}

But I got this message:

/cygdrive/c/DOCUME~1/DR855C~1.KAY/LOCALS~1/Temp/ccqrnb08.o: In function `main':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:32: undefined reference to `xget_clock_ticks'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:37: undefined reference to `xget_clock_ticks'
collect2: ld returned 1 exit status
make: *** [TestApp_Peripheral/executable.elf] Error 1

If I uncomment the xilkernel_main() call, I get additional errors like:

/cygdrive/c/DOCUME~1/DR855C~1.KAY/LOCALS~1/Temp/ccCts2qW.o: In function `main':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:32: undefined reference to `xget_clock_ticks'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/TestApp_Peripheral/src/TestApp_Peripheral.c:37: undefined reference to `xget_clock_ticks'
./microblaze_0/lib//libxil.a(main.o): In function `xilkernel_init':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/main.c:107: undefined reference to `hw_init'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/main.c:121: undefined reference to `init_idle_task'
./microblaze_0/lib//libxil.a(pthread.o): In function `sys_pthread_exit':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/pthread.c:273: undefined reference to `xmk_enter_kernel'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/pthread.c:267: undefined reference to `xmk_leave_kernel'
./microblaze_0/lib//libxil.a(pthread.o): In function `sys_pthread_create':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/pthread.c:210: undefined reference to `setup_initial_context'
./microblaze_0/lib//libxil.a(sched.o): In function `scheduler':
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/sched.c:101: undefined reference to `save_context'
/cygdrive/e/ddrive/JISHNU/7thProjStar1/microblaze_0/libsrc/xilkernel_v4_00_a/src/src/sys/sched.c:106: undefined reference to `restore_context'
collect2: ld returned 1 exit status
make: *** [TestApp_Peripheral/executable.elf] Error 1

Before proceeding with writing the code, I went throught the Xilkernel section in oslib_rm.pdf, which states:
"Your application must provide a main( ) which is the starting point of execution for your Kernel image. Inside your main( ), you can do any initialization and setup that you need to do. The Kernel remains unstarted and dormant. At the point where your application setup is complete and you want the Kernel to start, you must invoke, xilkernel_main( ) that starts off the Kernel, enables interrupts, and transfers control to your application processes, as configured."


So, I think the kernel is not configured properly yet. Any idea as to what the problem might be?
Message Edited by jishnukd on 06-23-2009 10:21 PM
0 Kudos
Xilinx Employee
Xilinx Employee
20,580 Views
Registered: ‎01-18-2008

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

Like I said, you need to read through the appropriate API section for every xilkernel call you use. In this case if you go to the API for xget_clock_ticks, you'll see a link to Configuring Software Timers, which points out that you need to set config_time xilkernel attribute.

 

Linker errors would occur if you don't specify -lxilkernel.

 

Personally I prefer Linux for everything, so that is what I'd suggest. The only pain point with Linux might be in getting the cable drivers installed, but once you get past that, it is really the best environment for FPGA development. 

Observer jishnukd
Observer
16,558 Views
Registered: ‎06-16-2009

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution
I read about configuring the Xilkernel OS. After that I set my MSS file in the same way as set by the sample code given in ML505_MB_XMK_92.zip provided on the Xilinx website. So my MSS file was ok. But it was a linker error. Once I included xilkernel in the "Libraries to link against", it worked fine. Thanks a lot!
0 Kudos
Observer jishnukd
Observer
16,493 Views
Registered: ‎06-16-2009

Re: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

>> Personally I prefer Linux for everything, so that is what I'd suggest. The only pain point with Linux might be in getting the cable drivers installed, but once you get past that, it is really the best environment for FPGA development.

 

In which OS am I more likely to get support for the Xilinx USB cable drivers? Fedora or CentOS?

0 Kudos
Highlighted
Visitor liuyuan1764
Visitor
6,657 Views
Registered: ‎03-25-2015

回复: time.h error with Microblaze on Virtex-5 with EDK 9.2i

Jump to solution

i met the same problem,have you solved? if you solved the problem,could you tell me how to do it please!

0 Kudos