Understanding the BeagleBone’s built in microcontrollers (2016)
righto.com
righto.com
My experience with real time systems led me to believe that RTOS's are kind of harmful and don't live up to expectations.
Using an RTOS felt basically like a regular OS but with cooperative multitasking. I could never separate the time consumption of one task from another and think about them in isolation.
What I really ended up wanting was preemptive multitasking.
But to instead divide the CPU time into fixed allocation of say 10 to 100 tasks, each with a dedicated slice of CPU time that never varies.
Then you can finally reason about tasks in isolation!
Interrupts are then disallowed.
It's basically equivalent to having a bunch of little CPUs communicating. (One should try to use ring buffers for all communication, not shared memory.)
To me, this is the only real time architecture I feel smart enough to even handle.
Could you expound upon that?
It works great with embedded real time systems as well. It can be easier to get right than the alternative -- because without locks, the performance is more predictable.
Less chance for race conditions and deadlocks as well.
It is also basically the same thing as hooking up different processors with a bunch of serial ports. UARTs typically have a hardware ring buffer for send and receive. So basically, you simulate a bunch of separate processors all communicating. You could do it in hardware, or within software. Both work equally well.
"When carefully implemented, a circular buffer requires no locking in the absence of multiple producers or consumers. The producer is the only thread that is allowed to modify the write index and the array location it points to. As long as the writer stores a new value into the buffer before updating the write index, the reader will always see a consistent view. The reader, in turn, is the only thread that can access the read index and the value it points to. With a bit of care to ensure that the two pointers do not overrun each other, the producer and the consumer can access the buffer concurrently with no race conditions."
In the context of embeded real time systems you are generally targeting specific hardware, so you can make gurantees about the atomicity of specific instructions.
This can fail on 32-bit processors like the x86 if you use a 64-bit index. For embedded work, it can fail on 8-bit processors if you use a 16-bit index.
You can check, in C++, whether operations on a type are a single instruction. This might be true on an x84_64 and false on an x86:
std::atomic<int64_t>::is_lock_free()It's still different enough to scare a lot of people off, but I'll give it a shot. I went poking around the forums and it looks like they just shipped out the first 100 evaluation boards in December.
For anyone interested in more examples and explanation of PRU programming on BeagleBone boards this repo is really good: https://github.com/MarkAYoder/PRUCookbook
Notable though the power controller for the BeagleBone has a serious issue with brownouts/slow power application. If the power ramps up too slowly it'll hang and needs to be manually reset. That's a not ready for prime time sort of thing. We solve it with a small uP that monitors the BB and kicks it if it fails to power up or hangs.
We do that to avoid having to send out a tech. Amusingly a friend maintains a similar system on satellite hardware.
But I get a kick out of getting more oomph out of little devices than you’d think you could, and one of the things I’d hoped to accomplish with the PRUs was to get some streaming processing going.
If I understood correctly, if you wanted stable, high sampling rates on GPIO you were going to want to do that on the PRU, and with 2 you could send and receive in duplex. So I thought some sort of control or logging backplane to remove traffic off of the underpowered ethernet port would be pretty cool.
And then the other idea was figuring out how to cross compile zlib to do transport compression without hogging the CPU.
but now I’m off fiddling with NanoPi’s, and not even really as embedded devices. With 1GB of memory and GigE ethernet I’m thinking of them as tiny servers instead. I’m probably missing out, though.
I imagine that the more interesting advantages are from the perspective of the board designer.
There are a lot of boards on the embedded systems market that use e.g. ARMs big.LITTLE architecture for that.
For example, burning electronic fuses in an ASIC, where timing had to be guaranteed or the chip was toast.
Beyond that, like most have said, bit banging odd protocols at reasonable speed, with full access to main memory for streaming.
For a funny optimization that resulted in lower performance: I offloaded one of our protocols to one of these coprocessors but noticed the overall throughput dropped to about 1/4 what it was before, with huge latency between transactions. I looked at the cpu and, as was the goal, main processor usage was down from 30% to about 2%. I eventually realized that, due to the low CPU usage, the main processor clock rate was scaled to the lowest frequency. This caused interrupt handling, and everything else, to slow wayyy down, including the arbiter in the kernel driver and user space code where the transactions were coming from.
The fix was to disable clock scaling completely, burning some watts more. I’m sorry dolphins :(
They're designed for deterministic bit banging of random protocols.
https://hackaday.com/2015/02/19/turn-your-beagleboneblack-in...
http://processors.wiki.ti.com/index.php/Control_Law_Accelera...
It even has its own (kind of) C compiler: http://processors.wiki.ti.com/index.php/C2000_CLA_C_Compiler
https://www.nxp.com/products/processors-and-microcontrollers...
https://www.nxp.com/products/processors-and-microcontrollers...
http://processors.wiki.ti.com/index.php/AM335x_PRU_Read_Late...
[0] https://en.m.wikipedia.org/wiki/Advanced_Microcontroller_Bus...
Random presentation slides I found on the topic:
A Raspberry Pi is closed source (though it can be designed in as a component to a larger open source hardware system).
An Arduino is “share-alike”, so more restrictive like a GPL 2+ license.
[https://hackaday.com/2015/02/19/turn-your-beagleboneblack-in...]