Information About Implementing the Millis Function in the spresense sdk

Asked 2 years ago, Updated 2 years ago, 42 views

I want to control the program that I created with arduino IDE a little bit more, so I put it in the spresense SDK
I'm doing the transplanting work.
Among them, the millis() function did not appear to exist in the spresense SDK.
Please let me know if you know any alternative functions or alternative methods.

spresense

2022-09-29 22:27

2 Answers

I don't know anything about spresense, but looking at the implementation of the Arduino Core Library, it seems that they are using a function called clock_gettime.This looks like an API provided by the SDK, so if you can call it, you will be able to achieve the same behavior as millis.


2022-09-29 22:27

SPRESENSE's Arduino Core Library time.c seems to be implemented as follows:

#include<time.h>
# include <Arduino.h>

... snip...

uint64_t millis(void)
{
    structure timespectp;

    /* Wait until RTC is available*/
    while(g_rtc_enabled==false);

    if(clock_gettime(CLOCK_MONOTONIC, & tp)){
        return 0;
    }

    return((uint64_t)tp.tv_sec)*1000+tp.tv_nsec/1000000);
}

For your information.


2022-09-29 22:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.