basic code timer for microcontroller usage

Files at this revision

API Documentation at this revision

Comitter:
snapo
Date:
Sun Oct 31 10:42:20 2021 +0000
Commit message:
basic timer for code optimisation

Changed in this revision

codeTimer.cpp Show annotated file Show diff for this revision Revisions of this file
codeTimer.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ef39a53751b9 codeTimer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeTimer.cpp	Sun Oct 31 10:42:20 2021 +0000
@@ -0,0 +1,21 @@
+#include "codeTimer.h"
+
+void CTIMER::cTimerStart(){
+    t_.reset();
+    t_.start();
+}
+
+void CTIMER::cTimerBreak(unsigned int interval){
+    t_.stop();
+    printf("Time interval %x : %lld \n" , interval, duration_cast<std::chrono::microseconds>(t_.elapsed_time()).count());
+    time_us_ += duration_cast<std::chrono::microseconds>(t_.elapsed_time()).count();
+    t_.reset();
+    t_.start(); 
+}
+
+void CTIMER::cTimerStop(){
+    t_.stop();
+    printf("Time interval finish : %lld \n" , duration_cast<std::chrono::microseconds>(t_.elapsed_time()).count());
+    time_us_ += duration_cast<std::chrono::microseconds>(t_.elapsed_time()).count();
+    printf("Total Time for completion : %lld \n" , time_us_ += duration_cast<std::chrono::microseconds>(t_.elapsed_time()).count());
+}
\ No newline at end of file
diff -r 000000000000 -r ef39a53751b9 codeTimer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeTimer.h	Sun Oct 31 10:42:20 2021 +0000
@@ -0,0 +1,13 @@
+#pragma once
+#include "mbed.h"
+
+class CTIMER {
+    long long time_us_;
+    Timer t_;
+public:
+
+    void cTimerStart();
+    void cTimerBreak(unsigned int timeInterval);
+    void cTimerStop();
+
+};
\ No newline at end of file