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

If the softdevice is enabled, can I call the function of "nrf_mtx.h"? If I could, would something bad happen?

Hi.

As the subject said,I want to know that if the softdevice is enabled, can I call the function of "nrf_mtx.h"?

such as:

 

__STATIC_INLINE bool nrf_mtx_trylock(nrf_mtx_t * p_mtx)
{
    ASSERT(p_mtx  != NULL);

    uint32_t old_val = nrf_atomic_u32_fetch_store(p_mtx, NRF_MTX_LOCKED);

    // Add memory barrier to ensure that the mutex is locked before any memory operations protected
    // by the mutex are started.
    __DMB();

    return (old_val == NRF_MTX_UNLOCKED);
}

__STATIC_INLINE void nrf_mtx_unlock(nrf_mtx_t * p_mtx)
{
    ASSERT(p_mtx  != NULL);
    ASSERT(*p_mtx == NRF_MTX_LOCKED);

    // Add memory barrier to ensure that any memory operations protected by the mutex complete
    // before the mutex is unlocked.
    __DMB();

    *p_mtx = NRF_MTX_UNLOCKED;
}

Parents
  • Hi

    When using the SoftDevice, I would suggest using the sd_mutex functions which are an implementation of mutex that can be used by the application. The mutex functionality itself is handled by the SoftDevice, and due to the characteristics of SVC calls in the ARM architecture, it's atomic. When the SoftDevice is running, you can never interrupt the "lower stack" interrupts. Here, the mutex is atomic, in the sense that grabbing/releasing it is a process that can't be interrupted as it will run through the SoftDevice supervisor call.

    Best regards,

    Simon

Reply
  • Hi

    When using the SoftDevice, I would suggest using the sd_mutex functions which are an implementation of mutex that can be used by the application. The mutex functionality itself is handled by the SoftDevice, and due to the characteristics of SVC calls in the ARM architecture, it's atomic. When the SoftDevice is running, you can never interrupt the "lower stack" interrupts. Here, the mutex is atomic, in the sense that grabbing/releasing it is a process that can't be interrupted as it will run through the SoftDevice supervisor call.

    Best regards,

    Simon

Children
Related