A compilation of test code for the P2 Eval

samuellsamuell Posts: 279
edited 2019-05-16 - 16:30:04 in Propeller 2
Hi all,

I thought it was good to start a tread where posts containing test and finished code for the P2 could be shared. So, to start, here is my last prime number calculation program. See the file attached. It should work on Linux with p2gcc and loadp2. However, mind that I'm using the old versions of the compiler and loader that are provided via nix, so the code is not yet updated to support long long variables, and still uses some deprecated/redundant code. If you have the tools installed and your P2 ready, you only need to run the script.

Also, why not provide links to other programs, as these two provided by garryj:
- USB Mass Storage Demo v0.05: https://forums.parallax.com/discussion/comment/1462546/#Comment_1462546
- Mouse/keyboard: https://forums.parallax.com/discussion/comment/1462633/#Comment_1462633

In the same note, please feel free to post useful code, or reference other posts, here. You are welcome!

Kind regards, Samuel Lourenço

Comments

  • I can't seem to get your prime number program to work with p2gcc (version 0.006, 2019-02-12, built from source from a repo pulled today). It just hangs after I enter the numbers to calculate. It looks like cogstart() isn't working, because when I put code in there to turn on LEDs they never turn on.

    The prime number program doesn't actually need lockset()/lockclr(), because each worker cog has its own flag. In fact as it's currently written there's a race condition that could cause a hang: sometimes the master cog and one or two other COGs can hog the lock (continually getting and clearing it) and then preventing other COGs that are actually doing work from getting the lock. It all depends on the timing of the hub windows, which varies between P1 and P2 and with different compilers. This isn't the cause of the hang I mentioned above though, because that happens even after I fix that issue :(.

    I was able to get primos.c to work with fastspin with a few small changes. I've attached the fastspin version to this message.
    c
    c
  • Hi ersmith,

    I've been using the version loaded with nix. I've retested the code from the zip file, just to be sure, and it seems to work fine. But I've seen some people having different issues.

    However, your code seems to work fine as well, and it is a bit faster (perhaps since it doesn't use lockset() and lockclr() ). Additionally, it compiles and runs with spin2gui, unlike mine. Thanks!

    Kind regards, Samuel Lourenço
Sign In or Register to comment.