Shop OBEX P1 Docs P2 Docs Learn Events
Header bug? — Parallax Forums

Header bug?

blittledblittled Posts: 681
edited 2011-11-25 16:01 in Propeller 1
I am building a library and have the following code
void PULSE(int pin, uint32_t duration)
{
    int mask = 1 << pin;

    DIRA |= mask;

    OUTA |= mask;
    DELAY(duration);
    OUTA &= ~mask;
}

void DELAY(uint32_t duration)
{
    uint32_t time;
   
    time = CNT;
    waitcnt(duration + time);
}

header file
void PULSE(int pin, uint32_t duration);

void DELAY(uint32_t duration);

This produces the error "unknown type name uint32_t" error when compiling with a file using #include in the header file for both functions, should this happen?

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2011-11-25 15:04
    blittled wrote: »
    I am building a library and have the following code
    void PULSE(int pin, uint32_t duration)
    {
        int mask = 1 << pin;
    
        DIRA |= mask;
    
        OUTA |= mask;
        DELAY(duration);
        OUTA &= ~mask;
    }
    
    void DELAY(uint32_t duration)
    {
        uint32_t time;
       
        time = CNT;
        waitcnt(duration + time);
    }
    

    header file
    void PULSE(int pin, uint32_t duration);
    
    void DELAY(uint32_t duration);
    

    This produces the error "unknown type name uint32_t" error when compiling with a file using #include in the header file for both functions, should this happen?

    Did you include stdint.h? That is where uint32_t is defined.
    #include <stdint.h>
    
  • ReinhardReinhard Posts: 489
    edited 2011-11-25 15:07
    Try:
    #include <stdint.h>
    
    void PULSE(int pin, uint32_t duration);
    
    void DELAY(uint32_t duration);
    
    #include "pulse.h"
    
    void main ()
    {
        for(;;)
        {
            PULSE(0,10000);
            DELAY(20000);
        }
    }
    
    #include <propeller.h>
    #include "pulse.h"
    
    void PULSE(int pin, uint32_t duration)
    {
        int mask = 1 << pin;
    
        DIRA |= mask;
    
        OUTA |= mask;
        DELAY(duration);
        OUTA &= ~mask;
    }
    
    void DELAY(uint32_t duration)
    {
        uint32_t time;
       
        time = CNT;
        waitcnt(duration + time);
    }
    

    propeller-elf-gcc -o pulse.o -c pulse.c
    propeller-elf-gcc -o pulse.elf pulse.o main.c
  • ReinhardReinhard Posts: 489
    edited 2011-11-25 15:08
    Ups, I see David was faster :smile:
  • blittledblittled Posts: 681
    edited 2011-11-25 16:01
    Including the stdint.h did the trick! I'll have to learn what is in the libraries. Thanks!
Sign In or Register to comment.