Shop OBEX P1 Docs P2 Docs Learn Events
sleep ? — Parallax Forums

sleep ?

RaymanRayman Posts: 14,665
edited 2013-03-29 11:58 in Propeller 1
Is there a regular sleep function that works?

Tried sleep(), but it wasn't recognized.
Tried including unistd.h, but that gives errors...

Noticed in one demo that Steve made his own msleep and usleep functions...
Is that what we need to do?

Comments

  • ersmithersmith Posts: 6,054
    edited 2013-03-29 09:45
    There's a sleep() function in the library, and usleep() too. Prototypes for both should be present in <unistd.h>. What errors did you get?

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-03-29 10:36
    1> c:\propgcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/cog.h:96:21: error: previous declaration of 'unsigned int _clkfreq' with 'C++' linkage

    1> c:\propgcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/time.h:9:16: error: conflicts with new declaration with 'C' linkage
  • SRLMSRLM Posts: 5,045
    edited 2013-03-29 10:39
    Try the extern "C" command around the plain C stuff.
    #ifdef __cplusplus
    extern "C" {
    // Plain C stuff
    }
    #endif
    

    Edit: although I haven't needed to use it in several months of intense PropGCC work. Can you post your code?
  • ersmithersmith Posts: 6,054
    edited 2013-03-29 10:58
    Rayman wrote: »
    1> c:\propgcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/cog.h:96:21: error: previous declaration of 'unsigned int _clkfreq' with 'C++' linkage

    1> c:\propgcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/time.h:9:16: error: conflicts with new declaration with 'C' linkage

    It sounds like propeller.h is missing an extern "C" declaration. As SRLM noted, you can wrap the whole thing up as follows in your program:
    #ifdef __cplusplus
    extern "C" {
    #endif
    #include <propeller.h>
    #ifdef __cplusplus
    }
    #endif
    
    while you're waiting for the header file to be fixed.

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-03-29 11:05
    I think I have an easier fix...

    Just moved propeller.h after unistd.h and it seems happy now...
  • jazzedjazzed Posts: 11,803
    edited 2013-03-29 11:58
    Rayman wrote: »
    I think I have an easier fix...

    Just moved propeller.h after unistd.h and it seems happy now...

    Eventually the real fix will be added, we don't want some order dependencies. It's fine for a temporary work-around.

    BTW, usleep and friends will give at least the amount of time you would like and is appropriate for threading. Use waitcnt for deterministic delays (though it is not appropriate to use during threading).
Sign In or Register to comment.