Atomic operations with <stdatomic.h> in IDF?

jabakobob
Posts: 7
Joined: Thu Dec 29, 2016 11:48 am

Atomic operations with <stdatomic.h> in IDF?

Postby jabakobob » Thu Jan 05, 2017 9:10 am

Hi!

I'm trying to write an ISR for a quadrature encoder. My function needs to xor a global variable and increments a global counter. I figured the correct way to do that would be by using atomic operations defined in <stdatomic.h>. However, when I include this header file, I get a lot of error messages (see below).

What's the recommended way to perform atomic operations if we can't use functions like atomic_fetch_xor(), atomic_fetch_add() ?

Code: Select all

In file included from /Users/jakob/Documents/esp32/idf/esp-idf/components/newlib/include/stdatomic.h:33:0,
                 from /Users/jakob/Documents/esp32/idf/romibot/main/./odometry.c:1:
/Users/jakob/Documents/esp32/idf/esp-idf/components/newlib/include/stdatomic.h:204:17: error: expected specifier-qualifier-list before 'int_least8_t'
 typedef _Atomic(int_least8_t)  atomic_int_least8_t;
                 ^
/Users/jakob/Documents/esp32/idf/esp-idf/components/newlib/include/sys/cdefs.h:296:30: note: in definition of macro '_Atomic'
 #define _Atomic(T)  struct { T volatile __val; }
                              ^
/Users/jakob/Documents/esp32/idf/esp-idf/components/newlib/include/stdatomic.h:205:17: error: expected specifier-qualifier-list before 'uint_least8_t'
 typedef _Atomic(uint_least8_t)  atomic_uint_least8_t;
                 ^
   ( ... and so on ...)

jabakobob
Posts: 7
Joined: Thu Dec 29, 2016 11:48 am

Re: Atomic operations with <stdatomic.h> in IDF?

Postby jabakobob » Thu Jan 05, 2017 9:46 am

I was able to fix the errors by including esp_types.h first:

Code: Select all

#include <esp_types.h>
#include <stdatomic.h>

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Atomic operations with <stdatomic.h> in IDF?

Postby ESP_Angus » Thu Jan 05, 2017 11:15 pm

Thanks jakob. For the record, I think including stdint.h is all that is strictly needed. Will fix this in esp-idf.

Who is online

Users browsing this forum: acsoprana, Gaston1980, Google [Bot] and 82 guests