XC does not have partin_timed, so I must use inline assembly.
However, the compiler reorders the inline assembly and the behavior of the code changes completely.
I want to guarantee that the four inline assembly instructions appear in the
same order once compiled:
Code: Select all
u16 t;
u32 sample[1];
while (1)
{
wordclock when pinseq(0) :> void;
wordclock when pinseq(1) :> void @ t;
asm volatile ("setpt res[%0], %1" :: "r"(din[0]), "r"(t + 23));
asm volatile ("setpt res[%0], %1" :: "r"(dout[0]), "r"(t + 32));
asm volatile ("outpw res[%0], %1, 24" :: "r"(dout[0]), "r"(sample[0]));
asm volatile ("inpw %0, res[%1], 24" : "=r"(sample[0]) : "r"(din[0]));
asm volatile ("setpt res[%0], %1" :: "r"(din[0]), "r"(t + 55));
asm volatile ("setpt res[%0], %1" :: "r"(dout[0]), "r"(t + 64));
asm volatile ("outpw res[%0], %1, 24" :: "r"(dout[0]), "r"(sample[0]));
asm volatile ("inpw %0, res[%1], 24" : "=r"(sample[0]) : "r"(din[0]));
}
Code: Select all
setpt
setpt
outpw
setpt
setpt
inpw
outpw
inpw
ports.
Code: Select all
asm volatile
(
"setpt res[%1], %3\n\t"
"setpt res[%2], %4\n\t"
"outpw res[%2], %5, 24\n\t"
"inpw %0, res[%1], 24\n\t"
// outputs
:
// %0
"=r"(sample[0])
// inputs
:
// %1 %2 %3 %4 %5
"r"(din[0]), "r"(dout[0]), "r"(t + 23), "r"(t + 32), "r"(sample[0])
);