Fix #50: Enable core cycle counter
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <reflow-controller/main-cycle-counter.h>
|
||||
#include <helper-macros/helper-macros.h>
|
||||
#include <stm32/stm32f4xx.h>
|
||||
|
||||
/**
|
||||
* @brief Variable storing the main cycle counter.
|
||||
@@ -33,7 +34,22 @@
|
||||
*/
|
||||
static uint64_t IN_SECTION(.ccm.bss) main_cycle_counter;
|
||||
|
||||
void main_cycle_counter_init(void)
|
||||
void main_and_core_cycle_counter_init(void)
|
||||
{
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
|
||||
/* Enable the core cycle counter if available on current processor */
|
||||
if (!(DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk)) {
|
||||
/* Cycle counter is available. Enable */
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
}
|
||||
|
||||
/* Reset the counters to 0 */
|
||||
main_cycle_counter_reset();
|
||||
core_cycle_counter_reset();
|
||||
}
|
||||
|
||||
void main_cycle_counter_reset(void)
|
||||
{
|
||||
main_cycle_counter = 0ULL;
|
||||
}
|
||||
@@ -48,4 +64,14 @@ uint64_t main_cycle_counter_get(void)
|
||||
return main_cycle_counter;
|
||||
}
|
||||
|
||||
void core_cycle_counter_reset(void)
|
||||
{
|
||||
DWT->CYCCNT = 0UL;
|
||||
}
|
||||
|
||||
uint32_t core_cycle_counter_get(void)
|
||||
{
|
||||
return DWT->CYCCNT;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Reference in New Issue
Block a user