Click to See Complete Forum and Search --> : vxWorks nanosleep...help?


datta016
June 10th, 2009, 11:28 AM
Hey everyone,

I wasn't too sure where to post this, so I figured General Topics would be a good start. I'm relatively new to vxWorks and RTOS in general. I have a quick question concerning nanosleep() in vxWorks. For some reason I just can't get it to work. I also can't find any examples of its usage through google (which was a shock, I'm sure I'm just not searching correctly).

All I am trying to do is set up the function in order to delay my task by 1 second (I'm trying to venture into POSIX commands as I am already familiar with taskDelay, for instance).

I am using #include <time.h> as the library (I think this is the correct one?). Aside from that I am pretty sure I am just screwing up the setup of the function. Here it is:

struct timespec nsTime;
nsTime.tv_sec = 1;
nsTime.tv_nsec = 0;

int nanosleep(nsTime, NULL);
/*Below this point is the code for the task I want delayed*/

When I attempt to compile I am presented with the following errors:

-warning: left-hand operand of comma has no effect
-error: initializor expression list treated as compound expression
-warning: unused variable 'nanosleep'

Any help would be great. Thank you in advance!

datta016
June 10th, 2009, 05:11 PM
Nice... seems all I had to do was get rid of the 'int' in front of nanosleep() and add an '&' in front of nsTime inside of nanosleep:

<#include time.h>
struct timespec nsTime;
nsTime.tv_sec = 1;
nsTime.tv_nsec = 0;

nanosleep(&nsTime, NULL);
/*Below this point is the code for the task I want delayed*/

Job's done!

datta016
June 10th, 2009, 05:16 PM
Hm, I posted the answer twice I think... I didn't realize a moderator had to verify it first. My bad.. thought it was a problem on my end.

datta016
June 10th, 2009, 05:17 PM
Hm, I guess I didn't. But the answer is still not showing up... just needed to change what I had to this:

struct timespec nsTime;
nsTime.tv_sec = 1;
nsTime.tv_nsec = 0;

nanosleep(&nsTime, NULL);
/*Below this point is the code for the task I want delayed*/