I am trying to port the MC33771 library which was written for S32K144(ARM architecture) to a MPC574x(Power architecture) controller. A piece of MC33771's sample code in bcc_wait.c is writtten in assembly where it waits for cycles in multiples of 4.
From the Power architecture instruction set I understand that "movs" needs to be changed to "mr" or some other equivalent instruction and "r0" can be a general-purpose register like GPR0 to GPR31.
But when I try to use GPR0-31 it throws a relocation error
1. What is the correct syntax to use the GPR registers inline with C-code?
2. What are other ways to count cycles in MPC574x?
Thanks in advance
first important point: due to pipelining, flash wait states, cache, other bus masters and priorities on crossabar etc., it's not easy to generate exact delays using asm or C code. This was easy on older and simpler devices where the timing of everything was strictly given. But features which increase the performance insert relatively high variability when talking about timing.
So, my usual recommendation is: if the timing is not critical and you can accept relatively high inaccuracy, use just simple delay loops like:
for(i=0; i<delay; i++)
... or whatever like this. I can't see a benefit to write this in asm.
If the timing is critical, use a timer like PIT or STM to generate accurate delays.
And to asnwer your original question, here is an example of inline asm syntax (writing value 0xA1000F00 to SPR register 624 using r3 register):
__asm("e_lis %r3, 0xA100");
__asm("e_or2i %r3, 0x0F00");
__asm("mtspr 624, %r3");