Merge branch 'feature/upgrade_c_cxx_standards' into 'master'

build system: use C17 and C++2a by default

Closes IDF-1499, IDFGH-1788, IDFGH-2781, and IDFGH-7617

See merge request espressif/esp-idf!18371
This commit is contained in:
Jakob Hasse 2022-06-20 12:24:08 +08:00
commit d7cceabbb4
23 changed files with 281 additions and 161 deletions

View File

@ -30,6 +30,7 @@
# define ASIO_SEPARATE_COMPILATION # define ASIO_SEPARATE_COMPILATION
# define ASIO_STANDALONE # define ASIO_STANDALONE
# define ASIO_HAS_PTHREADS # define ASIO_HAS_PTHREADS
# define ASIO_DISABLE_CONCEPTS
# ifdef CONFIG_ASIO_USE_ESP_OPENSSL # ifdef CONFIG_ASIO_USE_ESP_OPENSSL
# define ASIO_USE_ESP_OPENSSL # define ASIO_USE_ESP_OPENSSL

View File

@ -127,6 +127,3 @@ else()
REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support
LDFRAGMENTS linker.lf) LDFRAGMENTS linker.lf)
endif() endif()
# uses C11 atomic feature
set_source_files_properties(spi_master.c PROPERTIES COMPILE_FLAGS -std=gnu11)

View File

@ -40,7 +40,10 @@
* ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value") * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value")
* }; * };
*/ */
#ifdef __cplusplus #if defined(__cplusplus) && __cplusplus >= 202002L
#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) .member = value,
#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
#elif defined(__cplusplus) && __cplusplus < 202002L
#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value }, #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value },
#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { }, #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
#else #else

View File

@ -53,6 +53,3 @@ idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ${include} INCLUDE_DIRS ${include}
REQUIRES "esp_event" # For using "ESP_EVENT_DECLARE_BASE" in header file REQUIRES "esp_event" # For using "ESP_EVENT_DECLARE_BASE" in header file
PRIV_REQUIRES ${priv_requires}) PRIV_REQUIRES ${priv_requires})
# uses C11 atomic feature
set_source_files_properties(src/esp_eth.c PROPERTIES COMPILE_FLAGS -std=gnu11)

View File

@ -25,8 +25,3 @@ idf_component_register(SRCS ${srcs}
REQUIRES ${requires} REQUIRES ${requires}
PRIV_REQUIRES ${priv_requires} PRIV_REQUIRES ${priv_requires}
LDFRAGMENTS linker.lf) LDFRAGMENTS linker.lf)
if(CONFIG_ESP_EVENT_LOOP_PROFILING)
# uses C11 atomic feature
set_source_files_properties(esp_event.c PROPERTIES COMPILE_FLAGS -std=gnu11)
endif()

View File

