Spin2 Serial I/O for both Fastspin and Pnut?
Rayman
Posts: 14,646
in Propeller 2
What options are there for serial I/O that works with both FastSpin and Pnut?
I've been using SmartSerial, but I'm pretty sure that won't work with Pnut…
I think there's fullduplexserial around somewhere...
Is there anything that doesn't use a cog?
I've been using SmartSerial, but I'm pretty sure that won't work with Pnut…
I think there's fullduplexserial around somewhere...
Is there anything that doesn't use a cog?
Comments
Found in this thread: http://forums.parallax.com/discussion/171327/p2-tm1638-driver-and-demo#latest
Did a quick look at jm_serial.spin2 and it looks like just what I want. Well, maybe a little more than I need, but that's probably OK.
I've been there... I've written just another SPI driver because it was easier to code some than to search and ask.
Of course releasing code to the public is much work. You need to carefully test and document it and be prepared for questions. But I think even a "raw" piece of code (I mean not very well tested and documented) would be helpful. At least everybody could see that there is already something and it's not necessary to re-invent the wheel. If there is a lot of interest the author could improve documentation and fix bugs later. If not nothing is lost.
My Serial Monitor compiles in both fastspin and pnut. It’s really a serial library but you can also call it as a monitor too. It also supports a cog/lut/hub list (dump) call in addition to the usual char, string, hex, etc routines.
For compiling it with fastspin, you just need to change the cog base _reg to $000 instead of $120 that I use in pnut.
The only thing that it doesn’t do is receive by interrupt. It has receive chat, string, check, and peek.
The send and the receive routines all come down to two tiny calls permitting easy modifications if required. I will probably add an interrupt call option to change to receive under interrupts later.
It’s working really well for me now. It’s based on my serial monitor in the P2 ROM, plus a few additions.
For a new user like myself, this would be very helpful indeed. Yes, I've found things by searching and then reading the entire text of the resultant threads, some many years old but so full of shared knowledge. Having a go to place for drivers and examples is the one thing that would make this so much easier, not to supplant the forum search, but to enhance the overall user experience.
If no one else writes an object, I'm sure I could quickly write some Spin2 code to do this or do I have to say "it's impossible"
If this could be done with interrupts too, so as to include buffering, that might be interesting...
Not sure it would be possible for the same code to compile with both PNut and Fastspin…
So far, I haven't seem to have needed buffering. But, I'm sure there will be a case where I do...
You may potentially require buffering if you paste data into a terminal and send to a prop. I found this with Micropython for example and added some receive buffering in the LUTRAM with an interrupt driven receiver in the main COG.
Just interactively typing directly into a terminal is often slow enough that a receiver can keep up (depending on what it does to parse and act on the data received).
How many times do I need to say it...
My Serial Monitor is a serial handler that does not use up a cog, resides in hub as hubexec (which incidentally overwrites my ROM Monitor and uses the very same calls and locations as the ROM - although that may change) and uses 16 cog long variables which are reconfigurable to suit pnut or fastspin. It comes complete with the ability to be called from spin or asm, and you can also call into the monitor to look and change cog/lut/hub and then return to your program with the "Q" command.
It's FDX on steroids with one current exception - it's half duplex as I don't use interrupts to receive characters or strings. I do plan to add an option to use receive via interrupts shortly.
Have you ever wanted to dump memory like this... It is now as simple as doing this in your code...
PS I'm using it in my P2 OS and it runs fine
Yes the GETBYTE does the same thing as SHR #24.
The PR0..PR7 registers are reserved cog registers directly accessable from Spin2.
Here's an updated source with rx_check and rx_read.
BUT some programs will not be able to cater for interrupt driven receive. For example, when reading/writing SD or Flash. There is also the case for a user running spin programs which may not be aware of what interrupts will do to his/her code.
So, there is a case for both. And that is what I will be doing. It will also be possible to have the serial in it's own cog where interrupts will not matter for the users code.
And as you know, most code is really half duplex. It sends something out, waits for a response or new data, processes it and sends something out again. Rinse and repeat.
(I think I can do that myself, just a binary blob that any language can shove into a cog.)
I think STALLI/ALLOWI is what you are looking for!
Can we load binary files easily in all the different ways of developing code? It would be like a preprogrammed chip, which it is, that doesn't need anything else except the mailboxes in low hub perhaps. Serial buffers could be maintained in LUT and surely we could have the one cog handle more than one serial channel. Same applies for other functions. Each cog should have a reserved mailbox area that could even point to new mailboxes.
This ROM could have 4 FDS serial ports or more, timer functions, time of day etc. I find that with a hardware RTC that it is easier to read this only once every so often and maintain the time in a more conducive format in software with very fast access, especially for time stamps.