Sign In

Don't have a Xilinx account yet?

  • Choose to receive important news and product information
  • Gain access to special content
  • Personalize your web experience on Xilinx.com

Create Account

Username

Password

Forgot your password?
XClose Panel
Xilinx Home
Reply
Visitor
gordwait
Posts: 17
Registered: ‎09-18-2007
0

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? 

 

Expert Contributor
bassman59
Posts: 4,679
Registered: ‎02-25-2008
0

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.
Visitor
gordwait
Posts: 17
Registered: ‎09-18-2007
0

Re: sleep function causes microblaze to restart my program?

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

 

 

 

Visitor
gordwait
Posts: 17
Registered: ‎09-18-2007
0

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'

 

 

 

 

Regular Contributor
jagron
Posts: 77
Registered: ‎01-04-2008
0

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

Xilinx Employee
brianhill
Posts: 142
Registered: ‎04-23-2008
0

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

Super Contributor
aminfar1
Posts: 182
Registered: ‎01-09-2009
0

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.

Visitor
gordwait
Posts: 17
Registered: ‎09-18-2007
0

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..

 

 

Xilinx Employee
william.kafig
Posts: 5
Registered: ‎01-07-2009
0

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()

 

Visitor
gordwait
Posts: 17
Registered: ‎09-18-2007
0

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.