Can't Wait for PropGCC on the P2?

1181920212224»

Comments

  • I have noticed that p2gcc does not have basic functions like high(), low(), setdirection(), toggle(), pause() that are used on the P1.
    I moved them over from simpletools and they work fine but I'm stuck.

    Should they be written in P2 code which means I would have to write them in assembly instead of C code.

    Mike

    Sample:
    void high(int pin)
    {
    	unsigned int mask;
    
    	if (pin > 31)
    	{
    		mask = 1 << (pin - 32);
    		OUTB |= mask;
    		DIRB |= mask;
    	}
    	else
    	{
    		mask = 1 << pin;
    		OUTA |= mask;
    		DIRA |= mask;
    	}
    }
    
    void low(int pin)
    {
    	unsigned int mask;
    
    	if (pin > 31)
    	{
    		mask = 1 << (pin - 32);
    		OUTB &= ~mask;
    		DIRB |= mask;
    	}
    	else
    	{
    		mask = 1 << pin;
    		OUTA &= ~mask;
    		DIRA |= mask;
    	}
    }
    
    void sleep(int sec)
    {
    	unsigned int t;
    
    	t = CNT;
    	while (sec--)
    		waitcnt(t += CLKFREQ);
    }
    
    void msleep(int millis)
    {
    	unsigned int t;
    
    	t = CNT;
    	while (millis--)
    		waitcnt(t += CLKFREQ / 1000);
    }
    
    
  • I've been focusing on the most frequently used standard C functions. Maybe it's time to port the whole simple library over. In general, the code could be left unchanged in C. However, because the P2 has 64 I/O pins changes have to be made like you did with high and low. It might make sense to implement these functions in assembly since high and low can be performed with DRVH and DRVL.
  • Dave Hein wrote: »
    I've been focusing on the most frequently used standard C functions. Maybe it's time to port the whole simple library over. In general, the code could be left unchanged in C. However, because the P2 has 64 I/O pins changes have to be made like you did with high and low. It might make sense to implement these functions in assembly since high and low can be performed with DRVH and DRVL.
    Didn't someone already offer to port over the Simple Libraries? Was it Roy?

  • David Betz wrote: »
    Eric: Do you intend to keep using the _IMPL method of associating function prototypes with the files containing their implementation? If so, I will have to add those clauses to all of the header files I move over from proplib. You've already done that for the ones you've moved over.

    I mean lines like this from string.h:
        char * strchr(const char *, int) _IMPL("libc/string/strchr.c");
    

    At least for now I plan to keep using that. For PropGCC _IMPL will be defined as empty (I've tried to keep compiler.h, at least, working with PropGCC) and it does serve as documentation on where to find the source code.
  • Thanks @Dave Hein for fixing my program problem.

    I had this library to drive the OLED display and it just didn't work. I would get one piece to work but as soon as I added some more code nothing worked. Went round and round and still couldn't figure it out.

    I just tried again and I got this message:
    Object 3 is an odd size - 5174
    Padding address to 4-byte boundary

    Now everything works as it should. Now I can start hacking at your code again.

    Mike
  • Glad that this fixes your problem. I've been working around this problem for quite a while by manually padding out my char arrays in my programs to make them a multiple of 4 bytes.
Sign In or Register to comment.