It would be better to use the repetitive interrupt timer.
RIT_Delay_Ten_Nsec has a minimum delay of 10 nanoseconds.
--------------------------------------------------------------------
#include <stdint.h>
void RIT_Delay_Ten_Nsec(uint32_t ten_nsec)
{
rit_delay_done = 0;
/* The RIT count increments every 10ns */
RICOMPVAL = ten_nsec;
RICOUNTER = 0x00000000;
/* Enable timer */
RICTRL = RICTRL_RITEN | RICTRL_RITENCLR;
while (!rit_delay_done)
; /* do nothing */
}
--------------------------------------------------------------------
A software instruction loop in assembler is a second choice.
delay_100nsec has a minimum delay of 100 nanoseconds.
This assumes that the CPU clock is 100MHz. You can add
or subtract "nop" instructions to adjust the delay time in the loop.
--------------------------------------------------------------------
#include <stdint.h>
void delay_100nsec(uint32_t num_nsec)
{
__asm volatile ( "delay_100:" );
__asm volatile ( "nop" );
__asm volatile ( "nop" );
__asm volatile ( "subs r0, r0, #1" );
__asm volatile ( "bne delay_100" );
}
--------------------------------------------------------------------