mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
soc: make register access macros compatible with C++20
In C++20, using the result of an assignment to a 'volatile' value is deprecated. Breaking change: register "setter" or modification macros can no longer be used as expressions. Closes https://github.com/espressif/esp-idf/issues/9170
This commit is contained in:
parent
157247f98f
commit
3973db7664
@ -37,10 +37,10 @@
|
||||
#endif
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
ASSERT_IF_DPORT_REG((_r), REG_WRITE); \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -55,22 +55,22 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//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); \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//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); \
|
||||
(*(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
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -79,10 +79,10 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
(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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -109,22 +109,22 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
(*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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); \
|
||||
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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); \
|
||||
WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -139,10 +139,10 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
(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
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -39,9 +39,9 @@
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -54,19 +54,19 @@
|
||||
})
|
||||
|
||||
//set bit or set bits to register
|
||||
#define REG_SET_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
#define REG_SET_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//clear bit or clear bits of register
|
||||
#define REG_CLR_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
#define REG_CLR_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//set bits of register controlled by mask
|
||||
#define REG_SET_BITS(_r, _b, _m) ({ \
|
||||
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \
|
||||
})
|
||||
#define REG_SET_BITS(_r, _b, _m) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
|
||||
} while(0)
|
||||
|
||||
//get field from register, uses field _S & _V to determine mask
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -74,9 +74,9 @@
|
||||
})
|
||||
|
||||
//set field of a register from variable, uses field _S & _V to determine mask
|
||||
#define REG_SET_FIELD(_r, _f, _v) ({ \
|
||||
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \
|
||||
})
|
||||
#define REG_SET_FIELD(_r, _f, _v) do { \
|
||||
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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -102,19 +102,19 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -127,9 +127,9 @@
|
||||
})
|
||||
|
||||
//set bits of register controlled by mask and shift
|
||||
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \
|
||||
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(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)) ); \
|
||||
} while(0)
|
||||
|
||||
//get field of register
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -32,9 +32,9 @@
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -47,19 +47,19 @@
|
||||
})
|
||||
|
||||
//set bit or set bits to register
|
||||
#define REG_SET_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
#define REG_SET_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//clear bit or clear bits of register
|
||||
#define REG_CLR_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
#define REG_CLR_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//set bits of register controlled by mask
|
||||
#define REG_SET_BITS(_r, _b, _m) ({ \
|
||||
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \
|
||||
})
|
||||
#define REG_SET_BITS(_r, _b, _m) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
|
||||
} while(0)
|
||||
|
||||
//get field from register, uses field _S & _V to determine mask
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -67,9 +67,9 @@
|
||||
})
|
||||
|
||||
//set field of a register from variable, uses field _S & _V to determine mask
|
||||
#define REG_SET_FIELD(_r, _f, _v) ({ \
|
||||
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \
|
||||
})
|
||||
#define REG_SET_FIELD(_r, _f, _v) do { \
|
||||
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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -95,19 +95,19 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -120,9 +120,9 @@
|
||||
})
|
||||
|
||||
//set bits of register controlled by mask and shift
|
||||
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \
|
||||
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(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)) ); \
|
||||
} while(0)
|
||||
|
||||
//get field of register
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -32,9 +32,9 @@
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -47,19 +47,19 @@
|
||||
})
|
||||
|
||||
//set bit or set bits to register
|
||||
#define REG_SET_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
#define REG_SET_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//clear bit or clear bits of register
|
||||
#define REG_CLR_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
#define REG_CLR_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//set bits of register controlled by mask
|
||||
#define REG_SET_BITS(_r, _b, _m) ({ \
|
||||
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \
|
||||
})
|
||||
#define REG_SET_BITS(_r, _b, _m) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
|
||||
} while(0)
|
||||
|
||||
//get field from register, uses field _S & _V to determine mask
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -67,9 +67,9 @@
|
||||
})
|
||||
|
||||
//set field of a register from variable, uses field _S & _V to determine mask
|
||||
#define REG_SET_FIELD(_r, _f, _v) ({ \
|
||||
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \
|
||||
})
|
||||
#define REG_SET_FIELD(_r, _f, _v) do { \
|
||||
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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -95,19 +95,19 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -120,9 +120,9 @@
|
||||
})
|
||||
|
||||
//set bits of register controlled by mask and shift
|
||||
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \
|
||||
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(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)) ); \
|
||||
} while(0)
|
||||
|
||||
//get field of register
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -38,9 +38,9 @@
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -53,19 +53,19 @@
|
||||
})
|
||||
|
||||
//set bit or set bits to register
|
||||
#define REG_SET_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
#define REG_SET_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//clear bit or clear bits of register
|
||||
#define REG_CLR_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
#define REG_CLR_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//set bits of register controlled by mask
|
||||
#define REG_SET_BITS(_r, _b, _m) ({ \
|
||||
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \
|
||||
})
|
||||
#define REG_SET_BITS(_r, _b, _m) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
|
||||
} while(0)
|
||||
|
||||
//get field from register, uses field _S & _V to determine mask
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -73,9 +73,9 @@
|
||||
})
|
||||
|
||||
//set field of a register from variable, uses field _S & _V to determine mask
|
||||
#define REG_SET_FIELD(_r, _f, _v) ({ \
|
||||
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \
|
||||
})
|
||||
#define REG_SET_FIELD(_r, _f, _v) do { \
|
||||
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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -101,19 +101,19 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -126,9 +126,9 @@
|
||||
})
|
||||
|
||||
//set bits of register controlled by mask and shift
|
||||
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \
|
||||
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(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)) ); \
|
||||
} while(0)
|
||||
|
||||
//get field of register
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -48,9 +48,9 @@
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
//write value to register
|
||||
#define REG_WRITE(_r, _v) ({ \
|
||||
#define REG_WRITE(_r, _v) do { \
|
||||
(*(volatile uint32_t *)(_r)) = (_v); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//read value from register
|
||||
#define REG_READ(_r) ({ \
|
||||
@ -63,19 +63,19 @@
|
||||
})
|
||||
|
||||
//set bit or set bits to register
|
||||
#define REG_SET_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) |= (_b)); \
|
||||
})
|
||||
#define REG_SET_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) | (_b); \
|
||||
} while(0)
|
||||
|
||||
//clear bit or clear bits of register
|
||||
#define REG_CLR_BIT(_r, _b) ({ \
|
||||
(*(volatile uint32_t*)(_r) &= ~(_b)); \
|
||||
})
|
||||
#define REG_CLR_BIT(_r, _b) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r)) & (~(_b)); \
|
||||
} while(0)
|
||||
|
||||
//set bits of register controlled by mask
|
||||
#define REG_SET_BITS(_r, _b, _m) ({ \
|
||||
(*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m))); \
|
||||
})
|
||||
#define REG_SET_BITS(_r, _b, _m) do { \
|
||||
*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)); \
|
||||
} while(0)
|
||||
|
||||
//get field from register, uses field _S & _V to determine mask
|
||||
#define REG_GET_FIELD(_r, _f) ({ \
|
||||
@ -83,9 +83,9 @@
|
||||
})
|
||||
|
||||
//set field of a register from variable, uses field _S & _V to determine mask
|
||||
#define REG_SET_FIELD(_r, _f, _v) ({ \
|
||||
(REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S))))); \
|
||||
})
|
||||
#define REG_SET_FIELD(_r, _f, _v) do { \
|
||||
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
|
||||
#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
|
||||
@ -111,19 +111,19 @@
|
||||
})
|
||||
|
||||
//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); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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)))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//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))); \
|
||||
})
|
||||
} while(0)
|
||||
|
||||
//get bits of register controlled by mask
|
||||
#define GET_PERI_REG_MASK(reg, mask) ({ \
|
||||
@ -136,9 +136,9 @@
|
||||
})
|
||||
|
||||
//set bits of register controlled by mask and shift
|
||||
#define SET_PERI_REG_BITS(reg,bit_map,value,shift) ({ \
|
||||
(WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(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)) ); \
|
||||
} while(0)
|
||||
|
||||
//get field of register
|
||||
#define GET_PERI_REG_BITS2(reg, mask,shift) ({ \
|
||||
|
@ -319,3 +319,22 @@ LCD
|
||||
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.
|
||||
|
||||
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);
|
||||
|
9
tools/test_apps/system/cxx_build_test/CMakeLists.txt
Normal file
9
tools/test_apps/system/cxx_build_test/CMakeLists.txt
Normal 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)
|
7
tools/test_apps/system/cxx_build_test/README.md
Normal file
7
tools/test_apps/system/cxx_build_test/README.md
Normal 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.
|
@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS cxx_build_test_main.cpp
|
||||
test_soc_reg_macros.cpp
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES soc)
|
@ -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)
|
||||
{
|
||||
}
|
@ -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));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user