Page 1 of 1

nanosleep library issue

Posted: Sat Oct 27, 2018 3:19 pm
by arpiabeka
Hello,

I would like to use nanosleep() function but I got this error on compile:
error: implicit declaration of function 'nanosleep' [-Werror=implicit-function-declaration]
nanosleep(&tim , &tim2);
^

My code looks like this:

Code: Select all

#include "sdkconfig.h"
#include <stdio.h>
#include <time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "soc/cpu.h"
#include "esp_clk.h"

void app_main()
{
	int clock_freq = esp_clk_cpu_freq();
	printf("CPU Freq %d \n", clock_freq);
	struct timespec tim, tim2;
	tim.tv_sec =0;
	tim.tv_nsec = 500000000L;
	nanosleep(&tim , &tim2);
	fflush(stdout);
	esp_restart();
	return;
}
time.h is included and I am not sure ESP-IDF has an alternate.
Any help are welcome!

Regards,
Arpi

Re: nanosleep library issue

Posted: Sun Oct 28, 2018 2:37 am
by ESP_Sprite
Suggest you either use vTaskDelay (https://www.freertos.org/a00127.html) for large-ish delays (>20mS or so), and if you really need it, ets_delay_us for short ones. Note that if you need this to do bitbanging, you may be better off looking at the hardware peripherals we have, there's usually one that can do what you want in hardware.

Re: nanosleep library issue

Posted: Mon Oct 29, 2018 2:24 am
by ESP_igrr
There's also 'usleep' which is a portable wrapper around ets_delay_us or vTaskDelay, depending on whether the delay is larger or smaller than the tick period. Thanks for the pointer about the missing nanosleep!

Re: nanosleep library issue

Posted: Mon Oct 29, 2018 5:07 am
by arpiabeka
For the time being I will try usleep.
RMT looks promising also. Thank you for your answers.