/* * peripherals_utility.cpp * * Created on: Feb 24, 2021 * Author: erki */ #include "peripherals_utility.hpp" #include "main.h" namespace Peripherals { void Initialize() { #ifdef PERIPHERALS_USE_DELAY_US CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; #endif } #ifdef PERIPHERALS_USE_DELAY_US void DelayUs(const std::uint32_t micros) { const std::uint32_t tick_start = DWT->CYCCNT; const std::uint32_t ticks_delay = micros * (SystemCoreClock / 1'000'000); while (DWT->CYCCNT - tick_start < ticks_delay); } #endif }