delays.hch
// delays.hch
/* Macro procs for delay intervals
*/
#ifdef PAL_ACTUAL_CLOCK_RATE
#define CLOCK_RATE PAL_ACTUAL_CLOCK_RATE
#endif
#ifdef RC200_ACTUAL_CLOCK_RATE
#define CLOCK_RATE RC200_ACTUAL_CLOCK_RATE
#endif
#ifndef CLOCK_RATE
#error "xxx_ACTUAL_CLOCK_RATE Must be defined"
#endif
macro proc milli_delay( msec )
{
macro expr Count =
assert( ( msec * CLOCK_RATE / 1000) > 0,
msec * CLOCK_RATE / 1000,
"Effective milli_delay is zero." );
unsigned (log2ceil(Count)) ticks;
ticks = Count - 1;
while ( ticks )
{
ticks--;
}
}
macro proc micro_delay( usec )
{
macro expr Count =
assert( ( usec * CLOCK_RATE / 1000000) > 0,
usec * CLOCK_RATE / 1000000,
"Effective micro_delay is zero." );
unsigned (log2ceil(Count)) ticks;
ticks = assert( Count < 1000, Count - 1,
"Micro delay is 1 msec or more; use milli_delay." );
while ( ticks )
{
ticks--;
}
}
macro proc nano_delay( nsec )
{
macro expr Count =
assert( ( nsec * CLOCK_RATE / 1000000000) > 0,
nsec * CLOCK_RATE / 1000000000,
"Effective nano_delay is zero." );
unsigned (log2ceil(Count)) ticks;
ticks = assert( Count < 1000, Count - 1,
"Nano delay is 1 usec or more; use micro_delay." );
while ( ticks )
{
ticks--;
}
}