Hello,
I've read several of the questions on here related to pstorage, including one poster who had trouble running it in conjunction with the mesh. I decided to take my PCA10031 dongle and program it with the mesh template example using the latest SDK (8.1) and S110 SoftDevice. Then, using the pstorage examples, I attempted to do a clear, store, and load. I simply cannot get this to work. My shortened code is below. Neither the callback or the sys_evt_dispatch() function is called. I was somewhat successful with previous attempts (on my own hardware), but it would take 20+ seconds before the first call to the callback was made. Can anyone please give me some clues? (Note that I am not doing BLE advertising - only running the mesh by itself - the template example). I am using the latest mesh from this past week. I am using Keil 5.14. Optimization level 0.
Thanks in advance. -s
static int pstorage_flag = false;
void rbc_mesh_event_handler(rbc_mesh_event_t* evt)
{
switch (evt->event_type)
{
case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL:
case RBC_MESH_EVENT_TYPE_NEW_VAL:
case RBC_MESH_EVENT_TYPE_UPDATE_VAL:
case RBC_MESH_EVENT_TYPE_INITIALIZED:
break;
}
}
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:
case PSTORAGE_STORE_OP_CODE:
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS)
{
pstorage_flag = true;
}
break;
default:
break;
}
}
static void sys_evt_dispatch(uint32_t sys_evt)
{
pstorage_sys_event_handler(sys_evt);
}
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
}
static uint8_t my_buffer[32];
static pstorage_handle_t m_p_example_id;
static uint8_t dummy_data[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
int main(void)
{
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, rbc_mesh_sd_irq_handler);
rbc_mesh_init_params_t init_params;
init_params.access_addr = 0xA541A68F;
init_params.adv_int_ms = 100;
init_params.channel = 38;
init_params.handle_count = 1;
init_params.packet_format = RBC_MESH_PACKET_FORMAT_ORIGINAL;
init_params.radio_mode = RBC_MESH_RADIO_MODE_BLE_1MBIT;
uint32_t error_code;
error_code = rbc_mesh_init(init_params);
APP_ERROR_CHECK(error_code);
error_code = rbc_mesh_value_enable(1);
APP_ERROR_CHECK(error_code);
error_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
APP_ERROR_CHECK(error_code);
error_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(error_code);
pstorage_module_param_t p_example_param;
p_example_param.block_size = 0x10;
p_example_param.block_count = 60;
p_example_param.cb = example_cb_handler;
error_code = pstorage_init();
APP_ERROR_CHECK(error_code);
error_code = pstorage_register (&p_example_param, &m_p_example_id);
APP_ERROR_CHECK(error_code);
uint16_t dummy_block = 0;
uint16_t dummy_size = 16;
uint16_t dummy_offset = 0;
pstorage_handle_t p_block_id;
error_code = pstorage_block_identifier_get(&m_p_example_id, dummy_block, &p_block_id);
APP_ERROR_CHECK(error_code);
error_code = pstorage_clear(&p_block_id, 60 * 16);
APP_ERROR_CHECK(error_code);
while (pstorage_flag == false) { }
pstorage_flag = false;
error_code = pstorage_store(&p_block_id, dummy_data, dummy_size, dummy_offset);
APP_ERROR_CHECK(error_code);
while (pstorage_flag == 0) { }
pstorage_flag = false;
error_code = pstorage_load(my_buffer, &p_block_id, dummy_size, dummy_offset);
APP_ERROR_CHECK(error_code);
while (pstorage_flag == false) { }
while (true)
{
sd_app_evt_wait();
}
}