-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbed_wait.cpp
43 lines (33 loc) · 972 Bytes
/
mbed_wait.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* mbed_wait.cpp
*
* Created on: Ene 2018
* Author: raulMrello
*
* Implementa la portabilidad de temporizaciones basadas en wait
*
*/
#include "mbed.h"
//------------------------------------------------------------------------------------
//-- PUBLIC METHODS IMPLEMENTATION ---------------------------------------------------
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
void wait(float s) {
wait_us(s * 1000000.0f);
}
//------------------------------------------------------------------------------------
void wait_ms(int ms) {
wait_us(ms * 1000);
}
//------------------------------------------------------------------------------------
void wait_us(int us) {
int ms = us / 1000;
if (MBED_MILLIS_TO_TICK(ms) > 1){
Thread::wait(ms);
}
else{
Timer tmr;
tmr.start();
while(tmr.read_us() < us);
}
}