| @@ -0,0 +1,38 @@ | |||||
| /* From: https://stackoverflow.com/questions/32610019/arm-m4-instructions-per-cycle-ipc-counters */ | |||||
| /* minor formating + type fixes */ | |||||
| volatile unsigned int *DWT_CYCCNT ; | |||||
| volatile unsigned int *DWT_CONTROL ; | |||||
| volatile unsigned int *SCB_DEMCR ; | |||||
| static void | |||||
| reset_timer() | |||||
| { | |||||
| DWT_CYCCNT = (unsigned int *)0xE0001004; //address of the register | |||||
| DWT_CONTROL = (unsigned int *)0xE0001000; //address of the register | |||||
| SCB_DEMCR = (unsigned int *)0xE000EDFC; //address of the register | |||||
| *SCB_DEMCR = *SCB_DEMCR | 0x01000000; | |||||
| *DWT_CYCCNT = 0; // reset the counter | |||||
| *DWT_CONTROL = 0; | |||||
| } | |||||
| static void start_timer() | |||||
| { | |||||
| *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter | |||||
| } | |||||
| static void | |||||
| stop_timer() | |||||
| { | |||||
| *DWT_CONTROL = *DWT_CONTROL | 0 ; // disable the counter | |||||
| } | |||||
| static unsigned int | |||||
| getCycles() | |||||
| { | |||||
| return *DWT_CYCCNT; | |||||
| } | |||||