Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12366 Discussions

simple friendly wait timer?

Honored Contributor I


I just want a simple OS friendly wait timer. I want to wait for 20ms and then continue my loop. However, I dont want just write some proccesor intensive loop (which obviously doesnt work in a multitasking enviroment) I just want some OS wait() or sleep() function where you specifey the time in milliseconds, and the application sleeps, returns the proccesor to the OS, and then wakes up to finish what it was doing in 20 milliseconds. 


Is there such a function built into C? 

What do I need to include to access this?<#EMO_DIR#>/blink.gif  


0 Kudos
2 Replies
Honored Contributor I

If you&#39;re in a linux environment, the function that you want is usleep(unsigned long usec). Please note, though, that it only sleeps for a minimum of the specified number of milliseconds -- it might sleep longer. Life is much harder if you&#39;re trying to go for guaranteed time intervals.

Honored Contributor I

In order to use usleep() I needed to include: 


# include <unistd.h> 


Thanks for all your help should work for what I need.