/// Emulation of Arduino's millis() functionality on AVR32 /// \bug doesn't handle cycle counter wraparound very well long millis(void) { static long count = 0; static long milliseconds = 0; // Read CPU cycle counter and convert to millisecond difference long newcount = Get_sys_count(); if (newcount < count) // cycle counter has wrapped since last update. { milliseconds += cpu_cy_2_ms(newcount, FCPU_HZ); } else { milliseconds += cpu_cy_2_ms(newcount - count, FCPU_HZ); } count = newcount; return milliseconds; }
/** * @brief get system's internal tick count. * Used for time reference. * @return current tick count. **/ unsigned long inv_get_tick_count(void) { const long cpu_hz = 12000000; long count, ms; count = Get_system_register(AVR32_COUNT); ms = cpu_cy_2_ms(count,cpu_hz); return ms; }
uint32_t time_tick_calc_delay(uint32_t tick_start, uint32_t tick_end) { return cpu_cy_2_ms(tick_end - tick_start, sysclk_get_cpu_hz()); }