Synergy Software Package User's Manual

Common function to implement a software delay. More...

Functions

void R_BSP_SoftwareDelay (uint32_t delay, bsp_delay_units_t units)
 Delay the specified duration in units and return. More...
 

Detailed Description

Common function to implement a software delay.

Implements a software delay function for all BSPs.

Function Documentation

◆ R_BSP_SoftwareDelay()

void R_BSP_SoftwareDelay ( uint32_t  delay,
bsp_delay_units_t  units 
)

Delay the specified duration in units and return.

Parameters
[in]delayThe number of 'units' to delay.
[in]unitsThe 'base' (bsp_delay_units_t) for the units specified. Valid values are: BSP_DELAY_UNITS_SECONDS, BSP_DELAY_UNITS_MILLISECONDS, BSP_DELAY_UNITS_MICROSECONDS.
For example:
At 1 MHz one cycle takes 1 microsecond (.000001 seconds).
At 12 MHz one cycle takes 1/12 microsecond or 83 nanoseconds.
Therefore one run through software_delay_loop() takes: ~ (83 * DELAY_LOOP_CYCLES) or 332 ns. A delay of 2 us therefore requires 2000ns/332ns or 6 loops.

The 'theoretical' maximum delay that may be obtained is determined by a full 32 bit loop count and the system clock rate. @240MHz: ((0xFFFFFFFF loops * 4 cycles /loop) / 240000000) = 71 seconds. @32MHz: ((0xFFFFFFFF loops * 4 cycles /loop) / 32000000) = 536 seconds

Note that requests for very large delays will be affected by rounding in the calculations and the actual delay achieved may be slightly less. @32 MHz, for example, a request for 532 seconds will be closer to 536 seconds.

Note also that if the calculations result in a loop_cnt of zero, the software_delay_loop() function is not called at all. In this case the requested delay is too small (nanoseconds) to be carried out by the loop itself, and the overhead associated with executing the code to just get to this point has certainly satisfied the requested delay.

Note
This function calls bsp_cpu_clock_get() which ultimately calls R_CGC_SystemClockFreqGet() and therefore requires that the BSP has already initialized the CGC (which it does as part of the Sysinit). Care should be taken to ensure this remains the case if in the future this function were to be called as part of the BSP initialization.
Return values
None.

Convert the requested time to microseconds.

Get the system clock frequency in Hz.

Get the # of nanoseconds/cycle.

Only delay if the supplied parameters constitute a delay.