For the CC3220S manufactured by Texas Instruments, I developed a function in the C programming language which uses inline Assembly to wait 1 second (excluding the instructions before the loop and outside the loop). According to the ARMv7-M reference manual, the MOV instruction which targets the PC takes 1 + P instruction cycles where P is between 1 and 3 depending on a pipeline refill. Worst case this means that the loop executes in 6 clock cycles.
The CC3220S its clock speed is 80 MHz. However, executing the loop 10 million times creates the desired delay of 1 second (verified with a logic analyzer). This means that the loop uses 8 clock cycles. I have my doubts about the amount of clock cycles the instruction uses. Hence my question, should a semiconductor manufacturer buying IPs from ARM meet the clock cycles for an instruction described in the reference manual?
void delay_1sec(void)
{
__asm(" PUSH {r4-r5,lr}");
__asm(" LDR r4, [pc, #12]");
__asm(" MOV r5, pc");
__asm(" NOP");
__asm(" SUBS r4, #1"); /* 1 instruction cycle */
__asm(" ITE NEQ"); /* 1 instruction cycle */
__asm(" MOV pc, r5"); /* 1 + P instructions (where P is between 1 and 3 depending on pipeline refill) */
__asm(" POP {r4-r5,pc}");
__asm(" .word 10000000");
}
__attribute__((naked))
so it can't inline into other functions and break them. Also, prefer one largeasm() statement. Although inside a
naked` function, this is safe. But really this is total overkill; just ask the compiler for10000000
in a"+r" (var)
register and another"=r"
dummy output in a GNU C Extended asm statement. – Peter Cordes__asm("...");
nonsense and don't have to worry about the compiler inserting whatever instructions it wants. – Ross Ridge