Atmel Software Framework

cycle_counter.h File Reference

AVR functions for busy-wait delay loops.

Copyright (c) 2011-2016 Atmel Corporation. All rights reserved.

#include <compiler.h>

Convenience functions for busy-wait delay loops

#define delay_cycles   __portable_avr_delay_cycles
 Delay program execution for a specified number of CPU cycles. More...
 
#define cpu_ms_2_cy(ms, f_cpu)   (((uint64_t)(ms) * (f_cpu) / 6 + 999) / 1e3)
 Convert milli-seconds into CPU cycles. More...
 
#define cpu_us_2_cy(us, f_cpu)   (((uint64_t)(us) * (f_cpu) / 6 + 999999ul) / 1e6)
 Convert micro-seconds into CPU cycles. More...
 
#define cpu_delay_ms(delay, f_cpu)   delay_cycles((uint64_t)cpu_ms_2_cy(delay, f_cpu))
 Delay program execution for a specified number of milliseconds. More...
 
#define cpu_delay_us(delay, f_cpu)   delay_cycles((uint64_t)cpu_us_2_cy(delay, f_cpu))
 Delay program execution for a specified number of microseconds. More...
 
static __always_optimize void __portable_avr_delay_cycles (unsigned long n)
 

#define cpu_delay_ms (   delay,
  f_cpu 
)    delay_cycles((uint64_t)cpu_ms_2_cy(delay, f_cpu))

Delay program execution for a specified number of milliseconds.

Parameters
delaynumber of milliseconds to wait
f_cpuCPU frequency in Hertz
#define cpu_delay_us (   delay,
  f_cpu 
)    delay_cycles((uint64_t)cpu_us_2_cy(delay, f_cpu))

Delay program execution for a specified number of microseconds.

Parameters
delaynumber of microseconds to wait
f_cpuCPU frequency in Hertz
#define cpu_ms_2_cy (   ms,
  f_cpu 
)    (((uint64_t)(ms) * (f_cpu) / 6 + 999) / 1e3)

Convert milli-seconds into CPU cycles.

Parameters
msnumber of milliseconds
f_cpuCPU frequency in Hertz
Returns
the converted number of CPU cycles
#define cpu_us_2_cy (   us,
  f_cpu 
)    (((uint64_t)(us) * (f_cpu) / 6 + 999999ul) / 1e6)

Convert micro-seconds into CPU cycles.

Parameters
msnumber of microseconds
f_cpuCPU frequency in Hertz
Returns
the converted number of CPU cycles
#define delay_cycles   __portable_avr_delay_cycles

Delay program execution for a specified number of CPU cycles.

Parameters
nnumber of CPU cycles to wait

static __always_optimize void __portable_avr_delay_cycles ( unsigned long  n)
inlinestatic

References barrier.