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

sd_app_evt_wait not giving call back

Hi

I'm using sd_app_evt_wait(); to go into low_power mode. For some reason it coming back , but I can't figure out why.

Peace of code I am executing is;

while (nrf_fstorage_is_busy(&my_instance)) {
NRF_LOG_INFO("INWHILE LOOP");
sd_app_evt_wait();
}

I am not sure how to debug it? Is is softDevice issue?

EDIT:

I can see the function nrf_fsstorage_is_busy() is in softdevice,

bool nrf_fstorage_is_busy(nrf_fstorage_t const * p_fs)
{

/* If a NULL instance is provided, return true if any instance is busy.
* Uninitialized instances are considered not busy. */
if ((p_fs == NULL) || (p_fs->p_api == NULL))
{
for (uint32_t i = 0; i < NRF_FSTORAGE_INSTANCE_CNT; i++)
{
p_fs = NRF_FSTORAGE_INSTANCE_GET(i); /* cannot be NULL. */
if (p_fs->p_api != NULL)
{
/* p_api->is_busy() cannot be NULL. */
if (p_fs->p_api->is_busy(p_fs))
{
return true;
}
}
}

return false;
}

return p_fs->p_api->is_busy(p_fs);
}

Which in turn call function,

is_busy(p_fs)

I am just wondering how to debug it ,I mean where I can give print statement?

Which function get this function sd_app_evt_wait() awake signal?

Sorry, if I am asking very basic question

Best Regards,

PAJ

  • PAJ: I am asking for the Software Development Kit(SDK) version, e.g. SDK v11.0.0 or SDK v15.0.0. I am not asking for the SoftDevice version, e.g. S132 v3.0.0 or S132 v6.0.0. 

    Which version of the SDK did you download from http://developer.nordicsemi.com/?

     

  • Dear Bajorn,

    Sorry for the confusion .. I am using SDK_14.2.0_17b948a

  • You should take a look at the flash_fstorage example in /peripheral/flash_fstorage. 

    nrf_fstorage_is_busy is calling is_busy() which returns the internal state of the fstorage module, i.e. 

    static bool is_busy(nrf_fstorage_t const * p_fs)
    {
        UNUSED_PARAMETER(p_fs);
    
        return (m_flags.state != NRF_FSTORAGE_STATE_IDLE);
    }
    

    The internal state flag, m_flags.state, is set in nrf_fstorage_sys_evt_handler() 

    void nrf_fstorage_sys_evt_handler(uint32_t sys_evt, void * p_context)
    {
        UNUSED_PARAMETER(p_context);
    
        switch (m_flags.state)
        {
            case NRF_FSTORAGE_STATE_OP_EXECUTING:
            {
                /* Handle the result of a flash operation initiated by this module. */
                bool operation_finished = false;
    
                switch (sys_evt)
                {
                    case NRF_EVT_FLASH_OPERATION_SUCCESS:
                        operation_finished = on_operation_success(m_p_cur_op);
                        break;
    
                    case NRF_EVT_FLASH_OPERATION_ERROR:
                        operation_finished = on_operation_failure(m_p_cur_op);
                        break;
    
                    default:
                        break;
                }
    
                if (operation_finished)
                {
                    /* The operation has finished. Change state to NRF_FSTORAGE_STATE_IDLE
                     * so that queue_process() will fetch a new operation from the queue. */
                    m_flags.state = NRF_FSTORAGE_STATE_IDLE;
    
                    event_send(m_p_cur_op, (sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS) ?
                                            NRF_SUCCESS : NRF_ERROR_TIMEOUT);
    
                    /* Free the queue element after sending out the event to prevent API calls made
                     * in the event context to queue elements indefinitely, without this function
                     * ever returning in case the SoftDevice calls are synchronous. */
                    queue_free();
                }
            } break;
    
            case NRF_FSTORAGE_STATE_OP_PENDING:
                /* The SoftDevice has completed a flash operation that was not requested by fstorage.
                 * It should be possible to request an operation now.
                 * Process the queue at the end of this function. */
                break;
    
            default:
                /* If idle, return. */
                return;
        }
    
        if (!m_flags.paused)
        {
            queue_process();
        }
        else
        {
            /* A flash operation has completed. Let the SoftDevice to change state. */
            (void) nrf_sdh_request_continue();
        }
    }


    when a flash operation has been finished succesfully. Hence, if you did not initiate any flash operation prior to calling wait_for_flash_ready(), then it should return true and exit the while loop. If you did call nrf_fstorage_write or erase prior to wait_for_flash_ready() and it does not return at all , then you're probably not forwarding the interrupts to the fstorage module. 

Related