@ Dmitry Suhamera
I have used your code but after compiling it gives an error.
Error: "count" is ambiguous in "P_storage.cpp", Line: 101, Col: 57
Error: "count" is ambiguous in "P_storage.cpp", Line: 102, Col: 26
***********
- include "mbed.h"
- include "BLE.h"
- include "pstorage.h"
- include "nrf_error.h"
BLEDevice ble;
uint32_t retval, count;
uint8_t source_data[8] = {0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x01,0x02};
uint8_t dest_data[8];
time_t savetime, loadtime;
pstorage_handle_t handle;
Serial serial(USBTX, USBRX); tx, rx
static void cb_handler(pstorage_handle_t * handle,
uint8_t op_code,
uint32_t result,
uint8_t * p_data,
uint32_t data_len)
{
serial.printf("Callback handler successful\r\n");
switch(op_code)
{
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS)
{
serial.printf("Clear operation successful in Callback\r\n");
}
else
{
serial.printf("Clear operation failed in Callback\r\n");
}
break;
case PSTORAGE_LOAD_OP_CODE:
if (result == NRF_SUCCESS)
{
serial.printf("Load operation successful in Callback\r\n");
}
else
{
serial.printf("Load operation failed in Callback\r\n");
}
break;
case PSTORAGE_STORE_OP_CODE:
if (result == NRF_SUCCESS)
{
serial.printf("Store operation successful in Callback\r\n");
}
else
{
serial.printf("Store operation failed in Callback\r\n");
}
break;
}
}
int main(void){
wait(5);
serial.printf("Warming up\r\n");
wait(5);
ble.init();
retval = pstorage_init();
if(retval == NRF_SUCCESS)
{
serial.printf("Module initialization successful\r\n");
pstorage_module_param_t param;
param.block_size = 100;
param.block_count = 10;
param.cb = cb_handler;
retval = pstorage_register(¶m, &handle); register our pstorage and store store address in handle
if (retval == NRF_SUCCESS)
{
serial.printf("Registration successful.\r\n");
serial.printf("Module id: %u , block: %u \r\n", handle.module_id, handle.block_id);
retval = pstorage_store(&handle, source_data, sizeof(source_data), 0); store test data in bloc 0
if (retval == NRF_SUCCESS)
{
serial.printf("Store successfully requested. Wait for operation result.\r\n");
retval = pstorage_access_status_get(&count);
if (count == 0)
{
loadtime = time(NULL);
serial.printf("No pending operations \r\n");
retval = pstorage_load(dest_data, &handle, sizeof(dest_data), 0); try to load test data
if (retval == NRF_SUCCESS)
{
serial.printf("STORE: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", source_data[0], source_data[1], source_data[2], source_data[3],source_data[4], source_data[5], source_data[6], source_data[7] );
serial.printf("LOAD: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", dest_data[0], dest_data[1],dest_data[2],dest_data[3], dest_data[4],dest_data[5],dest_data[6],dest_data[7] );
}
else {
serial.printf("Failed to load, take corrective action.\r\n");
}
}
else
{
serial.printf("Storage access pending, wait!\r\n");
serial.printf("Time div: %d \r\n", (loadtime-savetime) );
}
}
else {serial.printf("Failed to request store, take corrective action.\r\n");}
}
else {serial.printf("Failed to register, take corrective action.\r\n");}
}
else {serial.printf("Initialization failed, take corrective action.\r\n"); }
while (true) {
ble.waitForEvent();
}
}
can u please provide link for liabrairy files??