Re:How to run C programs on the BeagleBone's PRU microcontro...
by kens on Tuesday September 20, 2016 @01:20PM
(#12541183)
Thanks for mentioning the constants table. In my case, saving a few cycles isn't important but eliminating jitter is very important, which is why I use interrupts.
Reading the PWM register took 5 cycles, so I ended up with 25 nanoseconds of jitter, which caused bit errors in my Alto Ethernet emulator. Polling interrupts take 1 cycle, so I end up with no jitter. (Does anyone else think it's bizarre that TI calls them "interrupts" when you need to poll them?) You might think 1 cycle would cause 5 ns jitter, but the timer uses the same clock so everything is synchronized.
I considered using the constants table if I needed to shave off some cycles, but as you point out the code required is pretty hideous. And you also need to define all the constants in the linker file too? That's just crazy.
The compiler can be coaxed, with some rather ridiculous clpru compiler-specific variable definitions, into referencing addresses from the constant table by a C number rather than loading up a general purpose register.
It is in the clpru compiler documentation under section 5.14.4 It is also discussed in some TI slides (flash required) in part 18 http://software-dl.ti.com/public/hpmp/software/pru_compiler_... PDF slides: http://software-dl.ti.com/public/hpmp/software/pru_compiler_... (PDF page 28)
TI states in their slides that this constant register table access "Barely counts as C code." I think they're right. It is, however, slightly faster. When trying to do cycle-perfect timing, such micro optimizations start to actually matter.