- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-06-2009 11:13 AM
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?
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-06-2009 11:34 AM
sounds like a watchdog timer is enabled, and you are not petting the dog.
-a
----------------------------------------------------------------
Yes, I do this for a living.
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-06-2009 11:43 AM
Nope, no watchdog present.. and I left the dog at home! :)
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-06-2009 12:02 PM
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_
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-11-2009 10:08 AM
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
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-11-2009 01:25 PM
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
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-16-2009 12:41 PM
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.
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-16-2009 12:50 PM
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..
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-07-2012 09:25 AM
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()
Re: sleep function causes microblaze to restart my program?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-07-2012 10:01 AM
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.











