mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 06:07:48 +00:00
[posix] use real time signal for microsecond timer (#5122)
This commit is contained in:
@@ -36,13 +36,7 @@
|
||||
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#ifndef __linux__
|
||||
#define __linux__ 0
|
||||
#endif
|
||||
|
||||
// linux microsecond timer
|
||||
#if __linux__
|
||||
|
||||
#ifdef __linux__
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -67,6 +61,12 @@ timer_t sMicroTimer;
|
||||
|
||||
#define DEFAULT_TIMEOUT 10 // seconds
|
||||
|
||||
#ifdef CLOCK_MONOTONIC_RAW
|
||||
#define OT_SIMULATION_CLOCK_ID CLOCK_MONOTONIC_RAW
|
||||
#else
|
||||
#define OT_SIMULATION_CLOCK_ID CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
static bool sIsMsRunning = false;
|
||||
static uint32_t sMsAlarm = 0;
|
||||
|
||||
@@ -75,7 +75,7 @@ static uint32_t sUsAlarm = 0;
|
||||
|
||||
static uint32_t sSpeedUpFactor = 1;
|
||||
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
static void microTimerHandler(int aSignal, siginfo_t *aSignalInfo, void *aUserContext)
|
||||
{
|
||||
assert(aSignal == OPENTHREAD_CONFIG_MICRO_TIMER_SIGNAL);
|
||||
@@ -90,7 +90,7 @@ void platformAlarmInit(uint32_t aSpeedUpFactor)
|
||||
{
|
||||
sSpeedUpFactor = aSpeedUpFactor;
|
||||
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
@@ -110,7 +110,7 @@ void platformAlarmInit(uint32_t aSpeedUpFactor)
|
||||
sev.sigev_signo = OPENTHREAD_CONFIG_MICRO_TIMER_SIGNAL;
|
||||
sev.sigev_value.sival_ptr = &sMicroTimer;
|
||||
|
||||
if (-1 == timer_create(CLOCK_REALTIME, &sev, &sMicroTimer))
|
||||
if (-1 == timer_create(CLOCK_MONOTONIC, &sev, &sMicroTimer))
|
||||
{
|
||||
perror("timer_create");
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -125,11 +125,7 @@ uint64_t platformGetNow(void)
|
||||
struct timespec now;
|
||||
int err;
|
||||
|
||||
#ifdef CLOCK_MONOTONIC_RAW
|
||||
err = clock_gettime(CLOCK_MONOTONIC_RAW, &now);
|
||||
#else
|
||||
err = clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
#endif
|
||||
err = clock_gettime(OT_SIMULATION_CLOCK_ID, &now);
|
||||
|
||||
VerifyOrDie(err == 0, OT_EXIT_ERROR_ERRNO);
|
||||
|
||||
@@ -181,7 +177,7 @@ void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
sUsAlarm = aT0 + aDt;
|
||||
sIsUsRunning = true;
|
||||
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
{
|
||||
struct itimerspec its;
|
||||
uint32_t diff = sUsAlarm - otPlatAlarmMicroGetNow();
|
||||
@@ -207,7 +203,7 @@ void otPlatAlarmMicroStop(otInstance *aInstance)
|
||||
|
||||
sIsUsRunning = false;
|
||||
|
||||
#if __linux__
|
||||
#ifdef __linux__
|
||||
{
|
||||
struct itimerspec its = {{0, 0}, {0, 0}};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user