waitvid in waitcnt
I've disassembled the following delay function used in program with LMM kernel:
Can anybody explain, what is waitvid doing here?
Thanks.
void delay_msec(int msec) {
waitcnt((CLKFREQ / 1000) * msec - 3932 + CNT);
}
and got such output:
00000884 <_delay_msec>:
884: a0bc0ff1 mov 1c <r7>, 7c4 <CNT>
888: 5c7c003a jmp e8 <__LMM_MVI_r5>
88c: fffff0a4 waitvid 7e0 <CTRA>, #164 wz, wc, wr
890: 80bc0e05 add 1c <r7>, 14 <r5>
894: 5c7c003a jmp e8 <__LMM_MVI_r5>
898: 00000000 nop
89c: a0bc0c00 mov 18 <r6>, 0 <__clkfreq>
8a0: 5c7c002e jmp b8 <__LMM_MVI_r1>
8a4: 000003e8 nop
8a8: 08bc0005 rdlong 0 <__clkfreq>, 14 <r5>
8ac: 5cfd3e8e jmpret 27c <__UDIVSI_ret>, #238 <__UDIVSI>
8b0: a0bc0200 mov 4 <__clkmode>, 0 <__clkfreq>
8b4: a0bc0006 mov 0 <__clkfreq>, 18 <r6>
8b8: 5cfd6eaf jmpret 2dc <__MULSI_ret>, #2bc <__MULSI>
8bc: 80bc0e00 add 1c <r7>, 0 <__clkfreq>
8c0: f8fc0e00 waitcnt 1c <r7>, #0
8c4: a0bc220f mov 44 <pc>, 3c <lr>
Can anybody explain, what is waitvid doing here?
Thanks.

Comments
When you see the "jmp e8 <__LMM_MVI_xx>" this means whatever that is next is data.
Maybe a fix in the future could be applied to the dissembler to make the output more readable?
The answer becomes apparent if you look at the assembly generated by compiling the delay_msec function with the "-Os --save-temps" flags:
_delay_msec mov r7, CNT jmp #__LMM_MVI_r5 long -3932 add r7, r5 jmp #__LMM_MVI_r5 long __clkfreq mov r6, r0 jmp #__LMM_MVI_r1 long 1000 rdlong r0, r5 call #__UDIVSI mov r1, r0 mov r0, r6 call #__MULSI add r7, r0 waitcnt r7,#0 mov pc,lrThe disassmbler's lack of the original symbol table obscured the actual intent.
Thanks, denominator!