@ -37,10 +37,10 @@
#endif #endif
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
ASSERT_IF_DPORT_REG((_r), REG_WRITE); \ ASSERT_IF_DPORT_REG((_r), REG_WRITE); \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -55,22 +55,22 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
ASSERT_IF_DPORT_REG((_r), REG_SET_BIT); \ ASSERT_IF_DPORT_REG((_r), REG_SET_BIT); \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
ASSERT_IF_DPORT_REG((_r), REG_CLR_BIT); \ ASSERT_IF_DPORT_REG((_r), REG_CLR_BIT); \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
ASSERT_IF_DPORT_REG((_r), REG_SET_BITS); \ ASSERT_IF_DPORT_REG((_r), REG_SET_BITS); \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -79,10 +79,10 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
ASSERT_IF_DPORT_REG((_r), REG_SET_FIELD); \ ASSERT_IF_DPORT_REG((_r), REG_SET_FIELD); \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -109,22 +109,22 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
ASSERT_IF_DPORT_REG((addr), WRITE_PERI_REG); \ ASSERT_IF_DPORT_REG((addr), WRITE_PERI_REG); \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
ASSERT_IF_DPORT_REG((reg), CLEAR_PERI_REG_MASK); \ ASSERT_IF_DPORT_REG((reg), CLEAR_PERI_REG_MASK); \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_MASK); \ ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_MASK); \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -139,10 +139,10 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_BITS); \ ASSERT_IF_DPORT_REG((reg), SET_PERI_REG_BITS); \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -39,9 +39,9 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -54,19 +54,19 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -74,9 +74,9 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -102,19 +102,19 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -127,9 +127,9 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -32,9 +32,9 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -47,19 +47,19 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -67,9 +67,9 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -95,19 +95,19 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -120,9 +120,9 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -32,9 +32,9 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -47,19 +47,19 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -67,9 +67,9 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -95,19 +95,19 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -120,9 +120,9 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -38,9 +38,9 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -53,19 +53,19 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -73,9 +73,9 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -101,19 +101,19 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -126,9 +126,9 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -48,9 +48,9 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
//write value to register //write value to register
#define REG_WRITE(_r, _v) ({ \ #define REG_WRITE(_r, _v) do { \
(*(volatile uint32_t *)(_r)) = (_v); \ (*(volatile uint32_t *)(_r)) = (_v); \
}) } while(0)
//read value from register //read value from register
#define REG_READ(_r) ({ \ #define REG_READ(_r) ({ \
@ -63,19 +63,19 @@
}) })
//set bit or set bits to register //set bit or set bits to register
#define REG_SET_BIT(_r, _b) ({ \ #define REG_SET_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) |= (_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
}) } while(0)
//clear bit or clear bits of register //clear bit or clear bits of register
#define REG_CLR_BIT(_r, _b) ({ \ #define REG_CLR_BIT(_r, _b) do { \
(*(volatile uint32_t*)(_r) &= ~(_b)); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define REG_SET_BITS(_r, _b, _m) ({ \ #define REG_SET_BITS(_r, _b, _m) do { \
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \ *(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
}) } while(0)
//get field from register, uses field _S & _V to determine mask //get field from register, uses field _S & _V to determine mask
#define REG_GET_FIELD(_r, _f) ({ \ #define REG_GET_FIELD(_r, _f) ({ \
@ -83,9 +83,9 @@
}) })
//set field of a register from variable, uses field _S & _V to determine mask //set field of a register from variable, uses field _S & _V to determine mask
#define REG_SET_FIELD(_r, _f, _v) ({ \ #define REG_SET_FIELD(_r, _f, _v) do { \
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \ REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))); \
}) } while(0)
//get field value from a variable, used when _f is not left shifted by _f##_S //get field value from a variable, used when _f is not left shifted by _f##_S
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
@ -111,19 +111,19 @@
}) })
//write value to register //write value to register
#define WRITE_PERI_REG(addr, val) ({ \ #define WRITE_PERI_REG(addr, val) do { \
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \ (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
}) } while(0)
//clear bits of register controlled by mask //clear bits of register controlled by mask
#define CLEAR_PERI_REG_MASK(reg, mask) ({ \ #define CLEAR_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
}) } while(0)
//set bits of register controlled by mask //set bits of register controlled by mask
#define SET_PERI_REG_MASK(reg, mask) ({ \ #define SET_PERI_REG_MASK(reg, mask) do { \
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \ WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
}) } while(0)
//get bits of register controlled by mask //get bits of register controlled by mask
#define GET_PERI_REG_MASK(reg, mask) ({ \ #define GET_PERI_REG_MASK(reg, mask) ({ \
@ -136,9 +136,9 @@
}) })
//set bits of register controlled by mask and shift //set bits of register controlled by mask and shift
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \ #define SET_PERI_REG_BITS(reg,bit_map,value,shift) do { \
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) )); \ WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & (bit_map))<<(shift)) ); \
}) } while(0)
//get field of register //get field of register
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \ #define GET_PERI_REG_BITS2(reg, mask,shift) ({ \

View File

