[riot-notifications] [RIOT-OS/RIOT] cpu/rpx0xx: add periph timer (#16627)

fabian18 notifications at github.com
Tue Jul 27 13:48:52 CEST 2021


> > This error disappears without `volatile` in the cast.
> 
> This could result in the compiler optimizing out the store, as it would be unaware that the store has side effects.
> 
> The issue is that the C++ compiler is interpreting the C code as C++ code.
> 
> I think something like this could work for both C and C++:
> 
> ```diff
> diff --git a/cpu/rpx0xx/include/periph_cpu.h b/cpu/rpx0xx/include/periph_cpu.h
> index 1f0ea78122..87803d12e0 100644
> --- a/cpu/rpx0xx/include/periph_cpu.h
> +++ b/cpu/rpx0xx/include/periph_cpu.h
> @@ -416,7 +416,7 @@ static inline volatile uint32_t * gpio_pad_register(uint8_t pin)
>   */
>  static inline void gpio_set_pad_config(uint8_t pin, gpio_pad_ctrl_t config)
>  {
> -    *(volatile gpio_pad_ctrl_t*)gpio_pad_register(pin) = config;
> +    *(volatile gpio_pad_ctrl_t*)gpio_pad_register(pin) = (volatile gpio_pad_ctrl_t)config;
>  }
>  
>  /**
> ```

C++ keeps being picky about it.
Nor do
```C
static inline void gpio_set_pad_config(uint8_t pin, volatile gpio_pad_ctrl_t config)
{
    *(volatile gpio_pad_ctrl_t *)gpio_pad_register(pin) = config;
}
```
and 
```C
static inline void gpio_set_pad_config(uint8_t pin, gpio_pad_ctrl_t config)
{
    *(volatile gpio_pad_ctrl_t *)gpio_pad_register(pin) = *(volatile gpio_pad_ctrl_t *)&config;
}
```
work out.
But this also pleases C++ and `volatile` stays.
```C
static inline void gpio_set_pad_config(uint8_t pin, gpio_pad_ctrl_t config)
{
    uint32_t *c = (uint32_t *)&config;
    *gpio_pad_register(pin) = *c;
}
```
I guess  because `operator=` cannot be overloaded for `uint32_t`.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16627#issuecomment-887445366
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210727/3c79a0c4/attachment.htm>


More information about the notifications mailing list