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: 
Highlighted
Observer gordwait
Observer
11,399 Views
Registered: ‎09-18-2007

sleep function causes microblaze to restart my program?

V5 LX30T fpga, EDK 10.1.03,

Using xilkernel 4.00.a

 

I let BSB build a basic microblaze core, all default settings, and added a uart. 

 

I started with standalone OS, and downloaded the "TestApp_Memory" default app and ran it successfully, including the print command output to an external serial terminal via stdout. 

 

All I want to do next is add a "sleep(2);" command in between two prints. 

 

Found out the standalone OS doesn't do sleep, so I loaded xilkernel and added the hardware timer xps_timer to the soup, enabled the drivers etc. 

 

The "default" TestApp_Memory doesn't do anything but print two lines (since it doesn't want to test the memory the program is running from). 

 

The basic program unmodified does this:

 

   print("-- Entering main() --\r\n");

 

   print("-- Exiting main() --\r\n");


 This works as expected, printing each message just once. 

 

 

When I add a sleep command:

 

 

   print("-- Entering main() --\r\n");

    

   sleep(2);

 

   print("-- Exiting main() --\r\n");

 

 

The program prints the start line over and over again till I reset the cpu, with about a 2 second gap each time:

 

-- Entering main() --

-- Entering main() --

-- Entering main() --

-- Entering main() --

-- Entering main() --

 

etc. 

 

It's as if the sleep command  causes a CPU warm restart every time.

 

Any ideas? 

 

Tags (2)
0 Kudos
11 Replies
Historian
Historian
11,398 Views
Registered: ‎02-25-2008

Re: sleep function causes microblaze to restart my program?

sounds like a watchdog timer is enabled, and you are not petting the dog.

 

-a

----------------------------Yes, I do this for a living.
0 Kudos
Observer gordwait
Observer
11,395 Views
Registered: ‎09-18-2007

Re: sleep function causes microblaze to restart my program?

Nope, no watchdog present..  and I left the dog at home! :)

 

 

 

0 Kudos
Observer gordwait
Observer
11,393 Views
Registered: ‎09-18-2007

Re: sleep function causes microblaze to restart my program?

Seems like some library issue - I tried using usleep instead to see what it would do, and the code won't even compile.

I added    "usleep(10000);"

 

and the EDK gives me this:

 


......../my_microblaze/TestApp_Memory/src/TestApp_Memory.c:71: undefined reference to `usleep'

 

 

 

 

0 Kudos
Adventurer
Adventurer
11,327 Views
Registered: ‎01-04-2008

Re: sleep function causes microblaze to restart my program?

The strange behavior sounds like a heap/stack overflow.  Try generating a new linker-script that has a bigger stack and heap, and re-run your program.

 

-JasonI

0 Kudos
Xilinx Employee
Xilinx Employee
11,319 Views
Registered: ‎04-23-2008

Re: sleep function causes microblaze to restart my program?

I notice you mention that sleep() is called from main().  I suspect that a xilkernel thread can't be put  to sleep until the kernel has been initialized -- after

    xilkernel_main();
(which will not return) in which case you could sleep() in one of the threads that were created.  The scheduler isn't running yet otherwise.

 

-Brian

0 Kudos
Explorer
Explorer
10,292 Views
Registered: ‎01-09-2009

Re: sleep function causes microblaze to restart my program?

I have similar problem. I don't need to use any threads. I just need a sleep function to sleep the processor for some mili-seconds. However, since I needed to use sleep fucntion, I was forced to use xilkernel. The program compiled well, but when I ran it, it kept restarting. Then I found out that I have not used xilkernel_main in my program. So I added it, but the control never reached after the xilkernel_main function (that is expected). So my question is how I can use sleep function without having threads? I really need a sleep function but my program is a simple single thread program that interacts with the user.

0 Kudos
Observer gordwait
Observer
10,290 Views
Registered: ‎09-18-2007

Re: sleep function causes microblaze to restart my program?

I ended up making my own gord_sleep() subroutine and bypassing all this other nonsense.

All it does is waste some cpu cycles in a for loop (loopcount supplied by the caller), so it's very approximate - all I needed..

 

 

0 Kudos
Xilinx Employee
Xilinx Employee
7,622 Views
Registered: ‎01-07-2009

Re: sleep function causes microblaze to restart my program?

Doesn't the sleep function wait the for the specified number of seconds? So, sleep(2) should make it sleep for 2 seconds - the exact behavior that you are observing. If you need finer granularity, try usleep()

 

0 Kudos
Observer gordwait
Observer
7,616 Views
Registered: ‎09-18-2007

Re: sleep function causes microblaze to restart my program?

No, the original sleep was not behaving, it was causing a 2 second delay (so far so good) then rebooting the CPU so it re-enters main over and over again. It should only print the "entering main" message once.

 

0 Kudos
Newbie obl
Newbie
2,312 Views
Registered: ‎06-06-2012

Re: sleep function causes microblaze to restart my program?

I had the same behaviour when adding sprintf() in my code. By using this library call the stdio library was added to my code which needed a lot more heap space than is default. By increasing the heap from 0x400 to 0x1000 my code started running normally again.

0 Kudos
Explorer
Explorer
2,303 Views
Registered: ‎03-31-2011

Re: sleep function causes microblaze to restart my program?

IF u call the sleep function before calling xilkernel_main() then ur sleep function will not show any effect,now if u put the sleep in any statically created thread then it will work?now haow many threads u have?Look at ur .mss file if ur timer_configuration is true then u will find timer interval value=10ms

 

ie after each 10ms an interupt will genarate....

0 Kudos