Volatile needed for I2c slave buffer

Hi, 

I am working on a module that will act as a i2c slave.

When providing the buffer for the twis library, it is unclear if the buffer should me made volatile or not using the SDK.

Could you please help me understanding this. A buffer is provided for the hardware to put rx data in it, so I would think of making it volatile.

But the function to provide the buffer has no qualifier for volatile in its argument:


ret_code_t nrf_drv_twis_tx_prepare(
nrf_drv_twis_t const * const p_inst,
void const * const p_buf,
size_t size)

What would be your recommendation here ?Thanks for your advice. Note: the buffer is used in the twis handler, and somewhere outside.

Best regards,

Hector.

  • Hi,

    The compiler sees that the buffer is passed in to a function in a different file (which is not const data) and then knows that it may be changed outside of the file. (And as optimization normally happens per file with C compilers, there will not be any need for using volatile regardless of what happens there).

    (Edit: I sould mention that in the MDK file that is used by the driver, volatile is used, so with regards to the HW possibly modifying the buffer, this is handled by the low-level code we provide)

Related