Timer peripheral class. This lib. include function ; WAIT, stop, reset, start, and read_ms.

Dependents:   DetectFreqAboveTH RN41

Committer:
AkinoriHashimoto
Date:
Fri Sep 29 07:05:10 2017 +0000
Revision:
7:8fbe0cf9d582
Parent:
6:4cb4eea64805
adj. wait_us()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:04c9087b9ca9 1 #include "myTimer.h"
AkinoriHashimoto 0:04c9087b9ca9 2
AkinoriHashimoto 0:04c9087b9ca9 3
AkinoriHashimoto 0:04c9087b9ca9 4 myTimer::myTimer()
AkinoriHashimoto 0:04c9087b9ca9 5 {
AkinoriHashimoto 0:04c9087b9ca9 6 this->stop();
AkinoriHashimoto 0:04c9087b9ca9 7 this->reset();
AkinoriHashimoto 0:04c9087b9ca9 8 }
AkinoriHashimoto 0:04c9087b9ca9 9
AkinoriHashimoto 0:04c9087b9ca9 10 void myTimer::stop()
AkinoriHashimoto 0:04c9087b9ca9 11 {
AkinoriHashimoto 0:04c9087b9ca9 12 this->timer.stop();
AkinoriHashimoto 0:04c9087b9ca9 13 return;
AkinoriHashimoto 0:04c9087b9ca9 14 }
AkinoriHashimoto 0:04c9087b9ca9 15
AkinoriHashimoto 0:04c9087b9ca9 16 void myTimer::reset()
AkinoriHashimoto 0:04c9087b9ca9 17 {
AkinoriHashimoto 0:04c9087b9ca9 18 this->timer.reset();
AkinoriHashimoto 0:04c9087b9ca9 19 return;
AkinoriHashimoto 0:04c9087b9ca9 20 }
AkinoriHashimoto 0:04c9087b9ca9 21
AkinoriHashimoto 2:3060a6604f13 22 void myTimer::start(bool _RESET)
AkinoriHashimoto 0:04c9087b9ca9 23 {
AkinoriHashimoto 2:3060a6604f13 24 if(_RESET)
AkinoriHashimoto 2:3060a6604f13 25 this->reset();
AkinoriHashimoto 0:04c9087b9ca9 26 this->timer.start();
AkinoriHashimoto 0:04c9087b9ca9 27 return;
AkinoriHashimoto 0:04c9087b9ca9 28 }
AkinoriHashimoto 0:04c9087b9ca9 29
AkinoriHashimoto 0:04c9087b9ca9 30 int myTimer::read_ms(bool _START, bool _RESET, bool _STOP)
AkinoriHashimoto 0:04c9087b9ca9 31 {
AkinoriHashimoto 0:04c9087b9ca9 32 int ans= 0;
AkinoriHashimoto 0:04c9087b9ca9 33 if(_STOP)
AkinoriHashimoto 0:04c9087b9ca9 34 this->stop();
AkinoriHashimoto 2:3060a6604f13 35
AkinoriHashimoto 0:04c9087b9ca9 36 ans= this->timer.read_ms();
AkinoriHashimoto 2:3060a6604f13 37
AkinoriHashimoto 0:04c9087b9ca9 38 if(_RESET)
AkinoriHashimoto 0:04c9087b9ca9 39 this->reset();
AkinoriHashimoto 2:3060a6604f13 40
AkinoriHashimoto 0:04c9087b9ca9 41 if(_START)
AkinoriHashimoto 0:04c9087b9ca9 42 this->start();
AkinoriHashimoto 2:3060a6604f13 43
AkinoriHashimoto 0:04c9087b9ca9 44 return ans;
AkinoriHashimoto 1:685c0f37a569 45 }
AkinoriHashimoto 5:c9304777ce1a 46 int myTimer::read_us(bool _START, bool _RESET, bool _STOP)
AkinoriHashimoto 5:c9304777ce1a 47 {
AkinoriHashimoto 5:c9304777ce1a 48 int ans= 0;
AkinoriHashimoto 5:c9304777ce1a 49 if(_STOP)
AkinoriHashimoto 5:c9304777ce1a 50 this->stop();
AkinoriHashimoto 5:c9304777ce1a 51
AkinoriHashimoto 5:c9304777ce1a 52 ans= this->timer.read_us();
AkinoriHashimoto 5:c9304777ce1a 53
AkinoriHashimoto 5:c9304777ce1a 54 if(_RESET)
AkinoriHashimoto 5:c9304777ce1a 55 this->reset();
AkinoriHashimoto 5:c9304777ce1a 56
AkinoriHashimoto 5:c9304777ce1a 57 if(_START)
AkinoriHashimoto 5:c9304777ce1a 58 this->start();
AkinoriHashimoto 5:c9304777ce1a 59
AkinoriHashimoto 5:c9304777ce1a 60 return ans;
AkinoriHashimoto 5:c9304777ce1a 61 }
AkinoriHashimoto 1:685c0f37a569 62
AkinoriHashimoto 1:685c0f37a569 63 void myTimer::wait_ms(int waitTime, bool _START, bool _RESET, bool _STOP)
AkinoriHashimoto 1:685c0f37a569 64 {
AkinoriHashimoto 1:685c0f37a569 65 int wt= waitTime- this->read_ms(_START, _RESET, _STOP);
AkinoriHashimoto 1:685c0f37a569 66 if(wt <= 0)
AkinoriHashimoto 1:685c0f37a569 67 return;
AkinoriHashimoto 3:de4737751df6 68 ::wait_ms(wt);
AkinoriHashimoto 4:2f7a8e62597a 69 if(_RESET)
AkinoriHashimoto 4:2f7a8e62597a 70 this->reset();
AkinoriHashimoto 1:685c0f37a569 71 return;
AkinoriHashimoto 6:4cb4eea64805 72 }
AkinoriHashimoto 6:4cb4eea64805 73 void myTimer::wait_us(int waitTime, bool _START, bool _RESET, bool _STOP)
AkinoriHashimoto 6:4cb4eea64805 74 {
AkinoriHashimoto 6:4cb4eea64805 75 int wt= waitTime- this->read_us(_START, _RESET, _STOP);
AkinoriHashimoto 6:4cb4eea64805 76 if(wt <= 0)
AkinoriHashimoto 6:4cb4eea64805 77 return;
AkinoriHashimoto 6:4cb4eea64805 78 ::wait_us(wt);
AkinoriHashimoto 6:4cb4eea64805 79 if(_RESET)
AkinoriHashimoto 6:4cb4eea64805 80 this->reset();
AkinoriHashimoto 6:4cb4eea64805 81 return;
AkinoriHashimoto 0:04c9087b9ca9 82 }