@ -319,3 +319,22 @@ LCD
7. Calling :cpp:func:`i2s_channel_disable` to stop the hardware of I2S channel. 7. Calling :cpp:func:`i2s_channel_disable` to stop the hardware of I2S channel.
8. Calling :cpp:func:`i2s_del_channel` to delete and release the resources of the channel if it is not needed any more, but the channel must be disabled before deleting it. 8. Calling :cpp:func:`i2s_del_channel` to delete and release the resources of the channel if it is not needed any more, but the channel must be disabled before deleting it.
Register access macros
----------------------
Previously, all register access macros could be used as expressions, so the following was allowed::
uint32_t val = REG_SET_BITS(reg, mask);
In IDF v5.0, register access macros which write or read-modify-write the register can no longer be used as expressions, and can only be used as statements. This applies to the following macros: ``REG_WRITE``, ``REG_SET_BIT``, ``REG_CLR_BIT``, ``REG_SET_BITS``, ``REG_SET_FIELD``, ``WRITE_PERI_REG``, ``CLEAR_PERI_REG_MASK``, ``SET_PERI_REG_MASK``, ``SET_PERI_REG_BITS``.
To store the value which would have been written into the register, split the operation as follows::
uint32_t new_val = REG_READ(reg) | mask;
REG_WRITE(reg, new_val);
To get the value of the register after modification (which may be different from the value written), add an explicit read::
REG_SET_BITS(reg, mask);
uint32_t new_val = REG_READ(reg);

View File

@ -4,8 +4,6 @@ idf_component_register(SRCS "esp_mqtt_cxx.cpp"
INCLUDE_DIRS "include" INCLUDE_DIRS "include"
) )
target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17")
if(TEST_BUILD) if(TEST_BUILD)
message(STATUS "Test build") message(STATUS "Test build")
idf_component_get_property(mqtt_dir mqtt COMPONENT_DIR) idf_component_get_property(mqtt_dir mqtt COMPONENT_DIR)

View File

