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

pstorage guide

HI,everyone!

I want to use pstorage to store some data, so I followed the steps given by devzone.nordicsemi.com/.../, but it didn't work. Then I checked ecah function and found out the

pstorage_register (&p_example_param, &m_p_example_id)

return NRF_ERROR_NULL,and I can't find out where the problems come from.

Can someone point out the problem or give me an example for pstorage use?

Thank you very much!

Parents
  • Are you using device manager along with your test psorage? You shouldn't initialize pstorage_init twice if you call example_pstorage_init after device manager init. Or you need to increase maximum number of applications PSTORAGE_MAX_APPLICATIONS in pstorage_platform.h.

    UPD:

    You can read more about pstorage here.

    There is a pstorage example code here

    Example handler:

    // Event Notification Handler.
    static void example_cb_handler(pstorage_handle_t  * 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)
               {
                   // Store operation successful.
               }
               else
               {
                   // Store operation failed.
               }
               // Source memory can now be reused or freed.
               break;       
            case PSTORAGE_UPDATE_OP_CODE:
               if (result == NRF_SUCCESS)
               {
                   // Update operation successful.
               }
               else
               {
                   // Update operation failed.
               }
               break;
           case PSTORAGE_CLEAR_OP_CODE:
               if (result == NRF_SUCCESS)
               {
                   // Clear operation successful.
               }
               else
               {
                   // Clear operation failed.
               }
               break;
        }
    }
    
  • to instantiate a callback handler one would create a function that mtaches the type required. Specifically:

    static void example_cb_handler( pstorage_handle_t *p_handle, uint8_t op_code, uint32_t result, uint8_t p_data, uint32_t dat_len ) { / do something */ }

    "example_cb_handler", then, is a pointer to the function itself, which can then be assigned in a statement

    example_param.cb = example_cb_handler;

    Please look to generic c-coding guides for typedef creations of function pointers. Function pointers are extremely useful tools, and can be used to greatly simplify otherwise very complex code.

Reply
  • to instantiate a callback handler one would create a function that mtaches the type required. Specifically:

    static void example_cb_handler( pstorage_handle_t *p_handle, uint8_t op_code, uint32_t result, uint8_t p_data, uint32_t dat_len ) { / do something */ }

    "example_cb_handler", then, is a pointer to the function itself, which can then be assigned in a statement

    example_param.cb = example_cb_handler;

    Please look to generic c-coding guides for typedef creations of function pointers. Function pointers are extremely useful tools, and can be used to greatly simplify otherwise very complex code.

Children
No Data
Related