daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jan 28th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int benchmark();
  2. void reset_timer();
  3. void start_timer();
  4. void stop_timer();
  5. unsigned int getCycles();
  6.  
  7. #define RUNS 1
  8.  
  9. volatile unsigned int numCycles;
  10. int main(void)
  11. {
  12.   int run;
  13.  
  14.   reset_timer(); //reset timer
  15.   start_timer(); //start timer
  16.   for(run = 0; run < RUNS; ++run)
  17.   {
  18.     //puts("Trial\n\r");
  19.     //printf("Run %d\n\r", run+1);
  20.     benchmark();
  21.   }
  22.  
  23.   stop_timer(); //stop timer
  24.   numCycles = getCycles(); //read number of cycles
  25.  
  26.   while(1);
  27.  
  28.   return numCycles;
  29. }
  30.  
  31.  
  32. volatile unsigned int *DWT_CYCCNT  ;
  33. volatile unsigned int *DWT_CONTROL ;
  34. volatile unsigned int *SCB_DEMCR   ;
  35.  
  36. void reset_timer(){
  37.     DWT_CYCCNT   = (int *)0xE0001004; //address of the register
  38.     DWT_CONTROL  = (int *)0xE0001000; //address of the register
  39.     SCB_DEMCR    = (int *)0xE000EDFC; //address of the register
  40.     *SCB_DEMCR   = *SCB_DEMCR | 0x01000000;
  41.     *DWT_CYCCNT  = 0; // reset the counter
  42.     *DWT_CONTROL = 0;
  43. }
  44.  
  45. void start_timer(){
  46.     *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
  47. }
  48.  
  49. void stop_timer(){
  50.     *DWT_CONTROL = *DWT_CONTROL &~ 1; // disable the counter    
  51. }
  52.  
  53. unsigned int getCycles(){
  54.     return *DWT_CYCCNT;
  55. }
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. OK, I Understand
 
Top