@ -1,4 +1,2 @@
idf_component_register(SRCS "mqtt_ssl_example.cpp" idf_component_register(SRCS "mqtt_ssl_example.cpp"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17")

View File

@ -1,3 +1,2 @@
idf_component_register(SRCS "mqtt_tcp_example.cpp" idf_component_register(SRCS "mqtt_tcp_example.cpp"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-std=gnu++17")

View File

@ -18,8 +18,8 @@
class chat_message class chat_message
{ {
public: public:
enum { header_length = 4 }; static constexpr std::size_t header_length = 4;
enum { max_body_length = 512 }; static constexpr std::size_t max_body_length = 512;
chat_message() chat_message()
: body_length_(0) : body_length_(0)

View File

@ -117,16 +117,57 @@ function(__build_set_default_build_specifications)
# go into the final binary so have no impact on size # go into the final binary so have no impact on size
"-ggdb") "-ggdb")
list(APPEND c_compile_options "-std=gnu99")
list(APPEND cxx_compile_options "-std=gnu++11")
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
endfunction() endfunction()
function(__build_set_lang_version)
if(NOT IDF_TARGET STREQUAL "linux")
# Building for chip targets: we use a known version of the toolchain.
# Use latest supported versions.
set(c_std gnu17)
set(cxx_std gnu++20)
else()
enable_language(C CXX)
# Building for Linux target, fall back to an older version of the standard
# if the preferred one is not supported by the compiler.
set(preferred_c_versions gnu17 gnu11 gnu99)
set(ver_found FALSE)
foreach(c_version ${preferred_c_versions})
check_c_compiler_flag("-std=${c_version}" ver_${c_version}_supported)
if(ver_${c_version}_supported)
set(c_std ${c_version})
set(ver_found TRUE)
break()
endif()
endforeach()
if(NOT ver_found)
message(FATAL_ERROR "Failed to set C language standard to one of the supported versions: "
"${preferred_c_versions}. Please upgrade the host compiler.")
endif()
set(preferred_cxx_versions gnu++20 gnu++2a gnu++17 gnu++14)
set(ver_found FALSE)
foreach(cxx_version ${preferred_cxx_versions})
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)
if(ver_${cxx_version}_supported)
set(cxx_std ${cxx_version})
set(ver_found TRUE)
break()
endif()
endforeach()
if(NOT ver_found)
message(FATAL_ERROR "Failed to set C++ language standard to one of the supported versions: "
"${preferred_cxx_versions}. Please upgrade the host compiler.")
endif()
endif()
idf_build_set_property(C_COMPILE_OPTIONS "-std=${c_std}" APPEND)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=${cxx_std}" APPEND)
endfunction()
# #
# Initialize the build. This gets called upon inclusion of idf.cmake to set internal # Initialize the build. This gets called upon inclusion of idf.cmake to set internal
# properties used for the processing phase of the build. # properties used for the processing phase of the build.
@ -151,6 +192,7 @@ function(__build_init idf_path)
idf_build_set_property(IDF_COMPONENT_MANAGER 0) idf_build_set_property(IDF_COMPONENT_MANAGER 0)
__build_set_default_build_specifications() __build_set_default_build_specifications()
__build_set_lang_version()
# Add internal components to the build # Add internal components to the build
idf_build_get_property(idf_path IDF_PATH) idf_build_get_property(idf_path IDF_PATH)

View File

@ -36,6 +36,8 @@ if(NOT __idf_env_set)
set(IDF_PATH ${idf_path}) set(IDF_PATH ${idf_path})
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(git_submodules) include(git_submodules)
include(crosstool_version_check) include(crosstool_version_check)
include(kconfig) include(kconfig)

View File

@ -0,0 +1,9 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
set(COMPONENTS main)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(cxx_build_test)

View File

@ -0,0 +1,7 @@
# C++ build test
This build-only app can be used to check if certain headers, macros or features can be successfully compiled in a C++ source file.
To add a new test, create a new file `main/test_<name>.cpp` and add it to main/CMakeLists.txt.
If you need to check specific compiler flags, use `set_source_files_properties` CMake function to adjust the compilation flags for the given source file.

View File

@ -0,0 +1,4 @@
idf_component_register(SRCS cxx_build_test_main.cpp
test_soc_reg_macros.cpp
INCLUDE_DIRS "."
REQUIRES soc)

View File

@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
extern "C" void app_main(void)
{
}

View File

@ -0,0 +1,39 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* Compiling this file checks if SoC register access macros
* can be used from C++ successfully. This check is necessary
* because C++ 20 deprecates certain uses of 'volatile' qualified
* variables.
*/
#include "soc/soc.h"
#include "soc/uart_reg.h"
/* non-static, to prevent the value being optimized out */
void sink(uint32_t arg)
{
}
void test_reg_macros(void)
{
REG_WRITE(UART_DATE_REG(0), 1);
sink(REG_READ(UART_DATE_REG(0)));
sink(REG_GET_BIT(UART_DATE_REG(0), BIT(0)));
REG_SET_BIT(UART_DATE_REG(0), BIT(0));
REG_CLR_BIT(UART_DATE_REG(0), BIT(0));
REG_SET_BITS(UART_DATE_REG(0), BIT(0), BIT(0) | BIT(1));
sink(REG_GET_FIELD(UART_DATE_REG(0), UART_DATE));
REG_SET_FIELD(UART_DATE_REG(0), UART_DATE, 42);
sink(READ_PERI_REG(UART_DATE_REG(0)));
WRITE_PERI_REG(UART_DATE_REG(0), 1);
CLEAR_PERI_REG_MASK(UART_DATE_REG(0), BIT(0));
SET_PERI_REG_MASK(UART_DATE_REG(0), BIT(0));
sink(GET_PERI_REG_MASK(UART_DATE_REG(0), BIT(0)));
sink(GET_PERI_REG_BITS(UART_DATE_REG(0), 2, 1));
SET_PERI_REG_BITS(UART_DATE_REG(0), BIT(0) | BIT(1), 1, 2);
sink(GET_PERI_REG_BITS2(UART_DATE_REG(0), BIT(0) | BIT(1), 1));
}