A compilation of test code for the P2 Eval
samuell
Posts: 554
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
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
zip
6K
Comments
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.
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