This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pstorage storing takes infinite time?

Hi,

I am trying to understand the pstorage to record a log for temperature. In my code, I can call pstorage_init(), and clear a block but when I try to store some data, the application never gets in the pstorage_handler.

I have put some RTT for debugging purposes. From RTT I can see that error1, error2, error3, error5 are 0, NRF_SUCCESS. error4 is never shown because the program cannot reach there.

Here are the main three functions related to this:

static void m_pstorage_init()
{
uint32_t err_code;         
pstorage_module_param_t p_example_param;    

// Setup pstorage with 60blocks of 16byte in each.
p_example_param.block_size  = 0x4; // recommended to be >= 4 byte
p_example_param.block_count = BLOCK_COUNT;
p_example_param.cb          = m_pstorage_handler;

err_code = pstorage_init();
SEGGER_RTT_printf(0, "error_code1: %d\n", err_code);
	APP_ERROR_CHECK(err_code);

	err_code = pstorage_register (&p_example_param, &m_pstorage);
SEGGER_RTT_printf(0, "error_code2: %d\n", err_code);
  APP_ERROR_CHECK(err_code);
}

static void temperature_timeout_handler(void * p_context)
 {		
	ret_code_t err_code;

	if( count != BLOCK_COUNT){
	
	int temperature;
	measureTemperature(&temperature);

	uint8_t* a;
	a = (uint8_t*)temperature;
	
	pstorage_handle_t block_id;
	
	err_code = pstorage_block_identifier_get(&m_pstorage, count, &block_id );
	SEGGER_RTT_printf(0, "error_code3: %d\n", err_code);
	APP_ERROR_CHECK(err_code);
	
	
	err_code = pstorage_clear(&block_id, 4);
	
	
	SEGGER_RTT_printf(0, "error_code5: %d\n", err_code);
	APP_ERROR_CHECK(err_code);
	
            wait = 1;
	err_code = pstorage_store(&block_id, a, 4, 0);
	
	while(wait )
	{
		power_manage();
	}

	SEGGER_RTT_printf(0, "error_code4: %d\n", err_code);
	APP_ERROR_CHECK(err_code);
	
	temperature_characteristic_update(&m_tempe_service, &m_pstorage, count);
	
	count++;
	}
 }



void m_pstorage_handler(pstorage_handle_t * p_handle,
											uint8_t             op_code,
											uint32_t            result,
											uint8_t *           p_data,
											uint32_t            data_len)
{
switch(op_code)
{
    case PSTORAGE_LOAD_OP_CODE:
       if (result == NRF_SUCCESS)
       {
          SEGGER_RTT_WriteString(0, "Storage Load Successful!\n");
						wait = 0;
						
       }
       else
       {
          SEGGER_RTT_WriteString(0, "Storage Load Failed!\n");
						SEGGER_RTT_printf(0, "result: %d\n", result);
						APP_ERROR_CHECK(result);
       }
       // Source memory can now be reused or freed.
       break;      
			case PSTORAGE_STORE_OP_CODE:
       if (result == NRF_SUCCESS)
       {
         SEGGER_RTT_WriteString(0, "Storage Store Successful!\n");
					 wait = 0;
       }
       else
       {
           SEGGER_RTT_WriteString(0, "Storage Store Failed!\n");
						 SEGGER_RTT_printf(0, "result: %d\n", result);
						 APP_ERROR_CHECK(result);
       }
       // Source memory can now be reused or freed.
       break;      
    case PSTORAGE_UPDATE_OP_CODE:
       if (result == NRF_SUCCESS)
       {
           SEGGER_RTT_WriteString(0, "Storage Update Successful!\n");
						 wait = 0;
       }
       else
       {
						SEGGER_RTT_WriteString(0, "Storage Update Failed!\n");
						SEGGER_RTT_printf(0, "result: %d\n", result); 
						APP_ERROR_CHECK(result);
       }
       break;
   case PSTORAGE_CLEAR_OP_CODE:
       if (result == NRF_SUCCESS)
       {
           SEGGER_RTT_WriteString(0, "Storage Clear Successful!\n");
					   wait = 0;
       }
       else
       {
						SEGGER_RTT_WriteString(0, "Storage Update Failed!\n");
						SEGGER_RTT_printf(0, "result: %d\n", result);  
						APP_ERROR_CHECK(result);
       }
       break;
}
}

As far as I understand the error_handler does not break the sd_app_evt_wait() function. Is this correct? How can I solve this issue?

Edit: Ok, I think I solved the waiting issue but there is another error now. The problem was that the app_timer was not allowing any interrupts from softdevice to arise. I simply assigned a flag which changes when the app_timer ticks. Then, I did the pstorage work in my main loop. I am closing this thread and oppening a new one since the error is different now. Anyone who is using the app_timer with the pstorage can use scheduler or just simply assign a flag as I did.

Thanks

Related