nanosleep library issue

arpiabeka
Posts: 3
Joined: Fri May 04, 2018 5:28 pm

nanosleep library issue

Postby arpiabeka » Sat Oct 27, 2018 3:19 pm

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

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: nanosleep library issue

Postby ESP_Sprite » Sun Oct 28, 2018 2:37 am

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.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: nanosleep library issue

Postby ESP_igrr » Mon Oct 29, 2018 2:24 am

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!

arpiabeka
Posts: 3
Joined: Fri May 04, 2018 5:28 pm

Re: nanosleep library issue

Postby arpiabeka » Mon Oct 29, 2018 5:07 am

For the time being I will try usleep.
RMT looks promising also. Thank you for your answers.

Who is online

Users browsing this forum: jtroncin21 and 121 guests