Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MRAA timer functions #950

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions utility/MRAA/compatibility.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "compatibility.h"
#include <time.h>
#include <chrono>
//static struct timeval start, end;
//static long mtime, seconds, useconds;

/**********************************************************************/
/**
Expand All @@ -10,33 +9,30 @@
*/
void __msleep(int milisec)
{
struct timespec req = {0};
req.tv_sec = 0;
req.tv_nsec = milisec * 1000000L;
nanosleep(&req, (struct timespec*)NULL);
//usleep(milisec*1000);
struct timespec req; // = {0};
req.tv_sec = (time_t)milisec / 1000;
req.tv_nsec = (milisec % 1000) * 1000000L;
clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
}

void __usleep(int milisec)
void __usleep(int microsec)
{
struct timespec req = {0};
req.tv_sec = 0;
req.tv_nsec = milisec * 1000L;
nanosleep(&req, (struct timespec*)NULL);
//usleep(milisec);
struct timespec req; // = {0};
req.tv_sec = (time_t)microsec / 1000000;
req.tv_nsec = (microsec / 1000000) * 1000;
2bndy5 marked this conversation as resolved.
Show resolved Hide resolved
clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
}

auto start = std::chrono::steady_clock::now();

/**
* This function is added in order to simulate arduino millis() function
*/
void __start_timer()
{
//gettimeofday(&start, NULL);
}

long __millis()
auto start = std::chrono::steady_clock::now();

uint32_t __millis()
{
auto end = std::chrono::steady_clock::now();

Expand Down
3 changes: 2 additions & 1 deletion utility/MRAA/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ extern "C" {
#include <stddef.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>

void __msleep(int milisec);

void __usleep(int milisec);

void __start_timer();

long __millis();
uint32_t __millis();

#ifdef __cplusplus
}
Expand Down