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

Random pool numbers - documentation

Dear Nordic,

Is there any documentation available,how the random pool works and where is expected that SoftDevice offers something and when it is blocked? And if there are no bytes available, it is sure that will be in future? I am working on very sensitive application and I have found this code in this thread:

devzone.nordicsemi.com/.../sd_rand_application_vector_get-crashes-system

However without any deep knowledge I can say, that this can end up with infinity loop. Let us say that I will add ERORR checking at this function, can I be sure that at next event I will have new values in pool for sure?

If I get the available bytes, how long do they keep available?

Do you consider this code will not state in finite loop if soft device will working correctly?

void get_rnd_buf(uint8_t *buf, uint8_t len)
{
    uint8_t bytes_available;
    uint32_t err_code;
    do
    {
        sd_rand_application_bytes_available_get(&bytes_available);
        if(bytes_available >= len)
        {
            err_code=sd_rand_application_vector_get(buf, len);
            if (err_code==NRF_SUCCESS) len = 0;
        }
        else
        {
        	err_code=sd_rand_application_vector_get(buf, bytes_available);
        	if (err_code==NRF_SUCCESS)
        	{
        		buf += bytes_available;
        		len -= bytes_available;
        	}
            sd_app_event_wait();
        }
    }while(len > 0);
}

Are there any cases where would I need to count number of tries? And exit at some limit?

Thx very much.

Jan

  • Hi Jan,

    The execution time of this function will depend on the stack availability. Doing blocking while-loops are always risky, but in this case you could end up in a while(1): The sd_app_event_wait is actually a wrapper function of __WFE(). What it does is that it forwards "open" peripheral (open = not used by SD) events to the application, and since the RNG is not forwarded, you can end up waiting for a long period of time. It's recommended not to sleep in this function.

    If I get the available bytes, how long do they keep available?

    They are kept in an application pool inside the softdevice, so it's valid until read out.

    Best regards Håkon

Related