diff --git a/components/soc/esp32/include/soc/soc.h b/components/soc/esp32/include/soc/soc.h index 92f4cb7a4e..e7cb5f33e9 100644 --- a/components/soc/esp32/include/soc/soc.h +++ b/components/soc/esp32/include/soc/soc.h @@ -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) ({ \ diff --git a/components/soc/esp32c2/include/soc/soc.h b/components/soc/esp32c2/include/soc/soc.h index f2edefacac..1f5f9a098f 100644 --- a/components/soc/esp32c2/include/soc/soc.h +++ b/components/soc/esp32c2/include/soc/soc.h @@ -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) ({ \ diff --git a/components/soc/esp32c3/include/soc/soc.h b/components/soc/esp32c3/include/soc/soc.h index 365d6b7452..547b7fe815 100644 --- a/components/soc/esp32c3/include/soc/soc.h +++ b/components/soc/esp32c3/include/soc/soc.h @@ -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) ({ \ diff --git a/components/soc/esp32h2/include/soc/soc.h b/components/soc/esp32h2/include/soc/soc.h index 165e8c73b4..98c5f62c92 100644 --- a/components/soc/esp32h2/include/soc/soc.h +++ b/components/soc/esp32h2/include/soc/soc.h @@ -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) ({ \ diff --git a/components/soc/esp32s2/include/soc/soc.h b/components/soc/esp32s2/include/soc/soc.h index caa446355a..55112b84e9 100644 --- a/components/soc/esp32s2/include/soc/soc.h +++ b/components/soc/esp32s2/include/soc/soc.h @@ -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) ({ \ diff --git a/components/soc/esp32s3/include/soc/soc.h b/components/soc/esp32s3/include/soc/soc.h index bc94faf5f6..0b1a48d4e8 100644 --- a/components/soc/esp32s3/include/soc/soc.h +++ b/components/soc/esp32s3/include/soc/soc.h @@ -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) ({ \ diff --git a/docs/en/migration-guides/peripherals.rst b/docs/en/migration-guides/peripherals.rst index 1d0fa4298c..8f7c49c0c8 100644 --- a/docs/en/migration-guides/peripherals.rst +++ b/docs/en/migration-guides/peripherals.rst @@ -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); diff --git a/tools/test_apps/system/cxx_build_test/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/CMakeLists.txt new file mode 100644 index 0000000000..6220fe0dff --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/CMakeLists.txt @@ -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) diff --git a/tools/test_apps/system/cxx_build_test/README.md b/tools/test_apps/system/cxx_build_test/README.md new file mode 100644 index 0000000000..85d7875f10 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/README.md @@ -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_.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. diff --git a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt new file mode 100644 index 0000000000..ece9736565 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS cxx_build_test_main.cpp + test_soc_reg_macros.cpp + INCLUDE_DIRS "." + REQUIRES soc) diff --git a/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp b/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp new file mode 100644 index 0000000000..3196de6e05 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/cxx_build_test_main.cpp @@ -0,0 +1,10 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include + +extern "C" void app_main(void) +{ +} diff --git a/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp b/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp new file mode 100644 index 0000000000..fa2d60b509 --- /dev/null +++ b/tools/test_apps/system/cxx_build_test/main/test_soc_reg_macros.cpp @@ -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)); +}