BackupGGCode / propgcc

GCC for the Parallax Propeller Microcontroller
Other
0 stars 0 forks source link

Definition of waitcnt(a) broken in propeller.h #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create test.c with the following contents:

#include <stdio.h>
#include <propeller.h>

void main()
{
    register unsigned long t1, t2, t3, t4;

    // Wait a couple of secs for the terminal mode to fully kick in
    waitcnt(CNT + (CLKFREQ << 1));
    printf("Hello\n");

    t1 = CNT;
    t2 = t1 + 10000;
    t3 = waitcnt(t2);
    t4 = CNT;

    printf("t1, t2, t3, t4 = %10u %10u %10u %10u\n", t1, t2, t3, t4);
}

2.  Compile and run it with the following commands:

propeller-elf-gcc -O2 -mfcache  -mlmm -o test.o -c test.c
propeller-elf-gcc -mlmm -fno-exceptions -fno-rtti -o test.elf test.o -s
propeller-load -b <yourboard> test.elf -r -t

What is the expected output? What do you see instead?

Expected something like this:

[ Entering terminal mode. Type ESC or Control-C to exit. ]
Hello
t1, t2, t3, t4 = 3586977037 3586987037 3586987037 3586987149

But got something like this:

[ Entering terminal mode. Type ESC or Control-C to exit. ]
Hello
t1, t2, t3, t4 =  139379025  139389025  278768114  139389137

Notice that t3 is should be the same as t2 (it should be the clock at the time 
the waitcnt woke up) but instead is effectively t1 + t2 plus a 64 cycles or so. 
 This value is *completely useless*.

What version of the product are you using? On what operating system?

propgcc-0.2.2

Please provide any additional information below.

This problem is caused by an incorrect definition in lib\include\propeller.h.

Change:

#define waitcnt(a) __builtin_propeller_waitcnt((a),_CNT)

To:

#define waitcnt(a) __builtin_propeller_waitcnt((a),0)

Original issue reported on code.google.com by tjstefan...@charter.net on 28 Jan 2012 at 11:35

GoogleCodeExporter commented 9 years ago
Thanks for the detailed bug report! Your fix looks correct to me, and I've 
checked it in.

Original comment by ersm...@hfx.eastlink.ca on 7 Feb 2012 at 5:37