Tool/software: TI C/C++ Compiler
I have a simple bit of code for the PRU to read the cycle counter of the PRU. If the cycle counter reaches 0xFFFFFFFFFF, I wish to set it to 0 and re-enable it. (Too bad it does not roll over...this would be much more useful).
Code is in C and looks like this:
uint32_t volatile cnt;
int main(void) {
while (1) {
cnt=PRU1_CTRL.CYCLE.CYCLE;
if (cnt==0xFFFFFFFF) {
PRU1_CTRL.CYCLE.CYCLE=0;
PRU1_CTRL.CTRL.CTRL_bit.COUNTER_ENABLE=1;
}
}
}
Assembly listing generates for the 1st 3 lines: (using either version 2.1.5 or 2.2 of the compiler)
159 00000000 000000248000E0 LDI r0, 0x8000 ; [] $O$K3
160 00000004 0000002EFF8190 ZERO &r16, 4 ; [] $O$K8
161 00000008 000000240000E1! LDI r1, ||cnt|| ; [] $O$K4,cnt
Seems reasonable enough...r0 has the address of the control registers, r1 has the address of my variable "cnt" and 4 bytes of r16 are set to zero for use as a value to move into the cycle counter to set it to 0.
The problem is with the code generated by the ZERO pseudo-op. 2EFF8190. It shows up in the debugger disassembly as
XIN 255, &R16.bo,4
The only info I can find on the hex op codes tells me the following:
The hex of the op code means Format 2.
That is, the SUBOP is 7, reserved.
The information in the Wiki on the PRU assembly instructions regarding XIN is:
On XIN, the register file data starting at the register REG with a length of IM(124) is read in from the parallel XFR interface from the hardware device with the device id specified in IM(253).
That is, the immediate operand 255 is illegal?
In any case, this instruction crashes the PRU.
Perhaps there is a flag on the compiler to prevent it from generating illegal instructions?
Any assistance would be nice.