DSP = C6748
SYSBIOS = V6.37.5.35
Code Composer = V5.5
What is the best way to implement a micro second delay, that doesn't yield, using SYSBIOS? I've done millisecond delays (see code below), but don't know the best way to implement a micro second delay.
/********************************************************************************************************************************/
/* void MilliSecDelayWithoutYield(U32 mSDelay) */
/* */
/* Delay for xx milliseconds WITHOUT yielding (no TASK switch). This function provides a MINIMUM delay. The actual delay */
/* using this function may be more than you requested (due to HWI/SWI still running and getting to close to roll over). */
/* */
/* Parameters: */
/* - mSDelay: number of milliseconds to delay */
/* */
/* Returns: none */
/* */
/* Notes: Public API function that can be called from the TASK level. */
/********************************************************************************************************************************/
void MilliSecDelayWithoutYield(U32 mSDelay)
{
UInt restore_key = Task_disable(); /* Disable TASKS so our checking of Clock_getTicks() is accurate. */
U32 Timestamp = Clock_getTicks();
U64 OverflowCheck = Timestamp + mSDelay; /* How close are we to rolling over the U32 system clock? */
/* Check if we are close to a roll over. If we are too close, then just wait for the roll over to happen, then do the delay.
This adds more time than what was expected, but this routine is designed to provide a MINIMUM delay, not an exact delay.
This way we don't have to worry about a delay spanning the roll over, or a rare edge condition that exists if the delay
plus the current time is close to 0xFFFFFFFF. In that case we could be miss seeing the 0xFFFFFFFF because maybe we got
interrupted by a HWI/SWI combo, and we would be stuck here for 49.7 days. */
if( OverflowCheck >= 0x00000000FFFFFFF0 )
{
/* We are 1mS to 16mS from rolling the clock over. Just wait for that to happen before doing the real requested delay. */
while( Clock_getTicks() > 0x00000100 )
{
/* Do nothing while we wait for the clock to roll over. */
}
}
Timestamp = Clock_getTicks();
while( Clock_getTicks() < (Timestamp + mSDelay) )
{
/* Do nothing while we wait for the delay to expire. */
}
Task_restore(restore_key); /* Restore TASK's to their previous state. */
}