This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?

Hello everybody, I study transceiver nrf24LE1. I'm trying to understand example of PRX in nRFgo SDK (Enhanced_shockburst_examples):

/

    / Global variables
    uint8_t payload [3];
     
    // Radio interrupt
    NRF_ISR () // #define NRF_ISR () void nrf_isr (void) interrupt 8 // RF interrupt (0x4b)
    {
    ...
         // Read payload
    ...
           hal_nrf_read_rx_payload (payload);
    ...
    }

Please explain why uint8_t payload [3] is not declared as volatile ? Thank you so much!!!

Parents
  • What do you mean 'address this issue'? If you want to put volatile on it, put volatile on it. It won't hurt, it may make your code ever so slightly less efficient but apart from that it's not going to do a lot apart from give you peace of mind that the compiler will always read from the memory and not assume the contents doesn't change during the course of a function call. Volatile isn't going to affect whether or not the buffer is optimised out (it's not) nor whether the compiler assumes the contents don't change across function calls (it doesn't assume that).

Reply
  • What do you mean 'address this issue'? If you want to put volatile on it, put volatile on it. It won't hurt, it may make your code ever so slightly less efficient but apart from that it's not going to do a lot apart from give you peace of mind that the compiler will always read from the memory and not assume the contents doesn't change during the course of a function call. Volatile isn't going to affect whether or not the buffer is optimised out (it's not) nor whether the compiler assumes the contents don't change across function calls (it doesn't assume that).

Children
Related