SHARE
TWEET
Untitled
a guest
Jan 28th, 2019
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- int benchmark();
- void reset_timer();
- void start_timer();
- void stop_timer();
- unsigned int getCycles();
- #define RUNS 1
- volatile unsigned int numCycles;
- int main(void)
- {
- int run;
- reset_timer(); //reset timer
- start_timer(); //start timer
- for(run = 0; run < RUNS; ++run)
- {
- //puts("Trial\n\r");
- //printf("Run %d\n\r", run+1);
- benchmark();
- }
- stop_timer(); //stop timer
- numCycles = getCycles(); //read number of cycles
- while(1);
- return numCycles;
- }
- volatile unsigned int *DWT_CYCCNT ;
- volatile unsigned int *DWT_CONTROL ;
- volatile unsigned int *SCB_DEMCR ;
- void reset_timer(){
- DWT_CYCCNT = (int *)0xE0001004; //address of the register
- DWT_CONTROL = (int *)0xE0001000; //address of the register
- SCB_DEMCR = (int *)0xE000EDFC; //address of the register
- *SCB_DEMCR = *SCB_DEMCR | 0x01000000;
- *DWT_CYCCNT = 0; // reset the counter
- *DWT_CONTROL = 0;
- }
- void start_timer(){
- *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
- }
- void stop_timer(){
- *DWT_CONTROL = *DWT_CONTROL &~ 1; // disable the counter
- }
- unsigned int getCycles(){
- return *DWT_CYCCNT;
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
